Skip to content

d3d12_xs: slot 57 DeserializeGraphicsPipelineStateX, fspx_gfx index, and pipeline blob input layout - #8890

Open
RipcuBAN wants to merge 1 commit into
ItsNotRexed:mainfrom
RipcuBAN:feat/slot57-fspx-gfx-and-boot-findings
Open

RipcuBAN wants to merge 1 commit into
ItsNotRexed:mainfrom
RipcuBAN:feat/slot57-fspx-gfx-and-boot-findings

Conversation

@RipcuBAN

Copy link
Copy Markdown
Contributor

Summary

Adds measured support for Xbox ID3D12Device slot 57 (DeserializeGraphicsPipelineStateX, +0x1c8, measured at RVA 0x2477578) and <shaders>/fspx_gfx/index.json loading for native RDNA2 graphics stages (vs / ps / ms / gs), along with full documentation of the measured slot-57 blobs in docs/fspx.md.

Unlike slot 67 (DeserializeComputePipelineStateX at RVA 0x24800d5), which falls back to slot 62 (CreateComputePipelineState at RVA 0x247fe66) when slot 67 fails, slot 57 at RVA 0x2477578 has no fallback: on a negative HRESULT (test r14d, r14d; js 0x2477a07) it leaves the PSO entry in the title's table null, causing a null graphics PSO dereference (mov r14, [rax+0x68] at RVA 0xb5a5f8) once boot shader creation finishes and offline xgamesave initialization begins.

Measured Facts Included

  1. ShaderLibrary <shaders>/fspx_gfx/index.json loading (runtime/src/shader_library.h):

    • Extends the optional folder loop from {fspx, bvh} to {fspx, fspx_gfx, bvh}.
    • Adds fspx_gfx_size() so fspx_size() (compute fspx/), fspx_gfx_size() (graphics fspx_gfx/), and bvh_size() (bvh/) remain separate.
    • Supports optional spv filename overrides in ShaderEntry (where fspx_gfx/index.json uses the 64-character fspx_code_sha256 as the JSON key and stores <sha256[:16]>_lib(ps|vs)_<id>.spv in spv).
    • Adds PipelineState::create_graphics fallback for bare RDNA2 program blobs via library->fspx_candidates(stage.name, hash) (runtime/shims/d3d12_vulkan_device.cpp).
  2. Xbox slot 57 (DeserializeGraphicsPipelineStateX) layout (0x68 bytes, 13 qwords) (runtime/shims/d3d12_xs_device.cpp, docs/fspx.md):

    • +0x00: ID3D12RootSignature*
    • +0x08 / +0x10: state_blob (388 B in boot PSOs 1–2, 380 B in boot PSO 3; magic 0x4005d800 / 0x4005d808 / 0x4005d810)
    • +0x18 / +0x20: pipeline_blob (188 B / 0xbc in boot PSOs 1–3; contains vertex input layout)
    • +0x28 / +0x30: prog_a (native RDNA2 program Add pytest regression tests for the RDNA2 -> SPIR-V translator, plus a Linux CI job #1, or nullptr/0 in VS-only PSOs such as boot PSO 3)
    • +0x38 / +0x40: stage_a (kind-2 stage blob Add pytest regression tests for the RDNA2 -> SPIR-V translator, plus a Linux CI job #1, e.g. 208 B, or nullptr/0)
    • +0x48 / +0x50: prog_b (native RDNA2 program Vulkan tools: fix builds on Linux #2, e.g. 320..384 B)
    • +0x58 / +0x60: stage_b (kind-2 stage blob Vulkan tools: fix builds on Linux #2, e.g. 752 B)
    • Important measured correction: in the first 3 boot graphics PSOs (records 8916, 8917, 12511), pair 2 (+0x28/+0x30, 448 B / 768 B) is the pixel shader (ps) and pair 4 (+0x48/+0x50, 384 B / 320 B) is the vertex shader (vs). Stage assignment is therefore taken from entry->stage in fspx_gfx/index.json by sha256(program_bytes), never assumed from blob position.
    • Preserves PC ID3D12Device4::CreateProtectedResourceSession forwarding on slot 57 when riid != IID_ID3D12PipelineState.
  3. Measured 188 B (0xbc) pipeline blob input-layout parser & tail-truncation guard:

    • +0x10: per-element field block size (0x1c = 28 B in PSOs 1–2, 0 in PSO 3)
    • +0x38: 4 + n*28 + sum(len(name)+1) (0x70 = 112 in PSOs 1–3)
    • +0x4c: num_elements (3)
    • +0x54..: array of NUL-terminated ASCII semantic name + 7 u32s (+0x00 InputSlot, +0x04 DXGI_FORMAT, +0x08 SemanticIndex, +0x0c AlignedByteOffset).
    • Decodes POSITION (DXGI_FORMAT_R32G32B32_FLOAT @ 0), COLOR (DXGI_FORMAT_R8G8B8A8_UNORM @ 12), TEXCOORD (DXGI_FORMAT_R32G32_FLOAT @ 16).
    • Because stored pipeline blobs truncate the last 1..4 bytes of the final 28-byte block (in PSO 1, TEXCOORD at 0x9b + 9 B name + 28 B fields ends at 0xc0, truncated at 0xbc), parse_xbox_pipeline_blob_input_layout checks bounds with memchr and never reads past blob_size.
  4. Measured 380..388 B state blob offset logging:

    • Logs each measured offset once ([rt] d3d12_xs: state blob: campo sin identificar en 0x%03x = 0x%08x) without guessing unconfirmed fixed-function D3D12 state fields.

Verification

  • python -I scripts/check_no_game_data.py passed on all modified files.
  • Tested on Windows 11 with an NVIDIA GeForce RTX 3060 (device_proxy, xs_proxy_mock, d3d12_compute, d3d12_fspx_compute, root_signature, pipeline_cache_file all 100% PASS, including a PAGE_NOACCESS guard-page test on the truncated 188-byte pipeline blob and synthetic fspx / fspx_gfx / bvh index count isolation test).
  • Note: AI-assisted contribution, reviewed and tested against live boot traces and unit tests.

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Windows 11.

  • Critical boot progress fix for retail graphics PSO deserialization in
    untime/shims/d3d12_xs_device.cpp:
    • Accurately decodes 13-qword \XboxNativeGraphicsPipelineStateDesc\ for \ID3D12Device\ slot 57 (\DeserializeGraphicsPipelineStateX).
    • Correctly pairs Stage 2 (pixel shader) and Stage 4 (vertex shader) against measured boot PSOs (8916, 8917, 12511), looking up binaries via \sha256\ in <shaders>/fspx_gfx/index.json.
    • Parses 188-byte pipeline input layout safely with bounds validation, guarding against truncated final descriptors.
    • Non-intrusive logging for unconfirmed state blob offsets without inventing state assumptions.
  • \compileall, \git diff --check, and clean-room checks pass.

LGTM!

@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Reproduced a real test failure on head f1ab75aca merged onto main (867d922f0) on native Windows 11 (10.0.26300.9974, MSVC 19.44, RelWithDebInfo):

Defect

device_proxy_test fails 2 checks in the new fspx_gfx test:

  • FAIL fspx_gfx PS entry preserves stage and custom spv filename
  • FAIL fspx_gfx VS entry preserves stage and custom spv filename

Root cause

ShaderLibrary::load_index() in runtime/src/shader_library.h prepends prefix ("fspx_gfx/") to e.spv_file:

e.spv_file = prefix + spv->string;

(which load_spirv() expects when opening dir_ + "/" + entry.spv_file), whereas runtime/test/device_proxy_test.cpp asserts spv_file without the "fspx_gfx/" prefix:

ps_entry->spv_file == "9e5ffd2c6c521c03_libps_00842.spv"
vs_entry->spv_file == "160fbe4368fb1a63_libvs_00843.spv"

Steps to reproduce

  1. Merge f1ab75aca onto main (867d922f0).
  2. cmake --build runtime/build --target device_proxy_test --parallel
  3. ctest --test-dir runtime/build -R '^device_proxy$' --output-on-failure -V
  4. Observe device_proxy_test: FAILED (2 failures) on the two fspx_gfx assertions above.

AI-assisted.

@kacper-serewis

Copy link
Copy Markdown
Contributor

Offline cache coverage check on f1ab75a, before a runtime comparison. Our existing translated work folder has 26,566 root entries, a compute-only library, and no fspx_gfx/index.json. For the first three boot graphics records, none of the five distinct stage/program pairs matched a same-stage root fssm_sha256 using either the whole native program or its extracted instruction range. Across all 18,838 distinct graphics stage/program pairs, both exact-match counts were zero. These hashes cover different representations, so this only rules out direct rekeying by those two byte ranges. Does your local fspx_gfx producer also resolve the source graphics interface, and is there a reproducible command for producing the index from the player's work folder? No runtime or frame result from this comparison. AI-assisted.

@Marukooh

Copy link
Copy Markdown
Contributor

checked: Wine 11.22 / RTX 5070 Ti / NVIDIA 620.73.04, offline.

base: dd44a4b53 boot integration with #7685, #7448, #8591, #7880, #8458 and #8763, plus adapted runtime hunks from f1ab75a. shader_library CTest passes. The full private graphics catalog contains 16,684 SPIR-V-validated modules from 18,837 graphics programs attempted.

With original #8890 parsing and the five modules for the initial checks, one PSO that had translated stages reached the device but returned E_INVALIDARG for an invalid vertex attribute format. With the parser from #8754 wired to the same runtime path and the full catalog, all 10,241 slot-57 calls in that retail run reached CreateGraphicsPipelineState and returned S_OK. No missing-stage or invalid-layout message was emitted. The title still presented black at both the 45 s and 95 s screen samples. This measures PSO creation and does not validate the guessed fixed-function state or explain the remaining black frames.

AI-assisted. No game files, blobs, identifiers, images or trace lines attached.

@kacper-serewis

Copy link
Copy Markdown
Contributor

Follow-up on the first three boot graphics records: each of their five stage records resolves to exactly one source container using the library stage digest and the carved container HASH. With those source interfaces beside the local disassembly, the translator at 867d922 produced 3 VS and 2 PS modules, all five passing spirv-val. Each generated fspx_code_sha256 matches the full native program bytes independently. This gives a five-entry private fspx_gfx index for a bounded runtime comparison. Pipeline creation and presented pixels remain unmeasured with that index. AI-assisted.

@gkissel

gkissel commented Nov 23, 2026

Copy link
Copy Markdown

I'd like to test this on Linux + Wine 11.21 with a GTX 1650 Mobile (4 GB, NVIDIA, 32-wide subgroups only), on ASTROWwwW:ladder-frame + #7584 (needed under Wine to get past the startup watchdog). On that stack today the title records frames for minutes (ClearRenderTargetView every frame, 0 draws) with about 10,241 slot-57 calls unserved, so this PR is the next thing to measure there.

One question before I build: how do you generate <shaders>/fspx_gfx/ and its index.json? This PR has no tool or make_game.py step for it. The keys are fspx_code_sha256, with the spv names given as <sha256[:16]>_lib(ps|vs)_<id>.spv. Is it tools/shader_library.py --stages vs,ps,ms plus rdna2spirv.py with particular flags, or a script of your own? If it is a script, could it go into this PR (or a linked one), so that anyone with a work folder can rebuild the folder the same way?

Once I can build it, I'll post: slot-57 calls served and refused, whether the first draws appear, and how far the boot gets, 2 runs each with and without this PR.

AI-assisted. No game data.

tibzejoker added a commit to tibzejoker/Leonida that referenced this pull request Nov 23, 2026
Only the PR's own commit is applied (its branch also carries 49 newer main commits, left out). Slot 57 handler and its dispatch added beside slots 17-24 and the lease/initial-state code; in the Vulkan layer the new FSSM/FSPX lookup keeps ItsNotRexed#7417's stub_or on both 'no translated shader' paths. device_proxy_test: the fspx_gfx spv filename check expects the folder prefix the loader adds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kacper-serewis

Copy link
Copy Markdown
Contributor

@gkissel For the five-module Windows check, I used the program bytes and code_range from tools/shader_library.py, matched each stage digest via carve_digests on the dxbc work folder, and put the matching source .dxbc beside disasm/ under the same stem. These are the operations of python -I tools/shader_library.py <shaders.rpf> --out <private-library> --stages vs,ps,ms,gs --carve <work/shaders/dxbc> --disasm (I restricted my local extraction to the three records). Then python -I tools/rdna2spirv.py <private-library>/disasm --out <private-translation> --wave64-emulate --no-asm. For each validated module, retain its translator metadata, key the fspx_gfx index by its full fspx_code_sha256, and place its module at fspx_gfx/.spv. I verified that all five keys equal the full native program digest, including the prologue. This recipe is verified on those five; the full catalog and Wine result above are the other contributor's measurement. AI-assisted.

@gkissel

gkissel commented Nov 23, 2026

Copy link
Copy Markdown

Thanks @kacper-serewis, that is what I needed. I will build fspx_gfx/ that way from the whole library (vs, ps, ms and gs) once my current pipelines stage frees the machine, and then post the with/without numbers here.

AI-assisted.

@kacper-serewis

Copy link
Copy Markdown
Contributor

Windows offline retail comparison, RTX 5070 616.56, MSVC 14.50. Private boot stack at 4ecae894d plus its recorded local changes and #8890 f1ab75a. Each measured run issued 25,450 slot-57 calls. On the same instrumented executable the empty graphics index served 0 calls; adding only the five verified modules served 4. With the same five modules and #8754 at 4a04398 wired into the runtime handler, 5 calls returned S_OK. The remainder returned E_INVALIDARG in each run. Full swapchain RGB readbacks were black in all 539, 375 and 337 images respectively. One additional launch stopped before slot 57 and was excluded from this comparison. All reached runs ended at a breakpoint within the 75 s bound. These are five-module results; the full-catalog Wine run above measures a different configuration. One synthetic discrepancy on my integration: device_proxy_test fails its two custom-filename comparisons because spv_file contains the fspx_gfx/ prefix while the test expects a bare filename. Both forms can be checked independently via a real module read. AI-assisted.

@venetanji

Copy link
Copy Markdown

Checked the bare-program code-base path on f1ab75ac with a synthetic pixel shader on Linux.

A bare graphics stage with uses_code_base=true can reach E_OUTOFMEMORY with ample memory. In d3d12_vulkan_device.cpp, the bare-program fallback at line 3322 resolves the catalog entry while leaving Stage::fssm empty. Line 3370 selects the stage for code-base upload. With one such stage, if pipeline creation succeeds, line 3766 then asks arena_allocate for zero bytes, which lines 701-702 reject.

A hand-written pixel shader using s_getpc_b64 and s_load_dwordx4 to read its embedded constants produces uses_code_base=true with the normal translator. The full-program hash matches and the generated module passes spirv-val --target-env vulkan1.2. I verified the metadata and followed the return in source. Windows execution of this particular PSO remains unmeasured.

The bare graphics path needs to retain the matching native program bytes for that upload, as the compute path does. The same synthetic shader would make a regression fixture for creating a PSO and reading back its embedded constant.

AI-assisted. Synthetic input only.

@FIocker

FIocker commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

For the state blob (pair 0), which this PR records but doesn't turn into PSO state: #8507 decodes it.

  • Layouts: it is a block of GPU context register values in two layouts. VS pipelines are 380–420 B, with the layout word = 4; your 0x4005d800/08/10 are its first word. MS pipelines are 464–520 B, with the same registers 0x54 later.
  • Registers decoded: CB_BLEND0..7_CONTROL, CB_TARGET_MASK, SPI_SHADER_COL_FORMAT, CB_SHADER_MASK, SX_PS_DOWNCONVERT (format class), DB_DEPTH_CONTROL, DB_STENCIL_CONTROL, DB_STENCILREFMASK(_BF). tools/pso_state_decode.py writes the D3D12-level reading per library record.
  • Checks: over all 5,680 distinct blobs, blend-on ⇔ SX_MRTn_BLEND_OPT ≠ disabled holds in 45,440 of 45,440 (blob, target) pairs, and no blob writes depth with the test off.
  • Not decoded yet: rasterizer and topology.

One measurement that supports keying by bytes (Windows 11, RTX 5080, LEONIDA_D3D12=vulkan, #7180 for the zlib reads, own 1.0.2.1 copy; counts and indices only). On our stack the first slot-57 call is the library's graphics record 0, verbatim. Its six pairs are byte-identical to the library's:

pair contents library
state 388 B blob 93, which only record 0 uses
input layout 188 B blob 94
pair 2 PS program program 42
pair 3 its stage blob blob 95
pair 4 VS program program 43
pair 5 its stage blob blob 96

That's the same PS-first order you measured on records 8916/8917/12511. So besides the program hashes, a handler can also find the exact record, and with it the decoded blend/depth state, from the state blob's bytes. There are 5,680 distinct state blobs.

AI-assisted (Claude Code).

@MarcPique

Copy link
Copy Markdown

Windows retail integration result for f1ab75ac on an RTX 4090 (32.0.16.1656), MSVC 19.44.35228, Windows 11.

  • Integrated this route with the Decode the vertex input layout used by slot 57 #8754 input-layout parser and the existing boot stack. A local probe recorded 20,478 native program references across the slot-57 startup calls. All 1,266 distinct programs mapped to the local pipeline library. All 1,266 translated and passed spirv-val.
  • With the same runtime and only a 17-module fspx_gfx pilot index, startup created 17 slot-57 PSOs. With the complete reached index, it created 10,241 of 10,241 slot-57 PSOs, with zero slot-57 failures or lookup misses.
  • The complete index run continued into presentation and drawing. Windows Graphics Capture still showed a uniformly black client area during the frame loop. Device slot 55 was reached and still fell through to the PC CreateReservedResource1 route on this stack.

The local index used the normal translator output filenames, keyed by fspx_code_sha256. The build-tool selector used for the initial pilot is in #9054. Counts and API names only. AI-assisted.

@kacper-serewis

Copy link
Copy Markdown
Contributor

Coverage detail while building the full catalog on Windows: 12,062 of the 25,471 graphics library records reference a mesh program (10,726 MS+PS and 1,336 MS only). At f1ab75a the stage lookup can return ms, but the slot-57 handler assigns VS, PS or GS only; a resolved ms takes the same E_INVALIDARG path as a missing stage. This is a static library count, not the number of mesh records reached on boot. Separating known-but-unsupported MS from lookup misses in the counters would make full-cache results easier to interpret. AI-assisted.

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.

9 participants