GPU: deduplicate identical per-list defer_gpu_write declarations #3112
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3114"
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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:29:37Z.
Summary
HostList::defer_gpu_writepreviously pushed a newStep::GpuWriteintoDeferred::copieson every draw or dispatch, even when the same command list repeatedly declared the exact same(shadow, address, len, marked, memory)tuple with no intervening step that writes title memory. In world command lists this appends thousands of redundantStep::GpuWriteentries per frame, repeatingArc::clone,batch.flush()/shadow.writing(...)lock acquisitions inrun_deferred, andHashMapdeduplication work inHost::execute.This change mirrors the existing per-list
Deferred::refresheddeduplication:Deferred::gpu_writes: HashSet<(usize, usize, usize, bool, bool)>keyed by(Arc::as_ptr(shadow) as usize, address, len, marked, memory).markedandmemoryin the key ensures that an earliermarked == truedeclaration never suppresses a subsequentmarked == falsedeclaration (which must flush and take a pre-submit snapshot), and an earliermemory == falsedeclaration never suppresses a subsequentmemory == truedeclaration (which governswithholding()on title-memory misses).Step::GpuWrite(shadow.clone(), ...)intoDeferred::copies, theArc<Shadow>stays alive untilHostList::reset()replacesDeferred, soArc::as_ptr(shadow)cannot alias another copy while ingpu_writes.Deferred::title_written(&mut self)to clear bothrefreshedandgpu_writes, called byHostList::defer_copyandHostList::defer(mergingdefer's twoself.deferred()lock acquisitions into one).HostList::resetcontinues to reset the entireDeferredstruct.Verification
crates/victory-gpu/src/host.rs(host::gpu_write_dedup::*):identical_gpu_writes_deduplicate_until_title_written_or_resetdistinct_marked_and_memory_flags_are_never_collapseddeduped_marked_then_unmarked_and_post_copy_writes_copy_backdeduped_ordinary_then_memory_write_still_withholds_on_misscargo test -p victory-gpu --lib --locked -- host::gpu_write_dedup:: host::batch:: host::withholding::— 6 passed, 0 failed.VICTORY_D3D12_WARP=1):cargo test -p victory-gpu --locked --features diagnostics— 250 passed, 0 failed (1 existing benchmark ignored), verified across 4 consecutive parallel runs.cargo clippy --workspace --all-targets --locked -- -D warningsand--all-features: 0 warnings.cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T08:53:36Z.
Review: APPROVED
Verified on RTX 5090 & WARP against
origin/main(63bcca4):cargo test -p victory-gpu --lib host::gpu_write_dedup:: -- --test-threads=1: 4/4 passed on RTX 5090 and WARP.cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 10/10 passed on RTX 5090 and WARP.cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed on RTX 5090.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly deduplicates identical per-list
defer_gpu_writedeclarations without collapsing distinct marked/memory flags or breaking post-copy/withholding semantics.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T09:19:59Z.
Automated triage for the maintainers.
Needs work: CI is failing. By my reading the change is right.
HostList::defer_gpu_write(crates/victory-gpu/src/host.rs) skips aStep::GpuWritethat repeats an identical(shadow, address, len, marked, memory)declaration untildefer_copy,deferorresetclears the set. Onmain, a repeated step only runsbatch.flush()andShadow::writing, andwritingdoes nothing for a range it already holds. Dropping the repeat therefore only defers a flush that a later step does anyway. The key includesmarkedandmemory, which keeps the snapshot and withholding behaviour. TheArcheld by the first step stops the pointer key from being reused. Please fix the failingcheckjob. Also coordinate with #3113, which adds its ownDeferred::title_written: the merged helper should clearrefreshed,filledandgpu_writes. With CI green this would be a merge candidate.CI:
checkfailing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:48:54Z.
Re-pushed identical tree (
ddcc6267->09cda65e) to re-trigger CI after an unrelated flaky failure indescriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait.Imported from Marvisak/VIctory. Originally posted by yumaste on 2026-11-26T14:09:04Z.
I tested an ordering case on Windows with WARP. A repeated unmarked
Step::GpuWritecan still matter as a flush boundary for a refresh queued since the preceding declaration. A laterStep::Hostcan observe that boundary, for example when reading a shadow in diagnostics.The fixture declares an unmarked write to A, queues a refresh of dirty B, repeats the identical write to A, and reads B in
defer_host. The capture is the byte observed at that step.main63bcca40x220x2209cda650x110x220x220x22I verified a local guard that sets a flag when
Refresh,HeaporMemoryis recorded, and keeps the next unmarked write even when its key is already present. That recorded write clears the flag because it flushes the batch.CopyandRunalso clear it throughtitle_written. The guarded tree passed all 41 tests selected byhost::with diagnostics under WARP, including the four tests from this PR and the reproducer below. The fixture establishes the deferred-ordering difference without any title assets.Regression test for host.rs, inside the existing test module withholding
AI-assisted (Codex).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T16:41:11Z.
Thanks @yumaste for catching this edge case and putting together a minimal reproducer!
Pushed
ccbba392adding aDeferred::pending_refreshguard set whenStep::Refresh,Step::Heap, orStep::Memoryis recorded, cleared ontitle_written(Copy/Run),HostList::reset, and any recorded unmarkedStep::GpuWrite(while leaving it set formarkedwrites, which do not flushBatch). Whilepending_refreshis set, a repeated unmarkeddefer_gpu_writeis still recorded once as a flush boundary before deduplicating subsequent repeats again.Added regression test
host::gpu_write_dedup::repeated_unmarked_write_flushes_pending_refresh_before_host_workcovering theRefresh->defer_hostordering (0x11before fix ->0x22after),markedpreservation,Heap/Memoryqueueing, andCopy/Runclearing, verified on both RTX 5090 and WARP withVICTORY_D3D12_DEBUG=1.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.