Skip to content

fix(shader): know the SCC a waterfall loop's exit leaves for a mask select - #608

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
earpjonathan:shader/lane-mask-data
Nov 28, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
earpjonathan:shader/lane-mask-data

Conversation

@earpjonathan

Copy link
Copy Markdown
Contributor

Two wave32 compute programs, 82a2ad6d07417d36 and 90a0692af4320129, were refused with "a lane mask read as data". Halves are not involved: both are wave32 with groups of 32 threads.

What the programs do

The refused instructions sit after a waterfall loop:

  1. The loop's last s_andn2_wrexec takes the lanes it served out of the pending mask, writes the rest to EXEC, and sets SCC to whether any lanes remain.
  2. The loop goes round again on s_cbranch_execnz.
  3. After the loop, the console compiler selects a lane mask on that SCC: s_cselect of EXEC or 0. It ORs the result with a compare's lane mask, and a v_cndmask then picks values by it.

The structure pass took that SCC as a uniform scalar. Lowering can't produce it from the loop's vote, so the mask counted as read as data.

Why the translation can be exact

The loop is left only through the execnz edge taken when EXEC is 0, so on the console SCC is always 0 where the select reads it. The select gives 0, and the mask is just the compare's.

The change

This lives in structure.rs, with nothing specific to 32-lane hosts. Take an SCC set by a lane-mask operation that writes EXEC, where SCC means "the new EXEC has a lane". If it is read in a block reached only through an s_cbranch_execz/execnz on that same EXEC (over a chain of single predecessors), the s_cselect takes the side that edge implies. Anywhere else the SCC stays a uniform value, as before.

Not covered

Two wave64 "(wave64 on a 32-lane host)" lane-mask refusals (466ec41d3f9d24c0, abd7a22106898c66) are a different pattern. They count a wave64 compare's lanes with s_bcnt1_i32_b64 and branch on whether any is set, which needs a count across the two 32-lane halves. This change leaves them to the halves work.

Tests

  • A new synthetic program in halves_tests.rs: a wave32 waterfall over the low two bits of the thread id, then that select OR-ed with "lane below 20". The test checks that the program is the instructions its comments name, and that it translates. Without this change it is refused.
  • The same program on the host GPU: 0 lanes differ from the console. If SCC were taken as 1, every lane would get the other value.
  • WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b" tools/macos/test-wine.sh -p victory-shader --no-fail-fast: 484 passed, 0 failed, 5 ignored.
  • cargo test -p xtask and cargo xtask policy pass (299 files ok).
  • Clippy is clean for x86_64-pc-windows-gnullvm --workspace --all-targets -- -D warnings, with and without --all-features.
  • Offline translation of 39 dumped compute programs with the runtime's Wine options: the two above now translate, and the other 37 translate byte-for-byte as on d1609d9d.

In game

Setup: M5 Pro, 48 GB, macOS 27.0.1, CrossOver 26.3 Wine with the repo's patches, D3DMetal 4.0 beta 3, Series X. A scripted opening was run cold then warm, with audio off. Figures are from the warm runs, against plain d1609d9d:

  • Both programs translate, and 36 compute programs are refused, against 38 on d1609d9d. No panic or device-removed lines.
  • Dropped-dispatch reports ("dropped N/frame without a host pipeline") over the run: 82a2ad6d 59 → 0, 90a0692a 9 → 0.
  • Frame time:
Build Median frame Prep GPU Late frames
d1609d9d 378 ms 140 ms 209 ms 369 ms
this branch, repeat 389 ms 148 ms 198 ms 371 ms
this branch, first run 435 ms 175 ms 217 ms 476 ms
  • The first run of this branch measured 435 ms. The repeat didn't reproduce that and lands within run-to-run spread of d1609d9d.

🤖 Generated with Claude Code

…elect

After a waterfall loop the console compiler can select a lane mask on the
SCC the loop's last `s_andn2_wrexec` left (`s_cselect` of EXEC or 0, then
OR-ed with a compare). The structure took that SCC as a uniform value,
which lowering cannot make from the loop's vote, so the program was
refused as "a lane mask read as data".

That SCC is whether the new EXEC has a lane, and the block is reached only
through the edge of an `s_cbranch_execz`/`execnz` on that same EXEC: the
edge shows the console's SCC. Where an EXEC-writing lane-mask operation's
SCC is read in a block reached only through such an edge (over a chain of
single predecessors), the select now takes the side that edge gives.

Test: a wave32 waterfall followed by that select, checked against the
console on the host GPU.

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

Copy link
Copy Markdown
Contributor

Tested this on an M3 Max (48 GB, CrossOver 26.1, Series X 1.0.2.1) together with #589, #605 and #606, all merged on d1609d9. One 720 s run into the prison cell, VICTORY_GPU_TIMING=0, cold cache.

Side observation on d1609d9 itself, also in an earlier run without these four: world frames switch between two steady levels, about 400 ms with 14 submissions per frame and about 720 ms with about 19.5. I haven't found what triggers the slow one yet.

@earpjonathan

Copy link
Copy Markdown
Contributor Author

@4TheDoctor About the two frame-time levels: I saw the same kind of switch on an M5 Pro. Here it follows the draw count much more than the submissions.

In two warm runs of this branch on the same scripted opening, the first switched to about 450–730 ms frames about 3.5 minutes in, and the repeat stayed at about 340–400 ms. Matching the host's 5-second report lines by time from world entry:

Time from world entry Run Draws a frame Frame Prep GPU Submissions
236–264 s slow 6,400–7,450 610–730 ms 250–290 ms 230–260 ms 15.0
236–264 s repeat 4,250–5,700 340–450 ms 130–160 ms 145–220 ms 14.1–15.2
269–342 s slow 5,250–5,900 450–600 ms 230–330 ms 167–186 ms 15.0
269–342 s repeat 3,690–3,990 334–391 ms 143–200 ms 122–144 ms 13.9–14.0

In the later stretch, the slow run costs about the same per draw (prep about 0.045 ms per draw against 0.049, GPU 0.032 against 0.033). So there it's mostly more being drawn: the scripted camera ends up somewhere else. In the 236–264 s stretch, prep per draw was also higher (about 0.040 against 0.028), and that part I can't explain from these numbers. On my runs the submissions were about 14–15 in both stretches. They reached 17–20 only around 100–180 s, at similar frame times in both runs. So I couldn't reproduce your 14 against 19.5 split. If you log draws per frame next to it, that would show whether yours is the same thing.

Prepared with Claude Code.

@4TheDoctor

Copy link
Copy Markdown
Contributor

@earpjonathan Thanks, good call on the draws. On the M3 Max it's not the same thing: the draw count is flat across both levels. From the host's 5-second report lines, 420 s onward, split at under 500 ms and over 600 ms:

Run Level Lines Frame Prep GPU Draws a frame
d1609d9 + #589 + #605 + #606 + #608 fast 41 401 ms 184 ms 177 ms 4,920
same slow 9 715 ms 130 ms 559 ms 5,000
d1609d9 + #589 (earlier run) fast 12 405 ms 188 ms 184 ms 5,000
same slow 36 733 ms 139 ms 564 ms 5,018

So here the slow level is about 380 ms more on the GPU line (0.036 against 0.112 ms per draw) with the same draws and a bit less prep. With VICTORY_GPU_TIMING=0 that line is submit-and-wait time, not pure GPU work. CS_VisHair (b6df66af105d8b2d, #610) is bound from world entry in both runs, so it's my first suspect. A run with VICTORY_LOOP_ENTRY_EXIT=1 should tell.

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.

3 participants