gpu: offload 1Hz sweep drops and eliminate eviction lock stalls #4948

Closed
github-bot wants to merge 1 commit from github-bot/gh-4947 into main AGit
Owner

@⁠topangag on GitHub · 2026-12-01 15:06 UTC · original
topangag:pr/reduce-cpu-wait-and-stutters → main · +290 −86 · 4 files · 1 commits · closed without merging

What it changes

Substantially reduces CPU waiting and periodic frame-time stutters on the submitting thread during 1 Hz memory sweeps, background slot eviction, and asynchronous residency settles:

  1. Offload 1 Hz sweep() resource destruction and OS memory queries off the submitting thread (crates/victory-gpu/src/host.rs, crates/victory-gpu/src/list.rs, crates/victory-gpu/src/pool.rs):
    • Adds host::drop_aside() reusing the existing "victory-bury" background drop thread (with bounded queue fallback).
    • Moves synchronous D3D12 COM Release() / WDDM decommit work during 1 Hz sweeps off the submitting thread and outside pool locks: list::trim_idle, host::trim_spare_uploads, host::trim_spare_chunks, and pool::room (via Pool::reclaim_taking()).
    • Moves host::memory_now() (K32GetProcessMemoryInfo + logging) onto "victory-bury" so process-memory queries under heavy paging do not stall the submitting thread.
  2. Eliminate TEXTURES and SHADER_HEAPS lock stalls during eviction sweeps (crates/victory-gpu/src/resource.rs):
    • Reduces SLOT_LOOK_PART from 4096 to 256 so the background victory-slot-look worker releases TEXTURES frequently instead of blocking texture creation or sweeps.
    • Prevents slot_look_aside from starting a new background scan while a previous batch is still draining (SLOT_HAS_READY), eliminating overlapping SHADER_HEAPS lock contention with slot_evict_ready().
    • Uses non-blocking textures_now() / try_lock() on the submitting thread in let_go_idle (when flush == 0) and slot_evict_ready, deferring work cleanly to the next submission whenever a lock is contended.
    • Applies bounded per-sweep / per-submission CPU budgets (VICTORY_SWEEP_BUDGET_US, default 3000 us, covering both the unmapped scan and main idle scan; VICTORY_SLOT_APPLY_BUDGET_US, default 4000 us, draining SLOT_READY via VecDeque) so eviction bursts spread smoothly across submissions.
  3. Coalesce completed async residency enqueues before mapped() (crates/victory-gpu/src/host.rs):
    • In wait_asked() (VICTORY_RESIDENT_LATER=1), advances SETTLED through the highest fence value already completed (clamped to ASKED, guarding against u64::MAX on device removal) before running mapped(&device) so concurrent completed EnqueueMakeResident calls share a single copy-queue barrier.

How it was tested

  • PC Hardware:
    • CPU: AMD Ryzen 9 9955HX3D
    • RAM: 16 GB physical RAM (15,544.2 MiB usable, system-managed C:\pagefile.sys)
    • GPU: NVIDIA GeForce RTX 5070 Ti Laptop GPU, 12 GB VRAM (Resizable BAR, Tiled Resources Tier 4)
    • OS: Windows 11
  • GPU and profile:
    • Xbox Series X (game_scarlett_master.exe), 1080to1440, DLSS Quality, Ray Tracing Off (VICTORY_HW_RT=0), DualSense input profile, tested in both a fixed idle-in-world automated run (entering the game with no further manual input) and live interactive play on Windows 11.
  • Before:
    • Under 16 GB host-memory pressure and active VRAM eviction, 1 Hz sweeps synchronously dropped D3D12 heaps/allocators and queried process memory on the submitting thread, while overlapping background slot scans contended on TEXTURES and SHADER_HEAPS, causing noticeable CPU waits and periodic frame-time spikes.
  • After:
    • In our specific automated test scenario (entering the game and standing in-scene with no further manual input), CPU waiting was reduced by nearly 90%.
    • In live interactive gameplay, CPU-induced micro-stutters and periodic sweep stalls are substantially reduced (some stutters still occur during heavy streaming), with no crashes, device losses, or VRAM regression.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes)
  • cargo test passed for the crates it touches: yes
    • Local on 6318c011: targeted victory-gpu unit tests (32 passed, 0 failed) and both default and --all-features Clippy reported 0 warnings/errors in the 4 touched files.
    • Full Windows GitHub Actions CI (check = Clippy, Clippy --all-features, full workspace cargo test) verified green in fork PR topangag/VIctory-NVIDIA#4 on top of upstream CI baseline fixes (#4708 Clippy fixes + #4143 victory-hle alias validation fix).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #4873 (moves diagnostics memory line and throttles procmem walk; does not cover host::drop_aside for 1 Hz sweep D3D12 drops, SLOT_LOOK_PART / SLOT_HAS_READY eviction lock contention, time-sliced let_go_idle / slot_evict_ready, or wait_asked residency coalescing).
**@⁠topangag** on GitHub · 2026-12-01 15:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4947) `topangag:pr/reduce-cpu-wait-and-stutters` → `main` · +290 −86 · 4 files · 1 commits · closed without merging ## What it changes Substantially reduces CPU waiting and periodic frame-time stutters on the submitting thread during 1 Hz memory sweeps, background slot eviction, and asynchronous residency settles: 1. Offload 1 Hz sweep() resource destruction and OS memory queries off the submitting thread (crates/victory-gpu/src/host.rs, crates/victory-gpu/src/list.rs, crates/victory-gpu/src/pool.rs): - Adds host::drop_aside() reusing the existing "victory-bury" background drop thread (with bounded queue fallback). - Moves synchronous D3D12 COM Release() / WDDM decommit work during 1 Hz sweeps off the submitting thread and outside pool locks: list::trim_idle, host::trim_spare_uploads, host::trim_spare_chunks, and pool::room (via Pool::reclaim_taking()). - Moves host::memory_now() (K32GetProcessMemoryInfo + logging) onto "victory-bury" so process-memory queries under heavy paging do not stall the submitting thread. 2. Eliminate TEXTURES and SHADER_HEAPS lock stalls during eviction sweeps (crates/victory-gpu/src/resource.rs): - Reduces SLOT_LOOK_PART from 4096 to 256 so the background victory-slot-look worker releases TEXTURES frequently instead of blocking texture creation or sweeps. - Prevents slot_look_aside from starting a new background scan while a previous batch is still draining (SLOT_HAS_READY), eliminating overlapping SHADER_HEAPS lock contention with slot_evict_ready(). - Uses non-blocking textures_now() / try_lock() on the submitting thread in let_go_idle (when flush == 0) and slot_evict_ready, deferring work cleanly to the next submission whenever a lock is contended. - Applies bounded per-sweep / per-submission CPU budgets (VICTORY_SWEEP_BUDGET_US, default 3000 us, covering both the unmapped scan and main idle scan; VICTORY_SLOT_APPLY_BUDGET_US, default 4000 us, draining SLOT_READY via VecDeque) so eviction bursts spread smoothly across submissions. 3. Coalesce completed async residency enqueues before mapped() (crates/victory-gpu/src/host.rs): - In wait_asked() (VICTORY_RESIDENT_LATER=1), advances SETTLED through the highest fence value already completed (clamped to ASKED, guarding against u64::MAX on device removal) before running mapped(&device) so concurrent completed EnqueueMakeResident calls share a single copy-queue barrier. ## How it was tested - PC Hardware: - CPU: AMD Ryzen 9 9955HX3D - RAM: 16 GB physical RAM (15,544.2 MiB usable, system-managed C:\pagefile.sys) - GPU: NVIDIA GeForce RTX 5070 Ti Laptop GPU, 12 GB VRAM (Resizable BAR, Tiled Resources Tier 4) - OS: Windows 11 - GPU and profile: - Xbox Series X (game_scarlett_master.exe), 1080to1440, DLSS Quality, Ray Tracing Off (VICTORY_HW_RT=0), DualSense input profile, tested in both a fixed idle-in-world automated run (entering the game with no further manual input) and live interactive play on Windows 11. - Before: - Under 16 GB host-memory pressure and active VRAM eviction, 1 Hz sweeps synchronously dropped D3D12 heaps/allocators and queried process memory on the submitting thread, while overlapping background slot scans contended on TEXTURES and SHADER_HEAPS, causing noticeable CPU waits and periodic frame-time spikes. - After: - In our specific automated test scenario (entering the game and standing in-scene with no further manual input), CPU waiting was reduced by nearly 90%. - In live interactive gameplay, CPU-induced micro-stutters and periodic sweep stalls are substantially reduced (some stutters still occur during heavy streaming), with no crashes, device losses, or VRAM regression. - For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes) - cargo test passed for the crates it touches: yes - Local on 6318c011: targeted victory-gpu unit tests (32 passed, 0 failed) and both default and --all-features Clippy reported 0 warnings/errors in the 4 touched files. - Full Windows GitHub Actions CI (check = Clippy, Clippy --all-features, full workspace cargo test) verified green in fork PR topangag/VIctory-NVIDIA#4 on top of upstream CI baseline fixes (#4708 Clippy fixes + #4143 victory-hle alias validation fix). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #4873 (moves diagnostics memory line and throttles procmem walk; does not cover host::drop_aside for 1 Hz sweep D3D12 drops, SLOT_LOOK_PART / SLOT_HAS_READY eviction lock contention, time-sliced let_go_idle / slot_evict_ready, or wait_asked residency coalescing).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 15:07:38 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-12-01 15:16 UTC · original

Ran the host:: / list::tests / pool:: / resource:: group selection at 6318c011 on an NVIDIA Blackwell desktop part with 16 GB of VRAM, with a control on main 5fabb46e in a separate target directory. No title was run.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own CARGO_TARGET_DIR, no local patches.

cargo test -q --locked -p victory-gpu --lib -- --test-threads=1 host:: list::tests pool:: resource::
  PR head 6318c011: 349 passed; 1 failed; 33 ignored; 779 filtered out      (exit 101)
  main    5fabb46e: 348 passed; 1 failed; 33 ignored; 779 filtered out      (exit 101)

The single failure is host::packed_present_tests::packed_float_single_planes_are_presented, at host.rs:17756 on the PR head and host.rs:17713 on main: it fails on this host with and without the PR, so it is not introduced here. The PR head has one more passing test than main in this selection. The description's 32-test targeted run and its ~90% CPU-waiting reduction were not reproduced: no retail title was run.

Not tested: the full workspace suite, a retail title, 1 Hz sweep CPU-wait measurements, Wine, AMD adapters, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out both commits in detached worktrees, built them, ran the tests, wrote this report; neither worktree was modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-12-01 15:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4947#issuecomment-7315623593) Ran the `host::` / `list::tests` / `pool::` / `resource::` group selection at `6318c011` on an NVIDIA Blackwell desktop part with 16 GB of VRAM, with a control on `main` `5fabb46e` in a separate target directory. No title was run. Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, debug build, detached worktree at the exact PR head, own `CARGO_TARGET_DIR`, no local patches. ``` cargo test -q --locked -p victory-gpu --lib -- --test-threads=1 host:: list::tests pool:: resource:: PR head 6318c011: 349 passed; 1 failed; 33 ignored; 779 filtered out (exit 101) main 5fabb46e: 348 passed; 1 failed; 33 ignored; 779 filtered out (exit 101) ``` The single failure is `host::packed_present_tests::packed_float_single_planes_are_presented`, at `host.rs:17756` on the PR head and `host.rs:17713` on `main`: it fails on this host with and without the PR, so it is not introduced here. The PR head has one more passing test than `main` in this selection. The description's 32-test targeted run and its ~90% CPU-waiting reduction were not reproduced: no retail title was run. Not tested: the full workspace suite, a retail title, 1 Hz sweep CPU-wait measurements, Wine, AMD adapters, release profile, game data. AI-assisted (OpenCode), model: **MiMo-V2.6-Flash Free** - checked out both commits in detached worktrees, built them, ran the tests, wrote this report; neither worktree was modified; no game data was used.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 15:21 UTC · original

On 6318c011, trim_spare_chunks() can return a positive byte count while its chunks are still queued for destruction. The commit-pressure path uses that return value to decide whether to retry the allocation immediately, so the retry can run before the driver releases the buffers.

e41f18ea keeps the direct trim synchronous and keeps the periodic sweep on the existing background queue. It uses the trim callback split from Colej1921’s #3951.

A focused Windows fixture ran the exact trim and its sweep call with synthetic chunks and a paused drop queue. The author head returned the byte count with 0 of 2 chunks released. With this change both chunks were released before the direct call returned. The periodic call still queued both for release, and both paths released outside the pool locks. The staged asset policy passed.

Please keep the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change in.

AI-assisted with OpenAI Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 15:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4947#issuecomment-7315782433) On `6318c011`, `trim_spare_chunks()` can return a positive byte count while its chunks are still queued for destruction. The commit-pressure path uses that return value to decide whether to retry the allocation immediately, so the retry can run before the driver releases the buffers. [e41f18ea](https://github.com/andrewpozdnakov7-jpg/VIctory-NVIDIA/commit/e41f18ea83f3ead463ff2e14a5c320a0671d5c90) keeps the direct trim synchronous and keeps the periodic sweep on the existing background queue. It uses the trim callback split from Colej1921’s #3951. A focused Windows fixture ran the exact trim and its sweep call with synthetic chunks and a paused drop queue. The author head returned the byte count with 0 of 2 chunks released. With this change both chunks were released before the direct call returned. The periodic call still queued both for release, and both paths released outside the pool locks. The staged asset policy passed. Please keep the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change in. AI-assisted with OpenAI Codex.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-12-01 15:24 UTC · original

Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree, per-worktree CARGO_TARGET_DIR.

Base 5fabb46eaf6ed8771321787f8871051abde69b9b, head 6318c01127ea9b70d3b34be1159522be5b8896c7. git diff --numstat → host.rs 78/27, list.rs 5/2, pool.rs 22/7, resource.rs 185/50.

One test is added and its name is new on the base — git grep -F resident_settled_cover_coalesces_completed_enqueues_and_guards_device_removal 5fabb46e -- . returns no match:
host::batch::resident_settled_cover_coalesces_completed_enqueues_and_guards_device_removal, at host.rs:20686.

What it covers, in full: four literal calls to the free function resident_settled_cover(settled, enqueued, completed) — (10,14,13) → 13 coalescing a completed enqueue, (10,14,20) → 14 clamping a completion past the enqueued mark, (10,10,10) → 10, and (10,14,u64::MAX) → 10 for the wild-value guard. It is a pure-function test; it does not exercise the batch book or a device-removal path.

git diff --check "5fabb46e..6318c011" → no output, exit 0.

$env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4947'
cargo test --locked -p victory-gpu --lib -- host::batch::resident_settled_cover_coalesces_completed_enqueues_and_guards_device_removal --exact --test-threads=1 --quiet

Result: running 1 test, test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1161 filtered out; finished in 0.00s.

No device opened, GPU/driver N/A. No game data.

**@⁠cloph-dsp** on GitHub · 2026-12-01 15:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4947#issuecomment-7315848180) Verification (independent, AI-assisted: Hy4 flash). Windows, Rust 1.100.0 (Scoop rust-msvc), MSVC, commit-scoped shallow worktree, per-worktree CARGO_TARGET_DIR. Base `5fabb46eaf6ed8771321787f8871051abde69b9b`, head `6318c01127ea9b70d3b34be1159522be5b8896c7`. `git diff --numstat` → host.rs 78/27, list.rs 5/2, pool.rs 22/7, resource.rs 185/50. One test is added and its name is new on the base — `git grep -F resident_settled_cover_coalesces_completed_enqueues_and_guards_device_removal 5fabb46e -- .` returns no match: `host::batch::resident_settled_cover_coalesces_completed_enqueues_and_guards_device_removal`, at host.rs:20686. What it covers, in full: four literal calls to the free function `resident_settled_cover(settled, enqueued, completed)` — `(10,14,13) → 13` coalescing a completed enqueue, `(10,14,20) → 14` clamping a completion past the enqueued mark, `(10,10,10) → 10`, and `(10,14,u64::MAX) → 10` for the wild-value guard. It is a pure-function test; it does not exercise the batch book or a device-removal path. `git diff --check "5fabb46e..6318c011"` → no output, exit 0. ``` $env:CARGO_TARGET_DIR='D:\Victory-Contrib\NVIDIA-Contrib\target-4947' cargo test --locked -p victory-gpu --lib -- host::batch::resident_settled_cover_coalesces_completed_enqueues_and_guards_device_removal --exact --test-threads=1 --quiet ``` Result: `running 1 test`, `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1161 filtered out; finished in 0.00s`. No device opened, GPU/driver N/A. No game data.
@ -4488,3 +4554,3 @@
};
let began = std::time::Instant::now();
slot_apply(victims, &job, true);
slot_apply_slice(&mut victims, &job, true, Some(slot_apply_budget_us()));
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 15:30 UTC · original

Could the new time-sliced slot-eviction queue get a focused regression test? slot_evict_ready carries the remaining VecDeque into the next submission after either the time budget expires or TEXTURES/made is busy. A test that forces a budget stop and a Busy result, then drains the next slice, would verify those victims are retained exactly once while stale victims are still dropped; the added test covers resident_settled_cover only, so this continuation behavior has no direct regression coverage.

**@⁠gut0to** on GitHub · 2026-12-01 15:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4947#discussion_r4756530745) Could the new time-sliced slot-eviction queue get a focused regression test? slot_evict_ready carries the remaining VecDeque into the next submission after either the time budget expires or TEXTURES/made is busy. A test that forces a budget stop and a Busy result, then drains the next slice, would verify those victims are retained exactly once while stale victims are still dropped; the added test covers resident_settled_cover only, so this continuation behavior has no direct regression coverage.
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 15:30 UTC · original · reviewed

AI-assisted review: I checked the bounded eviction continuation and its existing tests. I used AI assistance and verified that the new queue-retry behavior has no focused regression test.

**@⁠gut0to** on GitHub · 2026-12-01 15:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4947#pullrequestreview-6134428037) · **reviewed** AI-assisted review: I checked the bounded eviction continuation and its existing tests. I used AI assistance and verified that the new queue-retry behavior has no focused regression test.
github-bot closed this pull request 2026-12-01 16:12:29 +00:00

Pull request closed

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!4948
No description provided.