Ray tracing: what Leonida measured about XboxBvhBuilder and the console BVH format #274

Open
opened 2026-11-26 03:57:32 +00:00 by github-bot · 2 comments
Owner

@⁠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_ray opcode. 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

  1. The title's ray-tracing shaders walk the BVH themselves. They use image_bvh_intersect_ray / image_bvh64_intersect_ray on 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.

  2. XboxBvhBuilder.dll builds 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 is CreateStateObject, so it has to be routed to compute-PSO creation. Its build, copy and rehydrate entry points take ID3D12GraphicsCommandList4/6/8.

  3. 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/XBCH record. The console executes the XBCH record, 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 passed spirv-val, and the last (Box16Rehydration) needed buffer_store_short. None of them was ever checked against a reference on a GPU.

  4. The batched build descriptions, recovered by static analysis of how the DLL reads them, not from headers:

    • D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2 is 0x50 bytes: the public build description, the postbuild-info count and pointer, then a 16-byte D3D12XBOX_XDXR_STREAM_DESC.
    • That stream description is a size and a pointer to 16-byte typed records. The DLL takes the first record of each type it wants, and stops walking at an unknown type.
    • The offline-statistics postbuild type (0x10) is always rejected with E_INVALIDARG, thrown as a C++ exception from exports that return void.
  5. Dehydrated bottom-level structures ship in the *_bvh4 packs. 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.

  6. 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_MEMORY builds, 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

  • Which path the title takes: the builder DLL, or the standard acceleration-structure calls.
  • Whether the title ever passes a non-empty stream description.
  • Whether the translated builder programs produce correct results on a GPU.

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.

**@⁠hadrianhola** on GitHub · 2026-11-24 01:58 UTC · [original](https://github.com/Marvisak/VIctory/issues/274) 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_ray` opcode. 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 1. **The title's ray-tracing shaders walk the BVH themselves.** They use `image_bvh_intersect_ray` / `image_bvh64_intersect_ray` on 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. 2. **`XboxBvhBuilder.dll` builds 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 is `CreateStateObject`, so it has to be routed to compute-PSO creation. Its build, copy and rehydrate entry points take `ID3D12GraphicsCommandList4/6/8`. 3. **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`/`XBCH` record. The console executes the `XBCH` record, 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 passed `spirv-val`, and the last (`Box16Rehydration`) needed `buffer_store_short`. None of them was ever checked against a reference on a GPU. 4. **The batched build descriptions,** recovered by static analysis of how the DLL reads them, not from headers: - `D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2` is `0x50` bytes: the public build description, the postbuild-info count and pointer, then a 16-byte `D3D12XBOX_XDXR_STREAM_DESC`. - That stream description is a size and a pointer to 16-byte typed records. The DLL takes the first record of each type it wants, and stops walking at an unknown type. - The offline-statistics postbuild type (`0x10`) is always rejected with `E_INVALIDARG`, thrown as a C++ exception from exports that return `void`. 5. **Dehydrated bottom-level structures ship in the `*_bvh4` packs.** 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. 6. **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_MEMORY` builds, 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 - Which path the title takes: the builder DLL, or the standard acceleration-structure calls. - Whether the title ever passes a non-empty stream description. - Whether the translated builder programs produce correct results on a GPU. ## 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`: - Build-description layouts: [docs/xdxr.md](https://github.com/hadrianhola/HHEmule/blob/2d53a8055656f1138e57de5367960fcc0714283a/docs/xdxr.md) - Node format, packs and rehydration: [docs/bvh.md](https://github.com/hadrianhola/HHEmule/blob/2d53a8055656f1138e57de5367960fcc0714283a/docs/bvh.md) - The builder's shader containers: [docs/embedded_shaders.md](https://github.com/hadrianhola/HHEmule/blob/2d53a8055656f1138e57de5367960fcc0714283a/docs/embedded_shaders.md) - Design discussion: [docs/d3d12_vulkan.md, §4.8](https://github.com/hadrianhola/HHEmule/blob/2d53a8055656f1138e57de5367960fcc0714283a/docs/d3d12_vulkan.md#48-ray-tracing-and-xdxr) and [§7.2](https://github.com/hadrianhola/HHEmule/blob/2d53a8055656f1138e57de5367960fcc0714283a/docs/d3d12_vulkan.md#72-the-bvh-builders-shader-path) - Code, for reference only: [runtime/src/xdxr_descs.h](https://github.com/hadrianhola/HHEmule/blob/2d53a8055656f1138e57de5367960fcc0714283a/runtime/src/xdxr_descs.h), [runtime/src/xdxr_build.h](https://github.com/hadrianhola/HHEmule/blob/2d53a8055656f1138e57de5367960fcc0714283a/runtime/src/xdxr_build.h), [tools/xdxr_bvh.py](https://github.com/hadrianhola/HHEmule/blob/2d53a8055656f1138e57de5367960fcc0714283a/tools/xdxr_bvh.py) 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:32 +00:00
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 05:32 UTC · original

Where the builder's own shaders stand now, measured on top of d2a4bae with the open PRs that touch them: the 52 compute containers in XboxBvhBuilder.dll (1.0.2.1), victory translate --validate, Windows 11. The CLI uses ir::build_with here (as noted on #302), so the spill-table rule applies.

Stack Resources traced Emitted / validated
main 0 / 52 0
+ #302 19 0
+ #294 19 4 / 4
+ #489 22 8 / 8
+ #69 22 16 / 16

The 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:

  • 19 resources: an address not from a root parameter: the program builds a pointer itself (not the spill table's s[0:1]) and loads through it.
  • 9 resources: an address from a root parameter that is no address: global atomics addressed through root constants that no descriptor covers.
  • 4 emit: a typed root view: #294 covers raw root UAVs only.
  • 2 resources: an address in an SGPR that is no root parameter and 1 buffer_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.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 05:32 UTC · [original](https://github.com/Marvisak/VIctory/issues/274#issuecomment-7123049814) Where the builder's own shaders stand now, measured on top of `d2a4bae` with the open PRs that touch them: the 52 compute containers in `XboxBvhBuilder.dll` (1.0.2.1), `victory translate --validate`, Windows 11. The CLI uses `ir::build_with` here (as noted on #302), so the spill-table rule applies. | Stack | Resources traced | Emitted / validated | |---|---|---| | `main` | 0 / 52 | 0 | | + #302 | 19 | 0 | | + #294 | 19 | 4 / 4 | | + #489 | 22 | 8 / 8 | | + #69 | 22 | 16 / 16 | The 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: - 19 `resources: an address not from a root parameter`: the program builds a pointer itself (not the spill table's `s[0:1]`) and loads through it. - 9 `resources: an address from a root parameter that is no address`: global atomics addressed through root constants that no descriptor covers. - 4 `emit: a typed root view`: #294 covers raw root UAVs only. - 2 `resources: an address in an SGPR that is no root parameter` and 1 `buffer_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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:46 UTC · original

Automated triage for the maintainers.

  • main now has more than the opcode. crates/victory-shader/src/emit/lower/bvh.rs (bvh, bvh_box, bvh_triangle) emulates image_bvh_intersect_ray / image_bvh64_intersect_ray over the console node layout in title memory, with a CPU reference and GPU comparisons in emit/bvh_tests.rs. The builder's own compute programs go through the same recompiler as the title's (the translate step 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 in main. What remains is getting the builder's programs to translate; the comment above lists their current refusal reasons.
  • The issue body and the linked notes contain console SDK type names, interface details and header-derived layouts. SDK material must not be posted here; please edit it out and keep to findings about our code and the GPU's public ISA.
  • The request fits the project's scope. Whether and how to coordinate work on this area is for the maintainers to decide.

Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:46 UTC · [original](https://github.com/Marvisak/VIctory/issues/274#issuecomment-7149948119) <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-24T05:32:51Z at=2026-11-25T01:46:35Z --> Automated triage for the maintainers. - `main` now has more than the opcode. `crates/victory-shader/src/emit/lower/bvh.rs` (`bvh`, `bvh_box`, `bvh_triangle`) emulates `image_bvh_intersect_ray` / `image_bvh64_intersect_ray` over the console node layout in title memory, with a CPU reference and GPU comparisons in `emit/bvh_tests.rs`. The builder's own compute programs go through the same recompiler as the title's (the `translate` step 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 in `main`. What remains is getting the builder's programs to translate; the comment above lists their current refusal reasons. - The issue body and the linked notes contain console SDK type names, interface details and header-derived layouts. SDK material must not be posted here; please edit it out and keep to findings about our code and the GPU's public ISA. - The request fits the project's scope. Whether and how to coordinate work on this area is for the maintainers to decide. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#274
No description provided.