Skip to content

GPU: index TextureQueue by due frame (VICTORY_DUE_INDEX) - #1497

Open
Czer0xx wants to merge 1 commit into
trustno1-coder:mainfrom
Czer0xx:pr/due-index
Open

Czer0xx wants to merge 1 commit into
trustno1-coder:mainfrom
Czer0xx:pr/due-index

Conversation

@Czer0xx

@Czer0xx Czer0xx commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Motivation

After #797 (28f87ef) packed TextureQueue into a dense 32-byte Vec<Entry>, collect_due_and_census, census, and all_due still linearly scan every queued entry under HostHeap::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 has due <= frame.

On RTX 3060 12 GB (1440p release, warm cache, post-#797 main), held taking the slots due still 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, TextureQueue and heap_textures behave identically to main.

  • crates/victory-gpu/src/descriptor/host.rs:
    • Add pub(crate) fn due_index() (VICTORY_DUE_INDEX=1, off by default).
    • Add DueBuckets storing the same contiguous 32-byte Entry values grouped per due frame in BTreeMap<u64, Vec<Entry>>, with FastMap<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 recycled spare bucket buffer to avoid steady-state re-allocations as frame buckets drain.
    • collect_due_and_census, census, and all_due iterate only by_due.range(..=frame) (O(|due|) instead of O(|queue|)).
    • Reuse all existing perf(gpu): reduce TextureQueue lock hold time, TELL fallbacks, and zero-work locks #797 machinery (Due::with_capacity hints outside the lock, Due::ordered partial selection, QueueMarks lock-free shadows, QueueBatch, cold checked/mapped/held side maps).
    • Add unit tests:
      • due_buckets_matches_flat_texture_queue: 4,000-step randomized equivalence test comparing flat TextureQueue vs DueBuckets across written, remove, done, later, hold, room, partly, recheck (print == 0 and != 0), changed, and QueueBatch::apply, verifying identical due_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:
    • When VICTORY_DUE_INDEX=1 and VICTORY_TEXSPK_PASS_MS is configured, skip before(0) and texture_slots_due_known if the current frame's upper-bound texspk_cap_ms budget is already exhausted, while still flipping finished uploads via texture_views_remade() and texture_slots_flip().

Verification

Automated

  • cargo test -p victory-gpu --lib --locked descriptor::host::tests -- --test-threads=1: 61 passed, 0 failed (including all perf(gpu): reduce TextureQueue lock hold time, TELL fallbacks, and zero-work locks #797 tests and both new due_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-index on main 923e38c, which already includes #797), RTX 3060 12 GB, 1440p, DLSS Performance, warm pipeline cache (0 being made throughout 3D), identical flags (VICTORY_TEXTURE_STAGE_MS=16, VICTORY_POOL_SMALL=1), only toggling VICTORY_DUE_INDEX:

Metric (3D, per 5 s / per frame) Baseline (main + #797, DUE_INDEX=0) VICTORY_DUE_INDEX=1 Delta
held taking the slots due (med / mean / max / 5 s) 75.0 / 72.8 / 100 ms 41.0 / 38.2 / 60 ms -45% med / -48% mean / -40% max
held taking the slots due (steady state, last 2 windows) 48 / 27 ms 9 / 3 ms -81% to -89%
Total queue-lock wait (mean / max / 5 s) 721.9 / 1,120 ms 593.3 / 915 ms -18% mean / -18% max
Other threads waiting on queue lock (mean / max / 5 s) 621.2 / 942 ms 518.1 / 813 ms -17% mean / -14% max
Pass waiting on queue lock (med / max / 5 s) 99.0 / 177 ms 73.0 / 113 ms -26% med / -36% max
before the passes' loops (mean / max / 5 s) 319.5 / 473 ms 271.7 / 407 ms -15% mean / -14% max
3D FPS (mean / med / max) 10.43 / 10.20 / 14.20 11.20 / 10.75 / 16.40 +7.4% mean / +5.4% med
3D frame time (med / p95 / max) 82.9 / 125.3 / 640.7 ms 77.8 / 108.9 / 268.7 ms -6% med / -13% p95 / -58% max
1 s windows with longest >= 180 ms / >= 300 ms 22 (28.2%) / 2 13 (16.5%) / 0 -41% spikes / 0 over 300 ms
Submitting thread median / GPU busy median 74.0 ms / 74.0% 70.2 ms / 82.0% -3.8 ms / +8.0 pp

Both runs exited cleanly with zero D3D12 errors.

Copilot AI balanced review requested due to automatic review settings November 28, 2026 20:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants