Skip to content

Shaders: one interpolation mode per signature row - #554

Closed
SAitken91 wants to merge 1 commit into
Marvisak:mainfrom
SAitken91:shader/separate-interpolation-rows
Closed

SAitken91 wants to merge 1 commit into
Marvisak:mainfrom
SAitken91:shader/separate-interpolation-rows

Conversation

@SAitken91

Copy link
Copy Markdown
Contributor

The console packs signature elements of different interpolation modes into one row, for example a constant SV_IsFrontFace or uint beside a linear TEXCOORD. The DXIL validator rejects this with "signature element ... has interpolation mode that differs from another element packed into the same row".

Change

  • New container::separate_interpolation, run on the inputs and outputs in Shader::finish before any signature is written. The first mode seen in a row keeps the row. Each later mode moves to a new free row, and that row's elements of the same mode share it.
  • Code addresses elements by id and stages link by semantic, so only the signatures change (metadata, ISG1/OSG1, PSV0).
  • Elements without a mode (0) are left in place. Programs without mixed rows are unchanged.

Results

victory translate --validate shaders.rpf, before → after:

validated
vertex/pixel 12172 → 12214
mesh 8129 → 8130

No interpolation-row errors remain. A few programs now report the "Container part 'Program Input/Output Signature' does not match" errors already in the list, which the packing error had hidden.

Testing

  • cargo test -p victory-shader: 70 passed, including the new rows_of_mixed_interpolation_are_separated. Clippy and rustfmt are clean.
  • Not exercised at runtime in the world. Only validation has been checked.

This is independent of #539 (64-bit image atomics), and the two can merge in either order.

Written with the help of Claude (AI).

🤖 Generated with Claude Code

The console packs elements of different interpolation modes into one
signature row (a constant SV_IsFrontFace or uint beside a linear
TEXCOORD), which the DXIL validator rejects: "signature element ... has
interpolation mode that differs from another element packed into the
same row". Before the signatures are written, each later mode of a row
now moves to a free row of its own, shared by that row's elements of
the mode. Code addresses elements by id and stages link by semantic, so
only the signatures (metadata, ISG1/OSG1, PSV0) change. Elements without
a mode are left in place, and programs without such rows are unchanged.

translate --validate on shaders.rpf: vertex/pixel 12172 -> 12214
validated, mesh 8129 -> 8130; no interpolation-row errors remain. A few
programs now report the signature-mismatch errors already in the list,
which the packing error had hidden.

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

KoLolX3 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Check on Linux, not Windows: pass. Head 9152a1bee merged onto main d2a4bae1f (clean merge).

  • Native tests of the seven crates that build on Linux (core, formats, game, loader, pe, pipeline, shader): PR 93 passed, 7 failed, main 92 passed, 7 failed.
  • Windows cross type-check of the whole workspace (cargo xwin check --workspace --target x86_64-pc-windows-msvc, covers victory-gpu, victory-hle and the app): PR ok, main ok.
  • Tests this PR adds: 1, of which 1 ran in the native run (the pass count rose by 1).
  • rustfmt: unformatted hunks, PR 168, main 168.
  • Failing on main here as well (not this PR): 7 tests in victory-loader and victory-pe that parse their own test binary as a PE image, which is an ELF file on Linux.
  • Not run: victory-gpu / victory-hle tests and the game itself.

On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.

@slint6614-dev

Copy link
Copy Markdown

Measured on the full retail shader pack (26,503 containers) with victory translate --validate, against main d2a4bae (emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100.

VS/PS MS validator failures changed
main 12272 / 12172 8191 / 8129
#554 12272 / 12214 8191 / 8130 clears all 49 "interpolation mode that differs from another element packed into the same row"; "Program Input Signature does not match" 21 → 23, "Program Output Signature does not match" 25 → 29
#565 12272 / 12186 8191 / 8129 clears the 14 "Interpolation mode for PS input position must be linear_noperspective_centroid…"
#381 12272 / 12172 8191 / 8129 none on this pack
#306 12316 / 12316 8191 / 8138 clears both kinds above and the signature mismatches (all VS/PS that emit validate)

cargo test -p victory-shader passes on all four.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested 9152a1b on Windows 11, RTX 5070, MSVC: the workspace passes (195 outside victory-shader; victory-shader --lib single-threaded: 70). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of the 12 mixes modes in a row.

Splitting rows by interpolation mode fixes the validator error, and the algorithm is fine: the first mode keeps its row, and each later (row, mode) gets one shared new row. One linkage question before I'd approve:

  • The row moves are done separately for each stage, on that stage's own inputs and outputs. A PS input element that moves to a new row stays at its original row on the VS side, because VS outputs carry no interpolation mode (interp == 0 stays put).
  • D3D12 checks at PSO creation that the PS input signature is compatible with the previous stage's outputs, by register and component, not only by semantic. That mismatch could make real VS+PS pipelines fail to create.
  • translate --pipelines can't catch this: for a pixel program it builds the VS with host::stub_vs(&ps) (apps/victory/src/translate.rs:441), which is derived from the PS's own (already moved) signature, so it always links.

Could you check one real VS/PS pair from the title where the PS moves a row, with the actual VS output signature? Or move the same elements in the producing stage's outputs (keyed by semantic), so both sides agree. If D3D12 turns out to link these by semantic alone in DXIL, a note saying so would settle it.

AI-assisted (Claude Code).

@alexander-src alexander-src left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested 9152a1b merged onto main (8e79c80 and ffe310e, clean merge) on Windows 11 (10.0.26200.0), NVIDIA GeForce RTX 5090 (driver 621.24), WARP, Rust 1.98.1, dxil.dll 10.0.26100.0.

  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass
  • cargo test -p victory-shader --locked -- --test-threads=1 (on 8e79c80): 90 passed, 0 failed, 1 ignored

Empirical answer to @mercuryVM's VS/PS linkage question (blocking)

Confirmed with a synthetic VS+PS test validated through dxil.dll 10.0.26100.0 and run through Host::pipeline + Host::draw on both RTX 5090 and WARP: D3D12 rejects VS/PS pairs whose (row, col) disagree at CreateGraphicsPipelineState, even when semantics match.

Setup:

  • PS declares SV_Position (row 0), TEXCOORD0 (f32, row 1 col 0, interp=2 linear), TEXCOORD1 (f32, row 1 col 1, interp=1 constant). separate_interpolation moves TEXCOORD1 to row 2 col 1.
  • VS outputs SV_Position (row 0), TEXCOORD0 (f32, row 1 col 0, interp=2 = 0.25), and TEXCOORD1 (f32, col 1 = 0.75) in three variants:
    1. row 1, interp=2 (exact emit/mod.rs VS default when both outputs are f32, so separate_interpolation leaves VS unchanged)
    2. row 2, interp=2 (same row as moved PS, different interp)
    3. row 2, interp=1 (same row and interp as moved PS)

Results (all four containers validated cleanly with dxil.dll):

Pair RTX 5090 (621.24) WARP
VS (row 1, interp 2) + PS (row 2, interp 1) CreateGraphicsPipelineState -> E_INVALIDARG ("The parameter is incorrect.") CreateGraphicsPipelineState -> E_INVALIDARG ("The parameter is incorrect.")
VS (row 2, interp 2) + PS (row 2, interp 1) PSO ok, rendered [0.25, 0.75, 0.5, 1.0] PSO ok, rendered [0.25, 0.75, 0.5, 1.0]
VS (row 2, interp 1) + PS (row 2, interp 1) PSO ok, rendered [0.25, 0.75, 0.5, 1.0] PSO ok, rendered [0.25, 0.75, 0.5, 1.0]

Why this will hit real VS+PS and MS+PS pairs at runtime (while victory translate --pipelines misses it via host::stub_vs(&ps)):

  1. In crates/victory-shader/src/emit/mod.rs:232-243, VS/MS outputs only get default modes (f32 -> 2, integer -> 1), whereas PS inputs have e.interp overridden by barycentrics during lowering (flat, centroid, noperspective, sample) and can carry PS-only SV_IsFrontFace (kind=13, interp=1). Any row mixing modes only on the PS side moves in the PS and stays put in the VS/MS.
  2. Even when both stages split the same row (e.g., f32 + u32), separate_interpolation picks next = max(row) + 1 per stage. Whenever a VS/MS exports extra trailing rows the PS does not declare, the two stages assign different destination rows and PSO creation fails with E_INVALIDARG.

Note that the second row of the table also shows D3D12 allows VS interp=2 to link with PS interp=1 as long as (row, col) stay identical — which is why keeping rows in place (like #306's harmonize_row_interp, when the mixed sibling is unread) preserves stage linkage, whereas moving rows in one stage breaks it unless both stages agree on the exact layout at PSO link time.

No game files used in the linkage probe. AI-assisted (Antigravity) analysis and test authoring; all builds, validation, and GPU/WARP runs executed on this machine.

@SAitken91

Copy link
Copy Markdown
Contributor Author

@alexander-src thank you — that's decisive, and it breaks the premise of this PR ("stages link by semantic"): moving rows in one stage changes (row, col) and CreateGraphicsPipelineState rejects the pair, which translate --pipelines can't see because it pairs the PS with a stub VS. Your second table row (VS interp 2 + PS interp 1 at the same row links fine) points to the safer approach #306 takes: keep rows in place and harmonize the mode. I'm converting this to a draft so it isn't merged as is; it would need both stages to derive the same layout, which a per-stage max(row) + 1 can't guarantee.

@SAitken91
SAitken91 marked this pull request as draft November 24, 2026 10:46

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

Sound fix for a real DXIL constraint (one interpolation mode per signature row). separate_interpolation keeps each row's first-seen mode in place and moves later modes to fresh rows (next starts above the max existing row, so no collisions), reusing one new row per (old row, mode) pair — the test shows B and D (both constant) sharing row 2 while A/E stay on row 0. Elements with mode 0 or no row are untouched, which is correct since they carry no interpolation semantics.

Calling it from Shader::finish for both inputs and outputs is the right place: lowering already happened, and DXIL links stages by semantic, so only the ISG1/OSG1 signature blobs change — the comment says exactly this and it's accurate.

Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 97 passed / 0 failed / 1 ignored, including the new rows_of_mixed_interpolation_are_separated unit test (runs on macOS, not Windows-gated).

@SAitken91

Copy link
Copy Markdown
Contributor Author

@catminou4 thanks for the review — note the blocker above, though: @alexander-src showed on an RTX 5090 and WARP that D3D12 rejects VS/PS pairs whose (row, col) differ (CreateGraphicsPipelineState → E_INVALIDARG). This PR moves rows per stage (next = max(row) + 1 in each), so a PS can end up with rows its VS doesn't have, which the validator and translate --pipelines (stub VS) can't catch. That's why it's a draft; #306's approach (keep rows, harmonize the mode) avoids it.

@SAitken91

Copy link
Copy Markdown
Contributor Author

Closing in favour of #306, which keeps signature rows in place and harmonizes the interpolation mode instead, so VS/PS (row, col) stay identical and pipelines link (per @alexander-src's RTX 5090/WARP results above). Thanks to everyone who tested and reviewed this.

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.

6 participants