GPU: let go of the idle snapshot pool, and shrink it under memory pressure #41

Open
welisonzika14-jpg wants to merge 1 commit from upstream-pr/41 into main
welisonzika14-jpg commented 2026-11-26 18:03:10 +00:00 (Migrated from git.gtahub.st)

Imported from TaynanGT/Vice-Tay-v2. Originally posted by welisonzika14-jpg on 2026-11-26T18:03:10Z.


@⁠welisonzika14-jpg on GitHub · 2026-11-26 17:58 UTC · original
welisonzika14-jpg:fix/shadow-pool-idle → main · +156 −0 · 1 files · 1 commits · open

Problem

shadow::POOL keeps snapshot buffers for reuse, up to 512 MiB (give_back, KEPT). Only give_back ever trims it, and only when another buffer comes back. So once snapshots stop, the last 512 MiB stays for the rest of the run, even when the host is short of memory. The largest buffer is always kept (kept > 0), so a single snapshot larger than 512 MiB stays too.

Change

shadow::let_go_idle already runs once a second from host::sweep. It now first calls let_go_idle_snapshots, which does this:

  • When the pool is idle for host::ram_idle_ms and 4 frames (the same rule as the loose windows), it frees all of it.
  • While residency::pressured() holds, it keeps only the smallest buffers, up to 32 MiB (POOL_PRESSURED_KEPT), and frees the rest, largest first.
  • Otherwise it does nothing, and the behaviour is the same as before.

pooled and give_back record the last use in POOL_USED, as a host::moment(). The freeing happens outside the lock, as give_back already does. The next snapshot after a trim is fresh memory, the same as every snapshot past the pool was before. With plenty of free RAM, ram_idle_ms is 5 minutes, so normal play keeps the pool. The FPS cost should only show after an idle stretch or under pressure. I did not measure FPS in game.

Tests

New shadow::pool_tests:

  • trimming_keeps_the_smallest_up_to_the_limit
  • trimming_to_nothing_empties_the_pool
  • a_buffer_past_the_limit_goes_even_alone
  • an_idle_pool_goes_and_a_pressed_one_shrinks
  • pool_memory_load (#[ignore], run alone, because the pool is global):
    cargo test -p victory-gpu --lib shadow::pool_tests::pool_memory_load -- --ignored --nocapture --test-threads=1

Load test on Windows 11 with an RTX 5070, in a debug build. It runs 256 snapshots of 1 to 32 MiB:

State Pool Private bytes over start
Full (main behaviour, stays forever) 520,192 KiB 521,336 KiB
Under pressure (new) ≤ 32 MiB 25,684 KiB
Idle (new) 0 12 KiB

Results:

  • cargo test -p victory-gpu --lib: 401 passed, 0 failed, 37 ignored.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: clean.

Related: HumanlyDev/HUMAN#7 also bounds this pool, in a different way. This PR is written separately and is smaller. It touches only shadow.rs.

Written with AI help (Claude/Kiro).

<!-- greyfinch-sync:TaynanGT/Vice-Tay-v2:issue:15329 --> Imported from [TaynanGT/Vice-Tay-v2](https://git.gtahub.st/github/TaynanGT--Vice-Tay-v2/pulls/41). Originally posted by [welisonzika14-jpg](https://github.com/welisonzika14-jpg) on 2026-11-26T18:03:10Z. --- **@⁠welisonzika14-jpg** on GitHub · 2026-11-26 17:58 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/41) `welisonzika14-jpg:fix/shadow-pool-idle` → `main` · +156 −0 · 1 files · 1 commits · open ## Problem `shadow::POOL` keeps snapshot buffers for reuse, up to 512 MiB (`give_back`, `KEPT`). Only `give_back` ever trims it, and only when another buffer comes back. So once snapshots stop, the last 512 MiB stays for the rest of the run, even when the host is short of memory. The largest buffer is always kept (`kept > 0`), so a single snapshot larger than 512 MiB stays too. ## Change `shadow::let_go_idle` already runs once a second from `host::sweep`. It now first calls `let_go_idle_snapshots`, which does this: - When the pool is idle for `host::ram_idle_ms` and 4 frames (the same rule as the loose windows), it frees all of it. - While `residency::pressured()` holds, it keeps only the smallest buffers, up to 32 MiB (`POOL_PRESSURED_KEPT`), and frees the rest, largest first. - Otherwise it does nothing, and the behaviour is the same as before. `pooled` and `give_back` record the last use in `POOL_USED`, as a `host::moment()`. The freeing happens outside the lock, as `give_back` already does. The next snapshot after a trim is fresh memory, the same as every snapshot past the pool was before. With plenty of free RAM, `ram_idle_ms` is 5 minutes, so normal play keeps the pool. The FPS cost should only show after an idle stretch or under pressure. I did not measure FPS in game. ## Tests New `shadow::pool_tests`: - `trimming_keeps_the_smallest_up_to_the_limit` - `trimming_to_nothing_empties_the_pool` - `a_buffer_past_the_limit_goes_even_alone` - `an_idle_pool_goes_and_a_pressed_one_shrinks` - `pool_memory_load` (`#[ignore]`, run alone, because the pool is global): `cargo test -p victory-gpu --lib shadow::pool_tests::pool_memory_load -- --ignored --nocapture --test-threads=1` Load test on Windows 11 with an RTX 5070, in a debug build. It runs 256 snapshots of 1 to 32 MiB: | State | Pool | Private bytes over start | |---|---:|---:| | Full (main behaviour, stays forever) | 520,192 KiB | 521,336 KiB | | Under pressure (new) | ≤ 32 MiB | 25,684 KiB | | Idle (new) | 0 | 12 KiB | Results: - `cargo test -p victory-gpu --lib`: 401 passed, 0 failed, 37 ignored. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings`: clean. Related: [HumanlyDev/HUMAN#7](https://github.com/HumanlyDev/HUMAN/pull/7) also bounds this pool, in a different way. This PR is written separately and is smaller. It touches only `shadow.rs`. Written with AI help (Claude/Kiro).
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/41:upstream-pr/41'
git switch 'upstream-pr/41'

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/41'
git switch 'upstream-pr/41'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/41'
git switch 'upstream-pr/41'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/41'
git switch 'main'
git merge --squash 'upstream-pr/41'
git switch 'main'
git merge --ff-only 'upstream-pr/41'
git switch 'main'
git merge 'upstream-pr/41'
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
TaynanGT/Vice-Tay-v2!41
No description provided.