Repository navigation
Shaders: read the per-stage root layout of console shader containers - #2217
CharlyRien wants to merge 1 commit into
Conversation
Every FSSM stage record (at the stage descriptor - 0x40) points at two tables of 20-byte entries: the root layout (where each root argument, static sampler and descriptor-heap address sits in the program's user data) and the resources the program uses. `xbox::root_layout` reads them with every offset and count bounds-checked, and `xcl disasm` prints them under each hardware stage. Nothing else calls it yet: binding and translation are unchanged. The layout was worked out from every stage of a retail title's shader pack with a standalone decoder: all counts read in bounds, no entry type outside 0/1/3/4/5/6, and every used resource agrees with the root entry of its slot. User-data dword i is s(i) in CS, VS and PS and s(i+8) in NGG stages, checked against the disassembly of a few programs. That these tables exist and what their fields mean was first learned by reading the VIctory project's container parser (GPL-3.0) as a reference; no code was taken from it. Part of xcl-dev#697. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Full diff review on Awaiting an independent verification check (including AMD) on |
|
Independent AMD verification requested in the review discussion, on exact clean head Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M (RDNA2), driver
Paired guarded retail smoke: Same locally owned title ( Main: PR head: AI assistance: OpenAI Codex (GPT-6; exact variant not exposed) prepared and ran the checks, inspected logs and exact revisions, and drafted this report. |
Every stage of a console shader container (FSSM) carries a record that says where the program expects each root argument and the descriptor heaps' addresses in its user data, and which resources it uses. XCL does not read it today: it derives the placement from the root signature. This PR adds a bounds-checked parser for those two tables and prints them in
xcl disasm, so a placement question can be answered from the container instead of from a game run. It changes no binding or translation behaviour; nothing outsidexcl disasmcalls the parser yet.Part of #697. The type-5 / type-6 entries (view-heap and sampler-heap address) are what #1803 places after the root arguments: in the title I checked they always come right after the last argument, the view heap's first. I first posted the format on #724 (#724 (comment)).
The format (record at the stage descriptor − 0x40; offsets relative to FSSM+0x10):
u32 type | u32 offset in the table (dwords) | u32 user SGPRs | u32 base register | u8 first user-data dword | u8 root slot | u16 0. Types: 0 constants, 1 root descriptor, 3 descriptor table (one entry per range), 4 static sampler, 5 view-heap address, 6 sampler-heap address.u8 kind (0 SRV, 1 sampler, 2 CBV, 3 UAV) | u8 root type | u16 0 | u32 table offset | u32 register | u32 ? | u8 descriptor dwords | u8 first user-data dword | u8 root slot | u8 0.s(i)in CS, VS and PS stages ands(i+8)in NGG (mesh) stages.xcl disasmprints the register only for those stage types; ES / GS / LS / HS were not checked.How it was worked out: a standalone decoder over every stage of a retail title's shader pack. Every count reads in bounds, no type outside the list above appears, and every used-resource entry agrees with the root-layout entry of its slot. The NGG
+8and the CS mapping were checked against the disassembled code of a few programs. Where these tables exist and what the fields mean, I first learned from reading the container parser of the VIctory project (GPL-3.0) as a reference. No code was taken from it: the byte layout above was worked out from the data by a decoder written without its source, and this parser was written from that layout.Example output (synthetic):
What is in it
crates/xcl/src/gpu/xbox.rs:root_layout(fssm, stage) -> Result<RootLayout, String>(root slots with type, first dword and SGPR count; the view-heap and sampler-heap dwords; static sampler count; used resources),user_sgpr(hw, dword); an unreadable table (count over 4096, offset or size outside the FSSM, unknown type or kind) is an error, never a panic. Unit tests on synthetic containers: a compute layout, a mesh layout with both heaps (s23 / s24), the empty case, and the error cases (truncated table, count overflow, offset out of bounds including an offset that overflows, unknown type / kind / root type, a descriptor too close to the start).crates/xcl/src/disasm.rs:xcl disasmprints the layout under each hardware stage, and the first 8 used resources (all with--hex, as for the header dump).Tested
rustc 1.100.0 (0ef1bc386 2026-11-09).cargo build -p xcl(debug): builds, no new warning.cargo test -p xcl --lib gpu::xbox:::test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 1115 filtered out(the 3 new tests:reads_the_root_layout_of_a_compute_stage,mesh_stage_heaps_follow_the_arguments,bad_root_layouts_are_errors).xcl disasmon three containers of the retail title's pack (one CS, two MS, kept locally): the printed layouts match the standalone decoder's output.cargo test --workspace -- --test-threads=4on this head, aftercargo build --workspace: 1157 passed, 0 failed, 46 ignored (21 test binaries). SKIPPED lines:Regression run
scripts/smoke.ps1 -Game <title folder>(default 60 s), same retail title and settings, release builds. The title run does not reach the changed code (onlyxcl disasmcalls the parser), so this checks that the build does not regress, nothing more.main(568e7db):This PR's head:
Not tested
xcl shadersdoes not print the layout (left for a follow-up if wanted).xcl disasmcalls it.AI use
🤖 Generated with Claude Code