Improve control over initialization of render plugin
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
At the moment, initialization of the render plugin focuses on the most common use case, i.e. writing a standalone game / app. There are some use cases though, where the author wants to have more control over initialization of hardware resources. This might be the case for:
* Writing tests (minimal hardware access desired)
* An editor (should share hardware resources / control the apps use of resources)
* Embedding games into other applications
* Machine learning, bots, ...
## What solution would you like?
Enable the user to create `Render(Device|Queue|Adapter|Instance|...)` themselves. An example how this could be implemented without adding complexity to the API is like in the asset plugin
https://github.com/bevyengine/bevy/blob/92ba6224b9b66eb779683603e7022e421511dfe5/crates/bevy_asset/src/lib.rs#L111-L115
I.e. the plugin should check if the resources it is creating are already present in the app's `World` and use them if they exist.
## What alternative(s) have you considered?
The use cases I mentioned should also be fine with running the app headless in another process and adding some kind of inter-process communication, but this would require modifying the game's code and be inefficient and more complex.
## More Context
All render resources besides `RenderInstance` are wrapped in an `Arc` and thus can be easily shared. `RenderInstance` is not linked to any hardware resources. It's just the entry point to wgpu. A new `RenderInstance` can easily be created. We should just make sure that it uses the same backend as the `RenderAdapter` which can be found in `RenderAdapterInfo`.
Contributor guide
Assessment
This issue has not been assessed yet.