Skip to content

Commit 92bd4f3

Browse files
WebGPURenderer: Improve TimestampQueryPool logs (#30393)
1 parent 0d34438 commit 92bd4f3

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

examples/webgpu_compute_particles.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,10 @@
266266
stats.update();
267267

268268
await renderer.computeAsync( computeParticles );
269+
renderer.resolveTimestampsAsync( THREE.TimestampQuery.COMPUTE );
269270

270271
await renderer.renderAsync( scene, camera );
272+
renderer.resolveTimestampsAsync( THREE.TimestampQuery.RENDER );
271273

272274
// throttle the logging
273275

examples/webgpu_compute_sort_bitonic.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import * as THREE from 'three';
5858
import { storage, If, vec3, not, uniform, uv, uint, float, Fn, vec2, abs, int, invocationLocalIndex, workgroupArray, uvec2, floor, instanceIndex, workgroupBarrier, atomicAdd, atomicStore, workgroupId } from 'three/tsl';
5959

60+
import WebGPU from 'three/addons/capabilities/WebGPU.js';
61+
6062
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
6163

6264
const StepType = {
@@ -130,6 +132,15 @@
130132
// When forceGlobalSwap is true, force all valid local swaps to be global swaps.
131133
async function init( forceGlobalSwap = false ) {
132134

135+
136+
if ( WebGPU.isAvailable() === false ) {
137+
138+
document.body.appendChild( WebGPU.getErrorMessage() );
139+
140+
throw new Error( 'No WebGPU support' );
141+
142+
}
143+
133144
let currentStep = 0;
134145
let nextStepGlobal = false;
135146

@@ -515,11 +526,15 @@
515526

516527
}
517528

529+
renderer.resolveTimestampsAsync( THREE.TimestampQuery.COMPUTE );
530+
531+
518532
const algo = new Uint32Array( await renderer.getArrayBufferAsync( nextAlgoBuffer ) );
519533
algo > StepType.DISPERSE_LOCAL ? ( nextStepGlobal = true ) : ( nextStepGlobal = false );
520534
const totalSwaps = new Uint32Array( await renderer.getArrayBufferAsync( counterBuffer ) );
521535

522536
renderer.render( scene, camera );
537+
renderer.resolveTimestampsAsync( THREE.TimestampQuery.RENDER );
523538

524539
timestamps[ forceGlobalSwap ? 'global_swap' : 'local_swap' ].innerHTML = `
525540

examples/webgpu_storage_buffer.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<script type="module">
5454

5555
import * as THREE from 'three';
56-
import { storageObject, If, vec3, uv, uint, float, Fn, instanceIndex, workgroupBarrier } from 'three/tsl';
56+
import { storage, If, vec3, uv, uint, float, Fn, instanceIndex, workgroupBarrier } from 'three/tsl';
5757

5858
const timestamps = {
5959
webgpu: document.getElementById( 'timestamps' ),
@@ -90,7 +90,7 @@
9090

9191
const arrayBuffer = new THREE.StorageInstancedBufferAttribute( new Float32Array( array ), typeSize );
9292

93-
arrayBufferNodes.push( storageObject( arrayBuffer, type[ i ], size ) );
93+
arrayBufferNodes.push( storage( arrayBuffer, type[ i ], size ).setPBO( true ) );
9494

9595
}
9696

@@ -218,6 +218,9 @@
218218
await renderer.computeAsync( compute );
219219
await renderer.renderAsync( scene, camera );
220220

221+
renderer.resolveTimestampsAsync( THREE.TimestampQuery.COMPUTE );
222+
renderer.resolveTimestampsAsync( THREE.TimestampQuery.RENDER );
223+
221224
timestamps[ forceWebGL ? 'webgl' : 'webgpu' ].innerHTML = `
222225
223226
Compute ${renderer.info.compute.frameCalls} pass in ${renderer.info.compute.timestamp.toFixed( 6 )}ms<br>

examples/webgpu_texturegrad.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
const box = new THREE.Mesh( new THREE.PlaneGeometry( 1, 1 ), material );
9191
scene.add( box );
9292

93-
const renderer = new THREE.WebGPURenderer( { antialias: false, forceWebGL: forceWebGL, trackTimestamp: true } );
93+
const renderer = new THREE.WebGPURenderer( { antialias: false, forceWebGL: forceWebGL } );
9494
renderer.setPixelRatio( window.devicePixelRatio );
9595
renderer.setSize( window.innerWidth / 2, window.innerHeight );
9696

src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { warnOnce } from '../../../utils.js';
12
import TimestampQueryPool from '../../common/TimestampQueryPool.js';
23

34
/**
@@ -57,6 +58,7 @@ class WebGLTimestampQueryPool extends TimestampQueryPool {
5758
// Check if we have enough space for a new query pair
5859
if ( this.currentQueryIndex + 2 > this.maxQueries ) {
5960

61+
warnOnce( `WebGPUTimestampQueryPool [${ this.type }]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${ this.type.toUpperCase() } ).` );
6062
return null;
6163

6264
}

src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool {
5252

5353
if ( this.currentQueryIndex + 2 > this.maxQueries ) {
5454

55-
warnOnce( 'WebGPUTimestampQueryPool: Maximum number of queries exceeded.' );
55+
warnOnce( `WebGPUTimestampQueryPool [${ this.type }]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${ this.type.toUpperCase() } ).` );
5656
return null;
5757

5858
}

0 commit comments

Comments
 (0)