Shaders: keep a skip around a loop that may not end with no lane left #71
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/71"
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 DexNom/VIctory. Originally posted by pr0vId3nce on 2026-11-26T14:03:29Z.
The cause and the shape of this fix come from fxceless/victory-fork#262 by xADEL. That PR found that
without_skipslets an empty wave into a loop it cannot leave, in the same particle light-atlas programs. This ports the fix to this tree as its own implementation. The differences, and why, are below.The problem. On a 32-lane host, the "without skips" forms of a wave64 program (
ir::without_skips) drops_cbranch_execzskips. A region the console only enters with lanes left then also runs with none. For straight-line code that is harmless, but not for a loop whose exit waits for some lane: with no lane left, a lane compare gives an empty VCC, the exit never comes, and every lane walks the loop to the 4,096-iteration limit.2561af9577c47289andc06aa62112ffba4c, the particle light-atlas sprite and trail programs, have such a loop. They are the two programs the comment inemit/mod.rsnames for losing the card underVICTORY_WAVE_WIDE=1. That form is built on the deep "without skips" base, and it puts dozens of group barriers in that loop nest.What this does.
without_skipskeeps a skip, and an early-out to the program's end, when the code it would leave running with no lane left holds a loop that may not end there:saveexec/wrexecforms make of them, round loops as well. A branch on an empty EXEC, VCC or SCC goes one known way. So a waterfall over the lanes of EXEC (v_cmpxands_cbranch_execnz, or an AND-NOT ands_cbranch_scc1) still ends at once, and its skip is still dropped.A loop until a lane compare holds, or on a scalar read from a lane, keeps its skip.
How this differs from fxceless/victory-fork#262. fxceless/victory-fork#262 keeps a skip when a mask branch inside the region (
vccz/vccnz,execz/execnz, or SCC from an AND with EXEC or VCC) has its zero edge on a cycle. Ported unchanged to this tree, atVICTORY_HOST_MAX_WAVE=32:WaveSize(64)fxceless/victory-fork#262 counts every VCC test as empty, including VCC made by scalar code. It also counts an inner
execzexit as a way to stay on a loop, and it guards early-outs. This tree has more exact 32-lane forms that depend on dropping those skips, so 27 programs lose their only 32-lane form there, and with default switches the light-atlas programs change too. Here those cases are told apart by which masks are actually empty.Two more differences:
v_readfirstlane) keeps it, and so does a!=count to a bound from before the region.without_early_outs. This PR does not (see Limits).Runs (RTX 4080, prologue save, DRED on):
VICTORY_WAVE_WIDE=1, unchanged main: the device was removed about 105 s in, 7 s after both light-atlas programs were first bound. DRED: the list in flight stopped at an indirect dispatch ofc06aa62112ffba4c.VICTORY_WAVE_WIDE=1with this change, same save and keys: 306 s, no device loss. Both light-atlas programs were first bound at frame 1995 and ran for the remaining 3 minutes, at 255-305 ms per frame.--rtwithVICTORY_WAVE_WIDE=1.Census (
shaders.rpf,VICTORY_HOST_MAX_WAVE=32, wave sizes fromPSV0, dumps compared):WaveSize(64)Every other program (vertex, pixel, mesh) is byte-identical, apart from the validator's error-report files, which change on every run. With default switches the light-atlas programs do not change; they take an approximate local-wave form before and after.
The 21 on main, by the form they take (before → after):
With #40 the same 21 change the same way, and 14 programs in #40's last-resort form change code, not form.
So 6 programs go from an exact form to an approximate one. Their exact form ran a loop with no lane left that the guard cannot show ends. Only the two pre-render programs were bound in the runs above.
Limits:
without_early_outsis unchanged, so a form built on it still drops an early-out in front of such a loop. Guarding it the same way, as fxceless/victory-fork#262 does, costs 11 programs their 32-lane form on main (tree instance culling, shadow masks, a temporal resolve, a decal classification). With #40 those 11 move to the wave-wide last resort instead. That change is ready as a separate commit if wanted.Tests (
ir.rs; each "kept" test fails on main):a_skip_around_a_loop_is_kept: a loop until a lane compare holds;a_skip_around_a_skipped_loop_is_kept: the same loop behind a skip of its own;an_early_out_before_a_loop_is_kept: a skip to the end of the program;a_skip_around_a_loop_on_a_lane_read_is_kept: a loop onv_readfirstlane;a_skip_around_a_loop_whose_count_cannot_leave_it_is_kept: a count test whose branch stays in the loop;a_skip_around_a_count_to_a_bound_it_may_pass_is_kept:while (++i != s0)withs0from before the skip;a_skip_around_a_loop_that_ends_with_its_lanes_is_left_out:v_cmpxands_cbranch_execnz;a_skip_around_a_waterfall_over_exec_is_left_out: an AND-NOT of a mask from EXEC ands_cbranch_scc1;a_skip_around_a_counted_loop_is_left_out: a count from 0 to 4;a_skip_around_a_counted_loop_with_a_lane_branch_in_it: the same count with a skip on EXEC inside is left out; a count that goes up on one side of that skip only is kept.victory-shader --libon an RTX 4080 and an AMD iGPU: 239 passed before, 249 after, 0 failed. Clippy-D warningsclean;xtask policyok.🤖 Generated with Claude Code
Imported from DexNom/VIctory. Originally posted by andrewDoing on 2026-11-26T23:47:05Z.
I found a wrapping-induction case not protected by the new ordered-comparison guard at
b279216. Using the existingskip()fixture with body[0xBE95_0385, 0x4A02_0281, 0x8015_C215, 0xBF08_0015, 0xBF85_FFFC]givess21=5, a vector operation,s21 += -2,s_cmp_gt_u32 s21,s0, and a loop while true.For
s0=0, the outer unsigneds0 > v0condition is false for every lane, so the original guard skips the body. After removing the skip, the unsigned counter stays odd (3, 1, 0xffffffff, ...) and is always greater than zero, so the loop cannot terminate naturally. Ats0=3it can terminate on the first iteration for an active wave. The fixture had one original skip and zero afterwithout_skips(&looped, true); an assertion that the guard remains failed.An ordered comparison alone does not establish that a wrapping induction crosses its limit. Conservatively retaining the guard unless an exit or range/step proof excludes wrap may be safer. This is missing coverage in the PR's protection, not a claim that the PR introduced the underlying behavior versus base; no retail shader or GPU hang was tested.
Verification was AI-assisted with GPT-6.2 Astra.
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.