GPU: batch dirty heap page ranges under one diff pass in sync_heaps #3139
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3139
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3139"
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?
@MeMako on GitHub · 2026-11-26 09:55 UTC · original
MeMako:pr/sync-heaps-1-batched-diff→main· +155 −36 · 2 files · 1 commits · openPart 1 of the triage-requested 3-part split of #3055: batches dirty 64 KiB heap page probing and diffs all dirty slot ranges under one
self.made->VIEWSlock with zero per-page allocations, zero thread changes, and zero lock-scope changes. Part 2 (batched buffer lookup viafind_existing_batch/PreparedBuffer) will be opened once Part 1 lands, and #3055 stays as a Draft for Part 3 (parallel sync viacrate::texture::in_parallel).Problem
In
descriptor::sync_heaps(), each dirty 64 KiB heap page callsHostHeap::sync_slotsindividually. Every page allocates three temporaryVecs (records,current,stale), locksVIEWSandself.madeseparately, and checksVIEWSeven for empty unchanged slots (tag != VIEW_TAG && made == 0).Fix
crates/victory-gpu/src/descriptor.rs:sync_heaps(), sorts and merges adjacent/overlapping ranges, and passes them in one call toHostHeap::sync_ranges.views_current(&[[u32; 3]]) -> Vec<bool>withwith_views(|views| ...), avoiding the per-pageVec<bool>allocation.crates/victory-gpu/src/descriptor/host.rs:HostHeap::sync_ranges(&self, ranges: &[(u32, u32)], start: u64, step: u64)(keepingsync_slotsunder#[cfg(test)]as a 1-line wrapper).self.count(preserving the capped-heap warning viapast_cap.max(last - 1)), sorts and merges ranges so every scanned slot index is unique, and diffs directly against title memory,self.made, andVIEWSunder one lock of each (preserving the existingself.made->VIEWSlock order) while skippingVIEWSfor empty unchanged slots.HostHeap::mirrorpath with no thread or lock-scope changes.descriptor::host::tests::sync_ranges_merges_overlapping_and_out_of_order_ranges.Verification & Benchmarks
Host: Windows 11 (
10.0.26200), AMD Ryzen 9 7950X, AMD Radeon RX 9070 XT (RDNA 4, driver32.0.32029.2010), basemain63bcca4.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.cargo test -p victory-gpu --lib --locked -- --test-threads=1: 232 passed, 0 failed, 1 ignored (includingsync_ranges_merges_overlapping_and_out_of_order_ranges).cargo run --locked -p xtask -- policy:asset policy: 191 files ok.Standalone benchmark (
--release, 700,416 slots across 342 dirty 64 KiB pages, 9-round medians,mainvs. Part 1 alone):main(63bcca4) median24618c9) median0changed / 700k scanned)6,000changed / 700k scanned)14,000changed / 700k scanned)Hardware runs and tests were performed by me on my 7950X / RX 9070 XT; PR and code drafted with Antigravity.
@Jackster on GitHub · 2026-11-26 12:15 UTC · original
On the retail title the batch does not move it, and the time is in view creation, not the scan
Same setup as my note on #2821 (Windows 11, RX 7900 XTX, 300 s world runs, same save, same cache).
stack2=63bcca4+ #2703 #1010 #2985 #2849 #2908 #2472 #2958 #3118 #2821, with and without this PR merged in:-8% on the sync, not the 2.43x the scan benchmark suggests: that gain needs many unchanged slots to skip, and in the world nearly every slot looked at has changed, so there is little to skip. The frame coming out lower I put down to scene spread in a single run.
What the sync is doing, from counters I added to
HostHeap::mirror(~400k slots examined a frame):So the cost is the ~47k
Create*Viewcalls, not the per-page scan this PR batches.For scale, deferring the read-only ones (constant buffers, buffer shader resources, non-UAV memory views) to the submission that first reads them took the sync from 261 ms to 126-151 ms and the frame from 1,025 ms to 859-880 ms at the same draw count. That prototype is not correct yet: a skipped slot keeps its previous descriptor, and constant-buffer slots have no read mark to bring them back (the tree marks texture reads; a local change also marks buffer loads; CBVs are the gap).
Suggestion: a "changed vs unchanged" line in the benchmark would predict which titles gain from the batch.
Written with an AI assistant.
@MeMako on GitHub · 2026-11-26 12:28 UTC · original
Thanks for running this on a real world trace and breaking down the
HostHeap::mirrorcounters — super helpful data!A few notes on those numbers:
+ #3139run (316,757 -> 394,581, likely scene spread as you noted), descriptor sync still dropped261.3 -> 239.1 ms(0.825 -> 0.606 usper mirrored slot,-26.5%), which lines up with the heavier-change end of our standalone benchmark table (14k / 700k->1.11x).0,6k, and14kchanged out of700kslots), and adding a higher-churn row (~12% changed, matching your ~47k / 400k ratio) makes sense so readers can see where Part 1's scan/diff speedup tapers off.Create*Viewbreakdown is spot-on and is exactly why#3055was split into three parts: Part 1 (#3139) cleans up thesync_heapsscan/diff half (eliminating per-page allocations/locks and skipping empty unchanged slots), while Part 2 (pr/sync-heaps-2-batched-buffers, queued behind this) batches theBUFFERSlookup for buffer/CBV/placed-memory views, and Part 3 (Draft#3055) parallelizesCreate*Viewacross workers viacrate::texture::in_parallel. Deferring read-only views to first use would also stack nicely on top of all three once CBV read-marking is solved.Comment drafted with Antigravity.
@Dukestar69 on GitHub · 2026-11-26 12:29 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 22/22 passed (includingsync_ranges_merges_overlapping_and_out_of_order_ranges).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly batches dirty heap page ranges under one diff pass in
sync_heaps.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@Jackster on GitHub · 2026-11-26 14:06 UTC · original
Follow-up: with the read marks in place, the deferral does not hold up
When I wrote the note above I had only the upper bound: skipping read-only slots without making them later. With the translator now marking buffer and constant-buffer heap reads, the host makes a marked slot after the submission that read it, and the saving largely disappears:
-4%, not -25%. The work moves rather than disappearing: the frame needs ~32k distinct views either way, and deferring them only decides when they are made.
One correction to my earlier note that may save someone time: a heap constant buffer is not a kind-13 handle. Shaders read one as a raw buffer view (kind 11,
emit/mod.rs"Constant buffers in the heap"), which is why the read-only raw kinds had to be let into the index map (heap_handle) before anything downstream could mark them.So for this PR's premise: batching helps only stale-heavy workloads (measured: not this one), and deferral helps only if the slots are never made at all (they are). What is left is the number and cost of the views a frame genuinely needs.
Written with an AI assistant.
@MeMako on GitHub · 2026-11-26 15:06 UTC · original
Thanks for the follow-up test — that's a really useful result, and the raw-view (kind 11) note on heap CBVs is great to have documented too.
Ruling out deferral actually lines up directly with why this work was split into three parts per triage feedback on
#3055: Part 1 (#3139) is intentionally just the zero-risk structural layer (collapsing the per-page loops into one deduplicatedstalebatch with no threading or lock-scope changes), not the full fix for those 261 ms. Since a frame genuinely needs those ~32k–47k views created either way, the bigger wins sit in Part 2 (batchedBUFFERSlookup) and Part 3 (parallelCreate*Viewacross workers).Draft
#3055already has all three parts stacked together if you ever feel like throwing it onstack2to see how much of the 261 ms moves once per-view lookup and view creation are batched and parallelized.Comment drafted with Antigravity.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.