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

Closed
QuentinDanblon wants to merge 0 commits from upstream-pr/36 into main
QuentinDanblon commented 2026-11-21 18:46:09 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T18:46:09Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6532923614 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/36). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T18:46:09Z. --- **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
QuentinDanblon commented 2026-11-21 22:02:46 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T22:02:46Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7069900158 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7069900158). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T22:02:46Z. --- 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 commented 2026-11-21 23:09:34 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T23:09:34Z.


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.
<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7070684353 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7070684353). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T23:09:34Z. --- 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 commented 2026-11-22 11:36:46 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-22T11:36:46Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7078556011 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7078556011). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-22T11:36:46Z. --- 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.
omonkeyz commented 2026-11-22 13:12:14 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:12:14Z.


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).

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079641071 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7079641071). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:12:14Z. --- 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 commented 2026-11-22 13:15:49 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:15:49Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079683331 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/36#issuecomment-7079683331). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:15:49Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!36
No description provided.