Skip to content

Runtime and build: compute PSOs from the FidelityFX DLL's FSPX programs, at slot 62 and from a bare kind-6 program (RT-99) - #1911

Merged
ItsNotRexed merged 6 commits into
ItsNotRexed:mainfrom
aslan2142:rt-99-fspx-runtime
Nov 22, 2026
Merged

ItsNotRexed merged 6 commits into
ItsNotRexed:mainfrom
aslan2142:rt-99-fspx-runtime

Conversation

@aslan2142

@aslan2142 aslan2142 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-99 (the run-time part, after the split agreed on #1714)

What and why

The FidelityFX DLL creates its compute pipelines from FSPX programs (docs/fspx.md). On main both of its paths end in E_INVALIDARG for all 29 programs: the layer accepts only FSSM bytecode, the build never translates the DLL, and the index has no key for these programs. This adds everything the real call needs behind CreateComputePipelineState. Two paths now resolve for every program the build translates:

Build (make_game.py, tools/shader_meta.py)

  • The shaders stage now has an FSPX step after the game's own shaders: tools/fspx_unpack.py --disasm (the unpacker from FSPX: unpack the FidelityFX DLL's native compute programs for the translator (13 of 29 translate) #1661) on the package's DLL into <work>/shaders/fspx/, then rdna2spirv.py into <work>/shaders/spirv/fspx/, with the same --wave64-emulate and fallback flags.
  • Each entry of a program without an FSSM blob gets fspx_code_sha256: the SHA-256 of its whole kind-6 entry, the bytes the layer receives.
  • The step is resumable like its neighbours: it counts as done when spirv/fspx/index.json exists and fspx_build.json, written after it, matches the DLL, the tools, llvm-mc, the wave64 mode and the flags. It never makes the game's shaders run again. A package without the DLL skips it.
  • One side effect: shader_meta.py is one of the translator sources, so an existing work folder translates the game's shaders once more. Its output is unchanged (measured below).

Run time (runtime/src/shader_library.h, create_compute)

  • ShaderLibrary::load also reads <dir>/fspx/index.json when it is there, with entries named fspx/<name>. A missing or broken one leaves the main index loaded.
  • Entries are findable by fspx_code_sha256, in a table separate from fssm_sha256. Each entry also carries fspx_state_sha256, the SHA-256 of its kind-0 entry.
  • Two programs with the same kind-6 bytes and different dispatch state (found in review by @Vonsek) are told apart by that second key when the input carries kind 0 (the slot-62 container, a bare payload). A bare kind-6 program whose candidates are different modules is refused with E_INVALIDARG, not resolved to one of them. The build fails if two entries share both keys but not their module.
  • compute_program() decides what a compute shader's bytecode is looked up by:
    • an FSSM blob, bare or in DXIL: unchanged;
    • a DXBC container whose ACCC part is an FSPX payload (what slot 62 gets): its kind-6 bytes;
    • a bare FSPX payload: its kind-6 bytes;
    • a bare kind-6 program (what slot 67 carries at +0x28): the bytes as they are. It is recognized by the 36-byte prologue that all 29 programs have, so every other input keeps today's path and error codes.
  • The FSPX directory is parsed with the DLL reader's rules (docs/fspx.md), with every offset and size checked in 64-bit arithmetic. A malformed directory, or one without kind 0 or kind 6, gives no program and E_INVALIDARG.
  • The pipeline's code base is the kind-6 bytes, since the translator's code offsets are into them.

Design choices

  • A sub-folder instead of merging into the main index: the FSPX step stays independent of the 26,503-shader translation and its markers, and the runtime still takes one LEONIDA_SHADERS folder.
  • The key in shader_meta.collect, next to fssm_sha256: running fspx_unpack.py and rdna2spirv.py by hand gives the same index.
  • Exact bytes at slot 67: the size at +0x30 is kind 6's own size, not the rounded allocation. This was read from the DLL's code (0x5649 to 0x56d5) and added to docs/fspx.md.

Results

Measured on my own copy of 1.0.2.1 (counts only):

Result
FSPX programs in the DLL, unpacked by the new step 29 of 29
Translated and spirv-val-valid 17 of 29 at this head, as on main since #1754 (13 before it); the 12 others stop where docs/fspx.md says
Index entries with fspx_code_sha256 17 of 17, all distinct
Translated programs found by the real ShaderLibrary from the DLL's bytes 17 of 17, from the ACCC container and from the bare kind-6 program alike; the 12 untranslated are found neither way; the two ways never disagree
vk_pipeline_check on the 17 modules 17 of 17 modules and pipelines on llvmpipe, on the Ryzen 9 7950X3D's integrated GPU (RDNA2) and on the Radeon RX 7900 XTX (RDNA3), with the Khronos validation layer on: 0 messages
Game's own shaders, full shaders stage 26,503 translated, 26,503 valid, the same as main's translator on the same disassembly: same entries, metadata equal, all 26,503 .spv files byte-identical

The four FSPX rows were measured again after main brought #1754 (the same checks gave 13 before that merge), and the counts of 17 once more at 6a16ac1 with both keys: 17 distinct code keys, 17 distinct (code, state) pairs, 17 found both ways. The pipeline check ran at 7886972.

Tested

Linux, Mesa 26.3.1 (RADV, llvmpipe). The branch was merged with main twice. The full list below ran at 003e7812. After the second merge (6a6704df, which brought #1714) I re-ran the Linux build, ctest (36 of 36), compileall, the four FSPX and stage test files, and d3d12_fspx_compute_test on llvmpipe and the integrated GPU (both pass). Since 6a6704df, d3d12_compute_test fails a device ref-count check (line 515) under Wine, and fails the same way on plain main at 6a6704df.

  • python -I -m compileall and every tests/test_*.py without pytest: 184 run. test_cf_ref.py and test_world_names.py fail, and fail the same way on main at 003e7812.
  • New tests/test_fspx_shaders_stage.py (9 tests): the key is the SHA-256 of the kind-6 bytes and matches both run-time inputs; an FSSM shader gets no FSPX key; a malformed directory is not unpacked; the step runs once, reruns for each changed input, leaves no marker or old module when stopped, is skipped without the DLL, and never reruns the game's shaders.
  • pytest tests --ignore=tests/semantic: 4,366 passed, 54 skipped, 5 failed. The 5 are the subtests of the two files above. Before the merge: 4,217 passed, 0 failed.
  • unittest discover -s tests/semantic: 1,567 OK. node --test tests/test_viewer_streaming.cjs: 35 of 35.
  • Linux cmake + Ninja build and ctest: 33 of 33 (one skipped: vk_sync_validation). shader_library_test covers the FSPX parsing, these malformed directories (end past the total, start inside the directory, 32-bit wrap, size past the buffer, kind 6 or kind 0 missing, kind 6 empty, the total cutting kind 6, a directory longer than the payload, a 32-bit wrap of the count), the lookup and the fspx/ folder.
  • New d3d12_fspx_compute_test (mingw-w64 + Wine, VK_LAYER_KHRONOS_validation on the host): PSOs from an ACCC container through slot 62 and from a bare kind-6 program, a dispatch each that reads its own program through the code base, and ten refused inputs. It passes with 0 validation errors of its own on llvmpipe, on the integrated GPU (RDNA2) and, before the merge with main, on the RX 7900 XTX (RDNA3). d3d12_compute_test and d3d12_set0_compute_test pass on the same devices.
  • All 34 D3D12 tests that build with mingw, under Wine on llvmpipe: the failures are d3d12_clear_test, d3d12_descriptor_test, d3d12_fence_timing_test and d3d12_present_test (known Wine failures), and d3d12_draw_test, which fails the same way on plain main (a vkDestroyPipeline in-use error, 3 of 3 runs each). d3d12_copy_xfmt_test, d3d12_m3_frame_test and d3d12_vulkan_device_test do not link with mingw, as on main.

Out of scope

Not tested

  • No MSVC build: the D3D12 tests were cross-built with mingw-w64 and run under Wine. CI's MSVC /W4 /permissive- build has not seen this code.
  • No Windows run.
  • No run of the DLL's own pipeline creation through the loader: after slot 67 it calls pipeline slot 11, which is not implemented.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. The tests build their FSPX inputs by hand; the measurements report counts only.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new translator rule.)

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2).

aslan2142 and others added 3 commits November 22, 2026 09:22
…their kind-6 bytes (RT-99)

The FidelityFX DLL creates its compute pipelines from FSPX programs (docs/fspx.md): through slot 67 with the bare
kind-6 program, then through slot 62 with the DXBC container whose ACCC part holds the payload. Both ended in
E_INVALIDARG: the layer took only FSSM bytecode, the build never translated the DLL and the index had no key for it.

- make_game.py: the shaders stage unpacks the package's DLL with tools/fspx_unpack.py --disasm into
  <work>/shaders/fspx and translates it into <work>/shaders/spirv/fspx, with the same wave64 mode and fallback
  flags. The step is redone as a whole when the DLL, its tools, llvm-mc or the flags change (fspx_build.json,
  written last) and never makes the game's shaders run again.
- tools/shader_meta.py: an entry of a program without an FSSM blob gets fspx_code_sha256, the SHA-256 of
  fspx/<name>.code.
- runtime/src/shader_library.h: the library also loads <dir>/fspx/index.json and finds entries by
  fspx_code_sha256. compute_program() takes an FSSM program as before, the kind-6 bytes of an ACCC container or of a
  bare FSPX payload, and a bare kind-6 program recognized by its prologue; the directory is parsed with the DLL
  reader's rules and bounds-checked, so a malformed one is refused.
- create_compute: looks the program up by the key of its kind and uses those bytes as the code base.
- Tests: shader_library_test (parsing, malformed directories, lookup, the fspx folder), d3d12_fspx_compute_test
  (PSOs from both forms, a dispatch each, refused inputs) and tests/test_fspx_shaders_stage.py.
- Docs: the lookup in docs/fspx.md; slots 62 and 67 in d3d12_command_objects.md and d3d12_vulkan.md. The size the
  slot-67 description carries at +0x30 is kind 6's own size, read from the DLL's code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/README.md
# Conflicts:
#	docs/d3d12_command_objects.md
@aslan2142
aslan2142 marked this pull request as ready for review November 22, 2026 15:01
… programs

The paragraph still said 13, from before the dot-product rule (ItsNotRexed#1754). docs/fspx.md, "Translation status", has 17
and lists what stops the other 12; the paragraph now points there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Vonsek Vonsek 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.

On 508e94d6, I built a synthetic DLL with two FSPX containers using the existing test builders. Both carry the same kind-6 code; their kind-0 dispatch state requests 32×1×1 and 64×1×1 respectively. The real unpacker and translator processed both on Windows with LLVM 21.1.8. Both passed spirv-val and disassembled to different LocalSize values, but the two entries have the same fspx_code_sha256.

The runtime extracts only kind 6 even for the wrapped slot-62 input. Both containers then get the same candidates and choose the same pipeline despite having different dispatch state. Could the wrapped lookup discriminate with kind 0, or could the build reject an ambiguous key at least when the generated SPIR-V differs? The bare slot-67 input cannot distinguish this pair from the code bytes alone. This reproducer is synthetic; I haven't established that this occurs in the retail DLL. The 30 FSPX stage and unpack Python tests also passed.

AI-assisted.

aslan2142 and others added 2 commits November 22, 2026 10:28
…ams are refused (RT-99 review)

Review on ItsNotRexed#1911: two containers with the same kind-6 program and different kind-0 entries (32x1x1 and 64x1x1)
translate to different modules but got the same fspx_code_sha256, so both resolved to the same pipeline.

- tools/fspx_unpack.py writes the kind-0 entry as fspx/<name>.state; tools/shader_meta.py records its SHA-256 as
  fspx_state_sha256 next to fspx_code_sha256.
- make_game.py: entries with the same code and state keys must have identical modules, otherwise the FSPX step fails
  naming both programs and drops the index. The same code key with other state keys is allowed.
- runtime: a container or bare payload (kinds 0 and 6 present) matches the code key and then the state key; no match
  is E_INVALIDARG. A bare kind-6 program (slot 67, no kind 0) takes the code key's entries when their modules are
  identical, and is refused with E_INVALIDARG and an "ambiguous" log line when they differ.
- Tests: the review case in tests/test_fspx_shaders_stage.py, shader_library_test and d3d12_fspx_compute_test.
- docs/fspx.md: the two keys and the ambiguous case.

On 1.0.2.1 the 29 kind-6 programs are distinct, so nothing resolved wrongly before: 17 translated entries, 17
distinct code keys, 17 distinct (code, state) pairs, all 17 found from the container and from the bare program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	tools/fspx_unpack.py
@aslan2142

Copy link
Copy Markdown
Contributor Author

@Vonsek, thanks, that was a real gap. It is fixed on the branch in 6a16ac1 (head d9f7ec4, which also merges main at 4eb6155).

  • Retail DLL: on 1.0.2.1 the 29 kind-6 programs are 29 different byte strings, so every code key has exactly one entry and nothing resolved wrongly. The code did accept an ambiguous pair silently, as your reproducer shows.
  • Index: each entry now also carries fspx_state_sha256, the SHA-256 of the kind-0 entry.
  • Wrapped input (the slot-62 container, or a bare payload): the lookup matches the code key and then the state key. Your 32×1×1 and 64×1×1 containers each get their own module, and an unknown kind 0 gets E_INVALIDARG.
  • Bare kind-6 program (what the slot-67 mapping forwards, without kind 0): the entries of its code key are used only when they are one module. If they differ, it is refused with E_INVALIDARG and a log line saying the program is ambiguous without its kind-0 state.
  • Build: two entries with the same code and state keys but different modules fail the FSPX step, with a message naming both programs.
  • Tests: your case is now a test in tests/test_fspx_shaders_stage.py, in shader_library_test and in d3d12_fspx_compute_test (mingw and Wine, on llvmpipe and an RDNA2 integrated GPU).
  • Measured again on my copy: 17 translated entries, 17 distinct code keys and 17 distinct (code, state) pairs; all 17 are still found both ways.

Passing kind 0 on from slot 67, so that the bare case can be told apart as well, fits the follow-up for the pipeline's slot 11.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2).

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

I retested d9f7ec41 on Windows. CTest shader_library passed with MSVC 19.44, including both wrapped lookups, the unknown-state miss and the ambiguous bare-program refusal. Both FSPX Python suites passed all 34 tests. I also reran my synthetic 32×1×1 / 64×1×1 pair through the actual unpacker and translator with LLVM 21.1.8. Both modules passed spirv-val, retained the expected LocalSize, shared the same code hash, and had distinct state hashes. This resolves my lookup finding.

AI-assisted.

@Serrambi Serrambi 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.

Reviewed d9f7ec41 and tested on NVIDIA GeForce RTX 5070 Ti (driver 610.88, Windows 11 Pro, MSVC 19.50.35719.0, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, LLVM 21.1.8 AMDGPU): approve.

Code review (runtime/src/shader_library.h, runtime/shims/d3d12_vulkan_device.cpp, make_game.py, tools/shader_meta.py, tests & docs)

  • fspx_parts() safely validates headers, total clamping against buffer size, 64-bit directory bounds (16 + 16 * uint64_t(u32(8))) and entry bounds (offset < end_dir || uint64_t(offset) + size > total), requires non-empty kind-0 and kind-6 entries, and preserves last-entry-wins semantics matching tools/fspx_unpack.py.
  • fspx_bare_program() validates 4-byte multiple length >= 36 and the three 0xD580 VOP3 prologue words at offsets 0, 3, and 6.
  • ShaderLibrary::load() isolates <dir>/fspx/index.json loading into fspx_entries_ with "fspx/" module path prefixing so a missing/corrupt fspx/index.json never breaks the main index; program_candidates() properly discriminates shared fspx_code_sha256 entries by fspx_state_sha256 when kind 0 is present, allows bare kind-6 when all modules match byte-for-byte, and refuses ambiguous bare kind-6 programs cleanly (E_INVALIDARG).
  • make_game.py (fspx_shaders, fspx_key_clash) isolates FSPX incremental state (fspx_build.json) without invalidating the main shader corpus and cleanly fails on colliding (fspx_code_sha256, fspx_state_sha256) entries with differing SPIR-V outputs.

Checks on d9f7ec41

  • python -m compileall -q make_game.py tools tests: passed (EXIT=0)
  • python -I tests/test_fspx_shaders_stage.py: Ran 12 tests in 0.406s — OK
  • python -I tests/test_fspx_unpack.py: Ran 22 tests in 0.123s — OK
  • shader_library_test.exe: passed (EXIT=0)
  • d3d12_fspx_compute_test.exe (default and LEONIDA_VK_VALIDATION=1): passed (EXIT=0, 0 Vulkan validation errors)
  • d3d12_compute_test.exe (default and LEONIDA_VK_VALIDATION=1): passed (EXIT=0, 0 Vulkan validation errors)
  • ctest --test-dir runtime/build --output-on-failure -R "^(shader_library|d3d12_fspx_compute|d3d12_compute)$": 3/3 passed

@SirKingg

Copy link
Copy Markdown
Contributor

Tested d9f7ec4 on NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088, Windows 11 build 26300 (MSVC 14.44 / VS 2022 Build Tools, Windows SDK 10.0.26100.0, Ninja, RelWithDebInfo): pass for everything this PR touches.

AI-assisted testing.

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.

5 participants