-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
webgpu-gpu-profiler.js
48 lines (38 loc) · 1.25 KB
/
webgpu-gpu-profiler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { DebugHelper } from "../../../core/debug.js";
import { GpuProfiler } from "../gpu-profiler.js";
import { WebgpuQuerySet } from "./webgpu-query-set.js";
class WebgpuGpuProfiler extends GpuProfiler {
device;
/** @type {number} */
frameGPUMarkerSlot;
constructor(device) {
super();
this.device = device;
// gpu timing queries
this.timestampQueriesSet = device.supportsTimestampQuery ? new WebgpuQuerySet(device, true, 512) : null;
}
destroy() {
this.timestampQueriesSet?.destroy();
this.timestampQueriesSet = null;
}
frameStart() {
this.processEnableRequest();
}
frameEnd() {
if (this._enabled) {
// schedule command buffer where timestamps are copied to CPU
this.timestampQueriesSet?.resolve(this.slotCount * 2);
}
}
request() {
if (this._enabled) {
// request results
const renderVersion = this.device.renderVersion;
this.timestampQueriesSet?.request(this.slotCount, renderVersion).then((results) => {
this.report(results.renderVersion, results.timings);
});
super.request(renderVersion);
}
}
}
export { WebgpuGpuProfiler };