gpu: batch descriptor-heap mirroring per draw (HostHeap::mirror_draw) #3391
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!3391
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3391"
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?
@borosf on GitHub · 2026-11-26 21:28 UTC · original
borosf:vibe/mirror-draw-batch-842ca5→main· +221 −38 · 2 files · 2 commits · openWhat
draw.rs::tables()mirrored every non-fresh descriptor-table entry with a separateHostHeap::mirrorcall — one globalVIEWSlock plus onemade/keptlock pair per entry. During a world frame the recording thread contends onVIEWSwith every view write on the other title threads.HostHeap::mirror_draw(&[(u32, u64)]) -> Vec<Option<View>>takes oneVIEWSlock, reads every slot once, and onemade/keptlock per heap per draw. Stale/remake-needed slots fall through to the fullmirror(..., true)path, so semantics are unchanged.tables()groups a draw's entries by host heap and mirrors each heap with one call.Measured (Intel Arc B580, Windows 11, synthetic test, 256 table entries per draw)
Verification
cargo test -p victory-gpu --lib --locked -- --test-threads=1: 231 passed, 2 failed = only the known B580 baseline failures (#1744/#1829), incl. newdescriptor::host::tests::mirror_draw_matches_mirror_and_batches_the_lockscargo clippy -p victory-gpu --all-targets --locked -- -D warningsand--all-features: cleancargo xtask policy: 191 files okNo game data used; synthetic tests only.
claim: mirror_draw batching per draw (posted on #1633, comment 7203605528)
@AurumCarlos on GitHub · 2026-11-26 21:38 UTC · original · reviewed
This overlaps with #3275 (KainanP, open), which takes the same draw-path
VIEWSlookups off the registry lock entirely (generation-checked, lock-free reads; with #2821'sRwLockand #3274 as companions).mirror_drawgoes the other way: it holdsVIEWSonce per draw and reads entries directly. If #3275 lands first, this brings the lock back onto the draw path. If this lands first, #3275 has to redomirror_draw. Worth agreeing with KainanP on one approach in #2586.Also, your own numbers show the uncontended case getting slower (585 → 627 µs). Without #3275 that may be the right trade, but with it the contended win goes away while the clone cost stays.
@borosf on GitHub · 2026-11-26 21:40 UTC · original
Good catch on #3275, and thank you for the honest read of the uncontended number.
You're right that the two overlap in direction: #3275 makes the draw path's view lookups lock-free (generation-checked reads), and
mirror_drawinstead takesVIEWSonce per heap per draw. If #3275 lands, the contended win in this PR is gone — what remains is the per-heapmade/keptbatching, which is a different pair of locks, and the 585 → 627 µs uncontended cost of the extraVecand clone.So I'd rather not have this compete with #3275. Three ways to settle it, in the order I'd pick them:
made/keptbatching still measures a win onceVIEWSis out of the picture (I'd re-measure before asking for review).I'll ask in #2586 which of the three the maintainer and KainanP want, and I won't push this further until there is an answer. If it's 1, closing it is not a problem from my side — the finding is worth more than the commit: the draw path's per-entry
VIEWSround-trips are ~1.4x of the mirror call under contention on this card, and that is what #3275 removes properly.@fuzeofficlal on GitHub · 2026-11-26 21:51 UTC · original · requested changes
I tested this on RTX 5090 and WARP with
VICTORY_D3D12_DEBUG=1(35/35descriptor::host::tests+draw::testspassed on RTX 5090 excluding the known 1M-cap test, 36/36 on WARP; 256-entry timing: 375.8 µs -> 293.7 µs contended / 296.6 µs -> 291.2 µs uncontended on RTX 5090, 322.5 µs -> 303.0 µs contended / 304.3 µs -> 301.7 µs uncontended on WARP).Independently of the coordination with #3275, there are four technical defects that need fixing if this PR moves forward:
1. Heap buffer overflow (out-of-bounds write) in the new test
crates/victory-gpu/src/descriptor/host.rs:1965, 2008-2013mirror_draw_matches_mirror_and_batches_the_lockscreates a descriptor heap ofN = 256entries (descriptor::create_heapallocatesMemory::zeroed(256 * 32, 64)= 8,192 bytes, valid indices0..256), and then spawns a contender thread writing atlet at = title_heap.start + u64::from(N) * 32;(offset 8,192 — index 256, one slot past the end of the allocation). Everycreate_placed_srv(..., at)call writes 12 bytes past the end of the allocated heap buffer (and also missesSHADER_HEAPS's(start..end)check indescriptor::mirror). The test heap needsN + 1slots.2.
mirror_drawmisses its fast path on 100% of samplers, null/unkept buffer views, and empty slotscrates/victory-gpu/src/descriptor/host.rs:869, 877Two issues here:
HostHeap::mirrorguardsneeds_remake_keptbehindis_texture(&view)(host.rs:758), butmirror_draw(host.rs:869) omitsis_texture(v). Because samplers (View::Sampler) and null/refused buffer views never populateself.kept(kept[index] == None),needs_remake_keptreturnstruefor every single one of them (verified live on both RTX 5090 and WARP:is_texture=false kept_is_none=true needs_remake_kept=true), forcing every sampler and null buffer view to miss the fast path and re-enterself.mirror(index, handle, true)— paying both the batched locks and the per-slot locks.view.is_none()andmade[index] == 0),out[at]remainsNone, soif out[at].is_none()(host.rs:877) cannot distinguish a cachedNonehit from a fast-path miss and still callsself.mirror(index, handle, true)on every empty slot. Tracking resolved entries separately (e.g.,Vec<bool>orVec<Option<Option<View>>>) and checking!is_texture(v) || !needs_remake_kept(...)fixes both.3.
self.keptis now held acrosscrate::resource::host_copy(r)crates/victory-gpu/src/descriptor/host.rs:761-762, 853, 1267-1287On
main,HostHeap::mirrorcopiedheldout ofself.keptand dropped theself.keptlock before callingcrate::resource::host_copy(r). Withneeds_remake_kept(&kept, ...), bothmirrorandmirror_drawholdself.madeandself.keptacrossresource::host_copy(r), which acquiresresource.hostand can perform D3D12 host texture creation, widening lock contention againsttextures_at/evict/keepand deepening lock nesting. Extracting only theOption<*mut c_void>raw pointer underself.kept(or checkinghost_copyafter releasingself.kept) avoids holdingself.keptacross resource creation.4. Minor: table handle lookup in
draw.rs:1278-1279State::table_entrypreviously looked upself.heap_of(handle);tables()now uses uncheckedtable + u64::from(u.table_offset_dwords) * 4andself.heap_of(table). Usingtable.checked_add(...)andself.heap_of(handle)keeps overflow safety and matchesmain.@Dukestar69 on GitHub · 2026-11-27 01:28 UTC · original · approved these changes
LGTM — verified on Windows (RTX 5090):
cargo test -p victory-gpu --lib descriptor::passed (22/22, includingmirror_draw_matches_mirror_and_batches_the_locks, skipping the pre-existingorigin/mainRTX 5090 failure)cargo test -p victory-gpu --lib draw::(20/20) andbindless::(3/3) passed on RTX 5090cargo clippy -p victory-gpu --all-targets -- -D warningspassed with 0 warningscargo xtask policypassed (191 files ok)Synthetic tests only (no game files used). AI-assisted (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.