Shaders: honor EXEC guards in Lower::interp #3147

Open
Arkenoz wants to merge 2 commits from upstream-pr/3149 into main
Arkenoz commented 2026-11-26 10:23:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Arkenoz on 2026-11-26T10:23:50Z.


Summary

Fixes missing EXEC guard handling when writing interpolation results in Lower::interp (crates/victory-shader/src/emit/lower.rs):

  1. Guarded vdst writes: ir.rs and structure.rs already classify Fields::Vintrp instructions as vector writes governed by EXEC and compute guards[b][i], but Lower::interp previously passed None to write and write_half. While the interpolation evaluation itself runs across lanes, the write to vdst must still preserve inactive lanes under narrowed EXEC (v_cmpx_*, s_and_saveexec_*). Lower::interp now queries self.guard(site.0, site.1)? and applies it to v_interp_mov_f32, v_interp_p2_f32, and v_interp_p2_f16.
  2. Preserving pre-p1 vdst on shared-destination p1 + p2 pairs: When v_interp_p1_* and v_interp_p2_* target the same VGPR, p1 is not emitted to DXIL and records Val::Missing(_), which would otherwise collapse inactive lanes to 0 on p2. Added Lower::interp_old to trace back to p1.read(Reg::V(reg)) when bools.meet proves p1 never executed on lanes outside p2's guard (and reach[b] => reach[b1]).
  3. Half-register writes (v_interp_p2_f16): Factored write_placed_with_old and write_half_with_old so active lanes keep existing half-preservation/modifier behavior while inactive lanes preserve the full previous (or pre-p1) vdst.

Leaves omod/clamp/op_sel[3] and SV_Barycentrics paths untouched to avoid conflicts with open PRs.

Testing

  • Added emit::tests::guarded_interpolation_preserves_inactive_lanes in crates/victory-shader/src/emit/mod.rs, running 5 synthetic pixel shaders via Host::draw (verified failing before the fix and passing after on both NVIDIA RTX 3060 and WARP, with DXIL validation):
    • v_interp_mov_f32
    • v_interp_p1_f32 + v_interp_p2_f32 (shared vdst)
    • v_interp_p1ll_f16 + v_interp_p2_f16 (low half, separate vdst)
    • v_interp_p1ll_f16 + v_interp_p2_f16 (shared vdst)
    • v_interp_p1ll_f16 + v_interp_p2_f16 (op_sel[3] = 1 high half, separate vdst)
  • rustfmt --edition 2024 --check — 0 diffs on all touched/added lines
  • cargo clippy --workspace --all-targets -- -D warnings — passed
  • cargo check --workspace --all-targets — passed
  • cargo xtask policy — passed (asset policy: 191 files ok)
  • cargo test -p victory-shader --locked --lib emit::tests:: — passed (18 passed; 0 failed)

Coordination & AI disclosure

  • Claimed in #1633.
  • AI-assisted (Antigravity / Gemini 4 Neon).
<!-- greyfinch-sync:Marvisak/VIctory:issue:5508231956 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3149). Originally posted by [Arkenoz](https://github.com/Arkenoz) on 2026-11-26T10:23:50Z. --- ### Summary Fixes missing `EXEC` guard handling when writing interpolation results in `Lower::interp` (`crates/victory-shader/src/emit/lower.rs`): 1. **Guarded `vdst` writes:** `ir.rs` and `structure.rs` already classify `Fields::Vintrp` instructions as vector writes governed by `EXEC` and compute `guards[b][i]`, but `Lower::interp` previously passed `None` to `write` and `write_half`. While the interpolation evaluation itself runs across lanes, the write to `vdst` must still preserve inactive lanes under narrowed `EXEC` (`v_cmpx_*`, `s_and_saveexec_*`). `Lower::interp` now queries `self.guard(site.0, site.1)?` and applies it to `v_interp_mov_f32`, `v_interp_p2_f32`, and `v_interp_p2_f16`. 2. **Preserving pre-`p1` `vdst` on shared-destination `p1 + p2` pairs:** When `v_interp_p1_*` and `v_interp_p2_*` target the same VGPR, `p1` is not emitted to DXIL and records `Val::Missing(_)`, which would otherwise collapse inactive lanes to `0` on `p2`. Added `Lower::interp_old` to trace back to `p1.read(Reg::V(reg))` when `bools.meet` proves `p1` never executed on lanes outside `p2`'s guard (and `reach[b] => reach[b1]`). 3. **Half-register writes (`v_interp_p2_f16`):** Factored `write_placed_with_old` and `write_half_with_old` so active lanes keep existing half-preservation/modifier behavior while inactive lanes preserve the full previous (or pre-`p1`) `vdst`. Leaves `omod`/`clamp`/`op_sel[3]` and `SV_Barycentrics` paths untouched to avoid conflicts with open PRs. ### Testing - Added `emit::tests::guarded_interpolation_preserves_inactive_lanes` in `crates/victory-shader/src/emit/mod.rs`, running 5 synthetic pixel shaders via `Host::draw` (verified failing before the fix and passing after on both NVIDIA RTX 3060 and WARP, with DXIL validation): - `v_interp_mov_f32` - `v_interp_p1_f32` + `v_interp_p2_f32` (shared `vdst`) - `v_interp_p1ll_f16` + `v_interp_p2_f16` (low half, separate `vdst`) - `v_interp_p1ll_f16` + `v_interp_p2_f16` (shared `vdst`) - `v_interp_p1ll_f16` + `v_interp_p2_f16` (`op_sel[3] = 1` high half, separate `vdst`) - `rustfmt --edition 2024 --check` — 0 diffs on all touched/added lines - `cargo clippy --workspace --all-targets -- -D warnings` — passed - `cargo check --workspace --all-targets` — passed - `cargo xtask policy` — passed (`asset policy: 191 files ok`) - `cargo test -p victory-shader --locked --lib emit::tests::` — passed (`18 passed; 0 failed`) ### Coordination & AI disclosure - Claimed in #1633. - AI-assisted (Antigravity / Gemini 4 Neon).
Dukestar69 commented 2026-11-26 10:27:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T10:27:30Z.

Review: APPROVED


Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-shader --lib guarded_interpolation_preserves_inactive_lanes -- --test-threads=1: passed.
  • cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1: 33/33 passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly honors EXEC guards in Lower::interp so inactive lanes preserve their prior VGPR values.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6072419241 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3149#pullrequestreview-6072419241). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:27:30Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib guarded_interpolation_preserves_inactive_lanes -- --test-threads=1`: passed. - `cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1`: 33/33 passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly honors EXEC guards in `Lower::interp` so inactive lanes preserve their prior VGPR values. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Jackster commented 2026-11-26 23:02:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T23:02:25Z.


Windows 11, 63bcca4 + this PR:

  • cargo test -p victory-shader --lib --features host guarded_interpolation: 1 passed (the new guarded_interpolation_preserves_inactive_lanes).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205201102 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3149#issuecomment-7205201102). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T23:02:25Z. --- Windows 11, `63bcca4` + this PR: - `cargo test -p victory-shader --lib --features host guarded_interpolation`: 1 passed (the new `guarded_interpolation_preserves_inactive_lanes`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. Synthetic only. AI-assisted.
fuzeofficlal commented 2026-11-26 23:26:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:26:47Z.

Review: CHANGES_REQUESTED


Thanks for adding EXEC guard preservation to Lower::interp along with the draw-test coverage. Two correctness issues came up in the shared-destination p1 + p2 handling:

  1. Shared-destination v_interp_p2_f16 zeroes the untouched half in active lanes (crates/victory-shader/src/emit/lower.rs:6904-6920, crates/victory-shader/src/emit/mod.rs:1985):
    In write_half_with_old, guard_old is only passed to the outer !guard select at line 6919 (old_for_guard). For active lanes, line 6904 still reads inst.read(Reg::V(reg)) to preserve the untouched half — which for a shared-destination v_interp_p1ll_f16 + v_interp_p2_f16 pair is p1's Val::Missing output, causing line 6906 to pack 0 into the untouched half. You can see this in the new v_interp_p2_f16_shared test case at mod.rs:1985, which skips checking the high half in active lanes ((0.25, None)) even though v_interp_p2_f16_sep preserves 2.0. Passing the recovered pre-p1 value through for the active-lane half preservation (when p1 did not define a representable half) should fix both halves.
  2. Stricter p2 guard (A && B vs p1's A) zeroes !A lanes (crates/victory-shader/src/emit/lower.rs:8209-8246, 2762-2774):
    In interp_old, if lanes exist that run p1 (g1) without p2 (g2), interp_old falls back to Some(old) (where old is p1's Val::Missing SSA value), and write_placed_with_old replaces all !g2 lanes with 0 — clobbering !A lanes that skipped both p1 and p2 and should retain the pre-p1 dst value.

Once those two cases are handled (and v_interp_p2_f16_shared asserts Some(2.0) on the untouched high half in active lanes), this should be good to go.

<!-- greyfinch-sync:Marvisak/VIctory:review:6081451460 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3149#pullrequestreview-6081451460). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T23:26:47Z. **Review:** CHANGES_REQUESTED --- Thanks for adding `EXEC` guard preservation to `Lower::interp` along with the draw-test coverage. Two correctness issues came up in the shared-destination `p1` + `p2` handling: 1. **Shared-destination `v_interp_p2_f16` zeroes the untouched half in active lanes (`crates/victory-shader/src/emit/lower.rs:6904-6920`, `crates/victory-shader/src/emit/mod.rs:1985`)**: In `write_half_with_old`, `guard_old` is only passed to the outer `!guard` select at line 6919 (`old_for_guard`). For active lanes, line 6904 still reads `inst.read(Reg::V(reg))` to preserve the untouched half — which for a shared-destination `v_interp_p1ll_f16` + `v_interp_p2_f16` pair is `p1`'s `Val::Missing` output, causing line 6906 to pack `0` into the untouched half. You can see this in the new `v_interp_p2_f16_shared` test case at `mod.rs:1985`, which skips checking the high half in active lanes (`(0.25, None)`) even though `v_interp_p2_f16_sep` preserves `2.0`. Passing the recovered pre-`p1` value through for the active-lane half preservation (when `p1` did not define a representable half) should fix both halves. 2. **Stricter `p2` guard (`A && B` vs `p1`'s `A`) zeroes `!A` lanes (`crates/victory-shader/src/emit/lower.rs:8209-8246, 2762-2774`)**: In `interp_old`, if lanes exist that run `p1` (`g1`) without `p2` (`g2`), `interp_old` falls back to `Some(old)` (where `old` is `p1`'s `Val::Missing` SSA value), and `write_placed_with_old` replaces **all** `!g2` lanes with `0` — clobbering `!A` lanes that skipped both `p1` and `p2` and should retain the pre-`p1` `dst` value. Once those two cases are handled (and `v_interp_p2_f16_shared` asserts `Some(2.0)` on the untouched high half in active lanes), this should be good to go.
Arkenoz commented 2026-11-27 14:10:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Arkenoz on 2026-11-27T14:10:34Z.


Thanks for the review, @fuzeofficial! Fixed both shared-destination p1 + p2 cases:

  1. Active-lane half preservation (v_interp_p2_f16): interp_old now recovers pre_p1 as half_old whenever inst.read(Reg::V(reg)) is p1's Val::Missing output, and write_half_with_old uses it to preserve the untouched half in active lanes. Updated v_interp_p2_f16_shared to assert Some(2.0) on the untouched high half.
  2. Stricter p2 guard (A && B vs p1's A): interp_old now returns a precomputed DXIL fallback for !g2 lanes (select(g1, 0, pre_p1) when both g1 && !g2 and !g1 && !g2 are reachable), preserving the pre-p1 dst value in !A lanes. Added v_interp_p2_f32_stricter_guard and v_interp_p2_f16_stricter_guard draw tests covering A && B, A && !B, and !A lanes.

Verified:

  • cargo test -p victory-shader --lib --features host guarded_interpolation -- --test-threads=1 — passed
  • cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1 — 33 passed
  • cargo clippy -p victory-shader --all-targets -- -D warnings — clean
  • cargo xtask policy — 191 files ok
<!-- greyfinch-sync:Marvisak/VIctory:comment:7220442716 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3149#issuecomment-7220442716). Originally posted by [Arkenoz](https://github.com/Arkenoz) on 2026-11-27T14:10:34Z. --- Thanks for the review, @fuzeofficial! Fixed both shared-destination `p1 + p2` cases: 1. **Active-lane half preservation (`v_interp_p2_f16`)**: `interp_old` now recovers `pre_p1` as `half_old` whenever `inst.read(Reg::V(reg))` is `p1`'s `Val::Missing` output, and `write_half_with_old` uses it to preserve the untouched half in active lanes. Updated `v_interp_p2_f16_shared` to assert `Some(2.0)` on the untouched high half. 2. **Stricter `p2` guard (`A && B` vs `p1`'s `A`)**: `interp_old` now returns a precomputed DXIL fallback for `!g2` lanes (`select(g1, 0, pre_p1)` when both `g1 && !g2` and `!g1 && !g2` are reachable), preserving the pre-`p1` `dst` value in `!A` lanes. Added `v_interp_p2_f32_stricter_guard` and `v_interp_p2_f16_stricter_guard` draw tests covering `A && B`, `A && !B`, and `!A` lanes. Verified: - `cargo test -p victory-shader --lib --features host guarded_interpolation -- --test-threads=1` — passed - `cargo test -p victory-shader --lib emit::lower::tests:: -- --test-threads=1` — 33 passed - `cargo clippy -p victory-shader --all-targets -- -D warnings` — clean - `cargo xtask policy` — 191 files ok
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3149:upstream-pr/3149'
git switch 'upstream-pr/3149'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3149'
git switch 'upstream-pr/3149'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3149'
git switch 'upstream-pr/3149'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3149'
git switch 'main'
git merge --squash 'upstream-pr/3149'
git switch 'main'
git merge --ff-only 'upstream-pr/3149'
git switch 'main'
git merge 'upstream-pr/3149'
git push origin 'main'
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!3147
No description provided.