GPU: clears of one view in a list share one dynamic slot #2871
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!2871
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2871"
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-25 22:49 UTC · original
r4tedx:gpu/clear-view-one-slot→main· +212 −11 · 2 files · 2 commits · openSplit out of #2619 at the maintainer's triage: this changes
clear_unorderedfor every unordered access clear, the title's own included, so it gets its own review. #2619 and #2620 will be rebased on top of it.What changes
clear_unorderedtook a fresh dynamic slot of the bound view heap on every call and held it until the list was reset. A list that clears the same view many times (a per-pass clear in a loop of passes, or a stand-in after each dispatch of its program) took one slot per clear from the capped heap. When the pool runs out, the draws and dispatches that need dynamic slots after it are dropped.State::clear_view(the resolved view in, whether it was recorded out).clear_unorderedcalls it after it looks up the title's CPU handle, and the test drives it directly. #2619 builds on the same function.Nothing else changes: the clear's barriers, the heap binding and the Clear call are as before.
Tests
The title was not used in these tests.
draw::tests::clears_of_one_view_in_a_list_share_a_dynamic_slot(WARP): eight clears of one view take one slot, a clear of a second view one more, and a further clear of the first none. A compute pass then reads both views, and each holds its last clear (0x55 and 0x77 at four texels). The slots come back at reset, and a new recording takes one afresh.HostHeap::dynamic_free(tests only) counts the free slots.mainf3578e38:cargo clippy -p victory-gpu --all-targets --locked -- -D warningsand the same with--all-features: both clean.VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked: 244 passed, 0 failed, 1 ignored (an existing benchmark).Note for later: if a change lands that lends each list a run of dynamic slots at once (rather than one slot at a time), this test's count of the heap's free slots has to count out of the list's run instead. We hit that in our play build and fixed the test that way; the slot sharing itself was unaffected.
🤖 Generated with Claude Code
@fuzeofficlal on GitHub · 2026-11-25 23:05 UTC · original
Reviewed and verified
e7169ee6on Windows 11 (RTX 5090 +VICTORY_D3D12_DEBUG=1+ WARP) againstmain(842b0cb):State::clear_slotson(heap_ptr, view.clone(), resource.as_raw() as usize)whilelist.keep(&resource)keeps the hostID3D12Resourcealive for the lifetime of the recorded list guarantees cache misses whenever the bound heap changes, the title rewrites the descriptor slot, or the underlying host texture/shadow is replaced.State::cutandState::resetboth clearclear_slotsin lockstep withfresh_tables/root_slotsand dynamic slot release.draw::tests21/21 (includingclears_of_one_view_in_a_list_share_a_dynamic_slot),descriptor::host::tests14/14,list::tests4/4 passed; WARPdraw::tests21/21 andlist::tests4/4 passed;VICTORY_D3D12_DEBUG=1passed on both RTX 5090 and WARP;cargo clippy(default &diagnostics) 0 warnings;cargo xtask policy(190 files ok).Looks clean and ready to merge.
@r4tedx on GitHub · 2026-11-25 23:10 UTC · original
Thanks, all three of you. @fuzeofficlal, the RTX 5090 run with the debug layer is very useful, since we can only test on WARP here.
@AwsAli05, I've added the test you suggested in
d3f9b11e:draw::tests::a_clear_after_a_cut_takes_a_new_slot_and_the_old_one_stays_held(WARP). One view is cleared twice in a list, the list is cut (State::cutonto a second host list, as a wait does), and the view is cleared twice more. Both segments are submitted in order. It checks that:Results at
d3f9b11eonmainf3578e38: clippy-D warningsclean with and without--all-features;VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked245 passed, 0 failed, 1 ignored. The title was not used in these tests.AI-assisted
@pawrenity on GitHub · 2026-11-25 23:49 UTC · original
VERIFY-2871: verified
d3f9b11e(incl. the new cut test) on NVIDIA GeForce RTX 4070, Windows 11 (default adapter, confirmed viaGetAdapterLuid→EnumAdapterByLuid), basef3578e38.Review: no defects found.
clear_viewmakes the CPU view before taking a slot, so a view the host cannot make no longer leaks a dynamic slot.make_at) only on a cache miss. The key(heap, View, host resource)changes whenever the bound heap, the title's view or the host resource changes, andlist.keep(&resource)holds the resource, so the cached descriptor still names the same view when it is reused.State::reset(*self = State::default()) dropsclear_slotsalong withdynamic, whoseDropreleases the slots.State::cutclearsclear_slotstogether withfresh_tables/root_slotsand releases nothing.Results (
cargo test -p victory-gpu --locked --lib):draw::tests::clears_of_one_view_in_a_list_share_a_dynamic_slotanddraw::tests::a_clear_after_a_cut_takes_a_new_slot_and_the_old_one_stays_held: pass.draw::: 22/22 pass with--features diagnosticsandVICTORY_D3D12_DEBUG=1,--test-threads=1..filter(|_| false)), both fail on the slot count: "eight clears of one view, one slot" (65528 vs 65535) and "one slot before the cut" (65534 vs 65535).descriptor::host::tests::dynamic_slots_are_held_until_released(NumDescriptors >= HEAP_VIEWS) andmemory::tests::lists_share_a_table_and_copies_keep_their_views("past the dynamic slots"). Both also fail alone (--test-threads=1) on basef3578e38and on currentmain63bcca4on this machine, so this PR does not cause them.main63bcca4merges cleanly (auto-merge indraw.rs) and gives 231 passed with the same 2 failures thatmainalready has.cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean.AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-26 04:26 UTC · original
Automated triage for the maintainers.
Merge candidate. Repeated unordered-access clears of one view in one list now share a single dynamic slot via
State::clear_slots, keyed on (view heap,View, host resource), and the host view is made before a slot is taken so a view the host cannot make no longer leaks one. The key is sound (ViewderivesOrd, the resource is kept alive bylist.keep), the cache is cleared inState::cutnext toroot_slots, and the tests check slot counts and the texel values each view holds after its last clear.CI: passing.
Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 22:53 UTC · original · reviewed
Sound: keying clear slots by (heap, view, host resource) and releasing them with the list's dynamic pool gives each cleared view exactly one slot per list — the resource in the key is what makes reuse safe since the list holds it. Clearing on reset matches root_slots' lifetime model. LGTM.
@AwsAli05 on GitHub · 2026-11-25 22:56 UTC · original · reviewed
The focused clear-slot test at
e7169eepassed on Windows with WARP and the D3D12 debug layer requested. The test covers repeated clears, final texel values, and slot release on reset.The patch also clears the lookup cache at a list cut while retaining the slots for the earlier segment. That is an important lifetime boundary for the world-rendering path. A useful follow-up would be to clear the same UAV on both sides of a cut, submit both segments, and verify the clear result and that the old segment's slot stays held until reset.
AI-assisted review and test.
@Dukestar69 on GitHub · 2026-11-26 10:08 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 22/22 passed (includingclears_of_one_view_in_a_list_share_a_dynamic_slotanda_clear_after_a_cut_takes_a_new_slot_and_the_old_one_stays_held).cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 21/21 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly reuses a single dynamic slot for repeated clears of the same view in a command list and allocates a fresh slot after a cut.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 10:52 UTC · original · requested changes
The slot-sharing idea and cut/reset handling are clean, and both new tests (
clears_of_one_view_in_a_list_share_a_dynamic_slotanda_clear_after_a_cut_takes_a_new_slot_and_the_old_one_stays_held) plus all 22draw::testspass on RTX 5090 and WARP underVICTORY_D3D12_DEBUG=1.However, reordering
make_view(view, at)beforevisible.make_at(slot, view)inState::clear_view(crates/victory-gpu/src/draw.rs) introduces a descriptor-identity bug on cache misses that did not exist onmain:Unaligned buffer UAVs (
shadow::for_view→shadow::exact/Arena) can clear the wrong slice silently.main,visible.make_at(slot, &view)ran first, pinningown: Option<Arc<Shadow>>insidevisible.kept[slot], so the subsequentmake_view(&view, at)upgraded the exact same liveWeak<Shadow>inshadow::EXACTand wrote matching(chunk, FirstElement)to both descriptors.make_view(view, at)runs first, andmake_view(crates/victory-gpu/src/descriptor/host.rs:1461) doesmake(view, at).flatten().map(|k| k.0), droppingk.1: Option<Arc<Shadow>>immediately. If no other heap slot currently holds thatexactshadow,Shadow::drop(shadow.rs:694-698) immediately callsarena().give_back(slice)and kills theWeakinEXACTwhileatstill points to the freed Arena offset.ARENAbeforevisible.make_at(slot, view)runs, that unrelated viewv2takesv1's freed offset (e.g. offset0) andvisible.make_at(slot, view)allocates a different offset (e.g.256, or even another Arena chunk).ClearUnorderedAccessViewUint(visible.gpu(slot), at, &resource, ...)on both RTX 5090 and WARP underVICTORY_D3D12_DEBUG=1leavesv1uncleared ([0, 0, 0, 0]) and silently overwritesv2's Arena slice withv1's clear values — with zero D3D12 Debug Layer messages because both slices share the same Arena chunk buffer. (Ifvisible.make_atspills into a new chunk, the GPU and CPU descriptors also disagree on theID3D12Resourceandclear_slotscaches the staleresource.as_raw().)Arenaslice andMARKSrange inmake_view, only to allocate them again invisible.make_at.Concurrent texture eviction/recreation mismatch.
make_view(view, at)andvisible.make_at(slot, view), a concurrent host texture eviction/recreation can causevisible.make_atto populateslotwith a differentID3D12Resource(or a null view) than theresourcewritten intoatand stored inclear_slots.Suggested fix:
On a cache miss, build the view once while retaining
Kept(both theID3D12ResourceandOption<Arc<Shadow>>), and copy the already-created non-shader-visible descriptor fromatintovisible.cpu(slot)viaCopyDescriptorsSimple(storingkeptand the slot's stride/mark/address metadata onvisible). That guarantees bit-for-bit identical GPU and CPU descriptors referencing the same resource and Arena slice, closes both race windows, and avoids creating the UAV twice.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.