fix(agc): roll back failed snapshot cache insertions #7919

Merged
Zenodeon merged 1 commit from upstream-pr/7919 into main 2026-10-23 08:20:18 +00:00
Zenodeon commented 2026-10-19 14:01:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Zenodeon on 2026-10-19T14:01:30Z.


What

A failed snapshot-cache insertion can leave an LRU key without a matching entry. A later eviction then dereferences a missing entry. Roll back the newly added recency key when snapshot-byte or map-node allocation throws, and propagate the original exception. Extract the internal cache metadata so the regression exercises the same insertion used by the runtime. Cache budgets, snapshot bytes, queued buffer ownership and guest APIs are unchanged.

Found while investigating memory pressure in Astro's Playroom (PPSA01325). This does not fix its separate 6.39 GiB heap-mirror allocation failure, establish a memory reduction or claim an FPS gain.

Related work, not dependencies: #7800 concerns image-cache reclamation, #6553 host-placement budget checks, and #7119 allocation-failure diagnostics. Also related: merged #3785 handles shader cache-file allocation failures, and open #6937 guards snapshot reuse around pending writes. Neither edits this insertion path. Existing contributions #6367, #6718, #6759, #6820 and #7307 remain separate; this fix needs none of them.

Tested

Windows 11 build 26200, Intel Core i7-13700, RTX 4070 / NVIDIA 610.88; WinLibs GCC 15.2.0, Release, SPIR-V Tools enabled.

Pre-fix main behavior with the cache metadata exposed for fault injection: the new regression fails with "failed snapshot insertion left inconsistent eviction metadata"; buffer-pool, descriptor-cache failure and graphics tests pass (3/4 overall, expected regression failure). Fixed source: the same four cases pass, longest 10.82 seconds on the rebased pre-publication rerun. The new case injects failure at all three insertion allocations, checks accounting/reference ownership, then retries, evicts and clears the cache.

Both focused runs used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Neither log reports a missing requested layer; both contain zero VUID identifiers. Conventions and diff checks pass against upstream/main. Baseline behavior was checked at 4b462ef60; the final branch is rebased onto upstream 85029a00f. The same four cases pass again on rebased commit 12bc5b14a, with no missing requested validation layer or VUID identifiers. The fork-base conventions invocation was also run; its outdated 4,364-commit comparison reports inherited findings, while the actual upstream PR diff passes.

The standalone snapshot insertion regression also compiles and passes under WSL/Ubuntu with g++ -std=c++20 -O2. This is a CPU-only cache-metadata test, not a Linux Vulkan/runtime validation.

Not a gameplay or performance comparison. New-game, five-minute stability and cross-title runs for this change have not been performed. No evidence bundle uploaded. Ran tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch astro-small-resource-fixes. It reported shared files in 67 PRs whose base conflicts prevented automatic hunk comparison. Manually inspected those shared-file patches and compared the snapshot-cache blocks against each PR's merge base. No matching insertion rollback was found. #6292 and #6615 change this cache's mutex from std::mutex to AgcDriver::Mutex; this extraction will need to carry that mutex change into the internal header if either lands first. These are related edits, not dependencies.

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: none
  • GPUs tested: NVIDIA GeForce RTX 4070, NVIDIA 610.88, Windows 11 build 26200
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4922155108 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7919). Originally posted by [Zenodeon](https://github.com/Zenodeon) on 2026-10-19T14:01:30Z. --- ### What A failed snapshot-cache insertion can leave an LRU key without a matching entry. A later eviction then dereferences a missing entry. Roll back the newly added recency key when snapshot-byte or map-node allocation throws, and propagate the original exception. Extract the internal cache metadata so the regression exercises the same insertion used by the runtime. Cache budgets, snapshot bytes, queued buffer ownership and guest APIs are unchanged. Found while investigating memory pressure in Astro's Playroom (PPSA01325). This does not fix its separate 6.39 GiB heap-mirror allocation failure, establish a memory reduction or claim an FPS gain. Related work, not dependencies: [#7800](https://github.com/boykopovar/AnyPS5/pull/7800) concerns image-cache reclamation, [#6553](https://github.com/boykopovar/AnyPS5/pull/6553) host-placement budget checks, and [#7119](https://github.com/boykopovar/AnyPS5/pull/7119) allocation-failure diagnostics. Also related: merged [#3785](https://github.com/boykopovar/AnyPS5/pull/3785) handles shader cache-file allocation failures, and open [#6937](https://github.com/boykopovar/AnyPS5/pull/6937) guards snapshot reuse around pending writes. Neither edits this insertion path. Existing contributions #6367, #6718, #6759, #6820 and #7307 remain separate; this fix needs none of them. ### Tested Windows 11 build 26200, Intel Core i7-13700, RTX 4070 / NVIDIA 610.88; WinLibs GCC 15.2.0, Release, SPIR-V Tools enabled. Pre-fix main behavior with the cache metadata exposed for fault injection: the new regression fails with "failed snapshot insertion left inconsistent eviction metadata"; buffer-pool, descriptor-cache failure and graphics tests pass (3/4 overall, expected regression failure). Fixed source: the same four cases pass, longest 10.82 seconds on the rebased pre-publication rerun. The new case injects failure at all three insertion allocations, checks accounting/reference ownership, then retries, evicts and clears the cache. Both focused runs used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Neither log reports a missing requested layer; both contain zero VUID identifiers. Conventions and diff checks pass against upstream/main. Baseline behavior was checked at 4b462ef60; the final branch is rebased onto upstream 85029a00f. The same four cases pass again on rebased commit 12bc5b14a, with no missing requested validation layer or VUID identifiers. The fork-base conventions invocation was also run; its outdated 4,364-commit comparison reports inherited findings, while the actual upstream PR diff passes. The standalone snapshot insertion regression also compiles and passes under WSL/Ubuntu with g++ -std=c++20 -O2. This is a CPU-only cache-metadata test, not a Linux Vulkan/runtime validation. Not a gameplay or performance comparison. New-game, five-minute stability and cross-title runs for this change have not been performed. No evidence bundle uploaded. Ran tools/pr_overlap.py --repo boykopovar/AnyPS5 --branch astro-small-resource-fixes. It reported shared files in 67 PRs whose base conflicts prevented automatic hunk comparison. Manually inspected those shared-file patches and compared the snapshot-cache blocks against each PR's merge base. No matching insertion rollback was found. [#6292](https://github.com/boykopovar/AnyPS5/pull/6292) and [#6615](https://github.com/boykopovar/AnyPS5/pull/6615) change this cache's mutex from std::mutex to AgcDriver::Mutex; this extraction will need to carry that mutex change into the internal header if either lands first. These are related edits, not dependencies. <!-- 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. --> ### 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: none - [x] GPUs tested: NVIDIA GeForce RTX 4070, NVIDIA 610.88, Windows 11 build 26200 - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7919
No description provided.