fix(recompiler): accept optional bodies that end the wave through an exit that keeps no lane #9904
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9904"
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:58:33Z.
What
On devices without
VK_EXT_shader_stencil_export,MaskReplaySafety::optionalBodyrefused any EXEC- or VCC-skipped region that reaches a return block: its merge reasoning assumes every path through the body reaches the merge.A
discardcompiles to exactly that shape. Inside the skipped body the shader removes the killed lanes from its live mask and, when no live lane is left, branches to a block that exports with a false guard and returns (exp null,s_endpgm). Such an exit loses no kept lane:keepsNothing), so no lane is kept on that path;control()like any other conditional branch, so an any-active gate must passguaranteed()(every lane kept on a path through the gate is in the gate's mask, so the exit is never taken while a kept lane exists), and a uniform branch is the same in the replay.optionalBodynow lets the region contain return blocks that keep no lane (it does not walk past them), and allows their false-guarded exports. A return block that keeps a lane is still refused, as is any other export orDiscardin the region.Onimusha: Way of the Sword (PPSA27836) needs this: its stencil-exporting pixel shader skips a discard's kill-and-exit behind an
s_cbranch_execz.This branch is rebased onto
main570089a80, which now carries #9317 (merged asdef1f5dd9, with #9017, #9030 and #9266, sooptionalBodytakes several blocks); the diff is this PR's own commit.Tested
Rebased 2026-10-26: on this head
c15ccc280(main570089a80), withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1on the RTX 3080,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 andagc_driver_stencil_ref_exportskips (noVK_EXT_shader_stencil_export);tools/check_conventions.py --base origin/mainpasses. The results below were taken on the earlier #9317 base.Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on #9317's head
92ebac241.agc_masked_select, two new cases on an EXEC-skipped body that branches, on a uniform condition, either to the merge or to a return block: an exit whose export has a false guard is replay-safe; an exit whose export keeps lanes is refused. With #9317'sStencilReplay.cppthe first fails (an optional wave body may end the wave through an exit that keeps no lane); with this change both pass.The Onimusha request (
shader_2111c51800, dumped withAPS5_DUMP_SHADERS) checked offline withPrepareResourceProgram+StencilReplaySafe: on #9317 + #8145 + #9393 + this change + the scalar ballot-word merge change (my next PR) + the ballot exemption asked about on #9317, the request passes; without this change it refuses at the optional body around the discard (block 8).With
ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, on #9317 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 #9317 and on this change.Not run: the Khronos validation layer (not installed on this host, so
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationhas nothing to load; neither log contains aVUID-line), 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:51Z.
Review: APPROVED
Reviewed exact head
ff0d9169ec2832b5fb5f4298c3edca8e61a35ad5on the declared #9317 stack. The optional region is bounded to 64 blocks, checks single-entry predecessors and merge-phi values, rejects returning paths that keep lanes, and allows only false-guarded exports in no-lane return blocks; tests include positive and kept-lane negative paths. The author reports Vulkan validation-layer A/B on NVIDIA and AMD, with no added VUIDs, and title-request replay evidence as part of the full stencil stack. Current-main conventions pass with the inherited debt-length warning; sync is clean, with only the shared debt file changed since base. Preserve #9317 and the complementary #9905/#9906 changes on the final refreshed stack. I did not run the C++/GPU tests locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:01:06Z.
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.