Shaders: interpolate by hand rows read flat and interpolated; zero and copied barycentrics #1450

Closed
federalcontraband wants to merge 1 commit from upstream-pr/1451 into main
federalcontraband commented 2026-11-24 18:06:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by federalcontraband on 2026-11-24T18:06:07Z.


victory translate --validate over the title's shaders, before and after (main at ffe310e):

before after
"an interpolation with computed barycentrics" 207 111
vertex/pixel programs emitted 12,243 12,339
vertex/pixel programs validated 12,167 12,293 (+126)
"interpolation mode that differs from another element packed into the same row" 48 17

Per program, 126 go from failing to validated and none from validated to failing. Two that failed the row check now fail later, on "Program Input Signature does not match".

What the 207 "computed barycentrics" were

None of them compute their barycentrics. With a temporary trace of where j comes from:

  • 96 interpolate with i = j = 0: v_mov_b32 vN, 0 into both, then v_interp_p1/p2. That is P0 + 0·P10 + 0·P20, the provoking vertex's value, which is the same as v_interp_mov_f32 ... p0. Mostly PS_ShadowRender_CSM_* and similar.
  • ~109 read i/j through a phi that merges the loaded value with a value from another path, where v0/v1 were reused as scratch. Not handled here.

Changes

io.rs

  • Barycentrics are followed through plain v_mov_b32 copies, with the same conditions as resource::vorigin: no abs/neg/SDWA/DPP.
  • An interpolation whose i and j are both the constant 0 becomes Interp::Vertex { vertex: 2 }.

emit

  • 95 of those 96 then read the same input both flat (P0) and interpolated, so they failed with "one input interpolated two ways". A D3D12 row has one interpolation mode, so now:
    • manual_rows lists the pixel input rows whose reads need more than one mode, counting integer and system-value elements (the front face) as constant.
    • Those rows' elements are declared nointerpolation.
    • A flat read of such a row is a plain loadInput.
    • An interpolated read is Σ AttributeAtVertex(k) · SV_Barycentrics[k], with an SV_Barycentrics input per mode (at most one perspective and one linear, as D3D12 allows).
    • SV_Barycentrics and AttributeAtVertex come with the Barycentrics shader flag (bit 22) and SFI0 feature 0x20000.
  • In emit::emit, an element packed into a row with a constant element now defaults to constant too. That fixes most of the 48 pre-existing "differs from another element packed into the same row" errors: unread float elements defaulted to linear beside the integer element or front face in their row.

Tests

  • io::tests::interpolation_from_copied_barycentrics
  • io::tests::interpolation_at_zero_barycentrics_is_the_provoking_vertex (one zero weight alone is still refused)
  • emit::tests::a_row_read_flat_and_interpolated_is_interpolated_by_hand: emits, passes dxil.dll, declares SV_Barycentrics and the SFI0 bit.

All tests use hand-encoded instructions; no title data. cargo test --workspace passes (345) and clippy is clean.

Not verified

  • In game. I haven't yet compared the CSM shadow passes in a capture against what they drew before.
  • GPU support. SV_Barycentrics needs D3D12_OPTIONS3.BarycentricsSupported (RDNA2+, Turing+, Xe). This change doesn't query it. On a GPU without it, these pipelines fail to create, which is where these programs already were.
  • Vertex order. The manual sum relies only on AttributeAtVertex and SV_Barycentrics sharing an order, which D3D12 defines. P0 reads still go through nointerpolation loadInput, so they don't depend on which vertex AttributeAtVertex(0) is.

Tested on: Windows 11, RX 9060 XT (RDNA4), driver 32.0.31044.16.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6588273125 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1451). Originally posted by [federalcontraband](https://github.com/federalcontraband) on 2026-11-24T18:06:07Z. --- `victory translate --validate` over the title's shaders, before and after (`main` at `ffe310e`): | | before | after | |---|---|---| | "an interpolation with computed barycentrics" | 207 | 111 | | vertex/pixel programs emitted | 12,243 | 12,339 | | vertex/pixel programs validated | 12,167 | **12,293** (+126) | | "interpolation mode that differs from another element packed into the same row" | 48 | 17 | Per program, 126 go from failing to validated and none from validated to failing. Two that failed the row check now fail later, on "Program Input Signature does not match". ### What the 207 "computed barycentrics" were None of them compute their barycentrics. With a temporary trace of where `j` comes from: - **96** interpolate with `i = j = 0`: `v_mov_b32 vN, 0` into both, then `v_interp_p1/p2`. That is P0 + 0·P10 + 0·P20, the provoking vertex's value, which is the same as `v_interp_mov_f32 ... p0`. Mostly `PS_ShadowRender_CSM_*` and similar. - **~109** read `i`/`j` through a phi that merges the loaded value with a value from another path, where v0/v1 were reused as scratch. Not handled here. ### Changes **`io.rs`** - Barycentrics are followed through plain `v_mov_b32` copies, with the same conditions as `resource::vorigin`: no abs/neg/SDWA/DPP. - An interpolation whose `i` and `j` are both the constant 0 becomes `Interp::Vertex { vertex: 2 }`. **`emit`** - 95 of those 96 then read the same input both flat (P0) and interpolated, so they failed with "one input interpolated two ways". A D3D12 row has one interpolation mode, so now: - `manual_rows` lists the pixel input rows whose reads need more than one mode, counting integer and system-value elements (the front face) as constant. - Those rows' elements are declared `nointerpolation`. - A flat read of such a row is a plain `loadInput`. - An interpolated read is `Σ AttributeAtVertex(k) · SV_Barycentrics[k]`, with an `SV_Barycentrics` input per mode (at most one perspective and one linear, as D3D12 allows). - `SV_Barycentrics` and `AttributeAtVertex` come with the Barycentrics shader flag (bit 22) and SFI0 feature `0x20000`. - In `emit::emit`, an element packed into a row with a constant element now defaults to constant too. That fixes most of the 48 pre-existing "differs from another element packed into the same row" errors: unread float elements defaulted to linear beside the integer element or front face in their row. ### Tests - `io::tests::interpolation_from_copied_barycentrics` - `io::tests::interpolation_at_zero_barycentrics_is_the_provoking_vertex` (one zero weight alone is still refused) - `emit::tests::a_row_read_flat_and_interpolated_is_interpolated_by_hand`: emits, passes `dxil.dll`, declares `SV_Barycentrics` and the SFI0 bit. All tests use hand-encoded instructions; no title data. `cargo test --workspace` passes (345) and clippy is clean. ### Not verified - **In game.** I haven't yet compared the CSM shadow passes in a capture against what they drew before. - **GPU support.** `SV_Barycentrics` needs `D3D12_OPTIONS3.BarycentricsSupported` (RDNA2+, Turing+, Xe). This change doesn't query it. On a GPU without it, these pipelines fail to create, which is where these programs already were. - **Vertex order.** The manual sum relies only on `AttributeAtVertex` and `SV_Barycentrics` sharing an order, which D3D12 defines. P0 reads still go through `nointerpolation` `loadInput`, so they don't depend on which vertex `AttributeAtVertex(0)` is. Tested on: Windows 11, RX 9060 XT (RDNA4), driver 32.0.31044.16. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-24 20:02:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:25:04Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 99. GPU/valu execution tests are Windows-gated and were not run here.

Rows read both flat and interpolated are now interpolated by hand: manual_rows computes the per-row mode bitmask from the stage inputs (fp16 pack2 rows included, integer/system values forced flat), barycentrics derives the sample position, and interpolate emits the row reads. Signature/container carry the new metadata. Three macOS tests in emit/mod.rs cover the flat+interpolated case (99 passed, +3). The remaining execution coverage is Windows-gated.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045876936 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1451#pullrequestreview-6045876936). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T19:25:04Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 99. GPU/valu execution tests are Windows-gated and were not run here. Rows read both flat and interpolated are now interpolated by hand: `manual_rows` computes the per-row mode bitmask from the stage inputs (fp16 pack2 rows included, integer/system values forced flat), `barycentrics` derives the sample position, and `interpolate` emits the row reads. Signature/container carry the new metadata. Three macOS tests in `emit/mod.rs` cover the flat+interpolated case (99 passed, +3). The remaining execution coverage is Windows-gated.
upstream-sync closed this pull request 2026-11-25 01:06:34 +00:00
Marvisak commented 2026-11-25 01:08:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:40:32Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1682. By-hand interpolation for the 207 'computed barycentrics' programs: main solved that class another way (io.rs joined/unless, container same_mode_per_row; 207 -> 0), and the same author's #1682 is a superset.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148758664 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1451#issuecomment-7148758664). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:40:32Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1682. By-hand interpolation for the 207 'computed barycentrics' programs: main solved that class another way (io.rs `joined`/`unless`, container `same_mode_per_row`; 207 -> 0), and the same author's #1682 is a superset. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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
Marvisak/VIctory!1450
No description provided.