Shaders: a divergent loop's scalars read after it ask for the console wave size (#2's RDNA2 wave-size failures) #110

Open
alexdeliu wants to merge 2 commits from upstream-pr/110 into main
alexdeliu commented 2026-11-25 14:20:43 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by alexdeliu on 2026-11-25T14:20:43Z.


What

When a loop that lanes leave at different iterations leaves scalars to the code after it, a wave64 compute program now asks the host for 64-lane waves (WaveSize(64)), if the host runs them. Other programs are not changed.

Why

MamaLeVrai found the cause in #2: these programs get no WaveSize, and the RDNA2 driver then runs them as wave32. This PR is the narrower rule they suggested.

Where the dependence is: leave_loops (emit/lower.rs) takes a divergent loop's scalars, as the wave's last iteration left them, with a waveActiveOp maximum over the host's wave. That matches the console only when the host wave is the console's size. Under wave32, lanes 0-31 take their half's count and lanes 32-63 take theirs, which is the 32/64 and 8/16 output in #2.

The rule, at the point where leave_loops uses such a value, sets wave_size = Some(64) only when all of these hold:

  • the program is wave64;
  • the host runs 64 lanes (target.runs(64));
  • no wave size was set already (so split and the console-lanes rules are unchanged);
  • the loop has an exit branch whose condition is over more than Atom::Uniforms (x.st.exits, LaneExit::Branch). If every lane leaves together, the count is the same at any wave size.

How many programs it touches

I logged it temporarily, across all of cargo test -p victory-shader --lib on the RX 9070. There are 85 wave64 compute lowerings for a host that runs 64 lanes:

rule programs given WaveSize(64)
broad (x.native.wave64 && x.target.runs(64), from #2) 10 (the 2 tests below, 2 in select_tests, 6 in sgpr_spill tests)
this PR 2 (scalar_counted_in_a_divergent_loop_read_after_it, scalar_counted_in_nested_divergent_loops)

That is unit tests only. I have no count for the title's pipelines (no game data here).

Tested

New test scalars_read_after_a_divergent_loop_ask_for_the_console_wave_size (valu_tests.rs, no GPU needed). It reads the PSV0 wave range: 64/64 for the divergent counted loop, and none for the same counter in a loop with a uniform s_cbranch_scc1 exit. It fails on 71652a2 (gets no range).

The two #2 tests, --test-threads=1:

on 71652a2 with this PR
Ryzen 7 7700 iGPU (gfx1036, RDNA2), VICTORY_ADAPTER=radeon(tm) both fail (same output as the RX 6950 XT in #2) both pass
RX 9070 (RDNA4) pass pass
WARP fail (wrong counts) fail: pipeline refused, like the other WaveSize(64) tests on WARP (loop_exit_mask_counted_after_the_loop, mask_grown_inside_a_branch_counted_after_it)

cargo test -p victory-shader --lib -- --test-threads=1 (VICTORY_DXIL = dxil.dll 1.8.2502.11):

unmodified 71652a2 with this PR
RX 9070 266 passed, 0 failed, 6 ignored 267 passed, 0 failed, 6 ignored
gfx1036 264 passed, 2 failed 267 passed, 0 failed, 6 ignored
WARP 252 passed, 14 failed 253 passed, 14 failed (the same 14)

Not covered

  • Wave32 programs: if a driver ran one as wave64, the same maximum would span two console waves. I did not change that; nothing here fails because of it.
  • join_scalars (scalars at the join of divergent branches) may depend on the host wave in the same way. I did not look into it.
  • Not run in the title. I can't say what this does to pipeline compile times or to the AMD compiler crashes you skip. It does add WaveSize(64) to fewer pipelines than the broad rule.

No game data was used; this is a unit-level change.

AI use: Claude Code (Claude Opus 5.5) wrote the change and ran the tests on my machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5493152161 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-25T14:20:43Z. --- ## What When a loop that lanes leave at different iterations leaves scalars to the code after it, a wave64 compute program now asks the host for 64-lane waves (`WaveSize(64)`), if the host runs them. Other programs are not changed. ## Why MamaLeVrai found the cause in #2: these programs get no `WaveSize`, and the RDNA2 driver then runs them as wave32. This PR is the narrower rule they suggested. Where the dependence is: `leave_loops` (`emit/lower.rs`) takes a divergent loop's scalars, as the wave's last iteration left them, with a `waveActiveOp` maximum over the host's wave. That matches the console only when the host wave is the console's size. Under wave32, lanes 0-31 take their half's count and lanes 32-63 take theirs, which is the 32/64 and 8/16 output in #2. The rule, at the point where `leave_loops` uses such a value, sets `wave_size = Some(64)` only when all of these hold: - the program is wave64; - the host runs 64 lanes (`target.runs(64)`); - no wave size was set already (so `split` and the console-lanes rules are unchanged); - the loop has an exit branch whose condition is over more than `Atom::Uniform`s (`x.st.exits`, `LaneExit::Branch`). If every lane leaves together, the count is the same at any wave size. ## How many programs it touches I logged it temporarily, across all of `cargo test -p victory-shader --lib` on the RX 9070. There are 85 wave64 compute lowerings for a host that runs 64 lanes: | rule | programs given `WaveSize(64)` | |---|---| | broad (`x.native.wave64 && x.target.runs(64)`, from #2) | 10 (the 2 tests below, 2 in `select_tests`, 6 in `sgpr_spill` tests) | | this PR | 2 (`scalar_counted_in_a_divergent_loop_read_after_it`, `scalar_counted_in_nested_divergent_loops`) | That is unit tests only. I have no count for the title's pipelines (no game data here). ## Tested New test `scalars_read_after_a_divergent_loop_ask_for_the_console_wave_size` (`valu_tests.rs`, no GPU needed). It reads the `PSV0` wave range: 64/64 for the divergent counted loop, and none for the same counter in a loop with a uniform `s_cbranch_scc1` exit. It fails on `71652a2` (gets no range). The two #2 tests, `--test-threads=1`: | | on `71652a2` | with this PR | |---|---|---| | Ryzen 7 7700 iGPU (gfx1036, RDNA2), `VICTORY_ADAPTER=radeon(tm)` | **both fail** (same output as the RX 6950 XT in #2) | both pass | | RX 9070 (RDNA4) | pass | pass | | WARP | fail (wrong counts) | fail: pipeline refused, like the other `WaveSize(64)` tests on WARP (`loop_exit_mask_counted_after_the_loop`, `mask_grown_inside_a_branch_counted_after_it`) | `cargo test -p victory-shader --lib -- --test-threads=1` (`VICTORY_DXIL` = dxil.dll 1.8.2502.11): | | unmodified `71652a2` | with this PR | |---|---|---| | RX 9070 | 266 passed, 0 failed, 6 ignored | 267 passed, 0 failed, 6 ignored | | gfx1036 | 264 passed, 2 failed | 267 passed, 0 failed, 6 ignored | | WARP | 252 passed, 14 failed | 253 passed, 14 failed (the same 14) | ## Not covered - Wave32 programs: if a driver ran one as wave64, the same maximum would span two console waves. I did not change that; nothing here fails because of it. - `join_scalars` (scalars at the join of divergent branches) may depend on the host wave in the same way. I did not look into it. - Not run in the title. I can't say what this does to pipeline compile times or to the AMD compiler crashes you skip. It does add `WaveSize(64)` to fewer pipelines than the broad rule. No game data was used; this is a unit-level change. AI use: Claude Code (Claude Opus 5.5) wrote the change and ran the tests on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Adika713 commented 2026-11-25 15:32:11 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Adika713 on 2026-11-25T15:32:11Z.


Verified on the discrete-RDNA2 machine from #2: AMD Radeon RX 6950 XT
(RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1.
No game data; the title was not run.

This is the RX 6950 XT confirmation asked for in #2. I fetched PR head
a7054b1 into a detached worktree and used an isolated CARGO_TARGET_DIR
for each tree (_agent_tmp\target-shader-main-verify and
_agent_tmp\target-pr110-verify, under F:\VIctory-Belobug-AMD). Reusing one
target dir across main and a worktree can silently run a stale test binary.

Before, at upstream/main 01aadd193d57e71fb4d57810eb2fdd1bc95c950b, from
F:\VIctory-Belobug-AMD:

cargo test -p victory-shader emit::valu_tests -- --test-threads=1
cargo test -p victory-shader --lib -- --test-threads=1
  • valu tests: exit 101 — test result: FAILED. 25 passed; 2 failed; 0 ignored; 0 measured; 245 filtered out.
  • full lib: exit 101 — test result: FAILED. 264 passed; 2 failed; 6 ignored; 0 measured; 0 filtered out.
  • The two failures were emit::valu_tests::scalar_counted_in_a_divergent_loop_read_after_it
    and emit::valu_tests::scalar_counted_in_nested_divergent_loops.

After, at PR head a7054b1, from a detached worktree at
F:\VIctory-Belobug-AMD\_agent_tmp\pr-110:

cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-110\Cargo.toml -p victory-shader emit::valu_tests -- --test-threads=1
cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-110\Cargo.toml -p victory-shader --lib -- --test-threads=1
  • valu tests: exit 0 — test result: ok. 28 passed; 0 failed; 0 ignored; 0 measured; 245 filtered out
    (plus doc-tests: 0 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out).
  • full lib: exit 0 — test result: ok. 267 passed; 0 failed; 6 ignored; 0 measured; 0 filtered out.
  • Both #2 tests now pass on this card. The extra valu test is the PR's new
    CPU-only wave-range regression test.

Overlap: I also ran the focused valu command on PR #92 head 7a592eb (the
broader wave64 rule); it also passes: 27 passed; 0 failed; 0 ignored; 0 measured; 246 filtered out, with the doc-test line 0 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out. I did not run #92's full lib. I wrote
no competing fix.

Not tested: the game, pipeline compile times or AMD compiler crashes; no game
files were used.

AI-assisted: OpenCode, model Big Pickle. No game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7166994663 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7166994663). Originally posted by [Adika713](https://github.com/Adika713) on 2026-11-25T15:32:11Z. --- Verified on the discrete-RDNA2 machine from #2: AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1. No game data; the title was not run. This is the RX 6950 XT confirmation asked for in #2. I fetched PR head `a7054b1` into a detached worktree and used an isolated `CARGO_TARGET_DIR` for each tree (`_agent_tmp\target-shader-main-verify` and `_agent_tmp\target-pr110-verify`, under `F:\VIctory-Belobug-AMD`). Reusing one target dir across main and a worktree can silently run a stale test binary. Before, at `upstream/main` `01aadd193d57e71fb4d57810eb2fdd1bc95c950b`, from `F:\VIctory-Belobug-AMD`: ```powershell cargo test -p victory-shader emit::valu_tests -- --test-threads=1 cargo test -p victory-shader --lib -- --test-threads=1 ``` - valu tests: exit 101 — `test result: FAILED. 25 passed; 2 failed; 0 ignored; 0 measured; 245 filtered out`. - full lib: exit 101 — `test result: FAILED. 264 passed; 2 failed; 6 ignored; 0 measured; 0 filtered out`. - The two failures were `emit::valu_tests::scalar_counted_in_a_divergent_loop_read_after_it` and `emit::valu_tests::scalar_counted_in_nested_divergent_loops`. After, at PR head `a7054b1`, from a detached worktree at `F:\VIctory-Belobug-AMD\_agent_tmp\pr-110`: ```powershell cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-110\Cargo.toml -p victory-shader emit::valu_tests -- --test-threads=1 cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-110\Cargo.toml -p victory-shader --lib -- --test-threads=1 ``` - valu tests: exit 0 — `test result: ok. 28 passed; 0 failed; 0 ignored; 0 measured; 245 filtered out` (plus doc-tests: `0 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out`). - full lib: exit 0 — `test result: ok. 267 passed; 0 failed; 6 ignored; 0 measured; 0 filtered out`. - Both #2 tests now pass on this card. The extra valu test is the PR's new CPU-only wave-range regression test. Overlap: I also ran the focused valu command on PR #92 head `7a592eb` (the broader wave64 rule); it also passes: `27 passed; 0 failed; 0 ignored; 0 measured; 246 filtered out`, with the doc-test line `0 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out`. I did not run #92's full lib. I wrote no competing fix. Not tested: the game, pipeline compile times or AMD compiler crashes; no game files were used. AI-assisted: OpenCode, model Big Pickle. No game data.
alexdeliu commented 2026-11-25 16:01:01 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by alexdeliu on 2026-11-25T16:01:01Z.


Thanks @Adika713 for the RX 6950 XT run, before and after, each tree with its own target dir. That makes three RDNA2 GPUs where #2's two tests fail on main: the RX 6950 XT here, the RX 6700 XT in #92, and the gfx1036 iGPU in the description. On the two where #110 was run, it fixes them.

How this relates to #92 (@dutch2005, opened first): both fix the same two tests, and only one of them is needed.

  • #92 asks for WaveSize(64) for every wave64 compute program on a 64-lane host.
  • #110 asks for it only where leave_loops takes a divergent loop's scalars with a wave maximum. That is the step whose result depends on the host's wave width.
  • Across the unit tests, #92's rule sets it for 10 programs and #110's for 2.

The broad rule is simpler. The narrow one leaves the driver's choice alone for every other pipeline, which is what @MamaLeVrai asked for because of compile times and the AMD compiler crashes. Either way works for the tests. @Belobug, it's your call which one you prefer.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7167517450 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7167517450). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-25T16:01:01Z. --- Thanks @Adika713 for the RX 6950 XT run, before and after, each tree with its own target dir. That makes three RDNA2 GPUs where #2's two tests fail on main: the RX 6950 XT here, the RX 6700 XT in #92, and the gfx1036 iGPU in the description. On the two where #110 was run, it fixes them. How this relates to #92 (@dutch2005, opened first): both fix the same two tests, and only one of them is needed. - #92 asks for `WaveSize(64)` for every wave64 compute program on a 64-lane host. - #110 asks for it only where `leave_loops` takes a divergent loop's scalars with a wave maximum. That is the step whose result depends on the host's wave width. - Across the unit tests, #92's rule sets it for 10 programs and #110's for 2. The broad rule is simpler. The narrow one leaves the driver's choice alone for every other pipeline, which is what @MamaLeVrai asked for because of compile times and the AMD compiler crashes. Either way works for the tests. @Belobug, it's your call which one you prefer.
ySKELLETONX commented 2026-11-25 16:35:46 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ySKELLETONX on 2026-11-25T16:35:46Z.


Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at a7054b1: cargo test -p victory-shader --lib --locked: 267 passed, 0 failed, 6 ignored, hardware dispatch tests included (main at 01aadd1: 266 passed). Workspace tests only; not run in the title.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7168232083 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7168232083). Originally posted by [ySKELLETONX](https://github.com/ySKELLETONX) on 2026-11-25T16:35:46Z. --- Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at `a7054b1`: `cargo test -p victory-shader --lib --locked`: **267 passed, 0 failed, 6 ignored**, hardware dispatch tests included (`main` at `01aadd1`: 266 passed). Workspace tests only; not run in the title.
adrianmjim commented 2026-11-25 17:24:34 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T17:24:34Z.


Results from an RX 7900 XT (RDNA3, Windows 11 build 26300, dxil.dll from Windows Kits 10.0.26100.0), at a7054b1. They agree with ySKELLETONX's RX 7600 XT run above. What is new is a wave32 case that the "Not covered" section of the description mentions.

  • cargo test -p victory-shader --lib -- --test-threads=1: 267 passed, 0 failed, 6 ignored. This includes the two #2 tests and scalars_read_after_a_divergent_loop_ask_for_the_console_wave_size. The two #2 tests also pass here without the PR (on 71652a2).
  • Why they pass: on this GPU the driver runs compute programs that declare no WaveSize as 64-lane waves, and this includes console wave32 programs. I checked it with a local probe that stores v_readfirstlane_b32 of the thread id. A group of 64 is one host wave, and groups of 128 and 256 start a host wave every 64 lanes. The result is the same for console wave32 and wave64 programs.

On wave32 programs, the description says that if a driver ran one as wave64, the same maximum would span two console waves, but nothing fails because of it. On RDNA3 that is the driver's default, and it does fail. I wrote a wave32 copy of the divergent-loop counter: the same loop with _b32 mask ops and a group of 64. On the console, lanes 0-31 read 32 and lanes 32-63 read 64. With this PR, every lane reads 64 on the 7900 XT, and the program declares no wave size, because the rule is for wave64 programs only. #92's broader rule is also wave64-only, so it does not cover this either.

I have a small follow-up commit on top of this PR. It is meant to go in after this PR, not instead of it. It keeps the rule where it is, with the same took / divergent_exit conditions:

  • It asks for the console's wave size, 32 or 64, if the host runs it, instead of only 64.
  • It asks for nothing when the thread group is no larger than both the console's wave and the host's smallest wave (target.lanes_min): such a group is one wave at any size the host picks.
    • On a host that runs 32-64 lanes, this drops WaveSize(64) for wave64 groups of 32 threads or fewer, which this PR sets.
    • With Target::ANY (lanes_min 4) the wave64 result is unchanged for groups larger than 4 threads.
    • Vertex and pixel programs have no thread group, so they never get it. Mesh programs still can, as with this PR. Neither rule checks the stage, and on the title's archive no mesh program gets one.
  • It adds two tests:
    • scalar_counted_in_a_wave32_divergent_loop_read_after_it needs a GPU. It fails on the 7900 XT with this PR alone and passes with the follow-up. On a host that runs wave32 programs as wave32 it passes either way.
    • a_group_of_several_host_waves_asks_for_the_console_wave_size needs no GPU. It checks the PSV0 range for wave32 and wave64 programs with groups of 64 and 32, on a host that runs 32-64 lanes. It fails with this PR alone.
  • cargo test -p victory-shader --lib -- --test-threads=1 with the follow-up: 269 passed, 0 failed, 6 ignored.

Counts over the title's shaders.rpf, from victory translate --validate --host-lanes 32-64. I counted the PSV0 wave size with a local counter that is not part of either change:

compute programs main (01aadd1) this PR this PR + follow-up
wave32, WaveSize(32) 898 898 899
wave32, none 633 633 632
wave64, WaveSize(64) 404 406 405
wave64, none 747 745 746

No mesh program gets a wave size in any of the three runs. All three validate the same: 14247 of 14247 vertex/pixel, 2682 of 2682 compute, and 8694 of 8765 mesh (the 71 are the existing "mesh outputs beyond the host's 32 KiB" failures). The per-program results of the three runs differ only in the wave size of these programs:

  • This PR adds WaveSize(64) to CS_ShadowTileBalanceRTCost_03da1e4a and CS_AutoHighbeamAmbientLightCalc_756e19e7.
  • The follow-up keeps the first and drops the second. The second's group must be 32 threads or fewer; that follows from the rule, I did not read it from the program.
  • The follow-up adds WaveSize(32) to CS_SurfacePrimitivesOptimized_12e6e205.

The description also says join_scalars may depend on the host wave. On the 7900 XT it does, and so does v_readfirstlane_b32. Neither this PR nor the follow-up changes them. Both are shown with small local probes only:

  • join_scalars: in a wave32 group of 64, a scalar is 1 before a branch that only lanes 48-63 take, and that branch sets it to 2. All 64 lanes read 2, and no wave size is declared. On the console, lanes 0-31 would read 1.
  • v_readfirstlane_b32 (waveReadLaneFirst): in a wave32 group of 64, every lane reads lane 0's value. On the console, the second wave (lanes 32-63) reads lane 32's. I have not checked whether game programs use it on values that differ between lanes.

Not tested:

  • RDNA2, NVIDIA and WARP. For wave64 groups over 32 threads (the #2 case), the follow-up does the same as this PR, but I have not run it on RDNA2. On WARP the new GPU test probably meets the same pipeline refusal as the other WaveSize tests; I have not run it.
  • The title itself (no game executable here).
  • Pipeline creation over the archive (I ran --validate only).

I can share the follow-up as a branch or as a diff, whichever you prefer.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7169460980 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7169460980). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T17:24:34Z. --- Results from an RX 7900 XT (RDNA3, Windows 11 build 26300, dxil.dll from Windows Kits 10.0.26100.0), at a7054b1. They agree with ySKELLETONX's RX 7600 XT run above. What is new is a wave32 case that the "Not covered" section of the description mentions. - `cargo test -p victory-shader --lib -- --test-threads=1`: 267 passed, 0 failed, 6 ignored. This includes the two #2 tests and `scalars_read_after_a_divergent_loop_ask_for_the_console_wave_size`. The two #2 tests also pass here without the PR (on 71652a2). - Why they pass: on this GPU the driver runs compute programs that declare no `WaveSize` as 64-lane waves, and this includes console wave32 programs. I checked it with a local probe that stores `v_readfirstlane_b32` of the thread id. A group of 64 is one host wave, and groups of 128 and 256 start a host wave every 64 lanes. The result is the same for console wave32 and wave64 programs. On wave32 programs, the description says that if a driver ran one as wave64, the same maximum would span two console waves, but nothing fails because of it. On RDNA3 that is the driver's default, and it does fail. I wrote a wave32 copy of the divergent-loop counter: the same loop with `_b32` mask ops and a group of 64. On the console, lanes 0-31 read 32 and lanes 32-63 read 64. With this PR, every lane reads 64 on the 7900 XT, and the program declares no wave size, because the rule is for wave64 programs only. #92's broader rule is also wave64-only, so it does not cover this either. I have a small follow-up commit on top of this PR. It is meant to go in after this PR, not instead of it. It keeps the rule where it is, with the same `took` / `divergent_exit` conditions: - It asks for the console's wave size, 32 or 64, if the host runs it, instead of only 64. - It asks for nothing when the thread group is no larger than both the console's wave and the host's smallest wave (`target.lanes_min`): such a group is one wave at any size the host picks. - On a host that runs 32-64 lanes, this drops `WaveSize(64)` for wave64 groups of 32 threads or fewer, which this PR sets. - With `Target::ANY` (lanes_min 4) the wave64 result is unchanged for groups larger than 4 threads. - Vertex and pixel programs have no thread group, so they never get it. Mesh programs still can, as with this PR. Neither rule checks the stage, and on the title's archive no mesh program gets one. - It adds two tests: - `scalar_counted_in_a_wave32_divergent_loop_read_after_it` needs a GPU. It fails on the 7900 XT with this PR alone and passes with the follow-up. On a host that runs wave32 programs as wave32 it passes either way. - `a_group_of_several_host_waves_asks_for_the_console_wave_size` needs no GPU. It checks the PSV0 range for wave32 and wave64 programs with groups of 64 and 32, on a host that runs 32-64 lanes. It fails with this PR alone. - `cargo test -p victory-shader --lib -- --test-threads=1` with the follow-up: 269 passed, 0 failed, 6 ignored. Counts over the title's shaders.rpf, from `victory translate --validate --host-lanes 32-64`. I counted the PSV0 wave size with a local counter that is not part of either change: | compute programs | main (01aadd1) | this PR | this PR + follow-up | |---|---|---|---| | wave32, WaveSize(32) | 898 | 898 | 899 | | wave32, none | 633 | 633 | 632 | | wave64, WaveSize(64) | 404 | 406 | 405 | | wave64, none | 747 | 745 | 746 | No mesh program gets a wave size in any of the three runs. All three validate the same: 14247 of 14247 vertex/pixel, 2682 of 2682 compute, and 8694 of 8765 mesh (the 71 are the existing "mesh outputs beyond the host's 32 KiB" failures). The per-program results of the three runs differ only in the wave size of these programs: - This PR adds `WaveSize(64)` to CS_ShadowTileBalanceRTCost_03da1e4a and CS_AutoHighbeamAmbientLightCalc_756e19e7. - The follow-up keeps the first and drops the second. The second's group must be 32 threads or fewer; that follows from the rule, I did not read it from the program. - The follow-up adds `WaveSize(32)` to CS_SurfacePrimitivesOptimized_12e6e205. The description also says `join_scalars` may depend on the host wave. On the 7900 XT it does, and so does `v_readfirstlane_b32`. Neither this PR nor the follow-up changes them. Both are shown with small local probes only: - `join_scalars`: in a wave32 group of 64, a scalar is 1 before a branch that only lanes 48-63 take, and that branch sets it to 2. All 64 lanes read 2, and no wave size is declared. On the console, lanes 0-31 would read 1. - `v_readfirstlane_b32` (`waveReadLaneFirst`): in a wave32 group of 64, every lane reads lane 0's value. On the console, the second wave (lanes 32-63) reads lane 32's. I have not checked whether game programs use it on values that differ between lanes. Not tested: - RDNA2, NVIDIA and WARP. For wave64 groups over 32 threads (the #2 case), the follow-up does the same as this PR, but I have not run it on RDNA2. On WARP the new GPU test probably meets the same pipeline refusal as the other `WaveSize` tests; I have not run it. - The title itself (no game executable here). - Pipeline creation over the archive (I ran `--validate` only). I can share the follow-up as a branch or as a diff, whichever you prefer.
alexdeliu commented 2026-11-25 17:41:56 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by alexdeliu on 2026-11-25T17:41:56Z.


Thanks @adrianmjim. That is the wave32 case I listed under "Not covered", and your probe shows it does fail on RDNA3, where the driver runs wave32 programs as wave64 by default. Your follow-up is the right shape: the console's own wave size, and nothing for a group that is one wave whatever the host picks.

The shaders.rpf counts are the best measure of this PR's reach: WaveSize changes on 2 of the 2,682 compute programs.

Please share it as a branch on top of fix/rdna2-wave64-scalar-loops. I'll run it on the three this machine has and you haven't: the RDNA2 iGPU (gfx1036, which runs undeclared compute as wave32), the RX 9070 and WARP. That covers both #2 tests and your two new ones, before and after. Then it's your choice:

  • you open it as a PR on top of #110;
  • or I add your commit to #110 with you as its author.

On join_scalars and v_readfirstlane_b32 in a wave32 group of 64: agreed, they depend on the host wave in the same way. They fit the same rule, a wave-level step in the translation asks for the console's wave size, but I'd keep them for a separate change, after this one, with probes like yours as tests.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7169872905 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7169872905). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-25T17:41:56Z. --- Thanks @adrianmjim. That is the wave32 case I listed under "Not covered", and your probe shows it does fail on RDNA3, where the driver runs wave32 programs as wave64 by default. Your follow-up is the right shape: the console's own wave size, and nothing for a group that is one wave whatever the host picks. The `shaders.rpf` counts are the best measure of this PR's reach: `WaveSize` changes on 2 of the 2,682 compute programs. Please share it as a branch on top of `fix/rdna2-wave64-scalar-loops`. I'll run it on the three this machine has and you haven't: the RDNA2 iGPU (gfx1036, which runs undeclared compute as wave32), the RX 9070 and WARP. That covers both #2 tests and your two new ones, before and after. Then it's your choice: - you open it as a PR on top of #110; - or I add your commit to #110 with you as its author. On `join_scalars` and `v_readfirstlane_b32` in a wave32 group of 64: agreed, they depend on the host wave in the same way. They fit the same rule, a wave-level step in the translation asks for the console's wave size, but I'd keep them for a separate change, after this one, with probes like yours as tests.
adrianmjim commented 2026-11-25 18:42:54 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T18:42:54Z.


Here it is: https://github.com/adrianmjim/VIctory-Belobug-AMD/tree/wave32-scalar-loops-follow-up

One commit, c20a5d0, directly on a7054b1 (this PR's head), so it fast-forwards fix/rdna2-wave64-scalar-loops. It touches emit/lower.rs (the rule) and emit/valu_tests.rs (the two new tests).

Of the two options, I'd prefer you add it to #110 with me as its author. A PR from my fork on top of #110 would have to target main and would carry #110's commit as well, which seems harder to review than one PR.

Agreed on keeping join_scalars and v_readfirstlane_b32 for a separate change.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7171293641 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7171293641). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T18:42:54Z. --- Here it is: https://github.com/adrianmjim/VIctory-Belobug-AMD/tree/wave32-scalar-loops-follow-up One commit, `c20a5d0`, directly on `a7054b1` (this PR's head), so it fast-forwards `fix/rdna2-wave64-scalar-loops`. It touches `emit/lower.rs` (the rule) and `emit/valu_tests.rs` (the two new tests). Of the two options, I'd prefer you add it to #110 with me as its author. A PR from my fork on top of #110 would have to target `main` and would carry #110's commit as well, which seems harder to review than one PR. Agreed on keeping `join_scalars` and `v_readfirstlane_b32` for a separate change.
MamaLeVrai commented 2026-11-26 00:05:26 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T00:05:26Z.


Result on an RX 6950 XT (RDNA2, the card of #2), Windows 11 build 26300, Rust 1.98.1. This PR (a7054b1) merged on main 4f62c2a, cargo test --release -p victory-shader --lib:

  • main: 275 passed, 2 failed (scalar_counted_in_a_divergent_loop_read_after_it, scalar_counted_in_nested_divergent_loops, every run).
  • With this PR: 278 passed, 0 failed.
  • With this PR, #144 and two diagnostics changes of mine (#214 and a local branch): 279 passed, 0 failed, two runs out of two. They all merge without a conflict.

victory-gpu and victory-hle are unchanged against main. Not run in the game.

harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7178383535 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7178383535). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T00:05:26Z. --- Result on an RX 6950 XT (RDNA2, the card of #2), Windows 11 build 26300, Rust 1.98.1. This PR (`a7054b1`) merged on `main` `4f62c2a`, `cargo test --release -p victory-shader --lib`: - `main`: 275 passed, 2 failed (`scalar_counted_in_a_divergent_loop_read_after_it`, `scalar_counted_in_nested_divergent_loops`, every run). - With this PR: **278 passed, 0 failed**. - With this PR, #144 and two diagnostics changes of mine (#214 and a local branch): 279 passed, 0 failed, two runs out of two. They all merge without a conflict. `victory-gpu` and `victory-hle` are unchanged against `main`. Not run in the game. harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300 AI-assisted (Claude Code); no game data.
adrianmjim commented 2026-11-26 00:06:45 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T00:06:45Z.


@MamaLeVrai, since you have the #2 card: if you have time, the wave32 follow-up I posted for this PR would be worth one run there too. It is one commit on top of a7054b1, branch https://github.com/adrianmjim/VIctory-Belobug-AMD/tree/wave32-scalar-loops-follow-up (c20a5d0), and it also merges into 4f62c2a without a conflict. It asks for the console's wave size in wave32 programs too, and asks for none when the group is a single wave.

On RDNA2 the interesting results are:

  • the two #2 tests;
  • the two tests it adds: scalar_counted_in_a_wave32_divergent_loop_read_after_it, which needs a GPU and fails on an RX 7900 XT with this PR alone, and a_group_of_several_host_waves_asks_for_the_console_wave_size, which needs none.

cargo test -p victory-shader --lib with and without it would show whether it changes anything on a card that runs undeclared compute as wave32.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7178407522 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7178407522). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T00:06:45Z. --- @MamaLeVrai, since you have the #2 card: if you have time, the wave32 follow-up I posted for this PR would be worth one run there too. It is one commit on top of `a7054b1`, branch https://github.com/adrianmjim/VIctory-Belobug-AMD/tree/wave32-scalar-loops-follow-up (`c20a5d0`), and it also merges into `4f62c2a` without a conflict. It asks for the console's wave size in wave32 programs too, and asks for none when the group is a single wave. On RDNA2 the interesting results are: - the two #2 tests; - the two tests it adds: `scalar_counted_in_a_wave32_divergent_loop_read_after_it`, which needs a GPU and fails on an RX 7900 XT with this PR alone, and `a_group_of_several_host_waves_asks_for_the_console_wave_size`, which needs none. `cargo test -p victory-shader --lib` with and without it would show whether it changes anything on a card that runs undeclared compute as wave32.
alexdeliu commented 2026-11-26 00:25:55 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by alexdeliu on 2026-11-26T00:25:55Z.


@adrianmjim, I've added your follow-up to this PR as you asked: commit c20a5d0, with you as its author, fast-forwarded on top of a7054b1. I ran it on the three adapters you didn't have: your tests alone on a7054b1 (before), then your whole commit (after), --test-threads=1, VICTORY_DXIL = dxil.dll 1.8.2502.11.

test RX 9070 (RDNA4) before → after gfx1036 iGPU (RDNA2) before → after WARP before → after
scalar_counted_in_a_divergent_loop_read_after_it pass → pass pass → pass pipeline refused, both
scalar_counted_in_nested_divergent_loops pass → pass pass → pass pipeline refused, both
scalar_counted_in_a_wave32_divergent_loop_read_after_it fail → pass pass → pass fail → pipeline refused
a_group_of_several_host_waves_asks_for_the_console_wave_size fail → pass fail → pass fail → pass

The wave32 case fails on RDNA4 too, not only on RDNA3. The RX 9070 also runs undeclared wave32 compute as wave64, so this follow-up matters on the card this fork is developed on. The RDNA2 iGPU runs undeclared compute as wave32, so it passes either way, as you expected.

Full cargo test -p victory-shader --lib with the follow-up:

  • RX 9070: 269 passed, 0 failed.
  • gfx1036: 269 passed, 0 failed.
  • WARP: 254 passed, 15 failed. These are the same 14 as on main, plus the new wave32 GPU test, which WARP refuses like the other WaveSize tests.

cargo clippy -p victory-shader --all-targets: no new warnings.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7178748276 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7178748276). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-26T00:25:55Z. --- @adrianmjim, I've added your follow-up to this PR as you asked: commit `c20a5d0`, with you as its author, fast-forwarded on top of `a7054b1`. I ran it on the three adapters you didn't have: your tests alone on `a7054b1` (before), then your whole commit (after), `--test-threads=1`, `VICTORY_DXIL` = dxil.dll 1.8.2502.11. | test | RX 9070 (RDNA4) before → after | gfx1036 iGPU (RDNA2) before → after | WARP before → after | |---|---|---|---| | `scalar_counted_in_a_divergent_loop_read_after_it` | pass → pass | pass → pass | pipeline refused, both | | `scalar_counted_in_nested_divergent_loops` | pass → pass | pass → pass | pipeline refused, both | | `scalar_counted_in_a_wave32_divergent_loop_read_after_it` | **fail → pass** | pass → pass | fail → pipeline refused | | `a_group_of_several_host_waves_asks_for_the_console_wave_size` | fail → pass | fail → pass | fail → pass | **The wave32 case fails on RDNA4 too, not only on RDNA3.** The RX 9070 also runs undeclared wave32 compute as wave64, so this follow-up matters on the card this fork is developed on. The RDNA2 iGPU runs undeclared compute as wave32, so it passes either way, as you expected. Full `cargo test -p victory-shader --lib` with the follow-up: - RX 9070: 269 passed, 0 failed. - gfx1036: 269 passed, 0 failed. - WARP: 254 passed, 15 failed. These are the same 14 as on main, plus the new wave32 GPU test, which WARP refuses like the other `WaveSize` tests. `cargo clippy -p victory-shader --all-targets`: no new warnings.
adrianmjim commented 2026-11-26 01:36:16 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T01:36:16Z.


Thanks @alexdeliu, and good catch on the RX 9070: so the wave32 case matters on RDNA4 as well as RDNA3, and the iGPU passing either way fits the RDNA2 default. The WARP result is what I expected: the new GPU test meets the same pipeline refusal as the other WaveSize tests.

@MamaLeVrai: since the commit is now part of this PR, a run of its current head on the RX 6950 XT is all that's needed for the discrete RDNA2 data point, if you get to it.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7179939228 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7179939228). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T01:36:16Z. --- Thanks @alexdeliu, and good catch on the RX 9070: so the wave32 case matters on RDNA4 as well as RDNA3, and the iGPU passing either way fits the RDNA2 default. The WARP result is what I expected: the new GPU test meets the same pipeline refusal as the other `WaveSize` tests. @MamaLeVrai: since the commit is now part of this PR, a run of its current head on the RX 6950 XT is all that's needed for the discrete RDNA2 data point, if you get to it.
MamaLeVrai commented 2026-11-26 05:29:32 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T05:29:32Z.


@adrianmjim here is the discrete RDNA2 run of the current head c20a5d0, merged onto main 4f62c2a. Machine: RX 6950 XT, Windows 11 build 26300, Rust 1.98.1.

  • Whole victory-shader lib, release: 280 passed, 0 failed, 6 ignored. Of three runs, the other two died without a result line. This test binary does that here on main as well (2 of 10 runs; #140 stops it).
  • The three tests alone, --test-threads=1: all pass.
    • scalar_counted_in_a_divergent_loop_read_after_it: ok
    • scalar_counted_in_a_wave32_divergent_loop_read_after_it: ok
    • scalar_counted_in_nested_divergent_loops: ok

On main the first and third fail on every run on this card.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7183533084 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7183533084). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T05:29:32Z. --- @adrianmjim here is the discrete RDNA2 run of the current head `c20a5d0`, merged onto `main` `4f62c2a`. Machine: RX 6950 XT, Windows 11 build 26300, Rust 1.98.1. - Whole `victory-shader` lib, release: **280 passed, 0 failed, 6 ignored**. Of three runs, the other two died without a result line. This test binary does that here on `main` as well (2 of 10 runs; #140 stops it). - The three tests alone, `--test-threads=1`: all pass. - `scalar_counted_in_a_divergent_loop_read_after_it`: ok - `scalar_counted_in_a_wave32_divergent_loop_read_after_it`: ok - `scalar_counted_in_nested_divergent_loops`: ok On `main` the first and third fail on every run on this card. AI-assisted (Claude Code); no game data.
adrianmjim commented 2026-11-26 05:30:17 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T05:30:17Z.


Thanks @MamaLeVrai. With alexdeliu's runs, c20a5d0 is now covered on the three RDNA generations: the discrete RDNA2 here and his gfx1036 iGPU (both pass with and without it), the RX 7900 XT (RDNA3) and the RX 9070 (RDNA4), where the wave32 case fails without it and passes with it. It is also covered on WARP, where the new GPU test meets the expected WaveSize refusal. The other two runs dying without a result line fits #140's case, not this change.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7183544610 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#issuecomment-7183544610). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T05:30:17Z. --- Thanks @MamaLeVrai. With alexdeliu's runs, `c20a5d0` is now covered on the three RDNA generations: the discrete RDNA2 here and his gfx1036 iGPU (both pass with and without it), the RX 7900 XT (RDNA3) and the RX 9070 (RDNA4), where the wave32 case fails without it and passes with it. It is also covered on WARP, where the new GPU test meets the expected `WaveSize` refusal. The other two runs dying without a result line fits #140's case, not this change.
gut0to commented 2026-11-27 14:41:08 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-27T14:41:08Z.

Code review location: crates/victory-shader/src/emit/lower.rs; line 12428

@@ -12409,11 +12411,58 @@ impl<'a> Lower<'a> {
                     && let Some(f) = final_of(self, val)
                 {
                     self.vals.insert(phi.value, f);
-                }
+                    took = true;
+                }
+            }
+            // The wave maximum above is over the host's wave: it stands for
+            // the console's only in a wave of the console's size. Lanes leave
+            // a loop at different iterations only through a branch over more
+            // than uniform values, so only then is the host asked for it (a
+            // host left to choose may run a wave64 program as wave32, and a
+            // wave32 one as wave64). A group no larger than the console's
+            // wave and the host's smallest is one wave at any size.
+            let wave = if self.x.native.wave64 { 64 } else { 32 };
+            let waves = self
+                .s
+                .threads
+                .is_some_and(|t| t.iter().product::<u32>() > wave.min(self.x.target.lanes_min));

Could a fixture cover a group size one lane above this threshold alongside the existing one-wave and two-wave cases? waves changes at group_threads > min(console_wave, host_min_wave), but the current assertions exercise only 32 and 64 threads. On a host with a 32-lane minimum, a 33-thread group is the first partial-final-wave case that needs an explicit 64-lane host wave for a divergent loop; checking the emitted PSV wave range would guard this boundary against an off-by-one regression.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4720692705 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#discussion_r4720692705). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-27T14:41:08Z. **Code review location:** `crates/victory-shader/src/emit/lower.rs`; line 12428 ~~~~diff @@ -12409,11 +12411,58 @@ impl<'a> Lower<'a> { && let Some(f) = final_of(self, val) { self.vals.insert(phi.value, f); - } + took = true; + } + } + // The wave maximum above is over the host's wave: it stands for + // the console's only in a wave of the console's size. Lanes leave + // a loop at different iterations only through a branch over more + // than uniform values, so only then is the host asked for it (a + // host left to choose may run a wave64 program as wave32, and a + // wave32 one as wave64). A group no larger than the console's + // wave and the host's smallest is one wave at any size. + let wave = if self.x.native.wave64 { 64 } else { 32 }; + let waves = self + .s + .threads + .is_some_and(|t| t.iter().product::<u32>() > wave.min(self.x.target.lanes_min)); ~~~~ --- Could a fixture cover a group size one lane above this threshold alongside the existing one-wave and two-wave cases? `waves` changes at `group_threads > min(console_wave, host_min_wave)`, but the current assertions exercise only 32 and 64 threads. On a host with a 32-lane minimum, a 33-thread group is the first partial-final-wave case that needs an explicit 64-lane host wave for a divergent loop; checking the emitted PSV wave range would guard this boundary against an off-by-one regression.
gut0to commented 2026-11-27 14:41:08 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-27T14:41:08Z.

Review: COMMENTED


AI-assisted static review (ChatGPT); I inspected the threshold and fixtures but did not run tests.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6089786521 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#pullrequestreview-6089786521). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-27T14:41:08Z. **Review:** COMMENTED --- AI-assisted static review (ChatGPT); I inspected the threshold and fixtures but did not run tests.
adrianmjim commented 2026-11-27 14:43:22 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-27T14:43:22Z.

Code review location: crates/victory-shader/src/emit/lower.rs; line 12428

@@ -12409,11 +12411,58 @@ impl<'a> Lower<'a> {
                     && let Some(f) = final_of(self, val)
                 {
                     self.vals.insert(phi.value, f);
-                }
+                    took = true;
+                }
+            }
+            // The wave maximum above is over the host's wave: it stands for
+            // the console's only in a wave of the console's size. Lanes leave
+            // a loop at different iterations only through a branch over more
+            // than uniform values, so only then is the host asked for it (a
+            // host left to choose may run a wave64 program as wave32, and a
+            // wave32 one as wave64). A group no larger than the console's
+            // wave and the host's smallest is one wave at any size.
+            let wave = if self.x.native.wave64 { 64 } else { 32 };
+            let waves = self
+                .s
+                .threads
+                .is_some_and(|t| t.iter().product::<u32>() > wave.min(self.x.target.lanes_min));

Good point: 33 threads on a host with a 32-lane minimum is the first group the rule has to treat as more than one wave, and a PSV wave-range check there would catch an off-by-one. Since this PR targets main, which is no longer the line being developed (work is on a-publier, where the divergent-loop handling is being done in #366), I won't add the fixture here. If this rule is ported to a-publier, that boundary case belongs in its tests.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4720714875 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/110#discussion_r4720714875). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-27T14:43:22Z. **Code review location:** `crates/victory-shader/src/emit/lower.rs`; line 12428 ~~~~diff @@ -12409,11 +12411,58 @@ impl<'a> Lower<'a> { && let Some(f) = final_of(self, val) { self.vals.insert(phi.value, f); - } + took = true; + } + } + // The wave maximum above is over the host's wave: it stands for + // the console's only in a wave of the console's size. Lanes leave + // a loop at different iterations only through a branch over more + // than uniform values, so only then is the host asked for it (a + // host left to choose may run a wave64 program as wave32, and a + // wave32 one as wave64). A group no larger than the console's + // wave and the host's smallest is one wave at any size. + let wave = if self.x.native.wave64 { 64 } else { 32 }; + let waves = self + .s + .threads + .is_some_and(|t| t.iter().product::<u32>() > wave.min(self.x.target.lanes_min)); ~~~~ --- Good point: 33 threads on a host with a 32-lane minimum is the first group the rule has to treat as more than one wave, and a PSV wave-range check there would catch an off-by-one. Since this PR targets `main`, which is no longer the line being developed (work is on `a-publier`, where the divergent-loop handling is being done in #366), I won't add the fixture here. If this rule is ported to `a-publier`, that boundary case belongs in its tests.
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/110:upstream-pr/110'
git switch 'upstream-pr/110'

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/110'
git switch 'upstream-pr/110'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/110'
git switch 'upstream-pr/110'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/110'
git switch 'main'
git merge --squash 'upstream-pr/110'
git switch 'main'
git merge --ff-only 'upstream-pr/110'
git switch 'main'
git merge 'upstream-pr/110'
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
Belobug/VIctory-Belobug-AMD!110
No description provided.