Shaders: a scalar a per-lane branch writes is the wave's after the join (#3562) #3593
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3593"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T19:41:03Z.
Fixes #3562.
What was wrong
On the console a scalar register is one value per wave. Where some lanes of a wave take a branch and the rest skip it (
s_and_saveexec_b64+s_cbranch_execz), the wave runs the branch, and every lane reads what the branch left after the join (s_or_b64 exec). The per-lane form gives each lane the value along its own edge, so the lanes that skipped the branch kept the old value. Av_readlane, a whole-wave reduction's result (s_or_saveexec_b64 -1…v_readlane_b32 sN, v, 0) or any scalar written under a lane branch was lost to them.The change (
emit/lower/joins.rs, hooked in after a block's phis)At a per-lane join (
!uniform_join(b)), each SGPR phi takes, in every lane, the value of a lane that came from the latest predecessor (in code order) that any lane came from. That's the path the console's wave ran last. Per lane: the predecessor's rank (ani32phi),WaveActiveMaxof it,WaveActiveMinof the lane index among the lanes with that rank, thenWaveReadLaneAtfor each scalar phi.It applies only:
console_lanes:WaveSizeat the console's width, so one host wave holds one console wave). Mesh programs and programs translated without console lanes are unchanged;break_loopgot worse without this guard, and is unchanged with it;st.masks/st.highs) or EXEC.lower.rsgrows by 789 bytes (521,352, under the policy limit).Measured
@Lyrnc's 151 hand-written GFX10 wave64 cases (gist), each compared lane by lane with the same code run natively on a gfx1036. RX 5700 XT (RDNA1), native
WaveSize(64):mainexactred_branch(reduction in a branch)red_earlyoutred_nestedreadlane_branchNo case is worse, and wrong output words go from 5,025 to 2,712. Still open:
firstlane_branch: that program has no console lanes, so the host's wave may group lanes differently and the change leaves it alone;readlane_branchcases: they also differ inside the branch (a lane read of a lane outside EXEC), which this change doesn't cover;Test
synthetic_tests::a_scalar_a_lane_branch_writes_is_the_waves_after_the_join(throughrun_permute_cs, wave64):s38 = 0x5555, lanes 40-63 runv_readlane_b32 s38, v0, 45, then every lane storess38.0x5555.main: lanes 0-39 store0x5555.WaveSize(64)there and is skipped, as in the other wave64 permute tests.Checks
cargo test -p victory-shader --lib --features host, RX 5700 XT: 303 passed, 0 failed, 3 ignored.VICTORY_WARP=1: 299 passed, 4 failed. Those are the same 4synthetic_teststhat fail onmainalone with this machine's system WARP.cargo clippy -p victory-shader --all-targets --all-features -- -D warnings: clean.cargo xtask policy: ok.Not tested: NVIDIA. On
mainthis code path needsWaveSize(64), which 32-lane hosts refuse; on them it matters through #2633-style halves. Also not tested: other AMD generations, and the title.AI use: Claude Code (Claude Opus 5.5).
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T13:11:30Z.
I replayed your #3562 regression on app-local WARP 1.0.22 with D3D12 Agility 1.620.2. This WARP version created the WaveSize(64) pipeline and executed the dispatches. Results matched with the D3D12 debug layer off and on.
63bcca4, with only your test copied over, lanes 0-39 still wrote0x5555and lanes 40-63 wrote45.86630f4, all 64 lanes wrote45when the branch ran. All 64 kept0x5555in the empty-branch control. Neither run skipped the pipeline.The full shader suite on
86630f4had 299 passes, four failures, and three ignored in both debug settings. The same four tests also failed on main: the gather, two permute tests, and the edge-flagged triangle test. Main without the debug layer had one additional permute failure that did not recur in the focused synthetic suite.This verifies the synthetic wave64 case on WARP. The RX 5700 XT results above remain the hardware evidence. AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T15:59:24Z.
First RDNA3 run: AMD Radeon 780M (RDNA3, gfx1103), Windows 11, head
86630f4.63bcca4+ this PR's test): fails on the hardware adapter. Lanes 0-39 read 21845, lanes 40-63 read 45; expected 45 in every lane.victory-shader+victory-gpu --features diagnostics): 552 passed.So the defect reproduces on RDNA3 as on RDNA1.
AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T16:38:11Z.
NVIDIA row for this PR: on a 32-lane card the PR's test runs nothing. The RTX 3070 and this machine's WARP both refuse the
WaveSize(64)pipeline, so the test passes with main's code too. A temporary wave32 copy of the same case does run on the 3070. It reproduces the defect on main, and the PR fixes it.RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head
86630f4on main63bcca4(one commit, clean).cargo test --locked -p victory-shader --lib -- a_scalar_a_lane_branch_writes_is_the_waves_after_the_join --nocapture: 1 passed, 0 failed, 0 ignored, in 3 of 3 runs, and again in 3 of 3 runs withVICTORY_WARP=1, where every device is WARP. But nothing ran: for both iterations of every run, the test printedhardware: no pipeline for a wave of 64; skippedandwarp: no pipeline for a wave of 64; skipped. Thev_readlane_b32sets console lanes, so the shader asks for the console's 64 lanes. This driver refuses that at pipeline creation, and so does this machine's system WARP. That matches the description's note on 32-lane hosts.Negative control: main's
emit/lower.rs, withemit/lower/joins.rsremoved.git diff --stat HEAD: 2 files, 126 deletions.git diff --stat 63bcca4: onlysynthetic_tests.rs, 24 insertions. Result: 1 passed, 0 failed, in 3 of 3 runs on hardware and 3 of 3 withVICTORY_WARP=1, with the same two skip lines. The control passes on this card. On NVIDIA the PR's test cannot tell main from the fix.To exercise the change on this card anyway, I made a temporary wave32 copy of the case. It uses
s_and_saveexec_b32 s34, vcc_loands_or_b32 exec_lo, exec_lo, s34, and lanes 20-31 runv_readlane_b32 s38, v0, 25. A second iteration withfrom31 puts no lane in the branch. I also added one temporaryeprintln!of the readback inrun_permute_cs, then restored the file. Command:cargo test --locked -p victory-shader --lib -- temp_wave32_scalar_a_lane_branch_writes a_scalar_a_lane_branch_writes_is_the_waves_after_the_join --nocapture --test-threads=1.0x5555. It passed.0x5555(21845) and lanes 20-31 read 25, where 25 is expected in every lane. That is the same pattern as the description's wave64 result on main (lanes 0-390x5555) and kilolimaVI's 780M (lanes 0-39 21845).WaveSize(32)(warp: no pipeline for a wave of 32; skipped), so the wave32 copy has no WARP result. UnderVICTORY_WARP=1the copy hitsrun_permute_cs'sassert!(warp || wave64)(hardware: no pipeline for a wave of 32) with both the PR's and main's code. That comes from the test helper, not from the PR.So a 32-lane host does take the new path through wave32 console programs, and not only through #2633-style halves:
wave_scalarsneeds onlyconsole_lanes, not wave64. A wave32 copy of the test would give 32-lane hardware a check that fails on main.cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index:63bcca4: 298 passed, 3 failed, 3 ignored.The 3 failures are the same on both:
stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardware. The skipped test crashes the binary on this card (open issue #2571).The PR does not touch
victory-gpu, so I did not run its lib suite.NVIDIA-specific: no wave64 at all, so the PR's own test is a no-op on NVIDIA. With the console's 32 lanes, the 3070 shows the defect on main and the fix with the PR.
Not tested:
WaveSize(64)pipeline; this machine's system WARP does not.break_loop), nested and early-out reductions, and Lyrnc's 151 cases;AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T16:55:11Z.
I added a wave32 regression on top of
86630f4, following @upipibi's RTX 3070 report. It is available as test commit1dbf4f4.On app-local WARP 1.0.22 with Agility 1.620.2, main
63bcca4with the same test left0x5555in lanes 0–19. At the PR head plus the test, all 32 lanes received 25 when the branch ran, and all 32 kept0x5555when no lane took it. The original wave64 case also passed. Both sizes executed with the D3D12 debug layer off and on. Strict shader Clippy in both configurations and the asset policy passed.The test helper now treats explicitly forced WARP as software when a fixed-wave pipeline is unavailable. @kilolimaVI, the commit is ready to cherry-pick. @upipibi, the filter on the RTX 3070 is
wave32_shares_the_scalar_written_by_a_lane_branch.Please retain the Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit. AI-assisted with OpenAI Codex.Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T16:59:51Z.
@andrewpozdnakov7-jpg your wave32 test
1dbf4f4runs on the RTX 3070 (616.56, debug), and it tells the PR from main:cargo test --locked -p victory-shader --lib -- wave32_shares_the_scalar_written_by_a_lane_branch --nocapture, 3 runs each:86630f4+1dbf4f4, hardware: 1 passed, 0 failed, 0 ignored. The 3070 runs both iterations. This machine's system WARP refusesWaveSize(32)(warp: no pipeline for a wave of 32; skipped).emit/lower.rsand withoutemit/lower/joins.rs(git diff --stat 63bcca4: onlysynthetic_tests.rs): 0 passed, 1 failed.hardware, left lanes 0-1921845and lanes 20-3125, right all25.VICTORY_WARP=1, on both trees: 1 passed, but with the system WARP both legs printno pipeline for a wave of 32; skipped, so nothing runs there. Yourforced_warpchange does stop theassert!that used to fire.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T17:11:47Z.
@andrewpozdnakov7-jpg @upipibi Thanks. I added the wave32 test
1dbf4f4to this branch as-is, a fast-forward that keeps andrew's authorship. The head is now1dbf4f4.RX 5700 XT (Navi 10, RDNA1, 32 and 64 lanes, driver 32.0.21045.29003, Windows 11 26200), 3 runs each. This card runs both wave sizes, so both cases ran on hardware. System WARP refuses both (
no pipeline for a wave of 32/64; skipped).wave32_shares_the_scalar_written_by_a_lane_brancha_scalar_a_lane_branch_writes_is_the_waves_after_the_join(wave64)1dbf4f4with main'semit/lower.rs, withoutemit/lower/joins.rs)21845, lanes 20-312521845, lanes 40-63451dbf4f4)Full
victory-shader --lib --features hostat1dbf4f4: 304 passed, 0 failed, 3 ignored.With the 780M (RDNA3), the RTX 3070 and WARP 1.0.22, the defect now reproduces and is fixed on RDNA1, RDNA3 and NVIDIA, at both wave sizes.
AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T19:40:58Z.
@andrewpozdnakov7-jpg RDNA3 wave32 row for
1dbf4f4: Radeon 780M (gfx1103, runs both wave sizes), Windows 11.wave32_shares_the_scalar_written_by_a_lane_brancha_scalar_a_lane_branch_writes_is_the_waves_after_the_join(wave64)lower.rs, withoutjoins.rs1dbf4f4System WARP skips both sizes, as for the others. Full suite (
victory-shader+victory-gpu --features diagnostics): 553 passed.Same lanes as the RTX 3070 and RDNA1, so with ColorMeBoom's table every wave size on every family here reproduces it on main and passes with the PR.
AI-assisted (Claude).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.