Shaders: v_writelane_b32 is dropped when its lane is outside EXEC (failing test on a branch) #111
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/fxceless--victory-fork#111
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?
@marketingwithlux on GitHub · 2026-11-24 21:34 UTC · original
Branch with the failing test and this write-up: https://github.com/marketingwithlux/victory-fork/tree/repro/writelane-outside-exec (one commit on top of
mainat4e17478;docs/fork-writelane-outside-exec.md). Found while looking into #62.Nothing from the game is attached; the test program is synthetic. AI-assisted (Claude Code).
Status: reproduced, not fixed. Written so that a person or a coding agent can pick it up.
What is wrong
On the console
v_writelane_b32 vN, sX, Kwrites lane K whatever EXEC is. The translatorlowers it as an ordinary vector write, under the guard of the lane that runs it
(
crates/victory-shader/src/emit/lower.rs, the"v_writelane_b32"arm, thenwrite_placed). So when lane K is outside EXEC, or does not reach the block, the write islost and a later
v_readlane_b32 sY, vN, Kgives the old value.The compiler uses this pair to park scalars in VGPR lanes.
ir::unspill(
crates/victory-shader/src/ir.rs) turns the pairs into scalar moves, but only for a VGPRwhose every use is such a pair with a constant lane. A VGPR with any other use keeps its
lane writes, and those are the ones affected.
Reproduce
The test is in
crates/victory-shader/src/emit/wave64_tests.rs. It needs a hardware devicewith shader model 6.6; without one it prints
not runand passes, which is not a result.On Windows 10 the in-box D3D12 stops at 6.5 (PR #69 adds the newer runtime).
Program: one console wave of 64,
if (t > s0) { v_writelane_b32 v9, s6, 0 }with s6 = 5 andv9 = 7 before, then every thread stores
v_readlane_b32of lane 0.The same in all three forms: as is,
ir::without_skips(p, false),ir::without_skips(p, true).The control with lane 0 inside (
t < s0) gives 5 and 7 as it should."Expected" is the instruction's documented behaviour (it ignores EXEC), which
unspillalready relies on. It has not been measured on a console.
What a fix must do
Lane K takes the scalar exactly when the console wave executes the instruction:
s_cbranch_execzskip): do not write. Making the writeunconditional breaks the
s0 = 63row in the forms without skips.Two ways, cheapest first:
unspilltake a parking VGPR that has other uses when theparked lanes' live ranges do not overlap those uses. No cost per frame, and the program
may then not need 64-lane waves at all.
two host waves an exchange, which costs group barriers). Only where 1 cannot apply.
Done when
#[ignore]on a 32-lane card and on a 64-lane one;cargo test --workspacepasses;victory translate --validateover a title's shaders translates no fewer programs than before.Not known yet
Whether this is what makes the 14
CS_ShadowRenderTiled*programs wrong in the "withoutskips, scalars followed" form (issue #62). To check:
VICTORY_HOST_WAVE=32 VICTORY_WAVE_WHY=1 victory translate --listand see whether those programs namev_writelane/v_readlane.Ruled out for #62: a loop running to the loop limit inside a region whose skip was left
out. A conditional back edge leaves the loop at the limit and the program goes on.
github-bot referenced this issue2026-11-26 03:36:27 +00:00
github-bot referenced this issue2026-11-26 03:38:42 +00:00
@kappalegoat on GitHub · 2026-11-25 01:57 UTC · original
The three open PRs for this issue, against its reproduction test, on an RTX 5070. None of them makes the test pass: all three refuse the program instead of writing the lane.
I took
a_lane_write_reaches_its_lane_outside_execfrom @marketingwithlux's branch (repro/writelane-outside-exec), without its#[ignore], and appended it towave64_tests.rson each head. RTX 5070 (Blackwell, driver 621.24), Windows 11,cargo test -p victory-shader --locked --no-fail-fast:victory-shadermain2119b0eUnsupported { offset: 56, what: "a lane written or read where not every lane runs" }"a lane write where not every lane runs""a lane write where not every lane runs"So each PR turns the silent wrong value into a refusal for this program (the console's one wave of 64, the write inside
if (t > s0)). That is safer thanmain, but the program then does not run at all, which for the shadow programs of #62 means they are dropped rather than fixed. Whichever is merged, the reproduction test would still need the lowering that writes lane K whatever EXEC is.The three PRs also conflict with each other pairwise (
git merge-tree); #219 is on currentmain, #139 and #119 are 2 commits behind and merge cleanly with it.No game files used; the test program is synthetic. AI-assisted (Claude Code).
@kappalegoat on GitHub · 2026-11-25 01:59 UTC · original
The three open PRs for this issue, against its reproduction test, on an RTX 5070. None of them makes the test pass: all three refuse the program instead of writing the lane.
I took
a_lane_write_reaches_its_lane_outside_execfrom @marketingwithlux's branch (repro/writelane-outside-exec), without its#[ignore], and appended it towave64_tests.rson each head. RTX 5070 (Blackwell, driver 621.24), Windows 11,cargo test -p victory-shader --locked --no-fail-fast:victory-shadermain2119b0eUnsupported { offset: 56, what: "a lane written or read where not every lane runs" }"a lane write where not every lane runs""a lane write where not every lane runs"So each PR turns the silent wrong value into a refusal for this program (the console's one wave of 64, the write inside
if (t > s0)). That is safer thanmain, but the program then does not run at all, which for the shadow programs of #62 means they are dropped rather than fixed. Whichever is merged, the reproduction test would still need the lowering that writes lane K whatever EXEC is.The three PRs also conflict with each other pairwise (
git merge-tree); #219 is on currentmain, #139 and #119 are 2 commits behind and merge cleanly with it.No game files used; the test program is synthetic. AI-assisted (Claude Code).
@pr0vId3nce on GitHub · 2026-11-25 14:57 UTC · original
A native measurement of what this issue takes as documented behaviour, and the PR runs from kappalegoat's table, repeated on two more GPUs.
What RDNA2 does. I ran
v_writelane_b32 v9, s6, 0(and lane 33 in wave64) on a Ryzen 7900X's gfx1036 iGPU, assembled and launched through the AMD driver's ownamd_comgr_2.dllandamdhip64_6.dll, with v9 = 7, s6 = 5 and four EXEC values: lanes 11 and up, only the last lane, lanes 0-9, and EXEC = 0. In all eight cases (wave32 and wave64) the named lane becomes 5 and no other lane changes. So the write ignores EXEC entirely, even an empty EXEC. The expected column here (5, 5, 7) holds because the test program branches around the write withs_cbranch_execz.kappalegoat's table holds here too, on an RTX 4080 and on the gfx1036 iGPU (main
0b0074e, #119481569b, #1393c408b4, #219ad4022f; the test from6a274bcappended without its#[ignore]). main fails with 7 for s0 = 10 and 62 in all three forms. Each PR fails with the refusal. The refusal comes from the test's last part, the lane-0-inside control, which lowers the form with the skip throughlowered(...).expect("lower"). In the loop above it, the test prints the same refusal for "as is" and moves on, and on every PR head both forms without the skip give 5, 5, 7.The refusal also doesn't drop the program. "... where not every lane runs" is the refusal
emit()answers by retrying with the skips left out. I passed the issue's program throughsuper::emitfor a 32-lane host, which is how a title's program gets translated. It translates on all three PRs and gives 5, 5, 7 on both GPUs. On main it translates and gives 7, 7, 7. So for this program the PRs fix the value. What fails is the issue test's control. Each PR's own copy of the test keeps the name and passes: #139 and #219 move the control to the form without the skip, and #119 goes throughemit().One case the three share. All three write when some lane of the console wave is in EXEC (#219 notes the gap: "a wave that walks on with EXEC empty and no skip writes too"). With this issue's program and the
s_cbranch_execzreplaced bys_nop, #119 on both GPUs gives 5 with threads 11 and up inside. With no thread inside it gives 7, where the hardware writes 5. I have not run that variant on #139 or #219. Whether any title program reaches a lane write with EXEC empty and no skip, I can't tell (no game data here).Synthetic programs only. AI-assisted (Claude Code).
@studiostephe on GitHub · 2026-11-26 01:48 UTC · original
A lowering that writes the lane whatever EXEC is, checked against the reproduction test.
Against
mainat44bff61b. AI-assisted (Claude Code).What the patch does
lower.rs, thev_writelane_b32arm. The current lowering is a plain vector write under theinstruction's guard (
select(is_lane_K, a, old)). On the console the write ignores EXEC: lane Ktakes the scalar whenever some lane of the console wave runs the instruction, even with K outside
EXEC. The plain write loses that.
The patch re-issues the write where the guard does not cover lane K's own host lane:
lane_write(guard_raw, lane, a, plain): when the guard is not the whole wave (and there-issue is safe: no exchange, and for
localhalves only whenlocal_anyholds), it findsthe FIRST HOST LANE IN EXEC (
waveActiveBallot+ a first-bit-low on the two 32-bit halves,the same idiom
first_lanealready uses), reads the scalar from that lane(
waveReadLaneAt), and returnsselect(is_lane_K, r, plain). The re-issued read runswhenever any lane runs the instruction, so lane K's host lane gets
athere; everywhereelse the plain result is kept.
guard_raw(the BDD guard from the structure) is threadedvalu()->valu_op(); thev_writelane_b32arm uses it to decide whether the re-issue is needed.The "do not write when no lane of the wave runs the instruction" half of the issue's
specification falls out for free: when EXEC is empty at the instruction, no host lane is in
EXEC, so the re-issue reads nothing and the plain write does not happen either. I checked
the
s0 = 63row by reading the emitted shape rather than running it (below).The test file change appends the issue's own reproduction test
(
a_lane_write_reaches_its_lane_outside_exec, from the branch in the issue) towave64_tests.rswithout its#[ignore], so it runs on a machine with a card.Verified
Mac (M1),
main44bff61b, Rust 1.98.1, no Windows:cargo test -p victory-shader --lib --locked: 172 passed, 0 failed, 2 ignored(171 before; the +1 is a CPU-side lowering test, below).
cargo check -p victory-shader --lib --profile test --locked --target x86_64-pc-windows-msvc:clean, so the appended
wave64_tests.rstest compiles where it runs.cpu_side_lane_write_reissue_is_emitted(inlower.rs, no card needed):a
v_writelane_b32under a per-lane EXEC narrowing emits the re-issue(
waveReadLaneAtcount >= 1); the same write with EXEC not narrowed emits none (count == 0).lane_writeto returnNonemakes that test fail; restoring thepatch makes it pass.
Not verified (no Windows here)
wave64_tests.rs, which isgated to a Windows host with shader model 6.6, and this machine has no Windows and no
dxil.dll. The table in the issue (s0 = 10/62/63, the three forms, the control) is the thing
to run:
cargo test -p victory-shader --lib a_lane_write_reaches_its_lane_outside_exec -- --nocapture.empty and no skip writes 7 where the hardware writes 5 (the
s_nopvariant). This patchhas the same behaviour in that variant: with no lane in EXEC, the re-issue's ballot is
empty and the plain write's EXEC is empty too, so nothing is written. I am stating that from
the emitted shape, not from a run.
Diff:
qwen3.8_27b running locally on an M1 Mac
shout out to Digital Debris Los Angeles