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

Open
opened 2026-10-14 22:04:32 +00:00 by tv7 · 6 comments
tv7 commented 2026-10-14 22:04:32 +00:00 (Migrated from github.com)
Contributor

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_budget reports about 7.1 GiB for heap 0), GCC 15.2.0 UCRT, Release, relinked with --to-intel. Base: main with #5998 (c1a9f6957). Each run is 900 s in the same scene. The numbers come from local counters added to cachedStorageTexture and evictStorage (not for merging). They log every 10 s:

  • creations, hits and evictions with their reason;
  • re-creations of a key evicted earlier;
  • for each surface created in the last 10 s: its key, base address, guestBytes and heldBytes.

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

Run (900 s) Created Re-created after an eviction LRU evictions (mip-extension / MetadataMoved evictions) Hits
#5998 377,506 376,014 (99.6 %) 376,758 (0 / 0) 101,544 (21 % of lookups)
#5998 + #5483 (budget 1,807 MiB) 367,651 366,158 (99.6 %) 367,365 (0 / 0) n/a

The surfaces involved sit at only 284 distinct base addresses over the whole run.

2. The cache budget does not matter here

Storage cache budget Result
2,048 MiB (default) about 400 creations/s (above)
1,807 MiB (#5483) the same, within 2 %
3,072 MiB (APS5_TEXTURE_CACHE_MIB=3072, on main before #5998) about 34,000 evictions before the device-memory abort, the same thrash
2,048 MiB with a local bimodal-insertion experiment (new entries at the LRU end, every 32nd at the front) 23 % fewer creations at equal run time, hits rise to 57 %, still about 300 creations/s

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):

Value
Distinct storage surfaces (cache keys) about 1,460 (1,492)
Base addresses about 260 (284)
Most surfaces at one base address 40
Host images, sum of heldBytes 5,931 MiB (5,992)
Largest surface per base address, summed 1,289 MiB (1,332)
Union of the guest ranges [baseAddress, baseAddress + guestBytes) 1,228 MiB (1,245)

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) and vk 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) and 98 (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:

  • one VkDeviceMemory block per base address, sized for the largest surface seen there and grown when a larger one appears;
  • each surface keeps its own VkImage bound to that block;
  • cache accounting is per block, not per image.

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:

  1. Pending results of an alias. Before a different surface over the same block is used, the pending results of the previous one must reach guest memory (as FlushPending does 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).
  2. Two aliases in one batch. Two surfaces sharing a block can be bound by different draws in the same batch, so barriers are needed between them. The simplest rule is probably that switching aliases in a block needs the same ordering as a write-after-write on the guest range.
  3. Fit with existing code. This touches the eviction and refresh paths, depth surfaces (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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5856451249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6099). Originally posted by [tv7](https://github.com/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_budget` reports about 7.1 GiB for heap 0), GCC 15.2.0 UCRT, Release, relinked with `--to-intel`. Base: `main` with #5998 (c1a9f6957). Each run is 900 s in the same scene. The numbers come from local counters added to `cachedStorageTexture` and `evictStorage` (not for merging). They log every 10 s: - creations, hits and evictions with their reason; - re-creations of a key evicted earlier; - for each surface created in the last 10 s: its key, base address, `guestBytes` and `heldBytes`. 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 | Run (900 s) | Created | Re-created after an eviction | LRU evictions (mip-extension / `MetadataMoved` evictions) | Hits | |---|---|---|---|---| | #5998 | 377,506 | 376,014 (99.6 %) | 376,758 (0 / 0) | 101,544 (21 % of lookups) | | #5998 + #5483 (budget 1,807 MiB) | 367,651 | 366,158 (99.6 %) | 367,365 (0 / 0) | n/a | The surfaces involved sit at only 284 distinct base addresses over the whole run. ### 2. The cache budget does not matter here | Storage cache budget | Result | |---|---| | 2,048 MiB (default) | about 400 creations/s (above) | | 1,807 MiB (#5483) | the same, within 2 % | | 3,072 MiB (`APS5_TEXTURE_CACHE_MIB=3072`, on `main` before #5998) | about 34,000 evictions before the device-memory abort, the same thrash | | 2,048 MiB with a local bimodal-insertion experiment (new entries at the LRU end, every 32nd at the front) | 23 % fewer creations at equal run time, hits rise to 57 %, still about 300 creations/s | ### 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): | | Value | |---|---| | Distinct storage surfaces (cache keys) | about 1,460 (1,492) | | Base addresses | about 260 (284) | | Most surfaces at one base address | 40 | | Host images, sum of `heldBytes` | **5,931 MiB** (5,992) | | Largest surface per base address, summed | 1,289 MiB (1,332) | | Union of the guest ranges `[baseAddress, baseAddress + guestBytes)` | **1,228 MiB** (1,245) | 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) and `vk 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) and `98` (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: - one `VkDeviceMemory` block per base address, sized for the largest surface seen there and grown when a larger one appears; - each surface keeps its own `VkImage` bound to that block; - cache accounting is per block, not per image. 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: 1. **Pending results of an alias.** Before a different surface over the same block is used, the pending results of the previous one must reach guest memory (as `FlushPending` does 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). 2. **Two aliases in one batch.** Two surfaces sharing a block can be bound by different draws in the same batch, so barriers are needed between them. The simplest rule is probably that switching aliases in a block needs the same ordering as a write-after-write on the guest range. 3. **Fit with existing code.** This touches the eviction and refresh paths, depth surfaces (`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
tv7 commented 2026-10-16 01:43:30 +00:00 (Migrated from github.com)
Author
Contributor

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

  • Windows 11 26200, i7-11700KF, 32 GB RAM, RTX 3070 8 GB (NVIDIA 617.14), WinLibs GCC 15.2, Release
  • Base: main 31cbb55d7 + #6160 (d1a68c4ae) + #6083 (f7b2ebd8b), needed to reach gameplay
  • Each PR merged on top of base at its current head: #6473 de7139081, #6340 ef724aad6, #5998 c1a9f6957, #6174 d6fe6551b, #6194 8bb130068. "All five" = all merged together (only conflict was the StorageCacheBudget.cpp test file).
  • Same relinked executable per build, ANYPS5_NO_SHADER_CACHE=1, OBS Vulkan layer disabled, 1260 s per run, scripted input (title -> New Game -> Start Game), same scene.
  • FPS = frame-counter difference over the same 510 s window in the harbor (150-660 s after Start Game).

Results

build runs harbor FPS GPU avg VRAM peak game RAM peak stdout lines
base 3 0.427 / 0.449 / 0.445 (avg 0.440) 58-62 % 7.39-7.46 GB 28-29 GB 223k-290k
all five 3 (1 crashed at boot, see below) 0.484 / 0.453 (avg 0.469) 60-64 % 7.40-7.46 GB 28-29 GB 22k-25k
+ #6473 1 0.414 61 % 7.42 GB 28.9 GB 23k
+ #6340 1 0.425 58 % 7.42 GB 28.2 GB 282k
+ #5998 1 0.422 59 % 7.41 GB 28.1 GB 279k
+ #6174 1 0.409 57 % 7.49 GB 28.3 GB 270k
+ #6194 1 0.409 57 % 7.43 GB 27.8 GB 272k

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

  • #6473 does what it says: stdout goes from ~280k to ~23k lines (-92 %). No measurable FPS change here (writing to a file, not a console).
  • No PR, and not all five together, reduces storage-image re-creation (the creation lines in the non-#6473 runs stay at 258k-276k vs 212k-276k on base) or VRAM pressure (7.4-7.5 GB in every run).
  • All five together: about +6 % FPS (0.469 vs 0.440). The ranges barely separate (0.453 vs 0.449), so I can't call it more than a small gain.
  • No new failures from the PRs: every run that booted reached the harbor and ran to the timeout.
  • The all-five run that crashed failed ~1 min into boot with 0xc0000005 in libc.prx.guest.prx+0x14920 while the title was formatting a UE LowLevelFatalError. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206118255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6099#issuecomment-6206118255). Originally posted by [tv7](https://github.com/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** - Windows 11 26200, i7-11700KF, 32 GB RAM, RTX 3070 8 GB (NVIDIA 617.14), WinLibs GCC 15.2, Release - Base: `main` 31cbb55d7 + #6160 (d1a68c4ae) + #6083 (f7b2ebd8b), needed to reach gameplay - Each PR merged on top of base at its current head: #6473 de7139081, #6340 ef724aad6, #5998 c1a9f6957, #6174 d6fe6551b, #6194 8bb130068. "All five" = all merged together (only conflict was the `StorageCacheBudget.cpp` test file). - Same relinked executable per build, `ANYPS5_NO_SHADER_CACHE=1`, OBS Vulkan layer disabled, 1260 s per run, scripted input (title -> New Game -> Start Game), same scene. - FPS = frame-counter difference over the same 510 s window in the harbor (150-660 s after Start Game). **Results** | build | runs | harbor FPS | GPU avg | VRAM peak | game RAM peak | stdout lines | |---|---|---|---|---|---|---| | base | 3 | 0.427 / 0.449 / 0.445 (avg 0.440) | 58-62 % | 7.39-7.46 GB | 28-29 GB | 223k-290k | | all five | 3 (1 crashed at boot, see below) | 0.484 / 0.453 (avg 0.469) | 60-64 % | 7.40-7.46 GB | 28-29 GB | 22k-25k | | + #6473 | 1 | 0.414 | 61 % | 7.42 GB | 28.9 GB | 23k | | + #6340 | 1 | 0.425 | 58 % | 7.42 GB | 28.2 GB | 282k | | + #5998 | 1 | 0.422 | 59 % | 7.41 GB | 28.1 GB | 279k | | + #6174 | 1 | 0.409 | 57 % | 7.49 GB | 28.3 GB | 270k | | + #6194 | 1 | 0.409 | 57 % | 7.43 GB | 27.8 GB | 272k | 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** - #6473 does what it says: stdout goes from ~280k to ~23k lines (-92 %). No measurable FPS change here (writing to a file, not a console). - No PR, and not all five together, reduces storage-image re-creation (the creation lines in the non-#6473 runs stay at 258k-276k vs 212k-276k on base) or VRAM pressure (7.4-7.5 GB in every run). - All five together: about +6 % FPS (0.469 vs 0.440). The ranges barely separate (0.453 vs 0.449), so I can't call it more than a small gain. - No new failures from the PRs: every run that booted reached the harbor and ran to the timeout. - The all-five run that crashed failed ~1 min into boot with `0xc0000005` in `libc.prx.guest.prx+0x14920` while the title was formatting a UE `LowLevelFatalError`. 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.
Capmare commented 2026-10-18 18:30:00 +00:00 (Migrated from github.com)
Author
Contributor

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):

  • Dynamic-resolution variants. For one surface at several extents, the image table builds only the variant that matches the newest GPU write (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.
  • Lazy image-table entries. The shader marks each entry it reads (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.
  • The scratch pool and reduced-size build for large tables from my earlier patches (about 81 % fewer Vulkan allocations; the first large pass fell from 5.0 s to 0.95 s).

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:

  • One compute shader (0x11d049aa00) becomes 2.7 million SPIR-V words and takes 19 to 20 minutes to compile on NVIDIA (1,222 s offline with agc_compute_pipeline_replay). The SPIR-V optimizer gave no gain on a 1M-word shader (23.0 s against 23.0 s). Removing DontInline gave -20 % on the 1M-word shader but was slower on the giant one. Emptying record_bda_fault gave -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.
  • The game then stops at INDEX_BUFFER_SIZE has not been set when the GPU pass that fills INDEX_ATTRIBUTES_INDIRECT has not run. A zero range should draw nothing, as the CP clamps it.
  • A pixel shader reads a slot that holds a T# (the 960x540 display target) as a buffer descriptor, and a 2D T# is sampled through a 2D-array image shape. Both are accepted on hardware.

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253549503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6099#issuecomment-6253549503). Originally posted by [Capmare](https://github.com/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):** - Dynamic-resolution variants. For one surface at several extents, the image table builds only the variant that matches the newest GPU write (`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. - Lazy image-table entries. The shader marks each entry it reads (`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. - The scratch pool and reduced-size build for large tables from my earlier patches (about 81 % fewer Vulkan allocations; the first large pass fell from 5.0 s to 0.95 s). **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:** - One compute shader (`0x11d049aa00`) becomes 2.7 million SPIR-V words and takes 19 to 20 minutes to compile on NVIDIA (1,222 s offline with `agc_compute_pipeline_replay`). The SPIR-V optimizer gave no gain on a 1M-word shader (23.0 s against 23.0 s). Removing `DontInline` gave -20 % on the 1M-word shader but was slower on the giant one. Emptying `record_bda_fault` gave -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. - The game then stops at `INDEX_BUFFER_SIZE has not been set` when the GPU pass that fills `INDEX_ATTRIBUTES_INDIRECT` has not run. A zero range should draw nothing, as the CP clamps it. - A pixel shader reads a slot that holds a T# (the 960x540 display target) as a buffer descriptor, and a 2D T# is sampled through a 2D-array image shape. Both are accepted on hardware. 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.*
ionut27001 commented 2026-10-19 03:26:31 +00:00 (Migrated from github.com)
Author
Contributor

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_budget reports 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 with relinker --windows. Base: main f3059421f + #6901 (needed to load). Every run is the same scene, the "Sony Interactive Entertainment presents" card, with no input and APS5_PROFILE_DRAW=1; "~400 s" is the 40th cumulative [textures] report.

  • Storage image cache budget at start: 3,819 MiB. Two base runs: 388,678 / 395,008 storage images created by ~400 s, against 110,907 / 112,433 hits; 0 image tables reused.
  • From the 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.
  • Heap 0 goes over its reported budget (uses 16128 of its 14773 MiB budget). The placed in host memory lines 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.
  • Open PRs merged one at a time on the same base, counts at ~400 s: only #6194 (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 current main; I resolved the conflicts locally for these runs (main's four-argument StorageTextureBudget call, main's storage-table check kept in the reuse condition).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6258989321 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6099#issuecomment-6258989321). Originally posted by [ionut27001](https://github.com/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_budget` reports 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 with `relinker --windows`. Base: `main` f3059421f + #6901 (needed to load). Every run is the same scene, the "Sony Interactive Entertainment presents" card, with no input and `APS5_PROFILE_DRAW=1`; "~400 s" is the 40th cumulative `[textures]` report. - Storage image cache budget at start: 3,819 MiB. Two base runs: 388,678 / 395,008 storage images created by ~400 s, against 110,907 / 112,433 hits; 0 image tables reused. - From the `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. - Heap 0 goes over its reported budget (`uses 16128 of its 14773 MiB budget`). The `placed in host memory` lines 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. - Open PRs merged one at a time on the same base, counts at ~400 s: only #6194 (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 current `main`; I resolved the conflicts locally for these runs (main's four-argument `StorageTextureBudget` call, main's storage-table check kept in the reuse condition). AI-assisted: yes
ionut27001 commented 2026-10-19 10:19:20 +00:00 (Migrated from github.com)
Author
Contributor

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), main f78675ae4 + #6901, Windows 11, RTX 4080 SUPER (617.42), APS5_SAMPLE_WORKER on the dispatching queue worker over 300 s: of the samples inside ShaderResources::resolveImageTables, 50 % are the destruction of the storage images the cache evicts (StorageTexture::release: vkFreeMemory and vkDestroyImage, which end in kernel calls through win32u.dll) and 40 % their creation (StorageTexture::Create, mostly vkAllocateMemory); the lookups themselves are the rest. The buffer pool already keeps released device buffers for reuse, but image memory is allocated and freed one VkDeviceMemory at 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6264954175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6099#issuecomment-6264954175). Originally posted by [ionut27001](https://github.com/ionut27001) on 2026-10-19T10:19:20Z. --- A profile of where the re-creations cost CPU time, same scene as above (the Sony card), `main` f78675ae4 + #6901, Windows 11, RTX 4080 SUPER (617.42), `APS5_SAMPLE_WORKER` on the dispatching queue worker over 300 s: of the samples inside `ShaderResources::resolveImageTables`, 50 % are the destruction of the storage images the cache evicts (`StorageTexture::release`: `vkFreeMemory` and `vkDestroyImage`, which end in kernel calls through `win32u.dll`) and 40 % their creation (`StorageTexture::Create`, mostly `vkAllocateMemory`); the lookups themselves are the rest. The buffer pool already keeps released device buffers for reuse, but image memory is allocated and freed one `VkDeviceMemory` at 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.
Capmare commented 2026-10-19 10:28:01 +00:00 (Migrated from github.com)
Author
Contributor

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6265109797 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6099#issuecomment-6265109797). Originally posted by [Capmare](https://github.com/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.
Capmare commented 2026-10-19 12:50:16 +00:00 (Migrated from github.com)
Author
Contributor

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:

  • Current 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 example 0x1175b40000). GPU memory is full (11.95 of 12 GB) from second 95, and the log says texture caches released 0 MiB of the 256 MiB asked for ... (cache or device busy, skipped).
  • #7395 head (59b319a779), about 9 min: no frame was presented. 284,392 storage-image creations on 371 addresses, for example 0x115df30000 7,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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6267614925 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6099#issuecomment-6267614925). Originally posted by [Capmare](https://github.com/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: - **Current `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 example `0x1175b40000`). GPU memory is full (11.95 of 12 GB) from second 95, and the log says `texture caches released 0 MiB of the 256 MiB asked for ... (cache or device busy, skipped)`. - **#7395 head (59b319a779), about 9 min:** no frame was presented. 284,392 storage-image creations on 371 addresses, for example `0x115df30000` 7,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.
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#6099
No description provided.