Ray tracing: what Leonida measured about XboxBvhBuilder and the console BVH format #274
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#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?
@hadrianhola on GitHub · 2026-11-24 01:58 UTC · original
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.
@SantannaCarlos on GitHub · 2026-11-24 05:32 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 01:46 UTC · original
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