bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.09k stars 3.56k forks source link

Implement better compute support #2638

Open Dimev opened 3 years ago

Dimev commented 3 years ago

What problem does this solve or what need does it fill?

I'm working on adding voxel cone tracing, which requires meshes to be processed with a compute shader. Right now, some of the compute bindings from wgpu are still missing, and things like Draw don't work with compute passes

What solution would you like?

Something similar to how the Draw logic currently works, but in a way that allows compute shaders as well, by either allowing it to have both Compute and Render passes, or making a seperate system that works for compute.

What alternative(s) have you considered?

None yet, besides implementing this myself, but I'll need help with understanding how the draw system works in more detail first.

Additional context

I've already made a pr for adding some of the missing wgpu exports for compute in #2628, but not much more. I'm also working on the voxel cone tracing here: https://github.com/Dimev/bevy-vxgi, but I have no clue how correct this is due to not knowing much about the rendering system (yet)

StarArawn commented 3 years ago

and things like Draw don't work with compute passes

I'm a little confused because compute passes can't draw things to the screen its not possible. Ideally compute runs before any draw nodes.

Example:

  1. Dispatch Compute Node to calculate mesh
  2. Pass mesh to standard bevy or custom Draw pipeline.
Dimev commented 3 years ago

hmm Effectively I need to run a compute shader for all meshes that are drawn, then write to a shared texture, so having some ways to process things with compute in a draw pipeline would be handy

StarArawn commented 3 years ago

hmm Effectively I need to run a compute shader for all meshes that are drawn, then write to a shared texture, so having some ways to process things with compute in a draw pipeline would be handy

I'm not really sure how VCT works in terms of vowelizing meshes, but if I had to guess you would pass a list of mesh buffers to the compute shader along with a list of game entities and transforms.

Dimev commented 3 years ago

yeah, I'd have to run the compute shader per mesh, then run another after that is done again, which I still have no idea of how that would work