perf(agc): answer Refresh's registry and host-import lookups from an index and a cache #15674

Closed
oneandonlydean wants to merge 15 commits from upstream-pr/15674 into main
oneandonlydean commented 2026-11-04 03:15:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-04T03:15:28Z.


What

Carries #7514 by @AlxcBTW, with credit: the branch keeps their seven commits with their authorship, followed by merges of current main. The original is on a fork that is now archived, so it cannot take pushes; it also conflicts with current main.

StorageTexture::Refresh runs for every storage image a dispatch or draw reads or writes and looks up the same facts each time: which images pending in the same memory overlap it, which pending image sits at its address, and which host import holds its range. Three exact changes (the same answers, only cheaper to get), all turned off together by APS5_NO_REFRESH_LOOKUP_CACHE=1:

  1. The pending list keeps its images in a RangeIndex (new Graphics/include/RangeIndex.hpp), so overlap and same-address queries are O(log n + k) instead of a scan under the registry mutex.
  2. A whole-image Refresh of an image with block units, unchanged DCC keys and no pending alias, whose surface has no stamp since the image's generation, answers "unchanged" without building the per-unit state. Scoped Refreshes and compared ones take the old path (the follow-up commits fix the first version, which read past an empty changed list).
  3. Each StorageTexture remembers the host import its last Refresh lookup returned, with the range, the import table's epoch and an insert count, and HostImportForCached answers from it while all three are unchanged and the registry has not moved, with the same last-use stamps as a full hit.

Resolution of the merge with main, for the reviewer: the insert counter is main's HostImports::inserted (bumped only when an import is actually added, at the one insert site), which the lookup cache compares, instead of the original's own counter; GuestBufferMemory.hpp, Texture.hpp (UnitFlags borrowedUnits next to importLookup), HostImportRetireHold.cpp and ENVIRONMENT.md keep both sides; the test registrations live in tests/cmake/agc_range_index_tests.cmake.

Tested

  • Carry checks (ours, Linux workstation, on this branch): the three ctests that use the changed sources passed 3/3 with none skipped: agc_range_index, agc_host_import_retire, agc_host_import_retirement. The branch merges cleanly with main 04a9eb4fa2. Not run: Windows, macOS, the full suite, any GPU or game qualification.
  • The original author's measurements (Windows, NVIDIA, PPSA16064) were taken on lab builds and on their own head, not on this branch; see #7514. No new performance or game-gate result is claimed here, and perf numbers are still missing.

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; silent stubs are listed in technical debt
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: none on the carry
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5148217156 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15674). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-11-04T03:15:28Z. --- ### What Carries #7514 by @AlxcBTW, with credit: the branch keeps their seven commits with their authorship, followed by merges of current `main`. The original is on a fork that is now archived, so it cannot take pushes; it also conflicts with current `main`. `StorageTexture::Refresh` runs for every storage image a dispatch or draw reads or writes and looks up the same facts each time: which images pending in the same memory overlap it, which pending image sits at its address, and which host import holds its range. Three exact changes (the same answers, only cheaper to get), all turned off together by `APS5_NO_REFRESH_LOOKUP_CACHE=1`: 1. The pending list keeps its images in a `RangeIndex` (new `Graphics/include/RangeIndex.hpp`), so overlap and same-address queries are O(log n + k) instead of a scan under the registry mutex. 2. A whole-image Refresh of an image with block units, unchanged DCC keys and no pending alias, whose surface has no stamp since the image's generation, answers "unchanged" without building the per-unit state. Scoped Refreshes and compared ones take the old path (the follow-up commits fix the first version, which read past an empty `changed` list). 3. Each `StorageTexture` remembers the host import its last Refresh lookup returned, with the range, the import table's epoch and an insert count, and `HostImportForCached` answers from it while all three are unchanged and the registry has not moved, with the same last-use stamps as a full hit. Resolution of the merge with `main`, for the reviewer: the insert counter is `main`'s `HostImports::inserted` (bumped only when an import is actually added, at the one insert site), which the lookup cache compares, instead of the original's own counter; `GuestBufferMemory.hpp`, `Texture.hpp` (`UnitFlags borrowedUnits` next to `importLookup`), `HostImportRetireHold.cpp` and `ENVIRONMENT.md` keep both sides; the test registrations live in `tests/cmake/agc_range_index_tests.cmake`. ### Tested - Carry checks (ours, Linux workstation, on this branch): the three ctests that use the changed sources passed 3/3 with none skipped: `agc_range_index`, `agc_host_import_retire`, `agc_host_import_retirement`. The branch merges cleanly with `main` `04a9eb4fa2`. Not run: Windows, macOS, the full suite, any GPU or game qualification. - The original author's measurements (Windows, NVIDIA, PPSA16064) were taken on lab builds and on their own head, not on this branch; see #7514. No new performance or game-gate result is claimed here, and perf numbers are still missing. ### 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 - [x] Unimplemented paths throw; silent stubs are listed in technical debt - [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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: none on the carry - [x] AI-assisted: yes

Pull request closed

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!15674
No description provided.