Repository navigation
Single storage buffer for the walk and the scene copy: walkPacking 'shared' (issue #36 option 2) - #124
Open
DennisSmolek wants to merge 3 commits into
Open
Single storage buffer for the walk and the scene copy: walkPacking 'shared' (issue #36 option 2)#124DennisSmolek wants to merge 3 commits into
DennisSmolek wants to merge 3 commits into
Conversation
…et helpers (issue #36) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pass row, trap (issue #36) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… copy in ONE storage buffer (issue #36 option 2) rtPackShared / rtSharedLayout, rtPackWalkAccess(.., 'rtShared'), rtPackSceneAccess(.., 'shared'), GpuScene.shared, scene copy binding 'shared' (textures only). Module needs 1 storage buffer in all; default, split and packed kernels byte-identical. Check page shared-buffer-check, trace-core walkPacking=shared. V595. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #36 (option 2). Depends on #83 (branched from
issue-36-host-buffer-budget; until #83 merges this PR's diff againstmainalso shows #83's two commits, the new work is the last commit2118244).What changed
walkPacking: 'shared'puts the walk and the packed scene copy in ONErtShared: array<vec4u>, so an inlinertModuleWgslneeds 1 storage buffer in total.Layout (offsets in vec4s):
[H0 | H1 | table | data | nodes | triangles | top level | positions].rtWalkheader holds). H1 = the packed scene header's words with absolute offsets (dataBase,tableBase,dataWords,totalVec4s).rtShared[e + 2u], as the packed copy'srtScene[e + 1u]), the data goes throughrtShared[1].x, the walk throughrtShared[0].k. So a scene read costs what a packed one does, a walk read what a packed walk does. Table, data, walk in that order is what keeps the table base constant.rtPackWalkAccess(walk, 'rtShared')andrtPackSceneAccess(source, 'shared').rtPackShared(device, trace, copy)builds it (buildGpuScene({ walkPacking: 'shared' })calls it): scene copy from the CPU, walk by Host-kernel storage-buffer budget: documented count, scene report, opt-in packed walk (#36) #83's compute copy (refactored into a shared helper).update(encoder)repacks the walk,writeScene(device, copy)rewrites the scene part (false if the table length changed or the data no longer fits; the walk sits behind both).rtSceneBufferBindings('shared')= 0,rtSceneCopyLayoutEntries(first, textures, 'shared')lists only textures and samplers, and the texture arrays start at the scene slot'sfirstBinding. The walk binding is attraceSlot.uploadSceneCopy(.., { packing: 'shared' })uploads textures only.SceneCopyBinding = SceneCopyPacking | 'shared'is the widened type (GpuScene.packing,SceneCopyBuffers.packing).rtPackSharedthrows aRangeErrornaming every part (scene table, data, walk nodes / triangles / top level / positions) and suggests the two-buffer layout.rtModuleStorageBuffers,rtWalkStorageBuffers,rtSceneStorageBuffers,rtSceneEntries('shared')(empty),GpuScene.storageBuffers(walk 1, copy 0, total 1).PtMegakernel/PtWavefront(ptSceneOptionsthrows for a shared scene), the batch tracers (walk only).walkPacking: 'shared'withoutscenethrows.inline-wgsl.mdx,api.mdx,design/trace-core.md), CLAUDE.md trap, TASKS P1.14, QUIET-PASS P1.14 (third arm).Verified (correctness only, shared Mac at load 30-50: no timings)
node bench/size-snapshot.ts355 filesdiff -rqempty; plus 80rtModuleWgsltexts (4 node formats x scene none / split / packed x shade x minify) forwalkPacking: 'split'AND'packed'byte-identical before / after (so Host-kernel storage-buffer budget: documented count, scene report, opt-in packed walk (#36) #83's packed mode is unchanged).pnpm typecheck: no new errors (only the known@pmndrs/vdbones). vitest: 18 files / 307 tests inpackages/raytracer/src/{trace,scene}and the pathtracer scene-options / scene-packing tests (22 inwalk-packing.test.ts, of which 9 new: onevar<storage>for 4 node formats x shade, no old names left, traceSlot, budgets, texture bindings, layout).node bench/runner/run.ts --page shared-buffer-check --no-lock(new): a host-style kernel with ONE storage buffer of its own runsrtClosest+rtShade(full mode, sun + sky) on Cornell, quad-light and tex-checker (textures) forsplit(5 module buffers),two(Host-kernel storage-buffer budget: documented count, scene report, opt-in packed walk (#36) #83's layout, 2) andshared(1). The module declares 1 buffer, equal tortModuleStorageBuffersandGpuScene.storageBuffers.total; shared == two-buffer == split per pixel (0 differing pixels, hit instance / t / triangle / material bit-identical, max rel 0); afterwalk.update(encoder)+writeScenethe image is unchanged; a changed table length is refused; the oversize error names all parts. (The split/packed control was already 0 for these scenes:max rel 0; P3.11 saw <= 3.2e-7 on other scenes.)trace-core walkPacking=shared(inline kernel on the shared buffer, the batch kernels as the oracle, also onSceneTreesbuffers): 3 of 3 runs pass on 6 formats (quantized, f32-indexed, bvh4 x2, cwbvh8 x2) x edges / cornell / quad-light / sponza-white. Withbvh4-single-instancedincluded it failed in 2 of 3 runs, only that row, with the knowninlineMismatch/coneMismatch/surfaceMismatchsignature (trace-core fails intermittently: zeroed inline records in whole subgroups (shadow-masked, bvh4-single-instanced) #29, X-trace-core: cause of the trace-core flake (bvh4 single walk on Metal), repro args #85: a Metal miscompile of bvh's single walk); split control: 1 of 1 run passed.The issue's table, with option 2
Storage buffers in the traced pass's compute stage (their pass 3, fallback, walk + scene copy, hit shading):
rtShadehit shadingrtShadeOption 1 takes walk + scene copy from 4 to 2 (indexed leaves: 5 to 2), option 2 to 1 (indexed leaves too). Every configuration then fits the default 8 with 2-4 to spare.
Left for the maintainer
Cost of the header loads (option 1 vs 2 vs split) is not measured: quiet-pass row P1.14 has the third arm (
--ab walkPacking=split,packed,shared, needs thetrace-timingarg, which does not exist yet). Reflections must rebuild walk and scene copy together to use it (rtPackShared/writeScene);PtMegakernel/PtWavefrontdo not read it.Check:
node bench/runner/run.ts --page shared-buffer-check --no-lock(read*_shared_vs_two_differing_pixels= 0 and*_storage_buffers_declared).🤖 Generated with Claude Code