fix(agc): keep heap mirror slabs within device memory #15295

Open
Prophet069 wants to merge 7 commits from upstream-pr/15295 into main
Prophet069 commented 2026-11-02 23:01:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Prophet069 on 2026-11-02T23:01:04Z.


What

A heap mirror slab refused by a full device heap stopped the title. The slab now falls back to host memory, as buffers and images already do, and a refusal lowers the heap mirror budget, evicts down to it and retries; a failed bind gives back the blocks it took.

Slabs are refused before the device heap is exhausted: when all live slabs would pass APS5_HEAP_MIRROR_MIB or when the device heap would keep less than 256 MiB of its reported budget, so the shrink and sweep path runs before Windows starts paging device memory. A budget lowered by refusals is a soft target that a mirror may pass up to the configured budget when nothing can be evicted, and the headroom refusal is not repeated within two seconds on the same thread.

Blocks are taken from the fullest slab, so partly used slabs drain and are freed instead of every slab staying partly used after evictions.

Nonzero scans of a heap remember each 64 KiB block with its write generation and read only blocks written since, instead of reading the whole multi-GiB heap again on every rebuild.

Tested

NVIDIA GeForce RTX 3080 Laptop GPU, driver 616.64, Windows 10 Pro 22H2 (19045.6466).
Focused tests on main (9090972b7e) and on this branch with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1, ctest -V -R "heap_mirror|^agc_driver_graphics$|^agc_driver_key_miss$|^agc_driver_bda_device$|^agc_driver_recorder$|native_multisample_depth|depth_storage|^agc_host_import_retire$|^agc_host_import_sparse$":

  • main: 17 of 20 selected tests passed (agc_host_import_sparse skips on this machine; the three agc_driver_depth_storage_* tests were not built in this run); validation layer loaded in both logs; VUID- errors: none.
  • this branch: 17 of 20 selected tests passed (agc_host_import_sparse skips on this machine; the three agc_driver_depth_storage_* tests were not built in this run), the same as main; VUID- errors: none.
  • Death Stranding 2 (PPSA02015), local integration branch with the GPU heap path pull requests: before this series the title stopped on a heap mirror slab allocation (device heap 8461/7235 MiB); with it the slab moves to host memory or the budget shrinks, and the title reached its main menu and game world.

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: PPSA02015 #5424
  • GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 616.64, Windows 10 Pro 22H2 (19045.6466)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5128809900 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295). Originally posted by [Prophet069](https://github.com/Prophet069) on 2026-11-02T23:01:04Z. --- ### What A heap mirror slab refused by a full device heap stopped the title. The slab now falls back to host memory, as buffers and images already do, and a refusal lowers the heap mirror budget, evicts down to it and retries; a failed bind gives back the blocks it took. Slabs are refused before the device heap is exhausted: when all live slabs would pass `APS5_HEAP_MIRROR_MIB` or when the device heap would keep less than 256 MiB of its reported budget, so the shrink and sweep path runs before Windows starts paging device memory. A budget lowered by refusals is a soft target that a mirror may pass up to the configured budget when nothing can be evicted, and the headroom refusal is not repeated within two seconds on the same thread. Blocks are taken from the fullest slab, so partly used slabs drain and are freed instead of every slab staying partly used after evictions. Nonzero scans of a heap remember each 64 KiB block with its write generation and read only blocks written since, instead of reading the whole multi-GiB heap again on every rebuild. ### Tested NVIDIA GeForce RTX 3080 Laptop GPU, driver 616.64, Windows 10 Pro 22H2 (19045.6466). Focused tests on `main` (9090972b7e) and on this branch with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1`, `ctest -V -R "heap_mirror|^agc_driver_graphics$|^agc_driver_key_miss$|^agc_driver_bda_device$|^agc_driver_recorder$|native_multisample_depth|depth_storage|^agc_host_import_retire$|^agc_host_import_sparse$"`: - `main`: 17 of 20 selected tests passed (agc_host_import_sparse skips on this machine; the three agc_driver_depth_storage_* tests were not built in this run); validation layer loaded in both logs; `VUID-` errors: none. - this branch: 17 of 20 selected tests passed (agc_host_import_sparse skips on this machine; the three agc_driver_depth_storage_* tests were not built in this run), the same as main; `VUID-` errors: none. - Death Stranding 2 (PPSA02015), local integration branch with the GPU heap path pull requests: before this series the title stopped on a heap mirror slab allocation (device heap 8461/7235 MiB); with it the slab moves to host memory or the budget shrinks, and the title reached its main menu and game world. ### 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 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: PPSA02015 #5424 - [x] GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 616.64, Windows 10 Pro 22H2 (19045.6466) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
XairRrR commented 2026-11-03 00:10:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T00:10:49Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The merged tree builds and the heap mirror and resident tests pass. However, a new pre-allocation refusal can now stop a title on a nearly full device heap when the heap mirrors hold 256 MiB or less, where main would have tried the allocation. None of the new paths has a test.

What I ran

Head 1743177ae4af40502f26cd384d2376d555074681, main 5cb015caaaaf83f8ee431414ee6a457b5b307d49, merged tree 7895dfbc86c6627273ff29b2d3bbc7eed5af335f.

git diff --check 5cb015caaaaf83f8ee431414ee6a457b5b307d49...1743177ae4af40502f26cd384d2376d555074681
python3 tools/check_conventions.py --base 5cb015caaaaf83f8ee431414ee6a457b5b307d49
ctest --test-dir build --output-on-failure -R "^agc_driver_image_sample_lod_clamp_shader_lane$|^unwrap_self_UnwrapTest_test_new_output_inherits"
# the PR's 4 production files restored from main:
ninja -C build -j32 -l32 agc_driver_image_sample_lod_clamp_tests
ctest --test-dir build --output-on-failure -R "^agc_driver_image_sample_lod_clamp_shader_lane$"
# merged files restored, git status --porcelain empty:
ninja -C build -j32 -l32
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "heap_mirror|resident|host_import|partially_resident"

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) ok
Script test run 2178 ran; 2 not on the baseline's failure list, neither caused by the PR (see below); 6 known failures that also fail on main
agc_driver_image_sample_lod_clamp_shader_lane fails with the PR, and still fails after the PR's production files are restored from main 5cb015ca. The baseline (096c4557) is older, so this failure comes from main, not this PR.
unwrap_self_..._destination_directory_group fails at os.chown on a temporary directory (EINVAL). This is a tools/ Python test the PR doesn't touch, and the failure comes from the sandbox.
Heap mirror, resident and host-import tests (27) 26 passed, 1 skipped (agc_host_import_sparse, an expected skip)
Validation layer (script, 759 tests) layer loaded in 758, missing in none; new VUID- lines: 0
lod_clamp failure, same output with the PR and on main
AGC graphics: image_sample_lz through the S# that holds the LOD at 0 with T# MIN_LOD 768 over BASE_LEVEL 0 with a second S# of words 1 0 and 2 5242880, and a second T# of MIN_LOD 0 and LAST_LEVEL 0: thread 0 component 1 is 0.000000, expected 0.062500

Negative control

There is none, because the PR adds and changes no tests. I used the restore-from-main procedure only to clear the PR of the lod_clamp failure (see Results).

Findings

Blocking

  1. The headroom refusal stops the title when the heap mirrors hold 256 MiB or less. In core/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cpp:153, Take() calls refuseSlab() before any vkAllocateMemory. At ResidentMirror.cpp:188, refuseSlab() throws when the device heap would keep less than 256 MiB of its reported budget. The only recovery is shrinkHeapMirrorBudget, and it returns false when held <= step (256 MiB) (core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:2823). Both callers then rethrow the error wrapped in heapMirrorError:

    • growResident at GuestBufferMemory.cpp:2852-2866;
    • acquireMirror at GuestBufferMemory.cpp:3396-3407.

    So when the device heap is close to its budget for reasons other than the heap mirrors (textures, render targets), the first slab of a small mirror is refused with nothing to evict, and the title stops. On main the same slab would go to vkAllocateMemory. With this PR it would even fall back to host memory, but that fallback is never reached. This is most likely on GPUs with little VRAM, which this PR is meant to help.

    The APS5_HEAP_MIRROR_MIB refusal at ResidentMirror.cpp:184 hits the same dead end. It counts whole 16 MiB slabs, fragmentation included, while state.heapBytes counts only accounted blocks. A small configured budget can therefore refuse a slab while held <= 256 MiB.

    Suggested fix: treat a refusal as a request to shrink and sweep, not as a final error. When shrinkHeapMirrorBudget can't lower anything, or the retries run out, go on to the real allocation and its host-memory fallback. Add a test that sets a heap budget the refusal triggers on (or a test hook for ReportedHeap) with fewer than 256 MiB of mirrors, and checks that the mirror is still created.

  2. None of the new behaviour has a test. The PR changes several things:

    • slab refusal at the configured budget and at device headroom;
    • budget shrink and retry;
    • the host-memory fallback for slabs;
    • returning blocks when Bind fails partway;
    • taking blocks from the fullest slab;
    • the generation-keyed nonzero-scan cache.

    It adds no test for any of them. All 27 existing heap mirror, resident and host-import tests pass with and without the change, so none of them covers these paths. Finding 1 shows a regression these paths can hide. At least the refusal/shrink/retry path and the Bind give-back need a test that fails on main (SetHeapMirrorBudget already exists for that). A scan-cache test should write a block after a first scan and check that the next scan sees it.

Non-blocking

  1. The scan cache trusts UnchangedSince even for content the write watch may not record. At ResidentMirror.cpp:401, a cached "zero" result is reused while GuestMemory::UnchangedSince holds. On Windows, possiblyNonzero returns the whole range as readable, so the result there depends entirely on the write watch. docs/dev/debt/libc.md describes direct-memory pages that are kept in a private reservation while unmapped and mapped again later, and pages mapped at a second address that become views tracked by write protection. Content can then appear at a guest address without a CPU write there. If no stamp covers that case, the mirror leaves a nonzero block unbacked, and the GPU reads zeros. Please confirm that guest maps and alias writes stamp the tracker, or use CollectCommittedWrites/UnchangedCommittedSince (which also check refusals). If neither covers it, record the gap in docs/dev/debt/libSceAgcDriver.md.
  2. The scan cache can use a lot of host memory. At ResidentMirror.cpp:382-383, the map grows to 2^22 entries before it is cleared. That is a few hundred MiB of unordered_map nodes and buckets for a process-lifetime cache, and the whole cache is then dropped at once. A per-heap bitmap of generations, or a smaller limit, would bound this better.
  3. The lowered budget never recovers. heapMirrorMemoryLimit (GuestBufferMemory.cpp:2714) is only ever set from the current heapBytes minus 256 MiB, never back toward the configured budget. A single transient headroom refusal, for example during a loading spike, caps the heap mirrors for the rest of the run. This is mitigated by the "soft target", but it is still surprising.
  4. Refusals are recognised by their error text. shrinkHeapMirrorBudget matches "of a heap mirror slab" in error.what() (GuestBufferMemory.cpp:2816). A dedicated exception type would be more robust to message edits.
  5. New tuning constants aren't recorded as technical debt. The 256 MiB reserve, the 2 s per-thread throttle, the 8 retries, 256 MiB shrink step and the 2^22-entry cache limit are unmeasured choices. docs/dev/debt/libSceAgcDriver.md already lists similar choices for the heap mirror reference storage ("unmeasured choices"); these belong there too.

Not verified

  • I couldn't reproduce Finding 1 at runtime: lavapipe reports a 64 GiB budget, so the headroom refusal never triggers here. The finding comes from reading the code paths cited above.
  • The host-memory fallback for slabs, and whether sparse binding of host-visible memory works on the drivers the PR targets (NVIDIA on Windows).
  • The Death Stranding 2 (PPSA02015) result and the Windows/NVIDIA test run in the description. No title was run.
  • Whether guest remaps and alias writes stamp the write tracker (Non-blocking 1).

To get this to a good state

  • Make a slab refusal that can't shrink anything go on to the real allocation (with its host fallback) instead of throwing.
  • Add tests that fail on main for the refusal/shrink/retry path, the Bind give-back on failure, and the scan cache seeing a later write.
  • Confirm or document how the scan cache stays sound for remapped or aliased guest memory.
  • Record the new constants in the debt file.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5745245063 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295#pullrequestreview-5745245063). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T00:10:49Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The merged tree builds and the heap mirror and resident tests pass. However, a new pre-allocation refusal can now stop a title on a nearly full device heap when the heap mirrors hold 256 MiB or less, where `main` would have tried the allocation. None of the new paths has a test. ## What I ran Head `1743177ae4af40502f26cd384d2376d555074681`, `main` `5cb015caaaaf83f8ee431414ee6a457b5b307d49`, merged tree `7895dfbc86c6627273ff29b2d3bbc7eed5af335f`. ``` git diff --check 5cb015caaaaf83f8ee431414ee6a457b5b307d49...1743177ae4af40502f26cd384d2376d555074681 python3 tools/check_conventions.py --base 5cb015caaaaf83f8ee431414ee6a457b5b307d49 ctest --test-dir build --output-on-failure -R "^agc_driver_image_sample_lod_clamp_shader_lane$|^unwrap_self_UnwrapTest_test_new_output_inherits" # the PR's 4 production files restored from main: ninja -C build -j32 -l32 agc_driver_image_sample_lod_clamp_tests ctest --test-dir build --output-on-failure -R "^agc_driver_image_sample_lod_clamp_shader_lane$" # merged files restored, git status --porcelain empty: ninja -C build -j32 -l32 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "heap_mirror|resident|host_import|partially_resident" ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, `libs` (script) | ok | | Script test run | 2178 ran; 2 not on the baseline's failure list, neither caused by the PR (see below); 6 known failures that also fail on `main` | | `agc_driver_image_sample_lod_clamp_shader_lane` | fails with the PR, and still fails after the PR's production files are restored from `main` `5cb015ca`. The baseline (`096c4557`) is older, so this failure comes from `main`, not this PR. | | `unwrap_self_..._destination_directory_group` | fails at `os.chown` on a temporary directory (`EINVAL`). This is a `tools/` Python test the PR doesn't touch, and the failure comes from the sandbox. | | Heap mirror, resident and host-import tests (27) | 26 passed, 1 skipped (`agc_host_import_sparse`, an expected skip) | | Validation layer (script, 759 tests) | layer loaded in 758, missing in none; new `VUID-` lines: 0 | <details><summary>lod_clamp failure, same output with the PR and on main</summary> ``` AGC graphics: image_sample_lz through the S# that holds the LOD at 0 with T# MIN_LOD 768 over BASE_LEVEL 0 with a second S# of words 1 0 and 2 5242880, and a second T# of MIN_LOD 0 and LAST_LEVEL 0: thread 0 component 1 is 0.000000, expected 0.062500 ``` </details> ## Negative control There is none, because the PR adds and changes no tests. I used the restore-from-`main` procedure only to clear the PR of the `lod_clamp` failure (see Results). ## Findings ### Blocking 1. **The headroom refusal stops the title when the heap mirrors hold 256 MiB or less.** In `core/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cpp:153`, `Take()` calls `refuseSlab()` before any `vkAllocateMemory`. At `ResidentMirror.cpp:188`, `refuseSlab()` throws when the device heap would keep less than 256 MiB of its reported budget. The only recovery is `shrinkHeapMirrorBudget`, and it returns `false` when `held <= step` (256 MiB) (`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:2823`). Both callers then rethrow the error wrapped in `heapMirrorError`: - `growResident` at `GuestBufferMemory.cpp:2852-2866`; - `acquireMirror` at `GuestBufferMemory.cpp:3396-3407`. So when the device heap is close to its budget for reasons other than the heap mirrors (textures, render targets), the first slab of a small mirror is refused with nothing to evict, and the title stops. On `main` the same slab would go to `vkAllocateMemory`. With this PR it would even fall back to host memory, but that fallback is never reached. This is most likely on GPUs with little VRAM, which this PR is meant to help. The `APS5_HEAP_MIRROR_MIB` refusal at `ResidentMirror.cpp:184` hits the same dead end. It counts whole 16 MiB slabs, fragmentation included, while `state.heapBytes` counts only accounted blocks. A small configured budget can therefore refuse a slab while `held <= 256 MiB`. Suggested fix: treat a refusal as a request to shrink and sweep, not as a final error. When `shrinkHeapMirrorBudget` can't lower anything, or the retries run out, go on to the real allocation and its host-memory fallback. Add a test that sets a heap budget the refusal triggers on (or a test hook for `ReportedHeap`) with fewer than 256 MiB of mirrors, and checks that the mirror is still created. 2. **None of the new behaviour has a test.** The PR changes several things: - slab refusal at the configured budget and at device headroom; - budget shrink and retry; - the host-memory fallback for slabs; - returning blocks when `Bind` fails partway; - taking blocks from the fullest slab; - the generation-keyed nonzero-scan cache. It adds no test for any of them. All 27 existing heap mirror, resident and host-import tests pass with and without the change, so none of them covers these paths. Finding 1 shows a regression these paths can hide. At least the refusal/shrink/retry path and the `Bind` give-back need a test that fails on `main` (`SetHeapMirrorBudget` already exists for that). A scan-cache test should write a block after a first scan and check that the next scan sees it. ### Non-blocking 1. **The scan cache trusts `UnchangedSince` even for content the write watch may not record.** At `ResidentMirror.cpp:401`, a cached "zero" result is reused while `GuestMemory::UnchangedSince` holds. On Windows, `possiblyNonzero` returns the whole range as readable, so the result there depends entirely on the write watch. `docs/dev/debt/libc.md` describes direct-memory pages that are kept in a private reservation while unmapped and mapped again later, and pages mapped at a second address that become views tracked by write protection. Content can then appear at a guest address without a CPU write there. If no stamp covers that case, the mirror leaves a nonzero block unbacked, and the GPU reads zeros. Please confirm that guest maps and alias writes stamp the tracker, or use `CollectCommittedWrites`/`UnchangedCommittedSince` (which also check refusals). If neither covers it, record the gap in `docs/dev/debt/libSceAgcDriver.md`. 2. **The scan cache can use a lot of host memory.** At `ResidentMirror.cpp:382-383`, the map grows to 2^22 entries before it is cleared. That is a few hundred MiB of `unordered_map` nodes and buckets for a process-lifetime cache, and the whole cache is then dropped at once. A per-heap bitmap of generations, or a smaller limit, would bound this better. 3. **The lowered budget never recovers.** `heapMirrorMemoryLimit` (`GuestBufferMemory.cpp:2714`) is only ever set from the current `heapBytes` minus 256 MiB, never back toward the configured budget. A single transient headroom refusal, for example during a loading spike, caps the heap mirrors for the rest of the run. This is mitigated by the "soft target", but it is still surprising. 4. **Refusals are recognised by their error text.** `shrinkHeapMirrorBudget` matches `"of a heap mirror slab"` in `error.what()` (`GuestBufferMemory.cpp:2816`). A dedicated exception type would be more robust to message edits. 5. **New tuning constants aren't recorded as technical debt.** The 256 MiB reserve, the 2 s per-thread throttle, the 8 retries, 256 MiB shrink step and the 2^22-entry cache limit are unmeasured choices. `docs/dev/debt/libSceAgcDriver.md` already lists similar choices for the heap mirror reference storage ("unmeasured choices"); these belong there too. ## Not verified - I couldn't reproduce Finding 1 at runtime: lavapipe reports a 64 GiB budget, so the headroom refusal never triggers here. The finding comes from reading the code paths cited above. - The host-memory fallback for slabs, and whether sparse binding of host-visible memory works on the drivers the PR targets (NVIDIA on Windows). - The Death Stranding 2 (PPSA02015) result and the Windows/NVIDIA test run in the description. No title was run. - Whether guest remaps and alias writes stamp the write tracker (Non-blocking 1). ## To get this to a good state - Make a slab refusal that can't shrink anything go on to the real allocation (with its host fallback) instead of throwing. - Add tests that fail on `main` for the refusal/shrink/retry path, the `Bind` give-back on failure, and the scan cache seeing a later write. - Confirm or document how the scan cache stays sound for remapped or aliased guest memory. - Record the new constants in the debt file. <!-- anyps5-bots job=2714 head=1743177ae4af40502f26cd384d2376d555074681 -->
XairRrR commented 2026-11-03 06:17:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T06:17:43Z.

Review: DISMISSED


Re-checked — changes still requested

Commit 89e3292072 now lets a refusal fall through to the real allocation while the live slabs hold 256 MiB or less. It replaces text matching with HeapMirrorSlabRefused, lets a lowered budget recover after 30 s, and adds one full-device-heap test, whose negative control fails as it should. Three paths still have no test: the shrink/evict/retry path, the Bind give-back and the scan cache. A refusal can also still stop the title when fragmented slabs keep the slab count above the gate while the accounted heap mirror bytes are below the shrink step.

What changed since my last review

  • New commit 89e3292072 ("let a small heap mirror reach the slab allocation and its host fallback"). The first commit 1743177ae4 is unchanged.
    • refuseSlab() returns early while the live slabs hold 256 MiB or less.
    • Refusals and slab allocation failures throw HeapMirrorSlabRefused.
    • heapMirrorBudget() restores a lowered limit after 30 s.
    • The headroom check uses the new Context::HeapReport::Fits.
    • New test hook SetDeviceHeapFullForTests and test FullDeviceHeapTests in tests/execution/ResidentHeapMirror.cpp.
  • The author replied in the discussion with a negative control and a Windows/RTX 3080 Laptop re-run. I accept that run as author-reported.

What I ran

Head 89e3292072015ff5710305f6fd2e097545a0bb50, main d1ae628bc2f62459cce1e9872ba5632c938c71f2, merged tree e656cfa05a1d3ab6e971f1f891ce43a02603f091.

git diff --check d1ae628bc2f62459cce1e9872ba5632c938c71f2...89e3292072015ff5710305f6fd2e097545a0bb50
python3 tools/check_conventions.py --base d1ae628bc2f62459cce1e9872ba5632c938c71f2
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "heap_mirror|resident"
ctest --test-dir build -V -R "^agc_driver_resident_heap_mirror$"
# negative control: in ResidentMirror.cpp:188, `if (live <= Reserve) return;` replaced by `(void)live;`
ninja -C build -j32 -l32 agc_driver_resident_heap_mirror_tests
ctest --test-dir build --output-on-failure -R "^agc_driver_resident_heap_mirror$"
build/tests/agc_driver_resident_heap_mirror_tests
# merged file restored from e656cfa05a, git status --porcelain empty
ninja -C build -j32 -l32 agc_driver_resident_heap_mirror_tests
ctest --test-dir build -R "^agc_driver_resident_heap_mirror$"
Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) ok
Script test run 2142 ran, 0 new failures, 0 timeouts; 7 known failures that also fail on main (baseline = main d1ae628b)
Validation layer (script, 767 tests) layer loaded in 766, missing in none; new VUID- lines: 0
Heap mirror and resident tests (16) all passed; agc_driver_resident_heap_mirror 2.1 s. The sparse branch runs on lavapipe (no skip message), so FullDeviceHeapTests is exercised.

Negative control

The new test calls SetDeviceHeapFullForTests, which main does not have, so it cannot be built against main's production files. Instead I removed only the new early return in refuseSlab (ResidentMirror.cpp:188). The test then fails with the same message the author reported:

output
AGC graphics: heap mirror of 0x7f2aa9ff0000+0x2000000: vkAllocateMemory of a heap mirror slab refused: its device heap would keep less than 256 MiB of its reported budget; heap mirrors hold 15 MiB of 24576 MiB (APS5_HEAP_MIRROR_MIB)

With the merged file restored, the test passes and the worktree matches the merged tree.

Previous findings

  • Blocking 1 (headroom refusal stops the title with ≤ 256 MiB of mirrors): resolved for the case I described. A refusal is now skipped while the live slabs hold 256 MiB or less, and the negative control above shows the test covers it. A related gap remains; see new Blocking 1.
  • Blocking 2 (no tests for the new paths): still open. One test was added, for the small-mirror headroom case. Still untested: the refusal → shrinkHeapMirrorBudget → sweep → retry path, the Bind give-back when Take() or submit fails partway, the host-memory fallback for slabs, and the generation-keyed cache in GuestNonzeroBlocks. oneandonlydean's review asked for the same three cases. The APS5_HEAP_MIRROR_MIB refusal can be forced deterministically with SetHeapMirrorBudget: build more than 256 MiB of slabs (or lower the gate for tests), then check the "budget lowered" path evicts and the retry succeeds.
  • Non-blocking 1 (scan cache trusts UnchangedSince for remapped or aliased content): still open. The code is unchanged (ResidentMirror.cpp:409), with no reply and no debt entry.
  • Non-blocking 2 (scan cache up to 2^22 map entries): still open (ResidentMirror.cpp:419).
  • Non-blocking 3 (lowered budget never recovers): resolved. heapMirrorBudget() restores the limit 30 s after the last lowering (GuestBufferMemory.cpp:2734).
  • Non-blocking 4 (refusal matched by error text): resolved. shrinkHeapMirrorBudget uses dynamic_cast<const HeapMirrorSlabRefused*> (GuestBufferMemory.cpp:2834).
  • Non-blocking 5 (tuning constants not in debt): still open. The PR now also adds a 30 s recovery; no file under docs/dev/debt/ changes.

New findings

Blocking

  1. The refusal gate and the shrink gate count different things, so a refusal can still stop the title.

    • refuseSlab() skips the refusal on live slab memory (Slabs().slabs * 16 MiB, ResidentMirror.cpp:187-188).
    • shrinkHeapMirrorBudget() gives up on accounted heap mirror bytes (state.heapBytes <= 256 MiB, GuestBufferMemory.cpp:2841).

    A slab is freed only when every block in it is free (ResidentMirror.cpp:175). After evictions, surviving mirrors keep blocks scattered across many slabs, so the live slabs can stay well above 256 MiB while heapBytes is far below it. That is exactly the state the shrink-and-sweep path leaves behind.

    What happens then on a device heap near its budget:

    • The headroom refusal fires.
    • shrinkHeapMirrorBudget returns false.
    • Both callers (GuestBufferMemory.cpp:2872 and :3416) rethrow without a retry, so the title stops.

    main would have attempted the allocation, and with this PR that allocation even has a host fallback. The 2 s throttle (ResidentMirror.cpp:193-198) does not help, because the first refusal is already final. The APS5_HEAP_MIRROR_MIB refusal has the same mismatch.

    Suggested fix: when shrinkHeapMirrorBudget returns false for a HeapMirrorSlabRefused that came from refuseSlab (not from a failed allocation), retry once with the refusal bypassed, so the real allocation and its fallback run. Alternatively, gate refuseSlab and the shrink on the same counter. Add a test that fragments slabs past the gate (or lowers the gate through a hook) with a full device heap, and checks the mirror is still made.

Non-blocking

  1. The shrank report prints whenever the last slab is freed. count % 32 == 0 is true for count == 0 (ResidentMirror.cpp:181), so each mirror whose release empties the slab list logs a line. The test log shows several [heap-mirror] shrank: slabs 0 (0 MiB) ... lines in a row. Suggested fix: use count != 0 && count % 32 == 0.
  2. The recovery returns the budget to its full value in one step. After 30 s, the limit goes straight back to the configured budget (GuestBufferMemory.cpp:2734). Under sustained pressure, this can cycle every 30 s: the mirrors grow, a refusal fires, the budget shrinks and the sweep runs again. Raising the limit in steps, or only while the heap reports headroom, would avoid the cycle. This is not shown on hardware; it comes from reading the code.

Not verified

  • The new Blocking 1 at runtime. Lavapipe reports a large heap budget, and the test hook only covers the small-mirror case; the finding comes from reading the cited code.
  • The host-memory fallback for slabs, and sparse binding of host-visible memory on NVIDIA/Windows.
  • The Windows/RTX 3080 Laptop re-run and the PPSA02015 result (author-reported; no title was run).
  • Whether guest remaps and alias writes stamp the write tracker (previous Non-blocking 1).

To get this to a good state

  • Make a refusal that shrinkHeapMirrorBudget cannot act on go on to the real allocation, whatever the slab fragmentation.
  • Add tests for the refusal → shrink → sweep → retry path, the Bind give-back, and the scan cache seeing a write made after an earlier scan cached the block as zero.
  • Confirm or record in docs/dev/debt/libSceAgcDriver.md how the scan cache stays sound for remapped or aliased guest memory, and record the new constants (256 MiB reserve and step, 2 s throttle, 8 retries, 30 s recovery, 2^22-entry cache limit).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5747958781 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295#pullrequestreview-5747958781). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T06:17:43Z. **Review:** DISMISSED --- # Re-checked — changes still requested Commit `89e3292072` now lets a refusal fall through to the real allocation while the live slabs hold 256 MiB or less. It replaces text matching with `HeapMirrorSlabRefused`, lets a lowered budget recover after 30 s, and adds one full-device-heap test, whose negative control fails as it should. Three paths still have no test: the shrink/evict/retry path, the `Bind` give-back and the scan cache. A refusal can also still stop the title when fragmented slabs keep the slab count above the gate while the accounted heap mirror bytes are below the shrink step. ## What changed since my last review - New commit `89e3292072` ("let a small heap mirror reach the slab allocation and its host fallback"). The first commit `1743177ae4` is unchanged. - `refuseSlab()` returns early while the live slabs hold 256 MiB or less. - Refusals and slab allocation failures throw `HeapMirrorSlabRefused`. - `heapMirrorBudget()` restores a lowered limit after 30 s. - The headroom check uses the new `Context::HeapReport::Fits`. - New test hook `SetDeviceHeapFullForTests` and test `FullDeviceHeapTests` in `tests/execution/ResidentHeapMirror.cpp`. - The author replied in the discussion with a negative control and a Windows/RTX 3080 Laptop re-run. I accept that run as author-reported. ## What I ran Head `89e3292072015ff5710305f6fd2e097545a0bb50`, `main` `d1ae628bc2f62459cce1e9872ba5632c938c71f2`, merged tree `e656cfa05a1d3ab6e971f1f891ce43a02603f091`. ``` git diff --check d1ae628bc2f62459cce1e9872ba5632c938c71f2...89e3292072015ff5710305f6fd2e097545a0bb50 python3 tools/check_conventions.py --base d1ae628bc2f62459cce1e9872ba5632c938c71f2 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "heap_mirror|resident" ctest --test-dir build -V -R "^agc_driver_resident_heap_mirror$" # negative control: in ResidentMirror.cpp:188, `if (live <= Reserve) return;` replaced by `(void)live;` ninja -C build -j32 -l32 agc_driver_resident_heap_mirror_tests ctest --test-dir build --output-on-failure -R "^agc_driver_resident_heap_mirror$" build/tests/agc_driver_resident_heap_mirror_tests # merged file restored from e656cfa05a, git status --porcelain empty ninja -C build -j32 -l32 agc_driver_resident_heap_mirror_tests ctest --test-dir build -R "^agc_driver_resident_heap_mirror$" ``` | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, `libs` (script) | ok | | Script test run | 2142 ran, 0 new failures, 0 timeouts; 7 known failures that also fail on `main` (baseline = `main` `d1ae628b`) | | Validation layer (script, 767 tests) | layer loaded in 766, missing in none; new `VUID-` lines: 0 | | Heap mirror and resident tests (16) | all passed; `agc_driver_resident_heap_mirror` 2.1 s. The sparse branch runs on lavapipe (no skip message), so `FullDeviceHeapTests` is exercised. | ## Negative control The new test calls `SetDeviceHeapFullForTests`, which `main` does not have, so it cannot be built against `main`'s production files. Instead I removed only the new early return in `refuseSlab` (`ResidentMirror.cpp:188`). The test then fails with the same message the author reported: <details><summary>output</summary> ``` AGC graphics: heap mirror of 0x7f2aa9ff0000+0x2000000: vkAllocateMemory of a heap mirror slab refused: its device heap would keep less than 256 MiB of its reported budget; heap mirrors hold 15 MiB of 24576 MiB (APS5_HEAP_MIRROR_MIB) ``` </details> With the merged file restored, the test passes and the worktree matches the merged tree. ## Previous findings - **Blocking 1 (headroom refusal stops the title with ≤ 256 MiB of mirrors): resolved for the case I described.** A refusal is now skipped while the live slabs hold 256 MiB or less, and the negative control above shows the test covers it. A related gap remains; see new Blocking 1. - **Blocking 2 (no tests for the new paths): still open.** One test was added, for the small-mirror headroom case. Still untested: the refusal → `shrinkHeapMirrorBudget` → sweep → retry path, the `Bind` give-back when `Take()` or `submit` fails partway, the host-memory fallback for slabs, and the generation-keyed cache in `GuestNonzeroBlocks`. oneandonlydean's review asked for the same three cases. The `APS5_HEAP_MIRROR_MIB` refusal can be forced deterministically with `SetHeapMirrorBudget`: build more than 256 MiB of slabs (or lower the gate for tests), then check the "budget lowered" path evicts and the retry succeeds. - **Non-blocking 1 (scan cache trusts `UnchangedSince` for remapped or aliased content): still open.** The code is unchanged (`ResidentMirror.cpp:409`), with no reply and no debt entry. - **Non-blocking 2 (scan cache up to 2^22 map entries): still open** (`ResidentMirror.cpp:419`). - **Non-blocking 3 (lowered budget never recovers): resolved.** `heapMirrorBudget()` restores the limit 30 s after the last lowering (`GuestBufferMemory.cpp:2734`). - **Non-blocking 4 (refusal matched by error text): resolved.** `shrinkHeapMirrorBudget` uses `dynamic_cast<const HeapMirrorSlabRefused*>` (`GuestBufferMemory.cpp:2834`). - **Non-blocking 5 (tuning constants not in debt): still open.** The PR now also adds a 30 s recovery; no file under `docs/dev/debt/` changes. ## New findings ### Blocking 1. **The refusal gate and the shrink gate count different things, so a refusal can still stop the title.** - `refuseSlab()` skips the refusal on *live slab memory* (`Slabs().slabs * 16 MiB`, `ResidentMirror.cpp:187-188`). - `shrinkHeapMirrorBudget()` gives up on *accounted heap mirror bytes* (`state.heapBytes <= 256 MiB`, `GuestBufferMemory.cpp:2841`). A slab is freed only when every block in it is free (`ResidentMirror.cpp:175`). After evictions, surviving mirrors keep blocks scattered across many slabs, so the live slabs can stay well above 256 MiB while `heapBytes` is far below it. That is exactly the state the shrink-and-sweep path leaves behind. What happens then on a device heap near its budget: - The headroom refusal fires. - `shrinkHeapMirrorBudget` returns `false`. - Both callers (`GuestBufferMemory.cpp:2872` and `:3416`) rethrow without a retry, so the title stops. `main` would have attempted the allocation, and with this PR that allocation even has a host fallback. The 2 s throttle (`ResidentMirror.cpp:193-198`) does not help, because the first refusal is already final. The `APS5_HEAP_MIRROR_MIB` refusal has the same mismatch. Suggested fix: when `shrinkHeapMirrorBudget` returns `false` for a `HeapMirrorSlabRefused` that came from `refuseSlab` (not from a failed allocation), retry once with the refusal bypassed, so the real allocation and its fallback run. Alternatively, gate `refuseSlab` and the shrink on the same counter. Add a test that fragments slabs past the gate (or lowers the gate through a hook) with a full device heap, and checks the mirror is still made. ### Non-blocking 1. **The `shrank` report prints whenever the last slab is freed.** `count % 32 == 0` is true for `count == 0` (`ResidentMirror.cpp:181`), so each mirror whose release empties the slab list logs a line. The test log shows several `[heap-mirror] shrank: slabs 0 (0 MiB) ...` lines in a row. Suggested fix: use `count != 0 && count % 32 == 0`. 2. **The recovery returns the budget to its full value in one step.** After 30 s, the limit goes straight back to the configured budget (`GuestBufferMemory.cpp:2734`). Under sustained pressure, this can cycle every 30 s: the mirrors grow, a refusal fires, the budget shrinks and the sweep runs again. Raising the limit in steps, or only while the heap reports headroom, would avoid the cycle. This is not shown on hardware; it comes from reading the code. ## Not verified - The new Blocking 1 at runtime. Lavapipe reports a large heap budget, and the test hook only covers the small-mirror case; the finding comes from reading the cited code. - The host-memory fallback for slabs, and sparse binding of host-visible memory on NVIDIA/Windows. - The Windows/RTX 3080 Laptop re-run and the PPSA02015 result (author-reported; no title was run). - Whether guest remaps and alias writes stamp the write tracker (previous Non-blocking 1). ## To get this to a good state - Make a refusal that `shrinkHeapMirrorBudget` cannot act on go on to the real allocation, whatever the slab fragmentation. - Add tests for the refusal → shrink → sweep → retry path, the `Bind` give-back, and the scan cache seeing a write made after an earlier scan cached the block as zero. - Confirm or record in `docs/dev/debt/libSceAgcDriver.md` how the scan cache stays sound for remapped or aliased guest memory, and record the new constants (256 MiB reserve and step, 2 s throttle, 8 retries, 30 s recovery, 2^22-entry cache limit). <!-- anyps5-bots job=3092 head=89e3292072015ff5710305f6fd2e097545a0bb50 -->
Superseabas commented 2026-11-06 09:24:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-06T09:24:51Z.

Review: APPROVED


Windows run of the current head, c75bd0a393, on an RTX 5070 Ti and on the integrated Radeon of a Ryzen 7 7700X, the first AMD result on Windows here. Nothing regresses, and the new FullDeviceHeapPastReserveTests catches the loss of the retry. One non-blocking note on what it doesn't cover.

Head merged onto main ed41d86d32 (clean merge, local only). Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Release. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, no missing-layer line, ANYPS5_GPU selecting the device, confirmed by Selected GPU:

  • NVIDIA GeForce RTX 5070 Ti (10de:2c05), 621.01
  • AMD Radeon of a Ryzen 7 7700X (1002:164e, integrated), AMD 26.10.2 (32.0.21045.20006)

Focused set. The 17 tests matching heap_mirror|resident (agc_driver_resident_heap_mirror, the agc_heap_mirror_* and agc_sparse_heap_mirror_* entries, agc_driver_partially_resident_*, agc_resident_* and the others) pass 3 of 3 on both GPUs, on main and on this PR. No VUID- lines. Both devices take the sparse path: agc_driver_resident_heap_mirror prints no skip line, and the [heap-mirror] refused line shows the full-heap cases ran.

Whole AGC set. ctest -R '^agc' -j 8 --timeout 300, 1,388 tests: 1,386 pass on the RTX and 1,385 on the Radeon, the same as main on this machine. Every failure is tracked: agc_driver_direct_write_completion (#15564), agc_driver_quad_pixel_mask on the RTX (#14341), and on the Radeon agc_driver_scratch_pool (#15566) and agc_driver_sample_order_grid_reference (#9503).

Red checks on agc_driver_resident_heap_mirror, 3 runs per GPU, each a local edit of the merged tree:

Edit Result
none passes
both if (!waive && dynamic_cast<const HeapMirrorSlabRefused*>(&error) != nullptr) { waive = true; continue; } retries removed (growResident, acquireMirror) fails: vkAllocateMemory of a heap mirror slab refused: its device heap would keep less than 256 MiB of its reported budget
only if (slabRefusalWaived) return; removed from refuseSlab passes
that line removed, and the headroom throttle (now - lastHeadroomRefusal > std::chrono::seconds(2)) disabled fails, the same message
the throttle disabled, the line kept passes

Non-blocking. The test covers the retry, but not the waive itself. Its refusal is the headroom one, and lastHeadroomRefusal was set by the refusal a moment earlier on the same thread, so the throttle already lets the retry's allocation through, with or without slabRefusalWaived. The waive matters for the other reason, the heap mirrors' slabs would pass APS5_HEAP_MIRROR_MIB, which has no throttle. A case refused through the budget hook, with too little held for shrinkHeapMirrorBudget to act, would cover it.

check_conventions.py --base main passes.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5798168811 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295#pullrequestreview-5798168811). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-06T09:24:51Z. **Review:** APPROVED --- Windows run of the current head, `c75bd0a393`, on an RTX 5070 Ti and on the integrated Radeon of a Ryzen 7 7700X, the first AMD result on Windows here. Nothing regresses, and the new `FullDeviceHeapPastReserveTests` catches the loss of the retry. One non-blocking note on what it doesn't cover. Head merged onto `main` `ed41d86d32` (clean merge, local only). Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (`x86_64-ucrt-posix-seh`, r3), Release. `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, no missing-layer line, `ANYPS5_GPU` selecting the device, confirmed by `Selected GPU`: - NVIDIA GeForce RTX 5070 Ti (`10de:2c05`), 621.01 - AMD Radeon of a Ryzen 7 7700X (`1002:164e`, integrated), AMD 26.10.2 (32.0.21045.20006) **Focused set.** The 17 tests matching `heap_mirror|resident` (`agc_driver_resident_heap_mirror`, the `agc_heap_mirror_*` and `agc_sparse_heap_mirror_*` entries, `agc_driver_partially_resident_*`, `agc_resident_*` and the others) pass 3 of 3 on both GPUs, on `main` and on this PR. No `VUID-` lines. Both devices take the sparse path: `agc_driver_resident_heap_mirror` prints no skip line, and the `[heap-mirror] refused` line shows the full-heap cases ran. **Whole AGC set.** `ctest -R '^agc' -j 8 --timeout 300`, 1,388 tests: 1,386 pass on the RTX and 1,385 on the Radeon, the same as `main` on this machine. Every failure is tracked: `agc_driver_direct_write_completion` (#15564), `agc_driver_quad_pixel_mask` on the RTX (#14341), and on the Radeon `agc_driver_scratch_pool` (#15566) and `agc_driver_sample_order_grid_reference` (#9503). **Red checks on `agc_driver_resident_heap_mirror`**, 3 runs per GPU, each a local edit of the merged tree: | Edit | Result | |---|---| | none | passes | | both `if (!waive && dynamic_cast<const HeapMirrorSlabRefused*>(&error) != nullptr) { waive = true; continue; }` retries removed (`growResident`, `acquireMirror`) | fails: `vkAllocateMemory of a heap mirror slab refused: its device heap would keep less than 256 MiB of its reported budget` | | only `if (slabRefusalWaived) return;` removed from `refuseSlab` | passes | | that line removed, and the headroom throttle (`now - lastHeadroomRefusal > std::chrono::seconds(2)`) disabled | fails, the same message | | the throttle disabled, the line kept | passes | **Non-blocking.** The test covers the retry, but not the waive itself. Its refusal is the headroom one, and `lastHeadroomRefusal` was set by the refusal a moment earlier on the same thread, so the throttle already lets the retry's allocation through, with or without `slabRefusalWaived`. The waive matters for the other reason, `the heap mirrors' slabs would pass APS5_HEAP_MIRROR_MIB`, which has no throttle. A case refused through the budget hook, with too little held for `shrinkHeapMirrorBudget` to act, would cover it. `check_conventions.py --base main` passes. AI-assisted: yes (Claude Code)
gabichuuuuu commented 2026-11-08 15:48:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T15:48:37Z.

Review: COMMENTED


Ran c75bd0a393 merged on main 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Khronos validation layer 1.4.368), ctest -R '^agc_driver_resident_heap_mirror' -V:

main change, 2 runs each
NVIDIA 1/1 1/1 twice
Intel 1/1 1/1 twice
  • The PR's ResidentHeapMirror.cpp uses SetDeviceHeapFullForTests and SetHeapMirrorSlabReserveForTests, which this PR adds, so there's no run of the tests without the change.
  • The layer was inserted in every test that opens a device. No log has was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has a VUID-. To be sure validation messages reach these logs, the same layer with best practices on printed 28 BestPractices- warnings into an agc_driver_recorder log on each GPU.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5818523207 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295#pullrequestreview-5818523207). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T15:48:37Z. **Review:** COMMENTED --- Ran `c75bd0a393` merged on `main` 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Khronos validation layer 1.4.368), `ctest -R '^agc_driver_resident_heap_mirror' -V`: | | `main` | change, 2 runs each | |---|---|---| | NVIDIA | 1/1 | 1/1 twice | | Intel | 1/1 | 1/1 twice | - The PR's `ResidentHeapMirror.cpp` uses `SetDeviceHeapFullForTests` and `SetHeapMirrorSlabReserveForTests`, which this PR adds, so there's no run of the tests without the change. - The layer was inserted in every test that opens a device. No log has `was not found but was requested by env var VK_INSTANCE_LAYERS`, and no log on either side has a `VUID-`. To be sure validation messages reach these logs, the same layer with best practices on printed 28 `BestPractices-` warnings into an `agc_driver_recorder` log on each GPU. AI-assisted: yes.
MarcZX10 commented 2026-11-20 21:19:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T21:19:44Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed changes at head 4c3e5d198988d477f2471f1cfc1cc62171ffb8a3 show no verified blocking defect; runtime checks were not run here.

What I ran

No commands or tests were run. I read the prepared description, commits, manifest and diff, plus the changed code sections and related context through repo_read.py.

Results

Check Result Note
Changed-code review passed Relevant hunks and context read
Runtime checks not run Author-reported test results only

Findings

Blocking

None verified in the code reviewed.

Non-blocking

None.

Not verified

The complete GuestBufferMemory.cpp file was excluded from the review folder because it was too large; I read its changed hunks and surrounding functions through repo_read.py. The full repository test suite and the author-reported GPU and game integration checks were not run or independently confirmed.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5999565709 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295#pullrequestreview-5999565709). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T21:19:44Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed changes at head `4c3e5d198988d477f2471f1cfc1cc62171ffb8a3` show no verified blocking defect; runtime checks were not run here. ## What I ran No commands or tests were run. I read the prepared description, commits, manifest and diff, plus the changed code sections and related context through `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Changed-code review | passed | Relevant hunks and context read | | Runtime checks | not run | Author-reported test results only | ## Findings ### Blocking None verified in the code reviewed. ### Non-blocking None. ## Not verified The complete `GuestBufferMemory.cpp` file was excluded from the review folder because it was too large; I read its changed hunks and surrounding functions through `repo_read.py`. The full repository test suite and the author-reported GPU and game integration checks were not run or independently confirmed. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 12:13:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T12:13:56Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 515aeee17bdcdfa5fc01e8a6ac2f62d671cbecf9. I did not run commands or tests.

Results

Check Result Note
Source review passed Changed logic inspected
Tests not run Only author-reported results available

Findings

Blocking

None.

Non-blocking

  • GuestNonzeroBlocks uses a process-wide cache keyed only by guest block address. Consider including the guest-memory identity in the key or invalidating entries when an address range is reused; otherwise a new allocation at a reused address may inherit a previous scan result if write tracking does not distinguish the allocations. See core/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cpp:397.

Not verified

  • core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp was excluded from the prepared full-text files because it is too large. I read the relevant changed regions through the pinned reader, but did not read the entire file.
  • No runtime checks were performed. The tests and GPU/title results in the PR description are author-reported, not independently verified.
  • ResidentMirror.hpp, ResidentMirror.cpp, ResidentHeapMirror.cpp, and libSceAcm.md were listed as included; the full changed text of libSceAcm.md was not read.
  • files.json was not available as a review document; the changed-file inclusion list came from the review-folder listing and manifest.

To get this to a good state

Nothing is required. Optional: key the scan cache by guest-memory identity or ensure address reuse invalidates it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6057398098 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295#pullrequestreview-6057398098). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T12:13:56Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `515aeee17bdcdfa5fc01e8a6ac2f62d671cbecf9`. I did not run commands or tests. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Changed logic inspected | | Tests | not run | Only author-reported results available | ## Findings ### Blocking None. ### Non-blocking - `GuestNonzeroBlocks` uses a process-wide cache keyed only by guest block address. Consider including the guest-memory identity in the key or invalidating entries when an address range is reused; otherwise a new allocation at a reused address may inherit a previous scan result if write tracking does not distinguish the allocations. See `core/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cpp:397`. ## Not verified - `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` was excluded from the prepared full-text files because it is too large. I read the relevant changed regions through the pinned reader, but did not read the entire file. - No runtime checks were performed. The tests and GPU/title results in the PR description are author-reported, not independently verified. - `ResidentMirror.hpp`, `ResidentMirror.cpp`, `ResidentHeapMirror.cpp`, and `libSceAcm.md` were listed as included; the full changed text of `libSceAcm.md` was not read. - `files.json` was not available as a review document; the changed-file inclusion list came from the review-folder listing and manifest. ## To get this to a good state Nothing is required. Optional: key the scan cache by guest-memory identity or ensure address reuse invalidates it.
MarcZX10 commented 2026-11-25 14:30:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T14:30:13Z.

Review: COMMENTED


Reviewed — comments

Changes are required before merge: address the findings below.

What I ran

  • Reviewed head 901975c9ef9be1d42ba811f31ec5f8443a834f4b; no build or test commands were run.
  • Read description.md, commits.md, manifest.json, diff.patch, and all included changed files. GuestBufferMemory.cpp was excluded from the review folder and read through repo_read.py at the allocation and retry paths it changes.

Results

Check Result Note
Diff and changed code passed Key changed code inspected
Build and focused tests not run No local execution available
Device behavior not verified Author-reported runs only

Findings

Blocking

None verified.

Non-blocking

  • core/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cpp:403: GuestNonzeroBlocks collects a generation for the entire candidate range, then reuses a cached block result when UnchangedSince says the block has not changed since its cached generation. A write to a different block in the same page can cause CollectWrites to stamp both blocks, so this check invalidates the cache for the unchanged block and triggers a rescan. This weakens the stated scan optimization for workloads that write many distinct blocks on shared pages. Consider tracking cache validity at the same granularity as the write stamps, or confirm with targeted profiling that this behavior is acceptable.
  • core/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cpp:397: the scan cache is keyed only by block address and is process-global. If guest address ranges are reused for a new allocation without a write stamp changing that block, the cached nonzero result can be reused for different contents. Confirm the allocator's write-watch and address-reuse guarantees, or include allocation identity in the cache key.

Not verified

  • No tests or build were run. The RTX 3080 Laptop GPU results and game integration behavior in the PR description are author-reported, not independently confirmed.
  • GuestBufferMemory.cpp was not read in full; only the changed budget, retry, and allocation sections were inspected. Other portions of that file and files excluded by review-folder rules were not reviewed.

To get this to a good state

Nothing is required. Optional points: assess the scan cache's invalidation granularity and address reuse behavior, and run the focused tests on the reviewed head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6059534666 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295#pullrequestreview-6059534666). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T14:30:13Z. **Review:** COMMENTED --- # Reviewed — comments Changes are required before merge: address the findings below. ## What I ran - Reviewed head `901975c9ef9be1d42ba811f31ec5f8443a834f4b`; no build or test commands were run. - Read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and all included changed files. `GuestBufferMemory.cpp` was excluded from the review folder and read through `repo_read.py` at the allocation and retry paths it changes. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Key changed code inspected | | Build and focused tests | not run | No local execution available | | Device behavior | not verified | Author-reported runs only | ## Findings ### Blocking None verified. ### Non-blocking - `core/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cpp:403`: `GuestNonzeroBlocks` collects a generation for the entire candidate range, then reuses a cached block result when `UnchangedSince` says the block has not changed since its cached generation. A write to a different block in the same page can cause `CollectWrites` to stamp both blocks, so this check invalidates the cache for the unchanged block and triggers a rescan. This weakens the stated scan optimization for workloads that write many distinct blocks on shared pages. Consider tracking cache validity at the same granularity as the write stamps, or confirm with targeted profiling that this behavior is acceptable. - `core/libs/prx/libSceAgcDriver/Graphics/src/ResidentMirror.cpp:397`: the scan cache is keyed only by block address and is process-global. If guest address ranges are reused for a new allocation without a write stamp changing that block, the cached nonzero result can be reused for different contents. Confirm the allocator's write-watch and address-reuse guarantees, or include allocation identity in the cache key. ## Not verified - No tests or build were run. The RTX 3080 Laptop GPU results and game integration behavior in the PR description are author-reported, not independently confirmed. - `GuestBufferMemory.cpp` was not read in full; only the changed budget, retry, and allocation sections were inspected. Other portions of that file and files excluded by review-folder rules were not reviewed. ## To get this to a good state Nothing is required. Optional points: assess the scan cache's invalidation granularity and address reuse behavior, and run the focused tests on the reviewed head.
ligmaSec commented 2026-12-03 22:45:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:45:13Z.

Review: COMMENTED


The trial merge onto c1601e56d5 was clean. The new headroom check suppresses repeated refusals for two seconds per thread. Please describe the 256 MiB figure as a retry threshold or show how retry still respects it during that interval. Keep the fixture that distinguishes a refused allocation from a failed bind, which separately needs to return its reserved blocks. Paired lavapipe controls are pending.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179946316 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15295#pullrequestreview-6179946316). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:45:13Z. **Review:** COMMENTED --- The trial merge onto `c1601e56d5` was clean. The new headroom check suppresses repeated refusals for two seconds per thread. Please describe the 256 MiB figure as a retry threshold or show how retry still respects it during that interval. Keep the fixture that distinguishes a refused allocation from a failed bind, which separately needs to return its reserved blocks. Paired lavapipe controls are pending. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/15295:upstream-pr/15295'
git switch 'upstream-pr/15295'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/15295'
git switch 'upstream-pr/15295'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/15295'
git switch 'upstream-pr/15295'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/15295'
git switch 'main'
git merge --squash 'upstream-pr/15295'
git switch 'main'
git merge --ff-only 'upstream-pr/15295'
git switch 'main'
git merge 'upstream-pr/15295'
git push origin 'main'
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!15295
No description provided.