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

Open
HailLucifer666 wants to merge 2 commits from upstream-pr/2720 into main
HailLucifer666 commented 2026-11-29 16:33:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by HailLucifer666 on 2026-11-29T16:33:24Z.


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).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5552754601 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2720). Originally posted by [HailLucifer666](https://github.com/HailLucifer666) on 2026-11-29T16:33:24Z. --- 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).
icdmkg2 commented 2026-11-29 19:21:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by icdmkg2 on 2026-11-29T19:21:34Z.


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7261216227 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2720#issuecomment-7261216227). Originally posted by [icdmkg2](https://github.com/icdmkg2) on 2026-11-29T19:21:34Z. --- 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).
Yoruiopz commented 2026-11-30 08:02:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Yoruiopz on 2026-11-30T08:02:50Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7272419635 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2720#issuecomment-7272419635). Originally posted by [Yoruiopz](https://github.com/Yoruiopz) on 2026-11-30T08:02:50Z. --- 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.
tyr0nsur commented 2026-11-30 08:24:43 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T08:24:43Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7272875572 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2720#issuecomment-7272875572). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T08:24:43Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2720:upstream-pr/2720'
git switch 'upstream-pr/2720'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2720'
git switch 'upstream-pr/2720'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2720'
git switch 'upstream-pr/2720'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2720'
git switch 'main'
git merge --squash 'upstream-pr/2720'
git switch 'main'
git merge --ff-only 'upstream-pr/2720'
git switch 'main'
git merge 'upstream-pr/2720'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!2720
No description provided.