Repository navigation
Conversation
…ce per slot On a capped view heap (NVIDIA, 1,000,000 views) main keeps 934,464 title slots, and every use of a title table past them made its views afresh into dynamic slots: about 30,000 views a frame in our title run. A CPU-only overflow heap now keeps a view for each title slot past the host's (310,720 for that title, 32 B each on NVIDIA, logged at creation). Each is made from the title's record at the slot's first use, and again only when the slot's record changes, as title slots are made when the title writes them. A fresh table makes the views whose records changed there, then copies all of them into its dynamic slots in one CopyDescriptorsSimple. Each dynamic slot keeps, strides and marks as make_at would. A placed texture's overflow slot is made again when its host texture changed, the check mirror makes for title slots (now placed_texture_moved, shared by both); a view the host could not make is tried again at the next use. Locks are taken once per table: the views' registry for the table's records, the overflow shards (1,024 slots each) the table spans, the kept resources. VICTORY_OVERFLOW_VIEWS=0 makes every view per use, as before. Heaps that are not capped have no overflow heap. Tests (WARP): a table past the title slots, copied, writes through its view the buffer the title's record names, and the new one after the title rewrites the slot; unchanged, it is copied without a view made; made one by one, the same buffer. A microbench (ignored by default) times 1,000 fresh tables of 8 both ways. Ported from play/main-overflow-views 203fe02 onto main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dukestar69
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Head update Verified here on WARP: clippy clean; AI-assisted |
fuzeofficlal
left a comment
There was a problem hiding this comment.
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.- RTX 5090:
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. - WARP (
--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::evict does not evict self.overflow (crates/victory-gpu/src/descriptor/host.rs)
When crate::resource::give_up evicts a host texture (resource.rs:1687-1709), it calls HostHeap::evict(&raws) and clears resource(r).host = None. Because HostHeap::evict only walks self.kept and never touches self.overflow:
- VRAM leak:
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. - Stale descriptor for evicted regular (non-placed) textures: For title slots (
< 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 walk self.overflow shards—when slot.kept matches textures (with k.1.is_none()), clear slot.kept = None, reset slot.key = 0 (so the next copy_overflow remakes it), and crate::host::retire the replaced ID3D12Resource after dropping the shard lock. Lock ordering stays clean (HostHeap::evict runs under SHADER_HEAPS, and copy_overflow never acquires SHADER_HEAPS). Adding a regression test mirroring a_texture_given_up_is_made_again_with_its_bytes_and_recorded_lists_keep_it through an overflow slot (evict with resource::give_up_now, mutate title bytes, re-copy and assert made == 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.- In
copy_overflow,first.checked_add(n).is_none_or(|end| end > self.count + self.dynamic)avoids relying on caller-guaranteed non-overflow forfirst + n.
Review of Marvisak#3068 (fuzeofficlal): `HostHeap::evict` walked only the slots' kept resources, never the overflow heap's. When `resource::give_up` gave up a host texture, an overflow slot viewing it kept the old resource alive (its video memory too) until another record took the slot, and since its record had not changed, `copy_overflow` copied its stale view into the next fresh table while `readable` made the texture again from title memory: the shader read the texture given up. `evict` now also walks the overflow shards: a slot holding a texture given up lets go of it (retired once the shard's lock is dropped) and clears its key, so its next use makes the view again, of the texture made again. Lock order: under SHADER_HEAPS, then a shard; `copy_overflow` takes shards without SHADER_HEAPS, and eviction runs on the submitting thread before a submission (`resource::evict_unused`). Also from the review: `keep_run` notes a texture a slot stops viewing, as `keep` does (diagnostics), and `copy_overflow`'s bound on its dynamic slots uses `checked_add`. Test: `an_overflow_table_reads_a_texture_given_up_as_made_again` reads a texture through an overflow table, gives it up, changes its title bytes and copies again: one view made, the new bytes read. It fails without the fix (no view made, left 0, right 1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @fuzeofficlal for the careful review and the RTX 5090 numbers. You were right. I checked it in the code before changing anything.
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 (6b42656, on top of b40e60b):
The test.
It fails without the fix and passes with it. Testing (WARP, Windows 11):
The title was not used in these tests. AI-assisted |
|
Automated triage for the maintainers. Verdict: needs work. The overflow heap is a reasonable approach and the record-key and placed-texture checks match
CI: Generated by Claude Code |
|
For triage's point (written at b40e60b): it's addressed in 6b42656, as described in the reply above.
The title was not used in these tests. AI-assisted |
fuzeofficlal
left a comment
There was a problem hiding this comment.
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): clean- RTX 5090:
descriptor::22/22 passed (skipping the pre-existing NVIDIAdynamic_slots_are_held_until_releasedcap failure),draw::23/23 passed (1 ignored bench) - RTX 5090 +
VICTORY_D3D12_DEBUG=1(--features diagnostics):overflow9/9 passed (includingan_overflow_table_reads_a_texture_given_up_as_made_again) - WARP +
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 ok
LGTM.
What 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
main63bcca4 (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