| 547 | } |
| 548 | |
| 549 | override time(f: () => void): Promise<WebGLTimingInfo> { |
| 550 | const oldActiveTimers = this.activeTimers; |
| 551 | const newActiveTimers: TimerNode[] = []; |
| 552 | |
| 553 | let outerMostTime = false; |
| 554 | if (this.programTimersStack == null) { |
| 555 | this.programTimersStack = newActiveTimers; |
| 556 | outerMostTime = true; |
| 557 | } else { |
| 558 | this.activeTimers.push(newActiveTimers); |
| 559 | } |
| 560 | this.activeTimers = newActiveTimers; |
| 561 | |
| 562 | f(); |
| 563 | |
| 564 | // needing to split these up because util.flatten only accepts certain types |
| 565 | const flattenedActiveTimerQueries = |
| 566 | util.flatten(this.activeTimers.map((d: KernelInfo) => d.query)) |
| 567 | .filter(d => d != null); |
| 568 | const flattenedActiveTimerNames = |
| 569 | util.flatten(this.activeTimers.map((d: KernelInfo) => d.name)) |
| 570 | .filter(d => d != null); |
| 571 | |
| 572 | this.activeTimers = oldActiveTimers; |
| 573 | |
| 574 | if (outerMostTime) { |
| 575 | this.programTimersStack = null; |
| 576 | } |
| 577 | |
| 578 | const res: WebGLTimingInfo = { |
| 579 | uploadWaitMs: this.uploadWaitMs, |
| 580 | downloadWaitMs: this.downloadWaitMs, |
| 581 | kernelMs: null, |
| 582 | wallMs: null // will be filled by the engine |
| 583 | }; |
| 584 | |
| 585 | return (async () => { |
| 586 | if (env().getNumber('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE') > |
| 587 | 0) { |
| 588 | const kernelMs = await Promise.all(flattenedActiveTimerQueries); |
| 589 | |
| 590 | res['kernelMs'] = util.sum(kernelMs); |
| 591 | res['getExtraProfileInfo'] = () => |
| 592 | kernelMs |
| 593 | .map((d, i) => ({name: flattenedActiveTimerNames[i], ms: d})) |
| 594 | .map(d => `${d.name}: ${d.ms}`) |
| 595 | .join(', '); |
| 596 | } else { |
| 597 | res['kernelMs'] = { |
| 598 | error: 'WebGL query timers are not supported in this environment.' |
| 599 | }; |
| 600 | } |
| 601 | |
| 602 | this.uploadWaitMs = 0; |
| 603 | this.downloadWaitMs = 0; |
| 604 | return res; |
| 605 | })(); |
| 606 | } |