Skip to content

Shaders: a lane mask spilled to a VGPR lane is still that mask - #1074

Closed
undeadhuman37 wants to merge 2 commits into
Marvisak:mainfrom
undeadhuman37:fix/mask-spill
Closed

undeadhuman37 wants to merge 2 commits into
Marvisak:mainfrom
undeadhuman37:fix/mask-spill

Conversation

@undeadhuman37

Copy link
Copy Markdown

The console compiler spills scalars, lane-mask pairs among them, with v_writelane_b32 into constant lanes of a VGPR and restores them with v_readlane_b32 of the same lane. The restored pair was an opaque mask, so selects, EXEC writes and joins that used it refused ("a select on an untracked mask", "an opaque lane mask", "a lane-mask join of an untracked mask").

structure now follows a constant-lane readlane back through a plain chain of writelanes to the scalar written to that lane, and gives the restored pair that scalar pair's mask. A chain with a phi or another write of the VGPR stays opaque (shortcut noted in code).

Stacked: this branch contains the commit of the lane-mask-join PR (shares its test helper), so it should merge after that one.

Measured offline over the shader corpus (26148 programs), against the first commit alone:

  • vertex/pixel programs emitted: 12250 -> 12269; compute: 1443 -> 1452
  • "a lane-mask join of an untracked mask": 20 -> 0
  • "an opaque lane mask": 29 -> 8
  • "a conditional export": 8 -> 0

Tests: a synthetic pixel program fails to lower before and lowers after. cargo clippy -p victory-shader --all-targets -- -D warnings is clean. Not run on a GPU, hence draft.

No game data. AI-assisted: written with Claude Code (Claude Sonnet 5.5).

🤖 Generated with Claude Code

undeadhuman37 and others added 2 commits November 24, 2026 18:27
…d vertex programs

A register can hold a compare result's high dword on one path and a loaded
number on another; the compiler only reads it where the number is live. The
join's mask side was "a lane mask read as data", which refused the program.
A pixel or vertex program now takes the mask's ballot as that incoming value
(counts and zero tests mean the same on any wave size). shortcut: the ballot
is the host wave's, so a join read some other way would differ from the console.

Offline corpus: "a lane mask read as data" 250 -> 212, vertex/pixel programs
emitted 12243 -> 12250; the other 31 move on to descriptor/scalar-memory
refusals. Synthetic wave64 pixel program fails before, lowers after.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The console compiler spills scalars, lane-mask pairs among them, with
v_writelane_b32 into constant lanes of a VGPR and restores them with
v_readlane_b32 of the same lane. The restored pair was an opaque mask, so
the selects, EXEC writes and joins that used it refused ("a select on an
untracked mask", "an opaque lane mask", "a lane-mask join of an untracked
mask"). structure now follows a constant-lane readlane back through a plain
chain of writelanes to the scalar written to that lane, and gives the
restored pair that scalar pair's mask. A chain with a phi or another write
of the VGPR stays opaque (shortcut noted in code).

Offline corpus, against fix/mask-phi-ballot (neither branch carries Marvisak#585):
vertex/pixel programs emitted 12250 -> 12269, compute 1443 -> 1452,
"a lane-mask join of an untracked mask" 20 -> 0, "an opaque lane mask"
29 -> 8, "a conditional export" 8 -> 0. Synthetic pixel program fails
before, lowers after. Stacked on fix/mask-phi-ballot (shares its test helper).

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

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:

  • cargo test -p victory-shader: 122 passed, 0 failed, 1 ignored (all hardware + WARP VALU/waterfall/diff tests green on RTX 5090 and WARP)
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok

Clean lane-mask spill tracking across VGPR lanes, verified on Blackwell hardware and WARP. Approving.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Draft noted — this carries the same emit/lower.rs ballot fallback as #1073 plus the structure.rs spilled() chain analysis (straight-line v_writelane_b32/v_readlane_b32 pairs with a constant lane, capped at 64 hops, phi/other writes end the search conservatively). The two tests cover both the scalar-join case and the spilled-mask case, and both run on macOS.

Same caveats as #1073, plus one specific to spilled(): the lane constant is decoded as Operand::Const(128..=192) (lane = c-128), which matches the console spill encoding, but a non-constant lane (v_readlane_b32 with a variable lane) returns None and the mask stays opaque — safe, but it means the optimization silently doesn't apply there; a test with a variable lane asserting the refusal (rather than the success path) would document that boundary. Also the 64-hop cap: a longer spill chain silently stops tracking; fine as a shortcut, worth a comment in the code.

Verified locally: test-merge with main clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 98 passed / 0 failed / 1 ignored.

@LooperSalty

Copy link
Copy Markdown

From a tester working with Claude (AI-assisted); measured on my own machine (i7-13700KF, RTX 4070 Super). No game data involved.

We carry the same fix independently (this PR, #298 and our local commit all follow a v_readlane_b32 of a constant lane back to the v_writelane_b32 that wrote it), so I am not opening another PR. Our version resolves the restored pair inside structure.rs's mask lookup, using the same spill map the resource tracer already builds (spilled_sgprs), with a cycle guard for joins through the spill; one test (a_mask_spilled_to_a_vgpr_lane_is_the_mask_read_back, fails without it).

Measured offline over the translation corpus on an integration tree (with other open PRs merged), before/after this one change:

  • vertex/pixel emitted 13327 -> 13358, compute 2107 -> 2198, mesh 8373 -> 8420 (+169 programs)
  • refusals "a lane-mask join of an untracked mask" 167 -> 43
  • RaytracingResolve (standard_rdp variant) now emits and validates with dxil.dll

If useful, I can post the exact diff or test as a comment here.

KainanP added a commit to KainanP/VIctory that referenced this pull request Nov 24, 2026
…d masks

`sgpr_spill::tests::a_spilled_mask_holding_lanes_elsewhere_is_used_as_a_mask_again`
asserts that, without Marvisak#309's forwarding, the else-mask spilled to a VGPR lane is
refused ("a lane mask holding lanes elsewhere read as data"). On the bundle stack the
same words translate without forwarding (the stack already follows a lane mask
spilled to a VGPR lane, the idiom of Marvisak#1074), so the assertion fails with `Ok(())`.

Integration-only change: the control now accepts either outcome without forwarding
and still requires forwarding to translate. It records an overlap: for this idiom
Marvisak#309 adds nothing on top of the bundle; its measured gain (+125 vs its merge base,
Marvisak#1247) has not been re-measured on the stack.
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Draft. A mask restored from a VGPR lane is that mask in main (structure.rs restored, with a test of the same name). Same as #298.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
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.

5 participants