Skip to content

Preparation for dispatchWorkgroupsIndirect #31026

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

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

Spiri0
Copy link
Contributor

@Spiri0 Spiri0 commented Apr 29, 2025

Related issue: #30982

This is the preparation for dispatchWorkgroupsIndirect

This allows an indirect buffer to be passed to the compute node, similar to the geometry. This indirect buffer has nothing to do with drawIndirect!
However, it is a very similar functionality to drawIndirect. This indirect buffer can be used to dynamically change the workgroup size with the GPU. This functionality can basically be used with any compute shader independent of drawIndirect.
In itself, the matter is quite simple, because the buffer simply needs to be passed to the passEncoderGPU, like this:

if ( indirect !== null ) {

	const buffer = this.get( indirect ).buffer;

	passEncoderGPU.dispatchWorkgroupsIndirect( buffer, 0 );

} else {

	passEncoderGPU.dispatchWorkgroups(
		dispatchSize.x,
		dispatchSize.y,
		dispatchSize.z
	);

}

However, I have not yet found the right place for the intermediate step in the compute routine that would actually retrieve the GPUBuffer with this.get( indirect )
But that would be all there is to it. Fortunately, this functionality is much less complex, since the most important part is already present with the IndirectStorageBufferAttribute.

Here's a pure webgpu example. You can see the application in the line: 180

https://codepen.io/Spiri0/pen/zxxdgYZ

The triangle is normally RGB colored. The compute shader executed with dispatchWorkgroupsIndirect makes it green

Copy link

github-actions bot commented Apr 29, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.33
78.33
336.33
78.33
+0 B
+0 B
WebGPU 547.85
151.9
547.95
151.92
+97 B
+22 B
WebGPU Nodes 547.2
151.74
547.3
151.76
+97 B
+21 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 466.09
112.57
466.09
112.57
+0 B
+0 B
WebGPU 623.04
168.7
623.14
168.72
+97 B
+18 B
WebGPU Nodes 577.91
158
578.01
158.02
+97 B
+21 B

@Spiri0 Spiri0 marked this pull request as draft April 29, 2025 02:11
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.

1 participant