GPU: track dynamic descriptor slots in a 64-bit word bitmap #3218

Open
github-bot wants to merge 1 commit from github-bot/gh-3218 into main AGit
Owner

@⁠danielibabet on GitHub · 2026-11-26 13:33 UTC · original
danielibabet:pr/dynamic-slot-bitmap → main · +425 −34 · 1 files · 1 commits · open

Summary

Replace the Vec<bool> dynamic slot allocator in HostHeap with a dense 64-bit word bitmap (DynamicSlots). This is a performance fix for NVIDIA GPUs where the host heap is capped at 1,000,000 shader-visible descriptors, forcing MIN_DYNAMIC = 65,536 slots to absorb all descriptor tables above slot 934,464 and all root-view runs.

Problem

The previous allocator stored one bool per slot (up to 262,144 bytes / 256 KiB for a 256K heap) and scanned byte-by-byte under the heap Mutex. When the dynamic range fragmented or saturated — which happens every frame on NVIDIA with ~4,700 shadow copies requesting pair() → dynamic(2) — a single frame could scan hundreds of thousands of bytes while holding the lock, stalling all render threads.

Solution

DynamicSlots packs slot state into Vec<u64> (8× less memory: 8 KiB for the NVIDIA 64K range, fits in L1D):

  • SWAR scan without branches: skips full words (u64::MAX) or empty words (0) in 1–2 instructions; resolves cross-word spans with trailing_zeros / leading_zeros; locates internal gaps of 1–63 slots in ≤6 bit-shift operations.
  • O(1) early-rejection: min_failed tracks the smallest n that did not fit after a full scan. Requests of size ≥ min_failed are rejected in nanoseconds until a release clears at least one bit (zero false negatives, no heuristics, no frame-counter coupling).

Benchmark results (cargo test --release, i9-14900KF)

Scenario Before (Vec<bool>) After (DynamicSlots) Speedup
NVIDIA 64K — rotation, 3 batches in flight, fragmented pairs 0.275 ms/frame 0.006 ms/frame 43.7×
NVIDIA 64K — saturated frame (2,500 table/root-view requests) 100.390 ms 0.0011 ms 91,264×
256K heap — rotation, 3 batches in flight, fragmented pairs 3.801 ms/frame 0.024 ms/frame 158.7×
256K heap — saturated frame (2,500 requests) 404.578 ms 0.0011 ms 367,798×

Tests

  • Differential equivalence against the reference allocator across 30,000 random operations and word-boundary edge cases: OK
  • descriptor::host::tests on WARP: 17/17 passed
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings
  • cargo run -p xtask -- policy: 191 files OK
**@⁠danielibabet** on GitHub · 2026-11-26 13:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/3218) `danielibabet:pr/dynamic-slot-bitmap` → `main` · +425 −34 · 1 files · 1 commits · open ## Summary Replace the `Vec<bool>` dynamic slot allocator in `HostHeap` with a dense 64-bit word bitmap (`DynamicSlots`). This is a performance fix for NVIDIA GPUs where the host heap is capped at 1,000,000 shader-visible descriptors, forcing `MIN_DYNAMIC` = 65,536 slots to absorb all descriptor tables above slot 934,464 and all root-view runs. ## Problem The previous allocator stored one `bool` per slot (up to 262,144 bytes / 256 KiB for a 256K heap) and scanned byte-by-byte under the heap `Mutex`. When the dynamic range fragmented or saturated — which happens every frame on NVIDIA with ~4,700 shadow copies requesting `pair() → dynamic(2)` — a single frame could scan hundreds of thousands of bytes while holding the lock, stalling all render threads. ## Solution `DynamicSlots` packs slot state into `Vec<u64>` (8× less memory: 8 KiB for the NVIDIA 64K range, fits in L1D): - **SWAR scan without branches**: skips full words (`u64::MAX`) or empty words (`0`) in 1–2 instructions; resolves cross-word spans with `trailing_zeros` / `leading_zeros`; locates internal gaps of 1–63 slots in ≤6 bit-shift operations. - **O(1) early-rejection**: `min_failed` tracks the smallest `n` that did not fit after a full scan. Requests of size ≥ `min_failed` are rejected in nanoseconds until a `release` clears at least one bit (zero false negatives, no heuristics, no frame-counter coupling). ## Benchmark results (cargo test --release, i9-14900KF) | Scenario | Before (Vec\<bool\>) | After (DynamicSlots) | Speedup | |---|---|---|---| | NVIDIA 64K — rotation, 3 batches in flight, fragmented pairs | 0.275 ms/frame | 0.006 ms/frame | **43.7×** | | NVIDIA 64K — saturated frame (2,500 table/root-view requests) | 100.390 ms | 0.0011 ms | **91,264×** | | 256K heap — rotation, 3 batches in flight, fragmented pairs | 3.801 ms/frame | 0.024 ms/frame | **158.7×** | | 256K heap — saturated frame (2,500 requests) | 404.578 ms | 0.0011 ms | **367,798×** | ## Tests - Differential equivalence against the reference allocator across 30,000 random operations and word-boundary edge cases: OK - `descriptor::host::tests` on WARP: 17/17 passed - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: 0 warnings - `cargo run -p xtask -- policy`: 191 files OK
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:35:53 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 13:52 UTC · original · approved these changes

Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 16/16 passed (1 ignored bench; including dynamic_slot_bitmap_handles_word_boundaries_and_failed_watermark and dynamic_slot_bitmap_matches_reference_allocator).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly accelerates dynamic descriptor slot allocation using a 64-bit word bitmap.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 13:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/3218#pullrequestreview-6075285845) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: 16/16 passed (1 ignored bench; including `dynamic_slot_bitmap_handles_word_boundaries_and_failed_watermark` and `dynamic_slot_bitmap_matches_reference_allocator`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly accelerates dynamic descriptor slot allocation using a 64-bit word bitmap. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠rezioliver-collab on GitHub · 2026-11-26 18:01 UTC · original

I measured how much of the saturated-heap speedup survives when releases repeatedly invalidate the cached failed request size. With 65,535 slots on Apple M1, even reopening two slots on every iteration reduced the time for the 256-iteration trace from 42.61 ms to 0.324 ms.

Reopen two slots Base, ms/trace PR, ms/trace
Every iteration 42.61 0.324
Every 8th iteration 20.25 0.0426
Once per trace 17.13 0.00313

The heap started full. Each reopening tried a three-slot allocation, then reclaimed the two-slot hole. Holes alternated between slots 63–64 and the heap tail. Each iteration also requested 3–6 slots from the full heap. Every returned index and failed request matched between 63bcca43 and 249ba2a6, including the 65- and 4,095-slot controls.

I compiled the allocator and release methods with their mutex into a single-threaded native CPU harness (Rust 1.98.1, opt-level=3, macOS 14.7). Times are medians from 12 alternating pairs and measure allocator work only.

**@⁠rezioliver-collab** on GitHub · 2026-11-26 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/3218#issuecomment-7199975647) I measured how much of the saturated-heap speedup survives when releases repeatedly invalidate the cached failed request size. With 65,535 slots on Apple M1, even reopening two slots on every iteration reduced the time for the 256-iteration trace from **42.61 ms to 0.324 ms**. | Reopen two slots | Base, ms/trace | PR, ms/trace | |---|---:|---:| | Every iteration | 42.61 | 0.324 | | Every 8th iteration | 20.25 | 0.0426 | | Once per trace | 17.13 | 0.00313 | The heap started full. Each reopening tried a three-slot allocation, then reclaimed the two-slot hole. Holes alternated between slots 63–64 and the heap tail. Each iteration also requested 3–6 slots from the full heap. Every returned index and failed request matched between `63bcca43` and `249ba2a6`, including the 65- and 4,095-slot controls. I compiled the allocator and release methods with their mutex into a single-threaded native CPU harness (Rust 1.98.1, `opt-level=3`, macOS 14.7). Times are medians from 12 alternating pairs and measure allocator work only.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3218/head:github-bot/gh-3218'
git switch 'github-bot/gh-3218'

Merge

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