GPU: batch and parallelize descriptor heap syncs #3055
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!3055
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3055"
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 05:40 UTC · original
MeMako:pr/sync-heaps-perf→main· +1154 −69 · 5 files · 4 commits · draftProblem
descriptor::sync_heaps()runs before every submission on the submitting thread:HostHeap::sync_slots), allocating three temporaryVecs per page (records,current,stale) and lockingVIEWSandself.madeonce per page while looking upVIEWSeven for empty unchanged slots.HostHeap::mirror, takingself.madetwice andVIEWS,self.kept,RETIRED, andself.viewedonce per slot, running D3D12Create*Viewserially, and callingshadow::for_view/shadow::findup to three times per buffer descriptor (prepare,make, andbindless::seen).Fix (Clean 4-Commit Stack)
24618c9(Part 1, #3139): Batches dirty page ranges and diffs directly against title memory,self.made, andVIEWSunder one lock of each (made->VIEWS), clamping withpast_cap.max(last - 1)and skippingVIEWSfor empty unchanged slots.5825419(Part 2): Addsshadow::find_existing_batch(placed cleanly afterfor_viewsofor_viewkeeps its doc comment),PreparedBuffer,prepare_resolved,make_with(removing duplicateGetDesc()inbuffer_uav),bindless::Viewed::set_with/seen_entry, and tests forfind_existing_batchandWHILE_PREPARINGretries (sync_ranges_retries_slot_rewritten_while_preparing).cae33f6(Part 3): Parallelizes dirty page probing (pages.len() >= 16), Phase 1 diff (total >= 32_768), Phase 2 texture preparation, and Phase 3 D3D12 descriptor creation (ready.len() >= 64) using the crate's existingcrate::texture::in_parallelhelper (max 4 workers, zerounsafein parallel result collection). Holdsself.madeonce across Phase 3, re-checks both live title slot bytes andVIEWSgeneration undermade->VIEWS(retrying concurrently rewritten or released slots viaHostHeap::mirrorafter droppingself.made), and appliesself.kept,host::retire_all, andbindless::Viewed::set_batchin one lock each.566a27a(by@passerbyyhx, viaMeMako/VIctory#1): Non-#[ignore]testa_sixteen_page_heap_sync_preserves_sparse_views_at_the_boundariescovering both the 16-page parallel probe and 32,768-slot Phase 1 parallel diff thresholds.Related PRs
bindlessFxMap+ O(1)forget): orthogonal;bindless.rs'sInnercontainers are untouched here.SHADER_HEAPS/BUFFERS/VIEWSRwLock): orthogonal; lock types are unchanged here, and holdingself.madeacross Phase 3 keepssync_rangessound even under concurrentSHADER_HEAPSreaders.Verification & Standalone 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 --workspace --locked -- --test-threads=1: all passed, 0 failed (victory-gpu: 236 passed,victory-shader: 305 passed,xtask: 6 passed).cargo run --locked -p xtask -- policy:asset policy: 191 files ok.Standalone benchmark (
--release,world_frame_sync_heaps, 700,416 slots across 342 dirty 64 KiB pages, 9-round medians,mainvs. Part 3 alone):main(63bcca4) median566a27a) median0changed / 700k scanned)6,000changed / 700k scanned)14,000changed / 700k scanned)(A standalone live
mainvs. Part 3 title run — without other PRs — will be added before marking this PR ready for review.)Hardware runs and tests were performed by me on my 7950X / RX 9070 XT; PR and code drafted with Antigravity.
@Marvisak on GitHub · 2026-11-26 06:19 UTC · original
Automated triage for the maintainers.
Verdict: needs work.
sync_heapscost is a real target. However, this PR rewritesHostHeap::sync_slotsinto a three-phase multithreadedsync_ranges(about 800 lines indescriptor/host.rs). It also changes lock scope:self.madeis now held across descriptor creation and thekept/RETIRED/viewedupdates. That is too much to review as one change. Specific points:sync_heaps(page probing) and bothsync_rangesphases usestd::thread::scopeplusscope.spawn. That creates fresh OS threads on every sync, before every submission, about 19 times a frame by your own figure. The crate already has a worker helper (crate::texture::in_parallel, used here for textures). Use it, or measure the spawn cost in the live case.crates/victory-gpu/src/shadow.rs,find_existing_batchis inserted betweenfor_view's doc comment andfor_view.for_viewloses its documentation, and the new function inherits it.find_existing_batch/PreparedBuffer). Third, parallel descriptor creation. Each part can then be measured and reviewed on its own, especially the held-madelock order and the concurrentset_stride/set_mark/note_addresswrites.mainagainst this PR alone in the live case.CI:
checkpassing.Generated by Claude Code
1a09c6fe3fto566a27aaeb@fuzeofficlal on GitHub · 2026-11-26 05:54 UTC · original · approved these changes
Reviewed head
1a09c6feline-by-line (lock ordering, disjoint-slot parallelism, MRU buffer lookup, and resource retirement) and verified locally on Windows 11 (NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):sync_ranges_mirrors_and_clears_many_slots_in_parallel,find_existing_batch_matches_find_for_nested_and_adjacent_buffers, anddescriptor::(22/22, skipping only the known RTX 1M-view heap cap testdynamic_slots_are_held_until_released) all passed.VICTORY_D3D12_WARP=1):sync_ranges_mirrors_and_clears_many_slots_in_parallel,find_existing_batch_matches_find_for_nested_and_adjacent_buffers, anddescriptor::(23/23) all passed.cargo clippy -p victory-gpu --locked --all-targets -- -D warnings(default and--features diagnostics) — 0 warnings.Lock ordering matches existing paths (
SHADER_HEAPS -> self.made -> VIEWSin Phase 1;self.madedropped for Phase 2find_existing_batch/texture::in_parallel;self.made -> self.keptthenhost::retire_allafter releasingself.kept, andself.made -> self.viewed.innerin Phase 3). Sorting/mergingraw_clampedinto disjoint intervals ensures worker threads write disjoint0..self.countdescriptor slots, and Phase 3 re-checks both the live title slot bytes andmade[index] != keybefore writing.Minor non-blocking notes:
HostHeap::sync_ranges,if last > self.count { past_cap = Some(last - 1); }overwritespast_caprather than taking.max(last - 1). Current callers pass sorted ranges, but taking the max keepsHIGHESTconsistent regardless of input order.resource::release->descriptor::forget(bumpingVIEWSgeneration without overwriting heap slot bytes), thenow == rawcheck still passes with the snapshotView(same window asHostHeap::mirroronmain); re-checkingVIEWSgeneration when buildingreadywould tighten that window.#[ignore]coverage for thepages.len() >= 16parallel probe path, thetotal >= 32_768Phase 1 parallel diff path, and a Phase 2->3retrytrigger (viaWHILE_PREPARING) would be nice additions.@kotekompotek on GitHub · 2026-11-26 06:04 UTC · original · approved these changes
Verified the concurrency design end-to-end: Phase 1 diffs under the same made→VIEWS lock order the serial path used; Phase 2 prepares outside locks (find_existing_batch is provably find-equivalent for buffer-resident queries — innermost containing = first .rev() match with end >= end, and the MRU's 'address < next_key_start' guarantees no deeper key; loose/ambiguous falls back to find); Phase 3 re-reads every record and retries changed slots through mirror — the TOCTOU that mattered. Ranges are sorted/merged so parallel slot writes are strictly disjoint; made is held across the whole apply; stride/mark/address/viewed/kept keep their own locking as in mirror. past_cap preserves the beyond-count path. sync_workers caps at half-parallelism ≤6 — leaves the title threads headroom. The 256-slot test discriminates make/clear/rewrite over split ranges.
@MeMako on GitHub · 2026-11-26 09:57 UTC · original
Updated
#3055per the triage review and@fuzeofficlal's notes, and marked it Draft while splitting it into three reviewable PRs:pr/sync-heaps-1-batched-diff,+155/-36, batched page probing + single-lock zero-alloc diff, zero thread or lock-scope changes). Part 2 (pr/sync-heaps-2-batched-buffers) is pushed on my fork and will be opened once #3139 lands.#3055now holds Part 3 cleanly stacked on top.crate::texture::in_parallel): Replaced all customstd::thread::scope/scope.spawnloops in page probing, Phase 1 diff, and Phase 3 descriptor creation withcrate::texture::in_parallel(max 4 workers).shadow.rsdoc comment: Movedfind_existing_batchafterfor_viewwith its own doc comment sofor_viewkeeps its documentation.@fuzeofficlal's three notes (past_cap.max(last - 1), Phase 3VIEWSgeneration re-check undermade -> VIEWS, and non-#[ignore]WHILE_PREPARINGretry testsync_ranges_retries_slot_rewritten_while_preparing), and included@passerbyyhx'sMeMako/VIctory#1commit (566a27a) covering both the 16-page and 32,768-slot parallel thresholds.main(63bcca4) vs. Part 3 (566a27a) numbers only (no mixed#2940figures). A standalone livemainvs. Part 3 run will follow before un-drafting.Hardware runs and tests were performed by me on my 7950X / RX 9070 XT; 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.