Skip to content

GPU: bound idle staging, shadow snapshot, arena, and list scratch pools - #3442

Open
Luislariosss wants to merge 1 commit into
Marvisak:mainfrom
Luislariosss:feat/gpu-pool-bounds
Open

Luislariosss wants to merge 1 commit into
Marvisak:mainfrom
Luislariosss:feat/gpu-pool-bounds

Conversation

@Luislariosss

Copy link
Copy Markdown
Contributor

Summary

Bounds four idle GPU/host memory pools that previously retained over 1 GiB of Private Commit across steady-state frames:

  1. Texture staging chunks (texture.rs): lower default CHUNKS_KEPT from 16 (512 MiB of D3D12_HEAP_TYPE_UPLOAD) to 4 (128 MiB), overridable via VICTORY_TEXTURE_STAGING_CHUNKS, and lower KEPT_BYTES for oversized power-of-two staging buffers from 64 MiB to 16 MiB (still covering the 12.7 MiB movie upload path). Excess chunks are drained and dropped outside CHUNKS.lock().
  2. Shadow writeback snapshot pool (shadow.rs): lower default POOL_BYTES from 512 MiB to 128 MiB, overridable via VICTORY_SHADOW_POOL_MB.
  3. Shadow view arena (shadow.rs): release completely empty 16 MiB ArenaChunks past ARENA_SPARE = 1 (preserving existing Slice indices via Option<ArenaChunk> slots and dropping released ID3D12Resources outside ARENA.lock()).
  4. Command-list scratch chunks (host.rs): on HostList::reset(), trim grown scratch chunks past 1 MiB (keeping at least the first chunk, and dropping excess chunks outside scratch.lock()).

Validation

  • cargo test -p victory-gpu --lib -- texture:: shadow:: host::tests::list_scratch: 14/14 passed (including new env-override and excess-arena-chunk release assertions).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics): clean.
  • cargo xtask policy: 191 files ok.
  • 75-second live run comparison on the local stack (2,048 frames presented, 0 errors):
    • Steady-state Private Commit: 11,636.1 MiB → 10,700.5 MiB (−935.6 MiB)
    • Peak Private Commit: 11,636.1 MiB → 11,319.4 MiB (−316.7 MiB)
    • Working Set: 6,882.4 MiB → 6,016.8 MiB (−865.6 MiB)

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

LGTM — verified on Windows (RTX 5090):

  • cargo test -p victory-gpu --lib shadow:: (10/10), texture:: (3/3, including staging_chunks_kept_defaults_to_four_and_respects_env), and host:: (34/34 excluding the pre-existing origin/main RTX 5090 dynamic_slots_are_held_until_released failure) all passed
  • cargo clippy -p victory-gpu --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

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

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me — clean, disciplined idle-pool trimming across scratch, snapshot, arena, and texture staging pools with proper lock-free resource drops and safe env-var parsing.

Review & Verification Notes

  • crates/victory-gpu/src/host.rs:1792-1812: HostList::reset trims scratch chunks past 1 MiB (keeping at least one chunk) only when the list is idle, dropping excess chunks outside self.scratch.lock().
  • crates/victory-gpu/src/shadow.rs:120-148, 711-715, 1137-1295: VICTORY_SHADOW_POOL_MB uses saturating_mul(1 << 20) safely across 0, invalid, and huge inputs; Arena tracks live slots as Vec<Option<ArenaChunk>>, returns completely empty chunks past ARENA_SPARE to be dropped after arena() releases the lock, reuses None holes without invalidating remaining Slice indices, and updates log_views to iterate flatten().
  • crates/victory-gpu/src/texture.rs:115-205: recycle() lowers default idle retention (KEPT_BYTES = 16 MiB, DEFAULT_CHUNKS_KEPT = 4, overridable via VICTORY_TEXTURE_STAGING_CHUNKS) and drops excess chunks outside CHUNKS.lock().
  • Verified locally on 5876166d:
    • cargo xtask policy passes (191 files ok).
    • cargo clippy -p victory-gpu (--lib, --tests, and --features diagnostics --lib/--tests, -D warnings) is clean.
    • shadow::tests (9/9) and texture::tests (3/3) pass on discrete D3D12 hardware (VICTORY_D3D12_DEBUG=1, VICTORY_D3D12_GBV=1) and WARP (--features diagnostics, VICTORY_D3D12_DEBUG=1, VICTORY_D3D12_WARP=1).
    • Also verified edge-case probes on discrete D3D12: pool_bytes_for bounds (0, negative, non-numeric, usize::MAX), Arena empty-chunk eviction & None-slot reuse preserving live slice indices, and HostList::reset trimming 4 scratch chunks back down to 1 (524,288 B).

bihanikeshav added a commit to bihanikeshav/victory-fork that referenced this pull request Nov 27, 2026
…2 MiB

The pool of host snapshot buffers kept for reuse between submissions held
up to 512 MiB past its largest buffer. On a 16 GB machine that is idle
commit the title could use. The cap is now 128 MiB by default and can be
set in MiB with VICTORY_SHADOW_POOL_MB (the switch name of the source PR).
The largest buffer is still always kept, as before.

Only the snapshot pool part of the source PR is ported: its staging chunk,
view arena and list scratch changes do not map onto our code, which manages
those pools differently.

Source: Marvisak/VIctory pull request #3442 (GPL-3.0)
Marvisak/VIctory#3442

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@reallyvibe

Copy link
Copy Markdown

I benchmarked the snapshot pool at this head (5876166d) against main (63bcca43), #3230 and #3384 in a CPU-only harness. Pool code is copied verbatim from each head; the caller (Shadow::writing's merge and the copy-back return) is ported once from main, as it is the same at all four heads apart from #3384's POOL. call syntax. The workload is synthetic: no game files, no GPU. Claim: #1633 (comment)

In this synthetic model the 128 MiB default regresses several cases, and the boundary is not one snapshot size. Real world submissions weren't measured, so this is a regression case worth checking, not a gameplay finding.

Steady state, 460 world submissions per run, medians over 5 seeds, p50 host time per submission. "Requested" sums every take in one submission, including each growth-chain piece. Main misses 0.05–0.13% in every row.

world snapshot requested / submission main (512 MiB) this PR (128 MiB)
64 MiB in 4 growth steps 164 MiB 12.5 ms 1.1% misses (seeds 0.1–7.5%), 12.4 ms; keeps 128 MiB
96 MiB in 4 steps 244 MiB 18.2 ms 63%, 66.5 ms; keeps 96 MiB
128 MiB in 4 steps 324 MiB 24.3 ms 63%, 88.7 ms; keeps 128 MiB
174 MiB, one piece 178 MiB 13.3 ms 100%, 79.3 ms; keeps 0
174 MiB in 4 steps 439 MiB 32.6 ms 100%, 197.9 ms; keeps 0
256 MiB in 4 steps 644 MiB 46.7 ms 100%, 286.2 ms; keeps 0

Per seed, p50 is 2.5–3.8× main's at 96 MiB in 4 steps, and 4.7–6.4× from 174 MiB up.

  • Why: this PR keeps main's return rule. The pool is sorted largest first and kept while the running total fits. The first buffer that crosses the cap is dropped, with every smaller one after it, so returning a buffer above 128 MiB empties the pool at that moment. In those oversized-buffer cases (174 and 256 MiB) the heap is returned last, so the pool ends each submission empty.
  • No single threshold fits: 64 MiB in 4 steps requests 164 MiB and mostly hits; 96 MiB in 4 steps never holds a buffer above 96 MiB and misses 63%.
  • Mid-size shadows: with no large snapshot but up to three 8–64 MiB shadows per submission, it misses 63% (main 0.2%).
  • Small buffers: after a 128 MiB snapshot built in 4 growth steps, 620 of the 640 small takes in the next 20 submissions are fresh allocations in every seed (main: 0).
  • Memory: peak private commit is −11.1% to +3.7% against main (20 steady cases); the saving is at idle, 5–113 MiB pooled against 250–467 MiB. Your live run (−935.6 MiB steady, −316.7 MiB peak) changes four pools and reports no frame times, so it isn't directly comparable.

I'm not suggesting a default; that needs real per-submission sizes. The idle trims I measured (#3230 and variants) each have a measured cost too.

Limitations: the submission mix is a model, not a capture; marked writes (which skip snapshots) aren't modelled; snapshot lifetimes are the harness's (returned at copy-back), not upstream's (returned when the shadow's last pending range completes); 174 MiB is the earlier-discussed heap size, not a measured snapshot; page faults are process-wide, so none are attributed to the pool; one Windows machine at 79–95% memory load (at run end), single-threaded, 5 seeds per case, no significance test.

With real per-submission snapshot sizes I can rerun.

Harness, pins, scripts, raw results and reproduction steps: 1,240 original runs plus 631 targeted follow-up runs (36 superseded runs kept, labelled). Byte-for-byte snapshot verification: 6,288 submissions, then 96,096 snapshots, 0 failures. Corrections to my earlier write-ups: CORRECTIONS.md.

https://github.com/farhankhan8571811-star/victory-snapshot-pool-bench

AI-assisted (Claude Code).

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.

4 participants