perf(gpu): reduce TextureQueue lock hold time, TELL fallbacks, and zero-work locks #797
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!797
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-797"
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?
@Capt-Speed on GitHub · 2026-11-28 06:12 UTC · original
Capt-Speed:perf/texture-queue-lock→main· +1073 −139 · 3 files · 1 commits · merged 2026-11-28 19:39 UTCMotivation
As recorded in #766 (
docs/findings.md),the texture queue's lock(TextureQueueincrates/victory-gpu/src/descriptor/host.rs) is the largest remaining lock in outdoor 4K runs (~214-278 ms waited / 5 s, peaks up to 594-666 ms):due_and_censuswalks a pointer-chasingBTreeMap<u32, Waiting>of 80-byte entries (including the cold 40-byteCheckedtuple) and growsDuevectors from capacity 0 while holdingHostHeap::textures'sMutex(41-51 ms held / 5 s, peaks 70-81 ms).draw.rs, when concurrent early and frame texture passes snapshot the same(index, write)due list and one finishes a slot (Told::Done(None)->marks[index] = 0), the sibling pass seestexture_slot_write(index) != Some(write)and falls back tohost.texture_slot_checked(index)underqueue_site::TELL(~73-84% of allTELLlock acquisitions, up to ~41k locks / 5 s) before executing the entire redundant slot body whoseToldis then dropped byTextureQueue::same.texture_news(),texture_slots_room(), and emptyMADE_DUEcalls acquire the queueMutexeven when nothing changed or no slots remain aftertabled_latelyfiltering.descriptor.rs::mirroracquiresheap.pending.lock()on every descriptor write even afterheap.host(OnceLock) is already published, andcopy_simplere-acquiresSHADER_HEAPS.read()per slot.Changes
crates/victory-gpu/src/descriptor/host.rs:BTreeMap<u32, Waiting>(80 B/entry) andheld: BTreeMap<u32, u64>with a cache-denseVec<Entry>(32 B/entry, swap-remove ontake_out, in-place overwrite onput),O(1)by_slotindex reusing existingcrate::host::AddressHash(zero new dependencies), and cold side mapschecked/mapped/held.Due(again: Vec<(u32, u64, u32)>,fresh: Vec<(u32, u64)>,checked: Vec<Checked>) outside theDUElock fromdue_hints; fast-pathmax == 0viacensus; useselect_nth_unstable_by_keyinDue::orderedto avoid sorting surplusagain/freshentries while preserving exact output order.QueueMarkswith lock-freewrites(AtomicU64) andhas_held(AtomicBool) sotexture_news()andtexture_slots_room()skip theMutexin the common case (respectingVICTORY_QUEUE_MARKS=0), and skip emptyMADE_DUElocks aftertabled_latelyfiltering. Keeptexture_slots_all_duesorted by slot index outside the lock and preserve atomicPAGE_WRITES[3]counting.QueueBatch/QueueFlusher::new_unpublished(&mut HostHeap)for initial unpublishedHeap::host()pending replay (compile-time restricted to&mut HostHeapso published heaps always commit per-slot underMade::lockand can never resurrect a table-read or stale slot).crates/victory-gpu/src/descriptor.rs:heap.host.get()lock-free beforeheap.pending.lock()inmirror(safe becauseHeap::host()drainspendingbeforeOnceLockpublishes).mirror_rangeforcopy_simpleto hoistSHADER_HEAPS.read()when the copied range overlaps a single heap that fully contains it (falling back to per-slotmirrorwhenever multiple placed heaps overlap, preserving priority order).crates/victory-gpu/src/draw.rs:queue_batch()is on and!baking && sync.is_none(), skip slots whosetexture_slot_write(index)is alreadySome(0)(left the queue) beforeTAKEN, and avoidhost.texture_slot_checked(index)onSome(0)in all modes.Tells::BATCHfrom 16 to 64.TextureQueue/Due::ordered/QueueBatchunit tests (dense_texture_queue_invariants_and_cold_maps,due_ordered_truncation_matches_full_sort,queue_batch_remove_if_never_clobbers_newer_write_and_matches_unbatched).audit_range_matches_individual_with_aliases,audit_shared_copy_table,audit_shared_copy_stale) covering overlapping placed-heap priority and concurrent table-read / stale-view races during range mirroring.Verification
Automated
cargo test -p victory-gpu --lib --locked audit_regressions -- --test-threads=1: 3 passed, 0 failedcargo test -p victory-gpu --lib --locked descriptor -- --test-threads=1: 69 passed, 0 failedcargo test -p victory-gpu --lib --locked draw -- --test-threads=1: all passedcargo test -p victory-gpu --features diagnostics --lib --locked descriptor::host:: -- --test-threads=1: 55 passed, 0 failedcargo test -p xtask repository_passes_policy --locked: 1 passed, 0 failedcargo clippy(default and--features diagnostics): 0 warnings in changed/added code and testsgit apply --checkagainst PR #666: clean, no conflicts;Cargo.lockunchanged (--locked).Real-hardware measurement (RTX 5090 D 32 GB, Ryzen 7 9800X3D, 4K Series X,
a4d05e7baseline)5-minute outdoor run (identical save snapshot, 120 s
VICTORY_KEYS_FILEsequence, identical 51VICTORY_*switches, 0 errors, normal outdoor textures):a4d05e7)TELLlock acquisitions / 5 sDUEhold time (due_and_census) / 5 sMADE_DUElock acquisitions / wait / 5 sTextureQueuelock wait / 5 sslots_taken/ 5 sDisclosure on FPS: This D run was taken with background processes leaving ~27 GB free RAM and triggered
host memory pressure (physical_free_mib=2651)mid-run, slowing unrelated subsystems (views' lock+21%,copying back+3-4 ms) relative to the fresh-reboot A run; therefore no net FPS delta is claimed here (only the lock-contention and duplicate-work telemetry above). I can follow up with a clean post-reboot A/D frame-time comparison in a comment.@nick0451 on GitHub · 2026-11-28 09:21 UTC · original · edited 2026-11-28 10:00 UTC
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
63b902f.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.
63b902fFor this PR: no change in fps here. Preparing is 1.2 ms higher, within noise. The lock you target is the one you measured outdoors at 4K, which this scene, a balcony by the water, does not stress the way a 4K street does.
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
ERRORlines in any build: about 7 minutes in the world each, warm-up included.Tested with an AI assistant (Claude Code); results are from this PC.