fix(shader): refuse divergent skip-edge constants when another arm holds skipping lanes #237

Closed
Sheffy007 wants to merge 1 commit from upstream-pr/237 into main
Sheffy007 commented 2026-11-27 02:52:39 +00:00 (Migrated from github.com)

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_there on main (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 edge q -> b whenever its support lacked Atom::Opaque and Atom::Quad.

  1. Lanes::constant (structure.rs) records non-mask partial integer constants (such as s_mov_b32 s6, 5) in st.other as Atom::Constant(5) rather than Bool::FALSE / Bool::TRUE.
  2. Even for 0 (Bool::FALSE), when q exits via a per-lane branch (!self.uniform_exit(q, |_| true), such as s_cbranch_execz on a skip edge q -> b) and the taken arm writes a mask holding the skipping lanes (e.g. saved EXEC), the console wave runs the taken arm and overwrites the scalar register for the skipping lanes too. Reading q's pre-branch value on the skip edge produces the wrong bit on mixed waves unless no_mask_lane_on_edge or unneeded_edges already proved no skipping lane is affected.

Changes

  • Require self.uniform_exit(q, |_| true) (every active lane in q leaves along this edge, covering uniform loop exits, uniform headers, and dedicated then/else arms jumping unconditionally to b) and exclude Atom::Constant(_) at non-uniform joins when lowering st.other entries at pending_masks.
  • Add cross-platform regression test emit::mask_tests::skip_edge_constant_joined_with_mask_holding_skipping_lanes_stays_refused covering both s_mov_b32 s6, 5 and s_mov_b32 s6, 0 on non-Windows hosts as well.
  • Update docs/native-host.md.

Verification

  • cargo test --workspace (all victory-shader, victory-gpu split_wave_tests, victory-metal, victory-hle, victory-loader, victory, and xtask tests pass)
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5520354862 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/237). Originally posted by [Sheffy007](https://github.com/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_there` on `main` (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 edge `q -> b` whenever its support lacked `Atom::Opaque` and `Atom::Quad`. 1. `Lanes::constant` (`structure.rs`) records non-mask partial integer constants (such as `s_mov_b32 s6, 5`) in `st.other` as `Atom::Constant(5)` rather than `Bool::FALSE` / `Bool::TRUE`. 2. Even for `0` (`Bool::FALSE`), when `q` exits via a per-lane branch (`!self.uniform_exit(q, |_| true)`, such as `s_cbranch_execz` on a skip edge `q -> b`) and the taken arm writes a mask holding the skipping lanes (e.g. saved `EXEC`), the console wave runs the taken arm and overwrites the scalar register for the skipping lanes too. Reading `q`'s pre-branch value on the skip edge produces the wrong bit on mixed waves unless `no_mask_lane_on_edge` or `unneeded_edges` already proved no skipping lane is affected. ### Changes - Require `self.uniform_exit(q, |_| true)` (every active lane in `q` leaves along this edge, covering uniform loop exits, uniform headers, and dedicated `then`/`else` arms jumping unconditionally to `b`) and exclude `Atom::Constant(_)` at non-uniform joins when lowering `st.other` entries at `pending_masks`. - Add cross-platform regression test `emit::mask_tests::skip_edge_constant_joined_with_mask_holding_skipping_lanes_stays_refused` covering both `s_mov_b32 s6, 5` and `s_mov_b32 s6, 0` on non-Windows hosts as well. - Update `docs/native-host.md`. ### Verification - `cargo test --workspace` (all `victory-shader`, `victory-gpu` `split_wave_tests`, `victory-metal`, `victory-hle`, `victory-loader`, `victory`, and `xtask` tests pass) - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy`
LakshanSivakumar commented 2026-11-27 03:00:46 +00:00 (Migrated from github.com)

Imported 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_refused passes on this branch and fails when merged with main: the s_mov_b32 s6, 0 case (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:

  1. show that 74072c2f's rule is wrong for a skip edge whose other arm holds saved EXEC, and make the refusal apply there too (with the test as it is), or
  2. if the bit join is right for 0 and -1, keep the refusal to partial constants only and change the 0 case to an accepted-shape test.

Also, the uniform_exit(q, |_| true) gate on the other arm 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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6082907626 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/237#pullrequestreview-6082907626). Originally posted by [LakshanSivakumar](https://github.com/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_refused` passes on this branch and fails when merged with main: the `s_mov_b32 s6, 0` case (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: 1. show that 74072c2f's rule is wrong for a skip edge whose other arm holds saved EXEC, and make the refusal apply there too (with the test as it is), or 2. if the bit join is right for 0 and -1, keep the refusal to partial constants only and change the 0 case to an accepted-shape test. Also, the `uniform_exit(q, |_| true)` gate on the `other` arm 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.
LakshanSivakumar commented 2026-11-27 03:28:22 +00:00 (Migrated from github.com)

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 in 2fa17f16, which landed a few minutes before your update) fails with this branch merged:

s_andn2: GFX10 code at 0x30: a lane-mask join of an untracked mask: data, on the host's lanes is not supported

That test is the case 2fa17f16 proves safe through unneeded_edges: an s_andn2 by EXEC whose edge's lanes are all in EXEC. Your uniform_exit gate on the other / all_or_none arms refuses it before that rule applies. Could you merge main and make the gate leave that shape alone? For example, apply it only when unneeded_edges hasn'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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6083070096 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/237#pullrequestreview-6083070096). Originally posted by [LakshanSivakumar](https://github.com/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 in 2fa17f16, which landed a few minutes before your update) fails with this branch merged: ``` s_andn2: GFX10 code at 0x30: a lane-mask join of an untracked mask: data, on the host's lanes is not supported ``` That test is the case 2fa17f16 proves safe through `unneeded_edges`: an `s_andn2` by EXEC whose edge's lanes are all in EXEC. Your `uniform_exit` gate on the `other` / `all_or_none` arms refuses it before that rule applies. Could you merge main and make the gate leave that shape alone? For example, apply it only when `unneeded_edges` hasn'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.
Sheffy007 commented 2026-11-27 04:08:34 +00:00 (Migrated from github.com)

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 to Lower::mask_arm_disagrees_on_edge:

  • Instead of gating st.other / all_or_none on uniform_exit(q) alone, a per-lane skip edge not cleared by unneeded_edges is now refused only when another incoming arm brings a tracked mask m (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.meet on (m, true), (edge_mask, false) or (m, false), (edge_mask, true)).
  • That keeps emit::gfx_refusal_tests::a_pixel_program_joins_data_an_else_part_clears_with_its_exec (2fa17f16) passing — at end: (0x30), (Atom::Phi(phi_else) & ~else_exec) | s3 equals Atom::Phi(phi_else) on every lane taking the skip edge — and allows -1 when joined with top-level saved EXEC (where both are 1 in every active lane), while still refusing 0, partial constants (5 in synthetic_tests::a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there), and -1 against subset masks that clear some skipping lanes.
  • Note: no local game shader dump is present on this development Mac to run a corpus sweep, so narrowing to exact bools.meet disagreement against a conflicting st.masks arm ensures no join without an actual mixed-wave/unmixed-wave discrepancy is affected.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7209554277 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/237#issuecomment-7209554277). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T04:08:34Z. --- Rebased onto latest `main` (`7f70c8d`) and narrowed the gate to `Lower::mask_arm_disagrees_on_edge`: - Instead of gating `st.other` / `all_or_none` on `uniform_exit(q)` alone, a per-lane skip edge not cleared by `unneeded_edges` is now refused **only** when another incoming arm brings a tracked mask `m` (`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.meet` on `(m, true), (edge_mask, false)` or `(m, false), (edge_mask, true)`). - That keeps `emit::gfx_refusal_tests::a_pixel_program_joins_data_an_else_part_clears_with_its_exec` (`2fa17f16`) passing — at `end:` (`0x30`), `(Atom::Phi(phi_else) & ~else_exec) | s3` equals `Atom::Phi(phi_else)` on every lane taking the skip edge — and allows `-1` when joined with top-level saved `EXEC` (where both are `1` in every active lane), while still refusing `0`, partial constants (`5` in `synthetic_tests::a_compare_mask_joined_with_data_on_the_skip_edge_is_0_there`), and `-1` against subset masks that clear some skipping lanes. - Note: no local game shader dump is present on this development Mac to run a corpus sweep, so narrowing to exact `bools.meet` disagreement against a conflicting `st.masks` arm ensures no join without an actual mixed-wave/unmixed-wave discrepancy is affected.
Sheffy007 commented 2026-11-27 04:09:58 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T04:09:58Z.


Closing as superseded by 72471c5f and 19788c59 on main.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7209574005 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/237#issuecomment-7209574005). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T04:09:58Z. --- Closing as superseded by `72471c5f` and `19788c59` on `main`.

Pull request closed

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
LakshanSivakumar/Native-Victory-macOS!237
No description provided.