Seeking Guidance: GPU Particle Updates via wgpu Targeting WebGL (Compute Shader Alternative) #7601
Unanswered
lucascompython
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I cannot advise you on the best way to achieve functionality like transform feedback, but I do have a suggestion to improve one of your alternatives, Render-to-Texture: you can store more data by shaping your data into a 2D rectangle (wrapping to the next row at an arbitrary point ≤ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
Firstly, I'd like to say that I'm new to wgpu and graphics programming in general, so I might have got some things wrong!
I'm working on a particle simulation project using and
wgpu
. I want to have simulation backends: CPU, Compute Shaders (for native/WebGPU), and a WebGL-compatible GPU method. I already implemented the CPU and Compute Shaders simulation backends.In native OpenGL development, this problem is often solved efficiently using Transform Feedback. A vertex shader performs the physics calculations for each particle, and its outputs (new position, velocity, etc.) are directly captured into an output buffer before rasterization, using API calls like
glTransformFeedbackVaryings
,glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, ...)
, andglBegin/EndTransformFeedback
.Here is an example of C++ code using this technique, which achieves the desired GPU-driven update on WebGL (via Emscripten targeting WebGL directly):
https://github.com/Im-Rises/particle-simulator-webgl/blob/main/ParticleSimulator/Scene/Entity/ParticleSimulatorTF/ParticleSimulatorTF.cpp
Attempts with
wgpu
Targeting WebGL:I've explored several approaches using
wgpu
to achieve a similar outcome (GPU-driven updates without Compute Shaders) when targeting WebGL, but encountered limitations:var<storage, read_write>
in the fragment shader to write results back. This fails because neitherFeatures::FRAGMENT_WRITABLE_STORAGE
norFeatures::VERTEX_WRITABLE_STORAGE
are available on the WebGL backend.Limits::max_texture_dimension_2d
issues when the particle count is high, as the texture width would need to match the particle count. It also requires complex texture-to-buffer copies.wgpu
doesn't seem to provide a mechanism to automatically capture these vertex shader outputs into a buffer like OpenGL TF does. Subsequentcopy_buffer_to_buffer
calls only copy the original data, as the destination buffer is never updated with the calculated results.What is the recommended or idiomatic
wgpu
pattern that could help me achieve GPU-accelerated per-particle updates?Is there an existing
wgpu
feature, technique, or combination thereof that allows capturing or writing back the results of vertex-shader-like computations to a buffer when the WebGL backend is used? Or is this specific type of GPU compute pattern currently infeasible throughwgpu
when targeting WebGL?Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions