fix(agc): let heap mirrors replace host imports when the import budget is full #12074

Merged
mehmetbayoglu merged 4 commits from upstream-pr/12074 into main 2026-10-29 23:20:40 +00:00
mehmetbayoglu commented 2026-10-27 18:57:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mehmetbayoglu on 2026-10-27T18:57:23Z.


What

Since #8380 imports a heap over the host import budget in pieces, the budget (8132 MiB here) can fill with imports that every address-based build uses. #11357 then protects every import used in the current or the previous frame, so none of them is evictable. Astro Bot (PPSA21567) has a working set of about 12 GiB and hits two problems:

  • Abort. When a registered range of about 1.1 GiB that is outside the write watch is re-registered, its import is refused and no mirror can serve it. The build's copy passes APS5_ADDRESS_COPY_MAX_MIB, the evicting retry finds nothing to evict, and the title stops with FATAL: an address-based build copies ~1.1 GiB ... import over the host import budget, heap not fully write-watched.
  • Copy storm. The address-space cache keeps the mirror of a heap whose range has left the write watch whenever the budget refuses that range's import. Such a mirror is refreshed in full at every use, so every build copied about 1.1 GiB and retried the import. That is thousands of refusals per run.

Many of the imports holding the budget cover a single releasable range that is still write-watched, so a heap mirror can serve that range just as well. This PR lets both paths evict those imports:

  • Copy cap path (AcquireRegistered): the evicting retry for a range only an import serves may also evict imports whose single range is releasable and write-watched, even inside the frame protection, as long as the current build has not taken them yet. The build then serves those ranges from heap mirrors. Remembered refusals are not used for this retry.
  • Address-space cache check (importsNow): for a cached heap mirror that left the write watch, the import attempt now evicts the same way, with the imports of earlier builds no longer held, instead of the non-evicting attempt that was refused every time.

Other requests keep the current eviction rules. The debt entry for host import windows and budget describes the new eviction.

Checked against open and merged PRs:

  • #7844 (keep at most 4 GiB of the host heap from the budget) raises the default budget. That only hides the problem on machines with more than 8 GiB of host heap; once the working set fills the larger budget, it behaves the same.
  • #11357 (do not evict host imports used in the current or previous frame, merged) makes the abort more likely: imports used in every frame are never idle.

Neither fixes it.

Tested

Windows 11 Pro, MinGW GCC (winlibs), Release, NVIDIA GeForce RTX 4070 Ti. main is 14332cd8d0; each tree was built in its own build directory.

New tests (each runs with 0, 1 and 2 frames ended, so both the lookup-count rule and the two-frame rule are covered):

  • agc_address_copy_cap_mirror: a build past the copy cap needs a range outside the write watch while the budget is held by a recently used, write-watched import.
    • On main with only this PR's test changes: aborts with FATAL: an address-based build copies 2 MiB of 1 registered ranges, past 1 MiB (APS5_ADDRESS_COPY_MAX_MIB); ... (2.0 MiB committed, import over the host import budget, heap not fully write-watched), the same abort as in Astro Bot.
    • With this PR: passes. The range is imported and the write-watched range is served from a heap mirror that holds the guest bytes.
  • agc_address_space_unwatched_mirror_import: a cached heap mirror leaves the write watch while the budget is held by another heap's import.
    • On main with only the test changes: fails (a heap whose mirror left the write watch was not imported in place of an import a mirror can replace).
    • With this PR: passes.
  • agc_heap_mirror_unwatch now takes its idle and busy ranges out of the write watch on Windows, so they are outside it as on Linux (where only the heap is registered) and a mirror cannot stand in for them. It passes on main and with this PR.

AGC suite, ctest -R "agc|shader_cache" -j 4:

  • main: 1107 of 1108 pass.
  • This PR: 1109 of 1110 pass.
  • The one failure is the same on both: agc_driver_mesh_barycentric_emulation (the pixel shader did not emulate barycentrics). It does not touch host imports.

Validation layer: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R "agc_address|agc_heap_mirror|host_import" -V

  • main: 19 of 19 pass.
  • This PR: 21 of 21 pass.
  • agc_host_import_sparse is skipped on both (udmabuf imports are Linux only).
  • Neither log has the "was not found but was requested by env var VK_INSTANCE_LAYERS" line. Both have 0 VUID- messages over 7 real devices. The new tests run against the mock Vulkan device, so the layer does not see them.

Astro Bot (PPSA21567), Windows, RTX 4070 Ti. Measured on our integration tree with the pin fix (#6182's change) and #11307, not on plain main:

Before With this change
Copy cap aborts 3 in about 12 runs 0 in 6 runs
Import refusals per run 6,000 to 28,000 72 to 308

Black Ops (BO1) output is identical on the same tree (byte-equal frames and draw records in a strict frame replay). This PR makes no speed claim.

python3 tools/check_conventions.py --base origin/main reports no errors and one warning: the host import debt entry, already over 1000 characters on main, grows by about 340.

python3 tools/pr_overlap.py reports one conflict: #7844 edits the same debt entry (docs/dev/debt/libSceAgcDriver.md L261). Either order is fine with me; the maintainers can choose. If #7844 lands first, this PR rebases on it, keeps both debt updates, and sets Depends on: #7844.

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
  • Fixes: none
  • Unblocks: PPSA21567 Astro Bot #11917
  • GPUs tested: AGC on NVIDIA GeForce RTX 4070 Ti, driver 617.42 (Windows 11 Pro)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5039478037 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12074). Originally posted by [mehmetbayoglu](https://github.com/mehmetbayoglu) on 2026-10-27T18:57:23Z. --- ### What Since #8380 imports a heap over the host import budget in pieces, the budget (8132 MiB here) can fill with imports that every address-based build uses. #11357 then protects every import used in the current or the previous frame, so none of them is evictable. Astro Bot (PPSA21567) has a working set of about 12 GiB and hits two problems: - **Abort.** When a registered range of about 1.1 GiB that is outside the write watch is re-registered, its import is refused and no mirror can serve it. The build's copy passes `APS5_ADDRESS_COPY_MAX_MIB`, the evicting retry finds nothing to evict, and the title stops with `FATAL: an address-based build copies ~1.1 GiB ... import over the host import budget, heap not fully write-watched`. - **Copy storm.** The address-space cache keeps the mirror of a heap whose range has left the write watch whenever the budget refuses that range's import. Such a mirror is refreshed in full at every use, so every build copied about 1.1 GiB and retried the import. That is thousands of refusals per run. Many of the imports holding the budget cover a single releasable range that is still write-watched, so a heap mirror can serve that range just as well. This PR lets both paths evict those imports: - **Copy cap path** (`AcquireRegistered`): the evicting retry for a range only an import serves may also evict imports whose single range is releasable and write-watched, even inside the frame protection, as long as the current build has not taken them yet. The build then serves those ranges from heap mirrors. Remembered refusals are not used for this retry. - **Address-space cache check** (`importsNow`): for a cached heap mirror that left the write watch, the import attempt now evicts the same way, with the imports of earlier builds no longer held, instead of the non-evicting attempt that was refused every time. Other requests keep the current eviction rules. The debt entry for host import windows and budget describes the new eviction. Checked against open and merged PRs: - #7844 (keep at most 4 GiB of the host heap from the budget) raises the default budget. That only hides the problem on machines with more than 8 GiB of host heap; once the working set fills the larger budget, it behaves the same. - #11357 (do not evict host imports used in the current or previous frame, merged) makes the abort more likely: imports used in every frame are never idle. Neither fixes it. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro, MinGW GCC (winlibs), Release, NVIDIA GeForce RTX 4070 Ti. `main` is 14332cd8d0; each tree was built in its own build directory. **New tests** (each runs with 0, 1 and 2 frames ended, so both the lookup-count rule and the two-frame rule are covered): - `agc_address_copy_cap_mirror`: a build past the copy cap needs a range outside the write watch while the budget is held by a recently used, write-watched import. - On `main` with only this PR's test changes: aborts with `FATAL: an address-based build copies 2 MiB of 1 registered ranges, past 1 MiB (APS5_ADDRESS_COPY_MAX_MIB); ... (2.0 MiB committed, import over the host import budget, heap not fully write-watched)`, the same abort as in Astro Bot. - With this PR: passes. The range is imported and the write-watched range is served from a heap mirror that holds the guest bytes. - `agc_address_space_unwatched_mirror_import`: a cached heap mirror leaves the write watch while the budget is held by another heap's import. - On `main` with only the test changes: fails (`a heap whose mirror left the write watch was not imported in place of an import a mirror can replace`). - With this PR: passes. - `agc_heap_mirror_unwatch` now takes its idle and busy ranges out of the write watch on Windows, so they are outside it as on Linux (where only the heap is registered) and a mirror cannot stand in for them. It passes on `main` and with this PR. **AGC suite**, `ctest -R "agc|shader_cache" -j 4`: - `main`: 1107 of 1108 pass. - This PR: 1109 of 1110 pass. - The one failure is the same on both: `agc_driver_mesh_barycentric_emulation` (`the pixel shader did not emulate barycentrics`). It does not touch host imports. **Validation layer**: `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -R "agc_address|agc_heap_mirror|host_import" -V` - `main`: 19 of 19 pass. - This PR: 21 of 21 pass. - `agc_host_import_sparse` is skipped on both (udmabuf imports are Linux only). - Neither log has the "was not found but was requested by env var VK_INSTANCE_LAYERS" line. Both have 0 `VUID-` messages over 7 real devices. The new tests run against the mock Vulkan device, so the layer does not see them. **Astro Bot (PPSA21567)**, Windows, RTX 4070 Ti. Measured on our integration tree with the pin fix (#6182's change) and #11307, not on plain `main`: | | Before | With this change | |---|---|---| | Copy cap aborts | 3 in about 12 runs | 0 in 6 runs | | Import refusals per run | 6,000 to 28,000 | 72 to 308 | Black Ops (BO1) output is identical on the same tree (byte-equal frames and draw records in a strict frame replay). This PR makes no speed claim. `python3 tools/check_conventions.py --base origin/main` reports no errors and one warning: the host import debt entry, already over 1000 characters on `main`, grows by about 340. `python3 tools/pr_overlap.py` reports one conflict: #7844 edits the same debt entry (`docs/dev/debt/libSceAgcDriver.md` L261). Either order is fine with me; the maintainers can choose. If #7844 lands first, this PR rebases on it, keeps both debt updates, and sets `Depends on: #7844`. ### 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 - [x] Fixes: none - [x] Unblocks: PPSA21567 Astro Bot #11917 - [x] GPUs tested: AGC on NVIDIA GeForce RTX 4070 Ti, driver 617.42 (Windows 11 Pro) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-27 19:00:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T19:00:28Z.

Review: CHANGES_REQUESTED


The two new regression scenarios target the reported failure modes, and the implementation only yields single-range, releasable, currently watched imports to mirrors. Exact-head conventions checks report no errors (with the existing debt-length warning), git diff --check is clean, and the branch merges cleanly with current main. The hosted Windows build has not finished, so I have not assessed its result yet.

Please resolve the remaining contribution-rule items before merge:

  1. The PR reports 5 fps versus 11–17 fps, but provides neither matched main/change summary lines nor attached traces. CONTRIBUTING.md requires the performance-report artifacts for speed claims. Please add a current-main comparison from the same title, scene and machine with the traces and digest, or remove the speed comparison and keep the claim focused on correctness/avoiding the abort and repeated copies.
  2. The body identifies a real debt-file conflict with open #7844, but says only that whoever lands second must rebase; Depends on: none does not record an agreed order. Please coordinate which PR lands first with its author and declare that dependency/order in the checklist, while preserving both debt updates.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5672725924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12074#pullrequestreview-5672725924). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T19:00:28Z. **Review:** CHANGES_REQUESTED --- The two new regression scenarios target the reported failure modes, and the implementation only yields single-range, releasable, currently watched imports to mirrors. Exact-head conventions checks report no errors (with the existing debt-length warning), `git diff --check` is clean, and the branch merges cleanly with current `main`. The hosted Windows build has not finished, so I have not assessed its result yet. Please resolve the remaining contribution-rule items before merge: 1. The PR reports 5 fps versus 11–17 fps, but provides neither matched `main`/change summary lines nor attached traces. `CONTRIBUTING.md` requires the performance-report artifacts for speed claims. Please add a current-main comparison from the same title, scene and machine with the traces and digest, or remove the speed comparison and keep the claim focused on correctness/avoiding the abort and repeated copies. 2. The body identifies a real debt-file conflict with open #7844, but says only that whoever lands second must rebase; `Depends on: none` does not record an agreed order. Please coordinate which PR lands first with its author and declare that dependency/order in the checklist, while preserving both debt updates.
MarcZX10 commented 2026-10-29 09:25:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:25:10Z.

Review: CHANGES_REQUESTED


Re-review — changes requested

The latest description now explicitly makes no speed claim and focuses on the correctness result: the copy-cap abort is avoided and repeated full-range copies/import refusals are reduced. That resolves my earlier request for matched performance-report artifacts or removal of the speed comparison. The author reports the two new regression tests pass with this change and fail on main; I did not rerun them locally.

Two integration items remain:

  1. The reported test baseline and PR base are 14332cd8d0, while current upstream main is aaccd0ba39b7. Please refresh onto current main and rerun the focused address-copy/import tests on the exact resulting head.
  2. The debt-file conflict with open #7844 is still unresolved. The author says either order is acceptable and leaves the choice to maintainers, but the checklist still says Depends on: none, and neither PR records an agreed order. Please get that order selected and recorded on both sides; if #7844 lands first, preserve its debt edit while rebasing this PR as described.

The authored Windows/AGC suite report is useful, but the hosted Linux product job is skipped and I did not run a local GPU build. I am holding approval for the current-main and overlap items, not for the removed speed claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5695446797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12074#pullrequestreview-5695446797). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T09:25:10Z. **Review:** CHANGES_REQUESTED --- # Re-review — changes requested The latest description now explicitly makes no speed claim and focuses on the correctness result: the copy-cap abort is avoided and repeated full-range copies/import refusals are reduced. That resolves my earlier request for matched performance-report artifacts or removal of the speed comparison. The author reports the two new regression tests pass with this change and fail on main; I did not rerun them locally. Two integration items remain: 1. The reported test baseline and PR base are `14332cd8d0`, while current upstream main is `aaccd0ba39b7`. Please refresh onto current main and rerun the focused address-copy/import tests on the exact resulting head. 2. The debt-file conflict with open #7844 is still unresolved. The author says either order is acceptable and leaves the choice to maintainers, but the checklist still says `Depends on: none`, and neither PR records an agreed order. Please get that order selected and recorded on both sides; if #7844 lands first, preserve its debt edit while rebasing this PR as described. The authored Windows/AGC suite report is useful, but the hosted Linux product job is skipped and I did not run a local GPU build. I am holding approval for the current-main and overlap items, not for the removed speed claim.
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!12074
No description provided.