Repository navigation
fix(shader): know the SCC a waterfall loop's exit leaves for a mask select - #608
Conversation
…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>
|
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,
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. |
|
@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:
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. |
|
@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:
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 |
Two wave32 compute programs,
82a2ad6d07417d36and90a0692af4320129, 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:
s_andn2_wrexectakes the lanes it served out of the pending mask, writes the rest to EXEC, and sets SCC to whether any lanes remain.s_cbranch_execnz.s_cselectof EXEC or 0. It ORs the result with a compare's lane mask, and av_cndmaskthen 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
execnzedge 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 ans_cbranch_execz/execnzon that same EXEC (over a chain of single predecessors), thes_cselecttakes 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 withs_bcnt1_i32_b64and 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
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.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 xtaskandcargo xtask policypass (299 files ok).x86_64-pc-windows-gnullvm --workspace --all-targets -- -D warnings, with and without--all-features.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:d1609d9d. No panic or device-removed lines.82a2ad6d59 → 0,90a0692a9 → 0.d1609d9dd1609d9d.🤖 Generated with Claude Code