renderer: fix cache accounting and eviction scans under memory pressure #977

Closed
github-bot wants to merge 2 commits from gh-pr/977/head into gh-pr/977/base
Owner

@⁠tototomate123 on GitHub · 2026-10-02 14:30 UTC · original
tototomate123:fix/cache-memory-pressure → main · +47 −14 · 3 files · 2 commits · closed without merging

Two cache fixes found while investigating HFW memory pressure, in separate commits:

  • Keep cache-owned allocation counters separate from driver usage estimates, preventing incorrect accounting during eviction.
  • Scan past protected textures so they cannot exhaust the candidate budget and hide reclaimable entries. Preserve depth/stencil eviction limits.

Reference: VMA allocation statistics versus driver usage/budget.

Validation: Linux/Clang build and buffer/texture cache checks pass. The regression with twelve protected textures before one reclaimable texture fails without the scan fix and passes with it.

AI-assisted implementation.

**@⁠tototomate123** on GitHub · 2026-10-02 14:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/977) `tototomate123:fix/cache-memory-pressure` → `main` · +47 −14 · 3 files · 2 commits · closed without merging Two cache fixes found while investigating HFW memory pressure, in separate commits: - Keep cache-owned allocation counters separate from driver usage estimates, preventing incorrect accounting during eviction. - Scan past protected textures so they cannot exhaust the candidate budget and hide reclaimable entries. Preserve depth/stencil eviction limits. Reference: [VMA allocation statistics versus driver usage/budget](https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/statistics.html). Validation: Linux/Clang build and buffer/texture cache checks pass. The regression with twelve protected textures before one reclaimable texture fails without the scan fix and passes with it. AI-assisted implementation.
Use driver residency only to choose garbage collection pressure. Keep registered buffer/image byte counters independent so eviction cannot subtract cache-owned allocations from a lower device-usage snapshot. Reduce the texture pressure estimate with saturation after eviction, while retaining the exact owned-byte invariant.
Apply GPU-owned tiled/non-pressure protection during LRU candidate collection as well as retirement. Continue past protected entries without changing the depth/stencil traversal budget. Add a regression with twelve protected images before one reclaimable image; preserve GPU contents while reclaiming the later entry.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:39:04 +00:00
github-bot closed this pull request 2026-11-26 09:39:04 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-02 14:54 UTC · original

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6e395995-3f9a-402f-b287-f170c333576f

📥 Commits

Reviewing files that changed from the base of the PR and between e317465d8a and 8dd843e6ab.

📒 Files selected for processing (3)
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

BufferCache and TextureCache now use reported device memory usage for garbage-collection thresholds when available, with cache-owned bytes as a fallback. TextureCache also filters candidates based on image and pressure conditions, then updates its local usage estimate after freeing an image. A new test checks that collection removes the final texture in a set of 13 while retaining the first 12.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 8dd84

No actionable issue remains from this review; the change is mergeable after normal checks.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 8dd84

The changes correct allocation accounting and prevent protected textures from hiding reclaimable entries. The inspected changes preserve resource-ownership checks and retirement controls, without introducing new entrypoints or privileges.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Device-wide pressure can influence eviction timing, but collection still operates on each cache's own resource identifiers. The changes do not confer authority to retire unrelated device allocations or expand the existing guest-to-renderer entrypoint boundary.

Trust Boundaries and Controls

  • observed — Dirty-buffer retirement validates GPU ownership, queues downloads, waits for GPU completion and priority operations, and checks that GPU ownership is cleared before releasing tracked pages and buffer storage. These controls remain outside the modified pressure-selection logic.

Resilience and Maintainability Implications

  • observed — Invalid texture transfers or failed guest backing reads return before reclamation. Successful readback callbacks capture the download buffer and guest range rather than the image object. Deferred destruction waits for GPU completion and priority callbacks, preserving the inspected readback-before-release ordering.
🚥 Pre-merge checks | ✅ 4 | ❓ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the two main changes: cache accounting and eviction scanning under memory pressure.
Description check ✅ Passed The description directly explains the cache accounting fix, protected-texture scan, depth/stencil behavior, validation, and regression coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 too large.)

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-02 14:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/977#issuecomment-5955084365) <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/977?cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `6e395995-3f9a-402f-b287-f170c333576f` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e317465d8a773b33482ad367ad2f856154c8bc6d and 8dd843e6ab90ca39642a5747f74a1022048a7813. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough BufferCache and TextureCache now use reported device memory usage for garbage-collection thresholds when available, with cache-owned bytes as a fallback. TextureCache also filters candidates based on image and pressure conditions, then updates its local usage estimate after freeing an image. A new test checks that collection removes the final texture in a set of 13 while retaining the first 12. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"8dd843e6ab90ca39642a5747f74a1022048a7813" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `8dd84` <!-- final_review_risk_coverage:{"sourceCommitId":"8dd843e6ab90ca39642a5747f74a1022048a7813","coveredCommitId":"8dd843e6ab90ca39642a5747f74a1022048a7813","kind":"reviewed"} --> No actionable issue remains from this review; the change is mergeable after normal checks. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _⚪ Minimal_ · up to `8dd84` The changes correct allocation accounting and prevent protected textures from hiding reclaimable entries. The inspected changes preserve resource-ownership checks and retirement controls, without introducing new entrypoints or privileges. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — Device-wide pressure can influence eviction timing, but collection still operates on each cache's own resource identifiers. The changes do not confer authority to retire unrelated device allocations or expand the existing guest-to-renderer entrypoint boundary. **Trust Boundaries and Controls** - _observed_ — Dirty-buffer retirement validates GPU ownership, queues downloads, waits for GPU completion and priority operations, and checks that GPU ownership is cleared before releasing tracked pages and buffer storage. These controls remain outside the modified pressure-selection logic. **Resilience and Maintainability Implications** - _observed_ — Invalid texture transfers or failed guest backing reads return before reclamation. Successful readback callbacks capture the download buffer and guest range rather than the image object. Deferred destruction waits for GPU completion and priority callbacks, preserving the inspected readback-before-release ordering. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❓ 1</summary> ### ❌ Failed checks (1 inconclusive) | Check name | Status | Explanation | Resolution | | :----------------: | :------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ❓ Inconclusive | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly and concisely describes the two main changes: cache accounting and eviction scanning under memory pressure. | | Description check | ✅ Passed | The description directly explains the cache accounting fix, protected-texture scan, depth/stencil behavior, validation, and regression coverage. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> <details> <summary>Full details: Docstring Coverage</summary> **Explanation** Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 too large.) </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts > Autopilot is currently an internal CodeRabbit preview. <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=977)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.