Expand description
GPU asset-cache eviction — budgeted reclamation of orphaned GPU resources.
The CPU→GPU projection (ProjectionRegistry)
is insert-only: it uploads a GpuMesh / GpuMaterial the first time an
entity needs one, tags the entity, and never revisits it. Despawning an
entity, or editing a material inline (which mints a fresh asset UUID),
therefore leaves the old cache entry — and the wgpu buffers, textures,
views and bind group it owns — alive forever. AssetHandle is a plain
Arc: dropping the last clone frees the struct, but its fields are
Copy id handles into backend slotmaps that only an explicit destroy_*
releases. So the cache grew without bound.
AssetEviction is the Data-layer self-maintenance that closes the leak,
the GPU-asset twin of EcsMaintenance. Each
frame, in TickPhase::Maintenance, it
diffs the cached UUID set against the set still referenced by live entities
and, under a per-frame budget, removes the orphans and destroys their GPU
resources. It only ever removes entries no live entity references, so it
changes representation, never game semantics (adapt the HOW, not the WHAT).
Maintenance runs at the end of the tick, after the render descent has read the caches for this frame, so freeing an orphan is safe: nothing projects a despawned entity next frame, and the ECS query already skips orphan rows so a not-yet-compacted despawned row never keeps a UUID artificially live.
Structs§
- Asset
Eviction - Direct GPU asset-cache maintenance service.