bevyengine / bevyengine/bevy

Directly upload assets that are only meant to be used on the GPU

Open
#12,856 0 comments 0 reactions 1 assignee Claimed by @JMS55 View on GitHub
A-Assets A-Rendering C-Performance
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## 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` and `static OnceLock` to provide easy access to wgpu resources in `Image` and `Mesh` asset 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::Read` results 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.