Skip to content

Shaders: read the per-stage root layout of console shader containers - #2217

Open
CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/fssm-root-layout
Open

CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/fssm-root-layout

Conversation

@CharlyRien

Copy link
Copy Markdown

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 outside xcl disasm calls 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):

  • record +0x28 / +0x30: u64 offsets of the root-layout table and the used-resource table; +0x38 / +0x3C: u32 entry counts.
  • root-layout entry, 20 bytes: 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.
  • used-resource entry, 20 bytes: 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.
  • user-data dword i is s(i) in CS, VS and PS stages and s(i+8) in NGG (mesh) stages. xcl disasm prints 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 +8 and 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):

  hardware stage: CS (API CS) – descriptor @ +0x100
    root layout: slot 0 table ×1 @ dw4 (s4), slot 1 constants ×2 @ dw5 (s5), view heap @ dw7 (s7), 2 static samplers
    uses Srv via table slot 0 @ dw4 (s4), table +8 dw, register 0x2, descriptor 8 dw

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 disasm prints the layout under each hardware stage, and the first 8 used resources (all with --hex, as for the header dump).

Tested

  • NVIDIA GeForce RTX 3090 24 GB (driver 616.56), AMD Ryzen 9 5950X, Windows 11 22631, 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 disasm on 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=4 on this head, after cargo build --workspace: 1157 passed, 0 failed, 46 ignored (21 test binaries). SKIPPED lines:
    SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64
    SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64
    SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64
    SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu: const_mask, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))
    SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))
    SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu: f64, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))
    SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu: mask_ff0_flbit, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64
    SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64
    SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
    SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
    SKIPPED shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): L’application a demandé une opération qui dépend d’un composant absent ou incompatible du Kit de développement logiciel (SDK). (0x887A002D)
    SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
    

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 (only xcl disasm calls the parser), so this checks that the build does not regress, nothing more.

main (568e7db):

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1337 (PresentX 1337)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16306 MB

This PR's head:

xcl-smoke v1
commit: f3b66bd1cafd924ea354b9780734fddc7aeca159
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1499 (PresentX 1499)
presents per 2 s (last 3): 61 60 59
device removals: 0
crashes: 0
peak commit: 15097 MB

Not tested

  • The register mapping of ES / GS / LS / HS stages (printed as dwords only).
  • FSPX (ACCC) containers: the title's pack has none.
  • Titles other than the one whose pack was decoded.
  • xcl shaders does not print the layout (left for a follow-up if wanted).
  • The regression run does not reach the parser: only xcl disasm calls it.

AI use

  • Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 writing the code and tests). The format was decoded offline by an agent of the same session with its own Python decoder; the description was drafted by the tool and checked by me.

🤖 Generated with Claude Code

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>
@raylitebull

Copy link
Copy Markdown
Member

Full diff review on f3b66bd (crates/xcl/src/gpu/xbox.rs, crates/xcl/src/disasm.rs) looks clean: bounds-checked root_layout() / user_sgpr() with no binding/translation changes and 3 solid synthetic tests, and CI is green.

Awaiting an independent verification check (including AMD) on f3b66bd before merge.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent AMD verification requested in the review discussion, on exact clean head f3b66bd1cafd924ea354b9780734fddc7aeca159 and main 568e7db7729c8fa6c8f0f4b32d798faaf11462bb.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M (RDNA2), driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5; XCL_ADAPTER=6800M.

  • cargo build --locked --workspace -j 2 and cargo build --release --locked -p xcl -j 2: passed.
  • cargo test --locked -p xcl --lib -j 2 gpu::xbox:: -- --test-threads=1 --show-output: 12 passed, 0 failed, 0 ignored; includes the three new root-layout tests.
  • xcl disasm (debug binary) on three locally extracted, owned console shader containers (CS, MS, PS): exit 0 for each; each printed one root layout: line, none printed root layout: not readable; CS and MS each printed eight resource lines (the default display cap), PS printed one. This checks real container parsing and output, not independent validation of every field's meaning. The private blobs and full disassembly stay local; none are attached.
  • cargo test --locked --workspace --no-fail-fast -- --test-threads=4: across 21 targets, 996 passed, 161 failed, 46 ignored, six explicit SKIPPED lines. The failing library target contains the RX 6800M's D3D12 device-suspension cluster (0x887A0005); the full suite is not green on this driver.

Paired guarded retail smoke: Same locally owned title (title: 2ef5fd64), release binaries, 12 seconds, separate fresh XCL data/DXIL caches, networking off. Neither run hit the external memory guard. Only xcl disasm calls the new parser, so the title run is a build regression check, not parser coverage.

Main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 12
exit: 0x0
frames shown: 107 (PresentX 107)
presents per 2 s (last 3): 1 46 60
device removals: 0
crashes: 0
peak commit: 8156 MB

PR head:

xcl-smoke v1
commit: f3b66bd1cafd924ea354b9780734fddc7aeca159
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 12
exit: 0x0
frames shown: 109 (PresentX 109)
presents per 2 s (last 3): 0 48 60
device removals: 0
crashes: 0
peak commit: 8189 MB

AI assistance: OpenAI Codex (GPT-6; exact variant not exposed) prepared and ran the checks, inspected logs and exact revisions, and drafted this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants