Expand description
Render-layer cache for GPU-backed subtree caching.
LayerCache manages a pool of RenderTargets keyed by a caller-provided
u64 layer_id. When a widget subtree is rendered, its output is saved to
a RenderTarget; subsequent frames can composite the cached layer texture
directly without replaying the full draw list, as long as the layer hasn’t
been invalidated.
§Invalidation model
- Each layer has a generation counter. The caller bumps the generation (via
LayerCache::invalidate) when the subtree’s content changes. - Layers that haven’t been accessed for
max_idle_framesframes are evicted to reclaim GPU memory.
§Usage
ⓘ
let mut cache = LayerCache::new(16); // keep up to 16 layers
cache.begin_frame();
let layer_id = widget.stable_id();
if let Some(target) = cache.get(layer_id) {
if !target.is_dirty() {
// composite cached layer texture into the parent pass
composite_layer(target.texture_view(), ...);
return;
}
}
// Layer is dirty or absent — render the subtree into it.
let target = cache.get_or_create(device, layer_id, width, height, 1)?;
render_subtree_into(target, ...);
target.mark_clean();Structs§
- Layer
Cache - A pool of off-screen render targets, keyed by
layer_id: u64.