Skip to content

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

Open
marketingwithlux wants to merge 2 commits into
fxceless:mainfrom
marketingwithlux:fix/writelane-outside-exec
Open

marketingwithlux wants to merge 2 commits into
fxceless:mainfrom
marketingwithlux:fix/writelane-outside-exec

Conversation

@marketingwithlux

Copy link
Copy Markdown

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 RTX 4080: the 14 CS_ShadowRenderTiled* programs look wrong in the deep-skips wave64 form (missing ceiling, dark room); loop limit 32 smears hair #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 and others added 2 commits November 24, 2026 21:32
…C (known failure, ignored)

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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@ezbyDev

ezbyDev commented Nov 24, 2026

Copy link
Copy Markdown

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.

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.

@kaayzouee

Copy link
Copy Markdown

Duplicate of #119?

@Revens2

Revens2 commented Nov 25, 2026

Copy link
Copy Markdown

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.

oceansde012 pushed a commit to oceansde012/victory-gta6 that referenced this pull request Nov 25, 2026
… writes its lane whenever the wave runs it (by marketingwithlux)
nullexxx pushed a commit to nullexxx/victory-fork that referenced this pull request Nov 25, 2026
* Shaders: reuse SSA sums when tracing memory addresses

Co-Authored-By: GPT 6.2 Sol <noreply@openai.com>

* Shader tests: an address from no root parameter is title memory

Main reads such an address as title memory instead of refusing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: GPT 6.2 Sol <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
deynesdev referenced this pull request in deynesdev/Protonida Nov 26, 2026
…ranslate --warm

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: v_writelane_b32 is dropped when its lane is outside EXEC (failing test on a branch)

4 participants