Marvel's Wolverine (PPSA03671) on an 8 GB card: storage images cycle ~5.4 GB through the 2 GB storage cache, and evicted images stay alive until device memory runs out #5961

Open
opened 2026-10-14 17:13:03 +00:00 by tv7 · 8 comments
tv7 commented 2026-10-14 17:13:03 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T17:13:03Z.


Marvel's Wolverine (PPSA03671) on plain main e34c47921 (which has #757) now gets past its old stops and presents 3840x2160 frames. After a few minutes it aborts because device memory runs out:

[videoout] presentation failed: compute shader 0x11d0372500: AGC graphics: vkAllocateMemory storage texture: Vulkan result -2
terminate called after throwing an instance of 'std::runtime_error'

Setup: Windows 11, NVIDIA GeForce RTX 3070 8 GB (driver 617.14, VK_EXT_memory_budget reports a budget of about 7 GB for heap 0), MinGW GCC 15.2 Release, relinked with --to-intel.

Before the abort, heap 0 usage swings between about 4.5 and 13 GB while the [gpu] budget lines report only about 2 GB of sampled textures and 2 GB of cached storage images. The host-memory fallback count in DeviceMemoryType reaches 65,536 allocations (182 GB in total).

I measured where the memory goes with two local debug hooks (not for merging): one wraps vkAllocateMemory/vkFreeMemory and sums live bytes per call site, and one keeps a weak_ptr to every image evictStorage removes.

  1. Live memory by call site at the peak (19.3 GB live): StorageTexture::StorageTexture holds 10.0 GB in 2,191 allocations, all in memory type 0 (heap 1, the host fallback). createHostPointerImport holds 5.2 GB (expected). Texture and buffer-pool allocations make up the rest.
  2. The storage cache stays at its budget, but evicted images stay alive: for example, the cache held 288 entries / 2,040 MiB while 1,472 images it had evicted (5,602 MiB) were still alive. At another point it was 720 images / 3.3 GB, and later the count drops back to about 10, so they are released eventually, not leaked. Most survivors have 1 or 3 other owners.
  3. Every eviction is the LRU one, and most creations re-create an evicted surface: 12,866 evictions (0 from the mip-extension path, 0 from MetadataMoved), and 11,894 of 13,265 creations were for a key evicted earlier. Only about 245 distinct base addresses are involved.
  4. The working set is larger than the budget and cycles as a whole: 1,371 distinct storage surfaces, about 5.4 GB by heldBytes, and 1,359 of them were created again within the last 10 seconds.

Two things I tried locally that did not help:

  • APS5_TEXTURE_CACHE_MIB=3072: about 34,000 evictions, same abort.
  • Making the LRU loop skip entries whose texture.use_count() > 1: re-creations fell from about 11,900 to about 1,700, but evicted images still reached about 4 GB alive, and the run aborted sooner, on a device buffer allocation in presentation.

So on an 8 GB card the problem seems to be two things together: a storage working set of about 5.4 GB cycling through a 2 GB LRU budget, and each evicted image staying alive until its other owners let go, so the re-created copy and the old one exist at the same time. #3256 had a similar shape (the resource cache's entry bound pinned storage images past their budget, fixed by #3473 and #3474). I have not identified the other owners yet. The image tables from #757 are one candidate, since their resource-cache keys include the table's T# list, but I have not confirmed that.

I can run any proposed change on this card with Wolverine and post the same numbers. Full logs are available if useful (no game data in them).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5852204206 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961). Originally posted by [tv7](https://github.com/tv7) on 2026-10-14T17:13:03Z. --- Marvel's Wolverine (PPSA03671) on plain `main` e34c47921 (which has #757) now gets past its old stops and presents 3840x2160 frames. After a few minutes it aborts because device memory runs out: ``` [videoout] presentation failed: compute shader 0x11d0372500: AGC graphics: vkAllocateMemory storage texture: Vulkan result -2 terminate called after throwing an instance of 'std::runtime_error' ``` Setup: Windows 11, NVIDIA GeForce RTX 3070 8 GB (driver 617.14, `VK_EXT_memory_budget` reports a budget of about 7 GB for heap 0), MinGW GCC 15.2 Release, relinked with `--to-intel`. Before the abort, heap 0 usage swings between about 4.5 and 13 GB while the `[gpu]` budget lines report only about 2 GB of sampled textures and 2 GB of cached storage images. The host-memory fallback count in `DeviceMemoryType` reaches 65,536 allocations (182 GB in total). I measured where the memory goes with two local debug hooks (not for merging): one wraps `vkAllocateMemory`/`vkFreeMemory` and sums live bytes per call site, and one keeps a `weak_ptr` to every image `evictStorage` removes. 1. **Live memory by call site at the peak (19.3 GB live):** `StorageTexture::StorageTexture` holds 10.0 GB in 2,191 allocations, all in memory type 0 (heap 1, the host fallback). `createHostPointerImport` holds 5.2 GB (expected). Texture and buffer-pool allocations make up the rest. 2. **The storage cache stays at its budget, but evicted images stay alive:** for example, the cache held 288 entries / 2,040 MiB while 1,472 images it had evicted (5,602 MiB) were still alive. At another point it was 720 images / 3.3 GB, and later the count drops back to about 10, so they are released eventually, not leaked. Most survivors have 1 or 3 other owners. 3. **Every eviction is the LRU one, and most creations re-create an evicted surface:** 12,866 evictions (0 from the mip-extension path, 0 from `MetadataMoved`), and 11,894 of 13,265 creations were for a key evicted earlier. Only about 245 distinct base addresses are involved. 4. **The working set is larger than the budget and cycles as a whole:** 1,371 distinct storage surfaces, about 5.4 GB by `heldBytes`, and 1,359 of them were created again within the last 10 seconds. Two things I tried locally that did not help: - `APS5_TEXTURE_CACHE_MIB=3072`: about 34,000 evictions, same abort. - Making the LRU loop skip entries whose `texture.use_count() > 1`: re-creations fell from about 11,900 to about 1,700, but evicted images still reached about 4 GB alive, and the run aborted sooner, on a device buffer allocation in presentation. So on an 8 GB card the problem seems to be two things together: a storage working set of about 5.4 GB cycling through a 2 GB LRU budget, and each evicted image staying alive until its other owners let go, so the re-created copy and the old one exist at the same time. #3256 had a similar shape (the resource cache's entry bound pinned storage images past their budget, fixed by #3473 and #3474). I have not identified the other owners yet. The image tables from #757 are one candidate, since their resource-cache keys include the table's T# list, but I have not confirmed that. I can run any proposed change on this card with Wolverine and post the same numbers. Full logs are available if useful (no game data in them). AI-assisted: yes
MarcZX10 commented 2026-10-14 17:33:42 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T17:33:42Z.


I traced the eviction path on current main. evictStorage marks an image uncached and queues it with noteUncached; sampled views that hold the image are removed later when dropUncachedViews drains that queue from a sampled-cache lookup (or TextureCacheUsage). So a stretch of storage-only lookups can leave stale sampled-view references alive after storage-cache eviction.

Could your existing eviction hook count how many TextureCache.views entries point at each evicted image, then compare that with the images that remain alive? If the sampled-view count tracks those survivors, we have a focused cleanup path to investigate. If it does not, the remaining owners are more likely in-flight resource captures or another cache, and we should trace those separately.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6174392159 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961#issuecomment-6174392159). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T17:33:42Z. --- I traced the eviction path on current `main`. `evictStorage` marks an image uncached and queues it with `noteUncached`; sampled views that hold the image are removed later when `dropUncachedViews` drains that queue from a sampled-cache lookup (or `TextureCacheUsage`). So a stretch of storage-only lookups can leave stale sampled-view references alive after storage-cache eviction. Could your existing eviction hook count how many `TextureCache.views` entries point at each evicted image, then compare that with the images that remain alive? If the sampled-view count tracks those survivors, we have a focused cleanup path to investigate. If it does not, the remaining owners are more likely in-flight resource captures or another cache, and we should trace those separately.
tv7 commented 2026-10-14 18:29:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T18:29:49Z.


@MarcZX100 I counted it. Under the storage-cache mutex, every 10 s, each evicted image that is still alive is checked against Textures().views (taken with try_lock on the sampled cache's mutex; it was never busy at a report), together with the size of the Uncached() queue. Same setup as above (main e34c47921, RTX 3070 8 GB, Wolverine), one 900 s run:

Evictions so far Evicted images still alive With a sampled view Without Uncached() queue
2,942 122 (432 MiB) 1 (24 MiB) 121 (408 MiB) 1
6,851 224 (1,080 MiB) 0 224 (1,080 MiB) 0
9,197 519 (2,999 MiB) 1 (15 MiB) 518 (2,984 MiB) 1
11,697 1,647 (6,993 MiB) 0 1,647 (6,993 MiB) 0
14,730 1,531 (6,224 MiB) 1 (0 MiB) 1,529 (6,206 MiB) 0
18,709 1,873 (8,283 MiB) 0 1,873 (8,283 MiB) 0

The sampled cache held 880 to 1,740 entries and 490 to 970 views at the same points. So the survivors are not held by sampled views: the drain keeps up and at most one survivor has a view. Going by your split, that points at owners outside the texture caches, such as recorded work that has not completed yet. I can count a specific holder next if you have one in mind.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175450941 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961#issuecomment-6175450941). Originally posted by [tv7](https://github.com/tv7) on 2026-10-14T18:29:49Z. --- @MarcZX100 I counted it. Under the storage-cache mutex, every 10 s, each evicted image that is still alive is checked against `Textures().views` (taken with `try_lock` on the sampled cache's mutex; it was never busy at a report), together with the size of the `Uncached()` queue. Same setup as above (`main` e34c47921, RTX 3070 8 GB, Wolverine), one 900 s run: | Evictions so far | Evicted images still alive | With a sampled view | Without | `Uncached()` queue | |---|---|---|---|---| | 2,942 | 122 (432 MiB) | 1 (24 MiB) | 121 (408 MiB) | 1 | | 6,851 | 224 (1,080 MiB) | 0 | 224 (1,080 MiB) | 0 | | 9,197 | 519 (2,999 MiB) | 1 (15 MiB) | 518 (2,984 MiB) | 1 | | 11,697 | 1,647 (6,993 MiB) | 0 | 1,647 (6,993 MiB) | 0 | | 14,730 | 1,531 (6,224 MiB) | 1 (0 MiB) | 1,529 (6,206 MiB) | 0 | | 18,709 | 1,873 (8,283 MiB) | 0 | 1,873 (8,283 MiB) | 0 | The sampled cache held 880 to 1,740 entries and 490 to 970 views at the same points. So the survivors are not held by sampled views: the drain keeps up and at most one survivor has a view. Going by your split, that points at owners outside the texture caches, such as recorded work that has not completed yet. I can count a specific holder next if you have one in mind. AI-assisted: yes
MarcZX10 commented 2026-10-14 18:35:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T18:35:19Z.


Thanks, that rules out sampled views as the main owner. I traced the current eviction path a step further: cachedStorageTexture calls SharedResourceCache().RemoveImage, then passes each returned ShaderResources to Recorder::Keep while recording. The resource cache removes entries that read the evicted image at ResourceCache::RemoveImage.

Could you count, at each report, how many surviving images are referenced by those recorder-kept ShaderResources objects (and whether their owning submissions have completed)? If that matches the survivor count, it would narrow this to recording/submission retirement; if not, we can trace another owner class. This is a more direct next check than sampled-cache accounting.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175554374 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961#issuecomment-6175554374). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T18:35:19Z. --- Thanks, that rules out sampled views as the main owner. I traced the current eviction path a step further: `cachedStorageTexture` calls [`SharedResourceCache().RemoveImage`](https://github.com/boykopovar/AnyPS5/blob/587b63d2a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L928-L933), then passes each returned `ShaderResources` to `Recorder::Keep` while recording. The resource cache removes entries that read the evicted image at [`ResourceCache::RemoveImage`](https://github.com/boykopovar/AnyPS5/blob/587b63d2a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L3235-L3245). Could you count, at each report, how many surviving images are referenced by those recorder-kept `ShaderResources` objects (and whether their owning submissions have completed)? If that matches the survivor count, it would narrow this to recording/submission retirement; if not, we can trace another owner class. This is a more direct next check than sampled-cache accounting.
MarcZX10 commented 2026-10-14 18:47:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T18:47:58Z.


I opened PR #5998 to charge storage images retained by recorded draw/dispatch batches against the existing recorder kept-byte budget. It covers direct storage operations, ShaderResources references and draw targets, with per-image deduplication within each batch.

The local checkout could not be built because its SDL2 submodule/system package is unavailable, and CI skipped compilation jobs, so this still needs runtime confirmation. Since you offered to rerun Wolverine, could you try this branch and share the same evicted-but-alive image counts and peak allocation/heap usage? That should show whether recorder-held references account for the survivors and whether recorder backpressure reduces overlap between evicted images and recreated copies.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175792213 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961#issuecomment-6175792213). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T18:47:58Z. --- I opened [PR #5998](https://github.com/boykopovar/AnyPS5/pull/5998) to charge storage images retained by recorded draw/dispatch batches against the existing recorder kept-byte budget. It covers direct storage operations, `ShaderResources` references and draw targets, with per-image deduplication within each batch. The local checkout could not be built because its SDL2 submodule/system package is unavailable, and CI skipped compilation jobs, so this still needs runtime confirmation. Since you offered to rerun Wolverine, could you try this branch and share the same evicted-but-alive image counts and peak allocation/heap usage? That should show whether recorder-held references account for the survivors and whether recorder backpressure reduces overlap between evicted images and recreated copies.
tv7 commented 2026-10-14 19:39:32 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T19:39:32Z.


Opened #6030 for the abort part: the storage cache keeps new images in the open batch without their size, and an evicted image that recorded work still holds is not counted anywhere, so Recorder::BoundKeptBytes never bounds them. With their size in the batch's kept bytes, Wolverine ran 900 s on this card without the abort (296 non-fatal storage-texture allocation failures remain, peak heap usage 8.7 GiB). The eviction churn itself is unchanged.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6176776333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961#issuecomment-6176776333). Originally posted by [tv7](https://github.com/tv7) on 2026-10-14T19:39:32Z. --- Opened #6030 for the abort part: the storage cache keeps new images in the open batch without their size, and an evicted image that recorded work still holds is not counted anywhere, so `Recorder::BoundKeptBytes` never bounds them. With their size in the batch's kept bytes, Wolverine ran 900 s on this card without the abort (296 non-fatal storage-texture allocation failures remain, peak heap usage 8.7 GiB). The eviction churn itself is unchanged. AI-assisted: yes
Thunderhawkk commented 2026-10-15 02:33:57 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Thunderhawkk on 2026-10-15T02:33:57Z.


Measured follow-up on the same machine (RTX 5070 Ti 16 GB, Windows 11 26200, driver 617.42) while bringing PPSA03671 up on current main with #6194 in the build — the CPU side of the same scene, separate from the storage churn:

  • APS5_PROFILE_DRAW, [resources] over 3000 builds: stage B 98–100 s, images 88–90 s; one dispatch (421,247-word shader) spent 9,575 ms in resources alone.
  • Image tables: ~100k elements resolved per 10 s (1,478,198 in 200 s); image tables 0 reused, 703 resolved per 10 s.
  • Local instrumentation (not for merging): tables are never remembered — FindReusedTable reports no match 100% with remembered tables = 0, because the remember gate is all-or-nothing: one element that is not a clean lookup (DCC address, storage-sourced view, …) discards the whole table.
  • Raising APS5_RESOURCE_CACHE_TABLE_ELEMENTS 16× changes nothing; the ~4,000 resource-cache misses per 10 s are not a table-budget problem.
  • Stage-A sampled fast path fails almost always: 35 fast hits of 9,963 records.

Proposal (your call on safety): remember tables with per-element flags and reuse per element; gate cross-submission reuse on GuestMemory::Watched (stamps trustworthy on watched ranges) instead of the thread epoch in TableState, which currently blocks all cross-submission reuse. I can implement and measure this on the title.

A performance-trace capture can be produced on request.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6183085406 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961#issuecomment-6183085406). Originally posted by [Thunderhawkk](https://github.com/Thunderhawkk) on 2026-10-15T02:33:57Z. --- Measured follow-up on the same machine (RTX 5070 Ti 16 GB, Windows 11 26200, driver 617.42) while bringing PPSA03671 up on current `main` with #6194 in the build — the CPU side of the same scene, separate from the storage churn: - `APS5_PROFILE_DRAW`, `[resources]` over 3000 builds: stage B 98–100 s, images 88–90 s; one dispatch (421,247-word shader) spent 9,575 ms in resources alone. - Image tables: ~100k elements resolved per 10 s (1,478,198 in 200 s); `image tables 0 reused, 703 resolved` per 10 s. - Local instrumentation (not for merging): tables are never remembered — `FindReusedTable` reports `no match` 100% with remembered tables = 0, because the remember gate is all-or-nothing: one element that is not a clean lookup (DCC address, storage-sourced view, …) discards the whole table. - Raising `APS5_RESOURCE_CACHE_TABLE_ELEMENTS` 16× changes nothing; the ~4,000 resource-cache misses per 10 s are not a table-budget problem. - Stage-A sampled fast path fails almost always: 35 fast hits of 9,963 records. Proposal (your call on safety): remember tables with per-element flags and reuse per element; gate cross-submission reuse on `GuestMemory::Watched` (stamps trustworthy on watched ranges) instead of the thread epoch in `TableState`, which currently blocks all cross-submission reuse. I can implement and measure this on the title. A performance-trace capture can be produced on request.
MarcZX10 commented 2026-10-15 08:46:22 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T08:46:22Z.


I checked the current table reuse path. A potentially narrow option is to cache eligible elements within the existing collect-epoch and invalidation rules, so one ineligible element no longer prevents the rest of a table from being reused. I would keep the current memory, pending-write, depth-surface, allocation, and texture-cache checks; Watched alone is not enough because GPU writes have separate stamps. Could you capture, for repeated identical tables, how many elements meet the current direct-cache criteria (source == nullptr, nonzero generation, uncompressed keys, no DCC) and how many are rejected for each reason? That would show whether a focused same-epoch change would address measurable work.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6188165218 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961#issuecomment-6188165218). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-15T08:46:22Z. --- I checked the current table reuse path. A potentially narrow option is to cache eligible elements within the existing collect-epoch and invalidation rules, so one ineligible element no longer prevents the rest of a table from being reused. I would keep the current memory, pending-write, depth-surface, allocation, and texture-cache checks; `Watched` alone is not enough because GPU writes have separate stamps. Could you capture, for repeated identical tables, how many elements meet the current direct-cache criteria (`source == nullptr`, nonzero generation, uncompressed keys, no DCC) and how many are rejected for each reason? That would show whether a focused same-epoch change would address measurable work.
MarcZX10 commented 2026-10-18 15:39:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T15:39:50Z.


The retained-image accounting fix has now merged in #5998 (merge commit 91ddd9e3a, now on main). It charges storage images retained by recorded work to the recorder budget, addressing the reported case where evicted images stayed alive but were no longer counted. I have not rerun the original 8 GB Wolverine scenario on this merged main, so the title outcome remains unverified. The separate image-table reuse and eviction-churn work is still tracked in open PRs #6340, #6223, and #6194.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251799779 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5961#issuecomment-6251799779). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T15:39:50Z. --- The retained-image accounting fix has now merged in #5998 (merge commit `91ddd9e3a`, now on `main`). It charges storage images retained by recorded work to the recorder budget, addressing the reported case where evicted images stayed alive but were no longer counted. I have not rerun the original 8 GB Wolverine scenario on this merged main, so the title outcome remains unverified. The separate image-table reuse and eviction-churn work is still tracked in open PRs #6340, #6223, and #6194.
Sign in to join this conversation.
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#5961
No description provided.