Shaders: allow redundant masked v_mov_b32 writes after per-lane descriptor joins (fixes #750) #3298

Open
github-bot wants to merge 1 commit from github-bot/gh-3298 into main AGit
Owner

@⁠pushkarreddyy on GitHub · 2026-11-26 16:22 UTC · original
pushkarreddyy:fix/shader-redundant-masked-write → main · +193 −12 · 1 files · 1 commits · open

Summary

Allows redundant masked v_mov_b32 writes after a per-lane descriptor join when every active lane writes the exact value its register already held (fixes #750).

Root Cause

In crates/victory-shader/src/resource.rs, Tracer::lane_value called Tracer::runs(site, known)? on every VGPR copy and rejected any masked write where some lanes in known could skip site, even when the active lanes wrote back the same value they already held from the prior SSA definition (such as a phi arm).

Changes

  • crates/victory-shader/src/resource.rs:
    • Added Tracer::redundant_mov_prior and Tracer::same_under: when runs(site, known) fails on a v_mov_b32, checks whether the prior SSA value of that VGPR in the block agrees with the written value on all active lanes (known + reach + guard). If so, lane_value continues tracing through the prior value so both active and skipping lanes remain consistent.
    • Added positive regression test joined_descriptor_redundant_partial_write (from #750) and negative test joined_descriptor_non_redundant_partial_write_fails.

Testing & Verification

  • Added joined_descriptor_redundant_partial_write and joined_descriptor_non_redundant_partial_write_fails in crates/victory-shader/src/resource.rs.
  • Testers on untested GPU models and drivers are welcome to verify shader translation and waterfall tracking.

No game files used.

AI-assisted: yes (Gemini 4 Neon)

**@⁠pushkarreddyy** on GitHub · 2026-11-26 16:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/3298) `pushkarreddyy:fix/shader-redundant-masked-write` → `main` · +193 −12 · 1 files · 1 commits · open ## Summary Allows redundant masked `v_mov_b32` writes after a per-lane descriptor join when every active lane writes the exact value its register already held (fixes #750). ## Root Cause In `crates/victory-shader/src/resource.rs`, `Tracer::lane_value` called `Tracer::runs(site, known)?` on every VGPR copy and rejected any masked write where some lanes in `known` could skip `site`, even when the active lanes wrote back the same value they already held from the prior SSA definition (such as a `phi` arm). ## Changes - `crates/victory-shader/src/resource.rs`: - Added `Tracer::redundant_mov_prior` and `Tracer::same_under`: when `runs(site, known)` fails on a `v_mov_b32`, checks whether the prior SSA value of that VGPR in the block agrees with the written value on all active lanes (`known + reach + guard`). If so, `lane_value` continues tracing through the prior value so both active and skipping lanes remain consistent. - Added positive regression test `joined_descriptor_redundant_partial_write` (from #750) and negative test `joined_descriptor_non_redundant_partial_write_fails`. ## Testing & Verification - Added `joined_descriptor_redundant_partial_write` and `joined_descriptor_non_redundant_partial_write_fails` in `crates/victory-shader/src/resource.rs`. - Testers on untested GPU models and drivers are welcome to verify shader translation and waterfall tracking. No game files used. AI-assisted: yes (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:27:45 +00:00
github-bot force-pushed github-bot/gh-3298 from e8f85261dc to e95add4b2f 2026-11-26 16:33:48 +00:00 Compare
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 16:50 UTC · original · reviewed

Ran local verification on Windows 11 x64 (origin/main 63bcca4 merged with this PR):

  • cargo test -p victory-shader --lib resource::tests:: -- --test-threads=1: 36 passed, 1 failed — the newly added test resource::tests::joined_descriptor_redundant_partial_write fails:
    thread 'resource::tests::joined_descriptor_redundant_partial_write' panicked at crates\victory-shader\src\resource.rs:4012:34:
    called `Result::unwrap()` on an `Err` value: Unsupported { offset: 264, what: "a per-lane descriptor written where some lanes may keep the old one" }
    
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 16:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/3298#pullrequestreview-6077842122) · **reviewed** Ran local verification on Windows 11 x64 (`origin/main` `63bcca4` merged with this PR): - `cargo test -p victory-shader --lib resource::tests:: -- --test-threads=1`: **36 passed, 1 failed** — the newly added test `resource::tests::joined_descriptor_redundant_partial_write` fails: ``` thread 'resource::tests::joined_descriptor_redundant_partial_write' panicked at crates\victory-shader\src\resource.rs:4012:34: called `Result::unwrap()` on an `Err` value: Unsupported { offset: 264, what: "a per-lane descriptor written where some lanes may keep the old one" } ``` - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 18:24 UTC · original

WARP verification of #3298 (synthetic tests only, no game files, no physical GPU).

Result: the PR's new positive test joined_descriptor_redundant_partial_write fails on the PR head.

Commits

  • Head: e95add4b2f6129935f6b2e4fda0d54292ccb0c15
  • Base / main control: 63bcca43c6a00a758510398fa43096ce7e4f7df0

Environment

  • Windows 11 10.0.26200, rustc/cargo 1.98.1
  • WARP d3d10warp.dll 10.0.26100.9818, dxil.dll 1.8.2502.11 (Windows SDK 10.0.26100.0 x64)
  • VICTORY_WARP=1, VICTORY_D3D12_WARP=1

New tests, head vs control
Control = 63bcca43 with only the PR's two tests applied.

test head control
resource::tests::joined_descriptor_redundant_partial_write FAILED FAILED
resource::tests::joined_descriptor_non_redundant_partial_write_fails ok ok

Both sides fail with the same error at waterfall(&words, false).unwrap():
Unsupported { offset: 264, what: "a per-lane descriptor written where some lanes may keep the old one" }.
It is deterministic: it failed on a parallel run and on --test-threads=1. These tests are pure shader tracing and do not touch the GPU, so WARP is not a factor. As the tests are written here, the PR's change does not make the redundant masked write accepted. The negative test passes both before and after, so it does not show the change.

Full cargo test -p victory-shader --lib on head: 299 passed, 5 failed, 3 ignored (307 total, 1955 s).

  • 1 failure is the PR's new positive test above.
  • 4 failures are the same wave-32/gather emit::synthetic_tests::* failures that also fail on unmodified 63bcca43. They are permutes_read_the_lane_named_and_zero_from_lanes_left_out, permutes_mask_high_address_bits_and_divergent_branches, gathers_at_a_level_match_the_hardware and a_mask_joined_with_data_at_a_uniform_loop_is_its_number.

Not tested

  • Any physical GPU: WARP software adapter only. The 3 wave-32 tests fail on WARP for lack of a wave32 pipeline, on both sides.
  • No game files, dumps or retail shaders, so I could not check the real-shader case behind #750.
  • I did not run clippy or xtask policy.

AI use: Claude Code (Claude Sonnet 5.5)

**@⁠oni-swr** on GitHub · 2026-11-26 18:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3298#issuecomment-7200426929) WARP verification of #3298 (synthetic tests only, no game files, no physical GPU). **Result: the PR's new positive test `joined_descriptor_redundant_partial_write` fails on the PR head.** **Commits** - Head: `e95add4b2f6129935f6b2e4fda0d54292ccb0c15` - Base / main control: `63bcca43c6a00a758510398fa43096ce7e4f7df0` **Environment** - Windows 11 10.0.26200, rustc/cargo 1.98.1 - WARP `d3d10warp.dll` 10.0.26100.9818, `dxil.dll` 1.8.2502.11 (Windows SDK 10.0.26100.0 x64) - `VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1` **New tests, head vs control** Control = `63bcca43` with only the PR's two tests applied. | test | head | control | |---|---|---| | `resource::tests::joined_descriptor_redundant_partial_write` | **FAILED** | FAILED | | `resource::tests::joined_descriptor_non_redundant_partial_write_fails` | ok | ok | Both sides fail with the same error at `waterfall(&words, false).unwrap()`: `Unsupported { offset: 264, what: "a per-lane descriptor written where some lanes may keep the old one" }`. It is deterministic: it failed on a parallel run and on `--test-threads=1`. These tests are pure shader tracing and do not touch the GPU, so WARP is not a factor. As the tests are written here, the PR's change does not make the redundant masked write accepted. The negative test passes both before and after, so it does not show the change. **Full `cargo test -p victory-shader --lib` on head:** 299 passed, 5 failed, 3 ignored (307 total, 1955 s). - 1 failure is the PR's new positive test above. - 4 failures are the same wave-32/gather `emit::synthetic_tests::*` failures that also fail on unmodified `63bcca43`. They are `permutes_read_the_lane_named_and_zero_from_lanes_left_out`, `permutes_mask_high_address_bits_and_divergent_branches`, `gathers_at_a_level_match_the_hardware` and `a_mask_joined_with_data_at_a_uniform_loop_is_its_number`. **Not tested** - Any physical GPU: WARP software adapter only. The 3 wave-32 tests fail on WARP for lack of a wave32 pipeline, on both sides. - No game files, dumps or retail shaders, so I could not check the real-shader case behind #750. - I did not run clippy or `xtask policy`. AI use: Claude Code (Claude Sonnet 5.5)
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-26 18:46 UTC · original

@⁠Marvisak Please review and merge this PR. Testers, kindly run on untested GPU models. AI‑assisted ✅ Gemini‑4 Neon

**@⁠pushkarreddyy** on GitHub · 2026-11-26 18:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/3298#issuecomment-7200829199) @⁠Marvisak Please review and merge this PR. Testers, kindly run on untested GPU models. AI‑assisted ✅ Gemini‑4 Neon
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 18:59 UTC · original

I reproduced the positive test failure on e95add4 before any DXIL or GPU work. 8b404f4 is a follow-up on that exact head.

The redundancy proof needs the incoming branch condition as well as the predecessor’s reach condition. With that condition, the two copies of the integer comparison also need to be recognized as the same per-lane predicate. Their explicit operands agree, while the implicit EXEC SSA value was redefined when EXEC was restored. The follow-up reuses the existing edge conditions, keeps explicit inputs in the comparison, and uses the existing join depth limit for nested proofs.

With the follow-up, the positive fixture traces both original table offsets (0 and 0x20). The real write in the negative fixture is still refused. All 37 resource tests passed. In three app-local WARP runs with DXIL validation, all five waterfall tests passed, including the extended test that reads red 1.0 from the first texture in lanes 0–15 and red 2.0 from the second in lanes 16–31, with and without the redundant write. Both all-target Clippy configurations passed. The full WARP run was 300 passed, 4 failed, 3 ignored, with the same four failures already reproduced on main.

pushkarreddyy, please consider applying the follow-up and rerunning CI on the PR branch. If you fold it into another commit, please preserve its Git author or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 18:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/3298#issuecomment-7201073143) I reproduced the positive test failure on `e95add4` before any DXIL or GPU work. [`8b404f4`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/8b404f4aa2d00c030ab15080f2c99a916cc66e1a) is a follow-up on that exact head. The redundancy proof needs the incoming branch condition as well as the predecessor’s reach condition. With that condition, the two copies of the integer comparison also need to be recognized as the same per-lane predicate. Their explicit operands agree, while the implicit EXEC SSA value was redefined when EXEC was restored. The follow-up reuses the existing edge conditions, keeps explicit inputs in the comparison, and uses the existing join depth limit for nested proofs. With the follow-up, the positive fixture traces both original table offsets (`0` and `0x20`). The real write in the negative fixture is still refused. All 37 resource tests passed. In three app-local WARP runs with DXIL validation, all five waterfall tests passed, including the extended test that reads red 1.0 from the first texture in lanes 0–15 and red 2.0 from the second in lanes 16–31, with and without the redundant write. Both all-target Clippy configurations passed. The full WARP run was 300 passed, 4 failed, 3 ignored, with the same four failures already reproduced on `main`. pushkarreddyy, please consider applying the follow-up and rerunning CI on the PR branch. If you fold it into another commit, please preserve its Git author or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 20:24 UTC · original · requested changes

Requesting changes on e95add4b: the new positive regression test currently fails on the PR head, and there are two soundness gaps in the equivalence proof.

Blocking issues

  1. [P1] joined_descriptor_redundant_partial_write fails on e95add4b:
    Running cargo test --locked -p victory-shader --lib resource::tests:: -- --test-threads=1 gives 36 passed, 1 failed (crates/victory-shader/src/resource.rs:4012:34 panics with Unsupported { offset: 264, what: "a per-lane descriptor written where some lanes may keep the old one" }). As noted in earlier comments, two independent issues break the proof:
    • same_compare (resource.rs:1640-1648) checks ia.reads == ib.reads, which fails when two identical v_cmp_* instructions read distinct implicit Reg::S(EXEC) SSA values (e.g., entry EXEC vs. restored EXEC).
    • check_phi (resource.rs:1667-1679) only pushes (lanes.reach[pred], true) and drops the pred -> pb branch edge condition, so it traverses unmatching predecessor edges back to the pre-join register input.
  2. [P1] vstep ignores clamp and omod on v_mov_b32:
    vstep (resource.rs:1689-1702) only guards abs == 0 && neg == 0 && sdwa.is_none() && dpp.is_none(), omitting !f.clamp && f.omod == 0. However, emit/lower.rs:6230-6236 and write_f (emit/lower.rs:2811-2831) treat v_mov_b32 with clamp or nonzero omod as a float transform rather than a bitwise copy. A masked v_mov_b32_e64 v4, s24 with omod != 0 or clamp would be misclassified by same_under as an identity write.
  3. [P1] check_phi traverses loop-header backedges:
    Unlike lane_phi (resource.rs:1951), check_phi (resource.rs:1673) does not reject loop headers (rpo[pred] >= rpo[pb]). Because structure.rs:1400-1402 forgets loop-redefined atoms across backedges, mixing exit-iteration facts in known with a backedge check can make consistent(&edge) return false and silently discard a live loop-carried value.

Additional notes

  • Prior definition lookup (resource.rs:1587-1598): scanning only earlier instructions in the same block and local phis misses reaching definitions from dominators; in IR, the prior value of the overwritten VGPR is already carried on inst.read(reg).
  • Dual-phi correlation (resource.rs:1651-1684): expanding va and vb sequentially rather than pairing matching predecessors allows cross-edge comparisons when both operands are phis from the same block.
  • Test coverage: once the proof passes, joined_descriptor_redundant_partial_write should also assert the traced descriptors/waterfall counts (and joined_descriptor_non_redundant_partial_write_fails will start genuinely exercising the s28 != s24 mismatch instead of failing at the pre-join input).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 20:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3298#pullrequestreview-6080118362) · **requested changes** Requesting changes on `e95add4b`: the new positive regression test currently fails on the PR head, and there are two soundness gaps in the equivalence proof. ### Blocking issues 1. **[P1] `joined_descriptor_redundant_partial_write` fails on `e95add4b`:** Running `cargo test --locked -p victory-shader --lib resource::tests:: -- --test-threads=1` gives **36 passed, 1 failed** (`crates/victory-shader/src/resource.rs:4012:34` panics with `Unsupported { offset: 264, what: "a per-lane descriptor written where some lanes may keep the old one" }`). As noted in earlier comments, two independent issues break the proof: - `same_compare` (`resource.rs:1640-1648`) checks `ia.reads == ib.reads`, which fails when two identical `v_cmp_*` instructions read distinct implicit `Reg::S(EXEC)` SSA values (e.g., entry `EXEC` vs. restored `EXEC`). - `check_phi` (`resource.rs:1667-1679`) only pushes `(lanes.reach[pred], true)` and drops the `pred -> pb` branch edge condition, so it traverses unmatching predecessor edges back to the pre-join register input. 2. **[P1] `vstep` ignores `clamp` and `omod` on `v_mov_b32`:** `vstep` (`resource.rs:1689-1702`) only guards `abs == 0 && neg == 0 && sdwa.is_none() && dpp.is_none()`, omitting `!f.clamp && f.omod == 0`. However, `emit/lower.rs:6230-6236` and `write_f` (`emit/lower.rs:2811-2831`) treat `v_mov_b32` with `clamp` or nonzero `omod` as a float transform rather than a bitwise copy. A masked `v_mov_b32_e64 v4, s24` with `omod != 0` or `clamp` would be misclassified by `same_under` as an identity write. 3. **[P1] `check_phi` traverses loop-header backedges:** Unlike `lane_phi` (`resource.rs:1951`), `check_phi` (`resource.rs:1673`) does not reject loop headers (`rpo[pred] >= rpo[pb]`). Because `structure.rs:1400-1402` forgets loop-redefined atoms across backedges, mixing exit-iteration facts in `known` with a backedge check can make `consistent(&edge)` return `false` and silently discard a live loop-carried value. ### Additional notes - **Prior definition lookup (`resource.rs:1587-1598`):** scanning only earlier instructions in the same block and local phis misses reaching definitions from dominators; in IR, the prior value of the overwritten VGPR is already carried on `inst.read(reg)`. - **Dual-phi correlation (`resource.rs:1651-1684`):** expanding `va` and `vb` sequentially rather than pairing matching predecessors allows cross-edge comparisons when both operands are phis from the same block. - **Test coverage:** once the proof passes, `joined_descriptor_redundant_partial_write` should also assert the traced descriptors/waterfall counts (and `joined_descriptor_non_redundant_partial_write_fails` will start genuinely exercising the `s28 != s24` mismatch instead of failing at the pre-join input).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3298/head:github-bot/gh-3298'
git switch 'github-bot/gh-3298'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3298'
git switch 'github-bot/gh-3298'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3298'
git switch 'github-bot/gh-3298'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3298'
git switch 'main'
git merge --squash 'github-bot/gh-3298'
git switch 'main'
git merge --ff-only 'github-bot/gh-3298'
git switch 'main'
git merge 'github-bot/gh-3298'
git push origin 'main'
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!3298
No description provided.