Ray tracing: what Leonida measured about XboxBvhBuilder and the console BVH format #274
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?
Imported from Marvisak/VIctory. Originally posted by hadrianhola on 2026-11-24T01:58:44Z.
Leonida, another Xbox Series translation and compatibility project (GPL-3.0-or-later, like VIctory), was retired by its author this week and its repository is gone from GitHub. Its notes cover one of the gaps in VIctory's README ("Shaders: ... the ray-tracing builder's shaders"), and as far as code search shows VIctory has nothing on that area yet beyond the
image_bvh_intersect_rayopcode. I'm posting a summary here so that work isn't lost. The full notes are archived in my fork, linked at the end.Nothing from the game is in this issue: no addresses, tables, shader dumps or hashes. It holds only layouts and conclusions, in the form Leonida documented them, following
docs/asset-policy.md. All credit goes to Leonida's author and contributors.What Leonida found
The title's ray-tracing shaders walk the BVH themselves. They use
image_bvh_intersect_ray/image_bvh64_intersect_rayon AMD's hardware node format: a node pointer is the address shifted right by 3 with the node type in the low bits, there are box16, box32 and triangle nodes, and the base unit is 256 bytes. A host acceleration structure (DXR or Vulkan) is opaque to those shaders. The runtime has to place the console node layout in memory and emulate the intersect instructions. Leonida treated this as its central design decision: build AMD-format BVH data, not a host acceleration structure.XboxBvhBuilder.dllbuilds on the GPU with its own compute shaders. Its constructor creates its compute pipelines through Xbox device slot 62, called with the compute-PSO shape (D3D12_COMPUTE_PIPELINE_STATE_DESC, two zero words, iid, out). On the PC interface, slot 62 isCreateStateObject, so it has to be routed to compute-PSO creation. Its build, copy and rehydrate entry points takeID3D12GraphicsCommandList4/6/8.The builder's 52 shader containers can go through the same recompiler as the title's shaders. Each container carries an LLVM bitcode blob and an
XDAT/XBCHrecord. The console executes theXBCHrecord, which unpacks to the same native-code container as the title's own compute shaders. Feeding the bitcode to the PC D3D12 compiler mostly failed, so that route is a dead end. Leonida's results, with its RDNA2 → SPIR-V translator: 52 of 52 containers unpacked, 51 translated and passedspirv-val, and the last (Box16Rehydration) neededbuffer_store_short. None of them was ever checked against a reference on a GPU.The batched build descriptions, recovered by static analysis of how the DLL reads them, not from headers:
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2is0x50bytes: the public build description, the postbuild-info count and pointer, then a 16-byteD3D12XBOX_XDXR_STREAM_DESC.0x10) is always rejected withE_INVALIDARG, thrown as a C++ exception from exports that returnvoid.Dehydrated bottom-level structures ship in the
*_bvh4packs. The DLL's rehydrate export works on CPU pointers (console unified memory) and makes no device calls. Leonida modelled the packing and matched the library's output byte for byte on 8 sampled structures. It never established whether the title rehydrates these structures or rebuilds them.A substitute builder. Leonida also had its own GPU builder that writes the console BVH4 records. It covers paired triangle leaves, BOX16 nodes for
MINIMIZE_MEMORYbuilds, refit for updates, and clone and compaction. It was checked against a CPU reference traversal on synthetic scenes. This is a reference design if running the DLL's own shaders turns out not to be viable.What stayed open
Where the full notes are
My fork keeps Leonida's tree as it was on its last day (GPL-3.0-or-later), pinned to commit
2d53a80:The licence is the same as VIctory's, but this issue is about the facts. Whether anything beyond facts is reused is your call.
If this area is useful to you, I'm happy to help. Let me know how you'd like contributions to it coordinated.
This summary was prepared with AI assistance (Claude Code) from Leonida's notes, and I checked it against them.
Imported from Marvisak/VIctory. Originally posted by SantannaCarlos on 2026-11-24T05:32:51Z.
Where the builder's own shaders stand now, measured on top of
d2a4baewith the open PRs that touch them: the 52 compute containers inXboxBvhBuilder.dll(1.0.2.1),victory translate --validate, Windows 11. The CLI usesir::build_withhere (as noted on #302), so the spill-table rule applies.mainThe title's own shader set does not regress with this stack (vertex/pixel 12272 emitted / 12172 validated, compute 1693/1670 -> 1694/1671, mesh 8191/8129).
What stops the other 36, by first refusal:
resources: an address not from a root parameter: the program builds a pointer itself (not the spill table'ss[0:1]) and loads through it.resources: an address from a root parameter that is no address: global atomics addressed through root constants that no descriptor covers.emit: a typed root view: #294 covers raw root UAVs only.resources: an address in an SGPR that is no root parameterand 1buffer_load_ushort(both in the area #164 touches), 1 LDS write of halves (#101).Translation and validation only; nothing of this was run on a GPU yet.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:46:52Z.
Automated triage for the maintainers.
mainnow has more than the opcode.crates/victory-shader/src/emit/lower/bvh.rs(bvh,bvh_box,bvh_triangle) emulatesimage_bvh_intersect_ray/image_bvh64_intersect_rayover the console node layout in title memory, with a CPU reference and GPU comparisons inemit/bvh_tests.rs. The builder's own compute programs go through the same recompiler as the title's (thetranslatestep in the README). The approach this issue describes (keep the console's node format and emulate the intersect instructions, not a host acceleration structure) is already the one inmain. What remains is getting the builder's programs to translate; the comment above lists their current refusal reasons.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by YaBulochka on 2026-11-30T04:25:29Z.
A crash from another fork, in case the builder path is being picked up somewhere: on this line
VICTORY_BVH_BUILDER=1does not fail gracefully, the title stops on its own breakpoint three seconds after launch.Build. Our fork
exp/btf-uptakeate9108896(linux-winemerged, plus #3845, #3265, #3654). Linux, Wine GE-Proton 11-15, RADV, Radeon RX 7600 XT 8 GB, Ryzen 5 9600X. Title build blake3b99f876b74d4a77f03af5f878223b27bd647b5c35a79d5decd9f716504239e93.What was set. Nothing but
VICTORY_BVH_BUILDER=1; no quarantine, no sizes wait, no trace.What happened. Three seconds after the launch, right after the layer opens the
*_bvh4core pack through DirectStorage, the title takes an exception twice:0x80000003is a breakpoint: the title's own check at+0x2219650fires, and the second fault is the crash handler indbghelpwhile it writes the dump. The process exits with code 5. Nothing of ours faults first, so the layer hands it something the title refuses; the candidate from the open questions is a build whose stream description or postbuild it does not accept, but this is not diagnosed.The same build without the switch runs the world for four minutes: 35 world frames, median 62-63 ms, no exception, and no rejected pipeline library.
Two differences seen only with the switch on, in case they are meaningful:
host pipeline library rejected; starting an empty one error=0x887E0002at startup; the runs without the switch do not print it.a pipeline creation method that is not implementedwarnings, at device slots0x218and0x1c8(the second asked 16384 times). These appear in the runs without the switch as well, 29 in each, so they are not the trigger; but if any slot the builder's constructor needs falls into that set, the builder cannot be whole.Also relevant to this area: #2368 is open here — node addresses derived from the root lose the pointer's high bits and the descriptor alignment in the translated shaders. If that holds, the rays walk garbage even once the builder is admitted, so the two are worth looking at together.
What would help us report back usefully: which path the title takes on this build (builder DLL against the standard acceleration-structure calls), and whether the empty pipeline library is expected when the builder is allowed. If there is a trace or a counter that says which build description or postbuild type reached the DLL, we can run it and send the numbers.