-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGPURenderer: Introduce TimestampQueryPool #30359
WebGPURenderer: Introduce TimestampQueryPool #30359
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
||
if ( renderContextData.activeQuery !== null ) { | ||
|
||
this.gl.beginQuery( this.disjoint.TIME_ELAPSED_EXT, renderContextData.activeQuery ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice to see the timestamp related code is moved into specific modules. That makes the backends easier to maintain.
|
||
// compute | ||
|
||
await renderer.computeAsync( computeParticles ); | ||
renderer.compute( computeParticles ); | ||
renderer.resolveTimestampsAsync( 'compute' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to have a static definition for this like TimestampQuery.COMPUTE
?
@RenaudRohlinger Do you now why I am getting this warning in some examples like
|
It's because trackTimestamp is being used but we need await renderer.computeAsync( computeParticles );
renderer.resolveTimestampsAsync( THREE.TimestampQuery.COMPUTE );
await renderer.renderAsync( scene, camera );
renderer.resolveTimestampsAsync( THREE.TimestampQuery.RENDER ); |
Maybe we could improve the log: Maximum number of queries exceeded, renderer.resolveTimestampsAsync is probably missing.
or:
Maximum number of queries exceeded,
when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync. |
"three": "../build/three.webgpu.js", | ||
"three/webgpu": "../build/three.webgpu.js", | ||
"three": "../src/Three.WebGPU.js", | ||
"three/webgpu": "../src/Three.WebGPU.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These break in gh-pages
:
https://threejs.org/examples/?q=snow#webgpu_compute_particles_snow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Refactor of timestamp and timer query handling in WebGPU/WebGL for the WebGPURenderer.
It is now more stable and performant through the use of TimestampQueryPool, which maintains a single querySet per type (render/compute) and global buffers. This resolves multiple errors and limitations that users have previously reported.
The API now supports multiple render passes (postprocessing) through a new
resolveTimestampsAsync
method in theRenderer
, which resolves all timestamps appended in the loop from different render/compute calls.Another significant improvement addresses a previous limitation by separating compute and render contexts. Compute operations can now be monitored independently of render calls, as they are often isolated for tasks such as simulations and other complex calculations (with the exception of
material.geometryNode
).Example of the new API:
While testing the tool I took the opportunity to improve one of the main example that seems to be affected by excessive buffer access within the loop, resolved by using const and vars:
Before (in WebGPU velocity affects performances 8/9ms per compute):
After quick optimization tests (velocity compute program speed up by ~50%):
If that's ok this refactor will introduce breaking changes. Rather than attempting to maintain backwards compatibility, which would significantly pollute the codebase, I will document the necessary updates in the migration guide for affected components.
This contribution is funded by Utsubo