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

Open
Luislariosss wants to merge 1 commit from upstream-pr/3442 into main
Luislariosss commented 2026-11-27 02:23:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-27T02:23:07Z.


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)
<!-- greyfinch-sync:Marvisak/VIctory:issue:5520090146 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3442). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-27T02:23:07Z. --- ### 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 `ArenaChunk`s past `ARENA_SPARE = 1` (preserving existing `Slice` indices via `Option<ArenaChunk>` slots and dropping released `ID3D12Resource`s 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 commented 2026-11-27 02:26:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T02:26:57Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6082687714 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3442#pullrequestreview-6082687714). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T02:26:57Z. **Review:** APPROVED --- 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 commented 2026-11-27 02:40:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:40:12Z.

Review: APPROVED


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).
<!-- greyfinch-sync:Marvisak/VIctory:review:6082778484 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3442#pullrequestreview-6082778484). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T02:40:12Z. **Review:** APPROVED --- 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).
farhankhan8571811-star commented 2026-11-28 10:12:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by farhankhan8571811-star on 2026-11-28T10:12:34Z.


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: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7226578104

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7237745324 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3442#issuecomment-7237745324). Originally posted by [farhankhan8571811-star](https://github.com/farhankhan8571811-star) on 2026-11-28T10:12:34Z. --- 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: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7226578104 **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).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3442:upstream-pr/3442'
git switch 'upstream-pr/3442'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3442'
git switch 'upstream-pr/3442'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3442'
git switch 'upstream-pr/3442'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3442'
git switch 'main'
git merge --squash 'upstream-pr/3442'
git switch 'main'
git merge --ff-only 'upstream-pr/3442'
git switch 'main'
git merge 'upstream-pr/3442'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3442
No description provided.