tombox-xshader: take the user-data base from the FSSM stage slot #330

Closed
github-bot wants to merge 3 commits from gh-pr/330/head into gh-pr/330/base
Owner

@⁠GDAgent on GitHub · 2026-11-23 20:16 UTC · original
GDAgent:feat/xshader-fssm-stage-user-base → main · +955 −10 · 9 files · 3 commits · closed without merging

Stacked on #289 (head 714efcc); only 12902f3 belongs to this PR. Please review git diff 714efcc.. until #289 lands; I will rebase onto main then.
Library / area: tombox-xshader (hlsl.rs, translate_linked_with).

Exports changed: None.

Builds on #289. Unlike #289's fallback, this changes the default path, but only when a shader's FSSM table parses and agrees with its root signature.

Problem

The static root-signature path guesses the first user-data SGPR from the API stage: VS s8, GS s22, MS s16, CS s4, or s_swappc_b64 target + 7. A vertex shader compiled as the ES half of a merged ES/GS program (hardware stage slot 0x28) without s_swappc_b64 receives user data after 8 system SGPRs. The guess of s8 then names the wrong root parameter. On The Matrix Awakens this hits 42 vertex shaders (#289's --fssm-check sweep):

  • 36 refuse with mubuf ...: buffer in table of kind Some(..);
  • 6 translate silently against the wrong parameter.

Change

fssm_user_base(ex): if the shader has a root signature (RTS0 or the PSO root signature passed at runtime), its FSSM table parses, Bindings::disagreements is empty (same parameter kinds, registers, SGPR layout and used descriptors), and the hardware stage slot is known, the user-data base is first slot + system SGPRs from the table (8 for slots 0x28/0x30/0x58, 0 for 0x38/0x40/compute). Otherwise the old guess and its s_swappc retry stay unchanged. No new switch: the table must agree with the root signature, so it only replaces a guess with the layout the console compiler recorded.

Evidence

  • #289's Matrix sweep: the table agrees with RTS0 on all 35,442 shaders and gives identical HLSL wherever the base is the same. The 42 shaders above differ only in the base, and all 42 table translations compile with DXC vs_6_5.
  • This branch on Matrix, full translate-only comparison of the HLSL hash of every unique shader against #289 (714efcc): 35,442 shaders compared; 35,376 byte-identical, 36 failing before and translating now, 6 translating before and changed, 24 failing in both with the same message. No shader that translated before fails now. Translated 35,382 -> 35,418 (99.83% -> 99.93%); all 36 mubuf ...: buffer in table of kind Some(..) refusals are gone, the remaining 26 are unrelated (ds_permute with LDS, constant-buffer MUBUF forms, no DXIL chunk). All 42 changed shaders are vertex shaders.
  • No effect on the AAA title offline (no RTS0). At runtime its PSO root signatures would take the table base when they agree.

Tests

  • tests/fssm_bind.rs:
    • merged_es_vertex_shader_reads_user_data_where_the_stage_slot_puts_it: slot 0x28, table at slot 8, RTS0 with one SRV table; the load from s[16:17] binds register(t0), and DXC compiles it.
    • without_an_agreeing_table_the_static_guess_stays: hardware-VS slot, no table, or a root signature with an extra parameter all keep the old refusal buffer in table of kind None.
  • cargo test --locked -p tombox-xshader --test fssm_bind: 7/7. Full cargo test --locked -p tombox-xshader --no-fail-fast (debug, native Windows 11): 360 passed, 0 failed, 18 ignored (lib 122/0/3, tests/exec.rs 128/0/2).
  • PR gate against #289's head (714efcc): 0 problems.

Not verified in a title

No title was run; offline translation only. GS (0x30) and MS (0x58) shaders on Matrix already gave identical HLSL from the table and from the guess. AAA GS shaders would get base 8 + slot instead of 22 at runtime, which is unverified. HS/DS/AS stage slots have never been seen, and their shaders keep the guess (an unknown slot makes Bindings::user_base return an error, which falls back). Native Windows 11; not run under Proton.

Merge notes

No conflict with #278 (merged vertex shader seeding) or #302. #183 touches tests/synthetic.rs only.

**@⁠GDAgent** on GitHub · 2026-11-23 20:16 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/330) `GDAgent:feat/xshader-fssm-stage-user-base` → `main` · +955 −10 · 9 files · 3 commits · closed without merging Stacked on #289 (head `714efcc`); only `12902f3` belongs to this PR. Please review `git diff 714efcc..` until #289 lands; I will rebase onto `main` then. **Library / area:** `tombox-xshader` (`hlsl.rs`, `translate_linked_with`). **Exports changed:** None. Builds on #289. Unlike #289's fallback, this changes the default path, but only when a shader's FSSM table parses and agrees with its root signature. ### Problem The static root-signature path guesses the first user-data SGPR from the API stage: VS s8, GS s22, MS s16, CS s4, or `s_swappc_b64` target + 7. A vertex shader compiled as the ES half of a merged ES/GS program (hardware stage slot `0x28`) without `s_swappc_b64` receives user data after 8 system SGPRs. The guess of s8 then names the wrong root parameter. On The Matrix Awakens this hits 42 vertex shaders (#289's `--fssm-check` sweep): - 36 refuse with `mubuf ...: buffer in table of kind Some(..)`; - 6 translate silently against the wrong parameter. ### Change `fssm_user_base(ex)`: if the shader has a root signature (RTS0 or the PSO root signature passed at runtime), its FSSM table parses, `Bindings::disagreements` is empty (same parameter kinds, registers, SGPR layout and used descriptors), and the hardware stage slot is known, the user-data base is `first slot + system SGPRs` from the table (8 for slots `0x28`/`0x30`/`0x58`, 0 for `0x38`/`0x40`/compute). Otherwise the old guess and its `s_swappc` retry stay unchanged. No new switch: the table must agree with the root signature, so it only replaces a guess with the layout the console compiler recorded. ### Evidence - #289's Matrix sweep: the table agrees with RTS0 on all 35,442 shaders and gives identical HLSL wherever the base is the same. The 42 shaders above differ only in the base, and all 42 table translations compile with DXC `vs_6_5`. - This branch on Matrix, full translate-only comparison of the HLSL hash of every unique shader against #289 (`714efcc`): 35,442 shaders compared; 35,376 byte-identical, 36 failing before and translating now, 6 translating before and changed, 24 failing in both with the same message. No shader that translated before fails now. Translated 35,382 -> 35,418 (99.83% -> 99.93%); all 36 `mubuf ...: buffer in table of kind Some(..)` refusals are gone, the remaining 26 are unrelated (ds_permute with LDS, constant-buffer MUBUF forms, no DXIL chunk). All 42 changed shaders are vertex shaders. - No effect on the AAA title offline (no RTS0). At runtime its PSO root signatures would take the table base when they agree. ### Tests - `tests/fssm_bind.rs`: - `merged_es_vertex_shader_reads_user_data_where_the_stage_slot_puts_it`: slot `0x28`, table at slot 8, RTS0 with one SRV table; the load from s[16:17] binds `register(t0)`, and DXC compiles it. - `without_an_agreeing_table_the_static_guess_stays`: hardware-VS slot, no table, or a root signature with an extra parameter all keep the old refusal `buffer in table of kind None`. - `cargo test --locked -p tombox-xshader --test fssm_bind`: 7/7. Full `cargo test --locked -p tombox-xshader --no-fail-fast` (debug, native Windows 11): 360 passed, 0 failed, 18 ignored (lib 122/0/3, `tests/exec.rs` 128/0/2). - PR gate against #289's head (`714efcc`): 0 problems. ### Not verified in a title No title was run; offline translation only. GS (`0x30`) and MS (`0x58`) shaders on Matrix already gave identical HLSL from the table and from the guess. AAA GS shaders would get base 8 + slot instead of 22 at runtime, which is unverified. HS/DS/AS stage slots have never been seen, and their shaders keep the guess (an unknown slot makes `Bindings::user_base` return an error, which falls back). Native Windows 11; not run under Proton. ### Merge notes No conflict with #278 (merged vertex shader seeding) or #302. #183 touches `tests/synthetic.rs` only.
The console shader compiler stores the shader's root-binding layout inside
the FSSM container, next to the code, whether or not the DXBC carries an
RTS0 chunk. fssm_bind::parse reads it:

- 0xE8 / 0xF8: parameter list (pointer + 0x10, count), 5-dword entries
  (kind, dword offset, count, register, param << 8 | user-data slot).
  Kinds: 0 root constants (count = num32), 1 root descriptor (2 SGPRs),
  3 descriptor table, 4 static sampler (index, register), 5 resource heap
  base, 6 sampler heap base. 0xE8 = DEADBEEF means no table.
- 0xF0 / 0xFC: resource list, one entry per descriptor the shader uses:
  (source << 8 | class, dword offset in the table, register, byte stride,
  param << 16 | slot << 8 | descriptor dwords). Class 0 SRV, 1 sampler,
  2 CBV, 3 UAV (not the D3D12 range order). Table strides are 8 dwords for
  CBV/SRV/UAV and 4 for samplers.
- 0xD6: user SGPR count; it equals the end of the last binding.
- 0x18..0x60: exactly one hardware-stage slot is set. 0x28 (merged ES
  part of a vertex shader), 0x30 (GS) and 0x58 (MS) start user data after
  8 system SGPRs; 0x38 (hardware VS), 0x40 (PS) and none (CS) at s0.

The parser refuses anything that does not fit: unknown kinds, gaps in the
SGPR layout, a user SGPR count that does not end at the last binding,
resources that name a parameter of another kind or slot, and a register
used at two table positions (the table has no register space field).

Bindings::root_signature builds a RootSig with one single-descriptor range
per used descriptor (space 0); Bindings::disagreements compares the table
with a real root signature.

Evidence (The Matrix Awakens, all 35,442 shaders with an RTS0, native
Windows 11, CPU only): every table parses, covers every RTS0 parameter,
and every used descriptor resolves to the same range type and register in
the RTS0. The stage-slot rule matches the SGPRs the code reads in every
shader where that can be checked.
translate_with_fssm_root / translate_linked_with_fssm_root translate a
shader that has no RTS0 (and no root signature supplied by the caller)
with the root signature built from its FSSM binding table, placing the
first parameter at the user-data base the table gives. Shaders with a
root signature are translated exactly as before.

Opt-in only:
- TOMBOX_FSSM_ROOT_SIG=1 makes hlsl::translate_linked use the table when
  no root signature is known (added to the d3d12_xs translation-index
  bypass list like TOMBOX_INFER_ROOT_SIG);
- xscan --fssm-root 1 sweeps an archive with the fallback;
- xscan --fssm-check 1 translates every shader that has an RTS0 a second
  time from its table alone and reports agreement and HLSL differences;
- xshader --fssm-root 1 ignores the RTS0 and prints the decoded table.

Static samplers (kind 4) and descriptor-heap bases (kinds 5/6) are parsed
and reported, but the translator still refuses literal samplers and
heap-indexed loads; those need their own work.

Matrix Awakens cross-check (xscan --fssm-check 1, 35,442 shaders with an
RTS0): see the PR description for the per-stage table.
The static root-signature path guesses where user data starts from the
API stage (VS s8, GS s22, MS s16, CS s4, s_swappc target + 7). A
merged ES vertex shader without s_swappc gets user data at s8 + slot,
not at s8, so the guess reads its root parameters from the wrong SGPRs:
some refuse ("buffer in table of kind ..."), others translate against
the wrong parameter.

The FSSM header names the hardware stage, and the root-binding table
gives each parameter's user-data slot. When a shader has a root
signature and its FSSM table parses and agrees with it (same
parameters, registers and used descriptors), the user-data base now
comes from the table. Without a table, or when the table disagrees,
the old guess and its s_swappc retry stay.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:19:10 +00:00
github-bot closed this pull request 2026-11-26 06:19:10 +00:00
Author
Owner

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

Applied on main in b96523a (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:50 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/330#issuecomment-7164356045) Applied on main in b96523a (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

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