UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

37 lines (36 loc) 943 B
import { GpuProfiler } from "../gpu-profiler.js"; import { WebgpuQuerySet } from "./webgpu-query-set.js"; class WebgpuGpuProfiler extends GpuProfiler { device; frameGPUMarkerSlot; constructor(device) { super(); this.device = device; this.maxCount = 1024; this.timestampQueriesSet = device.supportsTimestampQuery ? new WebgpuQuerySet(device, true, 2 * this.maxCount) : null; } destroy() { this.timestampQueriesSet?.destroy(); this.timestampQueriesSet = null; } frameStart() { this.processEnableRequest(); } frameEnd() { if (this._enabled) { this.timestampQueriesSet?.resolve(this.slotCount * 2); } } request() { if (this._enabled) { const renderVersion = this.device.renderVersion; this.timestampQueriesSet?.request(this.slotCount, renderVersion).then((results) => { this.report(results.renderVersion, results.timings); }); super.request(renderVersion); } } } export { WebgpuGpuProfiler };