gpu(descriptor): atomic sparse candidate index for HostHeap::slots_showing (#1644) #2720

Open
github-bot wants to merge 2 commits from github-bot/gh-2720 into main AGit
Owner

@⁠HailLucifer666 on GitHub · 2026-11-29 16:33 UTC · original
HailLucifer666:perf/evictable-slots-bitmap → main · +463 −54 · 3 files · 2 commits · open

Addresses #1644

What it changes

HostHeap::slots_showing walked every slot in HostHeap::kept acquiring each slot's Mutex on every sweep() call (~28–79 ms stalls on the submitting thread on 8 GB cards, [Reported] in #1644).

Split into two commits on 829188e9:

  1. refactor(descriptor): encapsulate HostHeap::kept in KeptSlots submodule — moves kept behind private fields in descriptor/kept.rs (including raw_at() for HostHeap::shows and keep(..., None) for take_kept).
  2. perf(descriptor): add atomic sparse candidate index for slots_showing (#1644) — maintains a 64-slot atomic occupancy bitmap (bits) and atomic raw-identity shadow (raw) updated under the slot lock, skipping empty 64-slot words in one load and re-verifying every candidate hit under slots[i].lock() (zero TOCTOU/ABA). Kill switch: VICTORY_SLOT_EVICT_BITMAP=0 falls back to the full locked scan.

How it was tested

  • Not verified here: Live 8 GB GPU sweep() frame-time benchmark.
  • cargo test -p victory-gpu --lib descriptor::kept → 5 passed, 0 failed (empty set, zero-clone identity, TOCTOU stale-candidate re-verification, differential oracle random ops + non-64-aligned lengths, concurrent same-word writers + scanner).
  • cargo clippy -p victory-gpu --lib --tests → exit 0, 0 warnings in descriptor/kept.rs and touched lines. (Pre-existing diagnostics feature errors on 829188e9 untouched.)
  • cargo test passed for the crates it touches: yes

Checked for overlap

  • Searched open PRs at 829188e9. Related: #2075 (timing log only for #1644, non-colliding), #2361 (touches descriptor/host.rs to reclaim dead RTs — KeptSlots preserves identical slot-lock semantics and does not change slot liveness, so both compose cleanly).
**@⁠HailLucifer666** on GitHub · 2026-11-29 16:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2720) `HailLucifer666:perf/evictable-slots-bitmap` → `main` · +463 −54 · 3 files · 2 commits · open Addresses #1644 ## What it changes `HostHeap::slots_showing` walked every slot in `HostHeap::kept` acquiring each slot's `Mutex` on every `sweep()` call (~28–79 ms stalls on the submitting thread on 8 GB cards, `[Reported]` in #1644). Split into two commits on `829188e9`: 1. `refactor(descriptor): encapsulate HostHeap::kept in KeptSlots submodule` — moves `kept` behind private fields in `descriptor/kept.rs` (including `raw_at()` for `HostHeap::shows` and `keep(..., None)` for `take_kept`). 2. `perf(descriptor): add atomic sparse candidate index for slots_showing (#1644)` — maintains a 64-slot atomic occupancy bitmap (`bits`) and atomic raw-identity shadow (`raw`) updated under the slot lock, skipping empty 64-slot words in one load and re-verifying every candidate hit under `slots[i].lock()` (zero TOCTOU/ABA). Kill switch: `VICTORY_SLOT_EVICT_BITMAP=0` falls back to the full locked scan. ## How it was tested - **Not verified here:** Live 8 GB GPU `sweep()` frame-time benchmark. - `cargo test -p victory-gpu --lib descriptor::kept` → **5 passed, 0 failed** (empty set, zero-clone identity, TOCTOU stale-candidate re-verification, differential oracle random ops + non-64-aligned lengths, concurrent same-word writers + scanner). - `cargo clippy -p victory-gpu --lib --tests` → exit 0, **0 warnings** in `descriptor/kept.rs` and touched lines. *(Pre-existing `diagnostics` feature errors on `829188e9` untouched.)* - `cargo test` passed for the crates it touches: **yes** ## Checked for overlap - [x] Searched open PRs at `829188e9`. Related: #2075 (timing log only for #1644, non-colliding), #2361 (touches `descriptor/host.rs` to reclaim dead RTs — `KeptSlots` preserves identical slot-lock semantics and does not change slot liveness, so both compose cleanly).
Move HostHeap's per-slot Mutex<Option<ID3D12Resource>> table behind a
private-field KeptSlots<H> submodule (descriptor/kept.rs) so all mutations
funnel through keep() and keep_ref() while preserving zero-AddRef identity
checks and outside-lock retire_resource().

Behavior-identical preparatory commit for the atomic sparse candidate index
in #1644.

Verified:
- cargo test -p victory-gpu --lib --locked -- keep_ref_skips_clone_on_identity_and_retires_on_replacement (1 passed, 0 failed)
HostHeap::slots_showing() previously locked every Mutex across all ~1M
descriptor slots on every eviction sweep.

Add a private advisory candidate index (raw: Box<[AtomicUsize]> and
bits: Box<[AtomicU64]>) inside KeptSlots updated strictly under each slot's
mutex using Release stores and fetch_or/fetch_and RMW (because 64
independently-locked slots share one AtomicU64 word). for_each_matching()
skips empty 64-slot words in one load and non-matching occupied slots
without locking, then re-verifies every candidate under slots[i].lock() to
eliminate TOCTOU and ABA races.

Add VICTORY_SLOT_EVICT_BITMAP=0 kill switch to fall back to the full
locked scan, and a periodic diagnostics self-audit (every 64th sweep).

Verified:
- cargo test -p victory-gpu --lib --locked -- descriptor::kept::tests (5 passed, 0 failed)
- cargo test -p victory-gpu --lib --locked -- keep_ref_skips_clone_on_identity_and_retires_on_replacement (1 passed, 0 failed)
- cargo check -p victory-gpu --features diagnostics --tests --locked (0 errors, 0 warnings in touched files)
- Mutation probe (skipping bits fetch_or) confirmed red (3 failures) before restoring.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 16:37:55 +00:00
Author
Owner

@⁠icdmkg2 on GitHub · 2026-11-29 19:21 UTC · original

The live 8 GB measurement the PR notes as not done yet.

Setup: RTX 5060 Laptop GPU (8 GB), Ryzen 7 H 260, 32 GB, Windows 11. Build: main 55d06914 + #2549 + #2783 + #2647 + #2795 + this PR, release, Series S, DLSS performance, the prologue's cell, about 90 s per run. I added one timer around the descriptor::evictable_slots call in slot_evict and changed only VICTORY_SLOT_EVICT_BITMAP between runs:

passes evictable_slots median range candidates
default (index on) 5 15.1 ms 11.2–21.8 52,789–60,230
VICTORY_SLOT_EVICT_BITMAP=0 6 15.7 ms 15.1–19.4 45,457–58,578

So there's no measurable difference here. Earlier (#1644) I counted about 1,000,127 slots in 2 heaps. If the bitmap only skips empty 64-slot words, a mostly-filled heap leaves little to skip, and the per-slot raws.contains lookup against 45–60k candidates probably dominates. I haven't confirmed the fill ratio. A count of skipped words per pass would show it.

Separately, with #2549 merged, the pass ran only 5–6 times in about 90 s, where it was about 84 before (once a second). So on this machine #2549's back-off is what removes most of the #1644 cost. Both A/B'd against a build without this PR: fps unchanged within noise (18.9 / 16.9 against 18.7 / 18.6 median).

**@⁠icdmkg2** on GitHub · 2026-11-29 19:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2720#issuecomment-7261216227) The live 8 GB measurement the PR notes as not done yet. **Setup:** RTX 5060 Laptop GPU (8 GB), Ryzen 7 H 260, 32 GB, Windows 11. Build: `main` `55d06914` + #2549 + #2783 + #2647 + #2795 + this PR, release, Series S, DLSS performance, the prologue's cell, about 90 s per run. I added one timer around the `descriptor::evictable_slots` call in `slot_evict` and changed only `VICTORY_SLOT_EVICT_BITMAP` between runs: | | passes | `evictable_slots` median | range | candidates | |---|---|---|---|---| | default (index on) | 5 | **15.1 ms** | 11.2–21.8 | 52,789–60,230 | | `VICTORY_SLOT_EVICT_BITMAP=0` | 6 | **15.7 ms** | 15.1–19.4 | 45,457–58,578 | So there's no measurable difference here. Earlier (#1644) I counted about **1,000,127 slots in 2 heaps**. If the bitmap only skips empty 64-slot words, a mostly-filled heap leaves little to skip, and the per-slot `raws.contains` lookup against 45–60k candidates probably dominates. I haven't confirmed the fill ratio. A count of skipped words per pass would show it. Separately, with #2549 merged, the pass ran only 5–6 times in about 90 s, where it was about 84 before (once a second). So on this machine #2549's back-off is what removes most of the #1644 cost. Both A/B'd against a build without this PR: fps unchanged within noise (18.9 / 16.9 against 18.7 / 18.6 median).
Author
Owner

@⁠Yoruiopz on GitHub · 2026-11-30 08:02 UTC · original

Independent same-binary test on an RTX 5070 Laptop GPU (8 GB), Windows 11, Series X at 1920×1080 output with DLSS Performance and 2× FG, cap 15 rendered FPS. I used both commits from this PR on 41adb551 plus the 1080p startup fix, sweep timers, and the allocation-pruning change from #3811. The warm cache, copied checkpoint, input tape, and all renderer switches were held fixed, except VICTORY_SLOT_EVICT_BITMAP=0 versus 1. Sampled eviction and sweep slicing were held off. I bypassed the periodic diagnostic full-scan audit in both arms so the audit would not enter the timing series. Both arms still maintained the bitmap/raw metadata.

90–130 s after first present Bitmap off Bitmap on
Sweeps 37 38
Median draws per render 7,968 7,727
Median matched slots per sweep 26,111 26,205
Median slot walk 13.12 ms 5.22 ms
Median rest of descriptor matching 2.20 ms 2.22 ms
Median entire slot eviction pass 20.00 ms 11.93 ms
Median entire submit maintenance 29.52 ms 21.81 ms
Rendered interval p95 70.70 ms 73.71 ms
Rendered interval p99 93.50 ms 115.25 ms

Both runs saw zero eligible textures, descriptor resets, and evictions. This confirms a CPU-side scan reduction in this active 8 GB case. The one A/B pair did not establish better frame tails or correctness during nonzero eviction. The control and variant both had a logical heap capacity of 1,000,127 slots; that counter is capacity, so does not measure the bitmap’s physical lock attempts.

**@⁠Yoruiopz** on GitHub · 2026-11-30 08:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2720#issuecomment-7272419635) Independent same-binary test on an RTX 5070 Laptop GPU (8 GB), Windows 11, Series X at 1920×1080 output with DLSS Performance and 2× FG, cap 15 rendered FPS. I used both commits from this PR on `41adb551` plus the 1080p startup fix, sweep timers, and the allocation-pruning change from #3811. The warm cache, copied checkpoint, input tape, and all renderer switches were held fixed, except `VICTORY_SLOT_EVICT_BITMAP=0` versus `1`. Sampled eviction and sweep slicing were held off. I bypassed the periodic diagnostic full-scan audit in both arms so the audit would not enter the timing series. Both arms still maintained the bitmap/raw metadata. | 90–130 s after first present | Bitmap off | Bitmap on | | --- | ---: | ---: | | Sweeps | 37 | 38 | | Median draws per render | 7,968 | 7,727 | | Median matched slots per sweep | 26,111 | 26,205 | | Median slot walk | 13.12 ms | 5.22 ms | | Median rest of descriptor matching | 2.20 ms | 2.22 ms | | Median entire slot eviction pass | 20.00 ms | 11.93 ms | | Median entire submit maintenance | 29.52 ms | 21.81 ms | | Rendered interval p95 | 70.70 ms | 73.71 ms | | Rendered interval p99 | 93.50 ms | 115.25 ms | Both runs saw zero eligible textures, descriptor resets, and evictions. This confirms a CPU-side scan reduction in this active 8 GB case. The one A/B pair did not establish better frame tails or correctness during nonzero eviction. The control and variant both had a logical heap capacity of 1,000,127 slots; that counter is capacity, so does not measure the bitmap’s physical lock attempts.
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 08:24 UTC · original

I measured the diagnostic audit that the RTX 5070 Laptop A/B above bypassed. With diagnostics and the sparse index enabled, the first call to slots_showing takes every slot lock in that heap. The global counter repeats that full audit every 64 calls and can keep selecting the same heap when heaps are visited in a fixed order.

Follow-up commit fa8a5d0 is based on 2d5663a. It checks one balanced slice per heap per call, retaining the locked checks of raw identity and occupancy. Each heap checks all its slots over 64 calls. Deliberate raw and bitmap drift tests cover uneven sizes and interleaved heaps.

Synthetic Windows CPU test on a Ryzen 7 5800X, optimized Rust, 1,000,127 slots, 25% occupied, one thread, 4,096 calls per arm after warm-up. Audit work only, with the candidate scan outside the timer.

Audit latency per call Global full audit Heap-local slices
p99.9 5.246 ms 0.103 ms
Max 5.477 ms 0.107 ms

cargo test --locked -p victory-gpu --lib descriptor::kept::tests passed all six tests. The full diagnostics test build still hits the pre-existing mb and timing errors on this head. Gameplay frame times and VRAM were outside this check.

**@⁠tyr0nsur** on GitHub · 2026-11-30 08:24 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2720#issuecomment-7272875572) I measured the diagnostic audit that the RTX 5070 Laptop A/B above bypassed. With diagnostics and the sparse index enabled, the first call to `slots_showing` takes every slot lock in that heap. The global counter repeats that full audit every 64 calls and can keep selecting the same heap when heaps are visited in a fixed order. [Follow-up commit `fa8a5d0`](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/fa8a5d042e79ac76893875212b3c902411a349d6) is based on `2d5663a`. It checks one balanced slice per heap per call, retaining the locked checks of raw identity and occupancy. Each heap checks all its slots over 64 calls. Deliberate raw and bitmap drift tests cover uneven sizes and interleaved heaps. Synthetic Windows CPU test on a Ryzen 7 5800X, optimized Rust, 1,000,127 slots, 25% occupied, one thread, 4,096 calls per arm after warm-up. Audit work only, with the candidate scan outside the timer. | Audit latency per call | Global full audit | Heap-local slices | | --- | ---: | ---: | | p99.9 | 5.246 ms | 0.103 ms | | Max | 5.477 ms | 0.107 ms | `cargo test --locked -p victory-gpu --lib descriptor::kept::tests` passed all six tests. The full diagnostics test build still hits the pre-existing `mb` and `timing` errors on this head. Gameplay frame times and VRAM were outside this check.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor.rs
  • crates/victory-gpu/src/descriptor/host.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/2720/head:github-bot/gh-2720'
git switch 'github-bot/gh-2720'

Merge

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