AnthonyTornetta / bevy_easy_compute

App compute plugin for Bevy
21 stars 4 forks source link

Using a channel to get data from Render World #7

Open tombh opened 3 months ago

tombh commented 3 months ago

So this repo is a fork of https://github.com/Kjolnyr/bevy_app_compute, with an emphasis on "app", which I assume refers to the fact that the code works entirely in App World? I wonder if the original code was written before the gpu_readback.rs example existed in the Bevy repo? Because that example suggests using a crossbeam channel to send data back from the Render World into the App world.

I mention it because I suspect that might be a better overall solution. It would mean that pipeline_cache.rs could be removed and also I think the dependencies on wgpu and naga.

The only issue I can see with using the channel readback approach is that it could make it harder to support the asynchronous workloads feature this crate has. But I wonder if that could be supported by Bevy's Async Compute?

AnthonyTornetta commented 3 months ago

The gpu_readback.rs file (as the note at the top suggests) is very evil. Replacing that would definitely improve the maintainability of this crate. I looked at the example you linked, and it does look very promising! Supporting async would involve a bit more work, but it looks pretty doable through swapping https://github.com/bevyengine/bevy/blob/main/examples/shader/gpu_readback.rs#L246 to use a polling approach (https://docs.rs/wgpu/latest/wgpu/type.Maintain.html).

This will require some more research on my part to see how viable this would be, but I'll look into it! I'll keep this issue opened and update it with any future findings. Thanks!

tombh commented 3 months ago

Great, I'm glad it looks promising. I'm still quite new to Bevy so you're probably better placed to look into it than me, but still let me know if you do start working on it because I'd be curios to try too. Though it's not a high priority if everything else is working.