xshader: lower ProjectScarlett's sun and lamp shadow walks to ray queries #306

Merged
Jerkin42 merged 5 commits from upstream-pr/306 into main 2026-11-27 12:36:16 +00:00
Jerkin42 commented 2026-11-27 11:37:21 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-27T11:37:21Z.


Summary

Follows #302: two more ProjectScarlett trace programs get their inlined console BVH walks replaced with native ray queries.

  • CS_RaytraceShadows_Mixed (sun shadows). Three first-hit walks: the near scene, then the far scene after a miss, or only the far scene when the program says so. Each becomes tbScarlettOccluded, as in #302.
  • CS_LaserLightShadowRaytracing (spot lamp shadows). The walk keeps the nearest triangle rather than stopping at the first, and the program clips each lamp's beam to that distance (plus 0.04). It becomes a new tbScarlettNearest query that returns the hit distance. Its walk uses a shared-memory stack and spills to lanes of v5. Upstream refused it ("mixed lane Wave32 cannot lower ds_write2_b32"). The Scarlett walks are now replaced before lane analysis, so that code goes with the walk. The root word the program tests for an empty scene becomes a constant; the native query handles an empty scene itself.
  • Both programs are matched by entry name, ISA size and FNV-1a of the ISA, like the irradiance programs.

Both are recorded without a root signature. The runtime translates them against the reflected root it builds from their user data, so the GPU replays declare that layout:

  • Lamp: t47 at table 0 offset 5; t371, t354, u48 (space 1) at table 1 offsets 0-2.
  • Sun: t10, t355, t405, t408, t354, t16, t330, t331 at table 1 offsets 0-7, u40 at 8, b20 at 9; b17 at table 0 offset 129; root constants b500.

Translated against the pipeline's own title root, the scene slot names a plain SRV (t240 or t346), so both stay refused there.

One known difference in the sun walk: the console walk's hit value is a word from the hit instance's record, and the program only tests it for nonzero. A hit on an instance whose word is 0 therefore counts as a miss there. The native query reports every triangle hit. That only matters if the title uses a zero word to mark instances that cast no shadow; I have not confirmed that it does.

Verified on Lanes

  • python tuxbox.py check passed on this branch. Not run: it opens windows on this desktop. The targeted replay below was run instead.
  • Changed or new behaviour is covered by a scenario: tools/check_scarlett_rays.py now replays all four programs.

GPU, driver and backend: AMD Radeon RX 9060 XT (1002:7590), RADV Mesa 26.1.8, Proton Experimental. NVIDIA still needs to run it.

tools/check_scarlett_rays.py (programs from a recorded ProjectScarlett run):

CS_IrradianceCache_ShadowTrace          failed=0 (5 scenarios)
CS_IrradianceCache_ShadowTrace_WithFar  failed=0 (12 scenarios)
CS_LaserLightShadowRaytracing           failed=0 (10 scenarios: wall, nearest of two walls in both orders,
                                        beyond beam length, behind, empty scene, half occluder,
                                        unnormalised and oblique directions, lamps masked off;
                                        worst distance error 4.8e-07)
CS_RaytraceShadows_Mixed                failed=0 (10 scenarios: near occluder, far occluder, nothing,
                                        beyond maximum, behind, half occluders in each scene,
                                        far-only mode skips the near scene)

Checks

  • cargo test for the shader compiler: 425 + 2 passed.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5525966073 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/306). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-27T11:37:21Z. --- ## Summary Follows #302: two more ProjectScarlett trace programs get their inlined console BVH walks replaced with native ray queries. - **CS_RaytraceShadows_Mixed (sun shadows).** Three first-hit walks: the near scene, then the far scene after a miss, or only the far scene when the program says so. Each becomes `tbScarlettOccluded`, as in #302. - **CS_LaserLightShadowRaytracing (spot lamp shadows).** The walk keeps the nearest triangle rather than stopping at the first, and the program clips each lamp's beam to that distance (plus 0.04). It becomes a new `tbScarlettNearest` query that returns the hit distance. Its walk uses a shared-memory stack and spills to lanes of v5. Upstream refused it ("mixed lane Wave32 cannot lower ds_write2_b32"). The Scarlett walks are now replaced before lane analysis, so that code goes with the walk. The root word the program tests for an empty scene becomes a constant; the native query handles an empty scene itself. - Both programs are matched by entry name, ISA size and FNV-1a of the ISA, like the irradiance programs. Both are recorded without a root signature. The runtime translates them against the reflected root it builds from their user data, so the GPU replays declare that layout: - Lamp: t47 at table 0 offset 5; t371, t354, u48 (space 1) at table 1 offsets 0-2. - Sun: t10, t355, t405, t408, t354, t16, t330, t331 at table 1 offsets 0-7, u40 at 8, b20 at 9; b17 at table 0 offset 129; root constants b500. Translated against the pipeline's own title root, the scene slot names a plain SRV (t240 or t346), so both stay refused there. One known difference in the sun walk: the console walk's hit value is a word from the hit instance's record, and the program only tests it for nonzero. A hit on an instance whose word is 0 therefore counts as a miss there. The native query reports every triangle hit. That only matters if the title uses a zero word to mark instances that cast no shadow; I have not confirmed that it does. ## Verified on Lanes - [ ] `python tuxbox.py check` passed on this branch. Not run: it opens windows on this desktop. The targeted replay below was run instead. - [x] Changed or new behaviour is covered by a scenario: `tools/check_scarlett_rays.py` now replays all four programs. GPU, driver and backend: AMD Radeon RX 9060 XT (1002:7590), RADV Mesa 26.1.8, Proton Experimental. NVIDIA still needs to run it. `tools/check_scarlett_rays.py` (programs from a recorded ProjectScarlett run): ```text CS_IrradianceCache_ShadowTrace failed=0 (5 scenarios) CS_IrradianceCache_ShadowTrace_WithFar failed=0 (12 scenarios) CS_LaserLightShadowRaytracing failed=0 (10 scenarios: wall, nearest of two walls in both orders, beyond beam length, behind, empty scene, half occluder, unnormalised and oblique directions, lamps masked off; worst distance error 4.8e-07) CS_RaytraceShadows_Mixed failed=0 (10 scenarios: near occluder, far occluder, nothing, beyond maximum, behind, half occluders in each scene, far-only mode skips the near scene) ``` ## Checks - `cargo test` for the shader compiler: 425 + 2 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!306
No description provided.