tombox-xshader: read the FSSM root-binding table (opt-in fallback for shaders without RTS0) #289

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

@⁠GDAgent on GitHub · 2026-11-23 13:45 UTC · original
GDAgent:feat/xshader-fssm-root-table → main · +902 −8 · 9 files · 2 commits · closed without merging

Library / area: tombox-xshader (new fssm_bind module, opt-in hook in hlsl.rs, xscan/xshader flags); one line in d3d12_xs/src/xlat_index.rs.

Exports changed: None (no DLL exports). New crate API: tombox_xshader::fssm_bind::{parse, Bindings, ...}, translate_with_fssm_root, translate_linked_with_fssm_root.

Follows the direction in #142 (opt-in fallback, the static RTS0 path stays the default) and the merged TOMBOX_INFER_ROOT_SIG fallback (#129): same switch shape, same pack-index bypass.

What the console compiler stores

Every FSSM program carries the shader's root-binding layout next to the code, whether or not the DXBC has an RTS0 chunk. Decoded from The Matrix Awakens (UE5) and checked against its RTS0 on all 35,442 shaders:

  • 0xE8 / 0xF8: parameter list ([0xE8] + 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 / 6 resource / sampler descriptor-heap base. 0xE8 = DEADBEEF means no table.
  • 0xF0 / 0xFC: resource list, one entry per descriptor the shader actually 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: 8 dwords for CBV/SRV/UAV, 4 for samplers.
  • 0xD6: user SGPR count, equal to the end of the last binding in every shader checked.
  • 0x18..0x60: exactly one hardware-stage slot is set. 0x28 (the merged ES part of a vertex shader), 0x30 (GS) and 0x58 (MS) start user data after 8 system SGPRs; 0x38 (hardware VS, including the s_swappc_b64 s4 form), 0x40 (PS) and none (CS) start at s0.

The parser is strict and refuses anything that does not fit (unknown kind, SGPR gaps, a user SGPR count that does not end at the last binding, a resource naming a parameter of another kind or slot, the same register at two table positions since there is no space field, more than one stage slot).

Change

  • fssm_bind::parse decodes the table; Bindings::root_signature builds a RootSig (one single-descriptor range per used descriptor, space 0); Bindings::disagreements compares the table with a real root signature.
  • translate_with_fssm_root / translate_linked_with_fssm_root: for a shader with no RTS0 and no caller-supplied root signature, translate with the table's root signature and the table's user-data base. With an RTS0 they call the normal path, so the output is unchanged.
  • Opt-in only: TOMBOX_FSSM_ROOT_SIG=1 makes hlsl::translate_linked use the table when no root signature is known (and it is in the xlat_index bypass list); xscan --fssm-root 1 sweeps with the fallback; xscan --fssm-check 1 re-translates every shader that has an RTS0 from its table alone and reports agreement; xshader --fssm-root 1 ignores the RTS0 and prints the decoded table.
  • Not done here: 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. The static-sampler registers could feed #183.

Evidence: The Matrix Awakens (has both RTS0 and the table)

xscan Frosty-XSX.pak --jobs 6 --fssm-check 1, 62,247 containers, 35,444 unique, 35,442 with an RTS0 (2 are root-signature-only containers):

Stage Bindings agree with RTS0 Same HLSL from table alone Only the table translates Different HLSL Both fail
VS 19,634 / 19,634 19,592 36 6 0
PS 12,271 / 12,271 12,271 0 0 0
CS 3,233 / 3,233 3,209 0 0 24
MS 192 / 192 192 0 0 0
GS 112 / 112 112 0 0 0
  • "Bindings agree": every parameter has the same kind, register and SGPR position, and every used descriptor resolves to the same range type and register in the RTS0.
  • The 36 + 6 vertex shaders are the merged ES programs (stage slot 0x28) that do not start with s_swappc_b64. Their tables are read from s16 and up, but the static path assumes s8 for vertex shaders, so it picks the wrong root parameter. The 36 are today's mubuf ...: buffer in table of kind Some(..) failures. All 42 table translations compile with DXC (vs_6_5). This PR does not change the static path. A follow-up could use the stage slot there too, which would change the output of exactly these 42 shaders.
  • The user-data base rule was also checked against the SGPRs the code reads before writing them (a crude check: every used parameter must have one of its SGPRs live at entry). Matrix: consistent on 35,242 shaders, no evidence on 199 (nothing read), 1 pixel shader not confirmed. That one still gives the same HLSL as its RTS0. The AAA title below: consistent on 24,202, no evidence on 1,182, not confirmed on 488. The ones I opened read their other parameters exactly where the rule puts them but never read one table pointer at entry, so the check cannot confirm them.

Its shaders ship without RTS0 and carry only this table. Translate-only sweep of 25,889 unique shaders (--jobs 6 --mnemonics 1): main translates 2,972 (11.5 %); with --fssm-root 1, 5,763 (22.3 %). Per stage: MS 0 -> 1,412 of 8,765, CS 5 -> 652 of 2,682, VS 671 -> 1,211 of 2,191, PS 2,101 -> 2,293 of 12,056, GS 195 -> 195 of 195. Every table in the title parses (only 17 shaders without a table remain "no root signature"). The first refusals are now mostly the parts this PR leaves out: literal static samplers (mimg ... not a sampler descriptor, 7,582, kind 4; see #183), descriptor-heap-indexed loads (mubuf ... buffer in table of kind None, 7,235, and bindless: ... is not a root parameter, 3,554; the shaders read the kind 5/6 heap-base SGPR), and v_interp_p1ll_f16 (1,595, an ISA gap that was hidden behind the binding refusal before). xscan reports only the first refusal per shader. DXC compile sample: of every 97th shader (266), 61 translate from the table and all 61 compile.

Tests

  • src/fssm_bind.rs: 6 unit tests on synthetic FSSM blobs (one table per parameter with typed uses + agreement with an engine-style RTS0, mismatch reporting, constants/descriptor/heaps/static samplers, 10 malformed layouts refused, stage slot to user-data base).
  • tests/fssm_bind.rs: a pixel shader with only a table is refused by translate and translates with the fallback (DXC compiles); the table and an equivalent unbounded RTS0 give byte-identical HLSL; a shader with an RTS0 ignores its table; missing/bad tables and a stage-slot mismatch are refused; UAV + SRV typing from the table.
  • tests/fssm_bind_env.rs: TOMBOX_FSSM_ROOT_SIG=1 switches plain translation to the table, 0/unset does not.
  • tests/mesh.rs: a mesh shader's table slot 8 lands on s16.
  • cargo test --locked -p tombox-xshader (CPU/WARP, no TOMBOX_EXEC_HW) on main f89e410 plus this branch: 358 passed, 0 failed, 18 ignored. d3d12_xs --lib xlat_index: 4 passed.

Not verified in a title

No title was run. Everything above is offline translation (and DXC compiles for the 42 shaders named above). Bindings agree with Matrix's RTS0 and the HLSL is identical where both paths translate, but the table-only output for shaders without RTS0 has not been executed on a GPU. Register spaces are assumed to be 0 because the table has no space field. Matrix only uses space 0, and the parser refuses a register that appears at two table positions. Native Windows 11; not run under Proton.

**@⁠GDAgent** on GitHub · 2026-11-23 13:45 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/289) `GDAgent:feat/xshader-fssm-root-table` → `main` · +902 −8 · 9 files · 2 commits · closed without merging **Library / area:** `tombox-xshader` (new `fssm_bind` module, opt-in hook in `hlsl.rs`, `xscan`/`xshader` flags); one line in `d3d12_xs/src/xlat_index.rs`. **Exports changed:** None (no DLL exports). New crate API: `tombox_xshader::fssm_bind::{parse, Bindings, ...}`, `translate_with_fssm_root`, `translate_linked_with_fssm_root`. Follows the direction in #142 (opt-in fallback, the static RTS0 path stays the default) and the merged `TOMBOX_INFER_ROOT_SIG` fallback (#129): same switch shape, same pack-index bypass. ### What the console compiler stores Every FSSM program carries the shader's root-binding layout next to the code, whether or not the DXBC has an RTS0 chunk. Decoded from The Matrix Awakens (UE5) and checked against its RTS0 on all 35,442 shaders: - `0xE8` / `0xF8`: parameter list (`[0xE8] + 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 / 6 resource / sampler descriptor-heap base. `0xE8 = DEADBEEF` means no table. - `0xF0` / `0xFC`: resource list, one entry per descriptor the shader actually 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: 8 dwords for CBV/SRV/UAV, 4 for samplers. - `0xD6`: user SGPR count, equal to the end of the last binding in every shader checked. - `0x18..0x60`: exactly one hardware-stage slot is set. `0x28` (the merged ES part of a vertex shader), `0x30` (GS) and `0x58` (MS) start user data after 8 system SGPRs; `0x38` (hardware VS, including the `s_swappc_b64 s4` form), `0x40` (PS) and none (CS) start at s0. The parser is strict and refuses anything that does not fit (unknown kind, SGPR gaps, a user SGPR count that does not end at the last binding, a resource naming a parameter of another kind or slot, the same register at two table positions since there is no space field, more than one stage slot). ### Change - `fssm_bind::parse` decodes the table; `Bindings::root_signature` builds a `RootSig` (one single-descriptor range per used descriptor, space 0); `Bindings::disagreements` compares the table with a real root signature. - `translate_with_fssm_root` / `translate_linked_with_fssm_root`: for a shader with no RTS0 and no caller-supplied root signature, translate with the table's root signature and the table's user-data base. With an RTS0 they call the normal path, so the output is unchanged. - Opt-in only: `TOMBOX_FSSM_ROOT_SIG=1` makes `hlsl::translate_linked` use the table when no root signature is known (and it is in the `xlat_index` bypass list); `xscan --fssm-root 1` sweeps with the fallback; `xscan --fssm-check 1` re-translates every shader that has an RTS0 from its table alone and reports agreement; `xshader --fssm-root 1` ignores the RTS0 and prints the decoded table. - Not done here: 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. The static-sampler registers could feed #183. ### Evidence: The Matrix Awakens (has both RTS0 and the table) `xscan Frosty-XSX.pak --jobs 6 --fssm-check 1`, 62,247 containers, 35,444 unique, 35,442 with an RTS0 (2 are root-signature-only containers): | Stage | Bindings agree with RTS0 | Same HLSL from table alone | Only the table translates | Different HLSL | Both fail | |---|---:|---:|---:|---:|---:| | VS | 19,634 / 19,634 | 19,592 | 36 | 6 | 0 | | PS | 12,271 / 12,271 | 12,271 | 0 | 0 | 0 | | CS | 3,233 / 3,233 | 3,209 | 0 | 0 | 24 | | MS | 192 / 192 | 192 | 0 | 0 | 0 | | GS | 112 / 112 | 112 | 0 | 0 | 0 | - "Bindings agree": every parameter has the same kind, register and SGPR position, and every used descriptor resolves to the same range type and register in the RTS0. - The 36 + 6 vertex shaders are the merged ES programs (stage slot `0x28`) that do not start with `s_swappc_b64`. Their tables are read from s16 and up, but the static path assumes s8 for vertex shaders, so it picks the wrong root parameter. The 36 are today's `mubuf ...: buffer in table of kind Some(..)` failures. All 42 table translations compile with DXC (`vs_6_5`). This PR does not change the static path. A follow-up could use the stage slot there too, which would change the output of exactly these 42 shaders. - The user-data base rule was also checked against the SGPRs the code reads before writing them (a crude check: every used parameter must have one of its SGPRs live at entry). Matrix: consistent on 35,242 shaders, no evidence on 199 (nothing read), 1 pixel shader not confirmed. That one still gives the same HLSL as its RTS0. The AAA title below: consistent on 24,202, no evidence on 1,182, not confirmed on 488. The ones I opened read their other parameters exactly where the rule puts them but never read one table pointer at entry, so the check cannot confirm them. ### Evidence: a very popular AAA title without RTS0 Its shaders ship without RTS0 and carry only this table. Translate-only sweep of 25,889 unique shaders (`--jobs 6 --mnemonics 1`): main translates 2,972 (11.5 %); with `--fssm-root 1`, 5,763 (22.3 %). Per stage: MS 0 -> 1,412 of 8,765, CS 5 -> 652 of 2,682, VS 671 -> 1,211 of 2,191, PS 2,101 -> 2,293 of 12,056, GS 195 -> 195 of 195. Every table in the title parses (only 17 shaders without a table remain "no root signature"). The first refusals are now mostly the parts this PR leaves out: literal static samplers (`mimg ... not a sampler descriptor`, 7,582, kind 4; see #183), descriptor-heap-indexed loads (`mubuf ... buffer in table of kind None`, 7,235, and `bindless: ... is not a root parameter`, 3,554; the shaders read the kind 5/6 heap-base SGPR), and `v_interp_p1ll_f16` (1,595, an ISA gap that was hidden behind the binding refusal before). xscan reports only the first refusal per shader. DXC compile sample: of every 97th shader (266), 61 translate from the table and all 61 compile. ### Tests - `src/fssm_bind.rs`: 6 unit tests on synthetic FSSM blobs (one table per parameter with typed uses + agreement with an engine-style RTS0, mismatch reporting, constants/descriptor/heaps/static samplers, 10 malformed layouts refused, stage slot to user-data base). - `tests/fssm_bind.rs`: a pixel shader with only a table is refused by `translate` and translates with the fallback (DXC compiles); the table and an equivalent unbounded RTS0 give byte-identical HLSL; a shader with an RTS0 ignores its table; missing/bad tables and a stage-slot mismatch are refused; UAV + SRV typing from the table. - `tests/fssm_bind_env.rs`: `TOMBOX_FSSM_ROOT_SIG=1` switches plain translation to the table, `0`/unset does not. - `tests/mesh.rs`: a mesh shader's table slot 8 lands on s16. - `cargo test --locked -p tombox-xshader` (CPU/WARP, no `TOMBOX_EXEC_HW`) on `main` `f89e410` plus this branch: 358 passed, 0 failed, 18 ignored. `d3d12_xs --lib xlat_index`: 4 passed. ### Not verified in a title No title was run. Everything above is offline translation (and DXC compiles for the 42 shaders named above). Bindings agree with Matrix's RTS0 and the HLSL is identical where both paths translate, but the table-only output for shaders without RTS0 has not been executed on a GPU. Register spaces are assumed to be 0 because the table has no space field. Matrix only uses space 0, and the parser refuses a register that appears at two table positions. Native Windows 11; not run under Proton.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:17:30 +00:00
github-bot closed this pull request 2026-11-26 06:17:30 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 14:28 UTC · original

Applied locally on main with your authorship kept (cherry-picked, b17ecef); the tombox-xshader suite passes in a sandbox (exec 158/158 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.

**@⁠omonkeyz** on GitHub · 2026-11-23 14:28 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/289#issuecomment-7104040745) Applied locally on main with your authorship kept (cherry-picked, b17ecef); the tombox-xshader suite passes in a sandbox (exec 158/158 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.
Author
Owner

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

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

**@⁠omonkeyz** on GitHub · 2026-11-25 13:07 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/289#issuecomment-7163327579) Applied on main in b17ecef (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.