Match interpolation modifiers between the pixel shader and the stage feeding it (PSO linkage #660/#662) #36

Closed
github-bot wants to merge 1 commit from gh-pr/36/head into gh-pr/36/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 18:46 UTC · original
QuentinDanblon:fix/interp-modifiers-linked → main · +521 −68 · 8 files · 104 commits · closed without merging

Library / area: tombox-xshader (stage output signatures) + d3d12_xs (graphics/stream PSO translation, shader cache key), xreplay

Exports changed (exports.txt rows): none

Source of the behaviour: D3D12 signature linkage rules (DXC packs elements into one register only when their interpolation modes match). Ported and adapted from brcly/TomBox 6b49c14 (GDAgent; crates declare MIT OR Apache-2.0).

Bug

The translated pixel shader declares _centroid inputs as centroid (hlsl.rs SIn). The VS/GS/MS feeding it declared no modifiers on its outputs (hlsl.rs SOut, hlsl/mesh.rs), and nothing in d3d12_xs reconciled the two. As a result DXC packs the two signatures differently. Reproduced with DXC: TEXCOORD0 float2 linear + TEXCOORD1 float2 centroid puts TEXCOORD1 in r1.zw in the VS but r2.xy in the PS. D3D12 then rejects the pipeline (SHADER_LINKAGE_REGISTERINDEX #660 / REGISTERMASK #662) and every draw using it is lost. Integer varyings were already fine, because DXC defaults them to nointerpolation on both sides.

Fix

  • hlsl::ps_input_interp(&ShaderExtract) derives the PS input modifiers from the PS extract alone. Unlike brcly's version, it does not need the PS translated first. It uses the same ps_input_modifier the PS emitter uses. Only non-default modifiers are recorded, and SV_Position is left out. So a PSO without centroid/flat float inputs keeps exactly the same HLSL and cache key as today.
  • hlsl::translate_linked puts those modifiers on the matching outputs of the feeding stage (GS, else DS, else VS; MS for stream PSOs). Integer outputs only accept nointerpolation.
  • d3d12_xs: create_gfx_pso_x, stream PSOs (mesh_pso.rs), hot reload and prefetch all translate the feeding stage with its PS link. Its cache key is link_key(cache_key(hash, rtfmt), link): unchanged when the link is empty, FNV-mixed otherwise. Linked variants are not written to the prewarm source directory, because prewarm cannot rebuild the link.
  • xreplay --retranslate links the same way.

Tests

  • New tests/linkage.rs (3 tests) covers:

    • the emitted declarations;
    • integer outputs getting no float modifier;
    • on Windows, compiling the pair with DXC and comparing the ISG1/OSG1 registers and masks (unlinked pair mismatches, linked pair matches), then creating the PSO on WARP (unlinked: hr < 0; linked: created).
  • New d3d12_xs unit test feeding_stage_key_follows_the_pixel_shader_modifiers: different modifier sets do not collide.

  • cargo test -p tombox-xshader --release --lib --test opcodes --test synthetic --test linkage: 8 / 22 / 7 / 3 pass.

  • Full --test exec: 56 pass / 4 fail, same as main (the vop::basic failures, fixed in #24). --test mesh: 12 / 2, same as main (fixture + #19).

  • cargo build --release -p d3d12_xs -p xreplay: OK. cargo test -p d3d12_xs --lib shader_xlat:: mesh_pso::: 5 + 5 pass. This needed the COND_POOL_TEST fix from #18 locally; that fix is not included here.

  • Not run against a title.

  • cargo test -p tombox-xshader passes (except the failures already on main)

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

**@⁠QuentinDanblon** on GitHub · 2026-11-21 18:46 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/36) `QuentinDanblon:fix/interp-modifiers-linked` → `main` · +521 −68 · 8 files · 104 commits · closed without merging **Library / area:** tombox-xshader (stage output signatures) + d3d12_xs (graphics/stream PSO translation, shader cache key), xreplay **Exports changed (exports.txt rows):** none **Source of the behaviour:** D3D12 signature linkage rules (DXC packs elements into one register only when their interpolation modes match). Ported and adapted from brcly/TomBox [6b49c14](https://github.com/brcly/TomBox/commit/6b49c147b71b409950d08321d8c8e391930c53a9) (GDAgent; crates declare MIT OR Apache-2.0). ### Bug The translated pixel shader declares `_centroid` inputs as `centroid` (`hlsl.rs` SIn). The VS/GS/MS feeding it declared no modifiers on its outputs (`hlsl.rs` SOut, `hlsl/mesh.rs`), and nothing in d3d12_xs reconciled the two. As a result DXC packs the two signatures differently. Reproduced with DXC: TEXCOORD0 float2 linear + TEXCOORD1 float2 centroid puts TEXCOORD1 in r1.zw in the VS but r2.xy in the PS. D3D12 then rejects the pipeline (SHADER_LINKAGE_REGISTERINDEX #660 / REGISTERMASK #662) and every draw using it is lost. Integer varyings were already fine, because DXC defaults them to nointerpolation on both sides. ### Fix - `hlsl::ps_input_interp(&ShaderExtract)` derives the PS input modifiers from the PS extract alone. Unlike brcly's version, it does not need the PS translated first. It uses the same `ps_input_modifier` the PS emitter uses. Only non-default modifiers are recorded, and SV_Position is left out. So a PSO without centroid/flat float inputs keeps exactly the same HLSL and cache key as today. - `hlsl::translate_linked` puts those modifiers on the matching outputs of the feeding stage (GS, else DS, else VS; MS for stream PSOs). Integer outputs only accept nointerpolation. - d3d12_xs: `create_gfx_pso_x`, stream PSOs (`mesh_pso.rs`), hot reload and prefetch all translate the feeding stage with its PS link. Its cache key is `link_key(cache_key(hash, rtfmt), link)`: unchanged when the link is empty, FNV-mixed otherwise. Linked variants are not written to the prewarm source directory, because prewarm cannot rebuild the link. - `xreplay --retranslate` links the same way. ### Tests - New `tests/linkage.rs` (3 tests) covers: - the emitted declarations; - integer outputs getting no float modifier; - on Windows, compiling the pair with DXC and comparing the ISG1/OSG1 registers and masks (unlinked pair mismatches, linked pair matches), then creating the PSO on WARP (unlinked: `hr < 0`; linked: created). - New d3d12_xs unit test `feeding_stage_key_follows_the_pixel_shader_modifiers`: different modifier sets do not collide. - `cargo test -p tombox-xshader --release --lib --test opcodes --test synthetic --test linkage`: 8 / 22 / 7 / 3 pass. - Full `--test exec`: 56 pass / 4 fail, same as main (the `vop::basic` failures, fixed in #24). `--test mesh`: 12 / 2, same as main (fixture + #19). - `cargo build --release -p d3d12_xs -p xreplay`: OK. `cargo test -p d3d12_xs --lib shader_xlat:: mesh_pso::`: 5 + 5 pass. This needed the `COND_POOL_TEST` fix from #18 locally; that fix is not included here. - Not run against a title. - [x] `cargo test -p tombox-xshader` passes (except the failures already on main) - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
The translated pixel shader declares `_centroid` inputs `centroid`, while the
VS/GS/MS feeding it declared no modifiers. DXC packs elements into one
register only when their interpolation modes match, so the two signatures
were packed differently (e.g. centroid TEXCOORD1.xy in r1.zw of the VS but
r2.xy of the PS) and D3D12 rejected the pipeline with
SHADER_LINKAGE_REGISTERINDEX (#660) / _REGISTERMASK (#662).

- tombox-xshader: `hlsl::ps_input_interp` lists the pixel shader's
  non-default input modifiers; `hlsl::translate_linked` puts them on the
  matching outputs of a vertex, geometry or mesh shader. A lowered
  centroid input (`TB_CEN_Q`) is linear unless the pixel shader is built
  with `TB_CENTROID_PC`; `InputInterp::pc_centroid` turns it into
  `centroid` for that case.
- d3d12_xs: graphics PSOs (CreateGraphicsPipelineStateX, stream PSOs, hot
  reload, prefetch) translate the stage feeding the pixel shader with its
  modifiers; they are part of that stage's cache key (`link_key`), and
  linked variants are not recorded for prewarm. `ps_link` takes the pixel
  shader's TB_CENTROID_PC state (`centroid_bind::tag_rtfmt`), and the mesh
  path with pipeline root data links too.
- xreplay --retranslate links the same way.
- tests/linkage.rs: emitted declarations, DXC signature registers, and
  pipeline creation on WARP with TB_CENTROID_PC (unlinked refused, linked
  accepted).

Ported and adapted from brcly/TomBox (MIT OR Apache-2.0) commit
6b49c147b71b409950d08321d8c8e391930c53a9
6b49c147b7

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:08:02 +00:00
github-bot closed this pull request 2026-11-26 06:08:02 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 22:02 UTC · original

Rebased onto 0fc7295, with the targeted tests re-run on the new base. #49 keeps the fused f16 FMA at VOP2 0x36-0x38 (gfx1013 v_fmac/fmamk/fmaak_f16) and updates the upstream ISA-sweep cases to the fused model. #36 adapts to upstream's TB_CEN_Q centroid qualifier. #48 now also includes the 4 regression scenarios from #28, credited.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 22:02 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7069900158) Rebased onto 0fc7295, with the targeted tests re-run on the new base. #49 keeps the fused f16 FMA at VOP2 0x36-0x38 (gfx1013 v_fmac/fmamk/fmaak_f16) and updates the upstream ISA-sweep cases to the fused model. #36 adapts to upstream's TB_CEN_Q centroid qualifier. #48 now also includes the 4 regression scenarios from #28, credited.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 23:09 UTC · original

Rebased onto 8491769; the conflict in shader_xlat.rs is resolved. Main replaced the per-blob disk cache with the pack keyed by the generated HLSL, so the linked variant no longer needs a disk key of its own: a linked translation produces different HLSL and therefore a different pack key. The in-memory cell still uses link_key, and the prewarm manifest still records unlinked shaders only.

  • --test linkage: 3 / 3.
  • d3d12_xs --lib shader_xlat: 8 / 8.
  • d3d12_xs --lib: 410 passed, 1 failed, centroid_bind::tests::lowered_pixel_shader_compiles_with_fxc_in_both_variants. FXC rejects uint64_t in tb_nrm, a helper that comes from main and that this PR does not touch (the error #63 describes). I did not run that test on main itself.
**@⁠QuentinDanblon** on GitHub · 2026-11-21 23:09 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7070684353) Rebased onto `8491769`; the conflict in `shader_xlat.rs` is resolved. Main replaced the per-blob disk cache with the pack keyed by the generated HLSL, so the linked variant no longer needs a disk key of its own: a linked translation produces different HLSL and therefore a different pack key. The in-memory cell still uses `link_key`, and the prewarm manifest still records unlinked shaders only. - `--test linkage`: 3 / 3. - `d3d12_xs --lib shader_xlat`: 8 / 8. - `d3d12_xs --lib`: 410 passed, 1 failed, `centroid_bind::tests::lowered_pixel_shader_compiles_with_fxc_in_both_variants`. FXC rejects `uint64_t` in `tb_nrm`, a helper that comes from main and that this PR does not touch (the error #63 describes). I did not run that test on main itself.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-22 11:36 UTC · original

Rebased onto 51f5319. One conflict in shader_xlat.rs (translate_mesh_with_root): main's shader_dump::note call is kept next to the linked cache cell.

The mismatch is still on main. hlsl.rs 6222-6240 puts centroid / TB_CEN_Q on the pixel shader inputs, and the outputs of the stage feeding it (SOut, 6243-6256) carry no modifier. tests/linkage.rs checks both halves on this base: for the unlinked pair DXC assigns different registers and WARP refuses the PSO, the linked pair is created.

Tests on this base:

  • cargo test -p tombox-xshader --release --lib --test linkage --test ps_linkage --test opcodes --test synthetic --test centroid: 60 / 3 / 1 / 22 / 11 / 1 pass.
  • --test exec on WARP: 73 of 73. --test mesh: 13 of 13.
  • cargo test -p d3d12_xs --release --lib shader_xlat: 8 pass. mesh_pso: 6 pass.
  • Not run against a title.

xshader_prelaunch and xprecompile still translate each stage alone (hlsl::translate), so the linked variant of a feeding stage is not part of what they precompile.

**@⁠QuentinDanblon** on GitHub · 2026-11-22 11:36 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7078556011) Rebased onto `51f5319`. One conflict in `shader_xlat.rs` (`translate_mesh_with_root`): main's `shader_dump::note` call is kept next to the linked cache cell. The mismatch is still on main. `hlsl.rs` 6222-6240 puts `centroid` / `TB_CEN_Q` on the pixel shader inputs, and the outputs of the stage feeding it (`SOut`, 6243-6256) carry no modifier. `tests/linkage.rs` checks both halves on this base: for the unlinked pair DXC assigns different registers and WARP refuses the PSO, the linked pair is created. Tests on this base: - `cargo test -p tombox-xshader --release --lib --test linkage --test ps_linkage --test opcodes --test synthetic --test centroid`: 60 / 3 / 1 / 22 / 11 / 1 pass. - `--test exec` on WARP: 73 of 73. `--test mesh`: 13 of 13. - `cargo test -p d3d12_xs --release --lib shader_xlat`: 8 pass. `mesh_pso`: 6 pass. - Not run against a title. `xshader_prelaunch` and `xprecompile` still translate each stage alone (`hlsl::translate`), so the linked variant of a feeding stage is not part of what they precompile.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

Main's history was rewritten, which auto-closed this PR. It is applied in 0ad667f (merged in 81a1252) with your authorship kept, thanks! The added comment lines were stripped on the applied copy (the project keeps code free of comment lines). brcly/TomBox is credited in the THIRD_PARTY files (14e873c).

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7079641071) Main's history was rewritten, which auto-closed this PR. It is applied in 0ad667f (merged in 81a1252) with your authorship kept, thanks! The added comment lines were stripped on the applied copy (the project keeps code free of comment lines). brcly/TomBox is credited in the THIRD_PARTY files (14e873c).
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:15 UTC · original

Small follow-up: credits now live in one root file, so the per-crate THIRD_PARTY entry for this PR moved to THIRD_PARTY/CREDITS (79a3b2f). CONTRIBUTING.md is updated to match.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:15 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7079683331) Small follow-up: credits now live in one root file, so the per-crate THIRD_PARTY entry for this PR moved to THIRD_PARTY/CREDITS (79a3b2f). CONTRIBUTING.md is updated to match.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.