-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
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 |
compute
Adds a new lifecycle function that can be used to dispatch a compute pass before
view
is calledThere's a bit more boilerplate than usual to implement:
The idea here is that the
Compute
trait helps define a state machine driven byCompute::State
. This of course can only be a single state, but is helpful for the typicalinit
->update
lifecycle seen in things like particle systems.We also introduce a new concept
ComputeModel
which is used to populate the uniform passed to the compute shader. This must implementAsBindGroup
and 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:
Instanced
causes the supplied primitive to be rendered over the provided instance range allowing access toinstance_index
in 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.
Indirect
allows 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