xshader: fetch compute samplers from the sampler heap at a run-time offset #31

Manually merged
github merged 1 commit from gh-pr/31/head into gh-pr/31/base 2026-11-26 06:26:29 +00:00
Owner

@⁠NathansDomainSolutions on GitHub · 2026-11-24 05:03 UTC · original
NathansDomainSolutions:fix/sload-dynamic-soffset → main · +38 −1 · 1 files · 1 commits · merged 2026-11-24 05:06 UTC

Refs #16.

CS_RaytracingResolve and its variants pick a sampler per material:

  • They read an index from a constant buffer and shift it by 4 (sampler descriptors are 16 bytes).
  • Inside a waterfall loop, they s_load_dwordx4 from the directly indexed compute sampler heap (FSSM user class 6, root flags 0xc00, the SamplerHeapIndexing feature bit).

xshader refused these with s_load at …: dynamic soffset unsupported.

This PR translates that load as a sampler-heap index (soff >> 4) and samples with SamplerDescriptorHeap[NonUniformResourceIndex(i)]. The static compute sampler-heap path already uses guest indices directly, and this follows the same convention. The waterfall around the load is emulated as before.

Corpus check (9,102 recorded ProjectScarlett requests, host xshader built from main vs. this branch):

  • 81 compute shaders no longer stop at this s_load.
  • +20 translate. All 20 compile with DXC (cs_6_6), both optimised and at -O0, and pass DXV.
  • The other 61 now stop at later gaps: 54 at wave reductions in divergent control flow, 7 at a MUBUF load with a dynamic SOFFSET.
  • 0 regressions, and no HLSL change for any request that already translated.
  • cargo test for the shader compiler passes.

Not tested in game.

Most dynamic soffset refusals are vertex-shader ResourceDescriptorHeap fetches, not this case. A separate change on fix/vs-resource-heap handles those.

AI disclosure: written with Claude Code; verified with the corpus diff and DXC/DXV validation above.

🤖 Generated with Claude Code

**@⁠NathansDomainSolutions** on GitHub · 2026-11-24 05:03 UTC · [original](https://github.com/brcly/TuxBox/pull/31) `NathansDomainSolutions:fix/sload-dynamic-soffset` → `main` · +38 −1 · 1 files · 1 commits · merged 2026-11-24 05:06 UTC Refs #16. `CS_RaytracingResolve` and its variants pick a sampler per material: - They read an index from a constant buffer and shift it by 4 (sampler descriptors are 16 bytes). - Inside a waterfall loop, they `s_load_dwordx4` from the directly indexed compute sampler heap (FSSM user class 6, root flags `0xc00`, the SamplerHeapIndexing feature bit). xshader refused these with `s_load at …: dynamic soffset unsupported`. This PR translates that load as a sampler-heap index (`soff >> 4`) and samples with `SamplerDescriptorHeap[NonUniformResourceIndex(i)]`. The static compute sampler-heap path already uses guest indices directly, and this follows the same convention. The waterfall around the load is emulated as before. **Corpus check** (9,102 recorded ProjectScarlett requests, host xshader built from `main` vs. this branch): - 81 compute shaders no longer stop at this `s_load`. - **+20 translate.** All 20 compile with DXC (`cs_6_6`), both optimised and at `-O0`, and pass DXV. - The other 61 now stop at later gaps: 54 at wave reductions in divergent control flow, 7 at a MUBUF load with a dynamic SOFFSET. - 0 regressions, and no HLSL change for any request that already translated. - `cargo test` for the shader compiler passes. Not tested in game. Most `dynamic soffset` refusals are vertex-shader `ResourceDescriptorHeap` fetches, not this case. A separate change on `fix/vs-resource-heap` handles those. AI disclosure: written with Claude Code; verified with the corpus diff and DXC/DXV validation above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CS_RaytracingResolve picks a sampler per material: the index from a
constant buffer is shifted by 4 (16-byte sampler descriptors) and read
from the directly indexed compute sampler heap (FSSM class 6, root flag
0x800) inside a waterfall loop. Translate that s_load as a sampler-heap
index and sample with SamplerDescriptorHeap[NonUniformResourceIndex(i)],
as the static sampler-heap path already does with guest indices.

Over 9,102 recorded ProjectScarlett requests: 81 compute shaders no
longer stop at this s_load; 20 now translate (all compile and validate
with DXC/DXV), 0 regressions, and no previously translated output changes.

Refs #16

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:26:26 +00:00
github manually merged commit ebd3022caf into gh-pr/31/base 2026-11-26 06:26:29 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.