Skip to content

TSL: Introduce computeKernel()#31402

Merged
sunag merged 18 commits into
mrdoob:devfrom
Spiri0:workgroups_and_dispatch_extension
Jul 18, 2025
Merged

TSL: Introduce computeKernel()#31402
sunag merged 18 commits into
mrdoob:devfrom
Spiri0:workgroups_and_dispatch_extension

Conversation

@Spiri0

@Spiri0 Spiri0 commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

Related issue: #31393

So far, the workgroup for the compute shader consists of a scalar and the dispatchSize always uses dispatch.x up to device.limits.maxComputeWorkgroupsPerDimension before dispatch.y is used. The default workgroup is now [ 64, 1, 1 ] instead of [ 64 ]. This ensures that all previous examples are treated as before.

Example on webgpu_compute_particles_rain, usual usage:

computeParticles = computeUpdate().compute( maxParticleCount );
renderer.compute( computeParticles );

Use with workgroup and dispatchSize

computeParticles = computeUpdate().computeKernel( [ 16, 16, 1 ] );
renderer.compute( computeParticles, [ 10, 10, 1 ] );

Since the instanceCount in the example is 25,000, workgroup = [ 16, 16, 1 ] and dispatchSize = [ 10, 10, 1 ] = 16 * 10 * 16 * 10 * 1 = 25,600 threads, enough to cover everything. If you choose smaller values for dispatchSize, e.g., [ 9, 9, 1 ], you would see that not all raindrops are computed.

You now have full control over the thread distribution for the GPU, which was not possible.
I'm setting the PR to draft for now, even though it works, because I might think of a few more things I'd like to add. Maybe warnings if you enter something incorrectly.

@github-actions

github-actions Bot commented Jul 13, 2025

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.02
78.86
338.02
78.86
+0 B
+0 B
WebGPU 557.93
154.37
558.57
154.64
+642 B
+273 B
WebGPU Nodes 556.85
154.17
557.49
154.43
+642 B
+261 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 469.28
113.56
469.28
113.56
+0 B
+0 B
WebGPU 633.23
171.4
633.86
171.67
+631 B
+271 B
WebGPU Nodes 588.37
160.71
589
160.99
+631 B
+280 B

@Spiri0 Spiri0 marked this pull request as draft July 13, 2025 07:10
@Spiri0 Spiri0 force-pushed the workgroups_and_dispatch_extension branch from 73116e1 to 910ce62 Compare July 13, 2025 09:38
@Spiri0 Spiri0 marked this pull request as ready for review July 13, 2025 10:03
Comment thread src/renderers/common/Renderer.js
Comment thread src/renderers/common/Renderer.js
Attila Schroeder added 2 commits July 14, 2025 03:27
Comment thread src/nodes/gpgpu/ComputeNode.js Outdated
Comment thread src/renderers/webgpu/WebGPUBackend.js Outdated
Comment thread src/renderers/webgpu/nodes/WGSLNodeBuilder.js Outdated
Comment thread src/renderers/common/Renderer.js Outdated
@sunag sunag changed the title Introduction of parameterizable workgroups for compute shaders and dispatch sizes for the renderer TSL: Introduce computeKernel() Jul 18, 2025
@sunag sunag merged commit f3769eb into mrdoob:dev Jul 18, 2025
9 checks passed
@sunag sunag added this to the r179 milestone Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants