fix(agc): keep sampled views that hold no cache bytes out of the released set #17573

Merged
NFSS10 merged 1 commit from upstream-pr/17573 into main 2026-11-21 09:17:53 +00:00
NFSS10 commented 2026-11-08 23:02:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NFSS10 on 2026-11-08T23:02:30Z.


What

A sampled texture that the texture cache drops while a descriptor set still holds it is marked released, and ResourceCache::Insert refuses every descriptor set that holds a released texture and removes the entries that do. The marking also covered the entries that account for no cache bytes: the views of cached storage images. Dropping such an entry frees nothing, but it invalidated every descriptor set that sampled the surface, so those descriptor sets were built again on every use.

In The Bendy and the Ink Machine the 4K RGBA16F scene surface is written by a compute dispatch and sampled by the draw that follows. Its storage image leaves the storage cache every frame, so its sampled view was dropped and marked released every frame, and the descriptor set that sampled the surface was discarded and built again every frame. The main menu then washed out to white about 30 s after the title reached it, the symptom PR #4794 had fixed before the released-texture mechanism landed in #6492.

Only the entries that account for cache bytes are marked released now. A view of a cached storage image is dropped from the sampled cache without marking its texture, so the descriptor sets that sample the surface stay cached and the menu keeps its colour. A view of a storage image that is not cached accounts the image's bytes and is still marked released, so the memory the released-texture mechanism reclaims is unchanged.

The debt entry for the released-texture mechanism names the exemption.

Tested

  • OS: Windows 11 Pro 10.0.22631 (build 22631). GPU: AMD Radeon RX 7900 GRE, driver 32.0.21013.1000 (2025-05-26).
  • The Bendy and the Ink Machine, main menu, on main and on this branch, same machine and build tree: on main the menu washes out to white (mean RGB 249, 249, 246 over the frames dumped from the menu onwards); on this branch it keeps the menu colour (mean RGB 120, 87, 16.5) for the whole 55 s the game watched the menu.
  • ctest --test-dir build -R 'sampled_cache|staged_clear|resource_cache|texture_cache': 16/16 pass on main and on this branch, with ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1. The check added to viewEvictionTests fails without the fix ("a view that accounted for no cache bytes was marked released when its entry left the sampled cache, which frees nothing and rebuilds every descriptor set that holds it").
  • ctest --test-dir build -R '^agc_driver_': 1047/1058 pass, 15 skipped. The 11 failures are the fp16, mesh, sdwa and vop2 shader tests that fail on this machine without this change: the same 11 were run against main in the same build tree and 10 fail there too (agc_driver_unregistered_label_on_gpu is flaky and fails on main in other runs).
  • python3 tools/check_conventions.py --base upstream/main: 0 errors (the debt entry it warns about was already over the 1000-character limit on main).
  • The Vulkan validation layer is not installed on this machine, so the VUID comparison could not be run here.

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 under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 7900 GRE, driver 32.0.21013.1000 (2025-05-26), Windows 11 Pro 10.0.22631 (build 22631)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5216027515 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17573). Originally posted by [NFSS10](https://github.com/NFSS10) on 2026-11-08T23:02:30Z. --- ### What A sampled texture that the texture cache drops while a descriptor set still holds it is marked released, and `ResourceCache::Insert` refuses every descriptor set that holds a released texture and removes the entries that do. The marking also covered the entries that account for no cache bytes: the views of cached storage images. Dropping such an entry frees nothing, but it invalidated every descriptor set that sampled the surface, so those descriptor sets were built again on every use. In The Bendy and the Ink Machine the 4K RGBA16F scene surface is written by a compute dispatch and sampled by the draw that follows. Its storage image leaves the storage cache every frame, so its sampled view was dropped and marked released every frame, and the descriptor set that sampled the surface was discarded and built again every frame. The main menu then washed out to white about 30 s after the title reached it, the symptom PR #4794 had fixed before the released-texture mechanism landed in #6492. Only the entries that account for cache bytes are marked released now. A view of a cached storage image is dropped from the sampled cache without marking its texture, so the descriptor sets that sample the surface stay cached and the menu keeps its colour. A view of a storage image that is not cached accounts the image's bytes and is still marked released, so the memory the released-texture mechanism reclaims is unchanged. The debt entry for the released-texture mechanism names the exemption. ### Tested - OS: Windows 11 Pro 10.0.22631 (build 22631). GPU: AMD Radeon RX 7900 GRE, driver 32.0.21013.1000 (2025-05-26). - The Bendy and the Ink Machine, main menu, on `main` and on this branch, same machine and build tree: on `main` the menu washes out to white (mean RGB 249, 249, 246 over the frames dumped from the menu onwards); on this branch it keeps the menu colour (mean RGB 120, 87, 16.5) for the whole 55 s the game watched the menu. - `ctest --test-dir build -R 'sampled_cache|staged_clear|resource_cache|texture_cache'`: 16/16 pass on `main` and on this branch, with `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`. The check added to `viewEvictionTests` fails without the fix ("a view that accounted for no cache bytes was marked released when its entry left the sampled cache, which frees nothing and rebuilds every descriptor set that holds it"). - `ctest --test-dir build -R '^agc_driver_'`: 1047/1058 pass, 15 skipped. The 11 failures are the fp16, mesh, sdwa and vop2 shader tests that fail on this machine without this change: the same 11 were run against `main` in the same build tree and 10 fail there too (`agc_driver_unregistered_label_on_gpu` is flaky and fails on `main` in other runs). - `python3 tools/check_conventions.py --base upstream/main`: 0 errors (the debt entry it warns about was already over the 1000-character limit on `main`). - The Vulkan validation layer is not installed on this machine, so the VUID comparison could not be run here. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 7900 GRE, driver 32.0.21013.1000 (2025-05-26), Windows 11 Pro 10.0.22631 (build 22631) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 15:58:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T15:58:23Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing in the inspected change shows a blocking defect; the patch exempts sampled cache entries with zero accounted bytes from released-texture marking.

What I ran

Reviewed head e23c6c759b0e7dbdc7d8dfc7ba4758d8debbecd4 using repo_read.py to inspect the prepared diff and relevant source lines. No commands or tests were run.

Results

Check Result Note
Diff and changed logic passed Inspected implementation and regression assertion
Tests not run Test results in the description were author-reported

Findings

Blocking

None in the inspected code.

Non-blocking

None.

Not verified

The full text of ShaderResources.cpp was excluded from the review folder; only lines 270–355 and targeted search matches were read through repo_read.py. The test file’s relevant changed function and the new debt entry were read in full. No test output, full-file behavior, or Vulkan validation was independently verified. Files in the prepared bundle: ShaderResources.cpp (excluded as too large), SampledCacheBudget.cpp, and fix-agc-uncached-view-release.md (both included).

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5995539362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17573#pullrequestreview-5995539362). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T15:58:23Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing in the inspected change shows a blocking defect; the patch exempts sampled cache entries with zero accounted bytes from released-texture marking. ## What I ran Reviewed head `e23c6c759b0e7dbdc7d8dfc7ba4758d8debbecd4` using `repo_read.py` to inspect the prepared diff and relevant source lines. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed logic | passed | Inspected implementation and regression assertion | | Tests | not run | Test results in the description were author-reported | ## Findings ### Blocking None in the inspected code. ### Non-blocking None. ## Not verified The full text of `ShaderResources.cpp` was excluded from the review folder; only lines 270–355 and targeted search matches were read through `repo_read.py`. The test file’s relevant changed function and the new debt entry were read in full. No test output, full-file behavior, or Vulkan validation was independently verified. Files in the prepared bundle: `ShaderResources.cpp` (excluded as too large), `SampledCacheBudget.cpp`, and `fix-agc-uncached-view-release.md` (both included). ## To get this to a good state Nothing is required.
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!17573
No description provided.