shader: refuse lane masks a divergent loop's passes change, keep OR-accumulated ones (#257, part one) #329
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!329
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@gagarinyury on GitHub · 2026-11-27 12:06 UTC · original
gagarinyury:fix/loop-mask-split-a→main· +1233 −6 · 3 files · 1 commits · openWhat 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)@Olima34 on GitHub · 2026-11-27 13:06 UTC · original
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.@AnastasisKon on GitHub · 2026-11-27 13:27 UTC · original
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.
@LakshanSivakumar on GitHub · 2026-11-27 16:01 UTC · original
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.
d3105da274to4c165c635c@gagarinyury on GitHub · 2026-11-27 16:17 UTC · original · edited 2026-11-27 16:28 UTC
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.)
4c165c635cto056ac63aebView command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.