Repository navigation
Add compute app function for running compute shaders - #976
Conversation
ac65416 to
1db0e1e
Compare
|
Wow, I just got put onto this from This Week In Bevy. The API is so good 🥹 It can't be used independently as a plugin in Bevy right? The most similar project I know of is https://github.com/AnthonyTornetta/bevy_easy_compute, but it has a couple of hacks at the moment. Did you get inspiration from somewhere or is this all completely made from scratch? |
|
Thanks for checking it out!
Although this PR is built as a Bevy plugin, it's not currently exposed in a way that would be convenient, but it is definitely a goal! Perhaps this is a prod that I need to refactor it a bit. :) I'm also personally interested in continuing to improve compute infrastructure in Bevy itself. Although our refactoring work still isn't totally mature, our goal is to be interoperable with Bevy.
This is all from scratch! |
|
Sure, no pressure! I'm getting by fine with that |
computeAdds a new lifecycle function that can be used to dispatch a compute pass before
viewis calledThere's a bit more boilerplate than usual to implement:
The idea here is that the
Computetrait helps define a state machine driven byCompute::State. This of course can only be a single state, but is helpful for the typicalinit->updatelifecycle seen in things like particle systems.We also introduce a new concept
ComputeModelwhich is used to populate the uniform passed to the compute shader. This must implementAsBindGroupand the associated Bevy traits necessary to generate a bind group.Draw commands
Additionally, two new draw commands have been added that are very useful for writing compute shaders:
Instancedcauses the supplied primitive to be rendered over the provided instance range allowing access toinstance_indexin the vertex shader:Typically, for performance reasons we render all primitives that share a material into a single mesh. However, this has the downside of resulting in a single draw call with one instance per mesh. Using explicit instancing helps avoid this.
Indirectallows the user to supply a Ssbo handle that can be supplied with draw arguments from a compute shader:This is an advanced technique, but allows eliminating almost all CPU overhead, uploading only the vertex and index buffer for a single mesh each frame. In the future we can support building the vertex buffer in the GPU or techniques like vertex pulling as well.
See the examples for more details:
game_of_life.mp4
particles.mp4
indirect_particles.mp4