gpu: keep the narrow barriers' scratch per thread and ask for CommandList7 once #2856
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2856"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by shiman1901 on 2026-11-29T18:14:45Z.
Related to #799
What it changes
The narrow-barrier replay (
VICTORY_NARROW_BARRIERS, merged in #799) runs 653–816 times a frame on the recording thread. On each call it queriedID3D12GraphicsCommandList7via.cast::<>()(QueryInterface), allocated four freshVecs plus a barrier-groupVec, and collected overlapping host copies for buffer barriers into a freshVec<Arc<Shadow>>. On CPU-bound setups (reported in #799 by @POMXARK on Ryzen 7 5700X + RTX 5080:victory-submit59.3 -> 70.9 ms,steps28.3 -> 36.5 ms), that adds ~800–1,000QueryInterfacecalls and ~3,000 heap allocations per frame on top of the barriers themselves.This keeps all emitted barriers, ordering, dedup keys, and global-UAV fallbacks identical while removing the per-call overhead:
HostList::list7(host.rs,host/place.rs,list.rs): queriesID3D12GraphicsCommandList7once atHostListcreation (list.cast::<ID3D12GraphicsCommandList7>().ok()) and reuses it across all four hot call sites (list.rslegacy narrow path +replay_narrow_barrier_groups, andhost/place.rsbuffer_barriers+wait_for_all, which now take&HostListdirectly fromself).BarScratch(list.rs): keeps the replay vectors in a thread-localRefCell<BarScratch>taken via an RAIIGuard. BecauseD3D12_BUFFER_BARRIER::pResourceis aManuallyDrop,BarScratch::clear()(called in bothGuard::dropandBarScratch::drop) drops everypResourcebefore clearing while preserving vector capacity — leak-free on early returns and panics.shadow::for_each_overlapping(shadow.rs): walksBUFFERSandLOOSEunder their read locks via callback without allocatingVec<Arc<Shadow>>. Buffer barriers clone only&ID3D12Resource(AddRef) intoscratch.keptinside the read locks, release the locks, then callHostList::keep(&res)(no host-list lock ever taken underSHADOWS/LOOSE) and moveresviakept.drain(..)straight intoD3D12_BUFFER_BARRIER::pResource(avoiding a secondAddRef/Release).peek_overlappingis now a 3-line wrapper overfor_each_overlapping.No new
unsafebeyond the existingManuallyDrop::drop.How it was tested
Ryzen 7 5700X + RTX 5080, 653–816 replays/frame). CC @Czer0xx @POMXARK for a live A/B re-check once CI is green.victory-submit59.3 -> 70.9 ms,steps28.3 -> 36.5 ms)cargo testpassed for the crates it touches: verified via Windows CI workflow (added 4 GPU-less unit tests:list::bar_scratch_tests::the_scratch_is_emptied_and_keeps_its_capacity,list::bar_scratch_tests::a_panic_empties_the_scratch_too,shadow::overlapping_tests::an_address_with_no_copy_names_none,shadow::overlapping_tests::a_range_past_the_address_space_is_refused)Checked for overlap