Shaders: v_writelane_b32 writes its lane whenever the wave runs it #139

Open
github-bot wants to merge 2 commits from github-bot/gh-139 into main AGit
Owner

@⁠marketingwithlux on GitHub · 2026-11-24 21:48 UTC · original
marketingwithlux:fix/writelane-outside-exec → main · +174 −2 · 3 files · 2 commits · open

Fixes #111. Found while looking into #62; not yet shown to be its cause.

What was wrong

v_writelane_b32 ignores 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 later v_readlane_b32. unspill hides 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):

  • a guarded lane write asks the wave whether some lane's guard holds (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;
  • two host waves of 32 exchange their answers (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, and emit goes 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):

threads inside expected before now
11..63, lane 0 outside 5 7 5
63, lane 0 outside 5 7 5
none (the wave skips) 7 7 7
lane 0 inside (control) 5 5 5

cargo test --workspace: everything passes except emit::rect::tests::the_rectangle_stage_is_a_geometry_shader and rectangles_are_drawn_whole, which fail the same way on main at 4e17478 (PSV0 validation, #12). cargo clippy -p victory-shader --all-targets is clean.

Not done: help wanted

docs/fork-writelane-outside-exec.md in this branch has the details, written so a person or an agent can pick it up. In short:

  • Not run over a title's shaders (no copy on the machine this was written on). If you have one: VICTORY_HOST_WAVE=32 victory translate --validate before 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.
  • Not run on a 64-lane card. There the change is the waveAnyTrue alone. Running the test above on an AMD card and posting its lines would settle it.
  • Not checked in the game. An A/B of the prison cell would show whether it changes the tiled shadows of #62.
  • Cost: two group barriers per guarded lane write on a 32-lane host, none elsewhere; not measured in a frame.

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

**@⁠marketingwithlux** on GitHub · 2026-11-24 21:48 UTC · [original](https://github.com/fxceless/victory-fork/pull/139) `marketingwithlux:fix/writelane-outside-exec` → `main` · +174 −2 · 3 files · 2 commits · open Fixes #111. Found while looking into #62; not yet shown to be its cause. ## What was wrong `v_writelane_b32` ignores 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 later `v_readlane_b32`. `unspill` hides 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): - a guarded lane write asks the wave whether some lane's guard holds (`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; - two host waves of 32 exchange their answers (`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, and `emit` goes 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): | threads inside | expected | before | now | |---|---|---|---| | 11..63, lane 0 outside | 5 | 7 | 5 | | 63, lane 0 outside | 5 | 7 | 5 | | none (the wave skips) | 7 | 7 | 7 | | lane 0 inside (control) | 5 | 5 | 5 | `cargo test --workspace`: everything passes except `emit::rect::tests::the_rectangle_stage_is_a_geometry_shader` and `rectangles_are_drawn_whole`, which fail the same way on `main` at 4e17478 (PSV0 validation, #12). `cargo clippy -p victory-shader --all-targets` is clean. ## Not done: help wanted `docs/fork-writelane-outside-exec.md` in this branch has the details, written so a person or an agent can pick it up. In short: - **Not run over a title's shaders** (no copy on the machine this was written on). If you have one: `VICTORY_HOST_WAVE=32 victory translate --validate` before 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. - **Not run on a 64-lane card.** There the change is the `waveAnyTrue` alone. Running the test above on an AMD card and posting its lines would settle it. - **Not checked in the game.** An A/B of the prison cell would show whether it changes the tiled shadows of #62. - Cost: two group barriers per guarded lane write on a 32-lane host, none elsewhere; not measured in a frame. 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](https://claude.com/claude-code)
A synthetic wave64 program run on the card: a lane write inside a per-lane
branch whose target lane is not in EXEC is lost in every form, although the
instruction ignores EXEC. The test is ignored until the lowering is fixed;
docs/fork-writelane-outside-exec.md says how to reproduce it and what a fix
must do.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The instruction ignores EXEC, but it was lowered under the guard of the lane
that runs it, so a scalar parked in a lane outside EXEC was lost and came back
stale. A guarded lane write now asks the wave whether some lane's guard holds;
two host waves of 32 exchange their answers, which needs every lane, so a lane
write where not every lane runs is refused as a lane read is and the forms
without skips take over.

The test runs the three cases on the card; it failed before in every form.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:49 +00:00
Author
Owner

@⁠ezbyDev on GitHub · 2026-11-24 22:05 UTC · original

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 -- --nocapture

lane 0 outside (s0 = 10, 62) wave skips (s0 = 63) lane 0 inside (controls) result
this PR, 3c408b4 5, 5 7 5, 5, 7 passes
main 4e17478 + only this PR's test file 7, 7 ("as is", "without skips" and "scalars followed" alike) 7 5, 5, 7 fails, as expected
#119 481569b + only this PR's test file 5, 5 7 5, 5, 7 passes

On 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 --lib on this PR: 211 passed, 0 failed, 2 ignored.
  • #119 overlaps: it also fixes #111, and gives the same values on this test on this card. It may help whoever reviews to compare the two.

Not done here: the VICTORY_HOST_WAVE=32 victory translate --validate comparison 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.

**@⁠ezbyDev** on GitHub · 2026-11-24 22:05 UTC · [original](https://github.com/fxceless/victory-fork/pull/139#issuecomment-7145790609) 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 -- --nocapture` | | lane 0 outside (s0 = 10, 62) | wave skips (s0 = 63) | lane 0 inside (controls) | result | |---|---|---|---|---| | this PR, `3c408b4` | 5, 5 | 7 | 5, 5, 7 | passes | | `main` `4e17478` + only this PR's test file | **7, 7** ("as is", "without skips" and "scalars followed" alike) | 7 | 5, 5, 7 | fails, as expected | | #119 `481569b` + only this PR's test file | 5, 5 | 7 | 5, 5, 7 | passes | On 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 --lib` on this PR: 211 passed, 0 failed, 2 ignored. - **#119 overlaps:** it also fixes #111, and gives the same values on this test on this card. It may help whoever reviews to compare the two. **Not done here:** the `VICTORY_HOST_WAVE=32 victory translate --validate` comparison 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.
Author
Owner

@⁠kaayzouee on GitHub · 2026-11-25 01:27 UTC · original

Duplicate of #119?

**@⁠kaayzouee** on GitHub · 2026-11-25 01:27 UTC · [original](https://github.com/fxceless/victory-fork/pull/139#issuecomment-7149568071) Duplicate of #119?
Author
Owner

@⁠Revens2 on GitHub · 2026-11-25 05:13 UTC · original

Build check only: this PR merges cleanly on main c96b4f2 and 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 breakpoint 0x80000003 at 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 test was not run on the combo, and nothing was checked on the title side of its change. Not verified.

**@⁠Revens2** on GitHub · 2026-11-25 05:13 UTC · [original](https://github.com/fxceless/victory-fork/pull/139#issuecomment-7153565214) Build check only: this PR merges cleanly on main c96b4f2 and 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 breakpoint `0x80000003` at 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 test` was not run on the combo, and nothing was checked on the title side of its change. Not verified.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/wave64_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/139/head:github-bot/gh-139'
git switch 'github-bot/gh-139'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-139'
git switch 'github-bot/gh-139'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-139'
git switch 'github-bot/gh-139'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-139'
git switch 'main'
git merge --squash 'github-bot/gh-139'
git switch 'main'
git merge --ff-only 'github-bot/gh-139'
git switch 'main'
git merge 'github-bot/gh-139'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.