Repository navigation
Conversation
tables() mirrored every non-fresh descriptor-table entry with a separate HostHeap::mirror call, taking the global VIEWS lock plus the heap's made/kept locks once per entry. During a world frame the recording thread contends on VIEWS with every view write on the other title threads, so those per-entry lock round-trips dominate. mirror_draw takes one VIEWS lock, reads every slot once, and one made/kept lock per heap per draw; stale or remake slots still fall through to the full mirror path. draw.rs groups a draw's table entries by host heap and mirrors each heap with a single call. Measured in the new test on Intel Arc B580 (Windows 11), 256 table entries: per-slot 755 us vs mirror_draw 547 us under VIEWS contention (~1.4x); uncontended 585 vs 627 us (clone cost dominates, no lock win). Synthetic tests only; no game data. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
… known parallel-suite flake, NEW-307/NEW-20) Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
AurumCarlos
left a comment
There was a problem hiding this comment.
This overlaps with #3275 (KainanP, open), which takes the same draw-path VIEWS lookups off the registry lock entirely (generation-checked, lock-free reads; with #2821's RwLock and #3274 as companions). mirror_draw goes the other way: it holds VIEWS once 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 redo mirror_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.
|
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 So I'd rather not have this compete with #3275. Three ways to settle it, in the order I'd pick them:
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 |
fuzeofficlal
left a comment
There was a problem hiding this comment.
I tested this on RTX 5090 and WARP with VICTORY_D3D12_DEBUG=1 (35/35 descriptor::host::tests + draw::tests passed 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-2013
mirror_draw_matches_mirror_and_batches_the_locks creates a descriptor heap of N = 256 entries (descriptor::create_heap allocates Memory::zeroed(256 * 32, 64) = 8,192 bytes, valid indices 0..256), and then spawns a contender thread writing at let at = title_heap.start + u64::from(N) * 32; (offset 8,192 — index 256, one slot past the end of the allocation). Every create_placed_srv(..., at) call writes 12 bytes past the end of the allocated heap buffer (and also misses SHADER_HEAPS's (start..end) check in descriptor::mirror). The test heap needs N + 1 slots.
2. mirror_draw misses its fast path on 100% of samplers, null/unkept buffer views, and empty slots
crates/victory-gpu/src/descriptor/host.rs:869, 877
Two 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.- For empty/unwritten slots (
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.kept is now held across crate::resource::host_copy(r)
crates/victory-gpu/src/descriptor/host.rs:761-762, 853, 1267-1287
On main, HostHeap::mirror copied held out of self.kept and dropped the self.kept lock before calling crate::resource::host_copy(r). With needs_remake_kept(&kept, ...), both mirror and mirror_draw hold self.made and self.kept across resource::host_copy(r), which acquires resource.host and can perform D3D12 host texture creation, widening lock contention against textures_at/evict/keep and deepening lock nesting. Extracting only the Option<*mut c_void> raw pointer under self.kept (or checking host_copy after releasing self.kept) avoids holding self.kept across resource creation.
4. Minor: table handle lookup in draw.rs:1278-1279
State::table_entry previously looked up self.heap_of(handle); tables() now uses unchecked table + u64::from(u.table_offset_dwords) * 4 and self.heap_of(table). Using table.checked_add(...) and self.heap_of(handle) keeps overflow safety and matches main.
Dukestar69
left a comment
There was a problem hiding this comment.
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).
|
Closing as superseded, as flagged in @AurumCarlos's review: #3275 (generation-checked reads, no registry lock on the draw path) plus #3405 removes the cost this PR pays once per heap per draw, and #3249 already covers the target-transition clones. Landing this first would only put the What was measured stays on the record: 256 table entries, Intel Arc B580 — per-entry |
What
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 (Test report: RTX 5070 (Blackwell), Windows 11, 70564ae: 471 passed, 5 failed, 7 ignored (4 from the 1,000,000 view heap cap) #1744/Test report: Intel UHD (Raptor Lake Xe-LP), 70564ae: victory-shader 201 passed, 8 failed (3 missing-feature skips, 5 different results) #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)