Shader: ignore guarded or modified v_mov_b32 in Lower::konst #2446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2448"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T13:39:27Z.
Problem
In
crates/victory-shader/src/emit/lower.rs,Lower::konst()(used bydead_on_edge()viacompared()to prove branch conditions constant and discard dead incoming phi edges) treats anyv_mov_b32withsdwa.is_none() && dpp.is_none()as unconditionally producing its raww.src[0]constant bits.That misses two cases already handled elsewhere in
lower.rs:self.x.st.guards[b][i].is_some(), cf.whole()at line 8574): a guardedv_mov_b32 v1, 0only writes0in active lanes; inactive lanes preserve their previous register value, sov1is not unconditionally0.w.abs != 0 || w.neg != 0 || w.clamp || w.omod != 0, cf.v_mov_b32lowering at line 5636):v_mov_b32_e64 v1, -(1.0)writes-1.0f(0xBF80_0000), not the unmodified source1.0f(0x3F80_0000).In either case,
dead_on_edge()can falsely prove a branch condition constant and drop a live incoming phi edge.Change
Lower::def_site(v)returning(block, inst_index, &Inst)(withdef_instdelegating to it).Lower::konst(), returnNonewhenself.x.st.guards[b][i].is_some(), and requirew.abs == 0 && w.neg == 0 && !w.clamp && w.omod == 0in addition tow.sdwa.is_none() && w.dpp.is_none()forv_mov_b32.v_mov_b32,s_mov_b32,s_movk_i32, andcompared()are unchanged.Test
guarded_or_modified_v_mov_b32_is_not_folded_as_constant(synthetic GFX10 compute shader words followinga_value_no_lane_from_its_edge_reads_needs_no_form, cross-platform, no game data):v_mov_b32:v1is initialized to-1, thenv_mov_b32 v1, 0runs underv_cmpx_eq_u32 exec, 0, v0. Inactive lanes keep-1, pass the join comparev_cmp_eq_u32 vcc_lo, -1, v1, and reads6(s_memtime, unsupported in DXIL). Asserts lowering refuses it identically to a direct read (onmain,dead_on_edgefalsely foldsv1to0and accepts it). Replacing the guard withs_nopverifies unguardedv_mov_b32still folds and lowers.v_mov_b32_e64:v_mov_b32_e64 v1, -(1.0)([0xD581_0001, 0x2000_00F2]) writes-1.0f, matchingv_cmp_eq_u32 vcc_lo, -1.0, v1sos6is live. Asserts lowering refuses it identically to a direct read (onmain,konstignoresnegand folds1.0f != -1.0f). Clearing thenegbit (0x0000_00F2) verifies unmodifiedv_mov_b32_e64still folds and lowers.Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:57:18Z.
Review: APPROVED
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:v_mov_b32inLower::konstprevents unsound constant propagation.cargo test -p victory-shader emit::lower::tests: 22/22 passed on RTX 5090, 22/22 passed on WARP (includingguarded_or_modified_v_mov_b32_is_not_folded_as_constant).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:04Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — guarded or modified v_mov_b32 ignored in Lower::konst.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T14:26:33Z.
Both holes are real miscompiles: a guarded
v_mov_b32only writes active lanes (inactive lanes keep the old value — the test'sv_cmpxcase shows the folded constant leaking into lanes that kept-1), and VOP3neg/abs/clamp/omodtransform the source (-(1.0)folds to the wrong sign). Checkingguardsat the def site plus the modifier fields is the right granularity — unguarded plain moves still fold. The test's refusal-equality trick (guarded program must fail the same way as the directs_memtimeread) is a clean way to pin liveness through the fold.Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T14:49:49Z.
Independent local validation (Windows, Rust 1.100.0/MSVC, head
8f5cf05, no game data):cargo test --locked -p victory-shader --lib-> 248 passed, 0 failed, 3 ignored, exit 0;git diff --check HEAD~1 HEADclean. The lib test count matches upstream main, so this is a compile/regression check only; I did not independently replay the synthetic guarded/modified v_mov_b32 scenario in Lower::konst. AI-assisted (Hy4 flash). GPU/driver: N/A for the CPU test run. No game data, assets or extracted content used.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:08:16Z.
Automated triage for the maintainers.
Merge candidate.
Lower::konst(emit/lower.rs) no longer folds av_mov_b32whose definition is EXEC-guarded (st.guards[b][i]), or one with VOP3abs/neg/clamp/omod. Both folds were wrong: a guarded move keeps the old value in inactive lanes, and the modifiers change the result. This matches howmainalready handles both:whole()checks the same guard, and thev_mov_b32lowering goes the float path under the same modifiers. Without the fix,dead_on_edgecould drop a live phi edge. I checked the test's encodings by hand (v_cmpx_eq_u32,v_cmp_eq_u32,v_mov_b32_e64withnegat bit 29 of word 1). Each case has a control showing that the unguarded or unmodified move still folds. The newdef_sitehelper is shared withdef_inst.CI:
checkpassing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T16:23:12Z.
Rebased cleanly onto
main(67e8ae1) ind5f7b7b(resolved the test-insertion conflict incrates/victory-shader/src/emit/lower.rs).