GPU: store HostHeap kept/made sparsely and allocate strides/marks lazily #2971

Open
github-bot wants to merge 4 commits from github-bot/gh-2971 into main AGit
Owner

@⁠0xKaji on GitHub · 2026-11-26 01:48 UTC · original
0xKaji:perf/sparse-host-heap → main · +126 −80 · 1 files · 4 commits · open

Summary

  • Store HostHeap::kept and HostHeap::made sparsely in HashMap<u32, ...> instead of dense ~1.26M-element Vecs per view heap.
  • Allocate HostHeap::strides and HostHeap::marks upload buffers lazily via OnceLock on first non-null write or root-view bind (matching HostHeap::addresses), avoiding ~26 MiB of upload memory on empty/unused heaps.
  • HostHeap::evict now iterates only occupied entries in kept instead of scanning all 1M+ slots.

Testing

  • cargo xwin check --tests --profile diag -p victory-gpu --features diagnostics --target x86_64-pc-windows-msvc --locked passes cleanly.
  • descriptor::host::tests under Wine (RTX 3060): 15 passed (including new empty_view_heap_defers_stride_and_mark_tables); the 1 failure (dynamic_slots_are_held_until_released) is the pre-existing NVIDIA 1M view heap cap.
  • Tested live in GTA VI (Series S mode) with no regressions.
**@⁠0xKaji** on GitHub · 2026-11-26 01:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2971) `0xKaji:perf/sparse-host-heap` → `main` · +126 −80 · 1 files · 4 commits · open ## Summary - Store `HostHeap::kept` and `HostHeap::made` sparsely in `HashMap<u32, ...>` instead of dense ~1.26M-element `Vec`s per view heap. - Allocate `HostHeap::strides` and `HostHeap::marks` upload buffers lazily via `OnceLock` on first non-null write or root-view bind (matching `HostHeap::addresses`), avoiding ~26 MiB of upload memory on empty/unused heaps. - `HostHeap::evict` now iterates only occupied entries in `kept` instead of scanning all 1M+ slots. ## Testing - `cargo xwin check --tests --profile diag -p victory-gpu --features diagnostics --target x86_64-pc-windows-msvc --locked` passes cleanly. - `descriptor::host::tests` under Wine (RTX 3060): 15 passed (including new `empty_view_heap_defers_stride_and_mark_tables`); the 1 failure (`dynamic_slots_are_held_until_released`) is the pre-existing NVIDIA 1M view heap cap. - Tested live in GTA VI (Series S mode) with no regressions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:58 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:43 UTC · original

Automated triage for the maintainers.

Verdict: needs work. Making the stride and mark tables lazy (strides_buf / marks_buf on a OnceLock, like addresses) is reasonable for view heaps that are never used. The other parts change behaviour on the hottest path in crates/victory-gpu/src/descriptor/host.rs, and the PR gives no measurement for them:

  • made as a HashMap. HostHeap::sync_slots looks up made for every slot it syncs. Its own comment says a world frame looks at about 700,000 slots (~75 ms in run perf3). In the title the heap is dense, so a hash map saves little memory there and turns each indexed load into a hash lookup inside that loop. Please measure sync_slots before and after in a world frame (the diagnostics frame report is enough). If it's slower, keep made dense and make only the unused heaps cheap.
  • The stale-slot filter changed. In sync_slots, None => true became None => current. For a slot not in the map this matches the old m == 0 case. But the old None arm covered indices past made's length, which were always re-synced; now they're skipped unless current. Please confirm first..last never goes past count, or keep the old result for those indices.
  • Null raw views. The raw-view path now writes stride 0 instead of 4 when buffer is None. Translated shaders read the stride table (VIEW_STRIDES), and 0 there means "no buffer view". That changes what a shader sees at a null raw slot, not only memory use. Either keep 4, or say why 0 is right for these shaders and add a test.
  • The claim of a live run with no regressions has no numbers. A frame report from the same scene, before and after, would settle the first point.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2971#issuecomment-7183751555) <!-- victory-triage v1 head=98c38907b1a9ff2ab839463cadbdd248c37edbb2 verdict=needs-work at=2026-11-26T05:43:35Z --> Automated triage for the maintainers. **Verdict: needs work.** Making the stride and mark tables lazy (`strides_buf` / `marks_buf` on a `OnceLock`, like `addresses`) is reasonable for view heaps that are never used. The other parts change behaviour on the hottest path in `crates/victory-gpu/src/descriptor/host.rs`, and the PR gives no measurement for them: - **`made` as a `HashMap`.** `HostHeap::sync_slots` looks up `made` for every slot it syncs. Its own comment says a world frame looks at about 700,000 slots (~75 ms in run perf3). In the title the heap is dense, so a hash map saves little memory there and turns each indexed load into a hash lookup inside that loop. Please measure `sync_slots` before and after in a world frame (the diagnostics frame report is enough). If it's slower, keep `made` dense and make only the unused heaps cheap. - **The stale-slot filter changed.** In `sync_slots`, `None => true` became `None => current`. For a slot not in the map this matches the old `m == 0` case. But the old `None` arm covered indices past `made`'s length, which were always re-synced; now they're skipped unless current. Please confirm `first..last` never goes past `count`, or keep the old result for those indices. - **Null raw views.** The raw-view path now writes stride 0 instead of 4 when `buffer` is `None`. Translated shaders read the stride table (`VIEW_STRIDES`), and 0 there means "no buffer view". That changes what a shader sees at a null raw slot, not only memory use. Either keep 4, or say why 0 is right for these shaders and add a test. - The claim of a live run with no regressions has no numbers. A frame report from the same scene, before and after, would settle the first point. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 02:01 UTC · original · reviewed

Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1) — solid and ready to merge:

  • Sparse HashMap storage for made/kept and lazy OnceLock initialization of strides (zero-filled) and marks (0xFF-filled) in crates/victory-gpu/src/descriptor/host.rs preserve all bounds checks (keep, mirror, write_stride, set_mark), sync_slots diffing, retire lifetime handling on overwrite/null, evict, and diagnostics slot inspection.
  • 98c38907 (write_stride(index, if buffer.is_some() { 4 } else { 0 })) cleanly avoids eagerly allocating the strides buffer for null raw buffer views while still zeroing out any previously stored stride when strides already exists.

Local verification:

  • victory-gpu (descriptor::, host::tests::, memory::tests:: with VICTORY_D3D12_DEBUG=1, tested at 638b3353 plus verified 1-line 98c38907 diff): 45/45 passed on both RTX 5090 and WARP (excluding the 2 pre-existing NVIDIA 1M view-heap baseline tests), including empty_view_heap_defers_stride_and_mark_tables
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings (default & --features diagnostics): 0 warnings
  • cargo xtask policy: 191 files ok
**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2971#pullrequestreview-6067561404) · **reviewed** Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`) — solid and ready to merge: - Sparse `HashMap` storage for `made`/`kept` and lazy `OnceLock` initialization of `strides` (zero-filled) and `marks` (`0xFF`-filled) in `crates/victory-gpu/src/descriptor/host.rs` preserve all bounds checks (`keep`, `mirror`, `write_stride`, `set_mark`), `sync_slots` diffing, `retire` lifetime handling on overwrite/null, `evict`, and `diagnostics` slot inspection. - `98c38907` (`write_stride(index, if buffer.is_some() { 4 } else { 0 })`) cleanly avoids eagerly allocating the `strides` buffer for null raw buffer views while still zeroing out any previously stored stride when `strides` already exists. **Local verification**: - `victory-gpu` (`descriptor::`, `host::tests::`, `memory::tests::` with `VICTORY_D3D12_DEBUG=1`, tested at `638b3353` plus verified 1-line `98c38907` diff): **45/45 passed** on both **RTX 5090** and **WARP** (excluding the 2 pre-existing NVIDIA 1M view-heap baseline tests), including `empty_view_heap_defers_stride_and_mark_tables` - `cargo clippy --locked -p victory-gpu --tests -- -D warnings` (default & `--features diagnostics`): 0 warnings - `cargo xtask policy`: 191 files ok
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 02:30 UTC · original · reviewed

Verified the sparse conversion end to end: absence in made/kept now means never-made (matching the old zero entries), the dirty-table filter's Some(_)=>true / None=>current mapping preserves both branches, and keep() gained a bounds check it lacked. Lazy strides/marks is the clever part — write_stride(0)/set_mark(None) early-out before OnceLock creation because a fresh table reads exactly that. The addresses() replay now zero-fills first, covering slots the old dense iteration wrote None into. Real memory win on multi-million-slot heaps.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2971#pullrequestreview-6067773871) · **reviewed** Verified the sparse conversion end to end: absence in made/kept now means never-made (matching the old zero entries), the dirty-table filter's Some(_)=>true / None=>current mapping preserves both branches, and keep() gained a bounds check it lacked. Lazy strides/marks is the clever part — write_stride(0)/set_mark(None) early-out before OnceLock creation because a fresh table reads exactly that. The addresses() replay now zero-fills first, covering slots the old dense iteration wrote None into. Real memory win on multi-million-slot heaps.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 08:50 UTC · original

Independent local verification of head 98c3890 on Windows 11, Rust 1.100.0/MSVC:

  • VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib descriptor::host::tests::empty_view_heap_defers_stride_and_mark_tables — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

Host GPU present: RTX 5060 Laptop (driver 621.24), AMD Radeon 780M; the test ran through WARP. Synthetic inputs only; no game assets or DRM material used. AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-26 08:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2971#issuecomment-7187085964) Independent local verification of head `98c3890` on Windows 11, Rust 1.100.0/MSVC: - `VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib descriptor::host::tests::empty_view_heap_defers_stride_and_mark_tables` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. Host GPU present: RTX 5060 Laptop (driver 621.24), AMD Radeon 780M; the test ran through WARP. Synthetic inputs only; no game assets or DRM material used. AI-assisted (Hy4 flash).
Author
Owner

@⁠0xKaji on GitHub · 2026-11-26 12:09 UTC · original

Addressed all triage points:

  1. Kept HostHeap::made as a dense Vec<u64> (lazily allocated on first mirrored view): sync_slots keeps O(1) indexed lookups on active heaps (0 hashing overhead in the hot loop), while unused view heaps still take 0 bytes.
  2. Preserved sync_slots out-of-bounds behavior: None if i < self.count => current, None => true matches the previous None => true for i >= count and skips unallocated slots below count unless current.
  3. Null raw buffer views (raw_view_at): buffer.is_none() is only used for null fallback/sentinel slots (NULL_BUFFER_VIEW and null raw pairs), where stride 0 ("no buffer view") is accurate and avoids allocating strides on empty heaps. Added an assertion in empty_view_heap_defers_stride_and_mark_tables.
  4. Before/after measurements (GTA VI Series S, 90 s A/B on main vs combined branch): menu FPS remained 30.0 fps (33.3 ms/frame); system memory dropped 1,427 -> 1,407 MB (-20 MB) in menus and 6,622 -> 6,466 MB working set at world load start with 0 FPS regression.
**@⁠0xKaji** on GitHub · 2026-11-26 12:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2971#issuecomment-7191639593) Addressed all triage points: 1. **Kept `HostHeap::made` as a dense `Vec<u64>` (lazily allocated on first mirrored view):** `sync_slots` keeps O(1) indexed lookups on active heaps (0 hashing overhead in the hot loop), while unused view heaps still take 0 bytes. 2. **Preserved `sync_slots` out-of-bounds behavior:** `None if i < self.count => current, None => true` matches the previous `None => true` for `i >= count` and skips unallocated slots below `count` unless `current`. 3. **Null raw buffer views (`raw_view_at`):** `buffer.is_none()` is only used for null fallback/sentinel slots (`NULL_BUFFER_VIEW` and null raw pairs), where stride `0` ("no buffer view") is accurate and avoids allocating `strides` on empty heaps. Added an assertion in `empty_view_heap_defers_stride_and_mark_tables`. 4. **Before/after measurements (GTA VI Series S, 90 s A/B on `main` vs combined branch):** menu FPS remained **30.0 fps (33.3 ms/frame)**; `system memory` dropped **1,427 -> 1,407 MB** (-20 MB) in menus and **6,622 -> 6,466 MB** working set at world load start with **0 FPS regression**.
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/2971/head:github-bot/gh-2971'
git switch 'github-bot/gh-2971'

Merge

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