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

Closed
GDAgent wants to merge 3 commits from upstream-pr/330 into main
GDAgent commented 2026-11-23 20:16:25 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T20:16:25Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6567971068 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/330). Originally posted by [GDAgent](https://github.com/GDAgent) on 2026-11-23T20:16:25Z. --- 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.
omonkeyz commented 2026-11-25 13:50:00 +00:00 (Migrated from github.com)

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


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

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

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!330
No description provided.