perf(gpu): replace TextureQueue BTreeMap scan with dense vector, add away_nonempty fast-path, bump Tells::BATCH #1242
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1242"
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 qlfu on 2026-11-28T16:15:59Z.
Summary
Reduces
TextureQueuemutex hold time and lock contention on dense texture-queue scans, avoids taking theHostHeaplocks on the common empty-awaypath, and increasesTells::BATCHflush granularity:TextureQueuestorage (crates/victory-gpu/src/descriptor/host.rs):TextureQueue.slots: BTreeMap<u32, Waiting>with denseVec<Waiting>+SlotMeta+HashMap<u32, usize>index usingswap_removeon removal, plusheld: HashMap<u32, u64>and pre-reservedDuestaging vectors.TextureQueue::due()now scans contiguousVec<Waiting>memory instead of chasingBTreeMapnode pointers across tens of thousands of queued slots.dense_texture_queue_preserves_pos_and_meta_across_removals_and_transitions.HostHeap::awaycheck (crates/victory-gpu/src/descriptor/host.rs):away_nonempty: AtomicBoolonHostHeap, allowingtexture_slot_here()andtexture_slot_gone()to return immediately in the common case whenawayis empty without lockingaway/made.crates/victory-gpu/src/draw.rs):Tells::BATCHfrom16to64so draw-thread texture notifications flush fewer small batches under contention.Benchmark (GTA VI, 90s steady gameplay, 1440p Series X, DLSS Quality, Ryzen 7 5700X + RTX 4070 Ti 12 GB)
Paired A/B on
main(9ce3cf9) with-FrameGen(VICTORY_TEXTURE_ROOM_PERCENT=80, 90% no-room intervals):main(9ce3cf9)pr/texture-queue-perf(ef3b9ae)TextureQueuelock hold indue()(held due)145.5 ms35.5 msTextureQueuetotal lock wait (notingpart)629.5 ms(434.5 ms)251.5 ms(179.5 ms)prep/copy back)63.95 ms(46.95/18.4)59.95 ms(44.85/14.95)present-wait19.7 ms15.4 ms15.6516.7016.0616.8921.323.2WARN/ERRORcount0/00/0(Before
64d4931ondf2daaf, the same commit improved non-VRAM-capped-NoFrameGenReadyruns from15.6 -> 18.8median FPS /13.64 -> 18.43mean FPS, and cut lock wait from202 -> 88 ms.)Verification
cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings/errors in modified files (descriptor/host.rs,draw.rs).cargo test --workspace --exclude victory-gpu --locked: all crate tests passed (xtaskfailed only on pre-existing upstreambindings.iniallowlist check from4715a42).cargo test -p victory-gpu --locked -- --test-threads=1: 455 passed, 0 failed, 36 ignored (single-threaded avoids pre-existing multi-thread hang inwatch::tests::faults_that_take_no_lock_tell_the_same).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jptorres96 on 2026-11-28T17:50:47Z.
Checked at
ef3b9ae(base9ce3cf9), Windows build 26300, rustc 1.98.1.The queue, differentially. I added a throwaway test, not for commit, that drives a
TextureQueuethrough a seeded random run of its operations:written(seen or not),take_out,later,hold,room,partly,recheck,changed,done, and frames moving on. That is 40 seeds of 4,000 operations over 200 slots. Every 7 steps it prints what callers see:due_and_census(frame)withDue::ordered(usize::MAX),census(frame), andchecked,mappedand the mark of a random slot. On the base and on this PR the outputs are byte-identical (45,760 lines). The runs keep about 120 slots queued, with every census state present.So the dense storage and
metastay in step throughswap_removeand every transition. The walk order changes from index order toVecorder, but that doesn't show, becauseDue::orderedsorts by write number, which is unique.cargo test -p victory-gpu --lib -- --test-threads=1: 455 passed, includingdense_texture_queue_preserves_pos_and_meta_across_removals_and_transitions.cargo clippy -p victory-gpu --all-targets [--all-features] --no-deps -- -D warnings: clean apart frommain's ownmanual_is_multiple_of.away_nonemptyis only stored under theawaylock, so it ends as the map does. The unlocked read intexture_slot_herecan only miss an insertion of the same slot made concurrently. Its other caller holds the slot'smadelock, astexture_slot_gonedoes, and the texture pass calls gone and here for a slot one after the other.One thing to look at:
Tells::BATCHgoes from 16 to 64. The comment just above it gives the reason for 16: "so that a pass that takes the slots due meanwhile on another thread finds few of these told late". With 64, a concurrent pass can find up to four times as many slots told late, and the differential can't measure that. It may be worth keeping 16, or making the change on its own with an in-game number, since the rest of the PR doesn't depend on it.No game files.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-28T18:39:16Z.
Thanks for the differential test and thorough audit @jptorres96! Good point on \Tells::BATCH\ — reverted it back to \16\ so this PR stays focused solely on the semantics-preserving dense \TextureQueue\ + \way_nonempty\ changes in \descriptor/host.rs.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T19:23:24Z.
Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.
Pull request closed