bevyengine / bevyengine/bevy

RenderAssets indirectly owning GPU Resources.

Open
#24,204 1 comment 0 reactions 0 assignees View on GitHub
A-Assets A-Rendering C-Code-Quality C-Performance D-Complex S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

My understanding of the RenderAsset trait is that it owns GPU resources. However multiple implimentations... mainly `MeshAllocator` use a interesting system of indirection. Instead of MeshAllocator giving handles that can be used to access the buffer they internally map AssetIds to resources. If we give out handles instead of mapping on the key of the associated resource a two things will happen

1. It will probably be faster because the handles can point into a generationed vector instead of a hashmap with hashing and collision overhead.
2. Ownership of resources will be clearer. EX. Inside the RenderMesh there will clearly exist ownership of a handle to the MeshAllocator VS the only proof that RenderMesh owns vertex data being in mesh_allocator.rs

Also currently the `RenderAsset::unload_asset`, which I would use to manually free claimed resources, would need to change from being called "whenever SourceAsset is removed from the MainWorld" => "Whenever this Asset is Dropped" (Aka Source Removed OR Changed/Reprepared). This would allow us to reclaim resources in that step. Also we would need to pass self or &self into the function so it can use the handles to reclaim resources.

Contributor guide

Open the contributing guide

Research direction

Start by reading the RenderAsset trait and the MeshAllocator implementation in mesh_allocator.rs, then trace how RenderMesh stores and accesses mesh resources. Review the unload_asset lifecycle, including what happens when a SourceAsset is removed, changed, or reprepared. Done means the ownership and resource-reclamation design is agreed and consistently represented across these entry points.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.