gpu: cut BDA synchronization and write-tracking overhead (PPSA09809) #1809

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

@⁠MrBigBritches on GitHub · 2026-10-22 02:54 UTC · original
MrBigBritches:bda-sync-perf → main · +602 −25 · 7 files · 3 commits · closed without merging

Every shader that reads memory through BDA synchronizes the pages queued since the previous one. In Octopath Traveler II this cost a lot:

  • Game-thread writes were uploaded over and over: a write fault on a game thread queued its page at once. Pages the game keeps writing for later frames were uploaded again at nearly every BDA draw.
  • Each dirty buffer took its own upload: every buffer a queued range touched got its own staging allocation and two whole-buffer barriers, even when an ordinary binding had already uploaded the pages. A busy draw found a few hundred of them.
  • Buffers were only retired under memory pressure: a large GPU rarely reaches that. Once the game reused a buffer's memory for CPU data, its pages stayed write-protected, so every write faulted and was uploaded again. The cache grew to ~3,500 buffers, with ~145k write faults and ~600 MB of uploads per second.

Changes

  1. Hold game-thread BDA events until the command processor resumes. Events from game-thread invalidations are queued separately. They're promoted when a submission starts or resumes, or when a WAIT_REG_MEM passes (its value may guard data a game thread wrote). GPU-thread writes still queue immediately. Promotion skips the lock when nothing is deferred.
  2. Upload BDA synchronization through one staging copy. SynchronizeBda collects the still-dirty runs of every buffer in the queued, mapped ranges with one tracker walk per buffer. It uploads them through one staging allocation, between one pair of barriers, with one copy command per buffer. The collected copies are kept in a member, so their storage is reused.
  3. Release buffers that nothing has bound for 300 frames. Each GC tick releases up to 16 clean buffers that no draw or dispatch has bound for 300 ticks, and untracks their pages.
    • Kept: buffers holding GPU-written data.
    • Pinned: a shader that reads a released page through BDA reports it in the fault buffer. The buffer is recreated and pinned, so it's never released for being unbound. A buffer that absorbs a pinned one keeps the pin.
    • Its own list: the release walks a list of buffers ordered by their last binding. Buffers it keeps move to the young end, so the walk reaches the buffers behind them. Memory-pressure eviction still uses the regular LRU list, so it still finds old GPU-written buffers.

Results (Octopath Traveler II)

The cache stays at ~700 buffers and ~100 MB. Write faults drop to ~65k/s, and field and battle scenes hold 60 fps.

Tests

  • CheckBdaSyncDeferredEvents: deferred events stay hidden until promotion, and are promoted once, into an empty or a non-empty set.
  • CheckBdaSyncUploads: a game-thread write waits for promotion.
  • CheckBdaSyncBatchesBuffers: one synchronization uploads every dirty page into the right buffer and offset.
  • CheckBufferCacheReleasesUnboundBuffers: clean unbound buffers are released; pinned, GPU-written and recent ones are kept; a pin survives a merge.
  • CheckBufferCacheReleaseWalksPastKeptBuffers: with more kept buffers than one walk visits, a clean buffer behind them is still released.

memory_tracker and shader_recompiler_compute pass.

Notes

Rebased onto main after the BDA queue moved into BufferCache (f356fa3). PrepareBda calls BufferCache::SynchronizeBda again.

**@⁠MrBigBritches** on GitHub · 2026-10-22 02:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809) `MrBigBritches:bda-sync-perf` → `main` · +602 −25 · 7 files · 3 commits · closed without merging Every shader that reads memory through BDA synchronizes the pages queued since the previous one. In Octopath Traveler II this cost a lot: - **Game-thread writes were uploaded over and over:** a write fault on a game thread queued its page at once. Pages the game keeps writing for later frames were uploaded again at nearly every BDA draw. - **Each dirty buffer took its own upload:** every buffer a queued range touched got its own staging allocation and two whole-buffer barriers, even when an ordinary binding had already uploaded the pages. A busy draw found a few hundred of them. - **Buffers were only retired under memory pressure:** a large GPU rarely reaches that. Once the game reused a buffer's memory for CPU data, its pages stayed write-protected, so every write faulted and was uploaded again. The cache grew to ~3,500 buffers, with ~145k write faults and ~600 MB of uploads per second. ## Changes 1. **Hold game-thread BDA events until the command processor resumes.** Events from game-thread invalidations are queued separately. They're promoted when a submission starts or resumes, or when a `WAIT_REG_MEM` passes (its value may guard data a game thread wrote). GPU-thread writes still queue immediately. Promotion skips the lock when nothing is deferred. 2. **Upload BDA synchronization through one staging copy.** `SynchronizeBda` collects the still-dirty runs of every buffer in the queued, mapped ranges with one tracker walk per buffer. It uploads them through one staging allocation, between one pair of barriers, with one copy command per buffer. The collected copies are kept in a member, so their storage is reused. 3. **Release buffers that nothing has bound for 300 frames.** Each GC tick releases up to 16 clean buffers that no draw or dispatch has bound for 300 ticks, and untracks their pages. - **Kept:** buffers holding GPU-written data. - **Pinned:** a shader that reads a released page through BDA reports it in the fault buffer. The buffer is recreated and pinned, so it's never released for being unbound. A buffer that absorbs a pinned one keeps the pin. - **Its own list:** the release walks a list of buffers ordered by their last binding. Buffers it keeps move to the young end, so the walk reaches the buffers behind them. Memory-pressure eviction still uses the regular LRU list, so it still finds old GPU-written buffers. ## Results (Octopath Traveler II) The cache stays at ~700 buffers and ~100 MB. Write faults drop to ~65k/s, and field and battle scenes hold 60 fps. ## Tests - `CheckBdaSyncDeferredEvents`: deferred events stay hidden until promotion, and are promoted once, into an empty or a non-empty set. - `CheckBdaSyncUploads`: a game-thread write waits for promotion. - `CheckBdaSyncBatchesBuffers`: one synchronization uploads every dirty page into the right buffer and offset. - `CheckBufferCacheReleasesUnboundBuffers`: clean unbound buffers are released; pinned, GPU-written and recent ones are kept; a pin survives a merge. - `CheckBufferCacheReleaseWalksPastKeptBuffers`: with more kept buffers than one walk visits, a clean buffer behind them is still released. `memory_tracker` and `shader_recompiler_compute` pass. ## Notes Rebased onto main after the BDA queue moved into `BufferCache` (`f356fa3`). `PrepareBda` calls `BufferCache::SynchronizeBda` again.
Every shader that uses BDA synchronizes the pages queued since the
previous one. A write fault on a game thread queued its page at once,
so pages the game keeps writing for later frames were uploaded again
at nearly every BDA draw.

Queue BDA events from game-thread invalidations separately and promote
them when the command processor starts or resumes a submission, or
passes a WAIT_REG_MEM whose value a game thread may have written after
the data it guards. GPU-thread writes still queue immediately, since
later draws of the same submission can read them.

Promotion runs at every submission slice and passing wait, and usually
finds nothing deferred: a flag set with each deferred event lets it
return without taking the lock. When the immediate set is empty, the
deferred set is swapped in whole.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
BDA synchronization synchronized every registered buffer that a queued
range touched, one buffer at a time: each one took its own staging
allocation and two whole-buffer barriers, even when the queued pages had
already been uploaded by an ordinary binding. A busy draw found a few
hundred such buffers.

BufferCache::SynchronizeBda now takes the queued ranges inside mapped
memory, collects the runs that are still CPU-modified with one tracker
walk per buffer range, and uploads them all through one staging
allocation, with the copies recorded between a single pair of global
barriers and copies into the same buffer sharing one copy command. The
collected copies are kept in a member so their storage is reused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The buffer cache retired buffers only under memory pressure, which a
large GPU rarely reaches. Once the game reused a buffer's memory for
CPU data, its pages stayed write-protected: every write faulted, and
BDA synchronization uploaded the page again. In Octopath Traveler II
the cache grew to 3,500 buffers within minutes, with ~145k write
faults and ~600 MB of uploads per second, half of them for buffers no
draw had bound for over 100 frames.

Each GC tick, release up to 16 clean buffers that no draw or dispatch
has bound for 300 ticks, untracking their pages. Buffers holding
GPU-written data are kept. A shader that reads a released page through
the BDA page table reports it in the fault buffer, which recreates the
buffer; such buffers are now pinned, so they are never released for
being unbound, and a buffer that absorbs a pinned one keeps the pin.
The release walks its own list of buffers ordered by their last
binding, and moves the buffers it keeps to the young end, so the walk,
which visits at most 256 buffers per tick, reaches the buffers behind
them. The memory-pressure LRU list is left untouched, so pressure
eviction still finds old GPU-written buffers.

The cache now stays at ~700 buffers and ~100 MB, write faults drop to
~65k/s, and field and battle scenes hold 60 fps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:06:17 +00:00
github-bot closed this pull request 2026-11-26 10:06:17 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-22 03:00 UTC · original · edited 2026-10-25 23:37 UTC

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 345655df9506e8239250062908d0002f14344128 and 80b4d43b39.

Files selected for processing: 7
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/faultManager.cpp
  • src/graphics/host_gpu/renderer/cache/streamBuffer.h
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

Walkthrough

BufferCache now defers selected BDA synchronization events until promotion, collects dirty ranges across mapped buffers, and uploads them through a shared staging allocation. Guest GPU processing promotes synchronization events, and RenderContext synchronizes mapped ranges. The cache also tracks unbound buffers, pins buffers found through BDA faults, and releases eligible aged buffers. Tests cover event promotion, multi-buffer uploads, and buffer release.

Suggested reviewers: nmzik, shadowbeat070

Priority: Normal

Change: Refactor

Merge Risk: Minimal · up to 80b4d

The previously identified buffer-release blockage is addressed. No remaining issue identified here prevents merging after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 32.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 9 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reducing BDA synchronization and write-tracking overhead.
Description check Passed The description directly explains the BDA synchronization, upload batching, buffer reclamation, pinning changes, performance results, and tests.
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 32.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 9 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

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-22 03:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809#issuecomment-6331612769) · edited 2026-10-25 23:37 UTC <!-- coderabbit-ai-generated:v1 --> <!-- 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/1809?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/b2c9ec76094460ed26a993ff8f483779ee4556bf/.coderabbit.yaml>) - **Commit**: [b2c9ec7](<https://github.com/KytyPS5/KytyPS5/commit/b2c9ec76094460ed26a993ff8f483779ee4556bf>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `95362f85-a7b5-4998-abed-17d8e5769efa` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 345655df9506e8239250062908d0002f14344128 and 80b4d43b39dc651af998886eee55c4cb1c51abe1. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 7</strong></summary> <dl> <dd> * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/faultManager.cpp` * `src/graphics/host_gpu/renderer/cache/streamBuffer.h` * `src/graphics/host_gpu/renderer/renderContext.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> BufferCache now defers selected BDA synchronization events until promotion, collects dirty ranges across mapped buffers, and uploads them through a shared staging allocation. Guest GPU processing promotes synchronization events, and RenderContext synchronizes mapped ranges. The cache also tracks unbound buffers, pins buffers found through BDA faults, and releases eligible aged buffers. Tests cover event promotion, multi-buffer uploads, and buffer release. **Suggested reviewers:** `nmzik`, `shadowbeat070` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <strong>Priority: <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/priority-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Normal</strong> <!-- change_assessment_commit:"80b4d43b39dc651af998886eee55c4cb1c51abe1" --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>80b4d</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `80b4d` --> <!-- final_review_risk_coverage:{"sourceCommitId":"80b4d43b39dc651af998886eee55c4cb1c51abe1","coveredCommitId":"80b4d43b39dc651af998886eee55c4cb1c51abe1","kind":"reviewed"} --> The previously identified buffer-release blockage is addressed. No remaining issue identified here prevents merging after normal checks. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 32.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 9 files. (1 skipped: … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: reducing BDA synchronization and write-tracking overhead. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the BDA synchronization, upload batching, buffer reclamation, pinning changes, performance results, and tests. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 32.35% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 9 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </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">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1809)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [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) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-22 03:00 UTC · original · edited 2026-10-25 17:19 UTC
On src/graphics/host_gpu/memoryTracker.h line 94 (outdated):

@@ -81,6 +86,18 @@ class MemoryTracker final {
 		});
 	}
 
+	// Calls func(address, size) for each CPU-modified run of pages in [vaddr, vaddr + size)
+	// without changing any state.
+	template <typename Func>
+	void ForEachCpuModifiedRange(uint64_t vaddr, uint64_t size, Func&& func) {
+		CheckNotInUploadCallback();
+		Iterate<false>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) {

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect Iterate<> semantics and how missing regions are handled.
rg -nP -C8 'Iterate\s*\(' src/graphics/host_gpu/memoryTracker.h
rg -nP -C6 'GetOrCreateRegion|create_region|bool\s+create' src/graphics/host_gpu/memoryTracker.h src/graphics/host_gpu/memoryTracker.cpp

Repository: KytyPS5/KytyPS5

Length of output: 4993


🏁 Script executed:

set -eu
printf '%s\n' '--- memoryTracker.h relevant declarations and definitions ---'
nl -ba src/graphics/host_gpu/memoryTracker.h | sed -n '1,230p'
printf '%s\n' '--- memoryTracker.cpp ---'
nl -ba src/graphics/host_gpu/memoryTracker.cpp | sed -n '1,260p'
printf '%s\n' '--- BDA synchronization and buffer cache references ---'
rg -n -F --glob '*.{h,cpp}' -e 'ForEachCpuModifiedRange' -e 'SynchronizeBda' -e 'ChangeRegister' -e 'ObtainBuffer' -e 'JoinOverlap' -e 'QueueBdaSync' -e 'Bda' src/graphics/host_gpu

Repository: KytyPS5/KytyPS5

Length of output: 22180


🏁 Script executed:

set -eu
printf '%s\n' '--- region manager ---'
nl -ba src/graphics/host_gpu/regionManager.h | sed -n '1,300p'
nl -ba src/graphics/host_gpu/regionManager.cpp | sed -n '1,280p'
printf '%s\n' '--- buffer cache lifecycle and synchronization ---'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '80,155p'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '360,550p'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '720,790p'
printf '%s\n' '--- fault path ---'
nl -ba src/graphics/host_gpu/renderer/cache/faultManager.cpp | sed -n '110,165p'

Repository: KytyPS5/KytyPS5

Length of output: 25457


🏁 Script executed:

set -eu
printf '%s\n' '--- SynchronizeBda remainder ---'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '741,875p'
printf '%s\n' '--- mapped ranges and PrepareBda ---'
nl -ba src/graphics/host_gpu/renderer/renderContext.cpp | sed -n '105,145p'
rg -n -F --glob '*.{h,cpp}' -e 'm_mapped_ranges' -e 'mapped_ranges' -e 'PrepareBda()' src/graphics/host_gpu/renderer
printf '%s\n' '--- relevant tests ---'
rg -n -F --glob '*.{h,cpp}' -e 'CheckBdaSyncBatchesBuffers' -e 'CheckBufferCacheReleasesUnboundBuffers' -e 'ForEachUploadRange' -e 'TestQueriesDoNotRequireMappedOwnership' src tests 2>/dev/null || true

Repository: KytyPS5/KytyPS5

Length of output: 12024


Create tracker regions while enumerating CPU-modified ranges.

ForEachCpuModifiedRange uses Iterate<false>, so it skips missing regions. Register queues the full buffer range, but ordinary synchronization creates tracker regions only for the requested range. An expanded buffer can therefore contain CPU-modified pages that SynchronizeBda omits. BDA then reads stale or uninitialized buffer data.

Use Iterate<true> for this query.

🐛 Suggested fix
-		Iterate<false>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) {
+		Iterate<true>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

		Iterate<true>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) {

✅ Addressed in commits e6839a5 to 02dfbac

**@⁠coderabbitai[bot]** on GitHub · 2026-10-22 03:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809#discussion_r4344131962) · edited 2026-10-25 17:19 UTC On `src/graphics/host_gpu/memoryTracker.h` line 94 (outdated): ```diff @@ -81,6 +86,18 @@ class MemoryTracker final { }); } + // Calls func(address, size) for each CPU-modified run of pages in [vaddr, vaddr + size) + // without changing any state. + template <typename Func> + void ForEachCpuModifiedRange(uint64_t vaddr, uint64_t size, Func&& func) { + CheckNotInUploadCallback(); + Iterate<false>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) { ``` <!-- coderabbit-ai-generated:v1 --> **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Inspect Iterate<> semantics and how missing regions are handled. rg -nP -C8 'Iterate\s*\(' src/graphics/host_gpu/memoryTracker.h rg -nP -C6 'GetOrCreateRegion|create_region|bool\s+create' src/graphics/host_gpu/memoryTracker.h src/graphics/host_gpu/memoryTracker.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 4993 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- memoryTracker.h relevant declarations and definitions ---' nl -ba src/graphics/host_gpu/memoryTracker.h | sed -n '1,230p' printf '%s\n' '--- memoryTracker.cpp ---' nl -ba src/graphics/host_gpu/memoryTracker.cpp | sed -n '1,260p' printf '%s\n' '--- BDA synchronization and buffer cache references ---' rg -n -F --glob '*.{h,cpp}' -e 'ForEachCpuModifiedRange' -e 'SynchronizeBda' -e 'ChangeRegister' -e 'ObtainBuffer' -e 'JoinOverlap' -e 'QueueBdaSync' -e 'Bda' src/graphics/host_gpu ``` Repository: KytyPS5/KytyPS5 Length of output: 22180 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- region manager ---' nl -ba src/graphics/host_gpu/regionManager.h | sed -n '1,300p' nl -ba src/graphics/host_gpu/regionManager.cpp | sed -n '1,280p' printf '%s\n' '--- buffer cache lifecycle and synchronization ---' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '80,155p' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '360,550p' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '720,790p' printf '%s\n' '--- fault path ---' nl -ba src/graphics/host_gpu/renderer/cache/faultManager.cpp | sed -n '110,165p' ``` Repository: KytyPS5/KytyPS5 Length of output: 25457 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- SynchronizeBda remainder ---' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '741,875p' printf '%s\n' '--- mapped ranges and PrepareBda ---' nl -ba src/graphics/host_gpu/renderer/renderContext.cpp | sed -n '105,145p' rg -n -F --glob '*.{h,cpp}' -e 'm_mapped_ranges' -e 'mapped_ranges' -e 'PrepareBda()' src/graphics/host_gpu/renderer printf '%s\n' '--- relevant tests ---' rg -n -F --glob '*.{h,cpp}' -e 'CheckBdaSyncBatchesBuffers' -e 'CheckBufferCacheReleasesUnboundBuffers' -e 'ForEachUploadRange' -e 'TestQueriesDoNotRequireMappedOwnership' src tests 2>/dev/null || true ``` Repository: KytyPS5/KytyPS5 Length of output: 12024 --- </details> **Create tracker regions while enumerating CPU-modified ranges.** `ForEachCpuModifiedRange` uses `Iterate<false>`, so it skips missing regions. `Register` queues the full buffer range, but ordinary synchronization creates tracker regions only for the requested range. An expanded buffer can therefore contain CPU-modified pages that `SynchronizeBda` omits. BDA then reads stale or uninitialized buffer data. Use `Iterate<true>` for this query. <details> <summary>🐛 Suggested fix</summary> ```diff - Iterate<false>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) { + Iterate<true>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) { ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion Iterate<true>(vaddr, size, [&](RegionManager* manager, uint64_t offset, uint64_t bytes) { ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:b2cdf2bc4a76ddeb04cb7bcf --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits e6839a5 to 02dfbac
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-22 03:00 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 87ab23bc-0e56-46ff-a011-42ff62dbd9c8
📥 Commits

Reviewing files that changed from the base of the PR and between d7c1896647 and df610e4e52d2781268852b904795955f18135aaf.

📒 Files selected for processing: 9
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/host_gpu/memoryTracker.cpp
  • src/graphics/host_gpu/memoryTracker.h
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/faultManager.cpp
  • src/graphics/host_gpu/renderer/cache/streamBuffer.h
  • tests/MemoryTrackerTests.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-22 03:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809#pullrequestreview-5608766020) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `87ab23bc-0e56-46ff-a011-42ff62dbd9c8` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between d7c1896647248b294bc56050c0006cdbb43a87d2 and df610e4e52d2781268852b904795955f18135aaf. </details> <details> <summary>📒 Files selected for processing: 9</summary> * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/host_gpu/memoryTracker.cpp` * `src/graphics/host_gpu/memoryTracker.h` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/faultManager.cpp` * `src/graphics/host_gpu/renderer/cache/streamBuffer.h` * `tests/MemoryTrackerTests.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=89a5b6a0-4d48-49a1-a8a1-350c16cafc3c attempt=0de782cf-1f07-4cef-8f75-0b4f5dba4442 batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-25 17:23 UTC · original · edited 2026-10-25 21:51 UTC
On src/graphics/host_gpu/renderer/cache/bufferCache.cpp line 687 (outdated):

@@ -635,8 +643,62 @@ bool BufferCache::IsRegionCpuModified(uint64_t vaddr, uint64_t size) {
 	return m_memory_tracker.IsRegionCpuModified(vaddr, size);
 }
 
+// Marks the buffer as read through the BDA page table, which keeps ReleaseUnboundBuffers from
+// releasing it.
+void BufferCache::PinBda(BufferId id) {
+	// FindBuffer returns no buffer for a null address.
+	if (!IsBufferInvalid(id)) {
+		m_slot_buffers[id].bda_pinned = true;
+	}
+}
+
+// Releases up to 16 buffers that no draw or dispatch has bound for 300 garbage-collector ticks.
+void BufferCache::ReleaseUnboundBuffers(uint64_t tick) {
+	// A buffer otherwise stays registered until memory pressure retires it, so its pages stay
+	// write-protected after the game reuses the memory for CPU data: every write then faults,
+	// and BDA synchronization uploads the page again. Release buffers that no draw or dispatch
+	// has bound for a while and that hold no GPU-written data. A BDA read of a released page
+	// reaches the fault buffer, which recreates the buffer and pins it.
+	constexpr uint64_t UnboundTicks = 300;
+	constexpr size_t   MaxReleased  = 16;
+	constexpr size_t   MaxVisited   = 256;
+	// No buffer can have gone unbound for long enough yet; this also keeps the subtraction below
+	// from wrapping.
+	if (tick <= UnboundTicks) {
+		return;
+	}
+	// Fixed storage: this runs on every garbage-collector tick.
+	std::array<BufferId, MaxReleased> released;
+	size_t                            released_count = 0;
+	size_t                            visited        = 0;
+	m_lru_cache.ForEachItemBelow(tick - UnboundTicks, [&](BufferId id) {
+		const auto& buffer = m_slot_buffers[id];
+		// Keep a buffer that:
+		// - is pinned: shaders read it through the BDA page table, which does not refresh its
+		//   LRU tick, so it looks unbound however often it is used;
+		// - holds GPU-written data not yet read back to guest memory: that data exists only in
+		//   this buffer. The buffer cache and the memory tracker each record such writes.
+		if (!buffer.bda_pinned &&
+		    !m_gpu_modified_ranges.Intersects(buffer.CpuAddress(), buffer.Size()) &&
+		    !m_memory_tracker.IsRegionGpuModified(buffer.CpuAddress(), buffer.Size())) {
+			released[released_count++] = id;
+		}
+		// Bound the work per tick: the LRU list can hold thousands of old buffers.
+		return ++visited == MaxVisited || released_count == MaxReleased;

Minor · Performance & Scalability · Quick win

🔎 Supported by static analysis

Script executed:

rg -n 'class LeastRecentlyUsedCache|struct LeastRecentlyUsedCache|ForEachItemBelow|TouchBuffer\(' src tests | head -100

Repository: KytyPS5/KytyPS5

Length of output: 1728


Script executed:

set -eu
printf '%s\n' '--- src/common/lruCache.h ---'
nl -ba src/common/lruCache.h
printf '%s\n' '--- bufferCache methods and release/pressure blocks ---'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '120,165p;500,555p;640,750p'
printf '%s\n' '--- bufferCache declarations and relevant tests ---'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.h | sed -n '1,145p'
rg -n -F --glob '*.{cpp,h}' -e 'CheckBufferCacheReleasesUnboundBuffers' -e 'ReleaseUnboundBuffers' -e 'PinBda' -e 'JoinOverlap' -e 'Touch(' tests src/graphics/host_gpu/renderer/cache src/common || test "$?" -eq 1
printf '%s\n' '--- LRU tests ---'
nl -ba tests/LruCacheTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 30537


Script executed:

set -eu
printf '%s\n' '--- JoinOverlap ---'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '380,445p'
printf '%s\n' '--- remaining pressure cleanup ---'
nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '738,785p'
printf '%s\n' '--- focused release test ---'
nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '5390,5495p'

Repository: KytyPS5/KytyPS5

Length of output: 12340


Do not let retained entries consume all 256 visits.

ForEachItemBelow visits the oldest entries first. Since retained entries are not touched, 256 old pinned or GPU-modified buffers can prevent later clean buffers from reaching the release check.

Collect retained IDs during the walk and touch them after the walk. Touch moves them to the newest end without clearing their pin or GPU-modified state.

Suggested fix
 		std::array<BufferId, MaxReleased> released;
+		std::array<BufferId, MaxVisited>  retained;
 		size_t                            released_count = 0;
+		size_t                            retained_count = 0;
 		size_t                            visited        = 0;
 		m_lru_cache.ForEachItemBelow(tick - UnboundTicks, [&](BufferId id) {
 			const auto& buffer = m_slot_buffers[id];
@@
 			if (!buffer.bda_pinned &&
 			    !m_gpu_modified_ranges.Intersects(buffer.CpuAddress(), buffer.Size()) &&
 			    !m_memory_tracker.IsRegionGpuModified(buffer.CpuAddress(), buffer.Size())) {
 				released[released_count++] = id;
+			} else {
+				retained[retained_count++] = id;
 			}
 			// Bound the work per tick: the LRU list can hold thousands of old buffers.
 			return ++visited == MaxVisited || released_count == MaxReleased;
 		});
+		for (const auto id: std::span(retained.data(), retained_count)) {
+			m_lru_cache.Touch(m_slot_buffers[id].lru_id, tick);
+		}
 		// Delete after the walk: deleting a buffer removes it from the LRU list being walked.

This also delays the separate pressure pass for touched entries. That delay is bounded by their refreshed LRU age and does not violate the inspected pinned or GPU-written retention checks.

✅ Addressed in commits 09cee75 to 477b803

**@⁠coderabbitai[bot]** on GitHub · 2026-10-25 17:23 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809#discussion_r4371697581) · edited 2026-10-25 21:51 UTC On `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` line 687 (outdated): ```diff @@ -635,8 +643,62 @@ bool BufferCache::IsRegionCpuModified(uint64_t vaddr, uint64_t size) { return m_memory_tracker.IsRegionCpuModified(vaddr, size); } +// Marks the buffer as read through the BDA page table, which keeps ReleaseUnboundBuffers from +// releasing it. +void BufferCache::PinBda(BufferId id) { + // FindBuffer returns no buffer for a null address. + if (!IsBufferInvalid(id)) { + m_slot_buffers[id].bda_pinned = true; + } +} + +// Releases up to 16 buffers that no draw or dispatch has bound for 300 garbage-collector ticks. +void BufferCache::ReleaseUnboundBuffers(uint64_t tick) { + // A buffer otherwise stays registered until memory pressure retires it, so its pages stay + // write-protected after the game reuses the memory for CPU data: every write then faults, + // and BDA synchronization uploads the page again. Release buffers that no draw or dispatch + // has bound for a while and that hold no GPU-written data. A BDA read of a released page + // reaches the fault buffer, which recreates the buffer and pins it. + constexpr uint64_t UnboundTicks = 300; + constexpr size_t MaxReleased = 16; + constexpr size_t MaxVisited = 256; + // No buffer can have gone unbound for long enough yet; this also keeps the subtraction below + // from wrapping. + if (tick <= UnboundTicks) { + return; + } + // Fixed storage: this runs on every garbage-collector tick. + std::array<BufferId, MaxReleased> released; + size_t released_count = 0; + size_t visited = 0; + m_lru_cache.ForEachItemBelow(tick - UnboundTicks, [&](BufferId id) { + const auto& buffer = m_slot_buffers[id]; + // Keep a buffer that: + // - is pinned: shaders read it through the BDA page table, which does not refresh its + // LRU tick, so it looks unbound however often it is used; + // - holds GPU-written data not yet read back to guest memory: that data exists only in + // this buffer. The buffer cache and the memory tracker each record such writes. + if (!buffer.bda_pinned && + !m_gpu_modified_ranges.Intersects(buffer.CpuAddress(), buffer.Size()) && + !m_memory_tracker.IsRegionGpuModified(buffer.CpuAddress(), buffer.Size())) { + released[released_count++] = id; + } + // Bound the work per tick: the LRU list can hold thousands of old buffers. + return ++visited == MaxVisited || released_count == MaxReleased; ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Performance & Scalability** · **Quick win** <details> <summary>🔎 Supported by static analysis</summary> <dl> <dd> Script executed: ```bash rg -n 'class LeastRecentlyUsedCache|struct LeastRecentlyUsedCache|ForEachItemBelow|TouchBuffer\(' src tests | head -100 ``` Repository: KytyPS5/KytyPS5 Length of output: 1728 --- Script executed: ```bash set -eu printf '%s\n' '--- src/common/lruCache.h ---' nl -ba src/common/lruCache.h printf '%s\n' '--- bufferCache methods and release/pressure blocks ---' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '120,165p;500,555p;640,750p' printf '%s\n' '--- bufferCache declarations and relevant tests ---' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.h | sed -n '1,145p' rg -n -F --glob '*.{cpp,h}' -e 'CheckBufferCacheReleasesUnboundBuffers' -e 'ReleaseUnboundBuffers' -e 'PinBda' -e 'JoinOverlap' -e 'Touch(' tests src/graphics/host_gpu/renderer/cache src/common || test "$?" -eq 1 printf '%s\n' '--- LRU tests ---' nl -ba tests/LruCacheTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 30537 --- Script executed: ```bash set -eu printf '%s\n' '--- JoinOverlap ---' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '380,445p' printf '%s\n' '--- remaining pressure cleanup ---' nl -ba src/graphics/host_gpu/renderer/cache/bufferCache.cpp | sed -n '738,785p' printf '%s\n' '--- focused release test ---' nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '5390,5495p' ``` Repository: KytyPS5/KytyPS5 Length of output: 12340 --- </dd> </dl> </details> **Do not let retained entries consume all 256 visits.** `ForEachItemBelow` visits the oldest entries first. Since retained entries are not touched, 256 old pinned or GPU-modified buffers can prevent later clean buffers from reaching the release check. Collect retained IDs during the walk and touch them after the walk. `Touch` moves them to the newest end without clearing their pin or GPU-modified state. <details> <summary>Suggested fix</summary> <dl> <dd> ```diff std::array<BufferId, MaxReleased> released; + std::array<BufferId, MaxVisited> retained; size_t released_count = 0; + size_t retained_count = 0; size_t visited = 0; m_lru_cache.ForEachItemBelow(tick - UnboundTicks, [&](BufferId id) { const auto& buffer = m_slot_buffers[id]; @@ if (!buffer.bda_pinned && !m_gpu_modified_ranges.Intersects(buffer.CpuAddress(), buffer.Size()) && !m_memory_tracker.IsRegionGpuModified(buffer.CpuAddress(), buffer.Size())) { released[released_count++] = id; + } else { + retained[retained_count++] = id; } // Bound the work per tick: the LRU list can hold thousands of old buffers. return ++visited == MaxVisited || released_count == MaxReleased; }); + for (const auto id: std::span(retained.data(), retained_count)) { + m_lru_cache.Touch(m_slot_buffers[id].lru_id, tick); + } // Delete after the walk: deleting a buffer removes it from the LRU list being walked. ``` This also delays the separate pressure pass for touched entries. That delay is bounded by their refreshed LRU age and does not violate the inspected pinned or GPU-written retention checks. </dd> </dl> </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:9409bfa546b94b6fd5b6c6e2 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits 09cee75 to 477b803
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-25 17:23 UTC · original · reviewed

Actionable comments posted: 1


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f27160c843a448b2ae0c8c04abff386962c2a1ed and 02dfbac82374cf73f29817ad30e8963ef3166cf6.

Files selected for processing: 7
  • src/graphics/host_gpu/memoryTracker.cpp
  • src/graphics/host_gpu/memoryTracker.h
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/faultManager.cpp
  • tests/MemoryTrackerTests.cpp
  • tests/ShaderRecompilerComputeTests.cpp
Files skipped from review as they are similar to previous changes: 1
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-25 17:23 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809#pullrequestreview-5644334480) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/c5016d9455fe52bdd090cef7d80beb15fad6a3a5/.coderabbit.yaml>) - **Commit**: [c5016d9](<https://github.com/KytyPS5/KytyPS5/commit/c5016d9455fe52bdd090cef7d80beb15fad6a3a5>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `ea5af81a-086d-437e-a709-91108b13a32f` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between f27160c843a448b2ae0c8c04abff386962c2a1ed and 02dfbac82374cf73f29817ad30e8963ef3166cf6. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 7</summary> <dl> <dd> * `src/graphics/host_gpu/memoryTracker.cpp` * `src/graphics/host_gpu/memoryTracker.h` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/faultManager.cpp` * `tests/MemoryTrackerTests.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-similar-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-similar.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files skipped from review as they are similar to previous changes: 1</summary> <dl> <dd> * tests/ShaderRecompilerComputeTests.cpp </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </dd> </dl> </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=8b9697c3-4c89-471c-afdd-e8586fb87803 attempt=98c3f730-aae1-40f4-afc4-e24d0a45a640 batch=1/1 -->
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-25 23:31 UTC · original

@⁠coderabbitai resume

**@⁠MrBigBritches** on GitHub · 2026-10-25 23:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809#issuecomment-6404913460) @⁠coderabbitai resume
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-25 23:31 UTC · original · edited 2026-10-25 23:37 UTC

✅ Action performed

Reviews resumed and review finished.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-25 23:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809#issuecomment-6404914624) · edited 2026-10-25 23:37 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated reply by CodeRabbit --> <!-- CodeRabbit review command invocation: 2c203d82-f32c-46f2-b166-0c8722032f70 --> <details> <summary>✅ Action performed</summary> <dl> <dd> Reviews resumed and review finished. </dd> </dl> </details>
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-27 01:55 UTC · original

Updating and splitting this into 2 PRs

**@⁠MrBigBritches** on GitHub · 2026-10-27 01:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1809#issuecomment-6431803980) Updating and splitting this into 2 PRs

Pull request closed

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