Skip to main content

Module mips

Module mips 

Source
Expand description

Mip-chain generation for 3D-transformed layers’ capture textures.

A transformed composite quad minifies its capture (tilt compresses many texels per pixel); bilinear-only sampling shimmers. Layers with the TRANSFORM3D promotion reason therefore allocate their sampled texture with a full mip chain ([super::alloc_layer_slot] / [super::alloc_filter_slot], keyed on the reason so identity↔non-identity value changes never realloc), and this module rebuilds the chain exactly when level 0 is rewritten — a cached capture keeps its mips for free.

The lifecycle mirrors the filter machinery: prepare_layer_mips stages one MipRun per dirty chain (pipeline + per-level bind groups/targets — the capture pass can create no GPU resources), ui_layer_capture_pass replays it right after the layer’s capture/filter passes, and the composite samples through the trilinear/anisotropic sampler only while the slot’s mips_valid holds (the fallback is plain bilinear over level 0 — never a gate, never a stale mip). For filtered layers the chain builds on the filter output ping-pong (what the quad actually samples), not the raw capture.

Each downsample level is one fullscreen-triangle pass (mip_blit.wgsl) sampling level i into level i + 1: linear filtering into a half-size target is a standard 2×2 box downsample, correct on premultiplied content.

Structs§

LayerBlitPipeline
The downsample-blit pipeline: one texture + sampler bind group, no uniforms (deliberately not the filter layout — that mandates the 160-byte FilterUniforms via min_binding_size).
LayerBlitPipelineKey
LayerMipMeta
Per-frame mip staging, index-aligned with ExtractedUiLayers::layers. runs[idx] = None = no downsample work (unmipped layer, cache hit, source not ready, or pipeline still compiling — the composite then falls back to bilinear over level 0 via the slot’s mips_valid).
MipChain
The per-texture mip-chain views a mipped slot carries. Built at alloc time (the capture pass creates no views); the blit source bind groups are filled lazily at first staging (they need the pipeline’s layout) and die with the slot on realloc.
MipLevel
One staged downsample pass: bind bind_group (source level), render 3 vertices into target (the next level).
MipRun
A layer’s staged downsample chain this frame.

Functions§

build_mip_chain
Build the per-level + full views for a texture allocated with mip_level_count levels.
init_layer_blit_pipeline
mip_level_count
Mip levels for a texture of size — the full chain down to 1×1.
prepare_layer_mips
Stage the downsample chain for every wants_mips layer whose sampled texture’s mips are stale. Predictive like the filter staging: mips_valid flips true only when the staged run is certain to execute this frame (source complete + blit pipeline compiled); until then the composite’s bilinear fallback covers.