Skip to content

P1.4e: opt-in chunked scene copy data (past maxStorageBufferBindingSize) - #110

Open
DennisSmolek wants to merge 1 commit into
mainfrom
issue-51-chunked-scene-copy
Open

DennisSmolek wants to merge 1 commit into
mainfrom
issue-51-chunked-scene-copy

Conversation

@DennisSmolek

Copy link
Copy Markdown
Member

Part of #51 (P1.4e only; P1.4b / P1.5a are untouched).

What changed

Opt-in chunked scene copy data for scenes whose data is past maxStorageBufferBindingSize.

  • packing: 'split:KxN' | 'packed:KxN' (K chunks of 2^N words). The string carries the layout, so kernel options, uploadSceneCopy, the setScene mismatch check, layout entries and storage-buffer counts need no new option. packed:KxN = rtScene (header + table, no data region) + rtSceneData0..K-1; split:KxN keeps rtSceneTable.
  • chooseSceneCopyPacking(device, copy, { base, chunkWordsLog2, otherStorageBuffers, stageLimit }): K from the size and the device limit; refuses (RangeError with the numbers) when table + K chunks + the kernel's other buffers exceed the stage budget, or when the table alone is over the limit. buildGpuScene({ chunkData }) uses it.
  • WGSL rtSceneWord(i): switch (i >> N) over the chunk bindings, i & mask. rtApplyScenePacking(source, packing) replaces the packed ? rtPackSceneAccess : x pattern at every call site (megakernel, wavefront, restir, interval-batch, modules, examples).
  • Each chunk counts as a storage binding in sceneCopyStorageBuffers / rtModuleStorageBuffers / rtSceneEntries / layout entries; textures bind after the chunks. PtMegakernel / PtWavefront add the chunk count to Dawn's layout error.
  • writeSceneCopy rewrites chunked buffers in place (false when K would change).

Chosen design (V515): the chunk is picked by the word index (shift and mask, a power of two, so no division), not by a per-mesh chunk id. Nothing in the data layout moves: offsets, light maps, fingerprint and CPU twins are the unchunked ones; a mesh bigger than a chunk works; an index triple, a vertex or an env texel may straddle a boundary. Cost: a switch per data word read. The per-mesh id would pay once per mesh but needs a per-mesh data layout and a chunk id through rtSIndex / rtSVertex. Built behind the same setting only if the A/B below says the switch costs.

Divergences V515-V518, TASKS P1.4e, QUIET-PASS row, docs (docs/raytracer/scene-copy.mdx), CLAUDE.md trap.

How verified

  • Default kernels byte-identical: node bench/size-snapshot.ts <dir> packed and split, base vs branch, diff -rq empty over 355 files (the 2 new chunked-* variants are extra files).
  • Unit: scene-chunked.test.ts (raytracer, pathtracer integrator) and bench/scenes/scene-chunks.test.ts: every data word of forced-small-chunk copies reads back through the chunk twin AND through the generated rtSceneWord text parsed back out and evaluated; Cornell at 2^7 / 2^5 words, Sponza (when downloaded) at 2^14 / 2^21; budget refusals; kernels for both table placements, megakernel and every wavefront kernel. 618 tests in the touched packages pass; pnpm typecheck shows only the known @pmndrs/vdb errors.
  • GPU --page scene-copy --args chunk=7|11 (both table placements, all accessors incl. rtSurface decode, first/last word of every chunk): 0 mismatches over 214k / 564k checks.
  • Renders, per pixel vs unchunked (Mac loaded, correctness only, --no-lock): Cornell 16 spp pt_scene_chunk=7 (5 chunks, megakernel, both placements) and =8 (2 chunks, wavefront, both); Sponza-white 4 spp pt_scene_chunk=21 (K = 3, 8 MiB chunks), megakernel and wavefront, packed and split. All 8 pairs: 0 differing values (of 0.79 M / 2.76 M), so no contraction-level differences showed up.
  • Limit behaviour seen live: Sponza at 2^20 words fails with 11 > 10 storage buffers (clear error), at 2^19 chooseSceneCopyPacking refuses with the numbers.
  • Not done: no real > 128 MiB scene (chunk path exercised with forced small chunks; the logic does not depend on the size).

A/B left for the maintainer (timing, quiet pass; QUIET-PASS row P1.4e)

node bench/adapters/matrix.ts --renderers pt-megakernel,pt-mk-chunk,pt-wavefront,pt-wf-chunk --scenes sponza-white,cornell --spp 256 --repeat 5 --interleave --name p14e-chunk-ab
node bench/adapters/paired-ratios.ts --report p14e-chunk-ab --base-map pt-mk-chunk=pt-megakernel,pt-wf-chunk=pt-wavefront

Sponza K = 3, Cornell K = 1 (control). A ratio above ~1.03 on Sponza means the per-word switch costs; then build the per-mesh chunk id (V515). No default depends on it (opt-in).

🤖 Generated with Claude Code

…KxN'), chooseSceneCopyPacking, bit-identical renders

The data region splits over K storage bindings of 2^N words; word i is chunk i >> N (V515). The default packing, kernels (355 size-snapshot files) and buffers are untouched.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant