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

Open
opened 2026-11-24 01:58:44 +00:00 by hadrianhola · 3 comments
hadrianhola commented 2026-11-24 01:58:44 +00:00 (Migrated from github.com)
Contributor

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_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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572870536 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/274). Originally posted by [hadrianhola](https://github.com/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_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.
SantannaCarlos commented 2026-11-24 06:56:03 +00:00 (Migrated from github.com)
Author
Contributor

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 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123049814 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/274#issuecomment-7123049814). Originally posted by [SantannaCarlos](https://github.com/SantannaCarlos) on 2026-11-24T05:32:51Z. --- 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.
Marvisak commented 2026-11-25 02:06:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:46:52Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149948119 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/274#issuecomment-7149948119). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:46:52Z. --- <!-- 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)_
YaBulochka commented 2026-11-30 04:25:29 +00:00 (Migrated from github.com)
Author
Contributor

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=1 does not fail gracefully, the title stops on its own breakpoint three seconds after launch.

Build. Our fork exp/btf-uptake at e9108896 (linux-wine merged, plus #3845, #3265, #3654). Linux, Wine GE-Proton 11-15, RADV, Radeon RX 7600 XT 8 GB, Ryzen 5 9600X. Title build blake3 b99f876b74d4a77f03af5f878223b27bd647b5c35a79d5decd9f716504239e93.

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 *_bvh4 core pack through DirectStorage, the title takes an exception twice:

ViCtory: first-chance exception  0x80000003 at victory-image-b99f876b74d4a77f.dll+0x2219650
ViCtory: unhandled exception     0x80000003 at victory-image-b99f876b74d4a77f.dll+0x2219650
ViCtory: first-chance exception  0xc0000005 at dbghelp.dll+0x1fe75 (read 0xffffffffffffffff: outside the address space)
ViCtory: unhandled exception     0xc0000005 at dbghelp.dll+0x1fe75 (read 0xffffffffffffffff: outside the address space)

0x80000003 is a breakpoint: the title's own check at +0x2219650 fires, and the second fault is the crash handler in dbghelp while 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=0x887E0002 at startup; the runs without the switch do not print it.
  • 29 a pipeline creation method that is not implemented warnings, at device slots 0x218 and 0x1c8 (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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7268763415 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/274#issuecomment-7268763415). Originally posted by [YaBulochka](https://github.com/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=1` does not fail gracefully, the title stops on its own breakpoint three seconds after launch. **Build.** Our fork `exp/btf-uptake` at `e9108896` (`linux-wine` merged, plus #3845, #3265, #3654). Linux, Wine GE-Proton 11-15, RADV, Radeon RX 7600 XT 8 GB, Ryzen 5 9600X. Title build blake3 `b99f876b74d4a77f03af5f878223b27bd647b5c35a79d5decd9f716504239e93`. **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 `*_bvh4` core pack through DirectStorage, the title takes an exception twice: ``` ViCtory: first-chance exception 0x80000003 at victory-image-b99f876b74d4a77f.dll+0x2219650 ViCtory: unhandled exception 0x80000003 at victory-image-b99f876b74d4a77f.dll+0x2219650 ViCtory: first-chance exception 0xc0000005 at dbghelp.dll+0x1fe75 (read 0xffffffffffffffff: outside the address space) ViCtory: unhandled exception 0xc0000005 at dbghelp.dll+0x1fe75 (read 0xffffffffffffffff: outside the address space) ``` `0x80000003` is a breakpoint: the title's own check at `+0x2219650` fires, and the second fault is the crash handler in `dbghelp` while 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=0x887E0002` at startup; the runs without the switch do not print it. - 29 `a pipeline creation method that is not implemented` warnings, at device slots `0x218` and `0x1c8` (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.
Sign in to join this conversation.
No labels
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.

Reference
Marvisak/VIctory#274
No description provided.