graphics: find BDA upload work from CPU-dirty hints #562
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!562
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/562/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?
@MehmetCambaz on GitHub · 2026-09-11 10:37 UTC · original
MehmetCambaz:perf/bda-selective-dirty→main· +1786 −8 · 15 files · 1 commits · closed without mergingUpdate: refreshed onto current main
The branch was 473 commits behind and no longer applied. I re-ported it onto current main instead of rebasing through the conflicts. The base is
fb7ff7ec; the three commits merged since then don't touch the BDA or tracker code and merge cleanly.The design is unchanged:
SynchronizeBuffer;What changed in the port:
GpuResourceManageris nowRenderContext, so the mapping hint and the--bda-syncmodes live there.PrepareBdachecks only the hint words that overlap mapped memory instead of all of them. Hints outside mapped memory stay pending. A mapped range the tracker cannot index also fails closed to the legacy walk.RenderContextdirectly. A new test,buffer_cache_bda_structural, checks that the selective path does less work.Current validation (this refreshed branch)
The structural test runs 64
PrepareBdacalls over 256 cached buffers in 32 tracker regions. The workload is mostly clean: 16 small guest writes and 8 hints that find nothing. It counts with test-only hooks, not timing:SynchronizeBuffercallsEvery call uploads the same bytes in both modes, and the BDA-visible contents of every buffer match guest memory.
SelectiveChecked;cdb64bfd. Onfb7ff7ec, every BDA, buffer-cache and tracker test passes.shader_recompiler_computeandcompute_meta_clear_classificationfail atResourceMaterialization.cpp:1398, but they fail the same way on unmodifiedfb7ff7ec, so that failure is unrelated to this change.Historical performance (original branch, September base, not re-measured on current main)
In a fixed Kena: Bridge of Spirits scene, using alternating legacy/selective 30-second blocks in the same process:
PrepareBdaAll four selective blocks were faster than all four legacy blocks. Kena also completed a gameplay smoke test in
SelectiveCheckedmode at the time. These numbers come from the original branch and have not been reproduced on current main.Teardown motivation (profiling evidence and estimates only)
A recent Teardown profile (main from 2026-10-05 plus #978 and #1066, which Teardown needs to run; legacy path) shows:
PrepareBdaruns 450–680 times per frame;That is the kind of workload this change targets. I have not A/B tested the refreshed code in Teardown, so no Teardown improvement is claimed.
--bda-sync Legacy/Selectiveallows a same-build comparison.Note for review: the selective path uploads per buffer and 4 MiB region. A buffer with dirty pages in several hinted regions is uploaded in several smaller batches. The bytes are the same; there are more barrier pairs.
Overlap with #937
#937 contains overlapping
PrepareBdadirty-region/epoch work. This PR stays focused on the conservative dirty-hint approach:#937 is part of a broader stack with different synchronization and epoch choices. I'm calling out the overlap so maintainers can choose the preferred direction, and I'm happy to adapt this PR either way.
Other open PRs:
Problem
PrepareBdaruns before draws and dispatches that use buffer device addresses. To find CPU-written data it currently walks every mapped cached buffer and queries its tracked state, even though most buffers have nothing to upload.Change
Track a hint bit for each 4 MiB memory-tracker region that may contain CPU-dirty pages. The hint is published when:
PrepareBdaconsumes the hints for mapped memory, reads the existing dirty bitmap and synchronizes only registered buffers that can contain dirty pages. The existing per-page dirty state remains authoritative.SynchronizeBuffer, page protection, uploads and Vulkan synchronization are unchanged.The old walk remains available as the legacy/fallback path (
--bda-sync Legacy).--bda-sync SelectiveCheckedadds an invariant check for debugging and validation.AI assistance was used during investigation, porting, review and testing. I reviewed the final code, diff and validation results before submission.
@MehmetCambaz on GitHub · 2026-10-06 18:15 UTC · original
@Nmzik I’ve refreshed this PR onto current main and substantially strengthened the validation.
The selective path now reduces the structural test from 16,384 region scans / sync attempts to 71 region scans and 16 sync attempts, while producing exactly the same 16 uploads and 65,536 uploaded bytes as the legacy path.
I also added mutation tests for every hint-publication path and the concurrency/fallback cases. BDA/buffer tests report no new Vulkan validation messages.
The original Kena result was +19.4% FPS and -46.1% PrepareBda time; those numbers are historical and aren’t being claimed for current main. Recent Teardown profiling independently shows PrepareBda is still a significant steady-state cost.
I’ve also called out the overlap with #937 in the description so the preferred direction can be decided during review.
@coderabbitai[bot] on GitHub · 2026-10-06 18:18 UTC · original · edited 2026-10-06 18:20 UTC
📝 Walkthrough
Walkthrough
The change adds three BDA synchronization modes, with Selective as the default, and exposes mode selection through
--bda-sync. MemoryTracker tracks atomic hints for dirty regions. BufferCache uses those hints to synchronize mapped dirty owners, while retaining a legacy path and fallback. RenderContext selects the path and can check hint coverage. New tests cover hint publication, synchronization results, fallback, concurrency, and scan counts.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Refactor
Merge Risk: 🔵 Low · up to
7fd37The selective BDA synchronization change is mergeable with a small test fix. A filtered BDA test run that matches no cases still reports success, which can hide a mistyped or skipped targeted test. No runtime defect in synchronization was established.
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 14.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 13 files. (2 skipped: 1 unsupported, 1 too large.)
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.@ -3949,0 +4228,4 @@const auto run_case = [&](const char *test, bool compare_modes,auto &&body) {if (only != nullptr && std::strstr(test, only) == nullptr) {return;@coderabbitai[bot] on GitHub · 2026-10-06 18:18 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reject filters that execute no cases.
With
--bda-selective-only T99, every case returns here. The function still prints success, andmain()returns zero. SelectingT27in a debug build also reports success without executing that case.Count executed cases and fail when the count is zero. This prevents filtered test runs from reporting false success.
@coderabbitai[bot] on GitHub · 2026-10-06 18:18 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
b68e6384-4fd9-427d-a381-aa5a8272d73f📥 Commits
Reviewing files that changed from the base of the PR and between
6ef406542cand7fd373df65.📒 Files selected for processing (15)
CMakeLists.txtsrc/common/emulatorConfig.cppsrc/common/emulatorConfig.hsrc/graphics/host_gpu/bdaTestHooks.hsrc/graphics/host_gpu/memoryTracker.cppsrc/graphics/host_gpu/memoryTracker.hsrc/graphics/host_gpu/regionManager.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/presentation/window/vulkanWindow.cppsrc/main.cpptests/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.
@Nmzik on GitHub · 2026-10-21 19:41 UTC · original
Superseded by
d58aefde4.Pull request closed