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

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

@⁠federalcontraband on GitHub · 2026-11-24 18:06 UTC · original
federalcontraband:shaders-manual-interpolation → main · +412 −36 · 5 files · 1 commits · closed without merging

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

**@⁠federalcontraband** on GitHub · 2026-11-24 18:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1451) `federalcontraband:shaders-manual-interpolation` → `main` · +412 −36 · 5 files · 1 commits · closed without merging `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)
A D3D12 input row has one interpolation mode. Pixel input rows whose
reads need more than one (an attribute read both as P0 and
interpolated, or packed beside an integer or the front face) are
declared nointerpolation, and an interpolation of one is the three
vertex values (AttributeAtVertex) weighted by SV_Barycentrics, as the
console's v_interp computes it.

io: barycentrics are followed through plain v_mov_b32 copies, and an
interpolation at i = j = 0 is the provoking vertex's value (P0), as
v_interp_mov p0 reads it. 96 of the 207 "computed barycentrics" were
that; the rest read i/j through phis and stay refused.

emit: an element packed into a row with a constant one defaults to
constant, which fixes most "interpolation mode that differs from
another element packed into the same row" validator errors.

Over Grand Theft Auto VI's shaders: 126 more vertex/pixel programs
validate (12,167 -> 12,293), none fewer; every emitted program still
makes a pipeline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:32:19 +00:00
github-bot closed this pull request 2026-11-26 04:32:19 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:40 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1451#issuecomment-7148758664) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1451
No description provided.