Shaders: a skip on EXEC on entry is left out in the deep form, so one more wave64 compute program runs on 32-lane hosts #577

Open
github-bot wants to merge 4 commits from github-bot/gh-577 into a-publier AGit
Owner

@⁠pr0vId3nce on GitHub · 2026-11-27 12:13 UTC · original
pr0vId3nce:exec-entry-skip → a-publier · +103 −2 · 2 files · 4 commits · open

What was wrong. On a host whose waves are 32 lanes (NVIDIA), a console wave64 compute program that cannot be split into 32-lane halves keeps WaveSize(64), which the card refuses, so its dispatch is dropped every frame. One of the three programs #346 lists as refused every frame (2da4beb386509b77) is one: it saves EXEC on entry (s_mov_b64 s[40:41], exec) and later skips a region with s_and_saveexec_b64 <saved>, s[40:41]. EXEC never holds a lane that EXEC on entry did not (the check assumes the program never sets EXEC wider, as whole-wave code would), so that skip is taken only when no lane is left, and the restore of <saved> at the join leaves no lane either. The console compiler had moved a sampler's constants into the region, and an image sample after the join reads them. The deep "without skips" form (ir::without_skips(p, true)) kept the skip, because a scalar the join reads is changed inside it, so every 32-lane form failed.

The fix. The deep form now leaves such a skip out when every scalar the region changes is read after the join only by image and buffer instructions of the join block, after the block's first instruction restores EXEC from the saved mask and before EXEC changes again. With no lane left those instructions do nothing, so they cannot tell that the region was skipped. A skip on any other mask, a read by an ALU instruction, or a read after EXEC changes again keeps the skip. So does a join whose first instruction sets EXEC without reading the saved mask: Inst::reads lists only registers, so s_mov_b64 exec, -1 reads nothing and would have passed a check that every register it reads is the mask's; the check now also asks for exactly two reads, the mask's two words.

TRANSLATOR_VERSION goes from 2 to 3, since that program's translation changes. My 16-bit halves PR and #479 also take 3; if either is merged first, this becomes 4.

Tests. ir::tests::a_skip_on_exec_on_entry_is_left_out_when_only_the_join_s_memory_reads_its_scalars, in the first commit, fails without the second: the skip is left out in the deep form only, and kept for a skip on VCC, for a read by v_mov, and for a read after EXEC changes. The third commit adds a join that begins with s_mov_b64 exec, -1 instead of the restore, where the skip must be kept; it fails without the fourth commit's two-read guard. cargo test --release -p victory-shader --lib on the RTX 4080: 304 passed, 0 failed (303 on a-publier).

A census at 32 lanes over the title's whole shader pack: exactly one program changes (2da4beb386509b77, 256 threads), and it is now emitted for waves of 32. All 2,682 compute programs validate as before.

Results on an RTX 4080 (NVIDIA, 32-lane waves; Ryzen 9 7900X, 32 GB, Windows 11; diagnostics build, the same checkpoint and scripted input, warm shader cache, Series S, 300 s runs, median of the frame lines from 200 to 295 s):

run 1 run 2 compute pipelines refused
a-publier 226.7 ms 207.5 ms 5
this PR 198.1 ms 210.3 ms 4 (2da4beb386509b77 now runs)

No crash. Frame time is within run-to-run noise. This PR's run 1 was the first with the new translator version (its translations were done before the 200 s window), and a test build was running beside its run 2. The picture changes in the one place I looked: a window now shows a glass pane over what is behind it, where before the glass was missing. I have not compared it with the console.

AMD. No change in what runs. The deep form is only tried for wave64 compute programs on a host whose widest wave is 32 (emit/mod.rs: lower::host_max_wave() == 32), so on RDNA these programs keep running as wave64, as before. The translator version bump makes every host translate its shaders once more.

This touches the same check in ir::without_skips as #345; whichever is merged second needs a small rebase.

🤖 Generated with Claude Code

**@⁠pr0vId3nce** on GitHub · 2026-11-27 12:13 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/577) `pr0vId3nce:exec-entry-skip` → `a-publier` · +103 −2 · 2 files · 4 commits · open **What was wrong.** On a host whose waves are 32 lanes (NVIDIA), a console wave64 compute program that cannot be split into 32-lane halves keeps `WaveSize(64)`, which the card refuses, so its dispatch is dropped every frame. One of the three programs #346 lists as refused every frame (`2da4beb386509b77`) is one: it saves EXEC on entry (`s_mov_b64 s[40:41], exec`) and later skips a region with `s_and_saveexec_b64 <saved>, s[40:41]`. EXEC never holds a lane that EXEC on entry did not (the check assumes the program never sets EXEC wider, as whole-wave code would), so that skip is taken only when no lane is left, and the restore of `<saved>` at the join leaves no lane either. The console compiler had moved a sampler's constants into the region, and an image sample after the join reads them. The deep "without skips" form (`ir::without_skips(p, true)`) kept the skip, because a scalar the join reads is changed inside it, so every 32-lane form failed. **The fix.** The deep form now leaves such a skip out when every scalar the region changes is read after the join only by image and buffer instructions of the join block, after the block's first instruction restores EXEC from the saved mask and before EXEC changes again. With no lane left those instructions do nothing, so they cannot tell that the region was skipped. A skip on any other mask, a read by an ALU instruction, or a read after EXEC changes again keeps the skip. So does a join whose first instruction sets EXEC without reading the saved mask: `Inst::reads` lists only registers, so `s_mov_b64 exec, -1` reads nothing and would have passed a check that every register it reads is the mask's; the check now also asks for exactly two reads, the mask's two words. `TRANSLATOR_VERSION` goes from 2 to 3, since that program's translation changes. My 16-bit halves PR and #479 also take 3; if either is merged first, this becomes 4. **Tests.** `ir::tests::a_skip_on_exec_on_entry_is_left_out_when_only_the_join_s_memory_reads_its_scalars`, in the first commit, fails without the second: the skip is left out in the deep form only, and kept for a skip on VCC, for a read by `v_mov`, and for a read after EXEC changes. The third commit adds a join that begins with `s_mov_b64 exec, -1` instead of the restore, where the skip must be kept; it fails without the fourth commit's two-read guard. `cargo test --release -p victory-shader --lib` on the RTX 4080: 304 passed, 0 failed (303 on a-publier). A census at 32 lanes over the title's whole shader pack: exactly one program changes (`2da4beb386509b77`, 256 threads), and it is now emitted for waves of 32. All 2,682 compute programs validate as before. **Results on an RTX 4080** (NVIDIA, 32-lane waves; Ryzen 9 7900X, 32 GB, Windows 11; diagnostics build, the same checkpoint and scripted input, warm shader cache, Series S, 300 s runs, median of the frame lines from 200 to 295 s): | | run 1 | run 2 | compute pipelines refused | |---|---:|---:|---:| | a-publier | 226.7 ms | 207.5 ms | 5 | | this PR | 198.1 ms | 210.3 ms | 4 (`2da4beb386509b77` now runs) | No crash. Frame time is within run-to-run noise. This PR's run 1 was the first with the new translator version (its translations were done before the 200 s window), and a test build was running beside its run 2. The picture changes in the one place I looked: a window now shows a glass pane over what is behind it, where before the glass was missing. I have not compared it with the console. **AMD.** No change in what runs. The deep form is only tried for wave64 compute programs on a host whose widest wave is 32 (`emit/mod.rs`: `lower::host_max_wave() == 32`), so on RDNA these programs keep running as wave64, as before. The translator version bump makes every host translate its shaders once more. This touches the same check in `ir::without_skips` as #345; whichever is merged second needs a small rebase. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A compute program saves EXEC on entry (s_mov_b64 s[40:41], exec) and later
skips a region with s_and_saveexec_b64 <saved>, s[40:41]. EXEC never holds a
lane EXEC on entry did not, so that skip is taken only with no lane left, and
the restore of <saved> at the join leaves none either. The console compiler
had moved a sampler's constants into such a region, and the sample after the
join read them: the deep "without skips" form kept the skip (a scalar the join
sees changed), every 32-lane form failed, and the program kept WaveSize(64),
which NVIDIA refuses (its dispatch dropped every frame).

The deep form now leaves such a skip out when every scalar the region changes
is read after the join only by image and buffer instructions of the join
block, after its first instruction restores EXEC from the saved mask and
before EXEC changes again.

TRANSLATOR_VERSION is bumped: that program's translation changes.

Census at 32 lanes over the title's whole shader pack: exactly one program
changes (one compute program, 256 threads), now emitted for waves of 32;
all 2,682 compute programs validate as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The join of such a skip must restore EXEC from the mask the skip saved for
the skip to be left out. A join that begins with s_mov_b64 exec, -1 instead
turns lanes on that the skipped region never ran for, and the memory
instructions after it read the scalars the region would have set. That
instruction reads no register (Inst::reads lists registers only), so the
check that every register it reads is one of the saved mask's passes, and
the deep form leaves the skip out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The check that the join of a skip on EXEC on entry restores EXEC from the
saved mask now also asks for exactly two reads (Inst::reads lists each
register dword, so s_mov_b64 exec, s[x:y] reads two). An instruction that
reads no register, such as s_mov_b64 exec, -1, no longer passes it, and
the skip is kept. The title's program this case was made for restores from
the saved pair, so its translation does not change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:22:27 +00:00
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 13:02 UTC · original · reviewed

AI-assisted review. I checked the EXEC-mask proof and left one question about the invariant the optimization relies on.

**@⁠gut0to** on GitHub · 2026-11-27 13:02 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/577#pullrequestreview-6088547627) · **reviewed** AI-assisted review. I checked the EXEC-mask proof and left one question about the invariant the optimization relies on.
@ -864,0 +875,4 @@
&& i.name() == "s_and_saveexec_b64"
&& mask.len() == 2
&& mask.iter().all(|m| entry.contains(m)))
.then(|| i.writes.iter().filter(|(r, _)| matches!(r, Reg::S(_)) && !is_exec(r)).map(|x| x.1).collect())
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 13:02 UTC · original

AI-assisted review: This optimization is sound only if EXEC cannot contain lanes outside the saved entry mask at this point. The comment states that invariant, but this predicate only checks the s_and_saveexec operand; it does not appear to rule out an earlier write that widens EXEC (for example, restoring or setting it to all ones). Could you enforce/prove the invariant over the path or add a regression with EXEC widened before this skip? If such a state is possible, the skip could be removed while lanes are still active.

**@⁠gut0to** on GitHub · 2026-11-27 13:02 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/577#discussion_r4719709073) AI-assisted review: This optimization is sound only if EXEC cannot contain lanes outside the saved entry mask at this point. The comment states that invariant, but this predicate only checks the s_and_saveexec operand; it does not appear to rule out an earlier write that widens EXEC (for example, restoring or setting it to all ones). Could you enforce/prove the invariant over the path or add a regression with EXEC widened before this skip? If such a state is possible, the skip could be removed while lanes are still active.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 15:56 UTC · original

Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At b5e1ab0: victory-shader 304 passed, 0 failed, 4 ignored.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 15:56 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/577#issuecomment-7222657647) Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At `b5e1ab0`: `victory-shader` 304 passed, 0 failed, 4 ignored. AI-assisted (Claude Code); no game data.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/577/head:github-bot/gh-577'
git switch 'github-bot/gh-577'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-577'
git switch 'github-bot/gh-577'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-577'
git switch 'github-bot/gh-577'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-577'
git switch 'a-publier'
git merge --squash 'github-bot/gh-577'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-577'
git switch 'a-publier'
git merge 'github-bot/gh-577'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.