fix(shader): refuse divergent skip-edge constants when another arm holds skipping lanes #237
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/237"
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 LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T02:52:39Z.
Fixes the failing Windows CI test
emit::synthetic_tests::a_compare_mask_joined_with_data_on_the_skip_edge_is_0_thereonmain(which also caused CI check failures on recent PRs) and prevents miscompiling divergent lane-mask joins (#182 / #15).Cause
In
Lower::fill_phis(crates/victory-shader/src/emit/lower.rs),self.x.st.other.get(&arg)was accepted on every incoming edgeq -> bwhenever its support lackedAtom::OpaqueandAtom::Quad.Lanes::constant(structure.rs) records non-mask partial integer constants (such ass_mov_b32 s6, 5) inst.otherasAtom::Constant(5)rather thanBool::FALSE/Bool::TRUE.0(Bool::FALSE), whenqexits via a per-lane branch (!self.uniform_exit(q, |_| true), such ass_cbranch_execzon a skip edgeq -> b) and the taken arm writes a mask holding the skipping lanes (e.g. savedEXEC), the console wave runs the taken arm and overwrites the scalar register for the skipping lanes too. Readingq's pre-branch value on the skip edge produces the wrong bit on mixed waves unlessno_mask_lane_on_edgeorunneeded_edgesalready proved no skipping lane is affected.Changes
self.uniform_exit(q, |_| true)(every active lane inqleaves along this edge, covering uniform loop exits, uniform headers, and dedicatedthen/elsearms jumping unconditionally tob) and excludeAtom::Constant(_)at non-uniform joins when loweringst.otherentries atpending_masks.emit::mask_tests::skip_edge_constant_joined_with_mask_holding_skipping_lanes_stays_refusedcovering boths_mov_b32 s6, 5ands_mov_b32 s6, 0on non-Windows hosts as well.docs/native-host.md.Verification
cargo test --workspace(allvictory-shader,victory-gpusplit_wave_tests,victory-metal,victory-hle,victory-loader,victory, andxtasktests pass)cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warningscargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warningscargo xtask policyImported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T03:00:46Z.
Review: CHANGES_REQUESTED
Thanks, but this no longer holds on current main.
skip_edge_constant_joined_with_mask_holding_skipping_lanes_stays_refusedpasses on this branch and fails when merged with main: thes_mov_b32 s6, 0case (0xbe860380) translates ("skip-edge constant 0xbe860380 joined with saved EXEC translated", mask_tests.rs:542).The cause is main's
74072c2f("mask data of every lane or none joins as that bit on the host's lanes"). It now joins a 0 or -1 as that bit before your gate sees it, so the two rules disagree on exactly this shape. Could you merge main and either:Also, the
uniform_exit(q, |_| true)gate on theotherarm applies to every value on a divergent exit edge, not just partial constants. Before/after translate counts for a dumped corpus would show whether it costs shaders that translate today.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T03:28:22Z.
Review: CHANGES_REQUESTED
Thanks for reworking it. It now passes its own tests, but it breaks a test on main:
emit::gfx_refusal_tests::a_pixel_program_joins_data_an_else_part_clears_with_its_exec(added in2fa17f16, which landed a few minutes before your update) fails with this branch merged:That test is the case
2fa17f16proves safe throughunneeded_edges: ans_andn2by EXEC whose edge's lanes are all in EXEC. Youruniform_exitgate on theother/all_or_nonearms refuses it before that rule applies. Could you merge main and make the gate leave that shape alone? For example, apply it only whenunneeded_edgeshasn't already cleared the edge, or only where the other arm writes a mask that holds the skipping lanes. Then keep both tests passing.As before, before/after translate counts on a dumped pixel corpus (main now reports 7,879 pixel shaders) would show whether the gate costs anything else.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T04:08:34Z.
Rebased onto latest
main(7f70c8d) and narrowed the gate toLower::mask_arm_disagrees_on_edge:st.other/all_or_noneonuniform_exit(q)alone, a per-lane skip edge not cleared byunneeded_edgesis now refused only when another incoming arm brings a tracked maskm(st.masks) that both holds some lane taking the skip edge and can disagree with the skip edge's lane function on those lanes (bools.meeton(m, true), (edge_mask, false)or(m, false), (edge_mask, true)).emit::gfx_refusal_tests::a_pixel_program_joins_data_an_else_part_clears_with_its_exec(2fa17f16) passing — atend:(0x30),(Atom::Phi(phi_else) & ~else_exec) | s3equalsAtom::Phi(phi_else)on every lane taking the skip edge — and allows-1when joined with top-level savedEXEC(where both are1in every active lane), while still refusing0, partial constants (5insynthetic_tests::a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there), and-1against subset masks that clear some skipping lanes.bools.meetdisagreement against a conflictingst.masksarm ensures no join without an actual mixed-wave/unmixed-wave discrepancy is affected.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T04:09:58Z.
Closing as superseded by
72471c5fand19788c59onmain.Pull request closed