GPU: store HostHeap::kept sparsely by slot index to save unpopulated slot RAM and speed up evict #3456

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

@⁠Luislariosss on GitHub · 2026-11-27 03:11 UTC · original
Luislariosss:feat/sparse-heap-kept → main · +49 −39 · 1 files · 1 commits · open

Summary

Stores HostHeap::kept sparsely (HashMap<u32, KeptEntry>) instead of a dense Vec<Option<KeptEntry>> sized to count + extra:

  • Eliminates eager allocation of millions of None entries per shader-visible view heap (up to ~37 MiB per 2M-slot heap).
  • Turns HostHeap::evict() from a full linear scan over every slot in the heap (0..count + extra) into an iteration over only live populated slots.
  • Drops/retires replaced ID3D12Resource and Arc<Shadow> values outside self.kept.lock().

Validation

  • cargo test -p victory-gpu --lib descriptor::host::: 15/15 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics): clean.
  • cargo xtask policy: 191 files ok.
**@⁠Luislariosss** on GitHub · 2026-11-27 03:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/3456) `Luislariosss:feat/sparse-heap-kept` → `main` · +49 −39 · 1 files · 1 commits · open ### Summary Stores `HostHeap::kept` sparsely (`HashMap<u32, KeptEntry>`) instead of a dense `Vec<Option<KeptEntry>>` sized to `count + extra`: - Eliminates eager allocation of millions of `None` entries per shader-visible view heap (up to ~37 MiB per 2M-slot heap). - Turns `HostHeap::evict()` from a full linear scan over every slot in the heap (`0..count + extra`) into an iteration over only live populated slots. - Drops/retires replaced `ID3D12Resource` and `Arc<Shadow>` values **outside** `self.kept.lock()`. ### Validation - `cargo test -p victory-gpu --lib descriptor::host::`: 15/15 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`): clean. - `cargo xtask policy`: 191 files ok.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:13:25 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 03:27 UTC · original

WARP test report (AI-assisted with Claude; synthetic tests only, no game files)

  • Head: 28fde825644cffda7a736dad0b2aa4a7b2eabe7a, base: origin/main @ 63bcca4 (this PR's merge base)
  • Windows 11 Pro, build 10.0.26200; D3D12 on WARP only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1, adapter vendor 0x1414 / software flag), DXIL validator dxil.dll from the Windows SDK 10.0.26100
  • Note: VICTORY_D3D12_WARP is only honored with --features diagnostics (host.rs create()); without it cargo test -p victory-gpu --lib picks the hardware GPU. I ran with --features diagnostics.
  • cargo test -p victory-gpu --lib --locked --features diagnostics: 246 passed, 0 failed, 1 ignored (identical to base; all 15 descriptor::host:: tests pass)
  • No new failures vs base. waits_end_on_ticks_and_count_frames passed on both. I did not re-run clippy.

Review: no correctness issue found; the index >= count + dynamic guard keeps the old out-of-range behavior, and the old resource and shadow are now released outside the lock. Trade-off to weigh: keep runs on every descriptor write and now hashes (SipHash) instead of indexing a Vec, and a heap that is mostly populated uses more memory as a map than the dense vector did. The PR only measures the sparse and evict cases, so a number for the dense write path would help. evict now visits slots in hash order, which looks harmless.

**@⁠oni-swr** on GitHub · 2026-11-27 03:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3456#issuecomment-7209002711) **WARP test report** (AI-assisted with Claude; synthetic tests only, no game files) - Head: `28fde825644cffda7a736dad0b2aa4a7b2eabe7a`, base: `origin/main` @ `63bcca4` (this PR's merge base) - Windows 11 Pro, build 10.0.26200; D3D12 on WARP only (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, adapter vendor 0x1414 / software flag), DXIL validator `dxil.dll` from the Windows SDK 10.0.26100 - Note: `VICTORY_D3D12_WARP` is only honored with `--features diagnostics` (`host.rs` `create()`); without it `cargo test -p victory-gpu --lib` picks the hardware GPU. I ran with `--features diagnostics`. - `cargo test -p victory-gpu --lib --locked --features diagnostics`: **246 passed, 0 failed, 1 ignored** (identical to base; all 15 `descriptor::host::` tests pass) - No new failures vs base. `waits_end_on_ticks_and_count_frames` passed on both. I did not re-run clippy. **Review:** no correctness issue found; the `index >= count + dynamic` guard keeps the old out-of-range behavior, and the old resource and shadow are now released outside the lock. Trade-off to weigh: `keep` runs on every descriptor write and now hashes (SipHash) instead of indexing a `Vec`, and a heap that is mostly populated uses more memory as a map than the dense vector did. The PR only measures the sparse and evict cases, so a number for the dense write path would help. `evict` now visits slots in hash order, which looks harmless.
Author
Owner

@⁠Desamodeth on GitHub · 2026-11-27 06:51 UTC · original · reviewed

Independent RTX 5070 + WARP verification and head-to-head Release benchmark against main (63bcca43) and competing PR #2971 (ba430844) — synthetic fixtures only, no game files.

Test & Lint Verification (28fde825)

  • cargo clippy --locked -p victory-gpu --lib --tests -- -D warnings (default and --features diagnostics): clean; cargo xtask policy: 191 files ok.
  • RTX 5070 (Windows 11, Ryzen 7 9800X3D, --test-threads=1): descriptor:: 21/22 passed (only failure is the pre-existing NVIDIA 1M view-heap cap assertion in dynamic_slots_are_held_until_released, identical to main), bindless:: 3/3 passed.
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics, --test-threads=1): descriptor:: 22/22 passed, bindless:: 3/3 passed.
  • Verified out-of-bounds keep(count + dynamic, Some(...)) is ignored and evict() removes only matching texture slots while keeping non-matching textures and buffer-with-shadow slots.

Deterministic kept Memory & Crossover (RTX 5070 1M-slot heap: count=934,464, dynamic=65,536)

size_of::<Kept>() on main is 16 B (non-null niche on ID3D12Resource); HashMap<u32, KeptEntry> buckets are 24 B + 1 B ctrl = 25 B/bucket (7/8 max load).

Live slots main (Vec<Kept>) #3456 (HashMap) Delta
0 (empty) 16,000,000 B (15.26 MiB) 0 B -100.0%
1,000 (0.1%) 16,000,000 B (15.26 MiB) 51,200 B (50 KiB) -99.7%
50,000 (5.0%) 16,000,000 B (15.26 MiB) 1,638,400 B (1.56 MiB) -89.8%
130,000 (13.0%) 16,000,000 B (15.26 MiB) 6,553,600 B (6.25 MiB) -59.0%
458,752 (45.9%) 16,000,000 B (15.26 MiB) 13,107,200 B (12.50 MiB) -18.1%
458,753 (crossover) 16,000,000 B (15.26 MiB) 26,214,400 B (25.00 MiB) +63.8%
1,000,000 (100%) 16,000,000 B (15.26 MiB) 52,428,800 B (50.00 MiB) +227.7%
Post-clear (1M -> 0) 16,000,000 B (15.26 MiB) 52,428,800 B (50.00 MiB) never shrinks

(On an uncapped 2.36M-slot AMD/WARP heap, main is 36.00 MiB and the crossover is 917,505 live slots = 38.9% occupancy.)

Interleaved Release Timings (RTX 5070, 5 forward+reverse pairs = 10 runs each, median [min..max])

Workload (1M heap) main (63bcca43) #3456 (28fde825) Delta
HostHeap::new(false, 1M) 11,186.6 us [10,781..12,248] 9,988.9 us [9,538..10,483] -10.7%
evict() scan, 1k live (0 hits) 1,065.5 us [1,033..1,096] 2.24 us [2.23..2.49] -99.8% (476x)
evict() scan, 130k live (0 hits) 1,275.0 us [1,241..1,310] 584.2 us [579.8..586.7] -54.2% (2.18x)
evict() 500 hits, 130k live 1,448.2 us [1,440..1,476] 707.1 us [703.3..719.0] -51.2% (2.05x)
evict() scan, 500k live (0 hits) 2,185.6 us [2,160..2,241] 2,820.4 us [2,809..2,877] +29.0% slower
keep() 50k overwrites (130k live) 1,416.6 us [1,358..1,652] 1,661.0 us [1,583..1,856] +17.2% (+4.9 ns/op)
keep() 50k remove+insert churn 1,708.5 us [1,693..1,728] 2,469.4 us [2,439..2,506] +44.5% (+15.2 ns/op)
textures_at() 4,096 slots (130k live) 4.28 us [3.82..4.50] 33.11 us [32.23..34.51] +674% (+7.0 ns/slot)

Summary vs #2971

  • No correctness issues found. Compared to competing #2971, #3456 is narrower and strictly cleaner on locking: keep() retires the old ID3D12Resource and drops Arc<Shadow> outside self.kept.lock() (avoiding lock nesting with host::RETIRED / Shadow::drop, and avoiding a second map lookup under --features diagnostics).
  • Main trade-off: Strong RAM and evict() wins up to ~230k-458k live slots on a 1M heap; above 45.9% occupancy HashMap uses more RAM and scans slower than dense Vec, never shrinks after peak, and pays SipHash cost on keep() overwrites (+4.9 ns/op), churn (+15.2 ns/op), and textures_at() (+7.0 ns/slot). A non-cryptographic u32 hasher would shrink the per-op regression without adding complexity.

AI-assisted with Gemini 4 Neon.

**@⁠Desamodeth** on GitHub · 2026-11-27 06:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/3456#pullrequestreview-6084527624) · **reviewed** Independent RTX 5070 + WARP verification and head-to-head Release benchmark against `main` (`63bcca43`) and competing PR #2971 (`ba430844`) — synthetic fixtures only, no game files. ### Test & Lint Verification (`28fde825`) - `cargo clippy --locked -p victory-gpu --lib --tests -- -D warnings` (default and `--features diagnostics`): clean; `cargo xtask policy`: 191 files ok. - **RTX 5070** (Windows 11, Ryzen 7 9800X3D, `--test-threads=1`): `descriptor::` **21/22 passed** (only failure is the pre-existing NVIDIA 1M view-heap cap assertion in `dynamic_slots_are_held_until_released`, identical to `main`), `bindless::` **3/3 passed**. - **WARP** (`VICTORY_D3D12_WARP=1`, `--features diagnostics`, `--test-threads=1`): `descriptor::` **22/22 passed**, `bindless::` **3/3 passed**. - Verified out-of-bounds `keep(count + dynamic, Some(...))` is ignored and `evict()` removes only matching texture slots while keeping non-matching textures and buffer-with-shadow slots. ### Deterministic `kept` Memory & Crossover (RTX 5070 1M-slot heap: `count=934,464`, `dynamic=65,536`) `size_of::<Kept>()` on `main` is `16 B` (non-null niche on `ID3D12Resource`); `HashMap<u32, KeptEntry>` buckets are `24 B + 1 B` ctrl = `25 B/bucket` (`7/8` max load). | Live slots | `main` (`Vec<Kept>`) | `#3456` (`HashMap`) | Delta | |---:|---:|---:|---:| | 0 (empty) | 16,000,000 B (15.26 MiB) | 0 B | -100.0% | | 1,000 (0.1%) | 16,000,000 B (15.26 MiB) | 51,200 B (50 KiB) | -99.7% | | 50,000 (5.0%) | 16,000,000 B (15.26 MiB) | 1,638,400 B (1.56 MiB) | -89.8% | | 130,000 (13.0%) | 16,000,000 B (15.26 MiB) | 6,553,600 B (6.25 MiB) | -59.0% | | 458,752 (45.9%) | 16,000,000 B (15.26 MiB) | 13,107,200 B (12.50 MiB) | -18.1% | | **458,753 (crossover)** | **16,000,000 B (15.26 MiB)** | **26,214,400 B (25.00 MiB)** | **+63.8%** | | 1,000,000 (100%) | 16,000,000 B (15.26 MiB) | 52,428,800 B (50.00 MiB) | +227.7% | | Post-clear (1M -> 0) | 16,000,000 B (15.26 MiB) | 52,428,800 B (50.00 MiB) | never shrinks | *(On an uncapped 2.36M-slot AMD/WARP heap, `main` is `36.00 MiB` and the crossover is `917,505` live slots = `38.9%` occupancy.)* ### Interleaved Release Timings (RTX 5070, 5 forward+reverse pairs = 10 runs each, median [min..max]) | Workload (1M heap) | `main` (`63bcca43`) | `#3456` (`28fde825`) | Delta | |---|---:|---:|---:| | `HostHeap::new(false, 1M)` | 11,186.6 us `[10,781..12,248]` | 9,988.9 us `[9,538..10,483]` | **-10.7%** | | `evict()` scan, 1k live (0 hits) | 1,065.5 us `[1,033..1,096]` | 2.24 us `[2.23..2.49]` | **-99.8% (476x)** | | `evict()` scan, 130k live (0 hits) | 1,275.0 us `[1,241..1,310]` | 584.2 us `[579.8..586.7]` | **-54.2% (2.18x)** | | `evict()` 500 hits, 130k live | 1,448.2 us `[1,440..1,476]` | 707.1 us `[703.3..719.0]` | **-51.2% (2.05x)** | | `evict()` scan, 500k live (0 hits) | 2,185.6 us `[2,160..2,241]` | 2,820.4 us `[2,809..2,877]` | **+29.0% slower** | | `keep()` 50k overwrites (130k live) | 1,416.6 us `[1,358..1,652]` | 1,661.0 us `[1,583..1,856]` | **+17.2%** (+4.9 ns/op) | | `keep()` 50k remove+insert churn | 1,708.5 us `[1,693..1,728]` | 2,469.4 us `[2,439..2,506]` | **+44.5%** (+15.2 ns/op) | | `textures_at()` 4,096 slots (130k live) | 4.28 us `[3.82..4.50]` | 33.11 us `[32.23..34.51]` | **+674%** (+7.0 ns/slot) | ### Summary vs #2971 - **No correctness issues found.** Compared to competing #2971, #3456 is narrower and strictly cleaner on locking: `keep()` retires the old `ID3D12Resource` and drops `Arc<Shadow>` **outside** `self.kept.lock()` (avoiding lock nesting with `host::RETIRED` / `Shadow::drop`, and avoiding a second map lookup under `--features diagnostics`). - **Main trade-off:** Strong RAM and `evict()` wins up to ~230k-458k live slots on a 1M heap; above 45.9% occupancy `HashMap` uses more RAM and scans slower than dense `Vec`, never shrinks after peak, and pays SipHash cost on `keep()` overwrites (+4.9 ns/op), churn (+15.2 ns/op), and `textures_at()` (+7.0 ns/slot). A non-cryptographic `u32` hasher would shrink the per-op regression without adding complexity. AI-assisted with Gemini 4 Neon.
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/3456/head:github-bot/gh-3456'
git switch 'github-bot/gh-3456'

Merge

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