d3d12_xs, tombox-xshader: console DXR runtime bring-up (draft, unfinished) #349

Open
GDAgent wants to merge 1 commit from upstream-pr/349 into main
GDAgent commented 2026-11-23 23:24:48 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T23:24:48Z.


Draft, not for merge as is. This is our console DXR bring-up, published so the work is not lost: we are wrapping up our work on this project. It is unfinished and partly the wrong design (see "What is wrong"). Everything below is honest status; please treat it as a starting point for whoever continues ray tracing, or close it.

Library / area: d3d12_xs (new rt_x.rs runtime, rt_bvh.rs CPU BVH builder, global_bind.rs TbGlobal table, device and command-list slots), tombox-xshader (new state_obj.rs decoder, rt_cps.rs CPS translator, global-memory ABI).

What it contains

  • State objects: DeserializeStateObjectX decodes the console state-object blob (state_obj.rs), translates each RDNA2 CPS program (rt_cps.rs: continuation-passing raygen/hit/miss programs, s_setpc/s_swappc continuation switch) to HLSL, compiles it to DXIL and creates PC compute PSOs; background compile with a per-program cache; metadata slots (export names, shader identifiers, RTS0 cbuffer sizes).
  • Acceleration structures: BuildRaytracingAccelerationStructure (list slot 117 and the batched variant at 131), postbuild info (118/119), CopyRaytracingAccelerationStructure including mode 4 DESERIALIZE of console BVH blobs, AS state 0x400000 mapped to COMMON, AS registry, staging buffers released after fence completion.
  • Dispatch: SetPipelineState1/DispatchRays as a compute dispatch of the translated raygen program through the real PC list methods, keeping the title's compute state; TbGlobal windows for 64-bit GPU-VA global memory (an earlier version of what #336 proposes separately).
  • Settings: TOMBOX_RAYTRACING_TIER and an OPTIONS5 patch (default reports tier 1.1); TOMBOX_RT_ASYNC.
  • CommandList6 QI for the Xbox list IID (overlaps #296; drop it if #296 lands).

What was seen in a title (The Matrix Awakens, native Windows 11, not run under Proton, RX 6600 XT / RDNA2)

  • 100+ DeserializeStateObjectX per run; 4 programs each translated and created as PSOs; 0 PSO creation failures since the root-signature hook commits.
  • CopyRaytracingAccelerationStructure DESERIALIZE with console BVH blobs (hundreds per run), BuildRaytracingAccelerationStructure BLAS/TLAS calls.
  • DispatchRays was never reached: every run stopped earlier (Nanite persistent-culling GPU hang, PSO build stalls, VRAM pressure; see the findings issue #350).

What is wrong / missing

  • The BLAS builder is the wrong design. rt_bvh.rs builds BVH4 nodes on the CPU at record time from vertex data read through a CPU mapping of title memory (cpu_ptr_for_va). GPU-written or GPU-local vertices are not there at record time, so every BLAS in the title came out empty (leaves=0). A GPU-side builder (or the console XboxBvhBuilder kernels translated) is needed.
  • No ray has been traced through a built or deserialized BVH on a GPU; the BLAS test traverses the built buffer with a Rust reference, not image_bvh64_intersect_ray; the TLAS instance layout is untested.
  • The CPS translation has one synthetic two-instruction test; real programs were only compiled, never executed.
  • The default tier (1.1) tells every title DXR works while DispatchRays is unverified; it should be opt-in before anything is merged.
  • global_bind.rs duplicates and predates #336; rebase onto #336 if this continues.
  • Two state_obj tests return early without TOMBOX_TEST_STATEOBJ (a captured blob).

Tests

  • tombox-xshader --lib -- state_obj rt_cps global_abi: 6 passed.
  • tombox-xshader --test exec -- exec_mem::global exec_mem::bvh exec_mem::ds: 15 passed (WARP).
  • d3d12_xs --lib -- rt_x:: rt_bvh:: global_bind::: all passed (30 with one dbcount test).
  • Full d3d12_xs --lib (--test-threads=1): 691 passed, 5 failed: the known host failures alias msaa, placed_offset uneven views, title_shadow migrate, the console-DLL fixture, and dbcount::translated_pixel_shaders_with_uavs_keep_their_source, which passes when run alone (order-dependent, also seen without this branch).
  • The full tombox-xshader suite was not rerun on this squash.

All 16 original commits are squashed into one; comment lines were removed for the PR gate (0 problems).

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6570948613 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/349). Originally posted by [GDAgent](https://github.com/GDAgent) on 2026-11-23T23:24:48Z. --- **Draft, not for merge as is.** This is our console DXR bring-up, published so the work is not lost: we are wrapping up our work on this project. It is unfinished and partly the wrong design (see "What is wrong"). Everything below is honest status; please treat it as a starting point for whoever continues ray tracing, or close it. **Library / area:** `d3d12_xs` (new `rt_x.rs` runtime, `rt_bvh.rs` CPU BVH builder, `global_bind.rs` TbGlobal table, device and command-list slots), `tombox-xshader` (new `state_obj.rs` decoder, `rt_cps.rs` CPS translator, global-memory ABI). ### What it contains - **State objects:** `DeserializeStateObjectX` decodes the console state-object blob (`state_obj.rs`), translates each RDNA2 CPS program (`rt_cps.rs`: continuation-passing raygen/hit/miss programs, `s_setpc`/`s_swappc` continuation switch) to HLSL, compiles it to DXIL and creates PC compute PSOs; background compile with a per-program cache; metadata slots (export names, shader identifiers, RTS0 cbuffer sizes). - **Acceleration structures:** `BuildRaytracingAccelerationStructure` (list slot 117 and the batched variant at 131), postbuild info (118/119), `CopyRaytracingAccelerationStructure` including mode 4 DESERIALIZE of console BVH blobs, AS state `0x400000` mapped to COMMON, AS registry, staging buffers released after fence completion. - **Dispatch:** `SetPipelineState1`/`DispatchRays` as a compute dispatch of the translated raygen program through the real PC list methods, keeping the title's compute state; TbGlobal windows for 64-bit GPU-VA global memory (an earlier version of what #336 proposes separately). - **Settings:** `TOMBOX_RAYTRACING_TIER` and an OPTIONS5 patch (default reports tier 1.1); `TOMBOX_RT_ASYNC`. - CommandList6 QI for the Xbox list IID (overlaps #296; drop it if #296 lands). ### What was seen in a title (The Matrix Awakens, native Windows 11, not run under Proton, RX 6600 XT / RDNA2) - 100+ `DeserializeStateObjectX` per run; 4 programs each translated and created as PSOs; 0 PSO creation failures since the root-signature hook commits. - `CopyRaytracingAccelerationStructure` DESERIALIZE with console BVH blobs (hundreds per run), `BuildRaytracingAccelerationStructure` BLAS/TLAS calls. - **`DispatchRays` was never reached**: every run stopped earlier (Nanite persistent-culling GPU hang, PSO build stalls, VRAM pressure; see the findings issue #350). ### What is wrong / missing - **The BLAS builder is the wrong design.** `rt_bvh.rs` builds BVH4 nodes on the CPU at record time from vertex data read through a CPU mapping of title memory (`cpu_ptr_for_va`). GPU-written or GPU-local vertices are not there at record time, so every BLAS in the title came out empty (`leaves=0`). A GPU-side builder (or the console `XboxBvhBuilder` kernels translated) is needed. - No ray has been traced through a built or deserialized BVH on a GPU; the BLAS test traverses the built buffer with a Rust reference, not `image_bvh64_intersect_ray`; the TLAS instance layout is untested. - The CPS translation has one synthetic two-instruction test; real programs were only compiled, never executed. - The default tier (1.1) tells every title DXR works while `DispatchRays` is unverified; it should be opt-in before anything is merged. - `global_bind.rs` duplicates and predates #336; rebase onto #336 if this continues. - Two `state_obj` tests return early without `TOMBOX_TEST_STATEOBJ` (a captured blob). ### Tests - `tombox-xshader --lib -- state_obj rt_cps global_abi`: 6 passed. - `tombox-xshader --test exec -- exec_mem::global exec_mem::bvh exec_mem::ds`: 15 passed (WARP). - `d3d12_xs --lib -- rt_x:: rt_bvh:: global_bind::`: all passed (30 with one dbcount test). - Full `d3d12_xs --lib` (`--test-threads=1`): 691 passed, 5 failed: the known host failures `alias` msaa, `placed_offset` uneven views, `title_shadow` migrate, the console-DLL fixture, and `dbcount::translated_pixel_shaders_with_uavs_keep_their_source`, which passes when run alone (order-dependent, also seen without this branch). - The full `tombox-xshader` suite was not rerun on this squash. All 16 original commits are squashed into one; comment lines were removed for the PR gate (0 problems).
omonkeyz commented 2026-11-25 13:51:18 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:51:18Z.


Review notes for when this comes out of draft: please base it on #336 once that is reworked (the TbGlobal ring of 8 is overwritten at record time), store private data and names for real (or return the honest error) instead of S_OK without storing, compute shader stack sizes from the translated programs instead of a constant, and move the BLAS build to the GPU or to execution time so GPU-written geometry is seen. Splitting state objects, AS builds and DispatchRays into separate PRs would make review possible.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7164387513 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/349#issuecomment-7164387513). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:51:18Z. --- Review notes for when this comes out of draft: please base it on #336 once that is reworked (the TbGlobal ring of 8 is overwritten at record time), store private data and names for real (or return the honest error) instead of S_OK without storing, compute shader stack sizes from the translated programs instead of a constant, and move the BLAS build to the GPU or to execution time so GPU-written geometry is seen. Splitting state objects, AS builds and DispatchRays into separate PRs would make review possible.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/349:upstream-pr/349'
git switch 'upstream-pr/349'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/349'
git switch 'upstream-pr/349'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/349'
git switch 'upstream-pr/349'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/349'
git switch 'main'
git merge --squash 'upstream-pr/349'
git switch 'main'
git merge --ff-only 'upstream-pr/349'
git switch 'main'
git merge 'upstream-pr/349'
git push origin 'main'
Sign in to join this conversation.
No reviewers
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
omonkeyz/xbox-emulator!349
No description provided.