GPU: the snapshot pool's limit can be raised with VICTORY_SNAPSHOT_POOL_MB #228

Open
murillojndem wants to merge 1 commit from upstream-pr/228 into main
murillojndem commented 2026-11-29 16:02:10 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-29T16:02:10Z.


The snapshot pool (SnapshotPool in shadow.rs) keeps at most 512 MiB of buffer capacity and 512 buffers. Each snapshot of a window outside buffers is a buffer of the whole 4 MiB window. When a dispatch's raw-address writes cannot be bounded, every visible window is declared written (memory::Writes::All), so with ray tracing on, one frame's snapshots need far more than the pool keeps.

In a run on an RX 7900 XT with the ray-tracing builder running, the log shows:

  • about 3.9 GB of snapshots a frame, in some 3,800 ranges of windows;
  • "snapshot buffers kept: 108 reserving 510 MB", so the pool sits at its limit;
  • 1.2 million page faults a frame for the process.

Most snapshot buffers are allocated anew each frame and handed back to the system after the copy-back, so their pages are faulted in again every frame.

Change:

  • VICTORY_SNAPSHOT_POOL_MB sets the most bytes of buffer capacity the pool keeps at one time. The most buffers is one per MiB, at least 512.
  • Unset, the limits are 512 MiB and 512 buffers, as before. 0 keeps no buffer.
  • When the variable is set, the limits in effect are logged once; a value that is not a number logs a warning and keeps the default.
  • The limits move from constants in put to fields of the pool, so tests can set them.

Measurement, synthetic and not from a title: a local benchmark took 256 buffers of 4 MiB a frame through the pool and copied 2 MiB into each, which is the run's proportions scaled down (512 MiB a frame, a pool an eighth of that). The benchmark is not part of this change.

pool page faults a frame time a frame
an eighth of a frame (as today) about 117,000, every frame about 98 ms
holds the frame 133,675 in the first frame, then 0 98 ms, then about 30 ms

The limit counts capacity held at one time, and each window's snapshot is a buffer of the whole 4 MiB, so the value that keeps a frame's snapshots is about 4 MiB per window alive. At the end of that run 1,896 windows were alive, which is about 7.6 GB. The default is left as it was; the variable is for runs that can spend the memory.

Tests:

  • New: the_pool_limits_come_from_megabytes_with_a_buffer_per_megabyte, a_larger_pool_keeps_every_window_of_a_frame, the_count_limit_holds_however_many_bytes_are_free.
  • victory-gpu --lib: 222 passed, 0 failed, 4 ignored on WARP and on the RX 7900 XT (main: 219, 0, 4).
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings is clean with and without --all-features, and cargo xtask policy passes.

Limits:

  • The frame-time effect in a title is not measured here.
  • The pool never shrinks, so what it keeps stays committed until the process ends. With less free memory the runtime lets windows and texture staging go sooner (after 5 s under 4 GiB free, 2 s under 2 GiB, host.rs), which a large setting can bring about.
  • With windows smaller than 1 MiB (VICTORY_WINDOW_KB) the count limit, one buffer per MiB, binds before the byte limit.
  • No test reads the variable itself; the tests cover the parsing and the pool's limits.
  • It merges cleanly with the open PRs that touch shadow.rs; #20, #32 and #43 conflict with main already, without this change.
  • The copy itself remains: every declared range is still snapshotted. Declaring fewer ranges is separate work.

Claude (Anthropic) wrote the change, the tests and the benchmark, and ran them on WARP and the RX 7900 XT under the adaptive GPU rules; an independent review checked the pool's paths.

Generated with Claude Code

<!-- greyfinch-sync:DexNom/VIctory:issue:5552480868 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/228). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-29T16:02:10Z. --- The snapshot pool (`SnapshotPool` in `shadow.rs`) keeps at most 512 MiB of buffer capacity and 512 buffers. Each snapshot of a window outside buffers is a buffer of the whole 4 MiB window. When a dispatch's raw-address writes cannot be bounded, every visible window is declared written (`memory::Writes::All`), so with ray tracing on, one frame's snapshots need far more than the pool keeps. In a run on an RX 7900 XT with the ray-tracing builder running, the log shows: - about 3.9 GB of snapshots a frame, in some 3,800 ranges of windows; - "snapshot buffers kept: 108 reserving 510 MB", so the pool sits at its limit; - 1.2 million page faults a frame for the process. Most snapshot buffers are allocated anew each frame and handed back to the system after the copy-back, so their pages are faulted in again every frame. Change: - `VICTORY_SNAPSHOT_POOL_MB` sets the most bytes of buffer capacity the pool keeps at one time. The most buffers is one per MiB, at least 512. - Unset, the limits are 512 MiB and 512 buffers, as before. 0 keeps no buffer. - When the variable is set, the limits in effect are logged once; a value that is not a number logs a warning and keeps the default. - The limits move from constants in `put` to fields of the pool, so tests can set them. Measurement, synthetic and not from a title: a local benchmark took 256 buffers of 4 MiB a frame through the pool and copied 2 MiB into each, which is the run's proportions scaled down (512 MiB a frame, a pool an eighth of that). The benchmark is not part of this change. | pool | page faults a frame | time a frame | |---|---|---| | an eighth of a frame (as today) | about 117,000, every frame | about 98 ms | | holds the frame | 133,675 in the first frame, then 0 | 98 ms, then about 30 ms | The limit counts capacity held at one time, and each window's snapshot is a buffer of the whole 4 MiB, so the value that keeps a frame's snapshots is about 4 MiB per window alive. At the end of that run 1,896 windows were alive, which is about 7.6 GB. The default is left as it was; the variable is for runs that can spend the memory. Tests: - New: `the_pool_limits_come_from_megabytes_with_a_buffer_per_megabyte`, `a_larger_pool_keeps_every_window_of_a_frame`, `the_count_limit_holds_however_many_bytes_are_free`. - `victory-gpu --lib`: 222 passed, 0 failed, 4 ignored on WARP and on the RX 7900 XT (main: 219, 0, 4). - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` is clean with and without `--all-features`, and `cargo xtask policy` passes. Limits: - The frame-time effect in a title is not measured here. - The pool never shrinks, so what it keeps stays committed until the process ends. With less free memory the runtime lets windows and texture staging go sooner (after 5 s under 4 GiB free, 2 s under 2 GiB, `host.rs`), which a large setting can bring about. - With windows smaller than 1 MiB (`VICTORY_WINDOW_KB`) the count limit, one buffer per MiB, binds before the byte limit. - No test reads the variable itself; the tests cover the parsing and the pool's limits. - It merges cleanly with the open PRs that touch `shadow.rs`; #20, #32 and #43 conflict with main already, without this change. - The copy itself remains: every declared range is still snapshotted. Declaring fewer ranges is separate work. Claude (Anthropic) wrote the change, the tests and the benchmark, and ran them on WARP and the RX 7900 XT under the adaptive GPU rules; an independent review checked the pool's paths. Generated with [Claude Code](https://claude.com/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/228:upstream-pr/228'
git switch 'upstream-pr/228'

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/228'
git switch 'upstream-pr/228'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/228'
git switch 'upstream-pr/228'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/228'
git switch 'main'
git merge --squash 'upstream-pr/228'
git switch 'main'
git merge --ff-only 'upstream-pr/228'
git switch 'main'
git merge 'upstream-pr/228'
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
DexNom/VIctory!228
No description provided.