Shaders: lanes of a wave reach group barriers together, as on the console #2920
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2920
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2920"
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?
@lhnizdo on GitHub · 2026-11-26 00:06 UTC · original
lhnizdo:pr/barrier-sync→main· +1152 −13 · 5 files · 8 commits · openThe problem
The console runs
s_barrierper wave. A branch skips a block only when no lane of the wave needs it; otherwise the wave runs the block, barrier included, with the other lanes masked off. The host'sGroupMemoryBarrierWithGroupSynccounts threads: each lane takes its own branch, so lanes that skip a block holding a barrier never arrive there, and the rest of the group waits for them forever. That's a GPU hang (TDR).The title's compute programs where this hung submissions here:
compute_graph_ops: the matrix programs (6 barriers on one side of a per-lane branch), andCS_FormulaOperation, which loops until any lane reaches its own count.sky_scattering CS_MultipleScattering: 7 barriers.CS_BatchCullPreSkinnedMeshlets: the meshlet culling, in the submission of a device hang (the debug layer reported the TDR).What this does
9eadbf3).0e0b272).8de7c96).s_cbranch_vccz/execzand theirnzforms, where that only makes lanes leave sooner.5d7e5e0moves this code as is intolower/barriers.rs. With it,lower.rswould pass the asset policy's 512 KiB per-file limit.lower.rsis now 524,190 bytes, close to the limit, so the next large addition will need a split too.Numbers
Measured on the earlier upstream base the commits were first written on, not re-measured on
63bcca4:_Prevvariants are balanced; its ParaboloidShadows ones aren't yet.Tested
cargo clippy -p victory-shader --all-targets -- -D warningsis clean, andcargo xtask policypasses.cargo test -p victory-shader --libon an RTX 2080 (Windows 10, with #2878's test exports so the hardware device runs): 298 passed, 4 failed. All four fail the same way on plainmainon this card, none through these commits:a_heap_buffer_read_by_element_takes_the_views_stride: NVIDIA's structured views, #2464.a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: NVIDIA's view-heap cap, #2461.pops_wait_loop_exits_immediately_for_inactive_lanes: wants a shader model 6.6 WARP device, and Windows 10's is 6.2.gathers_at_a_level_match_the_hardware: another texel on NVIDIA. It failed on plainmainhere too, and passed in one run.In the game, on an RTX 2080 (32-lane waves), Windows 10 19045: these commits have been in the builds here that reached gameplay through the opening cutscene (with the title's pools made larger, #698), and in those loading a save straight into the world, together with #2460 #2461 #2462 #2464.
No unit tests are added. The cases above are the title's programs, and I'd welcome a pointer to the preferred place for synthetic barrier cases.
Also builds on this: the wave64 split (#1960) and a console mode for a group of one console wave split into two host waves (work in progress on my side, for the
InstanceCullingpasses) both use the wave-wide branch decisions.AI-assisted (Claude Code); the runs were on my machine. No game data.
🤖 Generated with Claude Code
https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
@fuzeofficlal on GitHub · 2026-11-26 00:17 UTC · original · reviewed
Verified head
5d7e5e0ccleanly onorigin/main(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0dxil.dll).Findings
emit/lower.rssize headroom (98 Bbelow 512 KiB cap):crates/victory-shader/src/emit/lower.rsgrows from520,563 Bto524,190 B— only 98 bytes belowcargo xtask policy's524,288 Blimit. Any small concurrent change tolower.rswill trip policy unless a bit more helper logic is moved intoemit/lower/barriers.rs.barriers.rs::leaves_loopon barrier-free loop latches:leaves_loopcomputes(ti, ni) = (inside(r, taken) && !back(b, taken), inside(r, not_taken) && !back(b, not_taken)). Whenbis the latch of a barrier-free loop whosetakenedge is the back-edge andnot_takenexits the loop, bothtiandniarefalse, soif ti { not_taken } else { taken }selectstaken(the back-edge) instead of the exit edgenot_taken.after(taken)then seesback(b, taken)and returns[0], losing all barrier counts after that loop.wave_loop_exits,barrier_balance, orconsole_mode.s_cbranch_scc0/1followings_cmp_eq_u64/s_cmp_lg_u64(whichstructure.rsmodels per-lane as!(a ^ c)) would maps_cbranch_scc1towaveAnyTruerather than all-lanes-equal inwave_loop_exits/console_branches.Architecture & Local Verification
wave_loop_exits->barrier_balanceedge-block padding ->console_modest.whens+st.execsfallback) preservesgroup_barrier's UAV fence (1 | 2 | 8) and meshno_barrierhandling cleanly.cargo test --locked -p victory-shader --lib -- emit::flow_tests emit::lower:: emit::crosslane_tests(RTX 5090 + WARP +dxil.dll): 39/39 passed.cargo clippy --locked -p victory-shader --tests -- -D warnings(default and--all-features) &cargo xtask policy(192 files ok): clean.@kotekompotek on GitHub · 2026-11-26 00:27 UTC · original · reviewed
Scoped review: the three-tier design is the honest shape for this — wave-uniform loop exits first, balanced extra barriers where counting permits, and
console_mode(whole-wave branch + EXEC guards) as the fallback when balance can't be proven. The named real-world programs (luminance histograms, shadow classification) give it a testable target list. The invariants are subtle — a barrier on an edge must be provably unreachable by lanes that didn't take the branch — so this one deserves a maintainer eye onbarrier_balance's counting, which I did not fully trace.@Marvisak on GitHub · 2026-11-26 04:31 UTC · original · edited 2026-11-26 08:25 UTC
Automated triage for the maintainers.
Needs work. The new commit
bdc3d48changes three things incrates/victory-shader/src/emit/lower/barriers.rs, and they read right to me:Lower::wave_branch. For the any-lane form the vote islane & !parked; for the all-lanes form it islane | parked. That matches EXEC leaving those lanes out on the console.a3e4d54.CI still fails on this head, with the same failure as before.
emit::barrier_tests::a_loop_ended_by_a_mask_compare_goes_round_while_any_lane_is_leftpanics atbarrier_tests.rs:351:pipeline: "The parameter is incorrect.". The runner's SM 6.6 WARP refuses to create the pipeline for the mask-compare loop in console mode, and this test is skipped on your Windows 10 machine. Please run it against an SM 6.6 WARP (for example the redistributable WARP, as CI uses) with the D3D12 debug layer on to get the reason, then fix the lowering rather than the test. A greencheckwould change the verdict.CI: failing.
Generated by Claude Code
@lhnizdo on GitHub · 2026-11-26 07:10 UTC · original
Thanks for the reviews, @fuzeofficlal and @kotekompotek, and for the triage. Pushed as
f6dfddf,dd15e11anda3e4d54:Tests (
emit/barrier_tests.rs).gfx10::decode. Each program is lowered, validated bydxil.dll, and run on the hardware adapter and on WARP. It must complete and store what the console would:a_barrier_on_one_side_of_a_lane_branch_is_balanced: threads 0–15 meet a barrier the others skip, then all meet one after the join.a_loop_with_a_barrier_left_per_lane_ends_for_the_wave: each thread goes round(thread & 3) + 1times with a barrier in every round, counting rounds under EXEC.a_side_meeting_no_more_barriers_exits: threads 0–15 meet one or two barriers (a uniform choice), the others none to the end. This is the path that relies on exited threads not being waited for, so it runs on both adapters.barriers_that_cannot_be_balanced_run_as_the_console_runs_them: the same with a barrier after the join ({2, 3}against{1}), which goes to console mode.a_loop_ended_by_a_mask_compare_goes_round_while_any_lane_is_left: thes_cmp_eqcase below.a_loop_without_barriers_counts_the_barriers_after_it, anda_loop_without_barriers_pads_the_side_that_skips_it(lowering only): theleaves_loopcase below.victory-shadersuite gives 303 passed, 4 failed, the same 4 asmainon this card.dd15e11: at every loop header a phi says whether a lane is parked. A latch whose exit is decided for the wave parks the lanes that would have left, and every guard inside the loop includes!parked. It only applies in console mode.leaves_loopbug doesn't show in results on NVIDIA (the over-padded side's extra barriers pair harmlessly there). So its test checks the lowering instead: the added barrier must go on the edge into the join, not into the loop's side. That fails without the fix (v_and_b32instead ofs_or_b32).Fixes.
leaves_loopbug you found, @fuzeofficlal, is real. At a latch of a loop without barriers, it took the back edge, losing every barrier after the loop. The branch going round a loop had the same mistake. It now takes the forward side: the other side of a back edge, else the side leaving the loop.s_cbranch_scc*afters_cmp_eqof two masks is decided the other way round now. SCC is set there when all lanes are equal, while fors_and_b64and the like, and fors_cmp_lg, it's set when any lane has the condition.Lower::wave_test, used by both the loop exits and console mode.console_branchesskipping lane branches that aren'ts_cbranch_*: a lane condition only reaches a branch through VCC, EXEC or SCC in GFX10, and those six are the conditional forms on them. Anything else ends a block another way (s_setpcis an indirect jump, whichbarrier_balancealready refuses).lower.rsheadroom: the wave-wide branch's lowering moved tolower/barriers.rs, solower.rsis 523,668 bytes with the parked lanes, still under the limit.On the early exit: if the hardware and WARP runs ever disagree here, the fallback is to send such programs to console mode instead (they'd cost guards but not rely on undefined behaviour). It's a one-line change in
barrier_balance, and I can make it the default if you'd prefer not to rely on it at all.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.