Skip to content

Shaders: keep prior per-lane descriptor word across redundant masked moves (fixes #750) - #1182

Closed
R0D4X wants to merge 1 commit into
Marvisak:mainfrom
R0D4X:fix/issue-750-redundant-per-lane-write
Closed

R0D4X wants to merge 1 commit into
Marvisak:mainfrom
R0D4X:fix/issue-750-redundant-per-lane-write

Conversation

@R0D4X

@R0D4X R0D4X commented Nov 24, 2026

Copy link
Copy Markdown

Summary

Fixes #750.

When a per-lane descriptor joined across control flow is followed by a plain predicated v_mov_b32 that re-writes one of its VGPR words with the exact value every active lane already holds, Tracer::lane_value previously refused the program with "a per-lane descriptor written where some lanes may keep the old one".

What changed

  • crates/victory-shader/src/resource.rs:
    • Added Tracer::redundant_vmov and Tracer::equals_under: when Tracer::runs cannot prove that every lane in known executes a plain v_mov_b32, check whether the destination VGPR's prior SSA value (inst.read(Reg::V(reg))) already equals the move's source on every feasible active lane (known ∧ reach[site] ∧ guard, walking forward phis and v_cndmask_b32 joins). If proven, the move is a no-op and lane_value continues from the prior VGPR value; otherwise the conservative refusal is unchanged.
    • Added Tracer::lanes_meet (with canonical pure v_cmp*/v_cmpx* comparison keys and BDD-order backtracking meet_equiv, fast-pathing straight through Bools::meet when no two lane-compare atoms share a key) so repeated comparisons of identical SSA operands (including operand swaps and integer negations, without unsafe float NaN negations) are recognized as equivalent without mutating structure::Bools.
    • Added 4 synthetic unit tests in resource::tests covering the exact Shader resource tracking: redundant masked write after a per-lane descriptor join is refused (synthetic repro on #566) #750 repro, a negated integer compare on the else arm, and two negative cases (writing the other arm's word; writing under a wider predicate mask) that must still be refused.
  • crates/victory-shader/src/emit/waterfall_tests.rs:
    • Added lanes_sample_their_arm_after_a_redundant_masked_write to verify DXIL lowering, dxil.dll validation, and end-to-end execution on both host GPU hardware and D3D12 WARP.

Verification

  • Hardware / OS: Windows 11, NVIDIA GeForce RTX 5080 (Blackwell, Wave32), Rust 1.98.1
  • cargo xtask policy: passed (154 files ok)
  • cargo clippy --workspace --all-targets -- -D warnings and --all-features: passed
  • cargo test --workspace: 347 passed, 0 failed (including victory-shader 125/125, running the new waterfall test on RTX 5080 + WARP with dxil.dll validation)
  • Offline A/B regression check (victory translate --list over 26,096 title programs): 0 regressions (25,736 / 26,096 tracked before and after; no game data or dumps included).

@pablogonz12

Copy link
Copy Markdown
Contributor

Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 (main's host build fails without it: E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 666 / 768 656 656

No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you handle, so this is a no-regression result only (same 10 SPIR-V validation failures as the base).

Not tested: in-game.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 8c94b5c: cargo test -p victory-shader passes, 125 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…tor word across redundant masked moves (fixes Marvisak#750)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 8c94b5c on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-shader -- --test-threads=1 passes on the head (125 passed, 1 ignored), including the new waterfall tests.
  • Merged into our fork: workspace tests, shader tests and clippy -D warnings (default and all features) are all clean.

The reasoning is sound:

  • The redundant-move proof only asks about the lanes that run the masked v_mov_b32 (known ∧ reach ∧ guard). Lanes that don't run it keep the old value by definition, so proving old == src on the running lanes means the result is the old value everywhere.
  • An infeasible lane set counts as vacuously equal.
  • Back-edge phis are refused.
  • Integer-only negation in CompareKey avoids the NaN trap of folding float compares.

A static measurement on a full game package, counts only: no program there hits "a per-lane descriptor written where some lanes may keep the old one", either before or after this PR. So this frees nothing in that package, and changes nothing either (0 programs change result). Both the fork and upstream are neutral on it.

AI-assisted (Claude Code).

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 25, 2026
Where a fork-only change duplicates upstream's own version of a feature,
upstream's is kept and the fork's dropped:
- victory-shader is upstream's crate with the fork-only merges replayed
  onto it oldest first; those that do not apply onto upstream are dropped
  (37 of 63: among them Marvisak#704/raw views, gather4_l, the lane-mask and Marvisak#308
  ports, Marvisak#947, Marvisak#1022, Marvisak#1112, Marvisak#1090, Marvisak#1182). Marvisak#284 (legacy fused madds) and
  Marvisak#98 (permlane16 in whole-wave sections) are dropped too: the first
  disagrees with upstream's hardware-checked model, the second refused 46
  programs upstream translates.
- translate: upstream's --cache replaces Marvisak#254's write-cache and work queue;
  Marvisak#378, Marvisak#517, Marvisak#673 and the victory.toml console are re-applied.
- victory-gpu: upstream's stride table, page table and heap views replace
  the fork's Marvisak#704/stride-table wiring; fork-only fixes re-applied on top.

Package (shaders.rpf, translate --validate --list, counts): vertex/pixel
emitted 12559 -> 14295 of 14337, compute 2359 -> 2628 validated, mesh
2730 -> 2811 validated. Tests: the failures left (rect fourth corner,
two stride tests, row order, gather4 at a level, memory table, dynamic
heap slots) fail on upstream main as well on this host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Fix for #750 ('per-lane descriptor written where some lanes may keep the old one'): that refusal class is 0 in main after today's lane-condition fixes; same issue as #1229.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shader resource tracking: redundant masked write after a per-lane descriptor join is refused (synthetic repro on #566)

5 participants