fix(shader): prove masked writes through guarded first-lane reads #3739

Merged
eljackjoestar-cmd merged 1 commit from upstream-pr/3739 into main 2026-10-12 06:39:13 +00:00
eljackjoestar-cmd commented 2026-10-11 16:14:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-11T16:14:26Z.


What

Lost Soul Aside (PPSA26358) aborts while recompiling a pixel shader because a masked copy keeps the packed ancillary input live. #3391 alone still fails on the captured 5,016-code-word wave64 request. With that dependency and this change, the same request recompiles into 306,669 SPIR-V words and a fresh title run progresses to the separate color-array-view refusal covered by #3633. That initial run remained black. Later integration runs reached menus, but the user still reports green flashes; gameplay and rendering correctness remain unverified.

Extend the existing mask proof to recognize boolean selects and independently rebuilt lane-bit predicates using the same mask words. Follow ReadFirstLane only when its read mask implies the source write mask and a separate liveness proof shows its result is unobserved outside the read mask. Keep the source select for unguarded results, wider masks and results carried across iterations of a loop-local mask. Nested proofs share the remaining per-walk work budget and retain the existing depth limits.

The first-lane behavior follows the existing EmitReadFirstLane backend and AMD's Vega ISA section 12.8, V_READFIRSTLANE_B32, page 127: a nonempty EXEC reads its lowest active lane; empty EXEC reads lane zero. The second proof prevents that fallback from becoming observable after removing the source select. Instruction lowering is unchanged. Console comparison is unverified and recorded in TechnicalDebt.

#3391 supplied the whole-quad proof and has since merged into main. The current PR head is fded8a7e7 and contains only this proof extension; the original tested implementation was d7066b678. #3550 overlaps the same pass with a separate per-shader budget; neither open PR implements these first-lane or boolean-select proofs.

Tested

Windows x86-64, Ryzen 7 7800X3D, 32 GB RAM, NVIDIA RTX 5070, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON. Built the full default target and the explicit libs target.

  • Full CTest: 827 passed, 4 failed, 5 skipped out of 836 in 90.27 s. The four failures (guest_kernel_sys, windows_exceptions, guest_filesystem, agc_driver_emulated_color_compare) also fail with the original main implementation. The skips are existing display/no-Vulkan cases. Full CI is not green.
  • agc_masked_select and pixel_ancillary pass in about 0.04 s each. New positive cases cover guarded first-lane reads, boolean selectors, identical mask words and same-iteration loop uses; negative cases cover empty read EXEC with observable fallback, wider read/consumer masks, mismatched wave64 high words and loop phi escape. Restoring the #3391 implementation fails four new positive cases and the captured request; restoring this fix passes both tests and recompiles the request.
  • Lost Soul Aside: before, packed-ancillary compilation abort; after, execution reaches AGC graphics: color views of several array slices are unsupported. No copyrighted request or game binary is included in the branch.
  • python tools/check_conventions.py --base origin/main and git diff --check pass.

The exact captured-request output also passes standalone spirv-val --target-env vulkan1.1spv1.4, built from the repository's bundled SPIRV-Tools and SPIRV-Headers. Local emulator build used SPIRV-Tools OFF.

Rebased onto main bca7a29d2, preserving both sides of an adjacent TechnicalDebt addition. The pass and regression source files are byte-identical to 84cf71319. The current source passes agc_masked_select and pixel_ancillary in the separately built #4150 dependency stack, alongside its relative-addressing GPU tests. The full-suite and initial title results above are historical evidence on the original base, not a new full-suite run on this head.

Not tested: Linux/lavapipe, console hardware or collaborator-triggered full CI.

Checklist

  • Based on current main; no other open PR implements the same functions (proof additions are distinct; overlaps with #3391 and #3550 described above)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none (#3391 is now merged)
  • AI-assisted: yes, OpenAI Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820460938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3739). Originally posted by [eljackjoestar-cmd](https://github.com/eljackjoestar-cmd) on 2026-10-11T16:14:26Z. --- ### What Lost Soul Aside (PPSA26358) aborts while recompiling a pixel shader because a masked copy keeps the packed ancillary input live. #3391 alone still fails on the captured 5,016-code-word wave64 request. With that dependency and this change, the same request recompiles into 306,669 SPIR-V words and a fresh title run progresses to the separate color-array-view refusal covered by #3633. That initial run remained black. Later integration runs reached menus, but the user still reports green flashes; gameplay and rendering correctness remain unverified. Extend the existing mask proof to recognize boolean selects and independently rebuilt lane-bit predicates using the same mask words. Follow `ReadFirstLane` only when its read mask implies the source write mask and a separate liveness proof shows its result is unobserved outside the read mask. Keep the source select for unguarded results, wider masks and results carried across iterations of a loop-local mask. Nested proofs share the remaining per-walk work budget and retain the existing depth limits. The first-lane behavior follows the existing `EmitReadFirstLane` backend and AMD's [Vega ISA section 12.8, V_READFIRSTLANE_B32, page 127](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/vega-shader-instruction-set-architecture.pdf): a nonempty EXEC reads its lowest active lane; empty EXEC reads lane zero. The second proof prevents that fallback from becoming observable after removing the source select. Instruction lowering is unchanged. Console comparison is unverified and recorded in TechnicalDebt. #3391 supplied the whole-quad proof and has since merged into main. The current PR head is `fded8a7e7` and contains only this proof extension; the original tested implementation was `d7066b678`. #3550 overlaps the same pass with a separate per-shader budget; neither open PR implements these first-lane or boolean-select proofs. ### Tested Windows x86-64, Ryzen 7 7800X3D, 32 GB RAM, NVIDIA RTX 5070, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON. Built the full default target and the explicit `libs` target. - Full CTest: 827 passed, 4 failed, 5 skipped out of 836 in 90.27 s. The four failures (`guest_kernel_sys`, `windows_exceptions`, `guest_filesystem`, `agc_driver_emulated_color_compare`) also fail with the original main implementation. The skips are existing display/no-Vulkan cases. Full CI is not green. - `agc_masked_select` and `pixel_ancillary` pass in about 0.04 s each. New positive cases cover guarded first-lane reads, boolean selectors, identical mask words and same-iteration loop uses; negative cases cover empty read EXEC with observable fallback, wider read/consumer masks, mismatched wave64 high words and loop phi escape. Restoring the #3391 implementation fails four new positive cases and the captured request; restoring this fix passes both tests and recompiles the request. - Lost Soul Aside: before, packed-ancillary compilation abort; after, execution reaches `AGC graphics: color views of several array slices are unsupported`. No copyrighted request or game binary is included in the branch. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. The exact captured-request output also passes standalone `spirv-val --target-env vulkan1.1spv1.4`, built from the repository's bundled SPIRV-Tools and SPIRV-Headers. Local emulator build used SPIRV-Tools OFF. Rebased onto main `bca7a29d2`, preserving both sides of an adjacent TechnicalDebt addition. The pass and regression source files are byte-identical to `84cf71319`. The current source passes `agc_masked_select` and `pixel_ancillary` in the separately built #4150 dependency stack, alongside its relative-addressing GPU tests. The full-suite and initial title results above are historical evidence on the original base, not a new full-suite run on this head. Not tested: Linux/lavapipe, console hardware or collaborator-triggered full CI. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (proof additions are distinct; overlaps with #3391 and #3550 described above) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none (#3391 is now merged) - [x] AI-assisted: yes, OpenAI Codex
Cor3Duo commented 2026-10-11 16:26:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Cor3Duo on 2026-10-11T16:26:40Z.


A second title for this: The Exit 9 (PPSA20955 v01.000.000, Unreal Engine) stops on main a11c8f7f at a 3720-code-word wave64 pixel shader with the same packed pixel ancillary input has an unsupported live use (used by SelectU32 ? ?). #3391 alone does not fix it. With this PR's head d7066b678 the saved request recompiles (245293 SPIR-V words) in agc_shader_replay.

Tested on Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, AMD Radeon Graphics (Ryzen 5 7600X, RDNA2, driver 32.0.21043.5001).

In this shader the first-lane reads sit inside a loop and their exec goes through a SelectU1, so it exercises the same-iteration and boolean-select proofs.

I had reached the same rules independently before seeing this PR (Cor3Duo/AnyPS5 fix/masked-select-first-lane, 0087537), so I am not opening a duplicate. That branch is there if an independent cross-check of the proofs is useful.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6111137974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3739#issuecomment-6111137974). Originally posted by [Cor3Duo](https://github.com/Cor3Duo) on 2026-10-11T16:26:40Z. --- A second title for this: The Exit 9 (PPSA20955 v01.000.000, Unreal Engine) stops on `main` a11c8f7f at a 3720-code-word wave64 pixel shader with the same `packed pixel ancillary input has an unsupported live use (used by SelectU32 ? ?)`. #3391 alone does not fix it. With this PR's head d7066b678 the saved request recompiles (245293 SPIR-V words) in `agc_shader_replay`. Tested on Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, AMD Radeon Graphics (Ryzen 5 7600X, RDNA2, driver 32.0.21043.5001). In this shader the first-lane reads sit inside a loop and their exec goes through a `SelectU1`, so it exercises the same-iteration and boolean-select proofs. I had reached the same rules independently before seeing this PR (Cor3Duo/AnyPS5 `fix/masked-select-first-lane`, 0087537), so I am not opening a duplicate. That branch is there if an independent cross-check of the proofs is useful.
adriadam10 commented 2026-10-11 22:21:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:21:26Z.


#3391 is merged, so I rebased this onto current main (only your commit d7066b678 remains; one adjacency conflict in docs/dev/TechnicalDebt.md, both lines kept). Checked merged onto main: the libSceAgc/AgcDriver tests pass on RADV, agc_masked_select fails without the change, and v_readfirstlane_b32 measured on RDNA2 (gfx1035, wave32 and wave64) reads the lowest active lane, lane 0 with EXEC empty. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114538378 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3739#issuecomment-6114538378). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:21:26Z. --- #3391 is merged, so I rebased this onto current `main` (only your commit `d7066b678` remains; one adjacency conflict in `docs/dev/TechnicalDebt.md`, both lines kept). Checked merged onto main: the libSceAgc/AgcDriver tests pass on RADV, `agc_masked_select` fails without the change, and `v_readfirstlane_b32` measured on RDNA2 (gfx1035, wave32 and wave64) reads the lowest active lane, lane 0 with EXEC empty. Merging once CI is green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3739
No description provided.