Help wanted: real ray-tracing acceleration structures (BVH) #34
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ThatRecompDev--five-star-recomp#34
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ThatRecompDev on GitHub · 2026-11-25 16:21 UTC · original
right now every ray-tracing pass is held back: our XboxBvhBuilder shim builds no acceleration structures by default, so the passes that trace rays (and the ones that only feed or shade them, like
CS_RaytracingResolveandbvh_skinning) stay stand-ins. letting them run over unbuilt memory took the device down at world load, so holding them was the fix for now. the cost is that shadows and indirect light come from stand-in values instead of the real thing.what would help:
--raytracingalready has a start: sizes and BLAS) or on the GPU with the game's own 52 builder pipelines (--raytracing-gpuinventories them)image_bvh_intersect_rayemulation against a real buildbackground:
docs/raytracing.md,docs/bvh-builder.md,docs/ray-intersection.md. happy to answer questions here.@almostxxx27 on GitHub · 2026-11-28 08:23 UTC · original
Ray tracing: plan for real acceleration structures (issue #34)
Every ray-tracing pass is held today: the
XboxBvhBuildershim builds nothing by default, so the 64 programs thattrace rays, and the passes that only feed or shade them (
CS_RaytracingResolve,bvh_skinning,rtdirectionalshadows), stay stand-ins, and shadows and indirect light come fromRtStandInsvalues. Letting thepasses run over unbuilt memory lost the device at world load (boots w63, w65b, w70e). This note is the plan for
building real structures in the console's layout and checking the
image_bvh_intersect_rayemulation against them.Background: raytracing.md, bvh-builder.md, ray-intersection.md.
Code:
src/FiveStar.Loader/Shims/Bvh,src/FiveStar.Shaders/Bvh.Where things stand
--raytracingcore_bvh4.rpf)BvhBatchBuilder,XdxrBlas,XdxrTlas), done; never seen in a boot--rt-traversallets the 64 run; no boot has shown they read anything (open: T# bits 47..40 are 0, game memory seen so far is above 1 TiB)--raytracing-gpuinventories only, nothing dispatchesRayTracingPrograms,BvhMiss,RtStandIns)The shortest path to real shadows and indirect light is finishing and proving the CPU path; the GPU builder follows
for skinned geometry and cost.
Phase 0: one instrumented boot
A boot with
--rt-traversal --d3d12-trace-records, with logging added so it answers, per structure:Build,RehydrateandCopy: type, destination address, console size, structure size, written or skipped(and why), time spent. Today only the first skip of each kind is logged (
OnceLog); add a per-sample counter lineas the other subsystems have.
match, and are the pages in the address map?
Deliverable: a table in
raytracing.mdclosing the "below 1 TiB" question. Everything after depends on it.Phase 1: the CPU path safe enough to be the default
The world-load device loss came from traversing unbuilt memory. The invariant: a program never walks a structure the
loader did not write.
BvhBuilderServicekeepsaddress → (type, size, generation, owner)for every BLAS andTLAS it wrote or rehydrated.
InstanceDescs.Readtakes root and bounds from whatever is at the BLAS address; a BLASthat was skipped puts garbage bounds and a garbage root into the TLAS. Change: an instance whose BLAS is not in the
registry (or whose header is not version 6 with bit 24 clear) is left out, counted and logged.
RayTracingPrograms.StandInsturns off only after thefirst TLAS has been written (as VIctory holds its pipelines until its builder has run). Until then the passes stay
stand-ins and
RtStandInsfills their outputs; after, each pass's stand-in stops as the pass runs.ServesRays(
CS_RaytracingResolve,rtdirectionalshadows) releases with the same gate;bvh_skinningstays held until step 4.BuildOneignores Flags bit 5 (PERFORM_UPDATE) and rebuilds, which is correct; checkthat the rebuilt size still fits and that
Copy's COMPACT path sees the postbuild size written.bvh_skinning~CS_*writes its vertices on the GPU when the list runs; a CPU build at recordtime reads pre-skin memory. Phase 0 shows what those buffers hold at record time. Options, in order: (a) build from
the previous frame's skinned output (one frame late, no crash); (b) defer the build to the list's fence and write
before the next frame's trace list executes; (c) leave to the GPU builder (Phase 3). Until decided, skinned BLASes
are built from whatever is readable and the registry marks them stale.
Bvh4Treeis a median quarter-split on the game thread. Measure ms per batch in Phase 0; if it matters,move builds to a worker and block in
ExecuteCommandListsfor the list that first references the structure. SAHstays out of scope unless hit quality is visibly bad.
rehydration writes them, so a shader that reads them sees sane values.
Acceptance: a boot survives 10 min or more with
--rt-traversal; shadow masks and the screen-probe light come fromthe traces (compared with the
RtStandInspicture); the sample lines count no "destination not mapped" or"larger than the console size" skips.
Phase 2: check
image_bvh_intersect_rayagainst a real buildThree checks, cheapest first:
--bvh-dump <dir>writes each rehydrated BLAS (bytes, source desc,vertex and index ranges) from game memory. A small one joins
FiveStar.Shaders.Tests/Assembledbeside thesynthetic
bvh_*.bincases: the HLSL emulation on WARP against the C# reference (BvhReference) against bruteforce over the leaf triangles, with the ray set of
BvhTests. This tests the emulation on the DLL's own nodelayout, not ours.
(raytracing.md). Synthesize them for an arbitrary triangle list, run
ConsoleBvhModule.Rehydrate, and diff theresult against
XdxrBlas.Buildof the same triangles: header dwords, node types, bounds, triangle-node fields.Anything the DLL writes that we do not (bit 17, the parent table, dword 15) shows here. A loader test; no boot.
--capture-dispatchonshadowmask~CS_TraceShadowRays_*with the TLAS it bound (fromthe registry): replay the captured rays through the reference model and compare the hit mask the shader wrote.
Disagreements beyond the last ULP point at a traversal-header field misread (instance node 0x00, 0x70, bit 30 of
0x38) or an emulation bug.
Phase 3: the GPU builder (
--raytracing-gpubeyond inventory)The steps of bvh-builder.md, with concrete gates:
completes on our device.
PipelineFactorylike any console program(subdword loads and stores, atomic sub, fmin and fmax are in the translator). Log compile time; they take the
normal cache, so it is paid once.
else the CPU path. Log every command-list slot the DLL calls during one batch (root signature, root constants and
views, Dispatch, barriers, copies,
UploadArenause) and make sure each has a shim.--raytracing-gpu quarantine): Dest and Scratch in the batched descs are rewritten to aloader-owned allocation, read back after the fence and compared with the CPU builder's result for the same desc
(triangle count, bounds, root type, every reachable triangle node). Nothing reaches title memory until the
comparison is clean for N batches.
batch the gate skipped. The registry of Phase 1 carries the owner.
bvh_skinningis released.Phase 4: defaults and docs
--raytracingand the traversal on by default once Phase 1's acceptance holds over a few boot series;--no-raytracingrestores today's stand-ins.raytracing.md(close the Unknowns the phases answer),ray-intersection.md("Without a built structure"becomes the fallback),
loader.md's flags and the status page.Order and size
Assumptions: the issue wants real geometry over a good-enough approximation, so the CPU path is finished and made
the default before the GPU builder, and the GPU builder's first job is skinned geometry rather than replacing the CPU
path. GPU-first still needs Phase 0 and Phase 1.1 to 1.2: the gate and the registry are what keep the device alive
either way.
@ThatRecompDev on GitHub · 2026-11-28 09:49 UTC · original
thanks, this is a solid plan and most of the structure is right. a few things have moved, though. --raytracing on its own already lets the 64 programs run (and the bvh_, resolve and rtdirectionalshadows ones) and turns the node misses off. the world-load losses from w63, w65b and w70e date from before nodes in unmapped memory missed and before rehydration and the CPU builds, and testers now run --raytracing --rt-traversal for 15-25 minutes, so the 10 minute bar is basically met. the open question is whether the traces hit anything, i.e. the T# below 1 TiB.
the stand-ins changed last night too. a held pass now fills only the records it stores through, lamps get their shadow-tile table set to lit instead of 0xffffffff, and the screen-probe light comes from the scene's cached radiance, not a flat grey. --no-raytracing and --bvh-dump don't exist yet, fine as proposals.
what would be great as PRs: per-sample counters for builds, rehydrations and skips. a check in InstanceDescs that a BLAS header is really built (version 6, bit 24 clear, root type 4 or 5) before it goes into a TLAS, which is a real gap today since a zeroed header gives root 0. and the DLL-as-oracle test, as long as it skips when the DLL isn't there, since that's a game file. one caveat on the dump fixture: a BLAS dumped from the game can't go in the repo, so keep those local and build committed fixtures from synthetic triangles.
@almostxxx27 on GitHub · 2026-11-28 19:51 UTC · original
#72