Reclaim expired GPU detile buffers under VRAM pressure #2240
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2240"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by LucaruluDev on 2026-11-29T10:55:45Z.
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_DETILEis off by default.Upstream rewrote
mainafter the previous revision of this branch. The branch is now a single commit,683d8d70342a4253b916a0c5d497911d69152031, directly onmainat5fabb46eaf6ed8771321787f8871051abde69b9b, so it no longer carries the pre-rewrite commits. The diff againstmainis unchanged:host.rsandtexture.rs, +170/−4. tyr0nsur keeps co-authorship of the commit.How it was tested
e1251c3199465565147711887351d80359162bb0retained all 256 MiB in both the mixed-age and fully idle scenarios under a synthetic local VRAM budget.cargo testpassed for the crates it touches: focusedvictory-gputests passed. The full crate and workspace suites were not run.Tested locally on
683d8d70342a4253b916a0c5d497911d69152031(treeb9af163bc7fb85cdc94afcf5ce5729a3637639aa) againstmainat5fabb46eaf6ed8771321787f8871051abde69b9b:cargo check --locked -j 4 -p victory-gpu --all-targetscargo test --locked -j 4 -p victory-gpu --lib texture:: -- --test-threads=2cargo test --locked -j 4 -p victory-gpu --lib texture::spare_linear_tests -- --nocapture --test-threads=1cargo clippy --workspace --all-targets --locked -j 4 -- -D warningsmain(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
mainwith the same five findings introduced by #4634: twotoo_many_argumentsinhost/font.rs, onemanual_is_multiple_ofinhost/menu.rs, and twocollapsible_ifinhost/panel.rs. This PR touches none of those files. #4679 and #4707 both address all five. Current main check · #4679 · #4707Known coverage gap:
trim_idle_spare_linearhas no unit test of its own.the_spare_detile_pool_trims_whole(from #2633) covers the full trim under host pressure, andstaging_drop_rejects_spares_past_the_pool_limitcovers 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
SpareLinearintoSpareLinear { buffer, returned_ms }. #2338 builds the tuple form (SpareLinear(buffer)ingive_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.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T07:13:12Z.
I reproduced a same-tick ordering case on
24426e6. The sweep samples DXGI, callspool::room(video), then passes the same sample tolinear_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.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by LucaruluDev on 2026-11-30T08:38:38Z.
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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.