bevy
bevy copied to clipboard
Directly upload assets that are only meant to be used on the GPU
What problem does this solve or what need does it fill?
Currently meshes and textures that don't need modification on the CPU (RenderAssetUsages == RENDER_WORLD) still need to be decoded to a CPU format, extracted, then unloaded. This incurs a system RAM cost, can be slow, and blocks the main world during extracted asset loads.
It'd be ideal if these assets would directly upload to the GPU as a part of the asset load, preferably on a thread that doesn't block the main world.
What solution would you like?
- Use a
static OnceLock<Queue>andstatic OnceLock<Device>to provide easy access to wgpu resources inImageandMeshasset loaders. - Check if the RenderAssetUsages requires main world access.
- If it's only supposed to be used in the render world, allocate a buffer.
- Obtain a staging buffer via
Queue::write_buffer_with. - Pipe
std::io::Readresults into the provided buffer (with the appropriate decoding).
This should also make it easier in future cases where we may need to support DirectStorage/Resizable BAR uploads of assets.
This is a bit hacky, and relying on globals in the form of static OnceLock-ed variables, but may be reasonable until wgpu supports multiple queues.
What alternative(s) have you considered?
Continue with blocking extractions and copies.
Additional context
Related: https://github.com/gfx-rs/wgpu/issues/3698