Shaders: v_readlane inside a loop the lanes leave at different iterations reads wrong lanes (wave32 and wave64, every GPU) #225
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#225
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@r4tedx on GitHub · 2026-11-24 01:36 UTC · original
What happens
A
v_readlaneinside a loop that the lanes leave at different iterations is translated wrongly on every GPU tried, both for wave32 and for wave64 programs.On the console a wave runs a loop while any of its lanes does, and
v_readlanereads the lane it names whatever EXEC holds. The translation runs such loops per lane (structurisation turns EXEC into per-lane branches), which loses two things:WaveReadLaneAtof a lane that is no longer active is undefined; here it reads 0.Minimal repro
Hand-assembled GFX10, one wave per group (32 or 64 threads). Lane t runs the loop t times, reading lane L's thread id (L = 20 of 32, 40 of 64) into s9 in each iteration, and then stores t + s9. On the console every lane stores t + L.
A self-contained test (it runs on every hardware adapter, lists each wrong lane, and is
#[ignore]d so the suite stays green) is onr4tedx:repro/loop-lane-read, commit a7f34b7, filecrates/victory-shader/src/emit/lane_read_loop_tests.rs:Results on main (
d2a4bae)The same lanes are wrong on both GPUs: lane 0 stores 0 (it skipped the loop, so s9 stayed 0), and every lane above L stores t (lane L had left the loop when their later iterations read it).
Possible direction
Run such programs as the console does: every lane of the wave through every block, vector instructions guarded by the lane's EXEC bit, and the console's
s_cbranch_*taken wave-wide. Lane reads then see lanes outside EXEC, as on the console. This is now #320 (on top of #233's "console flow"): a compute program withv_readlane/v_writelaneand a branch its lanes take differently runs that way on every host, and this repro is exact for wave32 and wave64 on the RTX 5070 and the Radeon iGPU with it.Not verified against console hardware; the expected values follow the ISA's
v_readlaneand EXEC semantics.AI-assisted; no game assets were used.
🤖 Generated with Claude Code
@r4tedx on GitHub · 2026-11-24 04:30 UTC · original
Status: the fix is in #320 (head
a5ba4a4). A compute program withv_readlane/v_writelaneand a branch its lanes take differently is translated in the console flow on every host, and falls back to the per-lane form only where the console flow cannot lower it.Confirmed by others:
lane_reads_in_a_loop_lanes_leave_at_different_iterations) is exact for wave32 and wave64 on an RTX 5080 and on an AMD Radeon iGPU.mainstops with #320.Not shown: a title program whose picture changes because of this. In compiled shaders these lane reads mostly come from SGPR spill slots, which PRs such as #54 and #309 resolve more cheaply, so the bug may be rare in practice.
No game data used. AI-assisted.
@Marvisak on GitHub · 2026-11-25 01:45 UTC · original
Automated triage for the maintainers.
Confirmed by reading
main: incrates/victory-shader/src/emit/lower.rs,valu_oplowers av_readlane_b32of a non-spill value towaveReadLaneAt(read_lane) inside the structured, per-lane control flow, so a lane that has already left the loop (or never entered it) is not active for the read, and a lane that skipped the loop never gets the scalar the loop set. That matches the wrong lanes listed in the report. The open PR #320 addresses it by running such compute programs in the console flow; the repro test is on the reporter's fork, and #320 is where the fix is under review.Generated by Claude Code