fix(agc): retire the window imports that pin a range a guest unmap waits for #6182

Merged
XairRrR merged 7 commits from upstream-pr/6182 into main 2026-11-02 07:55:32 +00:00
XairRrR commented 2026-10-15 00:52:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-15T00:52:43Z.


What

A registered range larger than the import window is imported in windows (windowRun, 64 MiB by default), and every window's HostImport holds the whole range through range / ranges. When the guest unmaps or frees part of such a range, GuestAllocationsRequireUnpinned waits until no one else references the range, and the pin waiter (WaitForLeasesAndImports) retires the live and parked imports that overlap the unmapped bytes (#4291). The imports of the range's other windows do not overlap those bytes, so they keep the range pinned: the unmap waits out APS5_PIN_WAIT_MS and fails.

PPSA05684 (Uncharted: Legacy of Thieves Collection) hit this in its main menu and at the start of its first level: guest allocation 0x103da00000+0x100000 is still pinned by GPU work or an import (waited 60000 ms for the lease (APS5_PIN_WAIT_MS)), after leased allocation ... still pinned after 8 recorder syncs. The 1 MiB it unmaps lies inside a 1.4 GiB registered range that is imported in 64 MiB windows.

The waiter now retires the live and parked imports whose window overlaps the waited bytes or that hold a registered range overlapping them (holdsRangeOver), in the places that chose imports by window overlap only: the live imports (both waits), the parked imports, and on Windows the settle-retired imports (releaseSettleRetired, added on main since this PR was opened), which hold the same range until their batch is released.

Tested

Linux 7.2.9-zen, GCC, Ninja, Release, rebased on main 9caecfd2d:

  • All 701 agc_ tests pass. tools/check_conventions.py --base origin/main passes. The Windows settle path is not tested.
  • New agc_window_import_unmap (agc_driver_recorder_tests --window-import-unmap-only, APS5_PIN_WAIT_MS=3000): registers a range of four import windows, imports only the first window, then unmaps the third. With GuestBufferMemory.cpp from main it fails with the same error as the title: guest allocation 0x...+0x20000 is still pinned by GPU work or an import (waited 3000 ms for the lease (APS5_PIN_WAIT_MS)); with the change it passes.
  • PPSA05684 on a local stack (main plus #6003/#6004 and local depth patches): before the change, two of three runs ended in this abort within five minutes; after it, no run hit it again (runs end only on this machine's memory limit) and the title reaches gameplay.

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 under Silent stubs in their library's technical debt file
  • 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 (extends #4291)
  • Unblocks: PPSA05684 #4001 (guest unmap abort in the menu and first level)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER, driver 615.78.08, Linux 7.2.9-zen
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4866575503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6182). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-15T00:52:43Z. --- ### What A registered range larger than the import window is imported in windows (`windowRun`, 64 MiB by default), and every window's `HostImport` holds the whole range through `range` / `ranges`. When the guest unmaps or frees part of such a range, `GuestAllocationsRequireUnpinned` waits until no one else references the range, and the pin waiter (`WaitForLeasesAndImports`) retires the live and parked imports that overlap the unmapped bytes (#4291). The imports of the range's other windows do not overlap those bytes, so they keep the range pinned: the unmap waits out `APS5_PIN_WAIT_MS` and fails. PPSA05684 (Uncharted: Legacy of Thieves Collection) hit this in its main menu and at the start of its first level: `guest allocation 0x103da00000+0x100000 is still pinned by GPU work or an import (waited 60000 ms for the lease (APS5_PIN_WAIT_MS))`, after `leased allocation ... still pinned after 8 recorder syncs`. The 1 MiB it unmaps lies inside a 1.4 GiB registered range that is imported in 64 MiB windows. The waiter now retires the live and parked imports whose window overlaps the waited bytes **or** that hold a registered range overlapping them (`holdsRangeOver`), in the places that chose imports by window overlap only: the live imports (both waits), the parked imports, and on Windows the settle-retired imports (`releaseSettleRetired`, added on `main` since this PR was opened), which hold the same range until their batch is released. ### Tested Linux 7.2.9-zen, GCC, Ninja, Release, rebased on `main` 9caecfd2d: - All 701 `agc_` tests pass. `tools/check_conventions.py --base origin/main` passes. The Windows settle path is not tested. - New `agc_window_import_unmap` (`agc_driver_recorder_tests --window-import-unmap-only`, `APS5_PIN_WAIT_MS=3000`): registers a range of four import windows, imports only the first window, then unmaps the third. With `GuestBufferMemory.cpp` from `main` it fails with the same error as the title: `guest allocation 0x...+0x20000 is still pinned by GPU work or an import (waited 3000 ms for the lease (APS5_PIN_WAIT_MS))`; with the change it passes. - PPSA05684 on a local stack (`main` plus #6003/#6004 and local depth patches): before the change, two of three runs ended in this abort within five minutes; after it, no run hit it again (runs end only on this machine's memory limit) and the title reaches gameplay. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 (extends #4291) - [x] Unblocks: PPSA05684 #4001 (guest unmap abort in the menu and first level) - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER, driver 615.78.08, Linux 7.2.9-zen - [x] AI-assisted: yes
XairRrR commented 2026-10-18 10:57:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-18T10:57:45Z.


Rebased onto main 9caecfd2d as 2f540fa6d. main restructured WaitForLeasesAndImports, so I reapplied holdsRangeOver on main's version. main has also added a Windows-only release of settle-retired imports (releaseSettleRetired), which matched by window overlap only. Those imports hold the same range until their batch is released, so it now uses holdsRangeOver too. That path is untested here (Linux only). All 701 agc_ tests pass. agc_window_import_unmap still fails with GuestBufferMemory.cpp from main (pinned, waited 3000 ms). Description updated.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249008411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6182#issuecomment-6249008411). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-18T10:57:45Z. --- Rebased onto `main` 9caecfd2d as 2f540fa6d. `main` restructured `WaitForLeasesAndImports`, so I reapplied `holdsRangeOver` on `main`'s version. `main` has also added a Windows-only release of settle-retired imports (`releaseSettleRetired`), which matched by window overlap only. Those imports hold the same range until their batch is released, so it now uses `holdsRangeOver` too. That path is untested here (Linux only). All 701 `agc_` tests pass. `agc_window_import_unmap` still fails with `GuestBufferMemory.cpp` from `main` (pinned, waited 3000 ms). Description updated. AI-assisted: yes
oneandonlydean commented 2026-10-20 17:09:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T17:09:41Z.


Thanks. Linux CI passes agc_window_import_unmap, but on Windows it exits 0xc0000135 (DLL not found) in 0.01 s, before the test runs. The new test is missing from the if(WIN32) list in core/libs/prx/libSceAgcDriver/CMakeLists.txt that gives the agc_driver_recorder_tests modes ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>" (the set_tests_properties(agc_recorder_read_list agc_host_import_unmap agc_parked_import_unmap ... line). Without it the exe can't find libc on Windows. Could you add agc_window_import_unmap to that list, next to agc_parked_import_unmap?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6296620167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6182#issuecomment-6296620167). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T17:09:41Z. --- Thanks. Linux CI passes `agc_window_import_unmap`, but on Windows it exits `0xc0000135` (DLL not found) in 0.01 s, before the test runs. The new test is missing from the `if(WIN32)` list in `core/libs/prx/libSceAgcDriver/CMakeLists.txt` that gives the `agc_driver_recorder_tests` modes `ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>"` (the `set_tests_properties(agc_recorder_read_list agc_host_import_unmap agc_parked_import_unmap ...` line). Without it the exe can't find `libc` on Windows. Could you add `agc_window_import_unmap` to that list, next to `agc_parked_import_unmap`?
XairRrR commented 2026-10-20 19:26:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-20T19:26:28Z.


Added agc_window_import_unmap to the if(WIN32) ENVIRONMENT_MODIFICATION list next to agc_parked_import_unmap in b1501db95, and merged main (b1fe49bca) since main had changed the same line (agc_draw_inputs_copied). agc_window_import_unmap passes on Linux; I can't run the Windows job here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6299414361 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6182#issuecomment-6299414361). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-20T19:26:28Z. --- Added `agc_window_import_unmap` to the `if(WIN32)` `ENVIRONMENT_MODIFICATION` list next to `agc_parked_import_unmap` in b1501db95, and merged main (b1fe49bca) since main had changed the same line (`agc_draw_inputs_copied`). `agc_window_import_unmap` passes on Linux; I can't run the Windows job here.
TheSovietWaffle commented 2026-10-21 09:32:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-21T09:32:27Z.


Title data point for this together with #6565: Onimusha: Way of the Sword (PPSA27836), owned, Windows 10 Pro 22H2, RTX 3080 (NVIDIA 617.42), WinLibs GCC 15.2.0, Release, APS5_NO_HOST_IMPORT=1. Tree: main 1d4164552 plus a few open AGC/shader PRs and local workarounds for the #6570 and stencil-mask stops; the only change between the two runs below is #6182 + #6565 merged in.

  • Without them: about 7 minutes in, around the first story-mode load, the title aborts with guest allocation 0xe82bf60000+0x1a0000 is still pinned by GPU work or an import (waited 60000 ms for the lease (APS5_PIN_WAIT_MS)) (from a guest mutation in libc).
  • With both: the same path ran for about 2 hours 14 minutes without that abort or any other error, until the session was closed.

I merged both together, so this does not say which of the two is needed for this title; one run each.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312729663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6182#issuecomment-6312729663). Originally posted by [TheSovietWaffle](https://github.com/TheSovietWaffle) on 2026-10-21T09:32:27Z. --- Title data point for this together with #6565: Onimusha: Way of the Sword (PPSA27836), owned, Windows 10 Pro 22H2, RTX 3080 (NVIDIA 617.42), WinLibs GCC 15.2.0, Release, `APS5_NO_HOST_IMPORT=1`. Tree: `main` `1d4164552` plus a few open AGC/shader PRs and local workarounds for the #6570 and stencil-mask stops; the only change between the two runs below is #6182 + #6565 merged in. - Without them: about 7 minutes in, around the first story-mode load, the title aborts with `guest allocation 0xe82bf60000+0x1a0000 is still pinned by GPU work or an import (waited 60000 ms for the lease (APS5_PIN_WAIT_MS))` (from a guest mutation in `libc`). - With both: the same path ran for about 2 hours 14 minutes without that abort or any other error, until the session was closed. I merged both together, so this does not say which of the two is needed for this title; one run each. AI-assisted: yes (Claude Code).
XairRrR commented 2026-10-21 23:57:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-21T23:57:31Z.


Merged main (51d5f7e04): main added agc_idle_publish_wait on the same WIN32 ENVIRONMENT_MODIFICATION line and next to the --window-import-unmap-only mode in tests/Recorder.cpp; both kept. agc tests pass except agc_driver_sample_order*, which fail on main a6dcea927 too.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329247545 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6182#issuecomment-6329247545). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-21T23:57:31Z. --- Merged main (51d5f7e04): main added `agc_idle_publish_wait` on the same WIN32 `ENVIRONMENT_MODIFICATION` line and next to the `--window-import-unmap-only` mode in `tests/Recorder.cpp`; both kept. agc tests pass except `agc_driver_sample_order*`, which fail on main a6dcea927 too. AI-assisted: yes
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!6182
No description provided.