fix(recompiler): clone small return blocks shared by early exits #2201

Merged
XairRrR merged 1 commit from upstream-pr/2201 into main 2026-10-10 06:59:15 +00:00
XairRrR commented 2026-10-09 11:29:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-09T11:29:43Z.


What

A pixel shader of Uncharted: Legacy of Thieves Collection (PPSA05684) stops on main with:

conditional block 15 has no structured merge

Its early discards all branch to one small ending block, which then has several conditional predecessors outside any loop. When the regular pass throws, the structurizer now restarts from the original graph and first gives each such predecessor its own copy of the return block (at most CloneWordFloor words, a budget of four clones per block). Test sharedDiscard in tests/Structurizer.cpp uses the shader's block sizes and fails without the fix.

Tested

Arch Linux, GCC 16.2.1, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.71.09).

  • The branch alone on current main (d70b8998): tools/check_conventions.py passes; of the 513 ctest tests all pass except agc_driver_dcc_keys_first_write, which fails the same way on main (an unchanged pending image was uploaded again). agc_driver_storage_cache_budget passes run alone; under ctest -j8 a local 3 GB RSS limit stopped it.
  • Uncharted: Legacy of Thieves Collection (PPSA05684): with this and the other changes of its bring-up, the title boots past the stop quoted above and reaches its main menu.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4799797715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2201). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-09T11:29:43Z. --- ### What A pixel shader of Uncharted: Legacy of Thieves Collection (PPSA05684) stops on `main` with: ``` conditional block 15 has no structured merge ``` Its early discards all branch to one small ending block, which then has several conditional predecessors outside any loop. When the regular pass throws, the structurizer now restarts from the original graph and first gives each such predecessor its own copy of the return block (at most `CloneWordFloor` words, a budget of four clones per block). Test `sharedDiscard` in `tests/Structurizer.cpp` uses the shader's block sizes and fails without the fix. ### Tested Arch Linux, GCC 16.2.1, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.71.09). - The branch alone on current `main` (d70b8998): `tools/check_conventions.py` passes; of the 513 ctest tests all pass except `agc_driver_dcc_keys_first_write`, which fails the same way on `main` (`an unchanged pending image was uploaded again`). `agc_driver_storage_cache_budget` passes run alone; under `ctest -j8` a local 3 GB RSS limit stopped it. - Uncharted: Legacy of Thieves Collection (PPSA05684): with this and the other changes of its bring-up, the title boots past the stop quoted above and reaches its main menu. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
rmz-24 commented 2026-10-09 13:07:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T13:07:48Z.


Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON, full build plus libs. 49e5143c cherry-picked onto current main d70b8998 (applies cleanly).

  • On this host agc_driver_dcc_keys_first_write passes on main and with this change, so the failure noted in the description (an unchanged pending image was uploaded again) doesn't reproduce on Windows/NVIDIA. agc_driver_storage_cache_budget also passes under ctest -j8 here (14 s).
  • Full ctest: 510/510.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6081508293 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2201#issuecomment-6081508293). Originally posted by [rmz-24](https://github.com/rmz-24) on 2026-10-09T13:07:48Z. --- Windows run: Windows 11 Pro 25H2 (10.0.26200.9457), RTX 5060 Ti (NVIDIA 617.42), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`, full build plus `libs`. 49e5143c cherry-picked onto current `main` d70b8998 (applies cleanly). - On this host `agc_driver_dcc_keys_first_write` passes on `main` and with this change, so the failure noted in the description (`an unchanged pending image was uploaded again`) doesn't reproduce on Windows/NVIDIA. `agc_driver_storage_cache_budget` also passes under `ctest -j8` here (14 s). - Full ctest: 510/510. AI-assisted: yes
adriadam10 commented 2026-10-10 06:49:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:49:27Z.


Rebased onto current main (only conflict: the new sharedDiscard case sits next to the "chain of fifty selections" case in tests/Structurizer.cpp; kept both). Built and ran the AGC/AgcDriver ctest scope: 323/323 pass, including agc_structurizer. The sharedDiscard case failed without the Structurizer change in the earlier check, and the Windows run by @rmz-24 passed. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094816256 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2201#issuecomment-6094816256). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:49:27Z. --- Rebased onto current `main` (only conflict: the new `sharedDiscard` case sits next to the "chain of fifty selections" case in `tests/Structurizer.cpp`; kept both). Built and ran the AGC/AgcDriver ctest scope: 323/323 pass, including `agc_structurizer`. The `sharedDiscard` case failed without the Structurizer change in the earlier check, and the Windows run by @rmz-24 passed. Merging.
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!2201
No description provided.