Expand description
Gradient colour-ramp (LUT) cache.
A gradient is drawn by sampling a pre-baked colour ramp. Baking a ramp is
expensive relative to a frame, and the same gradient typically recurs across
frames (a themed button, a scrim), so ramps are cached by the colour-affecting
properties of the gradient — its stops, interpolation colour space and hue
direction — which is exactly what GradientCacheKey captures. Geometry
(start/end points, radii, angles) does not affect the ramp and is therefore
deliberately absent from the key: two gradients that differ only in placement
share one ramp.
Every cached ramp lives in one packed Rgba8Unorm byte buffer that is uploaded
to a single texture as a flat texel stream. A cached ramp is addressed by a
texel offset plus a width, so the buffer must stay contiguous: eviction
therefore compacts the buffer and rewrites the offsets of the survivors.
Residency is bounded by GradientCache::capacity and reclaimed LRU by frame
epoch. The epoch advances on every lookup, so each live entry carries a
distinct last-used value and the eviction threshold is unambiguous.
Structs§
- Cached
Ramp - Where one cached gradient ramp lives in the packed LUT buffer.
- Gradient
Cache - An LRU cache of baked gradient colour ramps packed into one upload buffer.
- Gradient
Texture Layout - Geometry of the single texture the packed gradient LUTs are uploaded into.
- LutUpload
- The packed LUT bytes padded to a texture’s footprint for one upload.
Constants§
- BYTES_
PER_ TEXEL - Bytes per texel of the gradient LUT texture (
Rgba8Unorm).