gpu/draw: batch ListViews descriptor copies and remove per-draw allocations #272
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/272"
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 TaynanGT/Vice-Tay. Originally posted by mint17 on 2026-11-27T13:16:24Z.
Eliminates per-draw heap allocations, SipHash overhead, COM refcount churn, and per-descriptor
CopyDescriptorsSimplecalls on the hot submission path incrates/victory-gpu/src/draw.rsandcrates/victory-gpu/src/descriptor/host.rs(zero merge conflict with #234, #245, or #257).Changes
ListViewsCopyDescriptors(ListCopyBatch+HostHeap::make_listed_into): Collapses up to 64 primary + twin descriptor copies inState::tablesinto a singleCopyDescriptorscall (keepingCopyDescriptorsSimple(1, ...)for single copies), uses a singleviews.made.get(&words)lookup on hit, flushes onDropand before recording resets, and buffers displaced COM resources inline ([Option; 64]) soretire_resourcestrictly runs afterCopyDescriptorsoverwrites the shader-visible descriptor slots.HostHeap::keep_ref: Compares raw COM pointers underself.kept[index]before cloning/retiring onmake_listed_into,raw_at,raw_uav_at,constant_at, andconstant_raw_at.host_signatureTLS cache: Stores leaked&'static ID3D12CommandSignaturereferences instatic MADEand caches plain 'static references inthread_local!viatry_with()— eliminating COMAddRef/ReleaseperExecuteIndirectwhile running zero COM calls in TLS destructors at teardown.Few<T, N>& 24-byteReadyReader): ExtendsFewwithclear(), inline/spill-preservingdedup(), andPartialEq/Eq/Debug; replaces heapVecs inState::host_targets,set_targetsscratch buffers,State::tablesselectedindices, andFreshTable::ready(packed into a 24-byteCopyReadyReader).AddressHash& zero-atomic root-slot hits: Switchesroot_srv_slots/root_uav_slotstoAddressHashand borrowsOption<&Arc<Shadow>>on hits inroot_uavandroot_srv_table.Release Microbenchmark (
cargo test --release --locked -p victory-gpu --lib draw_batch_and_alloc_bench -- --ignored --nocapture)ListCopyBatch/ Zero-Alloc)ListViewscopy (20,000 tables)Vec+ SipHash +Arc::clonevsFew+ReadyReader+AddressHash)Verification
cargo test --locked -p victory-gpu --lib -- zero_alloc_tests descriptor::host::tests draw::record_hash_tests -- --test-threads=1(56 passed, 0 failed — includes 70-slotListCopyBatchboundary +len == 63pair-flush + deferred-retirement tests,keep_refidentity/retirement test, 4-threadhost_signaturetest, andFew/ReadyReadertests).cargo test --locked -p victory-gpu --lib --features diagnostics -- zero_alloc_tests -- --test-threads=1(6 passed, 0 failed).cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default +--all-features) andcargo test --locked -p xtask(11 passed, 0 failed).Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T13:23:17Z.
@mint17 The 48-descriptor comparison isolates the batching gain. The boundary I’ll check is that displaced COM resources stay alive until the destination slots are overwritten and any in-flight use completes. Keep the per-draw allocation result scoped to the microbenchmark.
Imported from TaynanGT/Vice-Tay. Originally posted by Garu667 on 2026-11-27T14:47:34Z.
Tested on an RTX 3080 10 GB (Series S,
-Machine auto, boat mission autosave, warm shader cache). Same executable source except for this PR:maine45051amain+ #272With this PR the game stalls for seconds at a time: frames of up to 36 s (
0.0 fps, 35992.8 ms/frame (22054.4 preparing: copies 7537.6 ms ...)). There's no crash and no card loss, and no pipelines are being made (warm cache). A combined build with #284 and #294 (run 160) stalled the same way. #272 alone reproduces it, so it looks like this one. Happy to rerun with a switch if there is one to turn the batching off.Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T15:01:51Z.
@Garu667 The switch is in
d3ff310.-More @{VICTORY_BATCH_LIST_VIEWS='0'}flushes each view with individual descriptor copies. Compare it with1on the same executable, boat save and warm shader cache. Median frame time, the longest stall and the preparing/copies breakdown are enough to tell whether the batching is responsible.Imported from TaynanGT/Vice-Tay. Originally posted by mint17 on 2026-11-28T04:00:11Z.
@TaynanGT @Garu667 Thanks for the detailed RTX 3080 reproduction and for adding the
VICTORY_BATCH_LIST_VIEWStoggle ind3ff310!After auditing
3caeac1line by line against thepreparing/copiesstall profile, all Rust state logic (Few,keep_ref,AddressHashroot slots,host_signature,views.made) emits identical deferred work, leaving two concrete regressions — both fixed ine2880f7:VICTORY_BATCH_LIST_VIEWSto off (directCopyDescriptorsSimple(1, ...)):ListCopyBatch::flush()was the only runtime multi-rangeID3D12Device::CopyDescriptorscall in the codebase, hit concurrently across 12 recording threads (VICTORY_THIN_THREADS=12+VICTORY_D3D12_DRED=faults) against the shared shader-visible heap whileHost::submit/refresh_spans/victory-heap-syncalso call intoID3D12Device. Flipping the default to directCopyDescriptorsSimple(1, ...)+ immediate post-copy resource retirement keeps theVICTORY_BATCH_LIST_VIEWS=1switch intact for A/B comparison while avoiding the stall by default.FreshTable2.6× bucket bloat: InliningFew<ReadyReader, 4>grewFreshTablefrom 40 B → 144 B (inflatingfresh_tablesHashMapbuckets from 64 B → 168 B). Keeping the compact 24 BReadyReaderinsideVec<ReadyReader>restores a 40 BFreshTable/ ≤ 64 B single-cache-line bucket (pinned with a compile-time layout guard infresh_table_fits_single_cache_line_bucket).Re-verified cleanly: 58/58 targeted tests (default), 8/8 diagnostics tests, Clippy (default +
--all-features), andxtask(11/11) all pass with zero warnings.Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T11:23:58Z.
Thanks for isolating the two regressions. Keeping direct copies as the default and the batch toggle available for A/B makes sense. Please repeat the RTX 3080 workload on
e2880f7with both toggle states before we reconsider batching by default.Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:13:52Z.
mainhas moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the currentmainand open a new PR; I'll review it there.Pull request closed