Shaders: v_writelane_b32 writes its lane whenever the wave runs it #139
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/139"
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 fxceless/victory-fork. Originally posted by marketingwithlux on 2026-11-24T21:48:15Z.
Fixes #111. Found while looking into #62; not yet shown to be its cause.
What was wrong
v_writelane_b32ignores EXEC on the console, but it was lowered under the guard of the lane that runs it. A scalar the compiler parks in a lane that is outside EXEC was lost and came back stale from the laterv_readlane_b32.unspillhides this for a VGPR used for parking alone; a parking VGPR with any other use keeps its lane writes.The change
crates/victory-shader/src/emit/lower.rs, the"v_writelane_b32"arm (28 lines):waveAnyTrue) and is written without the guard, so a wave with no lane in EXEC still writes nothing, as when the console takes the skip;exchange_halves). That needs every lane, so a lane write in a block not every lane runs is refused with "a lane write where not every lane runs", as a lane read already is, andemitgoes on to the forms without skips.Tests
a_lane_write_reaches_its_lane_outside_exec(synthetic GFX10 words), run on an RTX 3090 (32-lane waves, Windows 10 with the runtime from #69):cargo test --workspace: everything passes exceptemit::rect::tests::the_rectangle_stage_is_a_geometry_shaderandrectangles_are_drawn_whole, which fail the same way onmainat4e17478(PSV0 validation, #12).cargo clippy -p victory-shader --all-targetsis clean.Not done: help wanted
docs/fork-writelane-outside-exec.mdin this branch has the details, written so a person or an agent can pick it up. In short:VICTORY_HOST_WAVE=32 victory translate --validatebefore and after, and compare the translated and validated counts. A program that newly stops with "a lane write where not every lane runs" in every form is a regression; please report its name.waveAnyTruealone. Running the test above on an AMD card and posting its lines would settle it.The expected values are the instruction's documented behaviour, not a console measurement. Nothing from the game is attached. AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from fxceless/victory-fork. Originally posted by ezbyDev on 2026-11-24T22:05:30Z.
The 64-lane run asked for in the description: passes on AMD, and the test catches the bug there.
Setup: AMD Radeon RX 9060 XT 16 GB (RDNA4, native 64-lane waves), Adrenalin 32.0.32029.2010; i7-9700K; Windows 11 Pro 26300; Rust 1.98.1 (pinned); DXC from the Windows SDK 10.0.26100.
cargo test -p victory-shader --lib a_lane_write_reaches_its_lane_outside_exec -- --nocapture3c408b4main4e17478+ only this PR's test file481569b+ only this PR's test fileOn this PR the "as is" form prints no lines, so it is refused and the forms without skips run, as the description says.
cargo test -p victory-shader --libon this PR: 211 passed, 0 failed, 2 ignored.Not done here: the
VICTORY_HOST_WAVE=32 victory translate --validatecomparison over a title's shaders and the prison cell A/B (#62). Both need the title's files, so they're for whoever has them; on a 64-lane card the first would only cover the 32-lane host path anyway.AI-assisted (Claude Code, Claude Opus 5.5): ran the tests on my machine and wrote this.
Imported from fxceless/victory-fork. Originally posted by kaayzouee on 2026-11-25T01:27:31Z.
Duplicate of #119?
Imported from fxceless/victory-fork. Originally posted by Revens2 on 2026-11-25T05:13:30Z.
Build check only: this PR merges cleanly on main
c96b4f2and the integration build of eight PRs (#115 #66 #36 #144 #147 #141 #139 #130) compiles (diagnostics profile). In the game, that combo was run alone 3 times (900 s,VICTORY_RELAY=2, scripted input): one run to the end (median 4.95 fps, about 4.9k draws per frame, against 4.84-5.04 fps on main), one title breakpoint0x80000003at about 157 s after a failed dstorage request (the pattern is explained on #115), one device removed (0x887A0005) at about 160 s that did not repeat in the two other runs. Nothing is proven for this PR alone: it was not run on its own,cargo testwas not run on the combo, and nothing was checked on the title side of its change. Not verified.Imported from fxceless/victory-fork. Originally posted by Lyrnc on 2026-11-27T00:46:18Z.
Tested this on an RTX 5080 against hardware rows from a Radeon (gfx1036) that runs the same kernels natively in wave64 and wave32. #119 and this PR gave the same value in every lane of every case below.
Setup
mainat52ac4ecwith this branch merged locally. No conflict inlower.rs; the test file conflicted only because both sides appended at its end, so both were kept.writelane_branch/<lane>/<mask>(a lane write inside ans_and_saveexec/s_cbranch_execzbranch, then a read back after the join). Also 45 more wave64 lane-write cases and 33 wave32 ones: no skip, early-out, a loop whose lanes leave, a small lane array, a read inside the branch, nested branches, and a lane in an SGPR.super::emitwith a 32-lane host forced, every form it tries,dxil.dllvalidation, then dispatched on the 5080. Wide on =with_wave_wide(true); wide off = the default.Results (exact / differ; nothing was refused)
writelane_branchcases whose lane is outside the branch (0/hi32,0/lane40,33/lo32,33/alt,33/lane40,63/lo32,63/alt,63/lane40). They now go through "without skips". No other case changed value.a_lane_write_reaches_its_lane_outside_execpasses on the 5080: 5, 5, 7 in both forms without skips, and the control with lane 0 inside gives 5, 5, 7.A regression: a lane write in nested branches is now silently zero
if (lane bit of mask) { if (lane < 48) { v_writelane_b32 v50, s38, K } }(v50 = 0x1234, s38 = 0x777):wl_nested/0/alt(lane 0 inside)wl_nested/0/hi32wl_nested/63/hi32,63/altAll four translate as they are, with no refusal. The refusal comes from an instruction without a side effect, so
Lower::inst(lower.rs:5051 on main) only records v50 as having no value. v50 is read after two joins. The inner join is read only by the outer one, and outsideVICTORY_STRICT_JOINS(lower.rs:11550) such a join takes the missing value as zero (lower.rs:11662).emitnever sees the refusal. WithVICTORY_STRICT_JOINS=1all four are exact with the same change (#119's binary, which gives the same values as this one: wave64 lane-write set 39 / 6). A fix is to make the refusal immediate for the lane write: inLower::inst,v_writelane_b32whose error satisfiesneeds_every_lanereturnsErr(unsupported(offset, why)). I measured that on top of #219, where it makes the four exact.What else still differs
s_and_saveexec_b64to no lane, thenv_writelane_b32, nos_cbranch_execz). The gfx1036 writes the lane (lanes 0 and 33: 0x777). The PR askswaveAnyTrueof the guard and keeps 0x1234 (wl_noskip/0/none,wl_noskip/33/none). The comment "a wave with none took the skip around it" is right only where there was a skip. Where no skip was left out, the write needs no condition and no exchange.wl_loop/*: exact with wide on, approximate local forms with wide off.None of the 8 refused wave64 game programs keeps a
v_writelane_b32afterspill::build(ir::unspillturns all their parking writes into scalar moves), so this does not touch them.AI use: Claude Code (Claude Opus 5.5) wrote the kernels and the harness, ran the hardware oracle and the translator, and drafted this comment; the numbers come from those runs.
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.