Shaders: lanes of a wave reach group barriers together, as on the console #2918
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-26T00:06:01Z.
The 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
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:17:36Z.
Review: COMMENTED
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.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T00:27:52Z.
Review: COMMENTED
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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:31:57Z.
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
Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-26T07:10:09Z.
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.Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T03:26:53Z.
RDNA1 run (AMD RX 5700 XT, Navi 10, driver 32.0.21045.29003, Windows 11 26200; from the batch in #3410). Head
bdc3d48merged onto main63bcca4.The CI failure isn't only WARP's.
a_loop_ended_by_a_mask_compare_goes_round_while_any_lane_is_leftfails on this AMD card too, at pipeline creation, before the WARP half runs:D3D12 reports wave lanes 32–64 here, and the 32-lane shaders of main's
crosslane_testscreate and run on it. So the card can runWaveSize(32)shaders; it refuses this program. The other barrier tests here (noWaveSize) pass on the card.What I compared (
dxc -dumpbin):WaveSize=32,NumThreads=(64,1,1), and the barrier inside the console-mode loop, withwaveActiveBallotandwaveAnyTruein the latch.crosslane_testsshader that creates fine on this card has the same entry metadata (!{i32 0, i64 1074266112, i32 4, !8, i32 11, !9}, shader flags andWaveSize32) and the same required features. The only difference isNumThreads=(32,1,1).So the AMD compiler seems to refuse the code of the program, not its declarations. I couldn't get the reason: this machine has no D3D12 debug layer (Graphics Tools), and I didn't install it. WARP refusing it as well fits WARP's 4-lane waves:
WaveSize(32)is outside WARP's range, so the test may also need to skip WARP there, as thecrosslane_testswave32 helper does. The RX 5700 XT refusal is separate from that.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T15:22:54Z.
A correction to my RDNA1 run, and a fix for the CI failure.
Correction: the RX 5700 XT does not refuse this pipeline. With a label printed before each
compute_pipeline, the hardware half ofa_loop_ended_by_a_mask_compare_goes_round_while_any_lane_is_leftcreates it, dispatches, and stores what the console would. The panic atbarrier_tests.rs:351comes from the WARP half that runs after it. I misread which adapter failed; sorry for the noise.Cause: this is the only program in the file that keeps the console's lanes, so its DXIL requires
WaveSize(32)(PSV0 32..32). The system WARP's waves are 4 lanes (WaveLaneCountMin..Max4..4), and D3D12 refuses anyWaveSizepipeline there withE_INVALIDARG. dxc-compiled[WaveSize(32)]and[WaveSize(64)]versions of the same loop are refused on WARP too, and the same HLSL withoutWaveSizeis accepted. So it isn't the lowering: the test asks WARP for a wave size it can't run. That's the only failure in CI's run (309 passed, 1 failed).Fix: one test-only commit on top of your head,
ColorMeBoom:pr2920-wave-skip(0b6bb06, fast-forward frombdc3d48):runs_as_the_consolereads the required wave size from PSV0 and skips an adapter whose lane range leaves it out, saying so. When WARP is the only adapter (CI), every adapter may be skipped, asvalu_tests::run_cases_onalready allows for a wave of 32. No production code changes.barrier_testsvictory-shader --lib --features hostVICTORY_WARP=1(CI's case), your head + fixmain63bcca4, RX 5700 XTmain,VICTORY_WARP=1synthetic_teststhat fail onmainalone with this machine's system WARP (not in CI's run)cargo clippy -p victory-shader --all-targets --features host -- -D warningsand the asset policy are clean. The new lines are rustfmt-clean; the file has older unformatted lines that I left alone.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-27T17:33:34Z.
Thanks, @ColorMeBoom, for tracking down the CI failure, and for the correction. I've taken
0b6bb06as it is (fast-forward), and pushed one more fix on top:ef794e8.0b6bb06, the wave-size skip: on this RTX 2080 the barrier tests behave as before. All of them run on the hardware. WARP has no SM 6.6 on Windows 10, so it's skipped there anyway.ef794e8: console mode parks lanes a waterfall carries round through a jump. I found this running the console BVH builder in the game: its waterfall loops never ended, and the device was removed.The bug: the console compiler's waterfall doesn't branch back to the header. The decided branch (
s_andn2_b64 s[16:17], s[16:17], exec, thens_cbranch_scc1) goes to a block that only narrows EXEC again (s_and_b64 exec, s[18:19], s[16:17]) and jumps back. Parking only took a latch going straight to the header, so no lane was parked in such a loop.What went wrong: two kinds of lane voted to go round and ran the body:
A loop that leaves when its counter equals each lane's count then never ends. It runs to the iteration limit and stores nothing.
The fix:
lower/barriers.rs, solower.rsgets 169 bytes smaller (523,564).Tests: two new ones,
a_waterfall_going_round_through_a_jump_leaves_when_its_lanes_are_doneanda_waterfall_with_its_saved_exec_reused_as_a_scalar_leaves_too.thread >> 4: none for threads 0–15, and different maxima in the two waves. The second test also reuses the saved-EXEC register as a scalar in the body, as the builder does.victory-shader --lib --features hostsuite gives 308 passed and 4 failed, the same 4 asmainon this card.In the game: with this fix (on my local stack), the builder's waterfall programs finish and the frame runs with the BVH builder on. A separate builder issue remains, in a tree-optimization program translated per lane. It's not in this PR's code path, and I'm tracking it separately.
AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T17:40:31Z.
@lhnizdo AMD run of
ef794e8: RX 5700 XT (RDNA1, 32–64 lanes), driver 32.0.21045.29003, Windows 11 26200. Merged ontomain63bcca4, no game files.barrier_tests: 10 passed, 0 failed. Both new tests (a_waterfall_going_round_through_a_jump_leaves_when_its_lanes_are_doneanda_waterfall_with_its_saved_exec_reused_as_a_scalar_leaves_too) ran on the hardware and on WARP, with no skips, and stored what the console would. As before, the mask-compare loop skips WARP for its wave size.VICTORY_WARP=1(CI's case):barrier_tests10 passed.victory-shader --lib --features host: 312 passed, 0 failed, 3 ignored.cargo clippy -p victory-shader --all-targets --features host -- -D warnings: clean.That adds a host with 64-lane waves to your RTX 2080 run.
AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-27T18:27:59Z.
Verified exact production
ef794e8c32on the physical RTX 4060 Laptop (NVIDIA 590.48.1, native wave range 32..32), Linux 6.17/Wine 11, 16 GiB system RAM. Diagnostic-relaxed-vtable vkd3d-proton 2576c0b4adfae4a+; not stock certification.victory-shader --lib barrier_tests -- --nocapture --test-threads=1: 10 passed, 0 failed/ignored, 4.35 s after fresh 6.12 s intended-worktree compilation. Seven actual NVIDIA dispatch/readbacks checked all 448 output words, including both new equality-exit waterfalls (ordinary and saved-EXEC reused as scalar). The other three tests check decoding/lowering.Local test-only changes in VIctory-pr2920 require SDK DXIL validation, physical NVIDIA vendor identity and 32..32 wave range; require every selected hardware case to execute; and run only the real hardware leg rather than Wine's misleading WARP fallback. No production changes, adapter skips, WARP/software claim, or deliberately hung parent control. Required modules validated and native pipelines created before dispatch.
Evidence: .compat-runtime/logs/verify-pr2920-waterfall-nvidia-20261127T182510Z/ (console, command, exact dirty provenance, resource samples/result.json). GPU peak 247 MiB, available RAM minimum 11236 MiB. Guards unchanged.
This verifies the synthetic native-wave barrier/waterfall cases, not original XboxBvhBuilder output, split-Wave64 coordination, the separately reported scalar/lane-loop correctness gates, or title rendering. No matched-parent/title/performance claim. In particular, the owner's remaining tree-optimization issue is not tested by these ten cases. No integration into the blocked mixed gameplay stack.
AI-assisted local verification: OpenAI Codex GPT-6-Astra. No game assets or imagery attached.
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.