fix(recompiler): accept EXEC copies in stencil replay masks #9017
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9017"
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 boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-21T09:50:57Z.
What
On devices without
VK_EXT_shader_stencil_export, a stencil-exporting pixel shader is replayed only ifMaskReplaySafetyproves its own-lane masks stable. Since #6291 a pixel shader's EXEC copy (s_mov_b64 s[..], execand the restores built from it) is read as the saved word ANDed withWQM(Ballot(true)). The proof accepts a whole-quad (WqmU64) expansion only of a ballot whose helper lanes it can classify (HelperMask::RealOnlyorQuadStable), and a ballot oftruewasUncertainbecause helper lanes vote true too. So any shader whose own-lane mask plumbing goes through an EXEC copy was refused with "own-lane mask not stable". Reported on #8145 for Monster Hunter Wilds (PPSA24191, by @Lindamea1) and Assassin's Creed Shadows (PPSA20397, by @akkadbakkad89), both at thes_mov_b64 exec, s[..]restore.Every lane of a quad runs (covered pixels and helpers), so a ballot of
truehas the same bits within each quad as the all-ones mask, whichhelpers()already classifies asQuadStable. A ballot of an immediatetrueis now classified the same way. Ballots of anything else are unchanged, so helper-dependent predicates stayUncertainand their whole-quad expansions stay refused. The stencil reference export replay entry indocs/dev/debt/libSceAgcDriver.mdsays so.This removes one of the gaps those reports list. The other one they name,
s_cbranch_execzregions with multi-block bodies (optionalBodyaccepts single-block bodies only), is not part of this PR, so neither title is claimed to be unblocked by this alone.Tested
Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on main
b5d763770.agc_masked_select, two new cases: an EXEC copy (a ballot word ANDed with the whole-quad expansion of a ballot oftrue) used as a stencil export guard is replay-safe; the same EXEC copy over a whole-quad expansion of a helper-dependent ballot is still refused. Without theStencilReplay.cppline the first fails (an exec copy masked by the whole-quad active lanes is a stable export guard); the existing helper-uncertainty cases (helper participation cannot choose a kept lane's stencil through whole-quad expansion,nested active ballots do not erase helper uncertainty before whole-quad expansion) pass unchanged.ANYPS5_NO_SHADER_CACHE=1:agc_masked_select,agc_driver_stencil_replay,agc_driver_stencil_replay_no_gpl,agc_driver_stencil_ref_export,agc_driver_stencil_ref_export_unused,agc_driver_sample_mask_depth_stencilandagc_driver_stencil_null_feedbackpass on both GPUs below, exceptagc_driver_stencil_ref_exportskipped on the RTX 3080 (noVK_EXT_shader_stencil_export) andagc_driver_stencil_replayskipped on the Radeon (it has the extension; withANYPS5_REQUIRE_VULKAN=1that skip is reported as a failure).tools/check_conventions.py --base origin/mainandgit diff --checkpass.tools/pr_overlap.pywas not run (noghon this host).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)1002:164e), 32.0.21045.5002, Windows 10 22H2🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T15:14:11Z.
Independent Windows run of this PR (data only).
Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against
mainis clean. I built onlyagc_masked_select_tests;ctest -N -R agc_masked_selectlists exactly one test.PR head tested:
027033f1c81812196e260fb8167807b5203b5ea6.Results (3 runs each):
agc_masked_selectpasses 3/3.core/shader/recompiler/StencilReplay.cppwith the version from the PR's merge base (b5d763770a), then rebuilt. The test fails 3/3 (ctest reports Failed). I restored the PR's files afterwards.GPU: the run output has no
Selected GPUline; no GPU claim is made.Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T17:43:27Z.
@TheSovietWaffle thanks for this. We tested it together with #9030 on a wave64 pixel shader from PPSA28183 that exports stencil. The shader still refuses in
maskStable, in the own-mask loop ofMaskReplaySafety::Check(), for a reason next to the one this PR fixes.The EXEC copy there is translated once per 32-bit half. Each half of the saved mask is
ballot(cond).half & extract(WqmU64(CompositeConstructU64(Ballot(true).x, Ballot(true).y)), half). But the low half and the high half use two separateWqmU64nodes, built from two separateBallot(true)in the same block. The WQM branch ofmaskStable(and the one inhelpers()) needsmask.high->Argument(0)to be the same node as the low half'swqm, so no pairing is ever accepted. The shader has six such pairs.In a local experiment, we treated two
WqmU64(CompositeConstructU64(Ballot(imm).x, Ballot(imm).y))with the same immediate in the same block as one mask, restricting the second tree too. All six pairs then pass. Reading EXEC once per 64-bit operand in the front end would also fix it. Would you like to cover this here, or should it be a separate PR?Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-21T18:25:47Z.
@oneandonlydean the shape you describe — one EXEC copy translated per 32-bit half, giving two same-block
WqmU64(CompositeConstructU64(Ballot(true).x, Ballot(true).y))nodes that failpairedon node identity — is exactly what open PR #9266 implements.Its
equivalentWqm()pairs twoWqmU64s whose source trees match opcode-for-opcode (equal immediates count as equal), requiring anyBallotpair to sit in the same block with no execution-mask-affecting instruction (SetExec*,Discard,Sendmsg,SetThreadBitScalarRegister,SetScalarMaskTag) between them — the same "same immediate, same block, restrict the second tree" rule you tried. Both themaskStable()andhelpers()WQM branches route through it. We hit the identical gate on PPSA20397 (0x407325e400, six same-block pairs,paired=0on object identity) and verifiedpaired=1afterwards.So a separate PR would duplicate #9266 — the cleaner path is testing it on your PPSA28183 shader. If it covers your six pairs, a datapoint on #9266 would help it land; if it doesn't, the gap would be good to know either way.
(Full chain for completeness: #9266 pairing -> this PR's provenance -> #9030 region bodies -> #9317 for the remaining
quadObservedaccounting of proven branch conditions and own-lane ballots.)Generated with Devin
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T02:31:15Z.
@akkadbakkad89 thanks. I replayed the logged request offline (
agc_shader_replay --prepare, one request) with #9266 at 9b578d5dc7:maskStablerefusal: the per-half whole-quad EXEC copies now pair as one mask, as you described.maskStablefor this shader, because it needs #9017's EXEC-copy acceptance underneath.control()→optionalBody(quadObservedon the optional body's merge phi). That's a question about #9030's rule, which I've asked there, not something in #9266.