AGC: dynamic resolution makes the storage cache hold ~4.8x the guest memory and re-create ~400 images/s (Wolverine on an 8 GB card) #6099
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T22:04:32Z.
With #5998, Marvel's Wolverine (PPSA03671) no longer aborts for device memory on an 8 GB card (#5961). The storage-image cache still thrashes in the same scene: about 400 storage images created per second, 99.6 % of them re-creations of a surface it evicted moments earlier (@CnRJay's point in #5998). I measured where the working set comes from. Most of it is one render target per base address, re-made at every step of the title's dynamic resolution, each step as a separate host image. Host memory for these images is about 4.8 times the guest memory they cover, so no budget near 2 GiB can hold them, and LRU over a repeating cycle gets almost no hits.
I'd like to fix this, but the change is architectural, so I'm asking how you'd want it done before writing it.
Setup
Windows 11, 32 GB RAM, RTX 3070 8 GB (driver 617.14,
VK_EXT_memory_budgetreports about 7.1 GiB for heap 0), GCC 15.2.0 UCRT, Release, relinked with--to-intel. Base:mainwith #5998 (c1a9f6957). Each run is 900 s in the same scene. The numbers come from local counters added tocachedStorageTextureandevictStorage(not for merging). They log every 10 s:guestBytesandheldBytes.The extents and formats listed below are from the existing
StorageTexture address=... WxH ... format=... vk=...log lines.1. Churn: every eviction is LRU, and nearly every creation is a re-creation
MetadataMovedevictions)The surfaces involved sit at only 284 distinct base addresses over the whole run.
2. The cache budget does not matter here
APS5_TEXTURE_CACHE_MIB=3072, onmainbefore #5998)3. The working set is about 4.8 times the guest memory it covers
Over the surfaces created in each 10 s window (steady state; whole run in brackets):
heldBytes[baseAddress, baseAddress + guestBytes)Grouped by base address and Vulkan format, there are 303 pairs over the run. 199 of them are seen at more than one extent, and 76 at ten or more. Almost every surface is a plain 2D image (1,361 of 1,492 have one mip and no array layers), and 1,145 use tile mode 7.
4. The cause: dynamic resolution
These are the surfaces at the busiest base address, 0x115df30000 (40 keys). They are the same address with the same tile mode (7), in four formats, each at a ladder of extents in 128×72 steps:
vk 122(B10G11R11_UFLOAT) andvk 37(R8G8B8A8_UNORM): 512×512 and 1664×936, 1792×1008, 1920×1080, 2048×1152, 2304×1296, 2560×1440, 2816×1584, 3072×1728, 3328×1872.vk 97(R16G16B16A16_SFLOAT): 1024×576, 1152×648, 1280×720, 1408×792, 1536×864, 1664×936, 832×468, 896×504, 960×540, 256×256.vk 109: 128×128 and 416×234 up to 832×468.The formats most often seen at several extents per address are
vk 122(41 addresses),37(32),9(30),97(25),76(14),83(11),100(10) and98(8).So the title keeps its render targets at fixed addresses and changes their extent with its resolution scale. On the console that costs nothing, because the target is just drawn smaller in the same memory. Here, every new extent is a new
SurfaceKey, so a new image is allocated, uploaded and later written back. With about 20 extents per target, the working set no longer fits, and the cache cycles through all of it.Proposed direction (open to yours)
Let storage images over the same guest range share device memory instead of each owning an allocation. For example:
VkDeviceMemoryblock per base address, sized for the largest surface seen there and grown when a larger one appears;VkImagebound to that block;Then a resolution change costs an image object and a bind, not an allocation plus an upload of guest memory. By the numbers above, the resident total would be about 1.3 GiB instead of 5.9 GiB.
What this has to keep correct, and where I'd want your view:
FlushPendingdoes at creation today), and the new surface must be refreshed from guest memory. It can't assume the previous surface's texels survive in a meaningful layout, because the layout differs per extent (and per tile mode).DepthSurfaceStorage),ExtendedChains, and the resource cache's per-image keys.A cheaper alternative, if you'd rather not alias memory: when a new extent appears at an address and format whose old surface has no pending results, reuse the old image's allocation if it is large enough (an allocation pool keyed by size). That saves the allocation but not the upload.
Is shared memory per guest range a direction you'd accept, and is there a part of it you'd want done first or differently? I can run any branch on this scene with the same counters.
Related: #5961, #5998, #5997, #5483.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-16T01:43:30Z.
Silent Hill Townfall: the open storage-cache PRs measured in gameplay (Windows, RTX 3070 8 GB)
A second title with the same pattern as this issue. With #6160 and #6083, Silent Hill Townfall (
--windows) reaches gameplay (the harbor after New Game; movement and the pause menu respond) at about 0.45 FPS. In that scene the device-local heap is over budget (7.5 of 7.1 GiB, storage textures and device buffers placed in host memory), the GPU averages ~60 %, and no CPU thread is saturated (busiest: queue worker 0x0 at ~30 % of a core). stdout gets ~250,000 storage-image creation lines per 20 minutes, so storage images are re-created all the time here too.Setup
main31cbb55d7+ #6160 (d1a68c4ae) + #6083 (f7b2ebd8b), needed to reach gameplayd6fe6551b, #61948bb130068. "All five" = all merged together (only conflict was theStorageCacheBudget.cpptest file).ANYPS5_NO_SHADER_CACHE=1, OBS Vulkan layer disabled, 1260 s per run, scripted input (title -> New Game -> Start Game), same scene.Results
Base and all-five runs alternated. The single-PR runs ran afterwards, one each, and all of them (including #6473) came in slightly below the base average, so I read that as drift over the 4-hour series rather than a regression. With one run each they don't separate the PRs.
What this shows for Silent Hill
0xc0000005inlibc.prx.guest.prx+0x14920while the title was formatting a UELowLevelFatalError. The same crash at the same address happened in three earlier Silent Hill runs without any of these PRs, so it's an existing boot flake, not from these PRs.So on this title the cost is still the cache churn this issue describes (one host image per shape over memory the title reuses). The open PRs don't change it. Logs and per-run frame counters are available if anyone wants them.
Imported from boykopovar/AnyPS5. Originally posted by Capmare on 2026-10-18T18:30:00Z.
Marvel's Wolverine (PPSA03671) now runs past its intro movies to the first game menus on Linux with an RTX 4070 SUPER. The storage-image churn described in this issue was the first thing that blocked it, so these are the measurements and the changes that removed it.
Setup: Linux, RTX 4070 SUPER (12 GB, driver 615.71), the head of #7395 (
aed137cae) plus local patches, relinked with--to-intel. The patches are not ready to merge; the numbers below are for one title.The churn on the #7395 head. One run showed no frame in 211 s. It built 62,675 storage images, and 84 % of them belonged to families of one address and format at several extents (148 address and format pairs, 77 of them with 10 or more extents, the same pattern as in the tables above). Device memory filled, 17 GB of textures moved to host memory, and the run never presented.
What removed it (mostly in the driver):
StorageTexture::LastWrite, falling back to the active depth extent, then to the largest accessible surface). The other entries (1,433 per table here) borrow that texture.AccessedFlag). The driver skips an entry that stayed unread for 3 s (DeferredCode). This needs two small changes in the recompiler (ImageTableAbi.hpp,SpirvImageEmitter.cpp) and an ABI version bump. Without it, a 5,746-entry table built 4,269 textures per pass and evicted about as many.Result: 1,044 storage-image builds in a whole 216 s run (was 62,675 in 211 s), peak GPU memory 11.0 GB, no out-of-memory abort, first frame at 117 s on a cold shader cache and 21 s on a warm one.
Other findings that may help:
0x11d049aa00) becomes 2.7 million SPIR-V words and takes 19 to 20 minutes to compile on NVIDIA (1,222 s offline withagc_compute_pipeline_replay). The SPIR-V optimizer gave no gain on a 1M-word shader (23.0 s against 23.0 s). RemovingDontInlinegave -20 % on the 1M-word shader but was slower on the giant one. Emptyingrecord_bda_faultgave -11 %. A switch that compiles pipelines above a size in a background thread and skips their dispatches meanwhile brings a cold start from 19 minutes down to 119 s.INDEX_BUFFER_SIZE has not been setwhen the GPU pass that fillsINDEX_ATTRIBUTES_INDIRECThas not run. A zero range should draw nothing, as the CP clamps it.Several descriptor-chain shapes are still replaced locally by null textures and samplers, so some pictures are wrong. I can run any branch on this title and report counters.
Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-19T03:26:31Z.
The same churn on a 16 GB card, on Windows.
Setup: Windows 11 Pro 26300, RTX 4080 SUPER 16 GB (NVIDIA 617.42;
VK_EXT_memory_budgetreports 15,279 MiB for heap 0 at start), Ryzen 7 5800X3D, 32 GB RAM, WinLibs GCC 15.2.0 r7, Release. Marvel's Wolverine (PPSA03671 01.001.005) converted withrelinker --windows. Base:mainf3059421f+ #6901 (needed to load). Every run is the same scene, the "Sony Interactive Entertainment presents" card, with no input andAPS5_PROFILE_DRAW=1; "~400 s" is the 40th cumulative[textures]report.StorageTexture address=lines of one 620 s run: 412,682 creations, 1,528 distinct (address, extent, Vulkan format) combinations at 351 base addresses. 150 (address, Vulkan format) pairs appear at more than one extent, 80 of them at ten or more. One of them, 0x114c6c0000 with vk 122, appears at 19 extents: 256x256, 512x512 and 17 16:9 extents from 832x468 to 3328x1872.uses 16128 of its 14773 MiB budget). Theplaced in host memorylines reached 8,192 texture allocations (19,664 MiB) and 2,048 device-buffer allocations (7,212 MiB) in one run, and 4,096 (12,264 MiB) and 8,192 (19,342 MiB) in the other. No allocation returned -2 in 16 runs, so the abort of #5961 does not happen on this card, but the overrun does.8bb130068) changed the churn, 347,592 created and 173,139 hits, with presents unchanged (42 against 40) and its budget moving 128 times between 1,733 and 6,118 MiB. #6340 (0dad1b2ac) reused 220 tables and #6223 (8729fc234) 146,580 table elements, without changing creations (396,999 and 399,390) or presents (40). #6194 and #6223 conflict with currentmain; I resolved the conflicts locally for these runs (main's four-argumentStorageTextureBudgetcall, main's storage-table check kept in the reuse condition).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ionut27001 on 2026-10-19T10:19:20Z.
A profile of where the re-creations cost CPU time, same scene as above (the Sony card),
mainf78675ae4+ #6901, Windows 11, RTX 4080 SUPER (617.42),APS5_SAMPLE_WORKERon the dispatching queue worker over 300 s: of the samples insideShaderResources::resolveImageTables, 50 % are the destruction of the storage images the cache evicts (StorageTexture::release:vkFreeMemoryandvkDestroyImage, which end in kernel calls throughwin32u.dll) and 40 % their creation (StorageTexture::Create, mostlyvkAllocateMemory); the lookups themselves are the rest. The buffer pool already keeps released device buffers for reuse, but image memory is allocated and freed oneVkDeviceMemoryat a time.I'm preparing a PR that keeps the device memory of released storage images in the buffer pool and hands it to the next image of the same memory type and size, so a re-creation costs neither call. It does not change which images are created. @Capmare, if the scratch pool in your patches already covers this, say so and I'll drop it.
Imported from boykopovar/AnyPS5. Originally posted by Capmare on 2026-10-19T10:28:01Z.
Thanks for the profile. The scratch pool in my patches does not cover this. It only pools the staging buffers of sampled-texture uploads. It never keeps or reuses the device memory of released storage images. So your PR is a separate change, and I think it is worth sending.
On my side, two other changes cut the churn: building only one variant per surface, and skipping image-table entries that stay unread. With both, one Wolverine run builds 1,044 storage images instead of 62,675. Your change should still lower the cost of the re-creations that remain. I can test your branch on Linux with an RTX 4070 SUPER and report build counts and timings.
Imported from boykopovar/AnyPS5. Originally posted by Capmare on 2026-10-19T12:50:16Z.
Data from Marvel's Wolverine (PPSA03671) on Linux, NVIDIA GeForce RTX 4070 SUPER (driver 615.71.09). The same churn shows on two builds, in two places:
main(b106f6f8c), 319 s: no frame was presented. The log has 20,392 sampled-texture creations, with the same surfaces created about 418 times each (for example0x1175b40000). GPU memory is full (11.95 of 12 GB) from second 95, and the log saystexture caches released 0 MiB of the 256 MiB asked for ... (cache or device busy, skipped).0x115df300007,681 times.On my local tree, building one representative per family of a surface that appears at several extents (dynamic-resolution variants), and building image-table entries lazily, cuts a Wolverine run from 62,675 storage-image builds to 1,044, and the title then makes frames. That is the part of this issue that dynamic resolution causes.
Does anyone already work on a one-variant-per-surface change? If not, I will send mine as a PR. I can only open one at a time while #7816 is unmerged, so it comes after that. @ionut27001: your pooling of released storage-image memory is complementary, since it lowers the cost of the re-creations that remain.