GPU: index TextureQueue by due frame (VICTORY_DUE_INDEX) #1497
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1497"
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 Czer0xx on 2026-11-28T20:49:39Z.
Motivation
After #797 (
28f87ef) packedTextureQueueinto a dense 32-byteVec<Entry>,collect_due_and_census,census, andall_duestill linearly scan every queued entry underHostHeap::textures's mutex on every pass. During gameplay the queue holds ~25,000-33,000 entries (~800-1,060 KiB), even when only a fraction hasdue <= frame.On RTX 3060 12 GB (1440p release, warm cache, post-#797
main),held taking the slots duestill averaged 72.8 ms / 5 s (median 75 ms, max 100 ms), blocking other threads for 621.2 ms / 5 s (max 942 ms).Changes
All new behavior is opt-in behind
VICTORY_DUE_INDEX=1(off by default, read once). With it unset,TextureQueueandheap_texturesbehave identically tomain.crates/victory-gpu/src/descriptor/host.rs:pub(crate) fn due_index()(VICTORY_DUE_INDEX=1, off by default).DueBucketsstoring the same contiguous 32-byteEntryvalues grouped perdueframe inBTreeMap<u64, Vec<Entry>>, withFastMap<u32, (u64, u32)>for O(1) slot lookup and in-bucket swap-remove, O(1)-maintained global census counters ([c[2], c[3], c[5]]), and a single recycledsparebucket buffer to avoid steady-state re-allocations as frame buckets drain.collect_due_and_census,census, andall_dueiterate onlyby_due.range(..=frame)(O(|due|)instead ofO(|queue|)).Due::with_capacityhints outside the lock,Due::orderedpartial selection,QueueMarkslock-free shadows,QueueBatch, coldchecked/mapped/heldside maps).due_buckets_matches_flat_texture_queue: 4,000-step randomized equivalence test comparing flatTextureQueuevsDueBucketsacrosswritten,remove,done,later,hold,room,partly,recheck(print == 0and!= 0),changed, andQueueBatch::apply, verifying identicaldue_and_census,ordered,census,all_due,checked,mapped,was_uploaded,QueueMarks, and internal invariants.due_buckets_skips_future_and_recycles_spare: verifies zero-work future skips and empty-bucket capacity recycling.crates/victory-gpu/src/draw.rs:VICTORY_DUE_INDEX=1andVICTORY_TEXSPK_PASS_MSis configured, skipbefore(0)andtexture_slots_due_knownif the current frame's upper-boundtexspk_cap_msbudget is already exhausted, while still flipping finished uploads viatexture_views_remade()andtexture_slots_flip().Verification
Automated
cargo test -p victory-gpu --lib --locked descriptor::host::tests -- --test-threads=1: 61 passed, 0 failed (including all #797 tests and both newdue_buckets_*tests).cargo test -p victory-gpu --lib --locked texspk: 2 passed, 0 failed.cargo clippy -p victory-gpu --lib --tests --locked: 0 warnings in modified files.cargo build --release --locked: succeeded cleanly.In-game A/B benchmark
Same release binary (
pr/due-indexonmain923e38c, which already includes #797), RTX 3060 12 GB, 1440p, DLSS Performance, warm pipeline cache (0 being madethroughout 3D), identical flags (VICTORY_TEXTURE_STAGE_MS=16,VICTORY_POOL_SMALL=1), only togglingVICTORY_DUE_INDEX:main+ #797,DUE_INDEX=0)VICTORY_DUE_INDEX=1held taking the slots due(med / mean / max / 5 s)held taking the slots due(steady state, last 2 windows)before the passes' loops(mean / max / 5 s)Both runs exited cleanly with zero D3D12 errors.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-28T20:49:47Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-29T02:27:29Z.
@Czer0xx — huge validation of the exact bottleneck this PR targets, plus a data point on taking the index one step further with an O(1) 256-slot timing wheel (
ready: Vec+wheel: [Vec; 256]+ overflowBTreeMap+ O(1) census counters).1. Synthetic 30,000-entry
TextureQueuemicrobenchmark (300 passes = 5 s window, Ryzen 7 5700X)HashMapscan14.09 ms1.0xVecscan4.67 ms3.0xBTreeMap<u64, Vec<Entry>>(PR #1497 design)2.89 ms4.9xready+ overflow0.68 ms20.7x(4.25xvsBTreeMap)2. Full 20-minute 3D A/B on Windows 11 (RTX 5080 16 GB, Ryzen 7 5700X 8C/16T, 32 GB RAM, 1440p DLSS Quality + 4x FG,
n=2285-second windows,0errors)BTreeMap<u32, Waiting>scan)held taking the slots due(med / mean)129.0/142.8 ms23.0/27.5 ms-82.2%/-80.7%(5.6xfaster)held taking the slots due(p90 / max)271.0/539 ms59.0/84 ms-78.2%/-84.4%waited for texture queue's lock(med / mean)860.5/1,103.9 ms415.5/475.9 ms-51.7%/-56.9%(-628 ms / 5s)waited for texture queue's lock(p90 / max)2,410.0/3,668 ms981.0/1,978 ms-59.3%/-46.1%>=10kdraws/f median8.60 FPS8.80 FPS+2.3%31,262 MB30,625 MB-637 MBKeeping already-due entries in a contiguous
ready: Vecand near-term future frames[cursor+1 .. cursor+256)in a power-of-two ring (wheel[due & 255], overflowing only>= 256frames intoBTreeMap) avoids tree rebalancing on every frame advance and keeps steady-statedue_and_censusstrictlyO(|due|)with O(1)swap_remove. Clean-room reference implementation + tests: https://github.com/POMXARK/bcpack-gpu-sdk/blob/main/src/timing_wheel.rs — feel free to reuse or adapt directly in this PR if helpful!Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Ty-lerCox on 2026-11-29T04:08:41Z.
this worked very well.