Shaders: a divergent loop's scalars read after it ask for the console wave size (#2's RDNA2 wave-size failures) #110
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!110
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-110"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@alexdeliu on GitHub · 2026-11-25 14:20 UTC · original
alexdeliu:fix/rdna2-wave64-scalar-loops→main· +193 −4 · 2 files · 2 commits · openWhat
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 awaveActiveOpmaximum 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_loopsuses such a value, setswave_size = Some(64)only when all of these hold:target.runs(64));splitand the console-lanes rules are unchanged);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 --libon the RX 9070. There are 85 wave64 compute lowerings for a host that runs 64 lanes:WaveSize(64)x.native.wave64 && x.target.runs(64), from #2)select_tests, 6 insgpr_spilltests)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 thePSV0wave range: 64/64 for the divergent counted loop, and none for the same counter in a loop with a uniforms_cbranch_scc1exit. It fails on71652a2(gets no range).The two #2 tests,
--test-threads=1:71652a2VICTORY_ADAPTER=radeon(tm)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):71652a2Not covered
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.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
@Adika713 on GitHub · 2026-11-25 15:32 UTC · original
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
a7054b1into a detached worktree and used an isolatedCARGO_TARGET_DIRfor each tree (
_agent_tmp\target-shader-main-verifyand_agent_tmp\target-pr110-verify, underF:\VIctory-Belobug-AMD). Reusing onetarget dir across main and a worktree can silently run a stale test binary.
Before, at
upstream/main01aadd193d57e71fb4d57810eb2fdd1bc95c950b, fromF:\VIctory-Belobug-AMD:test result: FAILED. 25 passed; 2 failed; 0 ignored; 0 measured; 245 filtered out.test result: FAILED. 264 passed; 2 failed; 6 ignored; 0 measured; 0 filtered out.emit::valu_tests::scalar_counted_in_a_divergent_loop_read_after_itand
emit::valu_tests::scalar_counted_in_nested_divergent_loops.After, at PR head
a7054b1, from a detached worktree atF:\VIctory-Belobug-AMD\_agent_tmp\pr-110: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).test result: ok. 267 passed; 0 failed; 6 ignored; 0 measured; 0 filtered out.CPU-only wave-range regression test.
Overlap: I also ran the focused valu command on PR #92 head
7a592eb(thebroader wave64 rule); it also passes:
27 passed; 0 failed; 0 ignored; 0 measured; 246 filtered out, with the doc-test line0 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out. I did not run #92's full lib. I wroteno 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 on GitHub · 2026-11-25 16:01 UTC · original
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.
WaveSize(64)for every wave64 compute program on a 64-lane host.leave_loopstakes a divergent loop's scalars with a wave maximum. That is the step whose result depends on the host's wave width.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 on GitHub · 2026-11-25 16:35 UTC · original
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 (mainat01aadd1: 266 passed). Workspace tests only; not run in the title.@adrianmjim on GitHub · 2026-11-25 17:24 UTC · original
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 andscalars_read_after_a_divergent_loop_ask_for_the_console_wave_size. The two #2 tests also pass here without the PR (on71652a2).WaveSizeas 64-lane waves, and this includes console wave32 programs. I checked it with a local probe that storesv_readfirstlane_b32of 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
_b32mask 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_exitconditions:target.lanes_min): such a group is one wave at any size the host picks.WaveSize(64)for wave64 groups of 32 threads or fewer, which this PR sets.Target::ANY(lanes_min 4) the wave64 result is unchanged for groups larger than 4 threads.scalar_counted_in_a_wave32_divergent_loop_read_after_itneeds 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_sizeneeds 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=1with 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:01aadd1)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:
WaveSize(64)to CS_ShadowTileBalanceRTCost_03da1e4a and CS_AutoHighbeamAmbientLightCalc_756e19e7.WaveSize(32)to CS_SurfacePrimitivesOptimized_12e6e205.The description also says
join_scalarsmay depend on the host wave. On the 7900 XT it does, and so doesv_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:
WaveSizetests; I have not run it.--validateonly).I can share the follow-up as a branch or as a diff, whichever you prefer.
@alexdeliu on GitHub · 2026-11-25 17:41 UTC · original
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.rpfcounts are the best measure of this PR's reach:WaveSizechanges 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:On
join_scalarsandv_readfirstlane_b32in 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 on GitHub · 2026-11-25 18:42 UTC · original
Here it is: https://github.com/adrianmjim/VIctory-Belobug-AMD/tree/wave32-scalar-loops-follow-up
One commit,
c20a5d0, directly ona7054b1(this PR's head), so it fast-forwardsfix/rdna2-wave64-scalar-loops. It touchesemit/lower.rs(the rule) andemit/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
mainand would carry #110's commit as well, which seems harder to review than one PR.Agreed on keeping
join_scalarsandv_readfirstlane_b32for a separate change.@MamaLeVrai on GitHub · 2026-11-26 00:05 UTC · original
Result on an RX 6950 XT (RDNA2, the card of #2), Windows 11 build 26300, Rust 1.98.1. This PR (
a7054b1) merged onmain4f62c2a,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).victory-gpuandvictory-hleare unchanged againstmain. 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 on GitHub · 2026-11-26 00:06 UTC · original
@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 into4f62c2awithout 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:
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, anda_group_of_several_host_waves_asks_for_the_console_wave_size, which needs none.cargo test -p victory-shader --libwith and without it would show whether it changes anything on a card that runs undeclared compute as wave32.@alexdeliu on GitHub · 2026-11-26 00:25 UTC · original
@adrianmjim, I've added your follow-up to this PR as you asked: commit
c20a5d0, with you as its author, fast-forwarded on top ofa7054b1. I ran it on the three adapters you didn't have: your tests alone ona7054b1(before), then your whole commit (after),--test-threads=1,VICTORY_DXIL= dxil.dll 1.8.2502.11.scalar_counted_in_a_divergent_loop_read_after_itscalar_counted_in_nested_divergent_loopsscalar_counted_in_a_wave32_divergent_loop_read_after_ita_group_of_several_host_waves_asks_for_the_console_wave_sizeThe 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 --libwith the follow-up:WaveSizetests.cargo clippy -p victory-shader --all-targets: no new warnings.@adrianmjim on GitHub · 2026-11-26 01:36 UTC · original
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
WaveSizetests.@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 on GitHub · 2026-11-26 05:29 UTC · original
@adrianmjim here is the discrete RDNA2 run of the current head
c20a5d0, merged ontomain4f62c2a. Machine: RX 6950 XT, Windows 11 build 26300, Rust 1.98.1.victory-shaderlib, release: 280 passed, 0 failed, 6 ignored. Of three runs, the other two died without a result line. This test binary does that here onmainas well (2 of 10 runs; #140 stops it).--test-threads=1: all pass.scalar_counted_in_a_divergent_loop_read_after_it: okscalar_counted_in_a_wave32_divergent_loop_read_after_it: okscalar_counted_in_nested_divergent_loops: okOn
mainthe first and third fail on every run on this card.AI-assisted (Claude Code); no game data.
@adrianmjim on GitHub · 2026-11-26 05:30 UTC · original
Thanks @MamaLeVrai. With alexdeliu's runs,
c20a5d0is 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 expectedWaveSizerefusal. The other two runs dying without a result line fits #140's case, not this change.@gut0to on GitHub · 2026-11-27 14:41 UTC · original · reviewed
AI-assisted static review (ChatGPT); I inspected the threshold and fixtures but did not run tests.
@ -12414,0 +12425,4 @@let waves = self.s.threads.is_some_and(|t| t.iter().product::<u32>() > wave.min(self.x.target.lanes_min));@gut0to on GitHub · 2026-11-27 14:41 UTC · original
Could a fixture cover a group size one lane above this threshold alongside the existing one-wave and two-wave cases?
waveschanges atgroup_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.@ -12414,0 +12425,4 @@let waves = self.s.threads.is_some_and(|t| t.iter().product::<u32>() > wave.min(self.x.target.lanes_min));@adrianmjim on GitHub · 2026-11-27 14:43 UTC · original
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 ona-publier, where the divergent-loop handling is being done in #366), I won't add the fixture here. If this rule is ported toa-publier, that boundary case belongs in its tests.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.