Shaders: interpolations with any i/j by hand; barycentrics read as data #1682

Closed
github-bot wants to merge 2 commits from gh-pr/1682/head into gh-pr/1682/base
Owner

@⁠federalcontraband on GitHub · 2026-11-24 20:43 UTC · original
federalcontraband:shaders-interpolate-any-barycentrics → main · +708 −46 · 6 files · 2 commits · closed without merging

Stacked on #1451, so its first commit is that PR. Review only the second commit.

victory translate --validate --list over the title's shaders.rpf, compared with #1451:

#1451 this
vertex/pixel programs validated 12,281 12,368 (+87)
"an interpolation with computed barycentrics" 111 0
"barycentrics read directly" 13 0

Per program, 87 go from failing to validated: 77 had "computed barycentrics" and 10 read barycentrics directly. None go from validated to failing. Of the rest, 32 now stop at "an opaque lane mask", 3 reach a texture sample that fails "out of bound coord must be undef" (an existing sample-lowering issue), and 2 fail "Program Input Signature does not match".

What these programs do

#1451 handled i = j = 0. The rest read i/j through a phi: v0/v1 are reused as scratch on one path, and the interpolation after the join reads the merged value. Per lane, that value is still the loaded i/j wherever the interpolation is active, but the IR can't prove it. So instead of proving it, this change computes what the hardware computes.

Changes

io.rs

  • When a v_interp_p2_f32 and its v_interp_p1_f32 halves don't read one kind's loaded i and j (or two zeros), every half becomes Interp::ByHand { attribute, second } instead of failing.
  • The 16-bit forms (p1ll_f16/p2_f16) are still refused.

emit/lower.rs

  • A ByHand half is lowered as the instruction is defined: p1 = P0 + i·(P1−P0) and p2 = acc + j·(P2−P0).
    • The vertex values come from AttributeAtVertex.
    • i/j are whatever the registers hold.
    • The attribute's row is declared flat, using #1451's manual_rows.
  • A barycentric input register read as data is SV_Barycentrics: i is .y (P1's weight) and j is .z.
    • It's loaded on first use, from get and when filling phis, so only programs that read one declare SV_Barycentrics.
    • Pull-model barycentrics are still refused.

The sum only uses AttributeAtVertex and SV_Barycentrics together, so it depends only on D3D12 giving both the same vertex order.

Tests

  • emit::tests::an_interpolation_with_other_weights_is_computed_by_hand
  • emit::tests::barycentrics_read_directly_are_sv_barycentrics
  • emit::tests::plain_interpolation_declares_no_barycentrics: checks the load is lazy.
  • Two io tests now expect ByHand halves where they used to expect a refusal.

The emit tests run dxil.dll where it's present. All tests use hand-encoded instructions; no title data. cargo test --workspace passes (348) and clippy is clean.

Not verified

  • In game. As in #1451.
  • Precision. By-hand interpolation rounds differently from the fixed-function path. It uses one FMad per half, the same as the console's own two-step form.

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

🤖 Generated with Claude Code

**@⁠federalcontraband** on GitHub · 2026-11-24 20:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/1682) `federalcontraband:shaders-interpolate-any-barycentrics` → `main` · +708 −46 · 6 files · 2 commits · closed without merging Stacked on #1451, so its first commit is that PR. Review only the second commit. `victory translate --validate --list` over the title's `shaders.rpf`, compared with #1451: | | #1451 | this | |---|---|---| | vertex/pixel programs validated | 12,281 | **12,368** (+87) | | "an interpolation with computed barycentrics" | 111 | 0 | | "barycentrics read directly" | 13 | 0 | Per program, 87 go from failing to validated: 77 had "computed barycentrics" and 10 read barycentrics directly. None go from validated to failing. Of the rest, 32 now stop at "an opaque lane mask", 3 reach a texture sample that fails "out of bound coord must be undef" (an existing sample-lowering issue), and 2 fail "Program Input Signature does not match". ### What these programs do #1451 handled `i = j = 0`. The rest read `i`/`j` through a phi: v0/v1 are reused as scratch on one path, and the interpolation after the join reads the merged value. Per lane, that value is still the loaded `i`/`j` wherever the interpolation is active, but the IR can't prove it. So instead of proving it, this change computes what the hardware computes. ### Changes **`io.rs`** - When a `v_interp_p2_f32` and its `v_interp_p1_f32` halves don't read one kind's loaded i and j (or two zeros), every half becomes `Interp::ByHand { attribute, second }` instead of failing. - The 16-bit forms (`p1ll_f16`/`p2_f16`) are still refused. **`emit/lower.rs`** - A `ByHand` half is lowered as the instruction is defined: `p1 = P0 + i·(P1−P0)` and `p2 = acc + j·(P2−P0)`. - The vertex values come from `AttributeAtVertex`. - `i`/`j` are whatever the registers hold. - The attribute's row is declared flat, using #1451's `manual_rows`. - A barycentric input register read as data is `SV_Barycentrics`: `i` is `.y` (P1's weight) and `j` is `.z`. - It's loaded on first use, from `get` and when filling phis, so only programs that read one declare `SV_Barycentrics`. - Pull-model barycentrics are still refused. The sum only uses `AttributeAtVertex` and `SV_Barycentrics` together, so it depends only on D3D12 giving both the same vertex order. ### Tests - `emit::tests::an_interpolation_with_other_weights_is_computed_by_hand` - `emit::tests::barycentrics_read_directly_are_sv_barycentrics` - `emit::tests::plain_interpolation_declares_no_barycentrics`: checks the load is lazy. - Two `io` tests now expect `ByHand` halves where they used to expect a refusal. The emit tests run `dxil.dll` where it's present. All tests use hand-encoded instructions; no title data. `cargo test --workspace` passes (348) and clippy is clean. ### Not verified - **In game.** As in #1451. - **Precision.** By-hand interpolation rounds differently from the fixed-function path. It uses one `FMad` per half, the same as the console's own two-step form. 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]>
An interpolation whose v_interp_p1_f32/p2_f32 halves do not read one
kind's loaded i and j (mostly i/j joined through a phi where v0-v1 are
reused as scratch on another path) is no longer refused: each half is
computed as the hardware defines it, p1 = P0 + i * (P1 - P0) and
p2 = acc + j * (P2 - P0), from AttributeAtVertex, with the attribute's
row declared flat. The 16-bit forms stay refused.

A barycentric input register read as data is SV_Barycentrics (i is .y,
P1's weight; j is .z), loaded on first use, from get and when filling
phis, so that only programs reading one declare it.

Over Grand Theft Auto VI's shaders, on top of the previous commit: 87
more vertex/pixel programs validate (12,281 -> 12,368), 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:41:26 +00:00
github-bot closed this pull request 2026-11-26 04:41:26 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 22:52 UTC · original

NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, at the PR head 3b0c7da. Tests matching interpolat / barycentrics, including the six new ones: 9 passed, 0 failed.
It is based on ffe310e and GitHub shows conflicts with main 70564ae, so this is the head as it stands, not a merge.
AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 22:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1682#issuecomment-7146752650) NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, at the PR head `3b0c7da`. Tests matching `interpolat` / `barycentrics`, including the six new ones: 9 passed, 0 failed. It is based on `ffe310e` and GitHub shows conflicts with `main` `70564ae`, so this is the head as it stands, not a merge. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:34 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/shader.rs, crates/victory-shader/src/io.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1682#issuecomment-7149701433) <!-- victory-triage v1 head=3b0c7dad7330e5e44423cbc55bdcfdbda83b0ce4 verdict=needs-rebase at=2026-11-25T01:34:20Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/shader.rs`, `crates/victory-shader/src/io.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠federalcontraband on GitHub · 2026-11-25 08:44 UTC · original

Closing this: main now covers it. On current main (940d32f), victory translate --validate over the title's shaders shows 0 "computed barycentrics" and no mixed-mode row errors, using joined/unless and same_mode_per_row.

What this PR would still add on top of main is three programs that read barycentrics as data ("barycentrics read directly": two bloom downsample pixel shaders and PS_SampleFromHigherResGrid). That isn't worth rebasing ~300 lines across lower.rs/io.rs/shader.rs for. If it's wanted, I can send a small separate PR that only lowers those reads to SV_Barycentrics.

Thanks for the triage, and thanks @⁠upipibi for the NVIDIA run.

**@⁠federalcontraband** on GitHub · 2026-11-25 08:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/1682#issuecomment-7157409131) Closing this: `main` now covers it. On current `main` (`940d32f`), `victory translate --validate` over the title's shaders shows 0 "computed barycentrics" and no mixed-mode row errors, using `joined`/`unless` and `same_mode_per_row`. What this PR would still add on top of `main` is three programs that read barycentrics as data ("barycentrics read directly": two bloom downsample pixel shaders and `PS_SampleFromHigherResGrid`). That isn't worth rebasing ~300 lines across `lower.rs`/`io.rs`/`shader.rs` for. If it's wanted, I can send a small separate PR that only lowers those reads to `SV_Barycentrics`. Thanks for the triage, and thanks @⁠upipibi for the NVIDIA run.

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!1682
No description provided.