GPU: reclaim idle snapshot and texture staging pools and compact pipeline/heap metadata #3230

Open
github-bot wants to merge 1 commit from github-bot/gh-3230 into main AGit
Owner

@⁠0xKaji on GitHub · 2026-11-26 13:49 UTC · original
0xKaji:perf/reclaim-idle-pools-and-metadata → main · +134 −32 · 6 files · 1 commits · open

Summary

Reclaims idle host memory held by internal pools and metadata after loading spikes, without lowering burst ceilings or regressing active frame performance.

Changes

  • Idle-window trimming for shadow::POOL (shadow.rs, host.rs): Keeps the 512 MiB burst ceiling (POOL_BYTES), but tracks peak live demand across 128-submission windows (trim_snapshot_pool() called once per submission in Host::execute) and trims excess pooled buffers down to recent peak demand (floor POOL_SPARE_BYTES = 32 MiB).
  • Idle-window trimming for texture::BUFFERS and bounded per-thread Scratch (texture.rs): Trims BUFFERS.free down to recent 64-submission peak usage (floor 8 MiB, ceiling 64 MiB), and caps per-thread Scratch retention at 8 MiB checking capacity() <= KEEP (avoiding 32 MiB/thread permanent retention).
  • Release boot-time Heap::pending vector (descriptor.rs): Uses std::mem::take(&mut *pending) when initializing HostHeap so the boot-time Vec<u32> capacity is freed immediately.
  • Compact library::CREATED (pipeline/library.rs): Stores 16-byte BLAKE3 key prefixes ([u8; 16]) instead of heap-allocated Strings for 60k+ created pipeline keys.
  • Tighter BITMAP_POOL_CAP (memory.rs): Lowers the idle dirty-page bitmap pool cap from 64 (16 MiB) to 16 (4 MiB).

Verification

  • cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings
  • cargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings
  • cargo test -p xtask --locked (6/6 passed)
  • Wine unit tests: snapshot_pool_trims_after_idle_window, note_created_counts_total_and_distinct_keys, mark_runs_are_reused_and_joined, memory::tests::bitmap_pool_reuses_and_zeroes_across_resets + 5 non-DXC memory::tests passed (9/11 passed; the 2 DXC-dependent memory::tests fail on Wine's d3dcompiler_47 due to pre-existing E5017: Unbounded resource arrays).
  • #2153 and #472 also touch shadow::POOL (lowering the hard cap or draining on allocation failure); this PR preserves the 512 MiB burst cap and trims only after idle submission windows.
  • #2972 trims texture::Chunks, HostList::scratch, and shadow::Arena; this PR covers the complementary texture::BUFFERS, per-thread texture::Scratch, shadow::POOL, Heap::pending, library::CREATED, and memory::BITMAP_POOL_CAP.
**@⁠0xKaji** on GitHub · 2026-11-26 13:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3230) `0xKaji:perf/reclaim-idle-pools-and-metadata` → `main` · +134 −32 · 6 files · 1 commits · open ## Summary Reclaims idle host memory held by internal pools and metadata after loading spikes, without lowering burst ceilings or regressing active frame performance. ## Changes - **Idle-window trimming for `shadow::POOL` (`shadow.rs`, `host.rs`):** Keeps the 512 MiB burst ceiling (`POOL_BYTES`), but tracks peak live demand across 128-submission windows (`trim_snapshot_pool()` called once per submission in `Host::execute`) and trims excess pooled buffers down to recent peak demand (floor `POOL_SPARE_BYTES = 32 MiB`). - **Idle-window trimming for `texture::BUFFERS` and bounded per-thread `Scratch` (`texture.rs`):** Trims `BUFFERS.free` down to recent 64-submission peak usage (floor `8 MiB`, ceiling `64 MiB`), and caps per-thread `Scratch` retention at `8 MiB` checking `capacity() <= KEEP` (avoiding 32 MiB/thread permanent retention). - **Release boot-time `Heap::pending` vector (`descriptor.rs`):** Uses `std::mem::take(&mut *pending)` when initializing `HostHeap` so the boot-time `Vec<u32>` capacity is freed immediately. - **Compact `library::CREATED` (`pipeline/library.rs`):** Stores 16-byte BLAKE3 key prefixes (`[u8; 16]`) instead of heap-allocated `String`s for 60k+ created pipeline keys. - **Tighter `BITMAP_POOL_CAP` (`memory.rs`):** Lowers the idle dirty-page bitmap pool cap from `64` (16 MiB) to `16` (4 MiB). ## Verification - `cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` - `cargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings` - `cargo test -p xtask --locked` (6/6 passed) - Wine unit tests: `snapshot_pool_trims_after_idle_window`, `note_created_counts_total_and_distinct_keys`, `mark_runs_are_reused_and_joined`, `memory::tests::bitmap_pool_reuses_and_zeroes_across_resets` + 5 non-DXC `memory::tests` passed (9/11 passed; the 2 DXC-dependent `memory::tests` fail on Wine's `d3dcompiler_47` due to pre-existing `E5017: Unbounded resource arrays`). ## Partial Overlaps / Related PRs - `#2153` and `#472` also touch `shadow::POOL` (lowering the hard cap or draining on allocation failure); this PR preserves the 512 MiB burst cap and trims only after idle submission windows. - `#2972` trims `texture::Chunks`, `HostList::scratch`, and `shadow::Arena`; this PR covers the complementary `texture::BUFFERS`, per-thread `texture::Scratch`, `shadow::POOL`, `Heap::pending`, `library::CREATED`, and `memory::BITMAP_POOL_CAP`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:53:06 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 14:08 UTC · original · approved these changes

Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11/11 passed (including snapshot_pool_trims_after_idle_window).
  • cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1: 24/24 passed (including note_created_counts_total_and_distinct_keys); texture::: 2/2 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly reclaims idle snapshot/staging pools and compacts pipeline/heap metadata.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 14:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/3230#pullrequestreview-6075526287) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: 11/11 passed (including `snapshot_pool_trims_after_idle_window`). - `cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1`: 24/24 passed (including `note_created_counts_total_and_distinct_keys`); `texture::`: 2/2 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly reclaims idle snapshot/staging pools and compacts pipeline/heap metadata. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-26 14:11 UTC · original

Tested d2d85cb merged onto main 63bcca4 on an RTX 4060 8 GB (driver 621.14, i5-13600KF, Windows 11 Pro 26300). No game files. cargo test -p victory-gpu --lib --locked -- --test-threads=1 gives 231 passed and 2 failed. The new snapshot_pool_trims_after_idle_window and note_created_counts_total_and_distinct_keys pass. The 2 failures are the known capped-heap ones (#1835), the same as on main with this card.

Two things from reading it:

  1. SnapshotPool::live_bytes can only drift upward. take adds a buffer's capacity and give_back subtracts it. But snapshot segments only go back through give_back in Shadow::snapshot (merging) and when pending empties. impl Drop for Shadow returns its slice and marks, not segments. So if a copy is dropped while a snapshot is still pending, its bytes stay counted as live forever. step_window then sets peak_bytes = live_bytes, so over a long session the trim budget creeps up to POOL_BYTES and stops trimming. That's harmless, but it's the opposite of what the PR is for. One option is to count the bytes taken within each window instead of a running live total, so nothing has to be given back to keep the count right.
  2. Scratch keep limit 32 MiB → 8 MiB. A 2048×2048 RGBA8 texture needs a 16 MiB scratch, so those are no longer reused. On this CPU, a fresh 16 MiB Vec filled once costs 4.8 ms, against 0.7 ms reused, because of first-touch page faults (8 MiB: 2.1 vs 0.5 ms; 32 MiB: 7.3 vs 1.8 ms; a standalone rustc -O loop, median of 20). That's about 4 ms more per such texture on the thread preparing the frame, while streaming. Unless the 24 MiB per thread is a real problem, 16 MiB, or keeping the old 32 MiB with the len → capacity fix, may be a safer default. The capacity fix itself looks right.

AI-assisted (Claude)

**@⁠potatoe0100** on GitHub · 2026-11-26 14:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/3230#issuecomment-7194393254) Tested `d2d85cb` merged onto `main` `63bcca4` on an **RTX 4060 8 GB** (driver 621.14, i5-13600KF, Windows 11 Pro 26300). No game files. `cargo test -p victory-gpu --lib --locked -- --test-threads=1` gives 231 passed and 2 failed. The new `snapshot_pool_trims_after_idle_window` and `note_created_counts_total_and_distinct_keys` pass. The 2 failures are the known capped-heap ones (#1835), the same as on `main` with this card. Two things from reading it: 1. **`SnapshotPool::live_bytes` can only drift upward.** `take` adds a buffer's capacity and `give_back` subtracts it. But snapshot segments only go back through `give_back` in `Shadow::snapshot` (merging) and when `pending` empties. `impl Drop for Shadow` returns its slice and marks, not `segments`. So if a copy is dropped while a snapshot is still pending, its bytes stay counted as live forever. `step_window` then sets `peak_bytes = live_bytes`, so over a long session the trim budget creeps up to `POOL_BYTES` and stops trimming. That's harmless, but it's the opposite of what the PR is for. One option is to count the bytes taken within each window instead of a running live total, so nothing has to be given back to keep the count right. 2. **`Scratch` keep limit 32 MiB → 8 MiB.** A 2048×2048 RGBA8 texture needs a 16 MiB scratch, so those are no longer reused. On this CPU, a fresh 16 MiB `Vec` filled once costs **4.8 ms**, against **0.7 ms** reused, because of first-touch page faults (8 MiB: 2.1 vs 0.5 ms; 32 MiB: 7.3 vs 1.8 ms; a standalone `rustc -O` loop, median of 20). That's about 4 ms more per such texture on the thread preparing the frame, while streaming. Unless the 24 MiB per thread is a real problem, 16 MiB, or keeping the old 32 MiB with the `len` → `capacity` fix, may be a safer default. The `capacity` fix itself looks right. AI-assisted (Claude)
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3230/head:github-bot/gh-3230'
git switch 'github-bot/gh-3230'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3230'
git switch 'github-bot/gh-3230'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3230'
git switch 'github-bot/gh-3230'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3230'
git switch 'main'
git merge --squash 'github-bot/gh-3230'
git switch 'main'
git merge --ff-only 'github-bot/gh-3230'
git switch 'main'
git merge 'github-bot/gh-3230'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3230
No description provided.