Recompiler: fix the EXEC bounds of the pixel-shader subset check #3798
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3798"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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) andTRANSLATOR_VERSION12 → 13 indxil/kernel.rs.ps_masks::subset_afterfollows the SGPRs known to be a subset of the live lanes (the entry EXEC): their helper-lane bits are 0.formsuses 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.formsalso uses it to mark a branch region that widens EXEC, andrunto decide whether the SCC of an EXEC write is exact. Four of its EXEC bounds were wrong:subset_after,forms(a region of a branch on the mask that sets EXEC that way was not marked as widening it) andrun(the SCC of such an EXEC write was taken as exact) now require all of EXEC's bits;s_mov_b32 s23, exec_lothens_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;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_vcczor by ans_cselecton the SCC (the shapes in the tests below).Where it runs:
formsruns for every direct pixel shader on every adapter (dxil/kernel.rs, outside theps_skip_run_through()check), soXCL_PS_SKIP_RUN_THROUGHdoes not turn this off. At this commit #3591'sflat_skipsdoes not callsubset_after.ps_masks.rsis in neither the translator nor the direct DXIL source hash, hence theTRANSLATOR_VERSIONbump.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 ors_nand_saveexec_b64 exec, 0would 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 ands_andn1_wrexecbound 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 ans_cselecton the SCC of such an EXEC write;a_saveexec_into_exec_bounds_neither_write:s_nand_saveexecands_or_saveexecinto 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 bys_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
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.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 withXCL_PS_SKIP_RUN_THROUGH=1;gpu::dxil: 355 passed, 4 ignored, 0 failed; oneSKIPPED: no wave64, expected on this card.XCL_PS_SKIP_RUN_THROUGH=1: built; the 8 named tests passed in each pass (0 failed), noSKIPPEDline.f4413ddband at this head, and compared their direct DXIL byte for byte: withXCL_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;mainfirst, then this head:Frames 439 / 488 (90 %), peak commit 15,570 / 16,164 MB (96 %), no device removal, no crash.
Not tested
formsruns on every adapter, so this commit reaches them; the CPU comparison above with=0is the path they take, but nothing was run on an AMD or Intel GPU.subset_afterandforms; the GPU tests above check that the existing shapes still draw right.AI use
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 mediumIn short: This is the first commit of #3785, split out as that review asked. It is stacked on #3591, and only
eb352ba1belongs here, the same commit reviewed in #3785. It fixes four EXEC bounds inps_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
ps_masksandlane_masksplus named GPU tests (36 in all) oneb352ba1. This commit changesformsfor every direct pixel shader on every adapter. CONTRIBUTING.md asks forcargo test --workspace -- --test-threads=4on the head under review, with its counts and SKIPPED tests.Checked and fine
eb352ba1is the commit reviewed in #3785, unchanged. The description saysStacked on #3591and that only the top commit belongs here.The bounds match the ISA:
S_ANDN1_WREXECandS_ANDN2_WREXEC;The commit's CPU tests fail on the old check.
TRANSLATOR_VERSION12 → 13 is needed, becauseps_masks.rsis 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=0and 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.