tombox-xshader: map root Constants parameter values onto user SGPRs on Scarlett static path #170

Closed
github-bot wants to merge 1 commit from gh-pr/170/head into gh-pr/170/base
Owner

@⁠adriaespii on GitHub · 2026-11-22 17:37 UTC · original
adriaespii:contrib/scarlett-root-constant-sgpr → main · +282 −8 · 5 files · 1 commits · closed without merging

Summary

Fixes the blocker entry recorded in docs/BLOCKERS.md: "RTS0 root-constant user SGPRs on the static Scarlett path (tombox-xshader, all titles)" (repro reported in #158).

What

  • On the static Scarlett path (!self.dg().is_some() && !self.rootmem()), shaders reading user SGPRs corresponding to root Constants parameters were previously translated with zero-initialized SGPR declarations (uint s8 = 0u;), never loading the bound 32-bit root constant values.
  • In hlsl.rs, added static_sgpr_init(&mut self) -> String to iterate root parameters starting from self.user_base() (4 for CS, 16 for MS, 22 for GS, 8 for PS/VS). For RootParamKind::Constants { num32, .. }, each live user SGPR s{at + i} is initialized from tb_rc{p}_{i}, registering p in self.rm_used and the SGPR in self.regs.
  • Wired static_init into the entry prologues of compute, graphics (VS, PS, GS), mesh (finish_mesh), and amplification (finish_amp) stages.
  • Added a synthetic test root_constant_user_sgprs_read_bound_values in tests/exec_mem/user_data.rs executing on WARP: reads s8..s11 with RTS0 having [Constants num32=4], binds root 32-bit constants, and verifies that pixel outputs receive the bound constants instead of zeros.
  • Updated docs/BLOCKERS.md to mark this entry fixed.

Verification

  • Passed .github/scripts/pr_gate.py --base upstream/main --head HEAD (5 files checked, 0 problems).
  • Passed cargo test -p tombox-xshader --test exec (98 passed, 0 failed, 2 ignored).
**@⁠adriaespii** on GitHub · 2026-11-22 17:37 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/170) `adriaespii:contrib/scarlett-root-constant-sgpr` → `main` · +282 −8 · 5 files · 1 commits · closed without merging ## Summary Fixes the blocker entry recorded in `docs/BLOCKERS.md`: **"RTS0 root-constant user SGPRs on the static Scarlett path (tombox-xshader, all titles)"** (repro reported in #158). ## What - On the static Scarlett path (`!self.dg().is_some() && !self.rootmem()`), shaders reading user SGPRs corresponding to root `Constants` parameters were previously translated with zero-initialized SGPR declarations (`uint s8 = 0u;`), never loading the bound 32-bit root constant values. - In `hlsl.rs`, added `static_sgpr_init(&mut self) -> String` to iterate root parameters starting from `self.user_base()` (4 for CS, 16 for MS, 22 for GS, 8 for PS/VS). For `RootParamKind::Constants { num32, .. }`, each live user SGPR `s{at + i}` is initialized from `tb_rc{p}_{i}`, registering `p` in `self.rm_used` and the SGPR in `self.regs`. - Wired `static_init` into the entry prologues of compute, graphics (VS, PS, GS), mesh (`finish_mesh`), and amplification (`finish_amp`) stages. - Added a synthetic test `root_constant_user_sgprs_read_bound_values` in `tests/exec_mem/user_data.rs` executing on WARP: reads `s8..s11` with RTS0 having `[Constants num32=4]`, binds root 32-bit constants, and verifies that pixel outputs receive the bound constants instead of zeros. - Updated `docs/BLOCKERS.md` to mark this entry fixed. ## Verification - Passed `.github/scripts/pr_gate.py --base upstream/main --head HEAD` (5 files checked, 0 problems). - Passed `cargo test -p tombox-xshader --test exec` (98 passed, 0 failed, 2 ignored).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:33 +00:00
github-bot closed this pull request 2026-11-26 06:12:34 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 17:48 UTC · original

Thanks for picking this up so quickly. The approach is right, and the Durango early return keeps Xbox One titles byte-identical. Two things are needed before it can land:

  1. Use the shared layout code. static_sgpr_init computes each parameter's first SGPR with its own loop (a table counts 1, a descriptor 2, constants num32). The rest of the translator uses root_param_at() / user_base(). Please derive the offsets from those so the two can't drift apart. If that isn't practical, add a unit test that builds mixed root signatures and asserts your offsets equal root_param_at() for every parameter. Cover table + root CBV + Constants num32=3 + root SRV + Constants num32=5, plus a case where Constants come first.
  2. A real multi-parameter test. Add an exec test with two Constants parameters behind a table and a root descriptor, where the PS reads SGPRs from both and the bound values come back. Then the BLOCKERS line can say multi-parameter layouts are covered. I'll fix the BLOCKERS wording to match whatever the tests cover.

No conflict with the opt-in user-data path from #158: that path only runs for shaders without a root signature, and yours only runs with one. Once it's updated I'll apply it with your authorship kept.

**@⁠omonkeyz** on GitHub · 2026-11-22 17:48 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/170#issuecomment-7083116557) Thanks for picking this up so quickly. The approach is right, and the Durango early return keeps Xbox One titles byte-identical. Two things are needed before it can land: 1. **Use the shared layout code.** `static_sgpr_init` computes each parameter's first SGPR with its own loop (a table counts 1, a descriptor 2, constants `num32`). The rest of the translator uses `root_param_at()` / `user_base()`. Please derive the offsets from those so the two can't drift apart. If that isn't practical, add a unit test that builds mixed root signatures and asserts your offsets equal `root_param_at()` for every parameter. Cover table + root CBV + Constants num32=3 + root SRV + Constants num32=5, plus a case where Constants come first. 2. **A real multi-parameter test.** Add an exec test with two Constants parameters behind a table and a root descriptor, where the PS reads SGPRs from both and the bound values come back. Then the BLOCKERS line can say multi-parameter layouts are covered. I'll fix the BLOCKERS wording to match whatever the tests cover. No conflict with the opt-in user-data path from #158: that path only runs for shaders without a root signature, and yours only runs with one. Once it's updated I'll apply it with your authorship kept.
Author
Owner

@⁠adriaespii on GitHub · 2026-11-22 18:04 UTC · original

@⁠omonkeyz Thanks for the clear feedback and guidance!

I've updated the implementation and tests to address both points:

  1. Shared layout code & offset derivation:

    • Updated \static_sgpr_init\ to derive parameter and word offsets directly using the shared \self.root_param_at(sgpr, base)\ helper starting from \ase = self.user_base(). This ensures that user SGPR initialization is strictly coupled with
      oot_param_at\ without duplicating any offset counting logic.
    • Added \mixed_root_layout_initialises_constants_sgprs\ unit test in \ ests/exec_mem/user_data.rs\ testing mixed root signatures:
      • \ able + root CBV + Constants num32=3 + root SRV + Constants num32=5, asserting that \s11..s13\ map to \ b_rc2_0..2\ and \s16..s20\ map to \ b_rc4_0..4.
      • Constants-first case (\Constants num32=2 + Table), asserting that \s8..s9\ map to \ b_rc0_0..1.
  2. Multi-parameter execution test:

    • Added \multi_param_root_constant_user_sgprs_read_bound_values\ running under WARP with a root signature consisting of a descriptor table, a root CBV descriptor, and two distinct Constants parameters (
      egister=1\ and
      egister=2).
    • The pixel shader reads \s11..s14\ across both Constants parameters and asserts that the bound values ([0x11112222, 0x33334444, 0x55556666, 0x77778888]) are returned correctly.
    • All tests in \ ombox-xshader --test exec\ pass cleanly under WARP.
    • Verified with \pr_gate.py\ (0 problems, comment-free).

Ready for re-review whenever you have a chance!

**@⁠adriaespii** on GitHub · 2026-11-22 18:04 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/170#issuecomment-7083322745) @⁠omonkeyz Thanks for the clear feedback and guidance! I've updated the implementation and tests to address both points: 1. **Shared layout code & offset derivation:** - Updated \static_sgpr_init\ to derive parameter and word offsets directly using the shared \self.root_param_at(sgpr, base)\ helper starting from \ase = self.user_base()\. This ensures that user SGPR initialization is strictly coupled with \ oot_param_at\ without duplicating any offset counting logic. - Added \mixed_root_layout_initialises_constants_sgprs\ unit test in \ ests/exec_mem/user_data.rs\ testing mixed root signatures: - \ able + root CBV + Constants num32=3 + root SRV + Constants num32=5\, asserting that \s11..s13\ map to \ b_rc2_0..2\ and \s16..s20\ map to \ b_rc4_0..4\. - Constants-first case (\Constants num32=2 + Table\), asserting that \s8..s9\ map to \ b_rc0_0..1\. 2. **Multi-parameter execution test:** - Added \multi_param_root_constant_user_sgprs_read_bound_values\ running under WARP with a root signature consisting of a descriptor table, a root CBV descriptor, and two distinct Constants parameters (\ egister=1\ and \ egister=2\). - The pixel shader reads \s11..s14\ across both Constants parameters and asserts that the bound values (\[0x11112222, 0x33334444, 0x55556666, 0x77778888]\) are returned correctly. - All tests in \ ombox-xshader --test exec\ pass cleanly under WARP. - Verified with \pr_gate.py\ (0 problems, comment-free). Ready for re-review whenever you have a chance!
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 18:26 UTC · original

Applied in 23505f0 (merged in f0213ec) with your authorship kept, thanks. The offsets now come from root_param_at(), and the mixed-layout and multi-parameter WARP tests cover what the BLOCKERS entry says. It conflicted with #172 in finish_mesh, which #172 split into one-pass and two-pass branches. I resolved it by adding your static_init after ud_init() in both branches.

**@⁠omonkeyz** on GitHub · 2026-11-22 18:26 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/170#issuecomment-7083609686) Applied in 23505f0 (merged in f0213ec) with your authorship kept, thanks. The offsets now come from `root_param_at()`, and the mixed-layout and multi-parameter WARP tests cover what the BLOCKERS entry says. It conflicted with #172 in `finish_mesh`, which #172 split into one-pass and two-pass branches. I resolved it by adding your `static_init` after `ud_init()` in both branches.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.