GPU: deduplicate identical per-list defer_gpu_write declarations #3114
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!3114
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@fuzeofficlal on GitHub · 2026-11-26 08:29 UTC · original
fuzeofficlal:perf/gpu-dedup-per-list-gpu-writes→main· +389 −9 · 1 files · 2 commits · openSummary
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.@Dukestar69 on GitHub · 2026-11-26 08:53 UTC · original · approved these changes
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).
@Marvisak on GitHub · 2026-11-26 09:19 UTC · original
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
ddcc62673eto09cda65e0b@fuzeofficlal on GitHub · 2026-11-26 11:48 UTC · original
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.@yumaste on GitHub · 2026-11-26 14:09 UTC · original
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).
@fuzeofficlal on GitHub · 2026-11-26 16:41 UTC · original
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.