Skip to content

fix(recompiler): let optional-body merges reach ballots that helper lanes cannot contribute to - #9906

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
TheSovietWaffle:fix/recompiler-stencil-replay-helper-free-ballots
Oct 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
TheSovietWaffle:fix/recompiler-stencil-replay-helper-free-ballots

Conversation

@TheSovietWaffle

@TheSovietWaffle TheSovietWaffle commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What

On devices without VK_EXT_shader_stencil_export, MaskReplaySafety::optionalBody refuses an EXEC- or VCC-skipped body when a merge phi is quadObserved. Since #9317 a merged value may reach a Ballot only when every use of that ballot funnels into a lane's own bit (ownBitBallot), which bounds what is read.

This adds the dual case, which bounds what is written: a ballot whose argument onHelper proves false on every helper lane. Helper lanes then contribute zero to every word of that ballot whatever the merged value holds on them, so its words are a function of real lanes only, and any consumer (an any-active early-exit gate, the export mask's merge phis) observes nothing about helper lanes. The exemption only applies to ballots the mask analysis has already restricted (they sit in a stable mask chain whose maskStable/helpers checks passed); any other ballot still goes through the funnel or is refused.

Onimusha: Way of the Sword (PPSA27836) needs this: after its discard, Ballot(ownLane(liveWords) && !killed) (with liveWords a ballot of non-helper lanes masked by the whole-quad active lanes) feeds both an any-active exit gate and the export mask's merge phis. @akkadbakkad89 agreed on #9317 that it should land as its own change on top of #9317.

This branch is rebased onto main 570089a80, which now carries #9317 (merged as def1f5dd9); the diff is this PR's own commit (one line in quadObserved and two test cases).

Tested

Checklist

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 7410 core/shader/recompiler/StencilReplay.cpp

@TheSovietWaffle

Copy link
Copy Markdown
Contributor Author

Paired run with the Khronos validation layer (@MarcZX10's request), 2026-10-23.

Layer: VK_LAYER_KHRONOS_validation from KhronosGroup/Vulkan-ValidationLayers' Windows nightly build of 2026-10-22 (manifest api_version 1.4.365), loaded with VK_ADD_LAYER_PATH; VK_LOADER_DEBUG=layer shows the loader inserting it in every test process, and neither log has was not found but was requested by env var VK_INSTANCE_LAYERS.

ctest -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, on #9317 92ebac241 and on this PR's head 3740a402f, Windows 10 22H2, on NVIDIA RTX 3080 (617.42) and AMD Radeon RDNA 2 iGPU (1002:164e, 32.0.21045.5002):

  • 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_replay and agc_driver_stencil_replay_no_gpl pass on both GPUs, on both trees; agc_driver_stencil_ref_export passes on the Radeon and skips on the RTX 3080 (no VK_EXT_shader_stencil_export).
  • No VUID- line in any of the four logs, so the change adds no validation errors.

AI-assisted: yes (Claude Code).

@MarcZX10

Copy link
Copy Markdown
Contributor

I reviewed the exact head 3740a402f2fac97794664f20bf87371a8404734d; diff-check and conventions pass, and the reported positive/negative GPU cases plus validation-layer rerun provide focused evidence. I compared #9905 as well: these changes are complementary, not duplicates. This PR restricts ballots proven false on helper lanes; #9905 handles merge-phi equality for skipped lanes’ own ballot bits. Both modify StencilReplay.cpp and MaskedSelect.cpp, and this PR’s report exercises the combined stack including #9905. Please list #9905 as an integration dependency if the submitted branch requires it, and preserve both code/test cases when rebasing or merging either first. I could not run the C++ tests locally because the workspace filesystem is full.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 3740a402f2fac97794664f20bf87371a8404734d on the #9317 stack. This separately recognizes ballots proven false on helper lanes; the tests cover accepted proof and negative controls. The author reports paired validation-layer runs on NVIDIA and AMD with no new VUIDs, and combined title-request evidence with #9904/#9905. Current-main diff-check passes; conventions report no errors and only the inherited #9317 debt-length warning. Sync is clean apart from the shared debt file. Preserve this helper-lane proof alongside the complementary return-block and own-bit-phi changes; I found no duplicate implementation. I did not rerun the C++/GPU tests locally.

@akkadbakkad89

Copy link
Copy Markdown
Contributor

Validation datapoint for the full follow-up chain (data + source read, no title run).

Setup: Windows 11 Pro 26200, WinLibs GCC 15.2.0 MinGW Release. Union tree 92ebac241 + 5844ac98 (#9393) + 4be42c51 (#9905) + ff0d9169 (#9904) + 3740a402 (#9906) — all four cherry-picks applied with clean auto-merges only, check_conventions clean.

Result on the union tree:

On this PR's diff: the exemption lands exactly as the reviewed one-liner — restricted ballot, single argument, onHelper(arg) == 0, continue. Contribution-bounded, the correct dual of the own-bit funnel.

Scope note: we do not have the PPSA27836/PPSA24191 dumps locally, so the title-level confirmation for those shaders stays with your runs.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@TheSovietWaffle Thanks, the helper-false ballot exemption looks right, and both new cases exercise it. Once #9317's current head builds, please rebase this branch onto it: this head carries #9317 at 92ebac241, and #9317 has since moved to 6b92945c1b with different StencilReplay.cpp/MaskedSelect.cpp contents.

@akkadbakkad89

Copy link
Copy Markdown
Contributor

Heads-up for the rebase oneandonlydean asked for: #9317's head moved once more since his note — it is now 4a59035543 (main -> #9030 -> #9266-fixed -> #9317's own commit), carrying the equivalentSource immediate-equality fix (constants differing only in value no longer pair) plus a refusal test in MaskedSelect.cpp. That is the head to stack on; the earlier 6b92945c1b is superseded.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@TheSovietWaffle Small correction to my note above: #9317 is now at 4a59035543, as akkadbakkad89 says, and that head has passed review. Please rebase this branch onto 4a59035543 rather than 6b92945c1b.

…anes cannot contribute to

quadObserved refuses an optional body whose merged value reaches a
ballot, unless the ballot is only read as each lane's own bit. A ballot
whose argument onHelper proves false on every helper lane is safe for
any reader: helper lanes contribute zero to every word whatever the
merged value holds there, so its words are a function of real lanes
only. quadObserved now skips such a ballot when the mask analysis has
restricted it. This bounds contribution where the own-bit funnel bounds
consumption.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TheSovietWaffle
TheSovietWaffle force-pushed the fix/recompiler-stencil-replay-helper-free-ballots branch from 3740a40 to 83d2093 Compare October 26, 2026 16:34
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@oneandonlydean
oneandonlydean merged commit d0bf428 into boykopovar:main Oct 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants