Skip to content

victory-gpu: stall-free per-draw zero-alloc and COM fast paths (2.74×) - #801

Merged
trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
mint17:perf/draw-zero-alloc-com-fast-paths
Nov 28, 2026
Merged

trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
mint17:perf/draw-zero-alloc-com-fast-paths

Conversation

@mint17

@mint17 mint17 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Eliminates hot-path heap allocations, SipHash overhead, and redundant COM reference-count traffic during per-draw recording in victory-gpu while deliberately keeping direct per-view CopyDescriptorsSimple(1, ...) copies and compact 64-byte FreshTable hash buckets:

  1. Pointer-equality HostHeap::keep_ref & single-lookup make_listed (crates/victory-gpu/src/descriptor/host.rs):
    • Compares raw COM interface pointers under self.kept[index] to skip AddRef/retirement on identity rebinds, retiring displaced ID3D12Resource handles strictly outside the slot lock and strictly after descriptor copy / twin update.
    • Replaces double/triple views.made lookups on make_listed cache hits with a single lookup while keeping direct CopyDescriptorsSimple(1, ...) (no multi-range ID3D12Device::CopyDescriptors batching, avoiding multi-threaded D3D12 driver serialization stalls).
    • Switches raw_at, raw_uav_at, and constant_at to keep_ref.
  2. Shutdown-safe zero-refcount host_signature TLS cache (crates/victory-gpu/src/draw.rs):
    • Leaks process-lifetime command signatures once into static MADE (matching existing process-lifetime retention) and caches plain &'static ID3D12CommandSignature pointers in thread_local! via try_with().
    • Zero COM AddRef/Release on hot ExecuteIndirect calls and merge::Held join checks, and zero COM Release calls on thread teardown.
  3. AddressHash + borrowed &Arc<Shadow> hit path (crates/victory-gpu/src/draw.rs):
    • Switches root_srv_slots and root_uav_slots from default SipHash to AddressHash and borrows &Arc<Shadow> on hits (moving without cloning on misses).
  4. Stack-inline Few<u32, 16> in State::tables (crates/victory-gpu/src/draw.rs):
    • Adds Few::dedup and PartialEq/Eq/Debug preserving inline invariants and removes per-draw Vec<u32> allocations when selecting descriptor tables.
  5. Compact 24-byte ReadyReader in Vec<ReadyReader> (crates/victory-gpu/src/draw.rs):
    • Keeps FreshTable at 40 B (<= 48 B) and its HashMap bucket at 64 B (<= 64 B), guarded by compile-time layout assertions (avoiding inline-array bucket bloat).

Conflict Hygiene

Benchmark & Verification

  • Release microbenchmark (draw_zero_alloc_bench, 250,000 draws): 44.0 ns/draw (baseline Vec + SipHash + Arc::clone + 40 B reader) -> 16.0 ns/draw (Few + AddressHash + borrow + 24 B reader) — 2.74× faster.
  • cargo test --locked -p victory-gpu --lib -- zero_alloc_tests descriptor::host::tests draw::record_hash_tests -- --test-threads=1: 54 passed, 0 failed (1 ignored opt-in bench)
  • cargo test --locked -p victory-gpu --lib --features diagnostics -- zero_alloc_tests -- --test-threads=1: 5 passed, 0 failed (1 ignored opt-in bench)
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings -A clippy::manual_is_multiple_of (default & --all-features): 0 warnings
  • cargo test --locked -p xtask: 6 passed, 0 failed

Eliminate hot-path heap allocations, SipHash overhead, and redundant COM
refcount traffic in per-draw recording without introducing multi-range
CopyDescriptors batching or inflating FreshTable HashMap buckets:

- HostHeap::keep_ref pointer-equality fast path and single-lookup
  views.made hit path in make_listed, keeping direct CopyDescriptorsSimple
  and immediate post-copy resource retirement
- Shutdown-safe &'static ID3D12CommandSignature TLS cache for
  host_signature (zero AddRef/Release on hot ExecuteIndirect and
  merge::Held join checks)
- AddressHash and borrowed &Arc<Shadow> lookup for root_srv_slots and
  root_uav_slots
- Stack-inline Few<u32, 16> with dedup for State::tables selection
- Compact 24-byte ReadyReader inside Vec<ReadyReader> in FreshTable
  (<= 48 B struct, <= 64 B HashMap bucket with compile-time layout guard)

@Dukestar69 Dukestar69 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.

Tested locally merged onto main (63b902f).

  • Merge & Policy: Clean merge; cargo xtask policy passed (294 files ok).
  • Tests (RTX 5090):
    • cargo test -p victory-gpu --lib descriptor:: passed (63 passed; 0 failed, including zero_alloc_tests::keep_ref_skips_clone_on_identity_and_retires_on_replacement).
    • cargo test -p victory-gpu --lib draw:: passed (12 passed; 0 failed; 2 ignored, including fresh_table_fits_single_cache_line_bucket, few_dedup_and_eq_preserve_inline_invariant, ready_reader_layout_and_fresh_table_matching_and_clearing, and host_signature_shares_static_com_pointer_across_threads).
  • Compiled with 0 warnings.

Strong per-draw hot-path optimization with clean lifetime/COM-pointer invariants and solid unit coverage. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@POMXARK

POMXARK commented Nov 28, 2026

Copy link
Copy Markdown

Tested this PR across two 20-minute 3D A/B runs on Windows 11 — PASS on warm-cache 20m run (strong Prep / heap reduction and +16.7%..+26.9% on heavy 3D draw workloads, -48.9% frames >100 ms, 0 errors).

Setup

20-Minute 3D A/B Results (Strict 3D-only, Draw-Count-Matched)

Metric Baseline (c41d01d, 20m) + PR #801 Run B (20m) Delta
Errors / DevRem / Exceptions 0 / 0 / 0 0 / 0 / 0 Clean
Responding (hw.csv) 328 / 328 (100%) 325 / 325 (100%) 100%
ALL 3D (n=162 / 181) 13.1 p50 (Prep 63.3, heap 17.9 ms) 13.5 p50 (Prep 52.7, heap 9.7 ms) Prep -10.6 ms, heap -8.2 ms
LATE 3D (last 30) 11.4 p50 (87.8 ms, Prep 69.2, heap 19.6) 13.3 p50 (75.2 ms, Prep 54.3, heap 3.2) +16.7%, max 112.3 -> 93.8 ms
1s frame_times (3D) 65.0 med / 85.3 p95 / 97.7 p99 (1,684 >100ms) 71.4 med / 78.4 p95 / 86.8 p99 (861 >100ms) p95 -6.9 ms, p99 -10.9 ms, >100ms -48.9%
4k–7k draws/frame (n=44 / 47) 13.20 p50 (Prep 63.0, heap 16.5 ms) 13.40 p50 (Prep 55.5, heap 9.7 ms) Prep -7.5 ms, heap -6.8 ms
7k–10k draws/frame (n=35 / 38) 10.40 p50 (96.4 ms, Prep 75.7, heap 18.8) 13.20 p50 (75.8 ms, Prep 56.4, heap 3.8) +26.9%, Prep -19.3 ms
Memory (hw.csv) SharedMax 9,468 MB, CommitMax 30,272 MB, MinRAM 0.75 GB SharedMax 8,860 MB, CommitMax 29,689 MB, MinRAM 1.84 GB SharedMax -608 MB, MinRAM +1.09 GB

Note on Run A (first run)

@nick0451

nick0451 commented Nov 28, 2026 •

Copy link
Copy Markdown

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.

Build fps, 3 runs median frame preparing card busy
main 63b902f 25.5, 24.7, 25.1 25.1 39.8 ms 25.6 ms 95%
#814 25.3, 25.6, 26.4 25.6 39.1 ms 25.1 ms 97%
#801 25.4, 25.8, 25.2 25.4 39.5 ms 25.8 ms 95%
#797 25.3, 25.2, 23.9 25.2 39.7 ms 26.8 ms 95%
#816 24.0, 25.4, 24.2 24.2 41.3 ms 25.0 ms 94%

For this PR: no regression, and +1% fps here, within noise. Preparing is unchanged. The per-draw CPU savings would need a scene where the submitting thread is the limit to show.

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 ERROR lines 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.

@yeedgrthfgv

Copy link
Copy Markdown
Contributor

Tested this on a Ryzen 5 9600X (6 cores) with an RTX 5080, Windows 11, Series X 4K output, DLSS Performance, frame generation 2x, THIN on with JOIN_PARTS 8, opening prison scene, about 4,800 draws a frame. Release builds of 63b902f and of this PR (0a68f4a), warm cache, alternating runs, mean fps from 30 to 150 s after the world starts:

run 1 run 2 run 3 mean
63b902f 23.3 24.0 23.7
this PR 23.4 25.5 23.2 24.0

So about +0.3 fps (1 to 2 %), which is inside the run to run spread here (about 1 fps). The preparing time was the same, 28 ms a frame both ways. On this PC the frame is set by the submitting thread's other work, so I could not measure a gain from the recording side.

No crash and no new warning in the three runs with this PR (about 12 minutes). One of the 63b902f runs ended with a device removal (0x887A0006, relay fence) after about 2.5 minutes, so that is not from this PR.

fylcr pushed a commit to fylcr/VIctory-NVIDIA-for-low-end that referenced this pull request Nov 28, 2026
…1-coder#923 trustno1-coder#890 trustno1-coder#1008 trustno1-coder#1005 trustno1-coder#801, and trustno1-coder#953 by hand

Merged from trustno1-coder/VIctory-NVIDIA, all aimed at the 8 GB card / 32 GB
RAM class of machine this fork targets:

  trustno1-coder#784  empty texture blocks kept in proportion to the card's budget
        (VICTORY_SPARE_SCALE=1)
  trustno1-coder#986  texture staging retried in smaller blocks after out-of-memory
  trustno1-coder#923  lists' upload buffers kept and used again, not made for each copy
  trustno1-coder#890  VICTORY_CARD_BUFFERS_MIN_KB, an 8 GB card's floor
  trustno1-coder#1008 fault-page bound raised to 16,384, <4 GiB strays skipped
  trustno1-coder#1005 >65,535-group indirect dispatches enabled on NVIDIA
  trustno1-coder#801  stall-free per-draw zero-alloc and COM fast paths

trustno1-coder#953 (an upload buffer refused for want of memory is asked again once the
spare scratch chunks are freed) conflicted with the tree's own try_upload_buffer
split; ported by hand with the same semantics and the same log line.

Not taken: trustno1-coder#991, trustno1-coder#1014, trustno1-coder#722 - they conflict in pool.rs / draw.rs /
memory.rs, which trustno1-coder#784, trustno1-coder#801 and trustno1-coder#1008 already changed here.
@trustno1-coder
trustno1-coder merged commit 7ac8d7b into trustno1-coder:main Nov 28, 2026
Marker689 added a commit to Marker689/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
…rustno1-coder#801)

From trustno1-coder/VIctory-NVIDIA, 686 lines over draw.rs and
descriptor/host.rs, reported as 2.74x per draw there. Applied as it was, with
one conflict in host_signature resolved in upstream's favour (it returns a
'static reference, so no COM refcount traffic per indirect execution and none
during thread teardown); our find_any by the record's first bytes and the
address cache are untouched beside it.
Marker689 added a commit to Marker689/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
Marker689 added a commit to Marker689/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
… path, and reverted

Same profile, same build otherwise: ExecuteIndirect 30,3 µs with our first-
record lookup and address cache, 65,3 µs with trustno1-coder#801 on top; finding the
arguments' copy 4-9 ms against 27-28. Tuned without those, its changes to the
same code take the slow way. Reverted; trustno1-coder#1134 and trustno1-coder#1400 stay.
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.

6 participants