AGC: the sampled-texture cache keys on the T# streaming-feedback fields, so a title that rotates them caches each texture several times #1790

Closed
opened 2026-10-08 19:16:12 +00:00 by fisherjoey · 2 comments
fisherjoey commented 2026-10-08 19:16:12 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T19:16:12Z.


Summary

MakeTextureKey (Graphics/src/ShaderResources.cpp:82 on main 6b56175a) copies the eight raw T# words into the key. Three of the fields in those words are texture-streaming feedback: MIN_LOD_WARN (word 5 bits 8-19), MIP_STATS_COUNTER_EN (word 5 bit 25) and MIP_STATS_COUNTER_ID (word 6 bits 0-7). DecodeTextureResource reads them and ignores them (GuestTextureResource.cpp:103), so they never change what the texture returns, but they do change the key.

Demon's Souls rotates MIP_STATS_COUNTER_EN and MIP_STATS_COUNTER_ID per use (counter ids 0x0d / 0x4d / 0xad). Each streaming texture in the level ends up under about six keys. Each new key is a fresh snapshot (vkCreateImage + vkAllocateMemory, about 5 MiB for a 2048x2048 BC texture), and the stale variants push live textures out under the budget.

Evidence

Demon's Souls (PPSA01341 v1.07), tutorial level, per 10 s:

  • 656-1017 budget evictions. With a "live twin at the same address" counter added: 711 of 711, 780 of 780, 948 of 948. Every evicted entry was a stale key of a texture still cached under another key.
  • The [texture] trace for one address shows T# words that differ only in word 5 bit 25 and word 6 bits 0-7.
  • The evicted textures are block-compressed streaming textures (2048x2048 and 1024x1024, tile 3). Each address was re-snapshotted about 7 times in 50 s.

Fix

MakeTextureKey clears the three feedback fields before the words go into the key. Two descriptors that differ only in those fields now share one entry.

Measured on our local build (an older main plus #157, #861 and our own patches), with an 8 GiB texture budget:

before after
budget evictions per 10 s 656-1017 0
texture cache churning at the budget 1260 entries, 8162 MiB, all resident
draw resource binding, per 10 s 1856 ms 54 ms
level fps 0.80 1.10

The same run also raised the pipeline store's 256-entry bound, so the fps change is not from the key alone. The eviction and binding numbers are, since the pipeline bound only affects pipeline creation. The level's texture set is about 8 GiB, so with main's fixed 2 GiB budget it still won't fit. #1059 sizes the budget from device memory. The key change applies either way: without it, the six variants of each texture compete for whatever budget there is.

The fix is ready on a branch: https://github.com/boykopovar/AnyPS5/compare/main...fisherjoey:AnyPS5:perf/texture-key-ignore-feedback

Tests: the 195 agc_driver tests pass on the branch (rebased on 6b56175a); agc_driver_buffer_format timed out once under load and passed on rerun. I didn't add a test because the cache has no hook a test can observe the key through.

Found on Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), with Demon's Souls PPSA01341 v1.07.

I'll open the PR if the approach looks right.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5767553268 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1790). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T19:16:12Z. --- ### Summary `MakeTextureKey` (`Graphics/src/ShaderResources.cpp:82` on `main` 6b56175a) copies the eight raw T# words into the key. Three of the fields in those words are texture-streaming feedback: MIN_LOD_WARN (word 5 bits 8-19), MIP_STATS_COUNTER_EN (word 5 bit 25) and MIP_STATS_COUNTER_ID (word 6 bits 0-7). `DecodeTextureResource` reads them and ignores them (`GuestTextureResource.cpp:103`), so they never change what the texture returns, but they do change the key. Demon's Souls rotates MIP_STATS_COUNTER_EN and MIP_STATS_COUNTER_ID per use (counter ids 0x0d / 0x4d / 0xad). Each streaming texture in the level ends up under about six keys. Each new key is a fresh snapshot (vkCreateImage + vkAllocateMemory, about 5 MiB for a 2048x2048 BC texture), and the stale variants push live textures out under the budget. ### Evidence Demon's Souls (PPSA01341 v1.07), tutorial level, per 10 s: - 656-1017 budget evictions. With a "live twin at the same address" counter added: 711 of 711, 780 of 780, 948 of 948. Every evicted entry was a stale key of a texture still cached under another key. - The `[texture]` trace for one address shows T# words that differ only in word 5 bit 25 and word 6 bits 0-7. - The evicted textures are block-compressed streaming textures (2048x2048 and 1024x1024, tile 3). Each address was re-snapshotted about 7 times in 50 s. ### Fix `MakeTextureKey` clears the three feedback fields before the words go into the key. Two descriptors that differ only in those fields now share one entry. Measured on our local build (an older `main` plus #157, #861 and our own patches), with an 8 GiB texture budget: | | before | after | |---|---|---| | budget evictions per 10 s | 656-1017 | 0 | | texture cache | churning at the budget | 1260 entries, 8162 MiB, all resident | | draw resource binding, per 10 s | 1856 ms | 54 ms | | level fps | 0.80 | 1.10 | The same run also raised the pipeline store's 256-entry bound, so the fps change is not from the key alone. The eviction and binding numbers are, since the pipeline bound only affects pipeline creation. The level's texture set is about 8 GiB, so with `main`'s fixed 2 GiB budget it still won't fit. #1059 sizes the budget from device memory. The key change applies either way: without it, the six variants of each texture compete for whatever budget there is. The fix is ready on a branch: https://github.com/boykopovar/AnyPS5/compare/main...fisherjoey:AnyPS5:perf/texture-key-ignore-feedback Tests: the 195 `agc_driver` tests pass on the branch (rebased on 6b56175a); `agc_driver_buffer_format` timed out once under load and passed on rerun. I didn't add a test because the cache has no hook a test can observe the key through. Found on Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), with Demon's Souls PPSA01341 v1.07. I'll open the PR if the approach looks right. AI-assisted: yes.
MarcZX10 commented 2026-10-08 20:35:10 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:35:10Z.


I reviewed fisherjoey:perf/texture-key-ignore-feedback against current main. The masks match the fields GuestTextureResource.cpp decodes as unreported streaming feedback: word 5 bits 8–19 and bit 25, plus word 6 bits 0–7. The descriptor fields that affect the returned texture remain in the key, so I don't see a semantic issue with this normalization.

git diff --check is clean. I haven't independently measured the title or run the reported AGC tests. The branch is based on 6b56175a; current main is 4b6ab6bb, so please rebase before opening the PR and rerun the focused checks on that head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6068561173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1790#issuecomment-6068561173). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T20:35:10Z. --- I reviewed `fisherjoey:perf/texture-key-ignore-feedback` against current `main`. The masks match the fields `GuestTextureResource.cpp` decodes as unreported streaming feedback: word 5 bits 8–19 and bit 25, plus word 6 bits 0–7. The descriptor fields that affect the returned texture remain in the key, so I don't see a semantic issue with this normalization. `git diff --check` is clean. I haven't independently measured the title or run the reported AGC tests. The branch is based on `6b56175a`; current main is `4b6ab6bb`, so please rebase before opening the PR and rerun the focused checks on that head.
MarcZX10 commented 2026-10-08 20:56:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:56:37Z.


Update: upstream main is now aa277b3; the prepared texture-key branch is still based on 6b56175 (1 commit ahead, 22 behind). My earlier rebase note referred to the then-current 4b6ab6b. Please rebase on aa277b3 and rerun the focused AGC checks before opening the PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6068901444 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1790#issuecomment-6068901444). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T20:56:37Z. --- Update: upstream `main` is now `aa277b3`; the prepared texture-key branch is still based on `6b56175` (1 commit ahead, 22 behind). My earlier rebase note referred to the then-current `4b6ab6b`. Please rebase on `aa277b3` and rerun the focused AGC checks before opening the PR.
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#1790
No description provided.