shader: accept more loop masks a divergent loop changes in kept bits (#257, part two) #271

Open
gagarinyury wants to merge 2 commits from upstream-pr/271 into main
gagarinyury commented 2026-11-27 07:30:59 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T07:30:59Z.


What this changes

Refs #257 (part two of the split agreed below; part one is #329, and until it lands this diff includes it)

On top of #329's refusal and its one accept rule, more loop-mask updates are accepted when they keep the bits of lanes that have left, each traced back to the loop header's phi:

  • s_cselect and s_cmov of two values that both keep the header phi's bits;
  • an AND with a value that is all ones for lanes that left (~vcc of a compare made in the pass), an ANDN2 or XOR with one that is 0 for them;
  • joins inside the loop whose arms each keep the bits;
  • xor copies and restored EXEC.

How it was tested

  • emit::lower::tests::loop_masks_whose_updates_keep_the_bits_of_lanes_that_left_translate: one accepted program per rule above (except xor copies and restored EXEC, not yet covered) and a near form of each that is refused. Fails on #329 alone (first at cselect_same_phi). Programs assembled with llvm-mc -mcpu=gfx1030.
  • split_wave_tests with Metal Shader Converter 4.0 beta 3 (GPU execution): 35 passed.
  • cargo test -p victory-shader (333 passed), cargo clippy --no-deps -p victory-shader --all-targets -- -D warnings, cargo xtask policy.
  • Not run here: the corpus and the Windows-only tests. No game run.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none new)
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5522918646 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T07:30:59Z. --- ## What this changes Refs #257 (part two of the split agreed below; part one is #329, and until it lands this diff includes it) On top of #329's refusal and its one accept rule, more loop-mask updates are accepted when they keep the bits of lanes that have left, each traced back to the loop header's phi: - `s_cselect` and `s_cmov` of two values that both keep the header phi's bits; - an AND with a value that is all ones for lanes that left (`~vcc` of a compare made in the pass), an ANDN2 or XOR with one that is 0 for them; - joins inside the loop whose arms each keep the bits; - xor copies and restored EXEC. ## How it was tested - `emit::lower::tests::loop_masks_whose_updates_keep_the_bits_of_lanes_that_left_translate`: one accepted program per rule above (except xor copies and restored EXEC, not yet covered) and a near form of each that is refused. Fails on #329 alone (first at `cselect_same_phi`). Programs assembled with `llvm-mc -mcpu=gfx1030`. - `split_wave_tests` with Metal Shader Converter 4.0 beta 3 (GPU execution): 35 passed. - `cargo test -p victory-shader` (333 passed), `cargo clippy --no-deps -p victory-shader --all-targets -- -D warnings`, `cargo xtask policy`. - Not run here: the corpus and the Windows-only tests. No game run. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none new) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
LakshanSivakumar commented 2026-11-27 08:08:12 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:08:12Z.


Thank you for taking #257 and for saying plainly that the lockstep execution test was skipped on your machine. Making the shape a refusal is the right direction.

Before it can merge:

  1. The comparison by output fingerprint over a corpus of the title's shaders: newly refused per stage, how many of those lockstep then translates, how many 1-wave shaders end refused, and outputs changed. The change adds a lot of refusals in principle; I need to see how many shaders it costs. I am running your branch over my own corpus now and will post the table here.
  2. The execution test must run: please run split_wave_tests with the converter installed, or ask someone who has it to, and put the result in the text. The shape in #257 reads 0 in lane 0 where the console gives 1; the test should show that value before and after.
  3. The accept side. zero_when_exited, trace_preserved_phi and exec_unwidened decide what stays accepted, so they are where a wrong accept can remain. Please add negatives: an OR with an operand that is not zero for exited lanes; a cselect whose arms come from different phis; an EXEC write that widens (restored from a value saved before the loop); a loop with a second exit. And say why a loop that is_divergent_loop does not find divergent cannot let lanes leave on different passes.
  4. #257 also names a family of about 56 pixel shaders that OR lanes in and out and are refused today because one value has two instances. Please say whether this pull request touches them. If not, change "Closes #257" to "Refs #257".
  5. If you can, split it: the refusal of every mask read after a divergent loop (and the retry in lockstep) first, the monotonic accept analysis after.

This touches the mask code in #261 and the area of the #254 branch, so expect conflicts.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213189612 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7213189612). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:08:12Z. --- Thank you for taking #257 and for saying plainly that the lockstep execution test was skipped on your machine. Making the shape a refusal is the right direction. Before it can merge: 1. The comparison by output fingerprint over a corpus of the title's shaders: newly refused per stage, how many of those lockstep then translates, how many 1-wave shaders end refused, and outputs changed. The change adds a lot of refusals in principle; I need to see how many shaders it costs. I am running your branch over my own corpus now and will post the table here. 2. The execution test must run: please run `split_wave_tests` with the converter installed, or ask someone who has it to, and put the result in the text. The shape in #257 reads 0 in lane 0 where the console gives 1; the test should show that value before and after. 3. The accept side. `zero_when_exited`, `trace_preserved_phi` and `exec_unwidened` decide what stays accepted, so they are where a wrong accept can remain. Please add negatives: an OR with an operand that is not zero for exited lanes; a `cselect` whose arms come from different phis; an EXEC write that widens (restored from a value saved before the loop); a loop with a second exit. And say why a loop that `is_divergent_loop` does not find divergent cannot let lanes leave on different passes. 4. #257 also names a family of about 56 pixel shaders that OR lanes in and out and are refused today because one value has two instances. Please say whether this pull request touches them. If not, change "Closes #257" to "Refs #257". 5. If you can, split it: the refusal of every mask read after a divergent loop (and the retry in lockstep) first, the monotonic accept analysis after. This touches the mask code in #261 and the area of the #254 branch, so expect conflicts.
LakshanSivakumar commented 2026-11-27 08:53:09 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:53:09Z.


My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1):

502 shaders that translate on main are refused with this branch (373 pixel, 129 compute), and 12 compute outputs change. 493 of the 502 carry your new refusal; 4 and 2 are refused for two lane-mask reasons that are not this one; 3 compute shaders that finished on main no longer finish in 300 s, and 6 time out in all. 62 of the 502 are shaders the game binds in a run. Nothing is gained. As it stands this costs too much: please find why shaders hang, and narrow the refusal, before the other points.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7214033886 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7214033886). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:53:09Z. --- My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1): 502 shaders that translate on main are refused with this branch (373 pixel, 129 compute), and 12 compute outputs change. 493 of the 502 carry your new refusal; 4 and 2 are refused for two lane-mask reasons that are not this one; 3 compute shaders that finished on main no longer finish in 300 s, and 6 time out in all. 62 of the 502 are shaders the game binds in a run. Nothing is gained. As it stands this costs too much: please find why shaders hang, and narrow the refusal, before the other points.
gagarinyury commented 2026-11-27 10:11:57 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T10:11:57Z.


Thanks for running the corpus and for the detailed feedback. I tracked down both the 300 s hangs and the bulk of the false refusals (and addressed points 3 and 4 as well) in 6f56b37:

1. Why shaders hung (>300 s)

loop_invariant_mask, trace_preserved_phi, zero_when_exited, and exec_unwidened::saved_in_loop popped visited nodes on return without memoizing results (O(2^N) backtracking across diamond DAGs inside loops), and check_one_loop_mask re-traversed the same (loop_idx, want_exec, value) pairs repeatedly. All five now memoize visited outcomes (using loop_mask_ok plus local memo maps), keeping each check linear in the visited IR/CFG slice.

2. Why 493+ shaders were falsely refused (narrowing)

Several overly broad checks fired on valid shaders even when structure.rs already resolved guards/exits or when EXEC was used normally:

  • Raw EXEC checks: dropped the EXEC checks from guard(), Fields::Valu(_) (checking EXEC on every post-loop v_cmp), exit() (s_cbranch_execz/execnz), and the EXEC source operand of loop-restore sop() writes (s_or exec, exec, saved), plus skipped exec == 0 edges (is_exec_zero_edge). Atom::Opaque(v) still checks resolved opaque masks.
  • Uniform pixel/loop exit false positives in is_divergent_loop: ignored st.discards exits, blocked traversal through back-edges to loop header h (s != h) in reach_b, and cached loop exit reachability (reachable_from) per loop.
  • zero_when_exited / exec_unwidened false positives: removed the single-block restriction (db != inst_b) on intra-loop v_cmp, handled s_and / s_cselect / s_cmov / intra-loop phis monotonically (including is_one_when_exited_op), accepted intra-loop phis + xor_copies/st.restored + pre-discard s_wqm in exec_unwidened, and restricted st.other traversal via is_mask_sop so integer scalar arithmetic is not treated as a lane mask.

3. Accept-side negative tests & is_divergent_loop completeness (point 3)

  • Added all four requested negative tests (neg_or_nonzero, neg_cselect_diff_phis, neg_exec_widens, neg_second_exit) plus pos_or_restore_exec in a_loop_carried_mask_changing_exited_lanes_is_refused_after_divergent_loop.
  • Added the completeness rationale to is_divergent_loop's doc comment: in a structured CFG loop, lanes can only exit on different passes if either an exit condition is non-uniform (so structure.rs leaves the loop with a divergent exit/latch outside uniform) or the loop has multiple distinct non-discard exit targets / a side exit before the latch; any loop with a single non-discard exit whose exit condition is uniform keeps all active-at-entry lanes exiting on the same pass.

4. Status of points 1, 2, 4

  • Point 4: Confirmed this PR does not touch the ~56 pixel shaders (OR lanes in and out / single value with two instances), so I updated the PR description from Closes #257 to Refs #257.
  • Point 2 (GPU execution): Metal Shader Converter is still not installed on this Mac (requires manual download from Apple Developer), so run_lockstep's Metal hardware execution path remains skipped locally while cargo test -j 2 -p victory-shader --locked -- --test-threads=2 (314 passed; 0 failed; 3 ignored) and cargo test -j 2 -p victory-gpu --lib split_wave_tests -- --test-threads=2 (35 passed; 0 failed) pass.
  • Point 1: Could you please re-run your corpus check on this updated branch when you get a chance to verify the hangs and false refusals are gone?
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7215593484 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7215593484). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T10:11:57Z. --- Thanks for running the corpus and for the detailed feedback. I tracked down both the 300 s hangs and the bulk of the false refusals (and addressed points 3 and 4 as well) in 6f56b37: ### 1. Why shaders hung (>300 s) `loop_invariant_mask`, `trace_preserved_phi`, `zero_when_exited`, and `exec_unwidened::saved_in_loop` popped visited nodes on return without memoizing results (`O(2^N)` backtracking across diamond DAGs inside loops), and `check_one_loop_mask` re-traversed the same `(loop_idx, want_exec, value)` pairs repeatedly. All five now memoize visited outcomes (using `loop_mask_ok` plus local memo maps), keeping each check linear in the visited IR/CFG slice. ### 2. Why 493+ shaders were falsely refused (narrowing) Several overly broad checks fired on valid shaders even when `structure.rs` already resolved guards/exits or when `EXEC` was used normally: - **Raw `EXEC` checks**: dropped the `EXEC` checks from `guard()`, `Fields::Valu(_)` (checking `EXEC` on every post-loop `v_cmp`), `exit()` (`s_cbranch_execz`/`execnz`), and the `EXEC` source operand of loop-restore `sop()` writes (`s_or exec, exec, saved`), plus skipped `exec == 0` edges (`is_exec_zero_edge`). `Atom::Opaque(v)` still checks resolved opaque masks. - **Uniform pixel/loop exit false positives in `is_divergent_loop`**: ignored `st.discards` exits, blocked traversal through back-edges to loop header `h` (`s != h`) in `reach_b`, and cached loop exit reachability (`reachable_from`) per loop. - **`zero_when_exited` / `exec_unwidened` false positives**: removed the single-block restriction (`db != inst_b`) on intra-loop `v_cmp`, handled `s_and` / `s_cselect` / `s_cmov` / intra-loop phis monotonically (including `is_one_when_exited_op`), accepted intra-loop phis + `xor_copies`/`st.restored` + pre-discard `s_wqm` in `exec_unwidened`, and restricted `st.other` traversal via `is_mask_sop` so integer scalar arithmetic is not treated as a lane mask. ### 3. Accept-side negative tests & `is_divergent_loop` completeness (point 3) - Added all four requested negative tests (`neg_or_nonzero`, `neg_cselect_diff_phis`, `neg_exec_widens`, `neg_second_exit`) plus `pos_or_restore_exec` in `a_loop_carried_mask_changing_exited_lanes_is_refused_after_divergent_loop`. - Added the completeness rationale to `is_divergent_loop`'s doc comment: in a structured CFG loop, lanes can only exit on different passes if either an exit condition is non-uniform (so `structure.rs` leaves the loop with a divergent exit/latch outside `uniform`) or the loop has multiple distinct non-discard exit targets / a side exit before the latch; any loop with a single non-discard exit whose exit condition is uniform keeps all active-at-entry lanes exiting on the same pass. ### 4. Status of points 1, 2, 4 - **Point 4**: Confirmed this PR does **not** touch the ~56 pixel shaders (`OR` lanes in and out / single value with two instances), so I updated the PR description from `Closes #257` to `Refs #257`. - **Point 2 (GPU execution)**: Metal Shader Converter is still not installed on this Mac (requires manual download from Apple Developer), so `run_lockstep`'s Metal hardware execution path remains skipped locally while `cargo test -j 2 -p victory-shader --locked -- --test-threads=2` (`314 passed; 0 failed; 3 ignored`) and `cargo test -j 2 -p victory-gpu --lib split_wave_tests -- --test-threads=2` (`35 passed; 0 failed`) pass. - **Point 1**: Could you please re-run your corpus check on this updated branch when you get a chance to verify the hangs and false refusals are gone?
gagarinyury commented 2026-11-27 10:30:40 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T10:30:40Z.


Checked both branches merged onto current main: clippy, victory-shader tests and split_wave_tests pass; the GPU part of split_wave_tests is still skipped here. On point 5: once your corpus numbers for 6f56b37 are in, I can split this into the refusal with the lockstep retry first and the accept analysis second, if you still want that. #293 touches the same spot in lower.rs, so whichever lands second I will update.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7215969856 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7215969856). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T10:30:40Z. --- Checked both branches merged onto current main: clippy, victory-shader tests and split_wave_tests pass; the GPU part of split_wave_tests is still skipped here. On point 5: once your corpus numbers for 6f56b37 are in, I can split this into the refusal with the lockstep retry first and the accept analysis second, if you still want that. #293 touches the same spot in lower.rs, so whichever lands second I will update.
LakshanSivakumar commented 2026-11-27 10:32:21 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:21Z.


Thank you for the quick work, the four negative tests, and for changing "Closes" to "Refs #257".

My corpus run was on the first head (502 newly refused, 62 of them bound by the game, 3 hangs), so it says nothing about 6f56b37f. I will run it again and post the table; I have not done it yet. The explanation of the hangs (nothing memoized, a walk of 2^N paths) sounds right, and the table will show it.

Still open: the execution test. The converter is a download from Apple's developer site; if you cannot install it, please ask someone who has it to run split_wave_tests and post the result. Also open: splitting the refusal from the accept analysis. Your workflow has not run; it needs my approval.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216004957 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7216004957). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T10:32:21Z. --- Thank you for the quick work, the four negative tests, and for changing "Closes" to "Refs #257". My corpus run was on the first head (502 newly refused, 62 of them bound by the game, 3 hangs), so it says nothing about 6f56b37f. I will run it again and post the table; I have not done it yet. The explanation of the hangs (nothing memoized, a walk of 2^N paths) sounds right, and the table will show it. Still open: the execution test. The converter is a download from Apple's developer site; if you cannot install it, please ask someone who has it to run `split_wave_tests` and post the result. Also open: splitting the refusal from the accept analysis. Your workflow has not run; it needs my approval.
gagarinyury commented 2026-11-27 10:43:56 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T10:43:56Z.


Ran split_wave_tests with Metal Shader Converter 4.0 beta 3 installed, so with GPU execution and no skips: 35 passed on 6f56b37. The #257 shape on 64 lanes, per-lane value of v_cndmask_b32 v2, 0, 1, s[8:9]: before (2a3b03d) it is not refused and all 64 lanes read 0; after (6f56b37) the fast path refuses it ("a loop-carried lane mask read after a divergent loop is not supported"), it runs in lockstep, lanes 0..47 read 1 and lanes 48..63 read 0, so lane 0 reads 1 as on the console. The after values are what a_loop_carried_mask_changing_exited_lanes_runs_in_lockstep asserts; the before values come from the same program run against the base lower.rs.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216237509 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7216237509). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T10:43:56Z. --- Ran split_wave_tests with Metal Shader Converter 4.0 beta 3 installed, so with GPU execution and no skips: 35 passed on 6f56b37. The #257 shape on 64 lanes, per-lane value of `v_cndmask_b32 v2, 0, 1, s[8:9]`: before (2a3b03d) it is not refused and all 64 lanes read 0; after (6f56b37) the fast path refuses it ("a loop-carried lane mask read after a divergent loop is not supported"), it runs in lockstep, lanes 0..47 read 1 and lanes 48..63 read 0, so lane 0 reads 1 as on the console. The after values are what `a_loop_carried_mask_changing_exited_lanes_runs_in_lockstep` asserts; the before values come from the same program run against the base lower.rs.
gagarinyury commented 2026-11-27 11:11:23 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T11:11:23Z.


On splitting: I tried it. The refusal alone (every mask a pass of a divergent loop changes, with the lockstep retry) breaks two of main's tests, a_mask_of_the_lanes_leaving_a_loop_by_a_uniform_exit_holds_them (the shadow pass) and a_mask_a_32_lane_wave_starts_as_a_pairs_constant_holds_the_lanes_ored_in (the G-buffer's 32-lane programs): both OR EXEC into the mask on each pass, which main translates and the refusal alone would refuse. So I would split it as: first the refusal plus the one accept rule those two need (an s_or of the mask with EXEC, or with a compare made in the pass, keeps the bits of lanes that left), then the rest of the accept analysis (s_cselect/s_cmov, phis inside the loop, s_wqm, restored EXEC). Does that work for you, or would you rather wait for the corpus table on 6f56b37 first?

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216784226 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7216784226). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T11:11:23Z. --- On splitting: I tried it. The refusal alone (every mask a pass of a divergent loop changes, with the lockstep retry) breaks two of main's tests, `a_mask_of_the_lanes_leaving_a_loop_by_a_uniform_exit_holds_them` (the shadow pass) and `a_mask_a_32_lane_wave_starts_as_a_pairs_constant_holds_the_lanes_ored_in` (the G-buffer's 32-lane programs): both OR EXEC into the mask on each pass, which main translates and the refusal alone would refuse. So I would split it as: first the refusal plus the one accept rule those two need (an `s_or` of the mask with EXEC, or with a compare made in the pass, keeps the bits of lanes that left), then the rest of the accept analysis (`s_cselect`/`s_cmov`, phis inside the loop, `s_wqm`, restored EXEC). Does that work for you, or would you rather wait for the corpus table on 6f56b37 first?
LakshanSivakumar commented 2026-11-27 12:00:33 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T12:00:33Z.


Thank you for running the converter tests, and for finding that the refusal alone breaks two of main's tests. That is exactly the information I needed.

I ran every shader by output on 6f56b37f (33,625 containers, against main c1b95875): 503 shaders that translate on main are refused (373 pixel, 130 compute), 13 compute shaders change, nothing is gained, and there are no hangs now (the first head had some). Of the shaders the game binds in the world, 62 are lost. So as one piece this would cost a lot of the world's draws, and I cannot merge it like this.

Yes, please split it as you describe: first the refusal plus the one accept rule those two tests need (an s_or of the mask with EXEC, or with a compare made in the pass), then the rest. For each part, the number I will look at is how many of those 503 stay refused. I have not run this in the game.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217728784 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7217728784). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T12:00:33Z. --- Thank you for running the converter tests, and for finding that the refusal alone breaks two of main's tests. That is exactly the information I needed. I ran every shader by output on 6f56b37f (33,625 containers, against main c1b95875): 503 shaders that translate on main are refused (373 pixel, 130 compute), 13 compute shaders change, nothing is gained, and there are no hangs now (the first head had some). Of the shaders the game binds in the world, 62 are lost. So as one piece this would cost a lot of the world's draws, and I cannot merge it like this. Yes, please split it as you describe: first the refusal plus the one accept rule those two tests need (an `s_or` of the mask with EXEC, or with a compare made in the pass), then the rest. For each part, the number I will look at is how many of those 503 stay refused. I have not run this in the game.
gagarinyury commented 2026-11-27 12:06:59 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T12:06:59Z.


Split as you asked: #329 is part one (the refusal plus the rule for an s_or of the mask with EXEC or with a compare made in the pass), and this pull request now holds part two on top of it, with a test of each accept rule that fails without part two; until #329 lands this diff includes it. Both keep main's two loop-mask tests and pass split_wave_tests on Metal (35 passed). Not yet covered by a test in part two: xor copies and restored EXEC.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217857691 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7217857691). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T12:06:59Z. --- Split as you asked: #329 is part one (the refusal plus the rule for an `s_or` of the mask with EXEC or with a compare made in the pass), and this pull request now holds part two on top of it, with a test of each accept rule that fails without part two; until #329 lands this diff includes it. Both keep main's two loop-mask tests and pass split_wave_tests on Metal (35 passed). Not yet covered by a test in part two: xor copies and restored EXEC.
LakshanSivakumar commented 2026-11-27 16:01:32 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:01:32Z.


Leaving this open: it contains #329's commit, so it carries the same two problems I noted there (the in-loop v_cmp accept, and main's a_loop_register_that_is_exec_on_every_edge_is_exec_at_the_head test failing once merged). It can follow #329.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222765267 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7222765267). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:01:32Z. --- Leaving this open: it contains #329's commit, so it carries the same two problems I noted there (the in-loop v_cmp accept, and main's `a_loop_register_that_is_exec_on_every_edge_is_exec_at_the_head` test failing once merged). It can follow #329.
gagarinyury commented 2026-11-27 16:18:00 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T16:18:00Z.


Rebased onto the updated PR #329 head (056ac63a, on origin/main be7dc1b5), updated to 69434f75:

  • Inherits the #329 fixes and docs/native-host.md update (in-loop v_cmp removed, exec_unwidened::saved_in_loop accepting st.active loop joins and s_and/s_andn2 narrowings while limiting single-operand copies to s_mov_b32/s_mov_b64, plus neg_in_loop_v_cmp and neg_exec_widens_s_not).
  • Keeps part two's scalar loop_invariant_mask (accepting pre-loop dominating inputs and chains of invariant scalar SOPs inside the loop whose operands remain loop-invariant; no v_cmp), and fixes 64-bit SOP operand lookup to read Reg::S(code + half) instead of Reg::S(code) (with an s_and_b64 regression test in a_wave64_loop_carried_mask_changing_exited_lanes_falls_back_to_lockstep where s7 mutates while s6 stays invariant, verified to translate erroneously under Reg::S(code) and refuse under Reg::S(code + half), plus its invariant twin translating).

Verification on 69434f75:

  • cargo clippy --no-deps -p victory-shader --all-targets --locked -- -D warnings (passed on macOS host and --target x86_64-pc-windows-msvc)
  • cargo test -p victory-shader --locked (384 passed; 0 failed; 3 ignored unit tests + 5 passed integration tests)
  • cargo test -p victory-gpu --lib split_wave_tests (47 passed; 0 failed on Metal; run on 0761b014)
  • cargo xtask policy (asset policy: 390 files ok)
  • Offline dump sweep (25,985 unique containers, wave32_host: true, zero_copy_memory: true, run on 0761b014): 25,599 ok / 386 refused vs be7dc1b5 (70 Cs newly refused, 0 Ps/Vs/Ms, 1 Cs changed output via lockstep; accepts 3 Cs shaders refused in #329).
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223095280 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/271#issuecomment-7223095280). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T16:18:00Z. --- Rebased onto the updated PR #329 head (`056ac63a`, on `origin/main` `be7dc1b5`), updated to `69434f75`: - Inherits the #329 fixes and `docs/native-host.md` update (in-loop `v_cmp` removed, `exec_unwidened::saved_in_loop` accepting `st.active` loop joins and `s_and`/`s_andn2` narrowings while limiting single-operand copies to `s_mov_b32`/`s_mov_b64`, plus `neg_in_loop_v_cmp` and `neg_exec_widens_s_not`). - Keeps part two's scalar `loop_invariant_mask` (accepting pre-loop dominating inputs and chains of invariant scalar SOPs inside the loop whose operands remain loop-invariant; no `v_cmp`), and fixes 64-bit SOP operand lookup to read `Reg::S(code + half)` instead of `Reg::S(code)` (with an `s_and_b64` regression test in `a_wave64_loop_carried_mask_changing_exited_lanes_falls_back_to_lockstep` where `s7` mutates while `s6` stays invariant, verified to translate erroneously under `Reg::S(code)` and refuse under `Reg::S(code + half)`, plus its invariant twin translating). Verification on `69434f75`: - `cargo clippy --no-deps -p victory-shader --all-targets --locked -- -D warnings` (passed on macOS host and `--target x86_64-pc-windows-msvc`) - `cargo test -p victory-shader --locked` (`384 passed; 0 failed; 3 ignored` unit tests + `5 passed` integration tests) - `cargo test -p victory-gpu --lib split_wave_tests` (`47 passed; 0 failed` on Metal; run on `0761b014`) - `cargo xtask policy` (`asset policy: 390 files ok`) - **Offline dump sweep (`25,985` unique containers, `wave32_host: true, zero_copy_memory: true`, run on `0761b014`)**: `25,599 ok / 386 refused` vs `be7dc1b5` (`70 Cs` newly refused, `0 Ps/Vs/Ms`, `1 Cs` changed output via lockstep; accepts `3 Cs` shaders refused in #329).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/271:upstream-pr/271'
git switch 'upstream-pr/271'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/271'
git switch 'upstream-pr/271'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/271'
git switch 'upstream-pr/271'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/271'
git switch 'main'
git merge --squash 'upstream-pr/271'
git switch 'main'
git merge --ff-only 'upstream-pr/271'
git switch 'main'
git merge 'upstream-pr/271'
git push origin 'main'
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!271
No description provided.