Skip to main content

Module grid

Module grid 

Source
Expand description

GPU.4 — grid-of-chunks upload + storage layout.

Concatenates every chunk of one roxlap-scene::Grid into a few flat storage buffers so a single compute dispatch can outer-DDA through chunk-space + inner-DDA into any chunk it hits.

Memory layout (post-bedrock-strip):

  • occupancy[meta_idx] — one chunk’s 128 KiB occupancy slice starts at meta_idx * vsid² * OCC_WORDS_PER_COLUMN u32 words. Uniform per chunk (all chunks are vsid² × CHUNK_Z voxels).
  • color_offsets[meta_idx] — one chunk’s vsid² + 1 u32 offsets start at meta_idx * (vsid² + 1) u32 words. Uniform per chunk.
  • colors — variable per chunk. Per-chunk base index lives in chunk_colors_base[meta_idx].
  • chunk_occupancy — 1 bit per chunk position. Bit at meta_idx set iff that chunk has any textured voxels. The outer DDA uses this to skip empty chunks in one step.

The meta_idx for a chunk at (chx, chy, chz) is its row-major offset within the grid’s chunks_dims bounding box:

rel = chunk_idx - origin_chunk
meta_idx = rel.x + rel.y * chunks_dims.x + rel.z * chunks_dims.x * chunks_dims.y

Structs§

GpuGridResident
GPU-resident storage for one grid’s chunks. Lives until the host drops it; in GPU.6 (edit invalidation) we’ll re-upload individual chunks via partial buffer writes.
GridUpload
CPU-side aggregation of a grid’s chunks ready to upload. Host (e.g. roxlap-scene-demo) builds this by iterating its roxlap-scene::Grid and calling crate::decompress_chunk per materialised chunk.

Constants§

GRID_CHUNK_Z
Z-extent of every chunk — re-export of the CHUNK_Z constant so hosts can budget without pulling crate::decompress in.

Functions§

bounding_box_of
Compute the smallest bounding box that contains every (chunk_idx, _) in chunks. Returns None if chunks is empty.
ceil_pow2
Round n up to the nearest power of 2. 0 and 1 both return 1. Used to derive a GPU.7 GridUpload::pool_dims from a non-pow2 chunks_dims.
occ_words_per_chunk
Number of u32 words a single chunk’s per-chunk occupancy slice occupies in the concatenated grid occupancy buffer. Useful for host-side memory budgeting.