shader: refuse lane masks a divergent loop's passes change, keep OR-accumulated ones (#257, part one) #329
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/329"
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 gagarinyury on 2026-11-27T12:06:39Z.
What this changes
Refs #257 (part one of splitting #271, as agreed there)
A lane mask read after a divergent loop is refused ("a loop-carried lane mask read after a divergent loop") unless no pass changes it, or each pass only ORs into it EXEC or a compare made in that pass (both 0 for lanes that have left), with EXEC never widened inside the loop. Otherwise a lane that left on an earlier pass reads the mask as it was on its exit pass, not the wave's final mask (#257: lane 0 reads 0 where the console gives 1). One-wave compute retries in lockstep.
The accept rule is the one main's two loop-mask tests need (
a_mask_of_the_lanes_leaving_a_loop_by_a_uniform_exit_holds_them, the shadow pass, anda_mask_a_32_lane_wave_starts_as_a_pairs_constant_holds_the_lanes_ored_in, the G-buffer's 32-lane programs); the refusal without it breaks both. The other accept rules (s_cselect/s_cmov, AND/ANDN2/XOR, joins in the loop, xor copies, restored EXEC) are part two, #271. The hang fix of #271 (memoized walks) is in here.How it was tested
split_wave_testswith Metal Shader Converter 4.0 beta 3 (GPU execution, no skips): 35 passed, including main's two loop-mask tests anda_loop_carried_mask_changing_exited_lanes_runs_in_lockstep(the #257 shape: lanes 0..47 read 1, lanes 48..63 read 0; on main all 64 read 0).cargo test -p victory-shader(332 passed),cargo clippy --no-deps -p victory-shader --all-targets -- -D warnings,cargo xtask policy.Checklist
VICTORY_*variable and documented (none added)Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:06:05Z.
Since #304 merged (main
c5d7f4d0), this branch conflicts with main incrates/victory-gpu/src/native/split_wave_tests.rs, on the tests appended at the end of the file. @gagarinyury, could you rebase it on main? Then I'll sweep it by output (boot-time set of 4,921 containers and the 4,129 refused at boot, per stage), counting how many of the maintainer's 503 shaders part one alone keeps refused, and post the table here.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T13:27:17Z.
Verified by running the branch: full cargo test -p victory-shader green (332 passed, 3 ignored, x86_64-unknown-linux-gnu, rustc 1.98.1). The read-site hooks are the part I checked hardest, since a refusal rule is only as good as its coverage: mask_dword_at, uniform_scc, uniform_bits, mask_scc, both opaque-atom paths, EXEC-written SOPs, v_cndmask_b32 selects, and the addcarry carry-in all call check_loop_mask — I could not find a lane-mask-as-number read path that escapes it. The proof structure (loop-invariant masks dominate-check; otherwise trace_preserved_phi per predecessor with the exec_unwidened and wave_wide guards) matches the stated rule, and the memoization (loop_mask_ok, bounded walks) is what #271's hang needed. The LOOP_MASK_EXIT refusal propagating even for dead results (effect || why == LOOP_MASK_EXIT) is the right conservatism.
One open item before merge, in my view: the author states the corpus was not run (no dump). Since this is part one of replacing #271's blanket refusal, a before/after sweep with the #286 tool would show both directions — how many shaders stop being wrongly accepted (the #257 bug, the win) and how many previously-translating shaders now refuse (the risk that black something out). #328's author just demonstrated exactly this workflow on their branch; the same table here would make the trade visible. The split-wave GPU suite (35 passed including the two main loop-mask tests and the #257 shape) covers correctness of what still translates — this ask is only about counting what doesn't.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:01:31Z.
Leaving this open. Two problems on the current head:
loop_invariant_maskaccepts any v_cmp made inside the divergent loop as safe to read after the exit. On the console, later passes write 0 into the bits of lanes that already left; on the host each lane keeps its own last compare. A small loop (v_cmp_le_u32 vcc,s_andn2 exec, exec, vcc,s_cbranch_execnz, thenv_cndmaskon vcc after the loop) translates with this PR. Taking that accept out fixes it.mask_tests::a_loop_register_that_is_exec_on_every_edge_is_exec_at_the_head(a world lighting shape from #258) with "a loop-carried lane mask read after a divergent loop". It needs to let that shape through or show main's output is wrong there.I have not run a corpus sweep or Metal test of it.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T16:17:59Z.
Rebased onto
origin/main(be7dc1b5) in056ac63a(commit message anddocs/native-host.mdupdated) and addressed the review points:v_cmpfromloop_invariant_mask(@LakshanSivakumar): removedloop_invariant_masksov_cmpinside a divergent loop is no longer treated as loop-invariant after exit, and added negative caseneg_in_loop_v_cmpinsidea_loop_carried_mask_changing_exited_lanes_is_refused_after_divergent_loop(v_cmp_le_u32 vcc_lo, 32, v3,s_andn2_b32 exec_lo, exec_lo, vcc_lo,s_cbranch_execnz,v_cndmask_b32after loop ->LOOP_MASK_EXIT).mask_tests::a_loop_register_that_is_exec_on_every_edge_is_exec_at_the_headand hardenedsaved_in_loop(@LakshanSivakumar): inexec_unwidened::saved_in_loop, accepted loop phis inst.active(exec_copies_at_joins) and monotones_and/s_andn2narrowings inside the loop while restricting single-operand scalar copies strictly tos_mov_b32/s_mov_b64(sos_not/s_wqm/s_brevcannot pass, guarded byneg_exec_widens_s_notinside the same test).main(@Olima34): resolvedsplit_wave_tests.rsandlower.rsonbe7dc1b5.056ac63a(@AnastasisKon):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(383 passed; 0 failed; 3 ignoredunit tests +5 passedintegration tests, includinga_loop_register_that_is_exec_on_every_edge_is_exec_at_the_head,neg_in_loop_v_cmp, andneg_exec_widens_s_not)cargo test -p victory-gpu --lib split_wave_tests(47 passed; 0 failedwith Metal Shader Converter installed)cargo xtask policy(asset policy: 390 files ok)25,985unique containers from local dump,Options { wave32_host: true, zero_copy_memory: true, .. }):be7dc1b5:25,669 ok / 316 refused056ac63a:25,596 ok / 389 refused73(Cs: 73, all"a loop-carried lane mask read after a divergent loop is not supported",0 Ps / 0 Vs / 0 Ms) — identical to the73count before removing the in-loopv_cmpaccept (none of the25,985corpus shaders used that rule)0ok -> ok):1 Cs(fell back to lockstep)(Runtime world-run shaders aren't covered by this static dump sweep, so ready for @Olima34 / @LakshanSivakumar's boot/world corpus check.)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.