tombox-xshader: read the FSSM root-binding table (opt-in fallback for shaders without RTS0) #289
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!289
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/289/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 mergingLibrary / area:
tombox-xshader(newfssm_bindmodule, opt-in hook inhlsl.rs,xscan/xshaderflags); one line ind3d12_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_SIGfallback (#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 entrieskind, 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 = DEADBEEFmeans 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) and0x58(MS) start user data after 8 system SGPRs;0x38(hardware VS, including thes_swappc_b64 s4form),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::parsedecodes the table;Bindings::root_signaturebuilds aRootSig(one single-descriptor range per used descriptor, space 0);Bindings::disagreementscompares 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.TOMBOX_FSSM_ROOT_SIG=1makeshlsl::translate_linkeduse the table when no root signature is known (and it is in thexlat_indexbypass list);xscan --fssm-root 1sweeps with the fallback;xscan --fssm-check 1re-translates every shader that has an RTS0 from its table alone and reports agreement;xshader --fssm-root 1ignores the RTS0 and prints the decoded table.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):0x28) that do not start withs_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'smubuf ...: 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.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, andbindless: ... is not a root parameter, 3,554; the shaders read the kind 5/6 heap-base SGPR), andv_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 bytranslateand 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=1switches 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, noTOMBOX_EXEC_HW) onmainf89e410plus 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 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-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.Pull request closed