Expand description
CPU → GPU packing of chunk descriptors for the Phase 2 chunked quadtree (CEL-62).
ChunkGpu must match struct ChunkGpu in shaders/ChunkRealize.slang
byte for byte (std430: 96 bytes, 16-byte aligned due to [f32;4] members).
The size invariant is locked by the chunk_gpu_layout_is_96_bytes test.
§Instance buffer layout (Godot 3D MultiMesh + custom data)
Each instance is 16 f32 values (64 bytes) in Godot’s TRANSFORM_3D + custom_data format:
- Floats 0–11: 3×4 transform matrix (3 rows of 4 floats; identity → vertex shader positions geometry from the vertex-pool texture, not from the instance transform)
- Float 12 (
INSTANCE_CUSTOM.r): slot index asf32; the shader reads this to index into the per-face vertex pool - Float 13 (
INSTANCE_CUSTOM.g): per-chunk geomorph factor (Phase 5):1= full detail,0= coarse/parent resolution. The surface vertex shader blends the realized grid toward its even (parent) sublattice by this factor. It rides in the per-frame instance buffer (NOT the cached realize descriptor / atlas), so a moving camera only re-uploads this small buffer — the realize/bake passes stay fully cached. - Floats 14–15: zero (reserved custom channels b/a)
Structs§
- Chunk
Gpu - One chunk’s GPU descriptor (std430, 96 bytes).
- Chunk
Params - Realize-batch parameters + embedded terrain, byte-identical to
struct ChunkParamsinshaders/ChunkRealize.slang/ChunkTileBake.slang(binding 1).
Functions§
- interior_
verts_ per_ chunk - Interior vertex count for one chunk at resolution
res. - pack_
chunks - Pack all visible chunks into a contiguous
ChunkGpubyte buffer (one entry per chunk). - pack_
instances - Pack per-instance data for the chunk MultiMesh into a byte buffer.
- pack_
params - Pack one
ChunkParams(header + terrain + tile_res + bump + surface) into its buffer.surface_enabled/surface_height_scaledrive the CPU-surface path (pass0.0, 0.0when the CPU surface is irrelevant). - per_
slot_ bytes - VRAM one resident chunk slot reserves across ALL the GPU pools:
geometry
verts_per_chunk(res) × 48 B(pos_tex rgba32f 16 + verts_tex 2×rgba16f 16 + verts_buf float4 16), the colour + normal detail atlases (tile_res² × 8 B), and the CPU-surface colour + height + normal storage buffers (tile_res² × 12 B— allocated unconditionally byChunkGpu::ensure). The VRAM budget divides by this; forgetting the surface buffers (the old accounting) made the real allocation ~2× the configured budget at largetile_res. - skirt_
verts_ per_ chunk - Number of skirt vertices appended after the interior grid (Phase 3): one
ring vertex per edge position on each of the 3 edges (corners duplicated per
edge so each edge owns its own skirt ring),
3*(res+1). - verts_
per_ chunk - Total vertex count for one chunk at resolution
res= interior grid + perimeter skirt (Phase 3 crack fix). This is the per-slot stride of the vertex pool, theverts_tex/pos_texsizing unit, and the realize dispatch count. The interior block (L < interior_verts_per_chunk(res)) is unchanged; skirt verts are appended atL >= interior_verts_per_chunk(res).