victory-gpu: coalesce and parallelize descriptor::sync_heaps #1290
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1293"
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?
Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-26T11:59:28Z.
Summary
Optimizes
descriptor::sync_heaps(crates/victory-gpu/src/descriptor.rs&crates/victory-gpu/src/descriptor/host.rs):read_into+ unmapped-page fallback (descriptor.rs): Merges touching/overlapping dirty[from, to)ranges without bridging clean gaps (coalesce_ranges) and splits runs intowatch::PAGE-aligned128 KiBchunks (chunk_ranges). Reads each chunk with a singleread_intocall, falling back to per-watch::PAGEread_intoacross the chunk on failure so valid neighbour blocks still mirror.descriptor.rs+descriptor/host.rs):HostHeap::copiedto lock-freeOnceLock<Vec<AtomicU64>>fingerprints (copied_slots) and passes snapshot[u32; 3]words (record_words) intomirror_inner.HostHeap::madeacrossKEPT_PIECES(64) mutexes matchingHostHeap::kept, droppingindex's shard before unmaking stale placed-texture slots viaSpans::note_keyed+HostHeap::unmake_if_key.slot_flags:FLAG_TEXTURE,FLAG_PLACED,FLAG_BUFFER,FLAG_KEPT) maintained inside their respective subsystem locks so unrelated descriptor writes (e.g. constant buffer views) skip empty subsystem mutexes.mirror_copied_sliceandVICTORY_HEAP_SYNC_PAGE=0mirror_copied) with per-shardmade_direct_epochcounters so a pre-copied snapshot never reverts a concurrent directHostHeap::mirror.crate::shadow::wide_runwhile preserving allVICTORY_HEAP_SYNC*toggles (=0,_CUT,_PAGE=0,_BESIDE,_TABLES) andSYNC_PARTS/SYNCEDwall-time telemetry.Verification
git diff --check origin/main,git merge-tree --write-tree origin/main HEAD, neutral-naming scan (0hits)cargo run -p xtask -- policy(220 files ok)cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated(default &--all-features:0warnings)VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu -- --test-threads=1(220 passed; 0 failed; 6 ignored — includes parity, mid-chunk unmapped-page fallback, chunk boundary/unchanged-slot skip,keep_views()mip-update stale unmake, requeuedFLAG_TEXTUREeviction, and concurrent direct-mirror clobber guard tests)VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1(239 passed; 0 failed; 7 ignored)cargo test --release -p victory-gpu --lib sync_heaps_coalesced_parallel_benchmark -- --nocapture(14,400dirty slots x10iters):64 KiBserial):2.504 ms/iter(8 reads/iter,parts=[take=0.014, read=0.038, walk=0.108, make=2.320])128 KiB):1.805 ms/iter(4 reads/iter,parts=[take=0.016, read=0.020, walk=0.089, make=1.677])Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-26T12:04:16Z.
Happy to A/B this on the RTX 3080 like #1279 (where your guard work gave 9.1 → 10.0 fps). It conflicts with current
main(ceb9e1f) indescriptor/host.rs:mainreworkedmirrorsince (made_now/heap_locks()fast path,keep_views/same_placed_texture,MIRROR_*timing), and yourmirror_innerrewrites the same body, so I'd rather not guess the merge. If you rebase it, I'll run it the same day against the same baseline.Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-26T13:08:10Z.
Independent A/B of this PR and the other two open
sync_heapsPRs (#1202, #1220), each against its own merge base, using one black-box benchmark. All three conflict with currentmain, so each PR head is compared with the commit it branched from.Benchmark.
descriptor::tests::sync_heaps_benchon KainanP/victory-fork@bench/sync-heaps, added unchanged to every tree. It only usescreate_heap,create_cbv/create_srv/create_uav,sync_heaps,SYNCEDandSYNC_PARTS.sync_heapscall is timed.mainceb9e1f06702fe4fe062c32b31f7a8f9c9dVICTORY_HEAP_SYNC_PARALLEL=1006c35318e9683VICTORY_HEAP_SYNC_ZERO_RUNS=1Results.
What this does not show.
@MKmajster, @CuteBooty (#1083): your profile had
descriptor::sync_heapsat 21–26 ms per frame. If you can, please run this PR and compare its by-part line ("the pass over the title's view heap by part") and the frame time with its base.AI use: Claude Code (Claude Opus 5.5) wrote the benchmark, built and ran the seven trees, and wrote this comment.
🤖 Generated with Claude Code
Imported from fxceless/victory-fork. Originally posted by CuteBooty on 2026-11-26T13:40:24Z.
Thanks for the benchmark. One correction to the mention: the 21-26 ms for
descriptor::sync_heapswas MKmajster's profile, not mine. My tree (CuteBooty/victory-8gb) does not havesync_heaps; it compares descriptor records in its own heap pass, about 240,000 records a frame at an estimated few milliseconds, so I cannot give a like-for-like number for this PR from it.If a run of the fork's own code on an RTX 3070 8 GB with a Ryzen 5 3600 would still help, I can do one, but it would be the fork's build, not mine, and it would take me a little while to set up.
Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-26T13:56:19Z.
@KainanP Thank you for running that 7-tree benchmark — seeing
1.42 msvs5.96 ms(4.2× faster, with identical401,408looked-at /9,298mirrored counts) is great confirmation of the coalesced reads and parallel walk/make pipeline.@Garu667 Cleanly rebased onto current
main(a20809d, includingceb9e1f) as8f3d81e, preserving all ofceb9e1f's changes alongside this PR:made_now/heap_locks()lock-free fast path (both pre-copied and direct paths inmirror_inner)keep_views()/same_placed_texturemip-refinement retention (withSpans::keysstale-span unmake intact)MIRROR_*diagnostics telemetry (MIRROR_HOWTLS per worker inmirror_copied_slice, all outcome counters inmirror_inner,MIRROR_US[0..3]acrossnote_buffer_key+stale_to_unmake, view creation, andkeep, and thesync_linebreakdown)Re-verified post-rebase:
cargo run --locked -p xtask -- policy:220 files okcargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated(default &--all-features): cleanVICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu -- --test-threads=1:220 passed, 0 failed(default) and239 passed, 0 failed(--features diagnostics), 0 D3D12 debug errorscargo test --release -p victory-gpu --lib sync_heaps_coalesced_parallel_benchmark -- --nocapture:2.035 ms/iter(4 reads/iter) vs2.494 ms/iter(8 reads/iter) baselineReady for A/B testing against
ceb9e1f/ currentmain!Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-27T00:08:04Z.
I reproduced a sequential interleaving on
d12f0029using GE-Proton11-14 and the RTX 5060 Laptop. The heap contains descriptor A. A sync pass captures interim record B, the title restores A, and a direct mirror hits the already-made A. The same-key path leaves the epoch unchanged. Applying the saved B then replaces the live descriptor.The focused D3D12 test failed on the PR plus the fixture and passed after a limited correction. The correction re-reads the live 12-byte record under the existing shard lock before a copied record can change the slot and clears the cached fingerprint on mismatch or read failure. Windows-target GPU Clippy passed with warnings denied. The neighboring filter returned 30 passes and one existing root-signature failure, which also reproduced before the correction.
This tests one descriptor interleaving. Parallel ordering across two clashing placed views and title throughput remain open measurements. The two source-only commits are available if useful. Review branch
Assisted by Codex (GPT-6.2-Sol High).
Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-27T07:00:36Z.
@Filip722 Thank you for reproducing the
A -> B -> Arepeated-view interleaving and sharing the fix and regression test (96c6e3a7/d146b467).Rebased onto current
main(9a9091d) and folded both commits intoafacd5e(withCo-authored-by: Filip722):heap_locks()default-on,view_address, and the lock-free!for_draw && tag != VIEW_TAGfast path (guarded byepoch_unchangedon copied snapshots).read_intounder the existing shard lock before a copied snapshot can update a slot, clearingcopied_slots[index]on mismatch or read failure and returningNoneif the live read fails.stale_copied_slice_does_not_replace_a_repeated_direct_view(matching the existingHostHeap::newskip-without-GPU guard and asserting fingerprint clearing on both mismatch and unreadable live handles).Re-verified (
VICTORY_D3D12_DEBUG=1):cargo clippy -p victory-gpu --all-targets -- -D warnings -A deprecated(default &--features diagnostics): cleancargo test -p victory-gpu descriptor:: -- --test-threads=1:47 passed, 0 failed(default and--features diagnostics), plus2 passed, 0 failedonstale_copied_sliceunderVICTORY_HEAP_LOCKS=0Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-27T20:57:29Z.
Closing as superseded following
5dbf5ce2(rebase ontoVIctory-NVIDIA959dcaf):descriptor.rsonmainnow includes background worker-threadedsync_heaps,begin_sync_heaps_after,VICTORY_SYNC_FINE,heap_marks.rs, and lock-freeHostHeap::quick/SPANS_QUICKfast paths. Happy to open a clean scoped PR on2eade68c+if a separate lock-freecopied/ shardedmadepass is still helpful.Pull request closed