fix(agc): retire host imports of ranges mapped again #1235

Merged
CnRJay merged 1 commit from upstream-pr/1235 into main 2026-10-08 02:17:35 +00:00
CnRJay commented 2026-10-07 18:56:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-07T18:56:37Z.


What

refreshImports and importAllocation keep a host import whenever the registry still holds a range with the same base and size. A fixed remap into a registered range (RemapFixedIntoRegistered) replaces the registry range at the same base and size, so the old import survives. The GPU then keeps reading the pages it pinned, or the alias view it mapped, before the remap. The CPU sees the new memory.

  • HostImport keeps a weak_ptr to the registry Range it was made from. A shared_ptr would be a lease, and the remap would wait for it forever.
  • An import is kept only while the registry range at its base is that same object (owner_before comparison, so a freed and reallocated range cannot alias). Otherwise it is retired and made again.
  • APS5_TRACE_HOST_IMPORT logs retired: the range was mapped again.

Registry ranges are only replaced by add, unmap and protect mutations of that range, so imports of untouched ranges are unaffected.

Interaction with #290: its refreshImports keeps an import while any containing range exists. With import windows, the identity to compare would be the containing range's.

Tested

Windows 11, MinGW, NVIDIA RTX (Vulkan).

  • PPSA23566 (UFC 6) re-maps its 0x3c… render-target pool during loading. The trace shows those 8 MiB imports retired. The game builds a per-tile UI mask from the UI target's CMASK, read as an 8_UINT buffer through the import. Before this change every load returned 0 (the old pages), the composite skipped the UI on every tile, and only black was presented. APS5_NO_HOST_IMPORT=1 also fixed the load, which isolated the import. With this change (and a CMASK fast-clear model as in #1072) the EA SPORTS splash renders.
  • New remappedImportTests in agc_driver_recorder_tests: remove and re-add a registered block at the same base and size, then require a new import serial. It fails on main with the import of a range mapped again was kept and passes with the change. The rest of the binary passes too.
  • ctest: 395 of 395 pass.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4777093873 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1235). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-07T18:56:37Z. --- ### What `refreshImports` and `importAllocation` keep a host import whenever the registry still holds a range with the same base and size. A fixed remap into a registered range (`RemapFixedIntoRegistered`) replaces the registry range at the same base and size, so the old import survives. The GPU then keeps reading the pages it pinned, or the alias view it mapped, before the remap. The CPU sees the new memory. - `HostImport` keeps a `weak_ptr` to the registry `Range` it was made from. A `shared_ptr` would be a lease, and the remap would wait for it forever. - An import is kept only while the registry range at its base is that same object (`owner_before` comparison, so a freed and reallocated range cannot alias). Otherwise it is retired and made again. - `APS5_TRACE_HOST_IMPORT` logs `retired: the range was mapped again`. Registry ranges are only replaced by add, unmap and protect mutations of that range, so imports of untouched ranges are unaffected. Interaction with #290: its `refreshImports` keeps an import while any containing range exists. With import windows, the identity to compare would be the containing range's. ### Tested Windows 11, MinGW, NVIDIA RTX (Vulkan). - PPSA23566 (UFC 6) re-maps its 0x3c… render-target pool during loading. The trace shows those 8 MiB imports retired. The game builds a per-tile UI mask from the UI target's CMASK, read as an 8_UINT buffer through the import. Before this change every load returned 0 (the old pages), the composite skipped the UI on every tile, and only black was presented. `APS5_NO_HOST_IMPORT=1` also fixed the load, which isolated the import. With this change (and a CMASK fast-clear model as in #1072) the EA SPORTS splash renders. - New `remappedImportTests` in `agc_driver_recorder_tests`: remove and re-add a registered block at the same base and size, then require a new import serial. It fails on `main` with `the import of a range mapped again was kept` and passes with the change. The rest of the binary passes too. - `ctest`: 395 of 395 pass. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-07 21:35:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-07T21:35:52Z.


Thanks, the cause and the test are clear. This is being tested now, together with #1237.

Because a whole-range protect also replaces the Range object (replaceRange in GuestAllocations.cpp), a title that re-protects whole registered ranges will now re-import them each time. The testing compares host-import creations and retirements with main under APS5_TRACE_HOST_IMPORT, to check that this doesn't become a re-import storm.

This conflicts with #290 in GuestBufferMemory.cpp, so whichever merges second needs a rebase. I'll post the results here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6047324118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1235#issuecomment-6047324118). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-07T21:35:52Z. --- Thanks, the cause and the test are clear. This is being tested now, together with #1237. Because a whole-range protect also replaces the `Range` object (`replaceRange` in `GuestAllocations.cpp`), a title that re-protects whole registered ranges will now re-import them each time. The testing compares host-import creations and retirements with `main` under `APS5_TRACE_HOST_IMPORT`, to check that this doesn't become a re-import storm. This conflicts with #290 in `GuestBufferMemory.cpp`, so whichever merges second needs a rebase. I'll post the results here.
github-actions[bot] commented 2026-10-08 01:02:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T01:02:13Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1357 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L326-330, L355, L475-477
#1359 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L326-330, L355, L475-477
#1361 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L326-330, L355, L475-477
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6049997468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1235#issuecomment-6049997468). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T01:02:13Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1357 | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L326-330](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L326-L330), [L355](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L355), [L475-477](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L475-L477) | | | | #1359 | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L326-330](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L326-L330), [L355](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L355), [L475-477](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L475-L477) | | | | #1361 | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L326-330](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L326-L330), [L355](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L355), [L475-477](https://github.com/boykopovar/AnyPS5/blob/39dd0b6cf01d968b86cee7e6050a08a8cb8f816c/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L475-L477) | | |
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!1235
No description provided.