fix(recompiler): accept optional wave bodies of several blocks in stencil replay #9030
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9030"
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-21T10:06:36Z.
What
On devices without
VK_EXT_shader_stencil_export,MaskReplaySafety::controlaccepts a non-uniforms_cbranch_execz/vccz(orexecnz/vccnz) branch when the skipped code is an optional body (optionalBody): inactive lanes see the same values whether or not the wave runs it.optionalBodyonly accepted a body that is one block branching straight to the merge. A body with its own branches was refused, which is the shape Onimusha: Way of the Sword (PPSA27836, its stencil-exporting pixel shader skips blocks 2 to 8 behind ones_cbranch_execz, see my note on #7006) and Monster Hunter Wilds (PPSA24191, reported by @Lindamea1 on #8145) hit after their other refusals.optionalBodynow takes the region of blocks reached from the body before the merge, and accepts it when:SetAttribute) or discarded, and its values are used only inside the region or by merge phis;inactiveEquals), which now also follows the region's own phis (each incoming value of such a phi must satisfy it).The single-block case is the same as before. Every branch inside the region still goes through
control()like any other branch, and the merge phis are still checked withquadObserved.Together with #9017 (EXEC copies), this covers the two gaps @Lindamea1 listed for Monster Hunter Wilds. Onimusha still needs a third one (a lane's own bit of a ballot of the predicate, at its EXEC restore), so no title is claimed to be unblocked.
Tested
Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on main
b5d763770.agc_masked_select, two new cases: an EXEC-skipped body made of a uniform branch into two arms that rejoin before the merge, each writingselect(predicate, value, old), is replay-safe; the same body with one arm writing an unmasked constant is refused. On main the first fails (an optional wave body spanning several blocks preserves inactive values through its own phis), and with only the region walk (withoutinactiveEqualsfollowing region phis) it still fails. The existing single-block cases (an optional wave body preserves inactive values consumed only within a laneand the two derivative-consumer refusals) 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).tools/check_conventions.py --base origin/mainandgit diff --checkpass.tools/pr_overlap.pywas not run (noghon this host); #9017 touches the same file inhelpers(), not here.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 oneandonlydean on 2026-10-21T17:43:29Z.
@TheSovietWaffle a question from testing this with #9017 on a wave64 pixel shader from PPSA28183 that exports stencil. Once the EXEC copy halves are paired (see #9017), the next refusal is
quadObserved(phi)inoptionalBody, on a three-block optional body that this PR now accepts. The phi merges a texture sample result with a computed value.The merged value reaches two places:
s_cbranch_execzskip conditions.quadObservedcounts every branch condition, whilehelperObservedexempts the Exec/Vcc kinds.Ballotof an FP compare that is ANDed with the own-lane bit of asaved & WQM(exec)mask. That's av_cmpunder a WQM mask, so helper lanes take part in the ballot.Is it intended that this stays refused? Or is it safe for a merged optional-body value to reach a ballot restricted by an own-lane mask whose helper provenance is known? If it's safe, it seems
quadObservedwould also need the Exec/Vcc branch exemption thathelperObservedhas.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T02:31:13Z.
@TheSovietWaffle I have a question about how #9030's optional bodies meet
quadObserved, from replaying one logged stencil-replay request of PPSA28183 offline (agc_shader_replay --prepareon a build with #9017 and #9030, then with #9266 added on top).With #9017 + #9030 the request refuses at the
maskStablecheck. #9266 clears that, and it now refuses incontrol(), throughoptionalBody, at:The optional body has three blocks, which #9030 accepts. Its merge phi combines a texture-sample result with a computed value, and
quadObservedreturns true for that phi in two ways:quadObservedcounts every branch condition, whilehelperObservedexempts the Exec and Vcc kinds.BallotofFPUnordGreaterThan(...) && ownLane(saved & WQM(exec)): a v_cmp result restricted to a whole-quad mask. Since that mask includes helper lanes, the ballot can see the phi's value in helper lanes.My questions:
quadObservedtoo, as they are inhelperObserved? A branch on whether any lane is live doesn't seem to expose a per-lane value to me, but you know why the two checks differ.I didn't relax the ballot rule, so I don't know what refuses after it.
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-22T05:05:07Z.
@oneandonlydean both of your
quadObservedcases are what open PR #9317 implements on this stack (main+ #9017 + #9030 + #9266). On PPSA20397's0x407325e400request the full stack reachesprepared: 96161 SPIR-V wordsunderagc_shader_replay --prepare, i.e. the verifier clears end to end.How each of your questions maps:
Exec/Vcc branch conditions: #9317 does not blanket-exempt them. It runs a memoized
controlProven()pre-pass over conditional branches (with a visiting set for cycles) and exempts a condition use only when the consuming branch's optional body itself validates undercontrol(). So a merged phi feedings_cbranch_execzis fine exactly when that branch's region is already replay-proven — the exemption stays conditional on the proof rather than on the branch kind. Your "a branch on whether any lane is live doesn't expose a per-lane value" intuition holds, but only because the region is independently proven; we keep rejecting conditions of unsafe branches.Ballot of
P && ownLane(WQM(exec)): #9317 exempts aBallotonly when every use funnels through the strict own-lane read —CompositeExtract(half)→ optional lane-localAndmask →Select(lane<32, lo, hi)→ShiftRight(·, lane&31)→And(·,1). Then the ballot is only ever read asballot[L], so cross-lane information — including what helper lanes computed — cannot escape the funnel; their divergence inPis unobservable. If the ballot result reaches anything else, it's still rejected, which matches your "keep refusing unless you can show the helper lanes match" — with the funnel, they provably can't be observed at all.Two extra details worth knowing:
optionalBodyhad to keep its region set local so nestedcontrol()proofs don't union regions across recursion (in the PR), and explicit-LOD samples (ImageSampleExplicitLodflags) are exempted as lane-local since they don't compute implicit quad derivatives.Worth replaying your PPSA28183 request on the full stack — if anything still refuses after that, it's a gate this title's shader doesn't exercise and worth a new finding.
AI-assisted: yes (Devin).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T05:12:38Z.
@akkadbakkad89 thanks, that's a clear answer to both questions, and keeping the condition exemption tied to the branch's own proof is what I hoped for. I'll replay our logged request on main + #9017 + #9030 + #9266 + #9317 and report back here, and if it clears, run it in the title.
Pull request closed