perf(gpu): fix sweep_unmapped zombie leak, lock-free kept slot bitmap, and read-first shadow let_go_idle #4041

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

@⁠qlfu on GitHub · 2026-11-30 15:05 UTC · original
qlfu:pr/fix-sweep-unmapped-zombie-and-lockfree-kept → main · +92 −46 · 3 files · 1 commits · closed without merging

Summary

Eliminates three long-session CPU sweep cliffs on the submitting thread:

  1. Fix permanent streamed-out texture zombie leak in resource::let_go_idle (sweep_unmapped_on):
    • sweep_unmapped_on called made.take() without resetting r.host.used.store(0, Relaxed) (unlike the main idle loop, dead-RT sweep, and slot_evict). Evicted streamed-out textures remained permanent used != 0 zombies, re-running K32QueryWorkingSetEx and bloating by_age/slot_evict scans on every sweep.
  2. Lock-free HostHeap::slots_showing and HostHeap::shows (descriptor/host.rs):
    • Adds parallel kept_raw: Box<[AtomicUsize]> and 64-slot occupancy bitmask kept_non_empty: Box<[AtomicU64]>, updated under the existing per-slot kept[i] lock in keep, keep_ref, and take_kept.
    • slots_showing skips empty 64-slot words in one instruction and reads kept_raw with zero per-slot Mutex::lock() calls (replacing up to ~1M mutex acquisitions per pressured slot_evict pass under SHADER_HEAPS.read()). shows also becomes lock-free.
  3. Read-first scan in shadow::let_go_idle (shadow.rs):
    • Scans LOOSE.read() first so COM references() checks do not block concurrent recording threads under LOOSE.write(); takes LOOSE.write() only when idle candidates exist and re-verifies is_idle before removing.

Verification

  • cargo check -p victory-gpu --all-targets --all-features --locked: exit 0.
  • cargo test -p victory-gpu --lib --locked -- resource:: descriptor::host:: shadow:: --test-threads=1: passed (0 failed).
  • git merge-tree --write-tree 41adb551 HEAD: clean merge.
  • 90s in-game runs (RTX 4070 Ti, 1440p DLSS Balanced Native & FG 2x, 0 WARNs / 0 ERRORs): heaps sweep time dropped 2.60 -> 0.50-0.60 ms (max 7.3 -> 1.7 ms).
**@⁠qlfu** on GitHub · 2026-11-30 15:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4041) `qlfu:pr/fix-sweep-unmapped-zombie-and-lockfree-kept` → `main` · +92 −46 · 3 files · 1 commits · closed without merging ## Summary Eliminates three long-session CPU sweep cliffs on the submitting thread: 1. **Fix permanent streamed-out texture zombie leak in `resource::let_go_idle` (`sweep_unmapped_on`)**: - `sweep_unmapped_on` called `made.take()` without resetting `r.host.used.store(0, Relaxed)` (unlike the main idle loop, dead-RT sweep, and `slot_evict`). Evicted streamed-out textures remained permanent `used != 0` zombies, re-running `K32QueryWorkingSetEx` and bloating `by_age`/`slot_evict` scans on every sweep. 2. **Lock-free `HostHeap::slots_showing` and `HostHeap::shows` (`descriptor/host.rs`)**: - Adds parallel `kept_raw: Box<[AtomicUsize]>` and 64-slot occupancy bitmask `kept_non_empty: Box<[AtomicU64]>`, updated under the existing per-slot `kept[i]` lock in `keep`, `keep_ref`, and `take_kept`. - `slots_showing` skips empty 64-slot words in one instruction and reads `kept_raw` with zero per-slot `Mutex::lock()` calls (replacing up to ~1M mutex acquisitions per pressured `slot_evict` pass under `SHADER_HEAPS.read()`). `shows` also becomes lock-free. 3. **Read-first scan in `shadow::let_go_idle` (`shadow.rs`)**: - Scans `LOOSE.read()` first so COM `references()` checks do not block concurrent recording threads under `LOOSE.write()`; takes `LOOSE.write()` only when idle candidates exist and re-verifies `is_idle` before removing. ## Verification - `cargo check -p victory-gpu --all-targets --all-features --locked`: exit 0. - `cargo test -p victory-gpu --lib --locked -- resource:: descriptor::host:: shadow:: --test-threads=1`: passed (0 failed). - `git merge-tree --write-tree 41adb551 HEAD`: clean merge. - 90s in-game runs (RTX 4070 Ti, 1440p DLSS Balanced Native & FG 2x, 0 WARNs / 0 ERRORs): `heaps` sweep time dropped `2.60 -> 0.50-0.60 ms` (max `7.3 -> 1.7 ms`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 15:10:43 +00:00
Author
Owner

@⁠IRennie74 on GitHub · 2026-11-30 18:22 UTC · original · edited 2026-11-30 18:44 UTC

This conflicts with main now, and part of it is already there:

  • Part 1 (zombie leak) is on main. let_go_idle's unmapped path now goes through take_unmapped_host and resets used right after wanted (crates/victory-gpu/src/resource.rs:3509 on 84bd61e2: r.host.used.store(0, Relaxed);). The one-line hunk here can go.
  • Part 2 (kept_raw / kept_non_empty) conflicts with main's slots_showing. On main it now returns a 6-tuple (index, raw, key, ok, lately, indexed) (callers at descriptor.rs:2185 and :2338). Slot eviction's choice also runs aside on main now (VICTORY_SLOT_EVICT_ASIDE, on), so the per-slot locks this removes are mostly off the submitting thread already. A fresh measurement on main would show whether the mirror (8 bytes plus a bit per slot) still pays for itself.
  • Part 3 (read-first LOOSE scan in shadow::let_go_idle) still applies, as far as I can see. It is the part most likely to help the frame, because recording threads take LOOSE too. Rebased down to this part alone, it would be easy to land.

The heaps 2.60 -> 0.50-0.60 ms figure predates main moving slot eviction aside, so it would need measuring again after the rebase.

**@⁠IRennie74** on GitHub · 2026-11-30 18:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4041#issuecomment-7287766499) · edited 2026-11-30 18:44 UTC This conflicts with main now, and part of it is already there: - **Part 1 (zombie leak) is on main.** `let_go_idle`'s unmapped path now goes through `take_unmapped_host` and resets `used` right after `wanted` (`crates/victory-gpu/src/resource.rs:3509` on 84bd61e2: `r.host.used.store(0, Relaxed);`). The one-line hunk here can go. - **Part 2 (`kept_raw` / `kept_non_empty`) conflicts with main's `slots_showing`.** On main it now returns a 6-tuple `(index, raw, key, ok, lately, indexed)` (callers at `descriptor.rs:2185` and `:2338`). Slot eviction's choice also runs aside on main now (`VICTORY_SLOT_EVICT_ASIDE`, on), so the per-slot locks this removes are mostly off the submitting thread already. A fresh measurement on main would show whether the mirror (8 bytes plus a bit per slot) still pays for itself. - **Part 3 (read-first `LOOSE` scan in `shadow::let_go_idle`) still applies, as far as I can see.** It is the part most likely to help the frame, because recording threads take `LOOSE` too. Rebased down to this part alone, it would be easy to land. The `heaps` 2.60 -> 0.50-0.60 ms figure predates main moving slot eviction aside, so it would need measuring again after the rebase.
github-bot closed this pull request 2026-12-01 18:50:46 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:46 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:46 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4041#issuecomment-7321533787) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

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