ProjectScarlett: lower the irradiance shadow ray walks to native ray queries #302

Merged
Jerkin42 merged 5 commits from upstream-pr/302 into main 2026-11-27 09:04:15 +00:00
Jerkin42 commented 2026-11-27 06:55:32 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-27T06:55:32Z.


Summary

ProjectScarlett traces rays in its own compute programs. The console compiler inlines each RayQuery as a loop over raw console BVH nodes: an LDS stack, flat loads of nodes and image_bvh64_intersect_ray. xshader refuses these programs ("raw BVH node intersection requires traversal translation"). This PR lowers the two irradiance-cache shadow programs to native DXR ray queries, the same way radiance_probe handles Frosty. Only the walk is replaced; the code around it stays guest ISA.

Commits:

  1. dxbc: read a compute scene descriptor as a table SRV.
    • An acceleration structure is a raw SRV in PSV, but FSSM gives its descriptor shape 4, not 1. Reflection gave up on the whole table, so the translator got the title's root, whose ranges are in a different order from the program's reads.
    • Result for CS_IrradianceCache_ShadowTrace: it read its UAV at slot 6 as SRV t333 ("buffer_store_format to a non-UAV table").
    • Shape 4 is now accepted only for a raw SRV with PSV resource kind 16. All 319 scene descriptors in a recorded run's requests have this shape. 180 requests gain a reflected root; none lose one.
  2. d3d12: bind several native scenes in a private space the title leaves free.
    • The private scene ABI used space 1 and a single scene. ProjectScarlett binds everything in space 1, and its far-field variants read two structures.
    • A translation can now declare scenes in space 900, where t<i> is the title's i-th acceleration structure ordered by (space, register).
    • Frosty's space 1 layout is unchanged. Layout tests are in src/tests/device/compute_scene.rs.
  3. d3d12: give a reflected-table ray-query program its scene root.
    • The scene root now extends the root the program is bound with: the reflected layout when there is one.
    • The reflected dispatch path now binds the scene SRVs. Before this, pipeline creation failed with E_INVALIDARG for these programs.
  4. xshader: lower ProjectScarlett's irradiance shadow walks to ray queries (hlsl/scarlett_rays.rs).
    • A program is matched by entry name plus ISA fingerprint.
    • Each walk becomes one tb_scarlett_ray_query. Its operands are the world ray the walk copies before it starts (the image_bvh64_intersect_ray origin, direction and extent). Its result is the register the guest code tests after the loop.
    • The scene is named by its table slot and resolved to the title's structure.
    • Programs covered: CS_IrradianceCache_ShadowTrace (near scene) and CS_IrradianceCache_ShadowTrace_WithFar (near scene, then on a miss the far scene from the near sphere's exit).
  5. tools: check ProjectScarlett's shadow ray queries on the GPU (tools/check_scarlett_rays.py, tools/reference/scarlett/rays_guest.cpp).
    • Replays both programs from a run's recorded shader requests through the provider. The guest builds native scenes through the Xbox raytracing API and compares every lane with the geometry.

Known gaps:

  • The guest walk reads a facing-cull field from each console instance's flags. The native query culls nothing, so the two only agree for instances that leave that field clear.
  • CS_RaytraceShadows_Mixed is recorded without a root signature, so it can't be replayed on its own. Its lowering is left for a follow-up.
  • In game, these dispatches still need native scenes. On main every ProjectScarlett AS build targets title memory and vkd3d drops it. Until scenes exist, scene resolution fails and the runtime skips the dispatch, as it already does for unresolved Frosty scenes.

Verified on Lanes

  • python tuxbox.py check passed on this branch
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below

Not run in full: the GPU suite's present lanes open windows on the desktop I'm working on. I ran its code steps and the new check:

  • Python tests: 426 OK (8 skipped).
  • Shader compiler: 420 + 2 passed, including 3 new scarlett_rays tests.
  • DXBC: 71 passed, including the new compute_acceleration_structure_is_a_table_srv, which fails without the fix.
  • XG layout: 14 passed.
  • D3D12 Windows typecheck: clean.

The new behaviour needs the title's recorded shader requests, so it is a standalone check like check_frosty_inline219.py, not a Lanes scenario.

GPU, driver and backend:

  • This changes code both vendors run, and the check passed on an AMD and an NVIDIA card. Otherwise, say which vendor still needs to run it: NVIDIA still needs to run check_scarlett_rays.py. AMD: RX 9060 XT, RADV (Mesa 26.1.8), Proton Experimental.
CS_IrradianceCache_ShadowTrace:
  adapter=1002:7590
  shadow_occluder=expected ffffffff observed ffffffff mismatches 0
  shadow_behind=expected 00000000 observed 00000000 mismatches 0
  shadow_beyond_maximum=expected 00000000 observed 00000000 mismatches 0
  shadow_empty=expected 00000000 observed 00000000 mismatches 0
  shadow_half_occluder=expected 00ff00ff observed 00ff00ff mismatches 0
  failed=0
CS_IrradianceCache_ShadowTrace_WithFar:
  adapter=1002:7590
  shadow_far_occluder=expected ffffffff observed ffffffff mismatches 0
  shadow_far_behind=expected 00000000 observed 00000000 mismatches 0
  shadow_far_beyond_maximum=expected 00000000 observed 00000000 mismatches 0
  shadow_far_empty=expected 00000000 observed 00000000 mismatches 0
  shadow_far_half_occluder=expected 00ff00ff observed 00ff00ff mismatches 0
  shadow_far_far_occluder=expected ffffffff observed ffffffff mismatches 0
  shadow_far_far_behind=expected 00000000 observed 00000000 mismatches 0
  shadow_far_far_half=expected 00ff00ff observed 00ff00ff mismatches 0
  shadow_far_far_inside_near_sphere=expected 00000000 observed 00000000 mismatches 0
  shadow_far_far_beyond_near_sphere=expected ffffffff observed ffffffff mismatches 0
  shadow_far_near_inside_sphere=expected ffffffff observed ffffffff mismatches 0
  shadow_far_far_past_shortened_maximum=expected eeeeeeee observed eeeeeeee mismatches 0
  failed=0

Checks

No evidence JSON changes.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5522558485 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/302). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-27T06:55:32Z. --- ## Summary ProjectScarlett traces rays in its own compute programs. The console compiler inlines each `RayQuery` as a loop over raw console BVH nodes: an LDS stack, flat loads of nodes and `image_bvh64_intersect_ray`. xshader refuses these programs ("raw BVH node intersection requires traversal translation"). This PR lowers the two irradiance-cache shadow programs to native DXR ray queries, the same way `radiance_probe` handles Frosty. Only the walk is replaced; the code around it stays guest ISA. Commits: 1. **dxbc: read a compute scene descriptor as a table SRV.** - An acceleration structure is a raw SRV in PSV, but FSSM gives its descriptor shape 4, not 1. Reflection gave up on the whole table, so the translator got the title's root, whose ranges are in a different order from the program's reads. - Result for `CS_IrradianceCache_ShadowTrace`: it read its UAV at slot 6 as SRV t333 ("buffer_store_format to a non-UAV table"). - Shape 4 is now accepted only for a raw SRV with PSV resource kind 16. All 319 scene descriptors in a recorded run's requests have this shape. 180 requests gain a reflected root; none lose one. 2. **d3d12: bind several native scenes in a private space the title leaves free.** - The private scene ABI used space 1 and a single scene. ProjectScarlett binds everything in space 1, and its far-field variants read two structures. - A translation can now declare scenes in space 900, where `t<i>` is the title's i-th acceleration structure ordered by (space, register). - Frosty's space 1 layout is unchanged. Layout tests are in `src/tests/device/compute_scene.rs`. 3. **d3d12: give a reflected-table ray-query program its scene root.** - The scene root now extends the root the program is bound with: the reflected layout when there is one. - The reflected dispatch path now binds the scene SRVs. Before this, pipeline creation failed with E_INVALIDARG for these programs. 4. **xshader: lower ProjectScarlett's irradiance shadow walks to ray queries** (`hlsl/scarlett_rays.rs`). - A program is matched by entry name plus ISA fingerprint. - Each walk becomes one `tb_scarlett_ray_query`. Its operands are the world ray the walk copies before it starts (the `image_bvh64_intersect_ray` origin, direction and extent). Its result is the register the guest code tests after the loop. - The scene is named by its table slot and resolved to the title's structure. - Programs covered: `CS_IrradianceCache_ShadowTrace` (near scene) and `CS_IrradianceCache_ShadowTrace_WithFar` (near scene, then on a miss the far scene from the near sphere's exit). 5. **tools: check ProjectScarlett's shadow ray queries on the GPU** (`tools/check_scarlett_rays.py`, `tools/reference/scarlett/rays_guest.cpp`). - Replays both programs from a run's recorded shader requests through the provider. The guest builds native scenes through the Xbox raytracing API and compares every lane with the geometry. Known gaps: - The guest walk reads a facing-cull field from each console instance's flags. The native query culls nothing, so the two only agree for instances that leave that field clear. - `CS_RaytraceShadows_Mixed` is recorded without a root signature, so it can't be replayed on its own. Its lowering is left for a follow-up. - In game, these dispatches still need native scenes. On main every ProjectScarlett AS build targets title memory and vkd3d drops it. Until scenes exist, scene resolution fails and the runtime skips the dispatch, as it already does for unresolved Frosty scenes. ## Verified on Lanes - [ ] `python tuxbox.py check` passed on this branch - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below Not run in full: the GPU suite's present lanes open windows on the desktop I'm working on. I ran its code steps and the new check: - Python tests: 426 OK (8 skipped). - Shader compiler: 420 + 2 passed, including 3 new `scarlett_rays` tests. - DXBC: 71 passed, including the new `compute_acceleration_structure_is_a_table_srv`, which fails without the fix. - XG layout: 14 passed. - D3D12 Windows typecheck: clean. The new behaviour needs the title's recorded shader requests, so it is a standalone check like `check_frosty_inline219.py`, not a Lanes scenario. GPU, driver and backend: - [ ] This changes code both vendors run, and the check passed on an AMD and an NVIDIA card. Otherwise, say which vendor still needs to run it: **NVIDIA** still needs to run `check_scarlett_rays.py`. AMD: RX 9060 XT, RADV (Mesa 26.1.8), Proton Experimental. ```text CS_IrradianceCache_ShadowTrace: adapter=1002:7590 shadow_occluder=expected ffffffff observed ffffffff mismatches 0 shadow_behind=expected 00000000 observed 00000000 mismatches 0 shadow_beyond_maximum=expected 00000000 observed 00000000 mismatches 0 shadow_empty=expected 00000000 observed 00000000 mismatches 0 shadow_half_occluder=expected 00ff00ff observed 00ff00ff mismatches 0 failed=0 CS_IrradianceCache_ShadowTrace_WithFar: adapter=1002:7590 shadow_far_occluder=expected ffffffff observed ffffffff mismatches 0 shadow_far_behind=expected 00000000 observed 00000000 mismatches 0 shadow_far_beyond_maximum=expected 00000000 observed 00000000 mismatches 0 shadow_far_empty=expected 00000000 observed 00000000 mismatches 0 shadow_far_half_occluder=expected 00ff00ff observed 00ff00ff mismatches 0 shadow_far_far_occluder=expected ffffffff observed ffffffff mismatches 0 shadow_far_far_behind=expected 00000000 observed 00000000 mismatches 0 shadow_far_far_half=expected 00ff00ff observed 00ff00ff mismatches 0 shadow_far_far_inside_near_sphere=expected 00000000 observed 00000000 mismatches 0 shadow_far_far_beyond_near_sphere=expected ffffffff observed ffffffff mismatches 0 shadow_far_near_inside_sphere=expected ffffffff observed ffffffff mismatches 0 shadow_far_far_past_shortened_maximum=expected eeeeeeee observed eeeeeeee mismatches 0 failed=0 ``` ## Checks No evidence JSON changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NickStallman commented 2026-11-27 07:36:29 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T07:36:29Z.


AMD run of this branch (2c2cec6), since the PR asks for one on a card with the full suite:

  • AMD Raphael iGPU (1002:13c0), RADV, GE-Proton11-14: full python tuxbox.py check passed, 135 gates.
  • tools/check_scarlett_rays.py on the same card, from our own recorded ProjectScarlett requests: both programs passed, 0 mismatches (failed=0 for CS_IrradianceCache_ShadowTrace and _WithFar).
  • NVIDIA (RTX 5090, 620.70.10) is queued behind our game runs; I'll post it when it's done.

Measured evidence for commit 1 from two probe runs in ProjectScarlett's story intro on the 5090:

  • At dispatch, the title binds a UAV (0x28000 bytes, raw) at table 1 slot 6 for CS_IrradianceCache_ShadowTrace_WithFar. That's the program's own u52, not the title root's SRV t333.
  • Across 363 dispatched compute programs whose FSSM layout differs from their root, the title always kept the root it gave at pipeline creation (1,013 of 1,013 dispatches). In the 140 table slots where the bound view's kind could tell the two readings apart, the view matched the program's layout in all 140 and the root's in none.

Overlap note: we had a reader change that also accepted shape-4 raw SRVs. Over the 4,631 recorded compute requests that carry a root, your kind-16 rule confirms all 60 of ours, so I've dropped it. A separate case, a compute root SRV after the tables (52 requests, [table, table, table, SRV, constants] roots), isn't covered here. I'll open that separately once it's checked on both cards; it stacks on this PR.

Also relevant to "In game, these dispatches still need native scenes": on the 5090, 43 of the retail XboxBvhBuilder.dll's 52 compute kernels fail to compile today. They're standard DXIL calling xbox.* intrinsics (s_load_dword_with_cache, global_load_dword*_with_cache, LaneSwizzle, Med3_F32, …), which dxil-spirv can't define, plus 5 that use insertvalue, which its reader rejects. So they run as stand-ins, and in our probe runs no TLAS start address was ever written.

<!-- greyfinch-sync:brcly/TuxBox:comment:7212638472 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/302#issuecomment-7212638472). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-27T07:36:29Z. --- AMD run of this branch (2c2cec6), since the PR asks for one on a card with the full suite: - **AMD Raphael iGPU (1002:13c0), RADV, GE-Proton11-14:** full `python tuxbox.py check` passed, 135 gates. - **`tools/check_scarlett_rays.py`** on the same card, from our own recorded ProjectScarlett requests: both programs passed, 0 mismatches (`failed=0` for `CS_IrradianceCache_ShadowTrace` and `_WithFar`). - **NVIDIA** (RTX 5090, 620.70.10) is queued behind our game runs; I'll post it when it's done. **Measured evidence for commit 1** from two probe runs in ProjectScarlett's story intro on the 5090: - At dispatch, the title binds a UAV (0x28000 bytes, raw) at table 1 slot 6 for `CS_IrradianceCache_ShadowTrace_WithFar`. That's the program's own `u52`, not the title root's SRV `t333`. - Across 363 dispatched compute programs whose FSSM layout differs from their root, the title always kept the root it gave at pipeline creation (1,013 of 1,013 dispatches). In the 140 table slots where the bound view's kind could tell the two readings apart, the view matched the program's layout in all 140 and the root's in none. Overlap note: we had a reader change that also accepted shape-4 raw SRVs. Over the 4,631 recorded compute requests that carry a root, your kind-16 rule confirms all 60 of ours, so I've dropped it. A separate case, a compute root SRV after the tables (52 requests, `[table, table, table, SRV, constants]` roots), isn't covered here. I'll open that separately once it's checked on both cards; it stacks on this PR. Also relevant to "In game, these dispatches still need native scenes": on the 5090, 43 of the retail `XboxBvhBuilder.dll`'s 52 compute kernels fail to compile today. They're standard DXIL calling `xbox.*` intrinsics (`s_load_dword_with_cache`, `global_load_dword*_with_cache`, `LaneSwizzle`, `Med3_F32`, …), which dxil-spirv can't define, plus 5 that use `insertvalue`, which its reader rejects. So they run as stand-ins, and in our probe runs no TLAS start address was ever written.
NickStallman commented 2026-11-27 09:30:31 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T09:30:31Z.


Heads-up: after #303 merged, this branch conflicts with main in with_reflected_table (runtime/d3d12/src/commands/compute_bindings.rs). #303 added a heap_reads argument there and this PR adds scene. Keeping both resolved it in our local rebase; recording.rs's callers then pass both in that order, and python tuxbox.py check --no-gpu passes on the result. The NVIDIA run I mentioned is running now; I'll post it when it's done.

<!-- greyfinch-sync:brcly/TuxBox:comment:7214763317 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/302#issuecomment-7214763317). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-27T09:30:31Z. --- Heads-up: after #303 merged, this branch conflicts with main in `with_reflected_table` (`runtime/d3d12/src/commands/compute_bindings.rs`). #303 added a `heap_reads` argument there and this PR adds `scene`. Keeping both resolved it in our local rebase; `recording.rs`'s callers then pass both in that order, and `python tuxbox.py check --no-gpu` passes on the result. The NVIDIA run I mentioned is running now; I'll post it when it's done.
NickStallman commented 2026-11-27 09:51:42 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T09:51:42Z.


NVIDIA result, for the record now that this is merged: tools/check_scarlett_rays.py on an RTX 5090 (10de:2b85, driver 620.70.10, GE-Proton11-14), from our recorded ProjectScarlett requests: both programs failed=0 (CS_IrradianceCache_ShadowTrace and _WithFar).

<!-- greyfinch-sync:brcly/TuxBox:comment:7215183503 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/302#issuecomment-7215183503). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-27T09:51:42Z. --- NVIDIA result, for the record now that this is merged: `tools/check_scarlett_rays.py` on an RTX 5090 (10de:2b85, driver 620.70.10, GE-Proton11-14), from our recorded ProjectScarlett requests: both programs `failed=0` (`CS_IrradianceCache_ShadowTrace` and `_WithFar`).
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
brcly/TuxBox!302
No description provided.