Skip to content

Conversation

@cmhhelgeson
Copy link
Contributor

Related issue: #31488

Description

Updates webgpu_compute_particles_rain to use indirect compute functionality. Instead of always dispatching the maximum number of particles, we only dispatch enough workgroups to handle the number of rendered particles.

Currently, I'm updating the indirect buffer with a uniform, but let me know if there's a better method.

@github-actions
Copy link

github-actions bot commented Nov 2, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 355.14
86.33
355.14
86.33
+0 B
+0 B
WebGPU 609.53
170.95
609.53
170.95
+0 B
+0 B
WebGPU Nodes 608.14
170.68
608.14
170.68
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 486.76
121.07
486.76
121.07
+0 B
+0 B
WebGPU 678.47
186.28
678.47
186.28
+0 B
+0 B
WebGPU Nodes 620.46
169.54
620.46
169.54
+0 B
+0 B

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 2, 2025

This example used to work in Firefox since it worked with WebGL as well. This is not true anymore, the example now badly flickers.

I would prefer to keep some of the compute examples compatible for WebGL as well. A lot of them are already WebGPU exclusive.

…liant in both WebGLBackend and WebGPUBackend
@cmhhelgeson
Copy link
Contributor Author

This example used to work in Firefox since it worked with WebGL as well. This is not true anymore, the example now badly flickers.

I would prefer to keep some of the compute examples compatible for WebGL as well. A lot of them are already WebGPU exclusive.

Resolved by putting the count variable back and explaining why count still needs to be provided even when indirect compute is used.

@cmhhelgeson
Copy link
Contributor Author

cmhhelgeson commented Nov 2, 2025

Perhaps the WebGLBackend code should be modified to treat the compute call as if dispatchSize was set to null when an IndirectStorageBufferAttribute is passed in so it will look to the compuetNode.count instead rather than having to switch based on the backend in the front-facing code.

Nevermind the warning already accounts for this behavior. Perhaps the warning can be modified to indicate to the user that the code will default to the computeNode.count value.

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 3, 2025

IMO, it is not required to include IndirectStorageBufferAttribute since the concept of workgroups or grids is advanced and maybe too complicated for the average user. I would prefer if the majority of our compute samples (at least the ones that work with WebGL and WebGPU) are implement in the simplest possible way in order to keep the demos approachable. Otherwise I fear they get too complicated.

Edit: I'm okay with #32176 (since it's already WebGPU only) but I would leave the rain example as it is.

@cmhhelgeson
Copy link
Contributor Author

IMO, it is not required to include IndirectStorageBufferAttribute since the concept of workgroups or grids is advanced and maybe too complicated for the average user. I would prefer if the majority of our compute samples (at least the ones that work with WebGL and WebGPU) are implement in the simplest possible way in order to keep the demos approachable. Otherwise I fear they get too complicated.

Edit: I'm okay with #32176 (since it's already WebGPU only) but I would leave the rain example as it is.

Was just about to ask about fluid, so that's fine by me. Will close this PR.

@cmhhelgeson cmhhelgeson closed this Nov 3, 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.

2 participants