Recompiler: run through execz skips over regions that only narrow EXEC #3785
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3785"
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-03T12:41:40Z.
Stacked on #3591 and #3798: only the commits after
eb352ba1belong here (#3591'sf4413ddband #3798'seb352ba1show in the diff until they are merged).Follow-up to #3591, as @Royalflamejlh asked there (comment and the reply below it). It should be merged after #3786 (the #3772 workaround): on #3591 alone, the extra run-throughs make one 17-program family of the sweep below worse on NVIDIA through #3772, and with #3786 under them the whole family is identical to HLSL. One other pixel shader was still worse on the RTX 3090 with #3786; the same DXIL is right on WARP, and the last commit keeps the skip involved (see the rule and Tested).
What is in it
The fix of
subset_after's EXEC bounds (Recompiler: fix the EXEC bounds of the pixel-shader subset check,eb352ba1), which was this PR's first commit, is now #3798, under this PR: it changesformson every adapter, and the rule below follows its bounds. Its changes and tests are described there.This PR's own commits, after
eb352ba1(3 files, +673 / −77,git diff --shortstat eb352ba1 a2a8389c; about 540 of the added lines are tests:recomp/tests.rs+243 and theps_masks.rstest module). Apart fromTRANSLATOR_VERSION, all of its non-test code is inflat_skips/flat_region, which run only where #3591 runs skips through (NVIDIA, orXCL_PS_SKIP_RUN_THROUGH=1):Recompiler: run through execz skips over regions that only narrow EXEC: the rule below.Recompiler: GPU test of a skip run through a nested if that narrows EXEC:gpu_direct_ps_skips_run_through_nested_ifs_that_narrow_exec(below), and a test-only override ofps_skip_run_through(kernel::PS_SKIP_IN_TEST, likeIDIOMS_IN_TEST) so that it runs the same on every adapter.Recompiler: the nested-if GPU test also samples a texture in the inner block: a sixth form of that test, where the inner block is an implicit-derivativeimage_sample(below).Recompiler: keep the skip over a whole-quad-mode EXEC write before a cross-lane read: the one refusal added after the sweep (below), with a CPU test, andTRANSLATOR_VERSION14.#3591 runs a pixel shader's
s_cbranch_execzthrough on NVIDIA when the skipped region writes no EXEC. In my test report on #3591, most of the skips it keeps in the retail title's shaders are kept for one reason: the region writes EXEC. That is the usualifinside the region: a saveexec orv_cmpxthat narrows EXEC, then the restore at its end. This PR runs those regions through too.The rule
With EXEC 0 at the skip, any EXEC computed as a subset of the entry EXEC is 0 too. So a region can run through when each EXEC write in it keeps EXEC a subset of its entry EXEC.
flat_regionfollows that bound withsubset_after(the module's existing "subset of a reference mask" step, with the EXEC bounds fixed in #3798), from the region's entry, forward along every path, intersected at joins.Accepted (each has a test in wave64 and one in wave32):
if:s_mov_b64 s[22:23], exec ; v_cmpx ; s_cbranch_execz L ; ... ; L: s_mov_b64 exec, s[22:23](both skips are run through);s_and_saveexec,s_andn1_saveexec,v_cmpx, and a VOP3v_cmpthat writes EXEC;s_and exec, s, execands_andn2 exec, exec, s;s_or/s_xor/s_cselectto EXEC when both operands are bounded;s_or/s_xor/s_andn2_saveexecwhen S0 is bounded;s_andn1_wrexec;s_andn2_wrexecwith a bounded S0;v_cmpto VCC, thens_mov_b64 exec, vcc;s_mov_b64 exec, 0).Refused (the branch is kept; each has a test in wave64 and one in wave32, except the join and the wave64 halves, tested in wave64 only):
s_mov_b64 exec, s[24:25],s_mov_b64 exec, 1,s_andn2_b64 exec, s[24:25], exec,s_or/s_xor/s_andn2_saveexecors_andn2_wrexecwith VCC, a restore whose saved mask comes from an unknown register on one incoming path, or from a write that no path of the region reaches;s_nand,s_nor,s_xnor,s_orn1,s_orn2_saveexec), even of 0;s_or_saveexec_b64 exec, vcc,s_nand_saveexec_b64 exec, 0), even an AND one: it bounds nothing (#3798);s_mov_b32 exec_lo, s22ors_mov_b32 exec_hi, 0; in wave32, a 64-bit SALU to EXEC;s_wqm, not known to be a subset of the live lanes) and an instruction after the region reads other lanes (DPP,ds_swizzle,ds_permute/ds_bpermute, permlane). Running it through gives the same result, but the RTX 3090 drew one such pixel shader wrong while WARP drew the same DXIL right (Tested).v_readfirstlaneand derivatives after the region do not count: the 17-program family has both and is right. Tested in wave64 (execz_skips_keep_a_region_that_writes_a_whole_quad_mode_exec_before_other_lanes_are_read: kept withds_swizzleor DPP after it, run through with nothing,v_readfirstlaneor a sample after it, or withouts_wqm);s_mov_b32 s23, -1), including the extra SGPRs the operand tables list beyond whatwritesreturns;v_writelane,s_sendmsg, float-mode changes,s_movrelsd_2_b32, scalar stores and atomics, indirect, backward or outgoing branches, a program end, and an SGPR (VCC included) or SCC written in the region and read after it (tested here for a saveexec's SDST and SCC, and a compare's VCC read byv_cndmaskors_cbranch_vccz).Why the result is the same
v_readlane/v_readfirstlaneand a VOP3 carry-out write an SGPR). The next point covers all of them.Lw::vopccan pick: the local form (c & act()), the per-quad form (lanebit_at(el, eh, ..)) andcond ? EXEC : 0. The new GPU test checks each of them.Code
ps_masks.rs(andTRANSLATOR_VERSIONinkernel.rs, sinceps_masks.rsis in no source hash).flat_skipscalls a newflat_region, which returns eitherOkor the first rule the region breaks and the instruction that breaks it. The tests check that rule and that instruction.XCL_PS_SKIP_RUN_THROUGHfrom #3591 turns it all off (=0) or on (=1).recomp/tests.rs), next to #3591's: a wave64 pixel shader with the nestedifinside a block thats_cbranch_execzskips. Pixels inside a disc take the outer block; in its_mov_b64 s[22:23], exec(or a saveexec) and a compare narrow EXEC to the pixels left of the centre, an inner skip passes over a write of v12, ands_mov_b64 exec, s[22:23]ends the block. Waves with no pixel in the disc enter the block with EXEC 0 when it is run through, so a narrowing compare that did not give 0 there would write v12 in their left pixels. The compare takes each lowered form:v_cmpxandv_cmp+s_and_saveexec_b64in the local form and in the per-quad form (the mask also read as data under the narrowed EXEC), and a VOP3v_cmpto EXEC with scalar operands. A sixth form puts an implicit-derivativeimage_sample(after the program'ss_wqm) in the inner block, with av_cmpxin the local form, the shape where NVIDIA lost whole waves in #3574. For each, it checks thatflat_skipsruns both skips through, that the compare has that form, that the DXIL differs from the one that keeps the skips, and every pixel on the GPU. A region that widens EXEC (s_mov_b64 exec, s[24:25], all ones) keeps its outer skip; drawn with that skip replaced bys_nop, its block writes a channel in every pixel outside the disc, which shows the image tells a wrong run-through apart. With the skips kept, the test only prints the count of wrong pixels (NVIDIA can leave such waves unwritten, #3574); with them run through, it requires 0 in every form.Tested
a2a8389c):gpu::recomp::ps_masks+gpu::recomp::lane_masks, 36 passed (the new refusal's test among them).XCL_REQUIRE_GPU=mesh: #3591's GPU test, the PS mask / helper-lane GPU tests and the new test, run together with the CPU tests above: 47 passed on this head (46 ona8330f03); the new test run 3 times on each of the two heads: 3/3 passed ona8330f03, 0 wrong pixels with the skips run through in each of the 6 forms, and the same on this head;gpu::dxil(at62e66d8a; the later commits add a test and a refusal inps_masks.rs, not ingpu/dxil): 355 passed, 4 ignored, 0 failed (one test reportsSKIPPED: no wave64, expected on this card). With the skips kept, all 6 forms gave 0 wrong pixels in each run as well: the sampling form does not show #3574 on this card. The widening region drawn withs_nopwrote its channel in all 2,832 pixels outside the disc.XCL_PS_SKIP_RUN_THROUGH=1: built, 40 passed in each pass (0 failed), noSKIPPEDline.XCL_PS_SKIP_RUN_THROUGH=0(the path every adapter but NVIDIA takes), the DXIL is the same for 119 of 119 at #3591's headf4413ddb, at62e66d8aand at this head (#3798's own comparison, ateb352ba1, is in #3798). With=1, 17 programs change against #3591's head and against #3798's headeb352ba1, which changes none of the 119, all through the skips this PR's first commit adds (at62e66d8a, before the last commit: 18; the last commit changes only the one other pixel shader, back to its DXIL atf4413ddb).XCL_PS_SKIP_RUN_THROUGH=1, RTX 3090, driver 621.47. The middle three columns were swept in one job, the left one a job earlier, the right one (this head) in a later job, all on the same driver. "First two commits" is #3798's commit and this PR's first commit (the branch before its last commit):On #3591 alone, the first two commits make two programs worse: one of the 17-program family (4,055 → 8,514 unwritten pixels; its #3591 side is not stable, the same DXIL gave 12,704 in an earlier run) and one other pixel shader (identical → 192). With #3786 under them, the whole 17-program family is identical to HLSL: that one came from #3772 (live lanes lost from the entry ballot on NVIDIA, the same DXIL is right on WARP), made visible by the extra run-throughs.
The other pixel shader stayed at 192 unwritten pixels with #3786 (two runs, the same count). It has one more skip run through: its region writes EXEC under whole quad mode (the nested
ifwith a VOP3v_cmpx), and ads_swizzlereads other lanes later. The direct DXIL with and without that skip differs only by the branch: the same instructions and the same selects under the same lane conditions. Drawn on WARP (warp 1.0.23, Agility 1.621) the same DXIL is identical to HLSL; on the 3090 it leaves 96 pixels per target unwritten. So it is the driver, not the translation, but this PR made the default NVIDIA path worse for that program, so the last commit keeps such skips (the rule above). With it, the probe changes only that program back (8,820 → 8,892 bytes, its DXIL atf4413ddb), and the sweep gives it identical to HLSL again, the 17-program family still identical, and every program's unwritten pixels the same as with #3591 + #3786.main817eb1fc+ the local probe commits (tests only) + #3591 at8ca2df9d+ #3591's laterps_masksrefusals (fromf4413ddb) + the first two commits + a local commit that copies this branch'sps_masks.rs(byte for byte the same as ate82669f6, or at this head for the right column), and for the #3786 columns its commit95c5f6e8cherry-picked on top (#3786's later commit adds a switch whose default translates the same). The 95-program family and the blur program need more than this rule: a backward branch whose condition comes from a zero mask, and a kill branch.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 556 / 488 (114 %), peak commit 15,628 / 16,164 MB (97 %), no device removal, no crash.
Not tested
XCL_PS_SKIP_RUN_THROUGH=1); the change that reaches every adapter (forms) is #3798's. Nothing was run on an AMD or Intel GPU.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T12:49:52Z.
Review of
e82669f6(code reading only, not a merge-check; draft,PR descriptionred) · 1 high, 2 mediumIn short: This PR builds on #3591 and contains its commit. Its first commit tightens the EXEC bounds in
ps_masks::subset_after. Its second lets a pixel-shaders_cbranch_execzrun through regions whose EXEC writes keep EXEC within the region's entry EXEC. The rule and its CPU tests look right on reading. What holds it back: the PR's own sweep shows worse output on NVIDIA with a cause that is only inferred, and the first commit changes the default path on every adapter.High
The PR's own sweep shows worse output on NVIDIA's default path, and the cause is not shown.
ps_skip_run_through_for,dxil/kernel.rs~124-130), so both reach users with no switch set.Fix: sweep this PR on top of #3786 (which fixes #3772) and show both programs come back identical, or show with the marker value that the 192 pixels are lanes missing from the entry ballot. Until then, stack it after #3786.
Medium
The first commit changes every adapter's default path and belongs in its own PR.
subset_after(recomp/ps_masks.rs~112) is already onmain.live_subsetsandforms(~192, ~275) call it for every direct pixel shader, outside theps_skip_run_through()check (kernel.rs~900-901).S_ANDN1_WREXECbound affect AMD too. That contradicts "Not tested: AMD (the rule only runs where #3591 runs skips through)".=0output unchanged (byte-identical DXIL) was made before the review fixes.Fix: open it separately with its tests, and repeat the
=0byte comparison at this head, or list AMD under Not tested for it.No GPU test runs a skip through a region that narrows EXEC.
flat_region). The rule is only right if the lowered compare,v_cmpxand saveexec produce 0 with EXEC 0: the local form'sc & act()and the quad form'slanebit_at(el, eh, ..)indxil/lower_valu.rs~1354-1400.recomp/tests.rs~4076, ~4127) only has regions that write no EXEC.Fix: add a variant with a nested
s_mov_b64 s[x], exec ; v_cmpx ; s_cbranch_execz ; ... ; s_mov_b64 exec, s[x]inside a skipped block.Checked and fine
f4413ddbis #3591's head, unchanged, and the two after it merge cleanly ontomain.subset_after's bounds match the ISA:S_ANDN1_WREXECandS_ANDN2_WREXEC;flat_regionruns forward, intersects at joins, and starts from EXEC. Extra SGPRs fromsgpr_useslose their bound. Any EXEC write that is not bounded, including VALU ones, is refused, andS_WQM,S_NOT,S_ORN2andS_CMOVto EXEC are refused.TRANSLATOR_VERSION12 → 13 is needed, sinceps_masks.rsis in no source hash. The one flipped #3591 test expectation is the intended change.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T14:57:38Z.
Thanks for the review.
95c5f6e8cherry-picked on the same sweep tree), in one job with #3591 + those commits and #3591 + #3786, same driver (621.47):if, with a VOP3v_cmpx), and ads_swizzleafter it. The direct DXIL with and without that skip differs only by the branch (same instructions, same selects under the same lane conditions), and WARP draws the same DXIL identical to HLSL, while the 3090 leaves 96 pixels per target unwritten. So the translation is right and the driver is not, but the PR still made the NVIDIA default path worse for that program.So I added a refusal (
a2a8389c): a region that writes EXEC while EXEC may hold helper lanes (afters_wqm) keeps its skip when something after it reads other lanes (DPP,ds_swizzle, permute, permlane), with a CPU test of that shape. On the 119 programs it takes back only that skip (only that program's DXIL changes, back to #3591's), and the sweep with #3786 gives that program identical again, the 17-program family still identical, and every program's unwritten pixels the same as with #3591 + #3786. The description has the table, and says to merge after #3786.formsusessubset_afterfor every direct pixel shader. I kept it in this PR (the rule depends on it) but repeated the=0comparison at this head: withXCL_PS_SKIP_RUN_THROUGH=0, the direct DXIL of the 119 programs is byte for byte the same (119 of 119) at #3591's headf4413ddband at62e66d8a(CPU, every DXIL compared, not only sizes). With=1, 18 programs changed at62e66d8a, all through the added skips; ata2a8389c, 17 (the other pixel shader is back to itsf4413ddbDXIL). AMD and Intel are now under Not tested for the first commit. If you or the maintainer prefer it as its own PR, I'll split it.gpu_direct_ps_skips_run_through_nested_ifs_that_narrow_exec(62e66d8a): the nesteds_mov_b64 s[22:23], exec ; v_cmpx ; s_cbranch_execz ; ... ; s_mov_b64 exec, s[22:23]inside a skipped block, with the narrowing compare in each lowered form (local and per-quadv_cmpx, local and per-quadv_cmp+s_and_saveexec, andcond ? EXEC : 0). It checks thatflat_skipstakes both skips, the compare's form, that the DXIL differs from the kept one, and every pixel (0 wrong pixels required with the skips run through); waves outside the disc enter with EXEC 0, so a compare that did not give 0 there would write their left pixels. A widening region is refused, and drawn with its skip replaced bys_nopit changes every pixel outside the disc, so the image catches a wrong run-through. A sixth form (a8330f03) samples a texture in the inner block, with implicit derivatives afters_wqm: the shape where NVIDIA lost whole waves in #3574. A test-onlykernel::PS_SKIP_IN_TESTmakes it run the same on any adapter. RTX 3090, 621.47: passed 3 times out of 3 ata8330f03, 0 wrong pixels in each of the 6 forms with the skips run through (the same ata2a8389c). With the skips kept it only prints the count, and it was 0 in all 6 forms too: this small shader does not reproduce #3574 on this card.Also fixed the description for the PR check (Tested / Not tested / AI use sections,
xcl-smokeblocks ofmain16c2fd08and this head: 556 / 488 frames, peak commit 15,628 / 16,164 MB).AI use: Claude Code (Claude Opus 5.5) wrote the test and the refusal, ran the sweeps, the WARP comparison and the CPU probe, and wrote this reply; checked and posted by me.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T15:01:47Z.
Follow-up review of
a2a8389c, sincee82669f6(code reading only, not a merge-check; draft) · 1 mediumIn short: The PR has three new commits since the last review:
ifthat narrows EXEC in every lowered compare form, plus a variant that samples a texture;The one point still open is the
subset_afterfix, which changes every adapter's default path and is still in this PR.Medium
The first commit still changes every adapter's default path, and it is still not split out (still open, in part).
subset_after(recomp/ps_masks.rs~112) is reached fromforms(~275, ~308) for every direct pixel shader, outside theps_skip_run_through()check (dxil/kernel.rs~916-918). So AMD and Intel get the changed bounds too.=0byte comparison was repeated (119 of 119 the same), and AMD / Intel are now under Not tested.f4413ddb, is now 812+/100-, about 910 changed lines. That is over the ~800 lines at which CONTRIBUTING.md asks the description to say why the PR cannot be split. The description says only that the rule depends on the fix, which is a reason to stack the fix underneath, not to keep it here.Fix: open
eb352ba1as its own PR with its tests, and stack this one on it (Stacked on #N).Checked and fine
Earlier finding fixed: the NVIDIA sweep's cause was only inferred.
95c5f6e8underneath, the 17-program family is identical to HLSL.a2a8389c,ps_masks.rs~566-589) puts that program back to its DXIL at #3591's head.Earlier finding fixed: no GPU test ran a skip through a region that narrows EXEC.
gpu_direct_ps_skips_run_through_nested_ifs_that_narrow_exec(recomp/tests.rs~4305) covers every lowered compare form:v_cmpx;v_cmp+s_and_saveexec_b64;v_cmpto EXEC;image_samplein the inner block.For each one it checks that both skips are taken, the compare's form, that the DXIL differs from the kept one, and every pixel. Waves wholly outside the disc enter with EXEC 0, so a compare that did not give 0 would show up as a written
v12. TheWidencontrol is refused by the rule, and when it is forced through, the image shows the wrong result.PS_SKIP_IN_TEST(dxil/kernel.rs~114-127) works likeIDIOMS_IN_TEST. It exists only under#[cfg(test)]and is copied into the translator thread.The new refusal is checked only when the region writes EXEC and EXEC at the skip is not known to be a subset of the live lanes. It can only keep skips, never add run-throughs. Its CPU test fails without it (
ds_swizzleand DPP after the region), and it also checks the accepted cases:v_readfirstlane, a sample, nothing after the region, and nos_wqm.TRANSLATOR_VERSION13 → 14 is needed, becauseps_masks.rsis in no source hash.Commits 1-3 are unchanged, and the head merges cleanly onto the current
main.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by CharlyRien on 2026-12-03T16:48:30Z.
Thanks. Split as you suggested:
eb352ba1(the EXEC bounds fix insubset_after, with its four CPU tests) is now #3798, stacked on #3591, and this PR is stacked on it ("Stacked on #3591 and #3798" at the top of the description).a2a8389c, witheb352ba1under it. Its own part is noweb352ba1..a2a8389c: 3 files, +673 / −77 (750 lines, about 540 of the added lines are tests). Apart fromTRANSLATOR_VERSION, all of its non-test code is inflat_skips/flat_region, which run only where #3591 runs skips through.=0/=1byte comparison of the 119 programs against #3591's head (119 of 119 the same both ways), a release build and a smoke run on its head. AMD and Intel are under Not tested there.AI use: Claude Code (Claude Opus 5.5) split the branch, ran the tests, the CPU comparison and the smoke run of the new PR, and wrote both descriptions and this reply; checked and posted by me.
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.