GPU: store HostHeap::kept sparsely by slot index to save unpopulated slot RAM and speed up evict #3456
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!3456
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3456"
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?
@Luislariosss on GitHub · 2026-11-27 03:11 UTC · original
Luislariosss:feat/sparse-heap-kept→main· +49 −39 · 1 files · 1 commits · openSummary
Stores
HostHeap::keptsparsely (HashMap<u32, KeptEntry>) instead of a denseVec<Option<KeptEntry>>sized tocount + extra:Noneentries per shader-visible view heap (up to ~37 MiB per 2M-slot heap).HostHeap::evict()from a full linear scan over every slot in the heap (0..count + extra) into an iteration over only live populated slots.ID3D12ResourceandArc<Shadow>values outsideself.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.@oni-swr on GitHub · 2026-11-27 03:27 UTC · original
WARP test report (AI-assisted with Claude; synthetic tests only, no game files)
28fde825644cffda7a736dad0b2aa4a7b2eabe7a, base:origin/main@63bcca4(this PR's merge base)VICTORY_WARP=1,VICTORY_D3D12_WARP=1, adapter vendor 0x1414 / software flag), DXIL validatordxil.dllfrom the Windows SDK 10.0.26100VICTORY_D3D12_WARPis only honored with--features diagnostics(host.rscreate()); without itcargo test -p victory-gpu --libpicks 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 15descriptor::host::tests pass)waits_end_on_ticks_and_count_framespassed on both. I did not re-run clippy.Review: no correctness issue found; the
index >= count + dynamicguard keeps the old out-of-range behavior, and the old resource and shadow are now released outside the lock. Trade-off to weigh:keepruns on every descriptor write and now hashes (SipHash) instead of indexing aVec, 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.evictnow visits slots in hash order, which looks harmless.@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.--test-threads=1):descriptor::21/22 passed (only failure is the pre-existing NVIDIA 1M view-heap cap assertion indynamic_slots_are_held_until_released, identical tomain),bindless::3/3 passed.VICTORY_D3D12_WARP=1,--features diagnostics,--test-threads=1):descriptor::22/22 passed,bindless::3/3 passed.keep(count + dynamic, Some(...))is ignored andevict()removes only matching texture slots while keeping non-matching textures and buffer-with-shadow slots.Deterministic
keptMemory & Crossover (RTX 5070 1M-slot heap:count=934,464,dynamic=65,536)size_of::<Kept>()onmainis16 B(non-null niche onID3D12Resource);HashMap<u32, KeptEntry>buckets are24 B + 1 Bctrl =25 B/bucket(7/8max load).main(Vec<Kept>)#3456(HashMap)(On an uncapped 2.36M-slot AMD/WARP heap,
mainis36.00 MiBand the crossover is917,505live slots =38.9%occupancy.)Interleaved Release Timings (RTX 5070, 5 forward+reverse pairs = 10 runs each, median [min..max])
main(63bcca43)#3456(28fde825)HostHeap::new(false, 1M)[10,781..12,248][9,538..10,483]evict()scan, 1k live (0 hits)[1,033..1,096][2.23..2.49]evict()scan, 130k live (0 hits)[1,241..1,310][579.8..586.7]evict()500 hits, 130k live[1,440..1,476][703.3..719.0]evict()scan, 500k live (0 hits)[2,160..2,241][2,809..2,877]keep()50k overwrites (130k live)[1,358..1,652][1,583..1,856]keep()50k remove+insert churn[1,693..1,728][2,439..2,506]textures_at()4,096 slots (130k live)[3.82..4.50][32.23..34.51]Summary vs #2971
keep()retires the oldID3D12Resourceand dropsArc<Shadow>outsideself.kept.lock()(avoiding lock nesting withhost::RETIRED/Shadow::drop, and avoiding a second map lookup under--features diagnostics).evict()wins up to ~230k-458k live slots on a 1M heap; above 45.9% occupancyHashMapuses more RAM and scans slower than denseVec, never shrinks after peak, and pays SipHash cost onkeep()overwrites (+4.9 ns/op), churn (+15.2 ns/op), andtextures_at()(+7.0 ns/slot). A non-cryptographicu32hasher would shrink the per-op regression without adding complexity.AI-assisted with Gemini 4 Neon.
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.