fix(recompiler): accept optional-body merges of ballot words of the skipped lanes' mask bits #9905
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9905"
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-22T20:59:24Z.
What
On devices without
VK_EXT_shader_stencil_export,MaskReplaySafety::optionalBodyaccepts an EXEC- or VCC-skipped body when every merge phi's value from the body equals the skipped value on lanes inactive in the body (inactiveEquals, inactive meaning the skip predicatePis false).A
discardkeeps its live mask in scalar wordsS(one per wave half). Inside a skipped body it removes the killed lanes withS' = Ballot(own(S) && !P), and the merge phi takesSwhen the body is skipped. The words are wave-wide, but every user reads them lane by lane through own-bit masks (maskStableandown()follow the phi), and on a lane inactive in the body its bit ofBallot(own(S) && !P)is its bit ofS. So the two incoming values agree on every inactive lane's bit.inactiveEqualsnow accepts a body value that is wordhofBallot(own(M) && !P)(either operand order), or ofBallot(own(M)), when the skipped value is wordhofM. Since #11699 rewrites a shader's rebuilt lane bit into theHelperInvocation == 0predicateL, the same discard readsBallot(L && !P), and its skipped value isBallot(L), possibly ANDed withWQM(Ballot(true)), so the rule also accepts a body ballot ofL && !P(orL) against a skipped word ofBallot(L), alone or ANDed with a word that covers every lane: a lane that reaches the merge passed that ballot, so its bit isL. Any other ballot argument is refused as before; in particularBallot(own(M) && Q)for anotherQcan clear an inactive lane's bit.Onimusha: Way of the Sword (PPSA27836) needs this: its stencil export mask is the live-mask words after such a discard.
This branch is rebased onto
mainc3c45d73a. The first commit is the original rule; the second,64e52b631, follows #11699's rewrite.Tested
Rebased 2026-10-31: on this head
64e52b631and onmainc3c45d73a, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(nightly 2026-10-22), on the RTX 3080 and the Radeon iGPU:agc_masked_select,agc_driver_sample_mask_depth_stencil,agc_driver_stencil_known_replace,agc_driver_stencil_null_feedback,agc_driver_stencil_ref_export_unused,agc_driver_stencil_replayandagc_driver_stencil_replay_no_gplpass on both trees and both GPUs;agc_driver_stencil_ref_exportpasses on the Radeon and skips on the RTX 3080 (noVK_EXT_shader_stencil_export). Neither tree's logs have aVUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS.tools/check_conventions.py --base origin/mainpasses.agc_masked_select, four new cases: a body ballot ofL && !Pmerged withBallot(L)and withBallot(L) & Ballot(true)is replay-safe;Ballot(L && P)and a ballot of other lanes are refused. Without the second commit only the two accepted cases fail.Onimusha's
shader_2111c51800onc3c45d73a+ #9904 + this PR: refused without the second commit,prepared: 20050 SPIR-V wordswith it. Lindamea1's PPSA24191 requests are not replayed here.The results below were taken before the rebase.
Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on #9393's head
5844ac98e(on #9317's92ebac241).agc_masked_select, two new cases on a single-block EXEC-skipped body whose merge phis take the live-mask wordsS(a ballot of the non-helper lanes) when skipped andBallot(own(S) && !P)from the body, read through an own-bit export guard: replay-safe; the same withBallot(own(S) && P), which clears inactive lanes' bits, is refused. With #9393'sStencilReplay.cppthe first fails (an optional wave body may merge a ballot of the skipped lanes' own mask bits with that mask); with this change both pass.The Onimusha request (
shader_2111c51800, dumped withAPS5_DUMP_SHADERS) checked offline withPrepareResourceProgram+StencilReplaySafe: on #9317 + #8145 + #9393 + this change + #9904 (the optional-body exit change) + the ballot exemption asked about on #9317, the request passes; without this change the export mask's merge after the discard is refused.With
ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, on #9393 and on this change:agc_masked_select,agc_driver_sample_mask_depth_stencil,agc_driver_stencil_known_replace,agc_driver_stencil_null_feedback,agc_driver_stencil_ref_export,agc_driver_stencil_ref_export_unused,agc_driver_stencil_replayandagc_driver_stencil_replay_no_gplpass on both GPUs below, exceptagc_driver_stencil_ref_exportskipped on the RTX 3080 (noVK_EXT_shader_stencil_export). Results are identical on #9393 and on this change.Not run: a title.
tools/check_conventions.py --base origin/mainpasses with no errors (its one warning,debt-lengthondocs/dev/debt/libSceAgcDriver.md, is in #9317's entry, which this PR does not touch) andgit diff --checkpasses.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 MarcZX10 on 2026-10-23T05:50:53Z.
Review: APPROVED
Reviewed exact head
4be42c510c7795d81528427d9b5811782289112eon the #9317 stack. The change handles skipped-lane own-bit ballot words through merge phis, with tests for the accepted equality case and negative controls. The author reports paired validation-layer runs on NVIDIA and AMD with no new VUIDs; the combined title scenario also uses #9904 and #9906. Current-main diff-check passes; conventions have no errors and only the inherited #9317 debt-length warning. Sync is clean aside from the shared debt file. Preserve this distinct phi proof with #9904/#9906 when refreshing; no duplicate behavior found. I did not rerun C++/GPU tests locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:01:04Z.
Review: CHANGES_REQUESTED
Re-check — changes requested\n\nThe previously reviewed focused cases and the paired validation-layer report are useful, but this branch is still based on an old main snapshot: its head is over 2,600 commits behind current main. A new overlap report also says it could not compare this PR with #6959 in StencilReplay.cpp and MaskedSelect.cpp.\n\nPlease update onto current main, manually inspect the #6959 interactions and keep the distinct optional-body behavior/tests, then rerun the focused recompiler and AGC masked-select tests with the validation layer where applicable. Record any required landing order or dependency. The earlier approval covered the 2026-10-22 head, not this integration point. I did not run these tests locally.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:44:16Z.
Review: CHANGES_REQUESTED
Re-check — changes requested for current-main integration
The latest NVIDIA report is useful, but it tests this head merged onto
main52c09d5, not currentmainaaccd0ba39b7d40fdbf19664575a7e567d8542f7. The current merge preview conflicts incore/libs/prx/libSceAgcDriver/tests/MaskedSelect.cpp,core/shader/recompiler/StencilReplay.cpp, anddocs/dev/debt/libSceAgcDriver.md; the overlap scan also could not compare #6959.Please rebase onto current main, manually preserve the distinct ballot-word merge behavior and tests while resolving #6959's changes, and record the integration/landing order with the companion optional-body change in #9904 if both are intended to land together. Then rerun the focused recompiler and masked-select tests, including the validation-layer check where available, on the exact refreshed head. The current product jobs are skipped, and I did not run these tests locally.