Skip to content

shader: read a scalar number kept in VCC as data, not a lane mask - #645

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
earpjonathan:shader/vcc-scratch-uniform
Nov 28, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
earpjonathan:shader/vcc-scratch-uniform

Conversation

@earpjonathan

@earpjonathan earpjonathan commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Reads a plain number the console compiler keeps in VCC_LO or VCC_HI as data rather than as a lane mask. This lets the whole-wave (literal) wave64 retry translate two compute programs it refused with "literal wave64 halves without uniform group control flow".

The refusal

step_and_cap_with in lower/barriers.rs decides which scalar values are the same in both 32-lane host waves. It took every read of EXEC or VCC as a lane mask, and outside literal mode no lane mask is group-uniform. The console compiler sometimes uses VCC_HI as a spare SGPR: in both programs a first-lane index is shifted into VCC_HI on its way into an s_buffer_load offset, and the loaded dword picks a branch. That branch was taken as divergent, so the blocks after it were not in step and the literal form was refused.

The rule

A value counts as a number, not a mask, when a single 32-bit scalar ALU instruction writes it alone to VCC_LO or VCC_HI (besides SCC), and the structure doesn't know it as a mask (masks, highs, other). It is still group-uniform only when everything it is computed from is. So no lane mask gets through:

  • EXEC on entry, and any phi, is no instruction's write.
  • v_cmp/v_cmpx and other VALU results are never group-uniform, so nothing a scalar op computes from them is either.
  • A saved copy of EXEC or of a compare reads the mask, so the copy is not group-uniform, and nor is a later move of it into VCC. Spills through v_writelane/v_readlane already go by restored.
  • Any 64-bit write of VCC is left out whatever it reads: in wave64 halves VCC_HI is the upper 32 lanes' bits, which differ between the host waves.
  • EXEC is never treated as a number.

Tests

In lower/tests.rs (synthetic programs):

  • A first-lane value through VCC_HI into an s_buffer_load offset, then a branch on the loaded dword: every block is in step in literal halves. This fails without the change.
  • The same with a user-data value: in step in per-lane halves too.
  • A v_cmp mask in VCC, read by a branch on VCC_HI directly or after an SALU op: not in step.
  • s_and_b64 vcc, exec, s[4:5], then s_cmp_lg_u32 vcc_hi, 0 and a branch: not in step.
  • s_mov_b64 s[10:11], exec early, s_mov_b64 vcc, s[10:11] later, then the same compare and branch: not in step.
  • s_mov_b64 vcc from uniform data: not in step (the 32-bit limit). s_mov_b32 vcc_hi from the same data: in step.
  • The hand-encoded words decode to the instructions their comments name.

In halves_tests.rs (Windows):

  • literal_wave64_reads_a_number_in_vcc_hi_as_data: the literal translation accepts the GPU program.
  • literal_wave64_vcc_hi_offset_matches_the_console_on_every_gpu: a 64-thread program reads the structured buffer at (first thread id + 1) × 16 bytes through VCC_HI and branches on the dword. Every lane matches the console.

Checks

  • cargo test -p xtask and cargo xtask policy pass.
  • Clippy with -D warnings is clean on x86_64-pc-windows-gnullvm, for the whole workspace and all targets, with and without --all-features.
  • Native cargo test -p victory-shader: 275 passed, 2 ignored.
  • Under Wine on an M5 Pro, the victory-shader suite passes: 491 passed, 0 failed, 5 ignored, and the other lib target 3 passed, 1 ignored. That includes the new GPU test.
  • Over 39 compute programs captured in game, only the two refused ones change; both now translate. The other 37 give identical output.

In game

A silent scripted opening, with and without this change. The build was main plus several open fixes (#589, #593, #605, #606, #608, #592, #595, #594, #604, #607, #609, #613, #610), plus a local per-host-wave fallback for first-lane programs. That fallback isn't in any PR (reported on #552). Only this commit differs between the two runs:

  • Both programs translate. One of them is bound in the world during the run; the other isn't reached in this stretch.
  • Refused compute programs: 24, against 26 without it.
  • Median world frame time 325 ms against 318 ms (noise). Median world brightness 52.8 against 54.3, with the pictures matching.
  • No hangs, no slow host submissions, no unhandled exceptions.

🤖 Generated with Claude Code

The console compiler sometimes keeps a plain number in VCC_LO or VCC_HI
as a spare SGPR. step_and_cap_with took every read of VCC as a lane mask,
so a branch on such a number was never group-uniform, and the literal
wave64 retry refused programs whose blocks all run in step.

A value one 32-bit scalar ALU instruction writes alone to a VCC dword,
and that the structure does not know as a mask, now counts as data. It
is alike only when everything it is computed from is: EXEC, v_cmp
results, saved copies of either and any 64-bit write of VCC stay out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pragyaangaur
pragyaangaur merged commit 4c15220 into pragyaangaur:main Nov 28, 2026
1 check passed
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.

2 participants