Repository navigation
Shaders: keep a skip around a loop that may not end with no lane left - #71
pr0vId3nce wants to merge 1 commit into
Conversation
The "without skips" forms drop `s_cbranch_execz` skips, so a region the console only enters with lanes left also runs with none. A loop whose exit waits for some lane (a lane compare's VCC, empty then) never ends there, and every lane walks it to the iteration limit: in the particle light-atlas sprite and trail programs, with the group barriers of the wave-wide form in the loop nest. The cause was found first in fxceless/victory-fork#262. Such a skip, or an early-out to the program's end, is now kept when the code left running with no lane holds a loop that may not end there: - With no lane left, EXEC, lane compares and the masks moves, ANDs, AND-NOTs, ORs and the saveexec/wrexec forms make of them are empty, and a branch on an empty EXEC, VCC or SCC goes one known way: a waterfall over EXEC's lanes ends at once. - A loop that counts its way out (its branches test scalars the lanes do not make: constants, values from before the region, scalar arithmetic on them, joined only where the loop chooses) goes round as on the console. Its tests are ordered compares, or equalities of counts made from constants alone: a count to a bound from before the region may pass it unseen when that bound is 0 with no lane left. If a branch in it tests the lanes, no join in it may choose, and every way round must pass a test of a count that can leave the loop. - Any other branch, and a skip inside the region (this or a later form may drop it too), can go either way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ith no lane left Port of DexNom/VIctory#71 (b27921645, pr0vId3nce) and its follow-up b60997d11 onto this tree; the cause was found first in fxceless/victory-fork#262. The "without skips" and "without early-outs" forms drop `s_cbranch_execz` skips and early-outs, so a region the console only enters with lanes left also runs with none. A loop whose exit waits for some lane (a lane compare's VCC, empty then) never ends there, and every lane walks it to the iteration limit: in the particle light-atlas sprite and trail programs, with the group barriers of the wave-wide form in the loop nest (a GPU hang on 32-lane cards). Such a skip, or an early-out to the program's end, is now kept when the code left running with no lane holds a loop that may not end there (`goes_round`). Here the early-out test is `early_out_continuation`, which both forms use, so the far-jump early-out (`s_cbranch_execnz` past a far jump to the end) is guarded too. (cherry picked from commit b27921645) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I found a wrapping-induction case not protected by the new ordered-comparison guard at For 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. |
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 Shaders: keep s_cbranch_execz over loops that cannot exit when EXEC is 0 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 Shaders: take the wave-wide form as a last resort on 32-lane hosts #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