Repository navigation
victory-gpu: stall-free per-draw zero-alloc and COM fast paths (2.74×) - #801
Conversation
Eliminate hot-path heap allocations, SipHash overhead, and redundant COM refcount traffic in per-draw recording without introducing multi-range CopyDescriptors batching or inflating FreshTable HashMap buckets: - HostHeap::keep_ref pointer-equality fast path and single-lookup views.made hit path in make_listed, keeping direct CopyDescriptorsSimple and immediate post-copy resource retirement - Shutdown-safe &'static ID3D12CommandSignature TLS cache for host_signature (zero AddRef/Release on hot ExecuteIndirect and merge::Held join checks) - AddressHash and borrowed &Arc<Shadow> lookup for root_srv_slots and root_uav_slots - Stack-inline Few<u32, 16> with dedup for State::tables selection - Compact 24-byte ReadyReader inside Vec<ReadyReader> in FreshTable (<= 48 B struct, <= 64 B HashMap bucket with compile-time layout guard)
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto main (63b902f).
- Merge & Policy: Clean merge;
cargo xtask policypassed (294 files ok). - Tests (RTX 5090):
cargo test -p victory-gpu --lib descriptor::passed (63 passed; 0 failed, includingzero_alloc_tests::keep_ref_skips_clone_on_identity_and_retires_on_replacement).cargo test -p victory-gpu --lib draw::passed (12 passed; 0 failed; 2 ignored, includingfresh_table_fits_single_cache_line_bucket,few_dedup_and_eq_preserve_inline_invariant,ready_reader_layout_and_fresh_table_matching_and_clearing, andhost_signature_shares_static_com_pointer_across_threads).
- Compiled with 0 warnings.
Strong per-draw hot-path optimization with clean lifetime/COM-pointer invariants and solid unit coverage. LGTM.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
Tested this PR across two 20-minute 3D A/B runs on Windows 11 — PASS on warm-cache 20m run (strong Setup
20-Minute 3D A/B Results (Strict 3D-only, Draw-Count-Matched)
Note on Run A (first run)
|
|
Tested in the game: RTX 3090 24 GB (driver 610.88), i9-14900K, Windows 11. Release builds, each of #797, #801, #814 and #816 merged on its own onto main at How: the same frozen save, outdoors on a balcony by the water, about 5,900-6,100 draws a frame (corrected: I first wrote "an interior"). Series S, DLSS Performance, frame generation off, standing still. Each build is started once first as a warm-up (a new build's first start is slow), then the five builds are run in turn, three rounds. Each run is 40 s to settle, then 60 s measured, and the figures are medians of the frame lines. An A/A run of main against itself the same way differed by 2-3%, so smaller differences are noise.
For this PR: no regression, and +1% fps here, within noise. Preparing is unchanged. The per-draw CPU savings would need a scene where the submitting thread is the limit to show. In this scene the card is about 95% busy, so the frame is the card's. Work saved on the CPU side would show in "preparing" more than in fps. No crashes, device losses or Tested with an AI assistant (Claude Code); results are from this PC. |
|
Tested this on a Ryzen 5 9600X (6 cores) with an RTX 5080, Windows 11, Series X 4K output, DLSS Performance, frame generation 2x, THIN on with JOIN_PARTS 8, opening prison scene, about 4,800 draws a frame. Release builds of 63b902f and of this PR (0a68f4a), warm cache, alternating runs, mean fps from 30 to 150 s after the world starts:
So about +0.3 fps (1 to 2 %), which is inside the run to run spread here (about 1 fps). The preparing time was the same, 28 ms a frame both ways. On this PC the frame is set by the submitting thread's other work, so I could not measure a gain from the recording side. No crash and no new warning in the three runs with this PR (about 12 minutes). One of the 63b902f runs ended with a device removal (0x887A0006, relay fence) after about 2.5 minutes, so that is not from this PR. |
…1-coder#923 trustno1-coder#890 trustno1-coder#1008 trustno1-coder#1005 trustno1-coder#801, and trustno1-coder#953 by hand Merged from trustno1-coder/VIctory-NVIDIA, all aimed at the 8 GB card / 32 GB RAM class of machine this fork targets: trustno1-coder#784 empty texture blocks kept in proportion to the card's budget (VICTORY_SPARE_SCALE=1) trustno1-coder#986 texture staging retried in smaller blocks after out-of-memory trustno1-coder#923 lists' upload buffers kept and used again, not made for each copy trustno1-coder#890 VICTORY_CARD_BUFFERS_MIN_KB, an 8 GB card's floor trustno1-coder#1008 fault-page bound raised to 16,384, <4 GiB strays skipped trustno1-coder#1005 >65,535-group indirect dispatches enabled on NVIDIA trustno1-coder#801 stall-free per-draw zero-alloc and COM fast paths trustno1-coder#953 (an upload buffer refused for want of memory is asked again once the spare scratch chunks are freed) conflicted with the tree's own try_upload_buffer split; ported by hand with the same semantics and the same log line. Not taken: trustno1-coder#991, trustno1-coder#1014, trustno1-coder#722 - they conflict in pool.rs / draw.rs / memory.rs, which trustno1-coder#784, trustno1-coder#801 and trustno1-coder#1008 already changed here.
…rustno1-coder#801) From trustno1-coder/VIctory-NVIDIA, 686 lines over draw.rs and descriptor/host.rs, reported as 2.74x per draw there. Applied as it was, with one conflict in host_signature resolved in upstream's favour (it returns a 'static reference, so no COM refcount traffic per indirect execution and none during thread teardown); our find_any by the record's first bytes and the address cache are untouched beside it.
…paths (trustno1-coder#801)" This reverts commit abdad93.
… path, and reverted Same profile, same build otherwise: ExecuteIndirect 30,3 µs with our first- record lookup and address cache, 65,3 µs with trustno1-coder#801 on top; finding the arguments' copy 4-9 ms against 27-28. Tuned without those, its changes to the same code take the slow way. Reverted; trustno1-coder#1134 and trustno1-coder#1400 stay.
Summary
Eliminates hot-path heap allocations, SipHash overhead, and redundant COM reference-count traffic during per-draw recording in
victory-gpuwhile deliberately keeping direct per-viewCopyDescriptorsSimple(1, ...)copies and compact 64-byteFreshTablehash buckets:HostHeap::keep_ref& single-lookupmake_listed(crates/victory-gpu/src/descriptor/host.rs):self.kept[index]to skipAddRef/retirement on identity rebinds, retiring displacedID3D12Resourcehandles strictly outside the slot lock and strictly after descriptor copy / twin update.views.madelookups onmake_listedcache hits with a single lookup while keeping directCopyDescriptorsSimple(1, ...)(no multi-rangeID3D12Device::CopyDescriptorsbatching, avoiding multi-threaded D3D12 driver serialization stalls).raw_at,raw_uav_at, andconstant_attokeep_ref.host_signatureTLS cache (crates/victory-gpu/src/draw.rs):static MADE(matching existing process-lifetime retention) and caches plain&'static ID3D12CommandSignaturepointers inthread_local!viatry_with().AddRef/Releaseon hotExecuteIndirectcalls andmerge::Heldjoin checks, and zero COMReleasecalls on thread teardown.AddressHash+ borrowed&Arc<Shadow>hit path (crates/victory-gpu/src/draw.rs):root_srv_slotsandroot_uav_slotsfrom default SipHash toAddressHashand borrows&Arc<Shadow>on hits (moving without cloning on misses).Few<u32, 16>inState::tables(crates/victory-gpu/src/draw.rs):Few::dedupandPartialEq/Eq/Debugpreserving inline invariants and removes per-drawVec<u32>allocations when selecting descriptor tables.ReadyReaderinVec<ReadyReader>(crates/victory-gpu/src/draw.rs):FreshTableat 40 B (<= 48 B) and itsHashMapbucket at 64 B (<= 64 B), guarded by compile-time layout assertions (avoiding inline-array bucket bloat).Conflict Hygiene
set_targets/State::host_targetsuntouched (conflict-free with draw: reuse State allocations across reset, cache target state sync, and stack-allocate RTVs #390).git merge-tree --write-treewithorigin/main, gpu/descriptor: 2-level 64-bit bitmap DynamicSlots allocator and batched reclamation #704 (perf/dynamic-slots-bitmap-batch-release), and gpu/heap_worker: add race-safe opt-in VICTORY_HEAP_WORKER #720 (feat/heap-worker-race-safe).Benchmark & Verification
draw_zero_alloc_bench, 250,000 draws):44.0 ns/draw(baselineVec+ SipHash +Arc::clone+ 40 B reader) ->16.0 ns/draw(Few+AddressHash+ borrow + 24 B reader) — 2.74× faster.cargo test --locked -p victory-gpu --lib -- zero_alloc_tests descriptor::host::tests draw::record_hash_tests -- --test-threads=1: 54 passed, 0 failed (1 ignored opt-in bench)cargo test --locked -p victory-gpu --lib --features diagnostics -- zero_alloc_tests -- --test-threads=1: 5 passed, 0 failed (1 ignored opt-in bench)cargo clippy -p victory-gpu --all-targets --locked -- -D warnings -A clippy::manual_is_multiple_of(default &--all-features): 0 warningscargo test --locked -p xtask: 6 passed, 0 failed