gpu: upload BDA synchronization through one staging copy #1932
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!1932
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1932/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-27 03:24 UTC · original
MrBigBritches:bda-sync-batch→main· +276 −14 · 4 files · 1 commits · closed without mergingBefore every BDA draw, BDA synchronization uploads the CPU-written pages that shaders may read through buffer device addresses. It handled one buffer at a time. Each buffer that still had dirty pages took its own staging allocation and two whole-buffer barriers. A busy draw in Octopath Traveler II found a few hundred such buffers.
Now all of a synchronization's copies go through one staging allocation, recorded between a single pair of global barriers.
This is the first part of #1809, split out on its own. The other two parts of #1809, holding game-thread BDA events until promotion and releasing unbound buffers, will follow as separate PRs after rework.
Changes
BufferCache::SynchronizeBdareplacesSynchronizeBuffersInRange. It takes the queued ranges inside mapped memory and collects the runs that are still CPU-modified, with one tracker walk per buffer range.Correctness
Testing
BdaSyncBatchesBuffersinshader_recompiler_compute_tests: dirties pages in two separate buffers, including two separate runs in one buffer. It checks that one synchronization uploads each page into the right buffer at the right offset. It checks the data, not the number of staging allocations.BdaSyncUploadsandBdaPageTableUploadstests pass unchanged.main:vdecswdoesn't build, becausestd::aligned_allocisn't available in MSVC's C runtime.kernel_file_systemcrashes with0xc0000028.main, and #1922 fixes them.@coderabbitai[bot] on GitHub · 2026-10-27 03:31 UTC · original
Walkthrough
BufferCachenow synchronizes CPU-modified BDA pages across mapped ranges and batches their uploads through staging memory.RenderContext::PrepareBdapasses the mapped-range set to the cache. A Vulkan test checks synchronization and copied values across two cached buffers.Suggested reviewers:
nmzikPriority:
Low
Change: Refactor
Merge Risk:
Moderate · up to
9eb20Large BDA uploads can still require the one-off host allocation this change is meant to avoid. Enforce the staging limit during collection before merging.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 3 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.@ -752,0 +823,4 @@}}upload.batches.push_back({&buffer, first, added});}@coderabbitai[bot] on GitHub · 2026-10-27 03:31 UTC · original · edited 2026-10-27 03:45 UTC
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7452
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32168
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42013
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 40301
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 23212
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10666
Flush the staging batch while collecting a large buffer.
CollectBdaBufferCopieschecks the full overlap only beforeForEachUploadRange. A mapped and invalidated BDA buffer can exceed 512 MiB. The tracker reports that buffer in multiple runs, so the callback can append more than 512 MiB after the pre-append flush.UploadMemorythen falls back to a temporary host allocation for the full upload.Suggested fix
Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-27 03:31 UTC · original · reviewed
Actionable comments posted: 1
c18334cb-5cf3-431a-b174-379889697e21Reviewing files that changed from the base of the PR and between
db12f0c5fband9eb20be515.src/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.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; 7 remain after this review.
@ -752,0 +823,4 @@}}upload.batches.push_back({&buffer, first, added});}@MrBigBritches on GitHub · 2026-10-27 03:45 UTC · original
A single buffer with more than 512 MiB of dirty pages still takes the one-off host allocation, the same as main, where SynchronizeBuffer uploads a buffer's dirty runs in one UploadMemory call. The pre-walk flush only keeps earlier buffers' copies out of that upload. Flushing inside the ForEachUploadRange callback isn't safe: it runs with the region's tracking spin lock held, and the flush can wait on the GPU and copy up to 512 MiB while guest write faults on those pages spin. If a cap is needed later, walking the range in ring-sized chunks keeps the flush outside the tracker walk.
@ -752,0 +823,4 @@}}upload.batches.push_back({&buffer, first, added});}@coderabbitai[bot] on GitHub · 2026-10-27 03:46 UTC · original
@MrBigBritches You're right.
SynchronizeBufferalready sends a buffer's collected dirty runs through oneUploadMemorycall. The pre-walk flush prevents earlier buffers' copies from enlarging that upload. It does not impose a strict per-buffer cap.I withdraw this finding and the callback-flush suggestion. I overlooked the tracking spin lock held during the callback. GPU waits and large memory copies should not run under that lock.
If a strict cap becomes necessary, ring-sized range walks can keep each flush outside the tracker walk. No change is needed for this finding.
✅ Review thread resolved.
You are interacting with an AI system.
@MrBigBritches on GitHub · 2026-10-27 04:49 UTC · original
Measurements from Octopath Traveler II, taken with a temporary per-second log of the emulator's debug counters. The logging isn't part of either PR.
I ran the same route on three builds, all based on
main986721f5:main.I didn't run this PR on its own, so its effect is the difference between the last two rows of each stretch.
mainmainEach build ran once, so run-to-run variance isn't measured.
Pull request closed