Expand description
GPU.5 — multi-grid scene upload + shared storage layout.
Concatenates every chunk of every grid into one set of storage
buffers + a per-grid offsets table. Each grid keeps its own
vsid, chunks_dims, origin_chunk, and runtime transform;
the shader iterates grids 0..grid_count, transforms the world
camera into each grid’s local frame, runs that grid’s outer-DDA
over chunks, and tracks the closest hit across all grids.
Why concatenate rather than one bind group per grid? wgpu’s
MAX_BIND_GROUPS default is 4; demos with 10+ grids
(roxlap-scene-demo has ground + ship + 10 marker pillars =
12) need a single bind-group layout that scales.
Structs§
- GpuScene
Resident - GPU-resident storage for an entire scene’s grids.
- Grid
Runtime Transform - Per-grid runtime transform — voxlap-style (world → grid-local).
rotationis column-major and encodes the inverse rotation applied to the world camera basis before passing it to that grid’s marcher. Identity for the ground; non-trivial for the rotating ship. - Grid
Static Meta - Per-grid static metadata: offsets into the concatenated storage buffers + the grid’s slot-pool dimensions. Uploaded once.
- MipLayout
- GPU.11 — per-slot occupancy/color-offset strides + per-mip
within-slot relative offsets for a grid of side
vsid. All chunks of a grid share these (uniform mip count bygpu_mip_count).colorskeep their fixedCOLORS_PER_CHUNK_WORDSstride; each mip’s colours are concatenated within that block and indexed by the chunk’s own (absolute)color_offsets. - Scene
Upload - CPU-side aggregation of every grid in a scene. Built once at
startup; per-grid transforms are recomputed each frame and
passed to
render_sceneseparately.
Enums§
- Refresh
Outcome - Outcome of
GpuSceneResident::refresh_chunk. Most callers can ignore the result;ColorsTruncatedindicates the chunk’s colour data overflowed the per-slot stride and was clipped.
Constants§
- COLORS_
PER_ CHUNK_ WORDS - Per-chunk colour-slot stride, in u32 words (256 KiB). Each
chunk’s colour data lives at
meta_idx * COLORS_PER_CHUNK_WORDSwithin its grid’s colours range. Fixed-stride layout means every slot — present or absent at upload time — has the same capacity, soGpuSceneResident::refresh_chunkcan always write new colour data into the slot when a chunk arrives via streaming or is re-baked. - MAX_
GPU_ MIPS - GPU.11 — max mip levels the per-slot layout reserves room for in
GridStaticMeta’s relative-offset tables. Matchescrate::decompress::GPU_MAX_MIPS; the shader’sarray<u32, N>must use the same N. - MAX_
OCC_ PAGES - Number of separate storage bindings the concatenated occupancy
buffer is split (“paged”) across. A single storage binding may
not exceed the device’s
max_storage_buffer_binding_size— on strict drivers that’s a hard 128 MiB (lavapipe), which the streaming demo’s occupancy already reaches. Splitting into pages keeps every binding under the limit while preserving a single global word index in the shader (each page is a whole number of chunk slots, so no slot ever straddles a page boundary). - MAX_
SCENE_ GRIDS - Maximum number of grids the shader’s per-grid camera uniform array can hold. The scene-demo has 12 (1 ground + 1 ship + 10 markers); 16 leaves headroom for a future +4 without re-cooking the shader. The runtime check rejects scenes that overflow.
- SLOT_
EMPTY_ SENTINEL - Sentinel chunk_idx written into empty slot_chunk_idx entries.
Real chunk indices never use
i32::MIN, so the shader can distinguish empty slots from collisions via a single equality check.
Functions§
- modular_
slot_ idx - Modular slot index for
chunk_idxgiven the grid’s power-of-2pool_dims. Negativechunk_idxcomponents map via two’s-complement bitwise AND, matching the shader’schunk_idx & (pool_dims - 1).