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

Closed
federalcontraband wants to merge 2 commits from upstream-pr/1682 into main
federalcontraband commented 2026-11-24 20:43:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by federalcontraband on 2026-11-24T20:43:16Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6591025698 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1682). Originally posted by [federalcontraband](https://github.com/federalcontraband) on 2026-11-24T20:43:16Z. --- 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)
catminou4 commented 2026-11-24 22:01:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:40:12Z.

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 → 102 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.

Interpolations with any i/j weights are computed by hand from SV_Barycentrics: rows read with mixed interpolation modes are declared flat and re-interpolated manually (manual_rows bitmask per row incl. fp16 pack2 row2), barycentrics read as data map to PerspectiveCenter/etc., and plain interpolation declares no barycentrics. +5 macOS tests (102 total). Big but well-tested.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047849654 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1682#pullrequestreview-6047849654). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:40:12Z. **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 → 102 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests. Interpolations with any i/j weights are computed by hand from SV_Barycentrics: rows read with mixed interpolation modes are declared flat and re-interpolated manually (manual_rows bitmask per row incl. fp16 pack2 row2), barycentrics read as data map to PerspectiveCenter/etc., and plain interpolation declares no barycentrics. +5 macOS tests (102 total). Big but well-tested.
upipibi commented 2026-11-24 23:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-24T22:52:53Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146752650 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1682#issuecomment-7146752650). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T22:52:53Z. --- 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.
Marvisak commented 2026-11-25 02:06:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:34:21Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149701433 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1682#issuecomment-7149701433). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:34:21Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-25 09:04:33 +00:00
federalcontraband commented 2026-11-25 09:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by federalcontraband on 2026-11-25T08:44:22Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157409131 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1682#issuecomment-7157409131). Originally posted by [federalcontraband](https://github.com/federalcontraband) on 2026-11-25T08:44:22Z. --- 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

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