perf(agc): key sampled textures without the streaming-feedback fields #1865

Merged
fisherjoey merged 2 commits from upstream-pr/1865 into main 2026-10-10 04:16:10 +00:00
fisherjoey commented 2026-10-08 22:25:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T22:25:03Z.


What

MakeTextureKey copies the eight raw T# words into the sampled-texture cache key. Three 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 and ignores them, so they never change the texture, but they do change the key. Demon's Souls rotates the counter fields per use, so each streaming texture ends up under about six keys. Every new key is a fresh snapshot (about 5 MiB for a 2048x2048 BC texture), and the stale variants push live textures out under the budget.

MakeTextureKey now clears those three fields before the words go into the key, so two descriptors that differ only in them share one entry.

Closes #1790.

Tested

Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti, driver 595.91.07.

  • Rebased on current main (ae91d978), no conflicts.
  • ctest -R "agc_driver|guest_agc_driver": 202 of 202 pass, without APS5_WRITE_WATCH_IMPORTS. agc_driver_lds_atomics64 and agc_driver_scalar_sop1 are excluded; they fail on unmodified main on this GPU too (the first one hangs it).
  • python3 tools/check_conventions.py --base origin/main: passes.
  • There's no new test: the cache has no hook a test can observe the key through.
  • Demon's Souls (PPSA01341 v1.07), tutorial level, per 10 s, with an 8 GiB texture budget:
before after
budget evictions 656-1017 0
texture cache churning at the budget 1260 entries, 8162 MiB, all resident
draw resource binding 1856 ms 54 ms
level fps 0.80 1.10

Before the change, every evicted entry was a stale key of a texture still cached under another key (711 of 711, 780 of 780 and 948 of 948 in three windows). These numbers come from a local build (an older main with #861 and other patches) that also raised the pipeline store's 256-entry bound, so the fps change isn't from the key alone. The eviction and binding numbers are. The level's texture set is about 8 GiB, so it still won't fit main's fixed 2 GiB budget; #1059 sizes the budget from device memory. Without this change the six variants of each texture compete for whatever budget there is.

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4793517838 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1865). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T22:25:03Z. --- ### What `MakeTextureKey` copies the eight raw T# words into the sampled-texture cache key. Three 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 and ignores them, so they never change the texture, but they do change the key. Demon's Souls rotates the counter fields per use, so each streaming texture ends up under about six keys. Every new key is a fresh snapshot (about 5 MiB for a 2048x2048 BC texture), and the stale variants push live textures out under the budget. `MakeTextureKey` now clears those three fields before the words go into the key, so two descriptors that differ only in them share one entry. Closes #1790. ### Tested Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti, driver 595.91.07. - Rebased on current `main` (ae91d978), no conflicts. - `ctest -R "agc_driver|guest_agc_driver"`: 202 of 202 pass, without `APS5_WRITE_WATCH_IMPORTS`. `agc_driver_lds_atomics64` and `agc_driver_scalar_sop1` are excluded; they fail on unmodified `main` on this GPU too (the first one hangs it). - `python3 tools/check_conventions.py --base origin/main`: passes. - There's no new test: the cache has no hook a test can observe the key through. - Demon's Souls (PPSA01341 v1.07), tutorial level, per 10 s, with an 8 GiB texture budget: | | before | after | |---|---|---| | budget evictions | 656-1017 | 0 | | texture cache | churning at the budget | 1260 entries, 8162 MiB, all resident | | draw resource binding | 1856 ms | 54 ms | | level fps | 0.80 | 1.10 | Before the change, every evicted entry was a stale key of a texture still cached under another key (711 of 711, 780 of 780 and 948 of 948 in three windows). These numbers come from a local build (an older `main` with #861 and other patches) that also raised the pipeline store's 256-entry bound, so the fps change isn't from the key alone. The eviction and binding numbers are. The level's texture set is about 8 GiB, so it still won't fit `main`'s fixed 2 GiB budget; #1059 sizes the budget from device memory. Without this change the six variants of each texture compete for whatever budget there is. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
fisherjoey commented 2026-10-08 23:05:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T23:05:34Z.


Added a test (1dcefb40). SampledTexturesShareEntry in ShaderResources compares two T#s through the cache's own key and hash. RunGuestTextureResourceTests checks that T#s differing only in MIN_LOD_WARN, MIP_STATS_COUNTER_EN or MIP_STATS_COUNTER_ID share an entry, and that a different base address, format or CORNER_SAMPLE (word 5 bit 23, between the cleared fields) still gives a separate one.

On main (f1451396 with only the test cherry-picked), agc_driver_graphics fails:

AGC graphics: T#s differing only in MIN_LOD_WARN, MIP_STATS_COUNTER_EN and MIP_STATS_COUNTER_ID must share a sampled texture entry

On the branch it passes. Also rebased on f1451396.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6070797933 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1865#issuecomment-6070797933). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-08T23:05:34Z. --- Added a test (1dcefb40). `SampledTexturesShareEntry` in ShaderResources compares two T#s through the cache's own key and hash. `RunGuestTextureResourceTests` checks that T#s differing only in MIN_LOD_WARN, MIP_STATS_COUNTER_EN or MIP_STATS_COUNTER_ID share an entry, and that a different base address, format or CORNER_SAMPLE (word 5 bit 23, between the cleared fields) still gives a separate one. On `main` (f1451396 with only the test cherry-picked), `agc_driver_graphics` fails: ``` AGC graphics: T#s differing only in MIN_LOD_WARN, MIP_STATS_COUNTER_EN and MIP_STATS_COUNTER_ID must share a sampled texture entry ``` On the branch it passes. Also rebased on f1451396.
popcoder565 commented 2026-10-09 19:43:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T19:43:15Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 36997299, merged onto main 8b393b6e in one build with 31 other PRs that had no Windows run.

  • agc_driver_graphics, which includes GuestTextureResource.cpp, passes.
  • Full ctest in that build: 520 of 521. The one failure is guest_offline_imports, broken by #2359 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088030678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1865#issuecomment-6088030678). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T19:43:15Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `36997299`, merged onto `main` 8b393b6e in one build with 31 other PRs that had no Windows run. - `agc_driver_graphics`, which includes `GuestTextureResource.cpp`, passes. - Full ctest in that build: 520 of 521. The one failure is `guest_offline_imports`, broken by #2359 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
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!1865
No description provided.