Recompiler: fix the EXEC bounds of the pixel-shader subset check #3798

Open
CharlyRien wants to merge 2 commits from upstream-pr/3798 into main
CharlyRien commented 2026-12-03 16:48:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T16:48:11Z.


Stacked on #3591: only the top commit (eb352ba1) belongs here; until #3591 is merged, the diff shows its commit too. It was the first commit of #3785 and is split out as asked in #3785's review: it changes the compare forms of every direct pixel shader on every adapter, not only the NVIDIA path #3785 is about. #3785 is now stacked on this PR, because its rule follows the bounds fixed here.

What is in it

Recompiler: fix the EXEC bounds of the pixel-shader subset check: recomp/ps_masks.rs (about 40 changed lines of code, 96 lines of tests) and TRANSLATOR_VERSION 12 → 13 in dxil/kernel.rs.

ps_masks::subset_after follows the SGPRs known to be a subset of the live lanes (the entry EXEC): their helper-lane bits are 0. forms uses it to pick each pixel-shader compare's mask form (#2083): the cheap local form (WaveActiveBallot(c) | own bit) where nothing reads another helper lane's bit or the mask is known to be such a subset, the per-quad rebuild (Lw::ballot_ps_quad) otherwise. forms also uses it to mark a branch region that widens EXEC, and run to decide whether the SCC of an EXEC write is exact. Four of its EXEC bounds were wrong:

  • in wave64 it took EXEC as bounded when only its bit 126 (EXEC_LO) was, so a 32-bit write of EXEC_HI from an unknown SGPR passed. subset_after, forms (a region of a branch on the mask that sets EXEC that way was not marked as widening it) and run (the SCC of such an EXEC write was taken as exact) now require all of EXEC's bits;
  • in wave64 a 32-bit saveexec or wrexec bounded both halves of EXEC, though it writes EXEC_LO alone, and a 32-bit SALU kept a bound between registers of either parity: s_mov_b32 s23, exec_lo then s_mov_b64 exec, s[22:23] passed lanes 0..31's bits off as lanes 32..63's. A register is bounded by the half of EXEC its parity names (64-bit operands are even pairs), so a 32-bit SALU now keeps a bound only between registers of one parity and bounds EXEC_LO alone, and a 64-bit operand at an odd register code bounds nothing;
  • a saveexec whose SDST is EXEC (SDST = EXEC, EXEC = op(S0, EXEC)) bounded EXEC through its SDST even when op widens it (s_nand_saveexec_b64 exec, 0). The ISA does not say which of the two writes EXEC keeps, so it now bounds neither;
  • S_ANDN1_WREXEC (EXEC = SDST = ~S0 & EXEC) was bounded by its S1, which SOP1 does not have, so never: it is now bounded by EXEC like the saveexecs.

The first three only remove bounds: they can only keep more compares in the per-quad form and mark more regions as widening EXEC. The last one adds a bound, in wave32 too. With a wrong bound, a compare under such an EXEC could take the local form while another helper lane's bit of its mask was still read, for example by s_cbranch_vccz or by an s_cselect on the SCC (the shapes in the tests below).

Where it runs: forms runs for every direct pixel shader on every adapter (dxil/kernel.rs, outside the ps_skip_run_through() check), so XCL_PS_SKIP_RUN_THROUGH does not turn this off. At this commit #3591's flat_skips does not call subset_after. ps_masks.rs is in neither the translator nor the direct DXIL source hash, hence the TRANSLATOR_VERSION bump.

Why #3785 needs it: #3785 runs a skip through when every EXEC write in the skipped region keeps EXEC a subset of its entry EXEC, and it follows that bound with subset_after. With the old bounds, a write of EXEC_HI from an unknown SGPR, the parity swap above or s_nand_saveexec_b64 exec, 0 would count as bounded, and the region would run with EXEC not 0.

Tests (CPU, ps_masks.rs):

  • exec_bounds_masks_only_when_both_wave64_halves_are_bounded: a saveexec, a compare and s_andn1_wrexec bound their SDST (and EXEC) when all of EXEC is bounded, and nothing when only EXEC_LO is; in wave32, bit 126 is all of EXEC;
  • a_wave64_exec_half_set_from_an_unknown_mask_is_not_bounded: a branch region that sets EXEC_HI from an unknown SGPR keeps the compare in the per-quad form, and so does an s_cselect on the SCC of such an EXEC write;
  • a_saveexec_into_exec_bounds_neither_write: s_nand_saveexec and s_or_saveexec into EXEC, in wave64 and wave32;
  • a_wave64_32_bit_salu_bounds_only_what_it_writes: the parity rule for moves and a 32-bit saveexec, a 64-bit operand at an odd code, and programs where a compare under such an EXEC is read by s_cbranch_vccz: per-quad form when EXEC_HI comes from an unknown SGPR or from EXEC_LO, local form when each half comes from its own half.

Tested

  • RTX 3090 24 GB (driver 621.47, Resizable BAR off), Ryzen 9 5950X, 32 GB, Windows 11 22631, Rust 1.100.0, DXC 1.9.2602.17.
  • CPU, release, on this head (eb352ba1): gpu::recomp::ps_masks + gpu::recomp::lane_masks: passed, 0 failed (36 tests, run together with the GPU tests of the next line), the four tests above among them.
  • GPU, release, with XCL_REQUIRE_GPU=mesh: #3591's tests and the pixel-shader mask / helper-lane GPU tests (gpu_direct_ps_masks_hold_helper_lanes_on_triangle_edges, gpu_direct_ps_readfirstlane_and_mask_live_on_triangle_edges, gpu_ps_masks_hold_helper_lanes_on_triangle_edges, gpu_wave32_pixel_carry_preserves_adjacent_mask_at_triangle_edges, gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k), run together with the CPU tests above: 36 passed without the switch, 36 passed with XCL_PS_SKIP_RUN_THROUGH=1; gpu::dxil: 355 passed, 4 ignored, 0 failed; one SKIPPED: no wave64, expected on this card.
  • Release build of this head with its named tests, without and with XCL_PS_SKIP_RUN_THROUGH=1: built; the 8 named tests passed in each pass (0 failed), no SKIPPED line.
  • A CPU probe translated the 119 programs of my #3591 sweep (117 pixel shaders and 2 compute shaders of the retail title) at #3591's head f4413ddb and at this head, and compared their direct DXIL byte for byte: with XCL_PS_SKIP_RUN_THROUGH=0 (every adapter but NVIDIA) 119 of 119 the same, with =1 (NVIDIA's default) 119 of 119 the same. So on these programs the fix changes no translation.

Regression run
scripts/smoke.ps1, 60 s each, the same title, the same machine and driver (621.47), a fresh shader cache on both sides; main first, then this head:

xcl-smoke v1
commit: 16c2fd082ae2e96967a2ab553bc2e1032e491f70
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 488 (PresentX 488)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 16164 MB
xcl-smoke v1
commit: eb352ba151782c584286f209f93e1db94063f46a
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 439 (PresentX 439)
presents per 2 s (last 3): 61 60 61
device removals: 0
crashes: 0
peak commit: 15570 MB

Frames 439 / 488 (90 %), peak commit 15,570 / 16,164 MB (96 %), no device removal, no crash.

Not tested

  • AMD and Intel GPUs. forms runs on every adapter, so this commit reaches them; the CPU comparison above with =0 is the path they take, but nothing was run on an AMD or Intel GPU.
  • Other NVIDIA cards and drivers.
  • A drawn pixel shader whose compare form this commit changes: the tests of the fix are CPU tests of subset_after and forms; the GPU tests above check that the existing shapes still draw right.
  • A game run beyond the 60 s smoke above.

AI use

  • AI use: Claude Code (Claude Opus 5.5) wrote the fix and its tests, had them reviewed by a second Claude Code agent and by Antigravity (gemini-4-neon-high), fixed what the reviews found, ran the tests, the CPU comparison and the smoke run, and wrote this description; checked and posted by me.
<!-- greyfinch-sync:ivall/xcl:issue:5630913907 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3798). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-12-03T16:48:11Z. --- Stacked on #3591: only the top commit (`eb352ba1`) belongs here; until #3591 is merged, the diff shows its commit too. It was the first commit of #3785 and is split out as asked in #3785's review: it changes the compare forms of every direct pixel shader on every adapter, not only the NVIDIA path #3785 is about. #3785 is now stacked on this PR, because its rule follows the bounds fixed here. **What is in it** `Recompiler: fix the EXEC bounds of the pixel-shader subset check`: `recomp/ps_masks.rs` (about 40 changed lines of code, 96 lines of tests) and `TRANSLATOR_VERSION` 12 → 13 in `dxil/kernel.rs`. `ps_masks::subset_after` follows the SGPRs known to be a subset of the live lanes (the entry EXEC): their helper-lane bits are 0. `forms` uses it to pick each pixel-shader compare's mask form (#2083): the cheap local form (`WaveActiveBallot(c) | own bit`) where nothing reads another helper lane's bit or the mask is known to be such a subset, the per-quad rebuild (`Lw::ballot_ps_quad`) otherwise. `forms` also uses it to mark a branch region that widens EXEC, and `run` to decide whether the SCC of an EXEC write is exact. Four of its EXEC bounds were wrong: - in wave64 it took EXEC as bounded when only its bit 126 (EXEC_LO) was, so a 32-bit write of EXEC_HI from an unknown SGPR passed. `subset_after`, `forms` (a region of a branch on the mask that sets EXEC that way was not marked as widening it) and `run` (the SCC of such an EXEC write was taken as exact) now require all of EXEC's bits; - in wave64 a 32-bit saveexec or wrexec bounded both halves of EXEC, though it writes EXEC_LO alone, and a 32-bit SALU kept a bound between registers of either parity: `s_mov_b32 s23, exec_lo` then `s_mov_b64 exec, s[22:23]` passed lanes 0..31's bits off as lanes 32..63's. A register is bounded by the half of EXEC its parity names (64-bit operands are even pairs), so a 32-bit SALU now keeps a bound only between registers of one parity and bounds EXEC_LO alone, and a 64-bit operand at an odd register code bounds nothing; - a saveexec whose SDST is EXEC (SDST = EXEC, EXEC = op(S0, EXEC)) bounded EXEC through its SDST even when op widens it (`s_nand_saveexec_b64 exec, 0`). The ISA does not say which of the two writes EXEC keeps, so it now bounds neither; - `S_ANDN1_WREXEC` (EXEC = SDST = ~S0 & EXEC) was bounded by its S1, which SOP1 does not have, so never: it is now bounded by EXEC like the saveexecs. The first three only remove bounds: they can only keep more compares in the per-quad form and mark more regions as widening EXEC. The last one adds a bound, in wave32 too. With a wrong bound, a compare under such an EXEC could take the local form while another helper lane's bit of its mask was still read, for example by `s_cbranch_vccz` or by an `s_cselect` on the SCC (the shapes in the tests below). Where it runs: `forms` runs for every direct pixel shader on every adapter (`dxil/kernel.rs`, outside the `ps_skip_run_through()` check), so `XCL_PS_SKIP_RUN_THROUGH` does not turn this off. At this commit #3591's `flat_skips` does not call `subset_after`. `ps_masks.rs` is in neither the translator nor the direct DXIL source hash, hence the `TRANSLATOR_VERSION` bump. Why #3785 needs it: #3785 runs a skip through when every EXEC write in the skipped region keeps EXEC a subset of its entry EXEC, and it follows that bound with `subset_after`. With the old bounds, a write of EXEC_HI from an unknown SGPR, the parity swap above or `s_nand_saveexec_b64 exec, 0` would count as bounded, and the region would run with EXEC not 0. Tests (CPU, `ps_masks.rs`): - `exec_bounds_masks_only_when_both_wave64_halves_are_bounded`: a saveexec, a compare and `s_andn1_wrexec` bound their SDST (and EXEC) when all of EXEC is bounded, and nothing when only EXEC_LO is; in wave32, bit 126 is all of EXEC; - `a_wave64_exec_half_set_from_an_unknown_mask_is_not_bounded`: a branch region that sets EXEC_HI from an unknown SGPR keeps the compare in the per-quad form, and so does an `s_cselect` on the SCC of such an EXEC write; - `a_saveexec_into_exec_bounds_neither_write`: `s_nand_saveexec` and `s_or_saveexec` into EXEC, in wave64 and wave32; - `a_wave64_32_bit_salu_bounds_only_what_it_writes`: the parity rule for moves and a 32-bit saveexec, a 64-bit operand at an odd code, and programs where a compare under such an EXEC is read by `s_cbranch_vccz`: per-quad form when EXEC_HI comes from an unknown SGPR or from EXEC_LO, local form when each half comes from its own half. **Tested** - RTX 3090 24 GB (driver 621.47, Resizable BAR off), Ryzen 9 5950X, 32 GB, Windows 11 22631, Rust 1.100.0, DXC 1.9.2602.17. - CPU, release, on this head (`eb352ba1`): `gpu::recomp::ps_masks` + `gpu::recomp::lane_masks`: passed, 0 failed (36 tests, run together with the GPU tests of the next line), the four tests above among them. - GPU, release, with `XCL_REQUIRE_GPU=mesh`: #3591's tests and the pixel-shader mask / helper-lane GPU tests (`gpu_direct_ps_masks_hold_helper_lanes_on_triangle_edges`, `gpu_direct_ps_readfirstlane_and_mask_live_on_triangle_edges`, `gpu_ps_masks_hold_helper_lanes_on_triangle_edges`, `gpu_wave32_pixel_carry_preserves_adjacent_mask_at_triangle_edges`, `gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k`), run together with the CPU tests above: 36 passed without the switch, 36 passed with `XCL_PS_SKIP_RUN_THROUGH=1`; `gpu::dxil`: 355 passed, 4 ignored, 0 failed; one `SKIPPED: no wave64`, expected on this card. - Release build of this head with its named tests, without and with `XCL_PS_SKIP_RUN_THROUGH=1`: built; the 8 named tests passed in each pass (0 failed), no `SKIPPED` line. - A CPU probe translated the 119 programs of my #3591 sweep (117 pixel shaders and 2 compute shaders of the retail title) at #3591's head `f4413ddb` and at this head, and compared their direct DXIL byte for byte: with `XCL_PS_SKIP_RUN_THROUGH=0` (every adapter but NVIDIA) 119 of 119 the same, with `=1` (NVIDIA's default) 119 of 119 the same. So on these programs the fix changes no translation. **Regression run** `scripts/smoke.ps1`, 60 s each, the same title, the same machine and driver (621.47), a fresh shader cache on both sides; `main` first, then this head: ``` xcl-smoke v1 commit: 16c2fd082ae2e96967a2ab553bc2e1032e491f70 gpu: NVIDIA GeForce RTX 3090 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 488 (PresentX 488) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 16164 MB ``` ``` xcl-smoke v1 commit: eb352ba151782c584286f209f93e1db94063f46a gpu: NVIDIA GeForce RTX 3090 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 439 (PresentX 439) presents per 2 s (last 3): 61 60 61 device removals: 0 crashes: 0 peak commit: 15570 MB ``` Frames 439 / 488 (90 %), peak commit 15,570 / 16,164 MB (96 %), no device removal, no crash. **Not tested** - AMD and Intel GPUs. `forms` runs on every adapter, so this commit reaches them; the CPU comparison above with `=0` is the path they take, but nothing was run on an AMD or Intel GPU. - Other NVIDIA cards and drivers. - A drawn pixel shader whose compare form this commit changes: the tests of the fix are CPU tests of `subset_after` and `forms`; the GPU tests above check that the existing shapes still draw right. - A game run beyond the 60 s smoke above. **AI use** - AI use: Claude Code (Claude Opus 5.5) wrote the fix and its tests, had them reviewed by a second Claude Code agent and by Antigravity (gemini-4-neon-high), fixed what the reviews found, ran the tests, the CPU comparison and the smoke run, and wrote this description; checked and posted by me.
Foniass commented 2026-12-03 16:50:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T16:50:58Z.


Review of eb352ba1 (code reading only, not a merge-check; draft) · 1 medium

In short: This is the first commit of #3785, split out as that review asked. It is stacked on #3591, and only eb352ba1 belongs here, the same commit reviewed in #3785. It fixes four EXEC bounds in ps_masks::subset_after, which picks each direct pixel shader's compare form on every adapter. The fix reads as right, and the 119 programs of the author's sweep translate byte for byte the same. One evidence gap: the whole suite was not run on this head.

Medium

  1. The whole suite is not reported on this head. Tested gives ps_masks and lane_masks plus named GPU tests (36 in all) on eb352ba1. This commit changes forms for every direct pixel shader on every adapter. CONTRIBUTING.md asks for cargo test --workspace -- --test-threads=4 on the head under review, with its counts and SKIPPED tests.
Checked and fine
  • eb352ba1 is the commit reviewed in #3785, unchanged. The description says Stacked on #3591 and that only the top commit belongs here.

  • The bounds match the ISA:

    • wave64 needs all of EXEC bounded, not only bit 126;
    • S_ANDN1_WREXEC and S_ANDN2_WREXEC;
    • the saveexec family;
    • a saveexec whose SDST is EXEC bounds nothing;
    • the even-pair check and the parity rule for 32-bit SALU in wave64.

    The commit's CPU tests fail on the old check.

  • TRANSLATOR_VERSION 12 → 13 is needed, because ps_masks.rs is in no source hash.

  • On the description's sweep (117 pixel shaders and 2 compute shaders), the direct DXIL is byte-identical to #3591's head, with XCL_PS_SKIP_RUN_THROUGH=0 and with =1. So on those programs nothing changes on any adapter.

  • Not tested lists AMD and Intel, and says no drawn pixel shader whose form this changes was run.

  • Smoke pair on a retail title: 439 against 488 frames (90 %) and less peak commit, both within the limits. With identical DXIL on the sweep, the frame difference is likely run-to-run noise.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7385547960 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3798#issuecomment-7385547960). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T16:50:58Z. --- **Review** of `eb352ba1` (code reading only, not a merge-check; draft) · 1 medium **In short:** This is the first commit of #3785, split out as that review asked. It is stacked on #3591, and only `eb352ba1` belongs here, the same commit reviewed in #3785. It fixes four EXEC bounds in `ps_masks::subset_after`, which picks each direct pixel shader's compare form on every adapter. The fix reads as right, and the 119 programs of the author's sweep translate byte for byte the same. One evidence gap: the whole suite was not run on this head. #### Medium 1. **The whole suite is not reported on this head.** **Tested** gives `ps_masks` and `lane_masks` plus named GPU tests (36 in all) on `eb352ba1`. This commit changes `forms` for every direct pixel shader on every adapter. CONTRIBUTING.md asks for `cargo test --workspace -- --test-threads=4` on the head under review, with its counts and SKIPPED tests. <details><summary>Checked and fine</summary> - `eb352ba1` is the commit reviewed in #3785, unchanged. The description says `Stacked on #3591` and that only the top commit belongs here. - The bounds match the ISA: - wave64 needs all of EXEC bounded, not only bit 126; - `S_ANDN1_WREXEC` and `S_ANDN2_WREXEC`; - the saveexec family; - a saveexec whose SDST is EXEC bounds nothing; - the even-pair check and the parity rule for 32-bit SALU in wave64. The commit's CPU tests fail on the old check. - `TRANSLATOR_VERSION` 12 → 13 is needed, because `ps_masks.rs` is in no source hash. - On the description's sweep (117 pixel shaders and 2 compute shaders), the direct DXIL is byte-identical to #3591's head, with `XCL_PS_SKIP_RUN_THROUGH=0` and with `=1`. So on those programs nothing changes on any adapter. - **Not tested** lists AMD and Intel, and says no drawn pixel shader whose form this changes was run. - Smoke pair on a retail title: 439 against 488 frames (90 %) and less peak commit, both within the limits. With identical DXIL on the sweep, the frame difference is likely run-to-run noise. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3798:upstream-pr/3798'
git switch 'upstream-pr/3798'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3798'
git switch 'upstream-pr/3798'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3798'
git switch 'upstream-pr/3798'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3798'
git switch 'main'
git merge --squash 'upstream-pr/3798'
git switch 'main'
git merge --ff-only 'upstream-pr/3798'
git switch 'main'
git merge 'upstream-pr/3798'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3798
No description provided.