-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
WebGPU compute shader support prototype. #20390
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
Conversation
|
This looks very nice! I think you can mark it as "Ready for review". I vote to merge this so there is a showcase for compute shaders. |
8c78079 to
ce320b1
Compare
|
Thanks. I switched to "ready for review". BTW, can we switch point color from red to white? |
ce320b1 to
0ed5756
Compare
|
Note that it might not be super useful to have multiple |
|
At the current state of the renderer, resources like pipelines and bind groups are not yet shared across objects. We've planned to refactor this part when the initial version of the new node-based material system is integrated.
I'm not sure I understand this bit, sorry. Does the current implementation not already do this? |
Whoops, that wasn't very clear, basically you probably don't need more than one bindgroup per compute shader (since multiple bindgroups is used to optimize high-throughput cases), so The API as it is now looks great too, so if this is confusing feel free to ignore my comment. |
|
How about starting with this implementation for now and try your suggestion with an additional PR? I think it would be useful to investigate your approach in order to find out which one works better. In general, myself and potentially other devs understand a suggestion easier when seeing the concrete code changes. Especially since compute shaders and WebGPU in general are new topics for me (and the project)^^. |
|
Indeed, I should have showed some code, and now that I tried to do it, I just realized my suggestion was non-sensical. Apologies for the noise. |
|
No problem. Your support here is highly appreciated 😊. |
|
Thanks for the comment.
I hope we keep investigation and discussion especially when we refactor and optimize webgpu renderer with node based material system or interleaved buffer attribute. |
|
Some thoughts about this PR.
|
This seems to hint that you think a single buffer is allowed per bindgroup. The goal of bindgroups is to batch multiple resource updates together so actually you are encouraged to put multiple buffers (and textures and samplers) per bindgroup.
Makes sense to hide such implementation details from the user. |
|
Sorry, I noticed that seems like I had mistaken bindgroup for bindgroup entry in #20390 (comment). Currently webgpu renderer supports only single bind group per a pipeline regardless rendering or computing, and it can put multiple buffers per single bindgroup. |
This draft PR adds initial Compute shader support. I'm not sure if you want to add now (because you might like to wait for node material or WGSL, or might think we should focus on basic rendering features) so I made this PR as draft so far.
Even if we go with this PR, I think there is big room for further simplifying, robustness, and flexibility, so feedback is very welcome.
Similar to #20319, I'm happy if this suggestion helps improve webgpu renderer design and/or we partially adopt some codes even if we decide not to support compute shader yet.
Live demo
https://raw.githack.com/takahirox/three.js/ComputeShader/examples/#webgpu_compute
I recommend to run in small window because point size is one pixel and hard to see.
API and example
I add
WebGPURenderer.compute()which takes an array of object havingAnd I add
WebGPUStorageBuffercorresponding tobufferin shader which can be input/output of compute shader. It takes Three.js attribute and webgpu buffer is created for it in renderer. So, if you add the attribute to geometry you can use computed data for rendering.Currently you need to write raw shader code and manually create bindings but I expect we use node based material system even for compute shader and node builder will build the shader and bindings if node based material system lands.
This is an example computing particle positions in compute shader and then rendering them as Points.
See
webgpu_compute.htmlfor more detail.Changes and notes
WebGPURenderer
.compute()toWebGPURendererrather than making new class likeWebGPUComputerbecause I want computed data to be abled to be used for rendering by sharing WebGPU resources.WebGPUComputePipelines (new)
WebGPUComputePipelineswould be simpler than adding compute pipelines management toWebGPURenderPipelines. (And I guess it's expected so named asWebGPU"Render"Pipelines.).WebGPUStorageBuffer (new)
bufferin the shader.WebGPUBindings
getForCompute(). It would be simpler than letting the existingget()handle bindings for compute.WebGPUStorageBuffersupport.WebGPUStorageBufferwhich can be reused for rendering so it has dependency withWebGPUAttributesnow.WebGPUAttributes
update()takes the new third argumentcustomUsagebecause webgpu buffer for outputting in compute shader needsGPUBufferUsage.STORAGE. It saves and checks usage of buffer. If new usage buffer for a certain attribute is requested it destroys the existing buffer and creates a new one. (I'm not sure if this design is good tho...)webgpu_compute