Shaders: lanes of a wave reach group barriers together, as on the console #2918

Open
lhnizdo wants to merge 10 commits from upstream-pr/2920 into main
lhnizdo commented 2026-11-26 00:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-26T00:06:01Z.


The problem

The console runs s_barrier per 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's GroupMemoryBarrierWithGroupSync counts 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), and CS_FormulaOperation, which loops until any lane reaches its own count.
  • sky_scattering CS_MultipleScattering: 7 barriers.
  • Blendshape and density-shadow programs: 1 barrier each.
  • CS_BatchCullPreSkinnedMeshlets: the meshlet culling, in the submission of a device hang (the debug layer reported the TDR).

What this does

  1. Balancing (9eadbf3).
    • At each per-lane branch, the lighter side's edge gets as many barriers as the two sides' counts to the program's end differ. A host barrier counts arrivals, not instructions, so this is enough.
    • Counts are taken over forward edges, as the sets possible along uniform paths. A branch leaving or going round a loop without barriers needs none.
  2. Early exits (0e0b272).
    • A side that meets no more barriers on any path runs to its end and exits, and needs nothing added: a host barrier doesn't wait for threads that have exited.
    • shortcut: D3D12 leaves a barrier after a thread's exit undefined. NVIDIA and AMD count exited threads out; an early return before a barrier works on both.
  3. Loop exits and console mode (8de7c96).
    • A per-lane branch leaving (or going round) a loop that holds a barrier is decided for the whole wave, as the console decides s_cbranch_vccz/execz and their nz forms, where that only makes lanes leave sooner.
    • Console mode: a program whose barriers still can't be balanced by counting runs as the console runs it. Every branch on a lane mask is decided for the wave, and every vector instruction is guarded by its own EXEC, so the wave's lanes reach each barrier together. It costs guards, so it's used only where counting fails.
  4. 5d7e5e0 moves this code as is into lower/barriers.rs. With it, lower.rs would pass the asset policy's 512 KiB per-file limit.
    • lower.rs is 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:

  • Balancing alone: 55 programs got extra barriers, and all 1,951 emitted compute programs still validated.
  • With early exits: unbalanced programs went from 37 to 28. The meshlet culling's base and _Prev variants are balanced; its ParaboloidShadows ones aren't yet.
  • Console mode: covers the programs counting can't, 53 of the title's, among them the luminance histograms, shadow classification and shadow-map culling.

Tested

  • cargo clippy -p victory-shader --all-targets -- -D warnings is clean, and cargo xtask policy passes.
  • cargo test -p victory-shader --lib on 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 plain main on 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 plain main here 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 InstanceCulling passes) 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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5501396856 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920). Originally posted by [lhnizdo](https://github.com/lhnizdo) on 2026-11-26T00:06:01Z. --- ## The problem The console runs `s_barrier` per **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's `GroupMemoryBarrierWithGroupSync` counts **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), and `CS_FormulaOperation`, which loops until any lane reaches its own count. - **`sky_scattering CS_MultipleScattering`:** 7 barriers. - **Blendshape and density-shadow programs:** 1 barrier each. - **`CS_BatchCullPreSkinnedMeshlets`:** the meshlet culling, in the submission of a device hang (the debug layer reported the TDR). ## What this does 1. **Balancing (`9eadbf3`).** - At each per-lane branch, the lighter side's edge gets as many barriers as the two sides' counts to the program's end differ. A host barrier counts arrivals, not instructions, so this is enough. - Counts are taken over forward edges, as the sets possible along uniform paths. A branch leaving or going round a loop without barriers needs none. 2. **Early exits (`0e0b272`).** - A side that meets no more barriers on any path runs to its end and exits, and needs nothing added: a host barrier doesn't wait for threads that have exited. - shortcut: D3D12 leaves a barrier after a thread's exit undefined. NVIDIA and AMD count exited threads out; an early return before a barrier works on both. 3. **Loop exits and console mode (`8de7c96`).** - A per-lane branch leaving (or going round) a loop that holds a barrier is decided for the **whole wave**, as the console decides `s_cbranch_vccz`/`execz` and their `nz` forms, where that only makes lanes leave sooner. - **Console mode:** a program whose barriers still can't be balanced by counting runs as the console runs it. Every branch on a lane mask is decided for the wave, and every vector instruction is guarded by its own EXEC, so the wave's lanes reach each barrier together. It costs guards, so it's used only where counting fails. 4. **`5d7e5e0`** moves this code as is into `lower/barriers.rs`. With it, `lower.rs` would pass the asset policy's 512 KiB per-file limit. - `lower.rs` is 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`: - **Balancing alone:** 55 programs got extra barriers, and all 1,951 emitted compute programs still validated. - **With early exits:** unbalanced programs went from 37 to 28. The meshlet culling's base and `_Prev` variants are balanced; its ParaboloidShadows ones aren't yet. - **Console mode:** covers the programs counting can't, 53 of the title's, among them the luminance histograms, shadow classification and shadow-map culling. ## Tested - `cargo clippy -p victory-shader --all-targets -- -D warnings` is clean, and `cargo xtask policy` passes. - `cargo test -p victory-shader --lib` on 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 plain `main` on 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 plain `main` here 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 `InstanceCulling` passes) 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.com/claude-code) https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
fuzeofficlal commented 2026-11-26 00:17:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:17:36Z.

Review: COMMENTED


Verified head 5d7e5e0c cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0 dxil.dll).

Findings

  1. emit/lower.rs size headroom (98 B below 512 KiB cap): crates/victory-shader/src/emit/lower.rs grows from 520,563 B to 524,190 B — only 98 bytes below cargo xtask policy's 524,288 B limit. Any small concurrent change to lower.rs will trip policy unless a bit more helper logic is moved into emit/lower/barriers.rs.
  2. Edge selection bug in barriers.rs::leaves_loop on barrier-free loop latches: leaves_loop computes (ti, ni) = (inside(r, taken) && !back(b, taken), inside(r, not_taken) && !back(b, not_taken)). When b is the latch of a barrier-free loop whose taken edge is the back-edge and not_taken exits the loop, both ti and ni are false, so if ti { not_taken } else { taken } selects taken (the back-edge) instead of the exit edge not_taken. after(taken) then sees back(b, taken) and returns [0], losing all barrier counts after that loop.
  3. Minor observations:
    • No unit tests are added yet for wave_loop_exits, barrier_balance, or console_mode.
    • s_cbranch_scc0/1 following s_cmp_eq_u64/s_cmp_lg_u64 (which structure.rs models per-lane as !(a ^ c)) would map s_cbranch_scc1 to waveAnyTrue rather than all-lanes-equal in wave_loop_exits / console_branches.

Architecture & Local Verification

  • The three-tier approach (wave_loop_exits -> barrier_balance edge-block padding -> console_mode st.whens + st.execs fallback) preserves group_barrier's UAV fence (1 | 2 | 8) and mesh no_barrier handling 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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6066834898 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#pullrequestreview-6066834898). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:17:36Z. **Review:** COMMENTED --- Verified head `5d7e5e0c` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0 `dxil.dll`). ### Findings 1. **`emit/lower.rs` size headroom (`98 B` below 512 KiB cap)**: `crates/victory-shader/src/emit/lower.rs` grows from `520,563 B` to **`524,190 B`** — only **98 bytes** below `cargo xtask policy`'s `524,288 B` limit. Any small concurrent change to `lower.rs` will trip policy unless a bit more helper logic is moved into `emit/lower/barriers.rs`. 2. **Edge selection bug in `barriers.rs::leaves_loop` on barrier-free loop latches**: `leaves_loop` computes `(ti, ni) = (inside(r, taken) && !back(b, taken), inside(r, not_taken) && !back(b, not_taken))`. When `b` is the latch of a barrier-free loop whose `taken` edge is the back-edge and `not_taken` exits the loop, both `ti` and `ni` are `false`, so `if ti { not_taken } else { taken }` selects **`taken` (the back-edge)** instead of the exit edge `not_taken`. `after(taken)` then sees `back(b, taken)` and returns `[0]`, losing all barrier counts after that loop. 3. **Minor observations**: - No unit tests are added yet for `wave_loop_exits`, `barrier_balance`, or `console_mode`. - `s_cbranch_scc0/1` following `s_cmp_eq_u64`/`s_cmp_lg_u64` (which `structure.rs` models per-lane as `!(a ^ c)`) would map `s_cbranch_scc1` to `waveAnyTrue` rather than all-lanes-equal in `wave_loop_exits` / `console_branches`. ### Architecture & Local Verification - The three-tier approach (`wave_loop_exits` -> `barrier_balance` edge-block padding -> `console_mode` `st.whens` + `st.execs` fallback) preserves `group_barrier`'s UAV fence (`1 | 2 | 8`) and mesh `no_barrier` handling 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 commented 2026-11-26 00:27:52 +00:00 (Migrated from github.com)

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 on barrier_balance's counting, which I did not fully trace.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066906998 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#pullrequestreview-6066906998). Originally posted by [kotekompotek](https://github.com/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 on `barrier_balance`'s counting, which I did not fully trace.
Marvisak commented 2026-11-26 05:04:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:31:57Z.


Automated triage for the maintainers.

Needs work. The new commit bdc3d48 changes three things in crates/victory-shader/src/emit/lower/barriers.rs, and they read right to me:

  • The parked-lane guard now covers the loop's natural body (the header plus the blocks that reach a latch), not an RPO range. So only blocks the header dominates read its phi.
  • Parked lanes are left out of the wave's exit vote in Lower::wave_branch. For the any-lane form the vote is lane & !parked; for the all-lanes form it is lane | parked. That matches EXEC leaving those lanes out on the console.
  • Only loops with a parking latch get the phi and the guards. Every other loop is lowered as on 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_left panics at barrier_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 green check would change the verdict.

CI: failing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182676649 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#issuecomment-7182676649). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:31:57Z. --- <!-- victory-triage v1 head=bdc3d488533fa8529884c6c81ac15512c3b54413 verdict=needs-work at=2026-11-26T08:20:18Z --> Automated triage for the maintainers. **Needs work.** The new commit `bdc3d48` changes three things in `crates/victory-shader/src/emit/lower/barriers.rs`, and they read right to me: - The parked-lane guard now covers the loop's natural body (the header plus the blocks that reach a latch), not an RPO range. So only blocks the header dominates read its phi. - Parked lanes are left out of the wave's exit vote in `Lower::wave_branch`. For the any-lane form the vote is `lane & !parked`; for the all-lanes form it is `lane | parked`. That matches EXEC leaving those lanes out on the console. - Only loops with a parking latch get the phi and the guards. Every other loop is lowered as on `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_left` panics at `barrier_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 green `check` would change the verdict. CI: failing. --- _Generated by [Claude Code](https://claude.ai/code)_
lhnizdo commented 2026-11-26 08:03:12 +00:00 (Migrated from github.com)

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, dd15e11 and a3e4d54:

Tests (emit/barrier_tests.rs).

  • The setup: one group of 64 threads in two waves of 32. Hand-written GFX10, whose encodings a test checks against gfx10::decode. Each program is lowered, validated by dxil.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) + 1 times 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: the s_cmp_eq case below.
    • a_loop_without_barriers_counts_the_barriers_after_it, and a_loop_without_barriers_pads_the_side_that_skips_it (lowering only): the leaves_loop case below.
  • Results: on an RTX 2080 all 8 pass. Windows 10's WARP has no shader model 6.6, so the WARP half skips here. The whole victory-shader suite gives 303 passed, 4 failed, the same 4 as main on this card.
  • They found a real bug: the loop test first stored 4 for every thread instead of its own count. Console mode kept the wave in the loop until its last lane was done (right), but lanes that had finished still ran the loop's vector instructions. The guard is the EXEC the structure works out per instruction, and that can't say a lane left in an earlier round. Fixed in 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.
    • shortcut: lanes are parked only at a latch (the do-while shape); a branch going round from the middle of a loop keeps its lanes running to the latch.
  • Each fix's test fails without it. I checked by undoing the fix: the mask-compare test fails without the flip. The leaves_loop bug 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_b32 instead of s_or_b32).

Fixes.

  • The leaves_loop bug 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* after s_cmp_eq of two masks is decided the other way round now. SCC is set there when all lanes are equal, while for s_and_b64 and the like, and for s_cmp_lg, it's set when any lane has the condition.
    • The mapping is in one place, Lower::wave_test, used by both the loop exits and console mode.
    • shortcut: only SCC set in the branch's own block is looked at.
  • On console_branches skipping lane branches that aren't s_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_setpc is an indirect jump, which barrier_balance already refuses).
  • The comments describe the patterns instead of naming programs.
  • lower.rs headroom: the wave-wide branch's lowering moved to lower/barriers.rs, so lower.rs is 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185167805 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#issuecomment-7185167805). Originally posted by [lhnizdo](https://github.com/lhnizdo) on 2026-11-26T07:10:09Z. --- Thanks for the reviews, @fuzeofficlal and @kotekompotek, and for the triage. Pushed as `f6dfddf`, `dd15e11` and `a3e4d54`: **Tests (`emit/barrier_tests.rs`).** - **The setup:** one group of 64 threads in two waves of 32. Hand-written GFX10, whose encodings a test checks against `gfx10::decode`. Each program is lowered, validated by `dxil.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) + 1` times 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`: the `s_cmp_eq` case below. - `a_loop_without_barriers_counts_the_barriers_after_it`, and `a_loop_without_barriers_pads_the_side_that_skips_it` (lowering only): the `leaves_loop` case below. - **Results:** on an RTX 2080 all 8 pass. Windows 10's WARP has no shader model 6.6, so the WARP half skips here. The whole `victory-shader` suite gives 303 passed, 4 failed, the same 4 as `main` on this card. - **They found a real bug:** the loop test first stored 4 for every thread instead of its own count. Console mode kept the wave in the loop until its last lane was done (right), but lanes that had finished still ran the loop's vector instructions. The guard is the EXEC the structure works out per instruction, and that can't say a lane left in an earlier round. Fixed in `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. - shortcut: lanes are parked only at a latch (the do-while shape); a branch going round from the middle of a loop keeps its lanes running to the latch. - **Each fix's test fails without it.** I checked by undoing the fix: the mask-compare test fails without the flip. The `leaves_loop` bug 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_b32` instead of `s_or_b32`). **Fixes.** - **The `leaves_loop` bug 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*` after `s_cmp_eq` of two masks** is decided the other way round now. SCC is set there when all lanes are equal, while for `s_and_b64` and the like, and for `s_cmp_lg`, it's set when any lane has the condition. - The mapping is in one place, `Lower::wave_test`, used by both the loop exits and console mode. - shortcut: only SCC set in the branch's own block is looked at. - **On `console_branches` skipping lane branches that aren't `s_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_setpc` is an indirect jump, which `barrier_balance` already refuses). - **The comments** describe the patterns instead of naming programs. - **`lower.rs` headroom:** the wave-wide branch's lowering moved to `lower/barriers.rs`, so `lower.rs` is 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.
ColorMeBoom commented 2026-11-27 03:26:53 +00:00 (Migrated from github.com)

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 bdc3d48 merged onto main 63bcca4.

The CI failure isn't only WARP's. a_loop_ended_by_a_mask_compare_goes_round_while_any_lane_is_left fails on this AMD card too, at pipeline creation, before the WARP half runs:

barrier_tests.rs:351: pipeline: "The parameter is incorrect."

D3D12 reports wave lanes 32–64 here, and the 32-lane shaders of main's crosslane_tests create and run on it. So the card can run WaveSize(32) shaders; it refuses this program. The other barrier tests here (no WaveSize) pass on the card.

What I compared (dxc -dumpbin):

  • The failing program has WaveSize=32, NumThreads=(64,1,1), and the barrier inside the console-mode loop, with waveActiveBallot and waveAnyTrue in the latch.
  • A crosslane_tests shader that creates fine on this card has the same entry metadata (!{i32 0, i64 1074266112, i32 4, !8, i32 11, !9}, shader flags and WaveSize 32) and the same required features. The only difference is NumThreads=(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 the crosslane_tests wave32 helper does. The RX 5700 XT refusal is separate from that.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7208995534 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#issuecomment-7208995534). Originally posted by [ColorMeBoom](https://github.com/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 `bdc3d48` merged onto main `63bcca4`. The CI failure isn't only WARP's. `a_loop_ended_by_a_mask_compare_goes_round_while_any_lane_is_left` fails on this AMD card too, at pipeline creation, before the WARP half runs: ``` barrier_tests.rs:351: pipeline: "The parameter is incorrect." ``` D3D12 reports wave lanes 32–64 here, and the 32-lane shaders of main's `crosslane_tests` create and run on it. So the card can run `WaveSize(32)` shaders; it refuses this program. The other barrier tests here (no `WaveSize`) pass on the card. What I compared (`dxc -dumpbin`): - The failing program has `WaveSize=32`, `NumThreads=(64,1,1)`, and the barrier inside the console-mode loop, with `waveActiveBallot` and `waveAnyTrue` in the latch. - A `crosslane_tests` shader that creates fine on this card has the same entry metadata (`!{i32 0, i64 1074266112, i32 4, !8, i32 11, !9}`, shader flags and `WaveSize` 32) and the same required features. The only difference is `NumThreads=(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 the `crosslane_tests` wave32 helper does. The RX 5700 XT refusal is separate from that. AI use: Claude Code (Claude Opus 5.5).
ColorMeBoom commented 2026-11-27 15:22:54 +00:00 (Migrated from github.com)

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 of a_loop_ended_by_a_mask_compare_goes_round_while_any_lane_is_left creates it, dispatches, and stores what the console would. The panic at barrier_tests.rs:351 comes 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..Max 4..4), and D3D12 refuses any WaveSize pipeline there with E_INVALIDARG. dxc-compiled [WaveSize(32)] and [WaveSize(64)] versions of the same loop are refused on WARP too, and the same HLSL without WaveSize is 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 from bdc3d48):

git fetch https://github.com/ColorMeBoom/VIctory pr2920-wave-skip
git merge --ff-only FETCH_HEAD

runs_as_the_console reads 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, as valu_tests::run_cases_on already allows for a wave of 32. No production code changes.

barrier_tests full victory-shader --lib --features host
RX 5700 XT + WARP, your head + fix 8 passed (WARP skipped for this one program) 310 passed, 0 failed
VICTORY_WARP=1 (CI's case), your head + fix 8 passed —
merged onto main 63bcca4, RX 5700 XT 8 passed 310 passed, 0 failed
merged onto main, VICTORY_WARP=1 8 passed 306 passed, 4 failed: the same 4 synthetic_tests that fail on main alone with this machine's system WARP (not in CI's run)

cargo clippy -p victory-shader --all-targets --features host -- -D warnings and 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7221986575 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#issuecomment-7221986575). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T15:22:54Z. --- **A correction to [my RDNA1 run](https://github.com/Marvisak/VIctory/pull/2920#issuecomment-7208995534), 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 of `a_loop_ended_by_a_mask_compare_goes_round_while_any_lane_is_left` creates it, dispatches, and stores what the console would. The panic at `barrier_tests.rs:351` comes 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..Max` 4..4), and D3D12 refuses any `WaveSize` pipeline there with `E_INVALIDARG`. dxc-compiled `[WaveSize(32)]` and `[WaveSize(64)]` versions of the same loop are refused on WARP too, and the same HLSL without `WaveSize` is 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](https://github.com/Marvisak/VIctory/actions/runs/45780402087) (309 passed, 1 failed). **Fix:** one test-only commit on top of your head, [`ColorMeBoom:pr2920-wave-skip`](https://github.com/ColorMeBoom/VIctory/tree/pr2920-wave-skip) (`0b6bb06`, fast-forward from `bdc3d48`): ``` git fetch https://github.com/ColorMeBoom/VIctory pr2920-wave-skip git merge --ff-only FETCH_HEAD ``` `runs_as_the_console` reads 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, as `valu_tests::run_cases_on` already allows for a wave of 32. No production code changes. | | `barrier_tests` | full `victory-shader --lib --features host` | | --- | --- | --- | | RX 5700 XT + WARP, your head + fix | 8 passed (WARP skipped for this one program) | 310 passed, 0 failed | | `VICTORY_WARP=1` (CI's case), your head + fix | 8 passed | — | | merged onto `main` `63bcca4`, RX 5700 XT | 8 passed | 310 passed, 0 failed | | merged onto `main`, `VICTORY_WARP=1` | 8 passed | 306 passed, 4 failed: the same 4 `synthetic_tests` that fail on `main` alone with this machine's system WARP (not in CI's run) | `cargo clippy -p victory-shader --all-targets --features host -- -D warnings` and 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).
lhnizdo commented 2026-11-27 17:33:34 +00:00 (Migrated from github.com)

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 0b6bb06 as 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, then s_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 lane that was already done;
    • a lane that never entered (on its own path, the loop's mask is the full set).

    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:

    • Such a jump-only block now counts as a latch: what the branch before it parks reaches the header through its back edge.
    • A lane enters a parked loop parked unless it comes on its own path: it reaches the entering block and is on its own side of a branch the wave decided.
    • The code is in lower/barriers.rs, so lower.rs gets 169 bytes smaller (523,564).
    • shortcut: only a jump-only block whose single predecessor is the decided branch counts, as the console compiler emits it.
  • Tests: two new ones, a_waterfall_going_round_through_a_jump_leaves_when_its_lanes_are_done and a_waterfall_with_its_saved_exec_reused_as_a_scalar_leaves_too.

    • The setup: the uneven barriers that send a program to console mode, then an equality-exit waterfall in that shape. Each thread's count is 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.
    • Both store each thread's count on the RTX 2080. Without the fix, both store 0 in every thread.
    • All 10 barrier tests pass. The full victory-shader --lib --features host suite gives 308 passed and 4 failed, the same 4 as main on 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224540382 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#issuecomment-7224540382). Originally posted by [lhnizdo](https://github.com/lhnizdo) on 2026-11-27T17:33:34Z. --- Thanks, @ColorMeBoom, for tracking down the CI failure, and for the correction. I've taken `0b6bb06` as 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`, then `s_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 lane that was already done; - a lane that never entered (on its own path, the loop's mask is the full set). 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:** - Such a jump-only block now counts as a latch: what the branch before it parks reaches the header through its back edge. - A lane enters a parked loop parked unless it comes on its own path: it reaches the entering block and is on its own side of a branch the wave decided. - The code is in `lower/barriers.rs`, so `lower.rs` gets 169 bytes smaller (523,564). - shortcut: only a jump-only block whose single predecessor is the decided branch counts, as the console compiler emits it. - **Tests:** two new ones, `a_waterfall_going_round_through_a_jump_leaves_when_its_lanes_are_done` and `a_waterfall_with_its_saved_exec_reused_as_a_scalar_leaves_too`. - The setup: the uneven barriers that send a program to console mode, then an equality-exit waterfall in that shape. Each thread's count is `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. - Both store each thread's count on the RTX 2080. Without the fix, both store 0 in every thread. - All 10 barrier tests pass. The full `victory-shader --lib --features host` suite gives 308 passed and 4 failed, the same 4 as `main` on 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).
ColorMeBoom commented 2026-11-27 17:40:31 +00:00 (Migrated from github.com)

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 onto main 63bcca4, no game files.

  • barrier_tests: 10 passed, 0 failed. Both new tests (a_waterfall_going_round_through_a_jump_leaves_when_its_lanes_are_done and a_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_tests 10 passed.
  • Full 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224664652 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#issuecomment-7224664652). Originally posted by [ColorMeBoom](https://github.com/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 onto `main` `63bcca4`, no game files. - `barrier_tests`: **10 passed, 0 failed**. Both new tests (`a_waterfall_going_round_through_a_jump_leaves_when_its_lanes_are_done` and `a_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_tests` 10 passed. - Full `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).
pickles976 commented 2026-11-27 18:27:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-27T18:27:59Z.


Verified exact production ef794e8c32 on 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7225516587 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2920#issuecomment-7225516587). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-27T18:27:59Z. --- Verified exact production ef794e8c32ce92365775eaeea16abb912a07f324 on 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2920:upstream-pr/2920'
git switch 'upstream-pr/2920'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2920'
git switch 'upstream-pr/2920'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2920'
git switch 'upstream-pr/2920'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2920'
git switch 'main'
git merge --squash 'upstream-pr/2920'
git switch 'main'
git merge --ff-only 'upstream-pr/2920'
git switch 'main'
git merge 'upstream-pr/2920'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2918
No description provided.