Closed tychedelia closed 2 months ago
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!
It can't be used independently as a plugin in Bevy right?
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.
Did you get inspiration from somewhere or is this all completely made from scratch?
This is all from scratch!
Sure, no pressure! I'm getting by fine with that bevy_easy_compute
plugin, I just think your approach is more idiomatic and up to date. So I'm going to study it nonetheless 🤓
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:
https://github.com/user-attachments/assets/9e4b9bfa-b691-4471-a2b9-72f6ddd96413
https://github.com/user-attachments/assets/8c474c0c-09f1-45b6-b203-bb59ec123661
https://github.com/user-attachments/assets/c7413190-54fc-4e67-99b4-35e738416277