GPU: fresh tables past a capped heap's title slots copy views made once per slot #3068
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!3068
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3068"
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?
@r4tedx on GitHub · 2026-11-26 06:13 UTC · original
r4tedx:gpu/overflow-views→main· +597 −18 · 3 files · 3 commits · openWhat changes
On a host that caps its shader-visible view heap (NVIDIA: 1,000,000 descriptors), main keeps 934,464 title slots and 65,536 dynamic ones. A title table that reaches past the title slots is made afresh at every use (
State::tables):make_atcreates each of its views into dynamic slots, every time. In our title run that came to about 30,000 views created a frame on the recording threads.This PR keeps a view for each title slot past the cap, and fresh tables copy those views instead of creating them again.
HostHeap::overflow), with one slot per title slot past the host's. That's 310,720 slots for our title, 32 B each on NVIDIA, about 10 MB of CPU memory. It is not shader-visible, so the host's cap doesn't apply to it. Its size is logged once, when it's made.HostHeap::copy_overflow), each of its slots is compared with the record (view entry, generation) its overflow slot was made from. A view is created only where the record changed. This is the same rule the title slots follow inHostHeap::mirror. The cache is per slot, not per record: the same record in two slots is made twice.CopyDescriptorsSimpleof the whole table into its dynamic slots. Each dynamic slot keeps the host resource, stride, write mark and view address thatmake_atwould have given it. Its ownreadablecalls (transitions, copy refreshes) are unchanged.mirrormakes for title slots (needs_remake).crate::host::retire).VICTORY_OVERFLOW_VIEWS=0restores main's path, with every view made per use. A heap that isn't capped has no overflow heap, so nothing changes there.Files:
descriptor/host.rs(Overflow,copy_overflow,keep_run, the heap's creation);descriptor.rs(views_of: the views of several records under one lock);draw.rs(State::tablescopies where the heap has an overflow heap, else makes views as before; tests).This doesn't depend on any other open PR.
Tests
The title was not used in these tests.
New:
draw::tests::a_table_past_the_title_slots_reads_the_same_views_copied_or_made(WARP). It makes a view heap that keeps 4 of its 16 title slots (a test-only, thread-local override of the title slots kept, as a capped heap would) and runs three checks on a table at title slot 8:make_atdoes.descriptor::host::tests::overflow_views_are_on_unless_switched_off.draw::tests::fresh_tables_made_or_copied_per_1000: a microbench, ignored by default. It times 1,000 fresh tables of 8 three ways: made one by one, copied at first use, and copied with the records unchanged.Results on
main63bcca43(this machine, WARP):cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, and the same with--features diagnostics: both clean.VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked: 248 passed, 0 failed, 2 ignored (the existing benchmark and the new one). Onmainitself: 246 passed, 0 failed, 1 ignored.--ignored --nocapture, WARP, one run), 1,000 tables of 8:In game
Local title data was used for these runs; only counts and timings from the logs are given here.
This was on an RTX 5070, in the title's first open-world area, 10 minutes a run with 0 device removals in either run. OV0 has the overflow heap switched off (
VICTORY_OVERFLOW_VIEWS=0) and OV1 has it on, with everything else the same exe and switches.The play build carries other unmerged changes: our dynamic-slot reclaim (see #688), host copies in video memory, and others. So the absolute numbers aren't main's. The difference between the two runs is this change.
mirrordoes, so it may make a few more views than OV1 did.Related
AI-assisted
🤖 Generated with Claude Code
@r4tedx on GitHub · 2026-11-26 06:44 UTC · original
Head update
67a8692→b40e60b: adds @passerbyyhx's regression testan_overflow_srv_follows_a_replaced_texture_without_a_new_record(draw.rs only, plusSlots::newsplit intoSlots::from_heap; no change to the fix). The title's record and generation stay the same while the placed texture's backing resource is replaced; the overflow copy must remake once and read the new contents.Verified here on WARP: clippy clean;
draw::tests 22 passed, 0 failed, 1 ignored. With the resource-change check disabled, the new test fails (0 remakes, stale texel), so it guards that check. The author also reports RTX 4090 Laptop and full WARP diagnostics results in r4tedx/VIctory#20; those were not re-run here. Synthetic tests only, no title data.AI-assisted
@Dukestar69 on GitHub · 2026-11-26 06:29 UTC · original · approved these changes
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):cargo test -p victory-gpu descriptor::host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released(RTX 5090 & WARP): 15 passed, 0 failed on both (includingoverflow_views_are_on_unless_switched_off). (Pre-existingdynamic_slots_are_held_until_releasedfails on NVIDIA's 1M view-heap cap #1744.)cargo test -p victory-gpu draw::tests -- --test-threads=1(RTX 5090): 21 passed, 0 failed (includinga_table_past_the_title_slots_reads_the_same_views_copied_or_made).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@kotekompotek on GitHub · 2026-11-26 06:36 UTC · original · approved these changes
Verified the whole path: Overflow CPU heap keyed by generation<<32|index (NULL=no view, 0=unmakeable->retried), placed_texture_moved factored correctly out of mirror, shards locked in index order, CopyDescriptorsSimple under the shard locks, retired kept go through host::retire post-unlock, keep_run/set_stride/set_mark/note_address mirror make_at's bookkeeping, graceful None fallback to one-by-one. views_of batches the VIEWS lock with the same tag+generation check. End-to-end test discriminates made=1/copied=0 and verifies actual dispatch writes.
@fuzeofficlal on GitHub · 2026-11-26 08:12 UTC · original · requested changes
Tested locally on Windows 11 x64 (
rustc 1.98.1, NVIDIA GeForce RTX 5090 + WARP):cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default and--all-features): clean.descriptor::host::tests(15 passed, skipping pre-existing NVIDIA cap testdynamic_slots_are_held_until_released),draw::tests(22 passed, 1 ignored). Microbench (fresh_tables_made_or_copied_per_1000): 8.5 ms one-by-one vs 7.0 ms first copy vs 2.8 ms unchanged copy.--features diagnostics,VICTORY_D3D12_WARP=1):descriptor::host::tests(16 passed),draw::tests(22 passed, 1 ignored). Microbench: 10.0 ms one-by-one vs 10.6 ms first copy vs 3.6 ms unchanged copy.cargo xtask policy: 191 files ok.One real bug in texture eviction handling should be fixed before merge:
HostHeap::evictdoes not evictself.overflow(crates/victory-gpu/src/descriptor/host.rs)When
crate::resource::give_upevicts a host texture (resource.rs:1687-1709), it callsHostHeap::evict(&raws)and clearsresource(r).host = None. BecauseHostHeap::evictonly walksself.keptand never touchesself.overflow:Overflow'sOver.keptretains a strongID3D12ResourceCOM reference to every evicted texture viewed through an overflow slot until a different title record overwrites that slot, keeping its VRAM pinned.< self.count),HostHeap::evictclearsself.kept[index] = None, which causesHostHeap::mirror'sneeds_remake()(let Some(held) = held else { return true; }) to remake the view on the next draw. Incopy_overflow, however,slot.keptis stillSome(old_evicted_tex)andmoved()only checksis_placed_texture(v). On the next draw of an evicted regular texture (View::Shader(r, ..)/View::Unordered(r, ..)),slot.key == keymatches andmoved()returnsfalse, socopy_overflowcopies the stale descriptor pointing to the old evictedID3D12Resource(made == 0), whiledraw.rs'sreadable()recreates a freshHostTextureand uploads the title bytes into the new resource. The shader then keeps sampling the stale evicted texture.Fix: in
HostHeap::evict, also walkself.overflowshards—whenslot.keptmatchestextures(withk.1.is_none()), clearslot.kept = None, resetslot.key = 0(so the nextcopy_overflowremakes it), andcrate::host::retirethe replacedID3D12Resourceafter dropping the shard lock. Lock ordering stays clean (HostHeap::evictruns underSHADER_HEAPS, andcopy_overflownever acquiresSHADER_HEAPS). Adding a regression test mirroringa_texture_given_up_is_made_again_with_its_bytes_and_recorded_lists_keep_itthrough an overflow slot (evict withresource::give_up_now, mutate title bytes, re-copy and assertmade == 1+ updated texel readback) will cover this directly.Minor non-blocking notes:
keep_runomits the#[cfg(feature = "diagnostics")] crate::resource::life::note(...)tracking present inHostHeap::keep.copy_overflow,first.checked_add(n).is_none_or(|end| end > self.count + self.dynamic)avoids relying on caller-guaranteed non-overflow forfirst + n.@r4tedx on GitHub · 2026-11-26 08:23 UTC · original
Thanks @fuzeofficlal for the careful review and the RTX 5090 numbers.
You were right. I checked it in the code before changing anything.
HostHeap::evictwalked onlyself.kept(title and dynamic slots), neverself.overflow.resource::give_upgave up a regular (non-placed) texture, the overflow slot still held the oldID3D12Resource, so its video memory stayed pinned.moved()only looks at placed textures. Socopy_overflowcopied the stale view (made == 0), whilereadablemade the texture again from title memory, and the shader read the one given up.The regression test you suggested shows it: without the fix it fails at "made again: its texture was given up" (left 0, right 1).
The fix (
6b42656a, on top ofb40e60b3):HostHeap::evictnow also walks the overflow shards. A slot holding a given-up texture (k.1.is_none()and in the set) drops it and clears its key, so the nextcopy_overflowmakes the view again, of the texture made again.descriptor::evicttakesSHADER_HEAPS, then each shard.copy_overflowtakes shards and neverSHADER_HEAPS, and nothing it calls while holding them (make_marked) reachesSHADER_HEAPS. Eviction runs on the submitting thread before a submission (resource::evict_unused), not from view creation.keep_runnow has the same#[cfg(feature = "diagnostics")] crate::resource::life::note(...)askeep.copy_overflowbounds its dynamic slots withfirst.checked_add(n).is_none_or(|end| end > self.count + self.dynamic).The test.
draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_again, modelled ona_texture_given_up_is_made_again_with_its_bytes_and_recorded_lists_keep_it:resource::give_up_now.It fails without the fix and passes with it.
Testing (WARP, Windows 11):
cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without--features diagnostics: clean.VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1: 250 passed, 0 failed, 2 ignored. That includes the new test,an_overflow_srv_follows_a_replaced_texture_without_a_new_recordanda_table_past_the_title_slots_reads_the_same_views_copied_or_made.The title was not used in these tests.
AI-assisted
@Marvisak on GitHub · 2026-11-26 08:23 UTC · original
Automated triage for the maintainers.
Verdict: needs work. The overflow heap is a reasonable approach and the record-key and placed-texture checks match
HostHeap::mirror. One interaction with texture eviction is missing, though.crate::resource::give_up→descriptor::evict→HostHeap::evict(descriptor/host.rs) nulls every slot whosekeptholds a given-up host texture, so the texture can be freed and is made again on the next read. The newOverflowslots keep their ownOver.kept, whichHostHeap::evictnever walks. So any overflow slot that last viewed a given-up texture keeps it alive until that slot is used again, which may be never. Under the card's budget (BUDGET_HIGH), that memory doesn't come back. The overflow slot's key also stays the same, so on its next use it is copied without being made again.placed_texture_movedcatches that case for placed textures only; a non-placed evictable texture would be viewed stale.HostHeap::evictalso clear overflow slots that hold one of the textures (null view,key = 0, kept retired). Add a test that gives up a texture viewed through an overflow slot and checks that it is released and made again at the nextcopy_overflow.CI:
checkpassing onb40e60b. The default-on switch (VICTORY_OVERFLOW_VIEWS) and the measured gain are noted; this is not a judgement on the approach.Generated by Claude Code
@r4tedx on GitHub · 2026-11-26 08:24 UTC · original
For triage's point (written at
b40e60b3): it's addressed in6b42656a, as described in the reply above.HostHeap::evictnow walks the overflow shards too. A slot holding a given-up texture has its key cleared and what it kept retired, after the shard's lock is dropped.draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_again. It gives up a texture viewed through an overflow slot (resource::give_up_now), changes its title bytes, copies the table again, and checks that the view is made again (one view made) and that the new texel is read back. Without the fix it fails ("made again: its texture was given up", left 0, right 1).The title was not used in these tests.
AI-assisted
@fuzeofficlal on GitHub · 2026-11-26 08:51 UTC · original · approved these changes
All three points from the earlier review are cleanly addressed in
6b42656a:HostHeap::evictnow callsevict_overflowafter droppingmade, clearing(slot.key, slot.mark)and retiring evictedID3D12Resourcehandles outside the shard locks. Lock ordering (SHADER_HEAPS-> individual shards inevict_overflow, ascending shards withoutSHADER_HEAPSheld acrossCopyDescriptorsSimpleincopy_overflow, andretire/keep_runafter dropping shards) is deadlock- and race-free, and sinceOver::NULL == u64::MAXand valid generations start at 1,key = 0guarantees the CPU descriptor is rebuilt before the next copy.keep_runlogsresource::life::noteunderdiagnostics, matchingHostHeap::keep, andcopy_overflowuseschecked_addfor the dynamic-slot bound check.draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_againdirectly exercises the eviction -> rewrite -> remake -> readback path.Verified locally on Windows 11 (RTX 5090 + WARP + D3D12 Debug Layer):
cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features): cleandescriptor::22/22 passed (skipping the pre-existing NVIDIAdynamic_slots_are_held_until_releasedcap failure),draw::23/23 passed (1 ignored bench)VICTORY_D3D12_DEBUG=1(--features diagnostics):overflow9/9 passed (includingan_overflow_table_reads_a_texture_given_up_as_made_again)VICTORY_D3D12_DEBUG=1(--features diagnostics,VICTORY_D3D12_WARP=1):descriptor::23/23 passed,draw::23/23 passed (1 ignored bench)cargo xtask policy: 191 files okLGTM.
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.