gpu: cut BDA synchronization and write-tracking overhead (PPSA09809) #1809
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1809
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1809/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@MrBigBritches on GitHub · 2026-10-22 02:54 UTC · original
MrBigBritches:bda-sync-perf→main· +602 −25 · 7 files · 3 commits · closed without mergingEvery shader that reads memory through BDA synchronizes the pages queued since the previous one. In Octopath Traveler II this cost a lot:
Changes
WAIT_REG_MEMpasses (its value may guard data a game thread wrote). GPU-thread writes still queue immediately. Promotion skips the lock when nothing is deferred.SynchronizeBdacollects 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.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_trackerandshader_recompiler_computepass.Notes
Rebased onto main after the BDA queue moved into
BufferCache(f356fa3).PrepareBdacallsBufferCache::SynchronizeBdaagain.@coderabbitai[bot] on GitHub · 2026-10-22 03:00 UTC · original · edited 2026-10-25 23:37 UTC
No actionable comments were generated in the recent review.
95362f85-a7b5-4998-abed-17d8e5769efaReviewing files that changed from the base of the PR and between 345655df9506e8239250062908d0002f14344128 and
80b4d43b39.src/graphics/guest_gpu/graphicsRun.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/faultManager.cppsrc/graphics/host_gpu/renderer/cache/streamBuffer.hsrc/graphics/host_gpu/renderer/renderContext.cpptests/ShaderRecompilerComputeTests.cppIncluded 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,shadowbeat070Priority:
Normal
Change: Refactor
Merge Risk:
Minimal · up to
80b4dThe previously identified buffer-release blockage is addressed. No remaining issue identified here prevents merging after normal checks.
Pre-merge checks:
4 ·
1
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.
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 helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-22 03:00 UTC · original · edited 2026-10-25 17:19 UTC
On
src/graphics/host_gpu/memoryTracker.hline 94 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4993
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 22180
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 25457
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12024
Create tracker regions while enumerating CPU-modified ranges.
ForEachCpuModifiedRangeusesIterate<false>, so it skips missing regions.Registerqueues the full buffer range, but ordinary synchronization creates tracker regions only for the requested range. An expanded buffer can therefore contain CPU-modified pages thatSynchronizeBdaomits. BDA then reads stale or uninitialized buffer data.Use
Iterate<true>for this query.🐛 Suggested fix
📝 Committable suggestion
✅ Addressed in commits e6839a5 to 02dfbac
@coderabbitai[bot] on GitHub · 2026-10-22 03:00 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
87ab23bc-0e56-46ff-a011-42ff62dbd9c8📥 Commits
Reviewing files that changed from the base of the PR and between
d7c1896647and df610e4e52d2781268852b904795955f18135aaf.📒 Files selected for processing: 9
src/graphics/guest_gpu/graphicsRun.cppsrc/graphics/host_gpu/memoryTracker.cppsrc/graphics/host_gpu/memoryTracker.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/faultManager.cppsrc/graphics/host_gpu/renderer/cache/streamBuffer.htests/MemoryTrackerTests.cpptests/ShaderRecompilerComputeTests.cppIncluded 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-25 17:23 UTC · original · edited 2026-10-25 21:51 UTC
On
src/graphics/host_gpu/renderer/cache/bufferCache.cppline 687 (outdated):🔎 Supported by static analysis
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1728
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 30537
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12340
Do not let retained entries consume all 256 visits.
ForEachItemBelowvisits 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.
Touchmoves them to the newest end without clearing their pin or GPU-modified state.Suggested fix
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 · reviewed
Actionable comments posted: 1
ea5af81a-086d-437e-a709-91108b13a32fReviewing files that changed from the base of the PR and between f27160c843a448b2ae0c8c04abff386962c2a1ed and 02dfbac82374cf73f29817ad30e8963ef3166cf6.
src/graphics/host_gpu/memoryTracker.cppsrc/graphics/host_gpu/memoryTracker.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/cache/faultManager.cpptests/MemoryTrackerTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@MrBigBritches on GitHub · 2026-10-25 23:31 UTC · original
@coderabbitai resume
@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.
@MrBigBritches on GitHub · 2026-10-27 01:55 UTC · original
Updating and splitting this into 2 PRs
Pull request closed