Reclaim expired GPU detile buffers under VRAM pressure #2240

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

@⁠LucaruluDev on GitHub · 2026-11-29 10:55 UTC · original
LucaruluDev:research/vram-detile-idle-age → main · +170 −4 · 2 files · 1 commits · open

Refs #1620

What it changes

The GPU detile pool can hold up to 256 MiB of idle buffers when local VRAM is at its DXGI budget and host memory is under no pressure. This update keeps sh3nw4ld's full-pool host-memory trim from #2633 and limits the new VRAM path to returned buffers that have been idle for at least two seconds.

After the other pools have had a chance to release memory, tyr0nsur's DXGI recheck (from 7daea79aa12d7d9f39a211ab76abe0b75328a8bc, an earlier revision of this PR) runs outside the pool lock if an expired buffer is eligible. A valid reading below budget cancels the trim. An unavailable or zero initial budget skips reclamation. If the recheck fails or reports a zero budget, the valid initial reading still permits trimming expired buffers. Active buffers stay with their staging objects, and recently returned buffers remain available for exact-size reuse. VICTORY_GPU_DETILE is off by default.

Upstream rewrote main after the previous revision of this branch. The branch is now a single commit, 683d8d70342a4253b916a0c5d497911d69152031, directly on main at 5fabb46eaf6ed8771321787f8871051abde69b9b, so it no longer carries the pre-rewrite commits. The diff against main is unchanged: host.rs and texture.rs, +170/−4. tyr0nsur keeps co-authorship of the commit.

How it was tested

  • GPU and profile: Windows 11, RTX 5070, Rust 1.98.1. Offscreen D3D12 and unit tests. No game profile, resolution, DLSS, frame generation or ray tracing settings were used.
  • Before: An offscreen D3D12 harness on the pre-rewrite base e1251c3199465565147711887351d80359162bb0 retained all 256 MiB in both the mixed-age and fully idle scenarios under a synthetic local VRAM budget.
  • After: In the same harness, the reclamation code in this commit reclaimed 224 MiB in the mixed-age scenario and kept both recent 16 MiB buffers, with zero recreations. It reclaimed the full 256 MiB in the fully idle scenario. When sibling pools lowered DXGI usage below the synthetic budget, the recheck kept the detile spares. Active GPU copy checks reported zero mismatches. That measurement predates the pool-limit test below, which is the only later addition and is test-only. These were synthetic pressure scenarios using native D3D12 resources and DXGI readings. Gameplay and FPS were not tested.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A.
  • cargo test passed for the crates it touches: focused victory-gpu tests passed. The full crate and workspace suites were not run.

Tested locally on 683d8d70342a4253b916a0c5d497911d69152031 (tree b9af163bc7fb85cdc94afcf5ce5729a3637639aa) against main at 5fabb46eaf6ed8771321787f8871051abde69b9b:

Command Result
cargo check --locked -j 4 -p victory-gpu --all-targets Passed.
cargo test --locked -j 4 -p victory-gpu --lib texture:: -- --test-threads=2 24 passed, 0 failed, 4 benchmark tests ignored.
cargo test --locked -j 4 -p victory-gpu --lib texture::spare_linear_tests -- --nocapture --test-threads=1 2 passed. The D3D12 subprocess verified 16 retained buffers, 256 MiB accounting and rejection of the extra buffer.
cargo clippy --workspace --all-targets --locked -j 4 -- -D warnings Exit 101 with the same five findings as main (below), none in files this PR touches.

The release (cargo build --release --locked -p victory) and diagnostics (cargo build --locked --profile diag -p victory --features diagnostics) builds passed on a local integration with the same tree hash, b9af163b.

Clippy fails on main with the same five findings introduced by #4635: two too_many_arguments in host/font.rs, one manual_is_multiple_of in host/menu.rs, and two collapsible_if in host/panel.rs. This PR touches none of those files. #4680 and #4708 both address all five. Current main check · #4680 · #4708

Known coverage gap: trim_idle_spare_linear has no unit test of its own. the_spare_detile_pool_trims_whole (from #2633) covers the full trim under host pressure, and staging_drop_rejects_spares_past_the_pool_limit covers the 256 MiB cap. Neither exercises the three behaviours specific to this PR: rechecking DXGI only when a trim would happen, expiring only cold spares while at budget, and keeping warm spares under sustained pressure. Those were checked only in the offscreen harness above.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2633 and #3503 cover host-pressure trimming, #2338 changes buffer leasing, #4138 moves releases to a background reaper, #3858 and #4306 change sweep scheduling, and #2038 covers the texture pools. None implements the same age-based trim of detile spares under VRAM-only pressure.
  • Merge-order conflict with #2338 and #4138, in both directions. This PR turns SpareLinear into SpareLinear { buffer, returned_ms }. #2338 builds the tuple form (SpareLinear(buffer) in give_linear) and #4138 reads it (.map(|s| s.0) in the reaper). Whichever of the three merges second will not compile until it adapts to the other's form. If this PR merges first, #2338 and #4138 need a small adaptation to the struct. If either merges first, this PR will be updated to match.

AI-assisted implementation and validation using OpenAI Codex and Claude Code. The reclamation policy was independently reviewed with Claude Code.

**@⁠LucaruluDev** on GitHub · 2026-11-29 10:55 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2240) `LucaruluDev:research/vram-detile-idle-age` → `main` · +170 −4 · 2 files · 1 commits · open Refs #1620 ## What it changes The GPU detile pool can hold up to 256 MiB of idle buffers when local VRAM is at its DXGI budget and host memory is under no pressure. This update keeps sh3nw4ld's full-pool host-memory trim from #2633 and limits the new VRAM path to returned buffers that have been idle for at least two seconds. After the other pools have had a chance to release memory, tyr0nsur's DXGI recheck (from `7daea79aa12d7d9f39a211ab76abe0b75328a8bc`, an earlier revision of this PR) runs outside the pool lock if an expired buffer is eligible. A valid reading below budget cancels the trim. An unavailable or zero initial budget skips reclamation. If the recheck fails or reports a zero budget, the valid initial reading still permits trimming expired buffers. Active buffers stay with their staging objects, and recently returned buffers remain available for exact-size reuse. `VICTORY_GPU_DETILE` is off by default. Upstream rewrote `main` after the previous revision of this branch. The branch is now a single commit, `683d8d70342a4253b916a0c5d497911d69152031`, directly on `main` at `5fabb46eaf6ed8771321787f8871051abde69b9b`, so it no longer carries the pre-rewrite commits. The diff against `main` is unchanged: `host.rs` and `texture.rs`, +170/−4. tyr0nsur keeps co-authorship of the commit. ## How it was tested - GPU and profile: Windows 11, RTX 5070, Rust 1.98.1. Offscreen D3D12 and unit tests. No game profile, resolution, DLSS, frame generation or ray tracing settings were used. - Before: An offscreen D3D12 harness on the pre-rewrite base `e1251c3199465565147711887351d80359162bb0` retained all 256 MiB in both the mixed-age and fully idle scenarios under a synthetic local VRAM budget. - After: In the same harness, the reclamation code in this commit reclaimed 224 MiB in the mixed-age scenario and kept both recent 16 MiB buffers, with zero recreations. It reclaimed the full 256 MiB in the fully idle scenario. When sibling pools lowered DXGI usage below the synthetic budget, the recheck kept the detile spares. Active GPU copy checks reported zero mismatches. That measurement predates the pool-limit test below, which is the only later addition and is test-only. These were synthetic pressure scenarios using native D3D12 resources and DXGI readings. Gameplay and FPS were not tested. - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A. - `cargo test` passed for the crates it touches: focused `victory-gpu` tests passed. The full crate and workspace suites were not run. Tested locally on `683d8d70342a4253b916a0c5d497911d69152031` (tree `b9af163bc7fb85cdc94afcf5ce5729a3637639aa`) against `main` at `5fabb46eaf6ed8771321787f8871051abde69b9b`: | Command | Result | | --- | --- | | `cargo check --locked -j 4 -p victory-gpu --all-targets` | Passed. | | `cargo test --locked -j 4 -p victory-gpu --lib texture:: -- --test-threads=2` | 24 passed, 0 failed, 4 benchmark tests ignored. | | `cargo test --locked -j 4 -p victory-gpu --lib texture::spare_linear_tests -- --nocapture --test-threads=1` | 2 passed. The D3D12 subprocess verified 16 retained buffers, 256 MiB accounting and rejection of the extra buffer. | | `cargo clippy --workspace --all-targets --locked -j 4 -- -D warnings` | Exit 101 with the same five findings as `main` (below), none in files this PR touches. | The release (`cargo build --release --locked -p victory`) and diagnostics (`cargo build --locked --profile diag -p victory --features diagnostics`) builds passed on a local integration with the same tree hash, `b9af163b`. Clippy fails on `main` with the same five findings introduced by #4635: two `too_many_arguments` in `host/font.rs`, one `manual_is_multiple_of` in `host/menu.rs`, and two `collapsible_if` in `host/panel.rs`. This PR touches none of those files. #4680 and #4708 both address all five. [Current main check](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46563306780/job/142355972539) · [#4680](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/4680) · [#4708](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/pulls/4708) Known coverage gap: `trim_idle_spare_linear` has no unit test of its own. `the_spare_detile_pool_trims_whole` (from #2633) covers the full trim under host pressure, and `staging_drop_rejects_spares_past_the_pool_limit` covers the 256 MiB cap. Neither exercises the three behaviours specific to this PR: rechecking DXGI only when a trim would happen, expiring only cold spares while at budget, and keeping warm spares under sustained pressure. Those were checked only in the offscreen harness above. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2633 and #3503 cover host-pressure trimming, #2338 changes buffer leasing, #4138 moves releases to a background reaper, #3858 and #4306 change sweep scheduling, and #2038 covers the texture pools. None implements the same age-based trim of detile spares under VRAM-only pressure. - Merge-order conflict with #2338 and #4138, in both directions. This PR turns `SpareLinear` into `SpareLinear { buffer, returned_ms }`. #2338 builds the tuple form (`SpareLinear(buffer)` in `give_linear`) and #4138 reads it (`.map(|s| s.0)` in the reaper). Whichever of the three merges second will not compile until it adapts to the other's form. If this PR merges first, #2338 and #4138 need a small adaptation to the struct. If either merges first, this PR will be updated to match. AI-assisted implementation and validation using OpenAI Codex and Claude Code. The reclamation policy was independently reviewed with Claude Code.
Reclaim only spare device-local buffers and pause pooling while the existing budget sample is full. Leave live staging buffers and the normal cache ceiling unchanged.

Co-authored-by: Codex <[email protected]>
Reclaim only returned GPU detile buffers that have been idle for two seconds, retaining exact-size reuse for hot buffers.

Co-authored-by: Codex <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 11:00:49 +00:00
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 07:13 UTC · original

I reproduced a same-tick ordering case on 24426e6. The sweep samples DXGI, calls pool::room(video), then passes the same sample to linear_spare_room. If the first reclaim already takes local usage under budget, the second can still discard reusable detile buffers.

On a Windows RTX 4060, I reproduced this in three fresh processes with real resident D3D12 allocations and a simulated trigger budget. Dropping two texture heaps took DXGI local usage from 188.45 to 60.45 MiB, below the 124.45 MiB trigger. With the old sample the detile pool still dropped both 16 MiB spares. With a fresh sample it retained both, and DXGI stayed at 60.45 MiB.

Cherry-pickable fix. It rechecks DXGI outside the pool lock only when the original sample would trim a cold spare. Empty and warm-only pools get no additional query. The three focused tests and the staged asset-policy check passed. Claude Opus 5.5 reviewed the call order.

**@⁠tyr0nsur** on GitHub · 2026-11-30 07:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2240#issuecomment-7271488197) I reproduced a same-tick ordering case on `24426e6`. The sweep samples DXGI, calls `pool::room(video)`, then passes the same sample to `linear_spare_room`. If the first reclaim already takes local usage under budget, the second can still discard reusable detile buffers. On a Windows RTX 4060, I reproduced this in three fresh processes with real resident D3D12 allocations and a simulated trigger budget. Dropping two texture heaps took DXGI local usage from 188.45 to 60.45 MiB, below the 124.45 MiB trigger. With the old sample the detile pool still dropped both 16 MiB spares. With a fresh sample it retained both, and DXGI stayed at 60.45 MiB. [Cherry-pickable fix](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/7daea79aa12d7d9f39a211ab76abe0b75328a8bc). It rechecks DXGI outside the pool lock only when the original sample would trim a cold spare. Empty and warm-only pools get no additional query. The three focused tests and the staged asset-policy check passed. Claude Opus 5.5 reviewed the call order.
The texture pool can free enough local memory after the sweep samples DXGI. If that sample would retire a cold detile buffer, query again outside the pool lock. Keep using the original budget sample if the query cannot provide a valid budget.

Cover empty and warm pools, an under-budget recheck, and the retry without a valid budget.
Author
Owner

@⁠LucaruluDev on GitHub · 2026-11-30 08:38 UTC · original

Thanks, @⁠tyr0nsur, for reproducing the same-tick reclaim and providing 7daea79. I kept your exact commit and authorship in the local candidate.

I reproduced the ordering issue independently on an RTX 5070 in five paired offscreen D3D12 runs. Releasing two resident texture heaps reduced local usage from 205.66 to 77.66 MiB against a simulated 141.66 MiB limit. The published code still discarded both 16 MiB spares. Your commit retained both in all five runs and still retired them when the fresh sample showed pressure. Empty and warm pools made no extra query. Each run also verified an active 16 MiB GPU copy byte for byte.

The independent policy tests covered failed or invalid queries and a concurrent checkout and return with the mutex released during the refresh. The conditional local and non-local DXGI query pair measured 0.7–1.1 µs in this fixture. Release and diagnostics builds both passed on a local merge with 41adb551. The pressure threshold and buffer age were simulated.

**@⁠LucaruluDev** on GitHub · 2026-11-30 08:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2240#issuecomment-7273161952) Thanks, @⁠tyr0nsur, for reproducing the same-tick reclaim and providing `7daea79`. I kept your exact commit and authorship in the local candidate. I reproduced the ordering issue independently on an RTX 5070 in five paired offscreen D3D12 runs. Releasing two resident texture heaps reduced local usage from 205.66 to 77.66 MiB against a simulated 141.66 MiB limit. The published code still discarded both 16 MiB spares. Your commit retained both in all five runs and still retired them when the fresh sample showed pressure. Empty and warm pools made no extra query. Each run also verified an active 16 MiB GPU copy byte for byte. The independent policy tests covered failed or invalid queries and a concurrent checkout and return with the mutex released during the refresh. The conditional local and non-local DXGI query pair measured 0.7–1.1 µs in this fixture. Release and diagnostics builds both passed on a local merge with `41adb551`. The pressure threshold and buffer age were simulated.
Narrow #2240 to the case #2633 does not cover. Keep sh3nw4ld's
full-pool host-pressure trim from #2633 (308fe0ff) unchanged. After the
other pools reclaim, and only when that host-pressure path was not
taken, retire linear spares unused for at least 2 s while DXGI reports
local usage at or over budget. Spares reused within the window stay
pooled. The existing vector buckets, exact-size reuse and 256 MiB cap
are kept.

The idle window and the DXGI recheck outside the pool lock come from
tyr0nsur's 7daea79. A missing or zero first sample keeps the pool as
main does; a failed recheck still trims the expired spares.

This replaces the earlier LinearSpares module, which no longer
compiles against main's trim_spare_linear after the merge.

Co-authored-by: tyr0nsur <[email protected]>
Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Exercise Staging::drop at the 256 MiB limit in an isolated test
process. Verify that returning an additional buffer keeps the same
resources and byte accounting.

Co-authored-by: OpenAI Codex <215057067+openai-codex[bot]@users.noreply.github.com>
github-bot force-pushed github-bot/gh-2240 from ba44da5942 to 683d8d7034 2026-12-01 13:54:50 +00:00 Compare
github-bot changed title from Reclaim idle GPU detile buffers under VRAM pressure to Reclaim expired GPU detile buffers under VRAM pressure 2026-12-01 14:00:32 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2240'
git switch 'github-bot/gh-2240'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2240'
git switch 'github-bot/gh-2240'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2240'
git switch 'main'
git merge --squash 'github-bot/gh-2240'
git switch 'main'
git merge --ff-only 'github-bot/gh-2240'
git switch 'main'
git merge 'github-bot/gh-2240'
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/trustno1-coder--VIctory-NVIDIA!2240
No description provided.