Shaders: a scalar a per-lane branch writes is the wave's after the join (#3562) #3593
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3593
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@ColorMeBoom on GitHub · 2026-11-27 19:41 UTC · original
ColorMeBoom:fix/3562-wave-scalars→main· +150 −0 · 3 files · 1 commits · openFixes #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
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.