fix(shader): prove masked lanes unread across exec phis, loops and image operations #3279

Merged
oneandonlydean merged 5 commits from upstream-pr/3279 into main 2026-10-11 07:19:41 +00:00
oneandonlydean commented 2026-10-11 05:02:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T05:02:23Z.


Carried from @AlxcBTW's fork (AlxcBTW/AnyPS5#37, commits 1-5; @xXPBSXx's commit kept under his name); the intake pause closes PRs opened from that account.

What

Refs #2548. Pixel shaders that read the packed ancillary VGPR once and then reuse the register are refused with

packed pixel ancillary input has an unsupported live use (used by SelectU32 ? ?)

The later writes become SelectU32(mask, new, ancillary), so the raw word stays in the lanes the mask excludes. MaskedSelectEliminator drops such a select when it can prove those lanes are never read. This PR lets it prove that in more programs. It removes a select only when the proof holds; a select it cannot prove is kept and refused as before, so no ancillary bit is produced and the gfx1013 layout question does not come up here.

Commits, cherry-picked unchanged onto main 961b25fe:

  1. c2a48416 follow exec phis and long kill chains. Kill paths save and restore exec, so later execs are phis at block merges, and the kills' AND chains go past the eight-level limit. To check that a later exec implies the write's exec, the pass now accepts a phi outside loops whose incoming values all imply it, pairs low and high exec words merged in one block predecessor by predecessor, memoises results per select and follows up to 64 levels. A cycle counts as not implied.
  2. cd4eaacf scale the walk limit with the program. The limit is max(4096, 2 x instructions) steps, linear per walk, and the walk uses id-indexed tables instead of hash sets.
  3. 98f99d38 loops. A loop phi implies the write's exec if every incoming value does. The phi is assumed to imply it while its back-edge values are checked, and results that relied on a failed assumption are discarded. The write's exec must be computed outside any loop.
  4. 83f8c193 image reads (@xXPBSXx, his 6f9f48d7 unchanged). ImageRead carries the exec as its last operand like the buffer loads and fetches only where it is true, so it joins readsOnlyWhereActive.
  5. fda4aa90 image writes, explicit-LOD gathers and size queries. ImageWrite stores inside an if on its exec operand, so it joins the exec-guarded list. ImageGatherRaw with its own LOD, or outside pixel shaders, and ImageQueryDimensions are lane-local. ImageQueryLod, implicit-LOD samples and gathers, ImageBvhIntersectRay and the atomics are left out.

Not included: the rest of AlxcBTW/AnyPS5#37 (a whole ancillary word for reads the walk keeps, and the trace switch). A read the walk cannot drop is still refused; Returnal and Minecraft Dungeons II need that part.

#2654 changes the visited storage of the same walk and conflicts with commit 2.

Tested

Linux (CachyOS, GCC 16.2.1, Release, CI's configure flags without ccache), RTX 4090 (NVIDIA 610.57.04), main 961b25fe plus the five commits:

  • agc_masked_select and pixel_ancillary pass. With MaskedSelectEliminator.cpp put back to main, both fail: agc_masked_select on the kill-chain, loop, image read, image write, gather and size-query cases, and pixel_ancillary with the refusal above.
  • ctest -R "agc|shader": 349/350. Full ctest: 758 tests, 1 failure, 5 video-out tests skipped. The failure in both is agc_driver_dcc_keys_first_write, which fails the same way on main (#3179).
  • tools/check_conventions.py passes.
  • No title was run here.

From #2548, on earlier states of the same commits:

  • Taxi Chaos 2 (PPSA30279, @AlxcBTW): all 54 dumped requests prepare with commit 1.
  • LEGO Horizon Adventures (PPSA14632, @alfalfa-star, Linux, RX 9070 XT, RADV): with commit 1 its one shader was still refused at the fixed walk limit and prepared with the limit raised to 8192. Commit 2 came from that; this thread has no rerun of it alone.
  • Returnal (PPSA01285, @xXPBSXx, Windows, RTX 4080 SUPER): with commits 1-3, 3 of the 6 refused shaders prepare and the title presents frames. With commit 4, 0x2026c60000 recompiles in agc_shader_replay. Two shaders stay refused and the title still aborts on one.
  • Demon Slayer (PPSA03490, @xXPBSXx): with commits 1-4, shaders refused at registration go from 5 to 2. The title still aborts.

Runs of the whole fork branch (these commits plus the whole-word part):

  • Lies of P (PPSA10261) 16 to 0 refused shaders and Ad Infinitum (PPSA10600) 27 to 0 (@xXPBSXx, Windows). The trace switch was on and printed no line. At that state it printed one for every select the walk kept, so per @AlxcBTW the walk dropped every select in these two titles.
  • Stray (PPSA02100) 15 to 0 and Kena (PPSA01746) 4 to 0 (@xXPBSXx); LEGO Horizon Adventures 1 to 0, Stray 31 to 0 and Kena 30 to 0 (@fma-rc, Linux, RTX 5080). The thread does not show how many of these shaders the walk covers alone.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4816713165 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3279). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T05:02:23Z. --- Carried from @AlxcBTW's fork (AlxcBTW/AnyPS5#37, commits 1-5; @xXPBSXx's commit kept under his name); the intake pause closes PRs opened from that account. ### What Refs #2548. Pixel shaders that read the packed ancillary VGPR once and then reuse the register are refused with ``` packed pixel ancillary input has an unsupported live use (used by SelectU32 ? ?) ``` The later writes become `SelectU32(mask, new, ancillary)`, so the raw word stays in the lanes the mask excludes. `MaskedSelectEliminator` drops such a select when it can prove those lanes are never read. This PR lets it prove that in more programs. It removes a select only when the proof holds; a select it cannot prove is kept and refused as before, so no ancillary bit is produced and the gfx1013 layout question does not come up here. Commits, cherry-picked unchanged onto `main` 961b25fe: 1. `c2a48416` **follow exec phis and long kill chains.** Kill paths save and restore exec, so later execs are phis at block merges, and the kills' AND chains go past the eight-level limit. To check that a later exec implies the write's exec, the pass now accepts a phi outside loops whose incoming values all imply it, pairs low and high exec words merged in one block predecessor by predecessor, memoises results per select and follows up to 64 levels. A cycle counts as not implied. 2. `cd4eaacf` **scale the walk limit with the program.** The limit is max(4096, 2 x instructions) steps, linear per walk, and the walk uses id-indexed tables instead of hash sets. 3. `98f99d38` **loops.** A loop phi implies the write's exec if every incoming value does. The phi is assumed to imply it while its back-edge values are checked, and results that relied on a failed assumption are discarded. The write's exec must be computed outside any loop. 4. `83f8c193` **image reads** (@xXPBSXx, his `6f9f48d7` unchanged). `ImageRead` carries the exec as its last operand like the buffer loads and fetches only where it is true, so it joins `readsOnlyWhereActive`. 5. `fda4aa90` **image writes, explicit-LOD gathers and size queries.** `ImageWrite` stores inside an if on its exec operand, so it joins the exec-guarded list. `ImageGatherRaw` with its own LOD, or outside pixel shaders, and `ImageQueryDimensions` are lane-local. `ImageQueryLod`, implicit-LOD samples and gathers, `ImageBvhIntersectRay` and the atomics are left out. Not included: the rest of AlxcBTW/AnyPS5#37 (a whole ancillary word for reads the walk keeps, and the trace switch). A read the walk cannot drop is still refused; Returnal and Minecraft Dungeons II need that part. #2654 changes the visited storage of the same walk and conflicts with commit 2. ### Tested Linux (CachyOS, GCC 16.2.1, Release, CI's configure flags without ccache), RTX 4090 (NVIDIA 610.57.04), `main` 961b25fe plus the five commits: - `agc_masked_select` and `pixel_ancillary` pass. With `MaskedSelectEliminator.cpp` put back to `main`, both fail: `agc_masked_select` on the kill-chain, loop, image read, image write, gather and size-query cases, and `pixel_ancillary` with the refusal above. - `ctest -R "agc|shader"`: 349/350. Full `ctest`: 758 tests, 1 failure, 5 video-out tests skipped. The failure in both is `agc_driver_dcc_keys_first_write`, which fails the same way on `main` (#3179). - `tools/check_conventions.py` passes. - No title was run here. From #2548, on earlier states of the same commits: - Taxi Chaos 2 (PPSA30279, @AlxcBTW): all 54 dumped requests prepare with commit 1. - LEGO Horizon Adventures (PPSA14632, @alfalfa-star, Linux, RX 9070 XT, RADV): with commit 1 its one shader was still refused at the fixed walk limit and prepared with the limit raised to 8192. Commit 2 came from that; this thread has no rerun of it alone. - Returnal (PPSA01285, @xXPBSXx, Windows, RTX 4080 SUPER): with commits 1-3, 3 of the 6 refused shaders prepare and the title presents frames. With commit 4, `0x2026c60000` recompiles in `agc_shader_replay`. Two shaders stay refused and the title still aborts on one. - Demon Slayer (PPSA03490, @xXPBSXx): with commits 1-4, shaders refused at registration go from 5 to 2. The title still aborts. Runs of the whole fork branch (these commits plus the whole-word part): - Lies of P (PPSA10261) 16 to 0 refused shaders and Ad Infinitum (PPSA10600) 27 to 0 (@xXPBSXx, Windows). The trace switch was on and printed no line. At that state it printed one for every select the walk kept, so per @AlxcBTW the walk dropped every select in these two titles. - Stray (PPSA02100) 15 to 0 and Kena (PPSA01746) 4 to 0 (@xXPBSXx); LEGO Horizon Adventures 1 to 0, Stray 31 to 0 and Kena 30 to 0 (@fma-rc, Linux, RTX 5080). The thread does not show how many of these shaders the walk covers alone. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-11 07:19:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:19:38Z.


Checked on Linux (Release, partial build of libs + AGC): agc_masked_select and pixel_ancillary pass, and both fail with MaskedSelectEliminator.cpp reverted to main. ImageRead/ImageWrite take their exec as the last operand and the SPIR-V emitter guards them with it, so listing them as read-only-where-active is exact. Loop revival and wider-exec cases keep the select. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106613004 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3279#issuecomment-6106613004). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:19:38Z. --- Checked on Linux (Release, partial build of libs + AGC): `agc_masked_select` and `pixel_ancillary` pass, and both fail with `MaskedSelectEliminator.cpp` reverted to `main`. `ImageRead`/`ImageWrite` take their exec as the last operand and the SPIR-V emitter guards them with it, so listing them as read-only-where-active is exact. Loop revival and wider-exec cases keep the select. Merging.
Mouhand-Kaddo commented 2026-10-11 07:19:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:19:51Z.


Additional platform validation of standalone PR head fda4aa90c9f81fa3b5160150b3bee926b6923955 (2026-10-11):

Windows: passed — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release, BUILD_TESTING=ON.

2 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.

Checks: agc_masked_select, pixel_ancillary.

Command after building: ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^(agc_masked_select|pixel_ancillary)$".

This scope checks CPU-side behavior; no GPU execution result is claimed.

No title/gameplay validation. These results cover the standalone head, not a merge with current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106614763 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3279#issuecomment-6106614763). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-11T07:19:51Z. --- <!-- anyps5-platform-validation:fda4aa90c9f81fa3b5160150b3bee926b6923955 --> Additional platform validation of standalone PR head `fda4aa90c9f81fa3b5160150b3bee926b6923955` (2026-10-11): **Windows: passed** — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release, `BUILD_TESTING=ON`. 2 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run. Checks: `agc_masked_select`, `pixel_ancillary`. Command after building: `ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^(agc_masked_select|pixel_ancillary)$"`. This scope checks CPU-side behavior; no GPU execution result is claimed. No title/gameplay validation. These results cover the standalone head, not a merge with current main.
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!3279
No description provided.