GPU: store HostHeap kept/made sparsely and allocate strides/marks lazily #2971
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2971
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2971"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@0xKaji on GitHub · 2026-11-26 01:48 UTC · original
0xKaji:perf/sparse-host-heap→main· +126 −80 · 1 files · 4 commits · openSummary
HostHeap::keptandHostHeap::madesparsely inHashMap<u32, ...>instead of dense ~1.26M-elementVecs per view heap.HostHeap::stridesandHostHeap::marksupload buffers lazily viaOnceLockon first non-null write or root-view bind (matchingHostHeap::addresses), avoiding ~26 MiB of upload memory on empty/unused heaps.HostHeap::evictnow iterates only occupied entries inkeptinstead of scanning all 1M+ slots.Testing
cargo xwin check --tests --profile diag -p victory-gpu --features diagnostics --target x86_64-pc-windows-msvc --lockedpasses cleanly.descriptor::host::testsunder Wine (RTX 3060): 15 passed (including newempty_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.@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_bufon aOnceLock, likeaddresses) is reasonable for view heaps that are never used. The other parts change behaviour on the hottest path incrates/victory-gpu/src/descriptor/host.rs, and the PR gives no measurement for them:madeas aHashMap.HostHeap::sync_slotslooks upmadefor 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 measuresync_slotsbefore and after in a world frame (the diagnostics frame report is enough). If it's slower, keepmadedense and make only the unused heaps cheap.sync_slots,None => truebecameNone => current. For a slot not in the map this matches the oldm == 0case. But the oldNonearm covered indices pastmade's length, which were always re-synced; now they're skipped unless current. Please confirmfirst..lastnever goes pastcount, or keep the old result for those indices.bufferisNone. 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.CI: passing (
check).Generated by Claude Code
@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:HashMapstorage formade/keptand lazyOnceLockinitialization ofstrides(zero-filled) andmarks(0xFF-filled) incrates/victory-gpu/src/descriptor/host.rspreserve all bounds checks (keep,mirror,write_stride,set_mark),sync_slotsdiffing,retirelifetime handling on overwrite/null,evict, anddiagnosticsslot inspection.98c38907(write_stride(index, if buffer.is_some() { 4 } else { 0 })) cleanly avoids eagerly allocating thestridesbuffer for null raw buffer views while still zeroing out any previously stored stride whenstridesalready exists.Local verification:
victory-gpu(descriptor::,host::tests::,memory::tests::withVICTORY_D3D12_DEBUG=1, tested at638b3353plus verified 1-line98c38907diff): 45/45 passed on both RTX 5090 and WARP (excluding the 2 pre-existing NVIDIA 1M view-heap baseline tests), includingempty_view_heap_defers_stride_and_mark_tablescargo clippy --locked -p victory-gpu --tests -- -D warnings(default &--features diagnostics): 0 warningscargo xtask policy: 191 files ok@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.
@cloph-dsp on GitHub · 2026-11-26 08:50 UTC · original
Independent local verification of head
98c3890on 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).
@0xKaji on GitHub · 2026-11-26 12:09 UTC · original
Addressed all triage points:
HostHeap::madeas a denseVec<u64>(lazily allocated on first mirrored view):sync_slotskeeps O(1) indexed lookups on active heaps (0 hashing overhead in the hot loop), while unused view heaps still take 0 bytes.sync_slotsout-of-bounds behavior:None if i < self.count => current, None => truematches the previousNone => truefori >= countand skips unallocated slots belowcountunlesscurrent.raw_view_at):buffer.is_none()is only used for null fallback/sentinel slots (NULL_BUFFER_VIEWand null raw pairs), where stride0("no buffer view") is accurate and avoids allocatingstrideson empty heaps. Added an assertion inempty_view_heap_defers_stride_and_mark_tables.mainvs combined branch): menu FPS remained 30.0 fps (33.3 ms/frame);system memorydropped 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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.