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

Closed
GDAgent wants to merge 2 commits from upstream-pr/289 into main
GDAgent commented 2026-11-23 13:45:58 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T13:45:58Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6560707524 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/289). Originally posted by [GDAgent](https://github.com/GDAgent) on 2026-11-23T13:45:58Z. --- **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.
omonkeyz commented 2026-11-23 14:28:01 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T14:28:01Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7104040745 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/289#issuecomment-7104040745). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T14:28:01Z. --- 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 commented 2026-11-25 13:07:36 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:07:36Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7163327579 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/289#issuecomment-7163327579). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:07:36Z. --- 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

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
omonkeyz/xbox-emulator!289
No description provided.