graphics: skip memory tracker upload passes that cannot change anything #1886
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!1886
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1886"
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?
@ArsenyYankovsky on GitHub · 2026-10-24 22:09 UTC · original
ArsenyYankovsky:perf/upload-memo→main· +142 −1 · 3 files · 1 commits · openDraws bind the same ranges again and again, unchanged. This skips
ForEachUploadRangecalls that repeat an identical call with no change in the range's regions since: each region counts changes of its dirty bits (a generation), and a repeat whose generation sum is unchanged only runs the upload callback.Benchmark
Offline replay of a 60-frame capture of the memory tracker calls in Demon's Souls' heaviest outdoor area (~33,000 upload calls a frame), against the tracker with real page protection and upload copies.
Tool:
tests/MemoryTraceReplay.cpp(on a separate branch, not part of this PR; before / after).
The trace (86 MB) is available on request. Three runs of each build, i7-14700KF:
Both builds upload the same 22.8 MiB/frame and make the same 2,769 protection calls/frame, with equal checksums over every upload range and protection change.
Tests
TestRepeatedUploadSkipcovers CPU writes, GPU unmarks, downloads and a new tracker over the same range; removing the generation bump inChangeStatefails it.Draws bind the same ranges again and again, unchanged. In a 60-frame capture of the memory tracker calls in Demon's Souls' heaviest outdoor area, the GPU thread made about 33,000 ForEachUploadRange calls a frame. Most of them repeated an identical call with no state change in the range's 4 MiB regions in between. One 112 MiB buffer that dispatches bind as writable was marked GPU-dirty again about 1,700 times a frame, each time walking 28 regions under their locks. Each tracker region now counts the changes of its dirty bits (a generation, bumped under its lock). ForEachUploadRange remembers per thread the sum of its range's region generations as it leaves them. An identical later call with the same sum would find nothing to upload and change nothing, so it only runs the upload callback. Generations only grow, so an equal sum means no region changed. Replaying the capture against the tracker with real page protection and upload copies (a replay tool kept out of this change), three runs of each build on an i7-14700KF: before after GPU thread's tracker calls 2.83-2.87 ms 1.53-1.56 ms a frame whole replay 4.32-4.38 ms 2.97-3.05 ms a frame Both builds upload the same 22.8 MiB a frame and make the same 2,769 protection calls a frame, with equal checksums over every upload range and protection change. TestRepeatedUploadSkip covers CPU writes, GPU unmarks, downloads and a new tracker over the same range; removing the bump in ChangeState fails it.@coderabbitai[bot] on GitHub · 2026-10-24 22:15 UTC · original · edited 2026-10-26 17:39 UTC
No actionable comments were generated in the recent review.
7c5641c6-603a-4882-8733-cf5ca8f4fee5Reviewing files that changed from the base of the PR and between
906d25568fand14380ddc4b.src/graphics/host_gpu/memoryTracker.hsrc/graphics/host_gpu/regionManager.htests/MemoryTrackerTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Walkthrough
RegionManagernow tracks generations for state changes and clearing nonempty modified ranges.MemoryTracker::ForEachUploadRangeuses those generations and a thread-local memo to skip repeated range processing when the tracker, range, write status, and generation sum match. Tests cover repeated calls, state changes, and new trackers.Suggested reviewers:
nmzikPriority:
Normal
Change: Refactor
Merge Risk:
Minimal · up to
14380The change skips repeated upload-range work when nothing relevant has changed. No concrete correctness risk was found, and the tests cover repeated calls, state changes, and new trackers.
Pre-merge checks:
4 ·
1
Full details: Title check
Explanation
The title names the main change: the memory tracker skips upload passes that cannot change anything. The changeset adds a memo in MemoryTracker::ForEachUploadRange, a Generation() counter in RegionManager, and a test. The title states the goal and the mechanism at a high level, which matches the objectives.
Full details: Description check
Explanation
The pull request description directly matches the changes. It describes skipping repeated ForEachUploadRange processing through region generations, reports benchmark results, and identifies the related regression test.
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.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.