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

Open
github-bot wants to merge 1 commit from github-bot/gh-349 into main AGit
Owner

@⁠GDAgent on GitHub · 2026-11-23 23:24 UTC · original
GDAgent:feat/xbox-dxr-runtime-draft → main · +5486 −123 · 23 files · 1 commits · draft

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

**@⁠GDAgent** on GitHub · 2026-11-23 23:24 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/349) `GDAgent:feat/xbox-dxr-runtime-draft` → `main` · +5486 −123 · 23 files · 1 commits · draft **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).
Unfinished console ray-tracing runtime, published as a draft so the work
is not lost:

- state objects: DeserializeStateObjectX decodes the console blob
  (state_obj.rs), translates each RDNA2 CPS program (rt_cps.rs) to HLSL
  and creates PC compute PSOs; background compile with a cache;
  metadata slots and exact RTS0 cbuffer sizes
- acceleration structures: BuildRaytracingAccelerationStructure (slots
  117 and 131), postbuild info (118/119), CopyRaytracingAcceleration-
  Structure including mode 4 DESERIALIZE, AS state 0x400000 -> COMMON,
  AS registry, staging release after fence completion
- dispatch: SetPipelineState1/DispatchRays through the real PC list
  methods; TbGlobal windows for 64-bit GPU-VA global memory (an earlier
  version of #336)
- settings: TOMBOX_RAYTRACING_TIER with an OPTIONS5 patch, TOMBOX_RT_ASYNC

Known wrong: the BLAS builder (rt_bvh.rs) runs on the CPU at record time
and reads vertices through a CPU mapping of title memory, so GPU-written
or GPU-local geometry gives empty BLAS. DispatchRays never ran in a
title. See the PR description for the full status.

Tests: state_obj, rt_cps, global_abi (tombox-xshader lib), exec_mem
global/bvh/ds, rt_x, rt_bvh, global_bind (d3d12_xs lib).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:19:52 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:51 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:51 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/349#issuecomment-7164387513) 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 has changes conflicting with the target branch.
  • crates/compat/d3d12_xs/src/cmdlist_wrap.rs
  • crates/compat/d3d12_xs/src/device_wrap.rs
  • crates/compat/d3d12_xs/src/gpu_va.rs
  • crates/tombox-xshader/src/hlsl.rs
  • crates/tombox-xshader/tests/exec_mem/ds.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/349/head:github-bot/gh-349'
git switch 'github-bot/gh-349'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-349'
git switch 'github-bot/gh-349'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-349'
git switch 'github-bot/gh-349'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-349'
git switch 'main'
git merge --squash 'github-bot/gh-349'
git switch 'main'
git merge --ff-only 'github-bot/gh-349'
git switch 'main'
git merge 'github-bot/gh-349'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.