GPU: run submissions asynchronously on a host fence timeline (rebase of #595) #1923
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!1923
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1923"
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?
@slatefield on GitHub · 2026-11-25 01:03 UTC · original
slatefield:up-595-rebase→main· +2115 −300 · 16 files · 1 commits · openRebase of #595 onto current
main(4118f33). The original work is wbkepler's; the commit is kept with its author and message, only conflict resolution sits inside it. If #595 is updated first, take that one.Why it is the biggest frame-time change available:
Host::executewaits for every submission before copying back, so a world frame's ~150 submissions are fully serialized and the CPU and GPU never overlap. The author measured, on an RTX 5090 in the world: median 283 -> 267 ms/frame, mean 319 -> 286, GPU wait per frame 79 -> 1 ms, with no device removal over 7-minute runs; a 5070 tester saw 1.8-2.0 -> 2.0-2.5 fps. It also makes a list reset while it runs safe, which is what the title does every frame.The rebase, 5 conflict regions over 3 files:
descriptor.rs:maininlinedshader_slot()away; the PR's heap-id scheme (NEXT_HEAP_ID, id-basedrelease_dynamic) is applied to main's inlined code.host.rsx3: main'sid/ScratchChunkgrowth kept, the PR'sbudget/last/fresh_afterfields and spare-chunk pool added. One design choice: scratch allocation uses the PR'slist_buffer(L0 custom heap) rather than main'supload_buffer, because repeated-list preludesCopyBufferRegioninto scratch and a D3D12 upload-heap resource cannot be a copy destination.shadow.rs: main's newerupdate_busyand the PR'sstale/submission_donekept side by side.executenow callhost.drain(), as tester notes on the PR said.Checked here: Windows-target clippy for
victory-gpuandvictory(and whole workspace) with and without--all-features, clean; native tests green for the crates that build on Linux (shader 144, formats 38, game 15, core 13, pipeline 7);timeline.rsis pure std, compiled and its tests run natively (ordering, signals, conflicts) and pass;cargo xtask policy183 files ok.Not checked, needs a Windows GPU: the 9 new tests and the live numbers. Also worth knowing before merging, from the PR's own review thread:
refresh_conflictignores in-flight GPU reads (a reviewer reproduced it; the author deferred it), the AMD inbox repeated-recording test fails there while WARP passes, and present still drains the frame.ID3D12CommandQueue::Waitis a no-op onmain(queue.rs:167) and the synchronous wait is what hides it today; #32 is the PR that fixesWait, and it is worth landing near this one.If merged as-is, the next bottleneck is CPU preparation (the author measured 148 -> 241 ms, title-memory copies); their note is that shadow buffers in VRAM with GPU dirty tracking is the next target.
@Marvisak on GitHub · 2026-11-25 02:18 UTC · original
Automated triage for the maintainers.
This pull request does not merge cleanly into
main. Conflicting files:crates/victory-gpu/src/host.rs,crates/victory-gpu/src/shadow.rs.It will be reviewed once it is rebased onto the current
main.Generated by Claude Code
@nathanbzrr on GitHub · 2026-11-25 09:40 UTC · original
I put together a tested rebase of #1923 (
4f1228c1) ontomain(940d32f) with the async soundness fixes needed for marked-page copy-backs and an AMD RDNA3 repeat-submission fix:261d75a5404983dd9aac16709718a6fa3665abb5)Conflicts resolved
crates/victory-gpu/src/host.rsandcrates/victory-gpu/src/shadow.rs(the other 14 files from4f1228c1merged cleanly, pluscrates/victory-gpu/src/descriptor/host.rsfor theset_mark/retire_shadowfixes below).victory-shaderchanges were needed:VIEW_WRITES(u1, space2) is already bound per command list via root UAV indraw.rs.Soundness fixes for async submissions + marked-page copy-backs
HostListpooledMarkBitmap(SPARE_MARK_BITMAPS, cap 64): replaces the single globalshadow::BITMAP(HostList::view_writes,Pending::marks,copy_back_marks), preventing CPU/GPU clearing races, lost marks from shader read-before-InterlockedOr, premature copy-backs, and&mut [u32]aliasing.Marksbit recycling:Shadow::dropqueues freed(base, count)runs intoRETIRED_MARKSinstead of callinghost.after(avoidingTimeline::entriesself-deadlock), andHostHeap::keepretires replaced shadows viaretire_shadow;Host::completereleases them after the fence passes.Shadow::pending:Pending::ofandrun_deferredround markedStep::GpuWriteranges to 64 KiB pages,Batch::armeddefersshadow.writing(..., true)until pending refreshes flush,Shadow::pendingis refcounted (HashMap<(usize, usize), u32>),Tracked::disarm_pageclears pages no longer covered by any remaining pending range, andShadow::updaterunsupdate_busyacross the whole tracked range rather than splitting pages.Batch::flushqueriesTimeline::in_flight_writersso clean in-flight writer subranges are skipped (and stale ones settled) instead of racingShadow::update_busy;Timeline::has_subsequent_readerguards host-copy updates (*h = *t) inShadow::copy_back_or_notandShadow::copy_back_marked.Timelinehazard tracking:Step::Heap(viewed, writes)threads UAV write ranges viabindless::refresh_kinds,Step::Memory(heap, writes)tracksstage.memory_dirtywrites, andStep::Indirect(address, len)addstouches.labelsbeforeindirect::bound.set_mark, and queue guards:descriptor::Heap::dropcallshost.drain()before removing fromSHADER_HEAPS;HostHeap::set_markuses a single aligned 64-bitAtomicU64::store(..., Release); added guards aroundExecuteCommandLists(!group.is_empty()),wait_gpu(!e.0.is_invalid()), andHost::drain(release_retired()).ExecuteCommandListscut (Host::execute_inner): ina_repeated_list_reads_its_own_upload_memory, submittinggroups[1] = [prelude, list]immediately behindgroups[0] = [list, between]on RX 7600 causedbetweento be skipped (out2[0] = 0, D3D12 Debug Layer clean, WARP unaffected) because resubmitting an in-flight command list that is not at the tail of itsExecuteCommandListsgroup disturbs the driver's IB2 chaining tail. Cutting the group immediately after any list that repeats later inruns(and before any repeated list) fixes it with zero CPU waits and keepsD3D12_CPU_PAGE_PROPERTY_WRITE_COMBINEonHost::list_buffer.New synthetic concurrent marked-page tests (
host::submissions)overlapping_marked_submissions_on_disjoint_pages_preserve_marks_and_title_writessame_page_marked_submissions_serialize_and_preserve_all_writerslist_reset_while_running_isolates_mark_bitmapsoverlapping_reader_and_title_write_preserve_marked_gpu_and_cpu_bytesdropped_shadow_mark_bits_wait_for_in_flight_submissionVerification (Windows 11 x64, AMD Radeon RX 7600,
dxil.dll10.0.26100.0)cargo xtask policy:asset policy: 182 files okcargo clippy --workspace --all-targets -- -D warnings: passedcargo clippy -p victory-gpu --all-targets --features diagnostics -- -D warnings: passedcargo test -p victory-gpu --lib -- --test-threads=1(RX 7600):157 passed; 0 failed; 2 ignoredcargo test -p victory-gpu --all-features --lib -- --test-threads=1(RX 7600):160 passed; 0 failed; 2 ignoredVICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1(RX 7600 + Debug Layer):160 passed; 0 failed; 2 ignoredVICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1(WARP + Debug Layer):160 passed; 0 failed; 2 ignoredAI-assisted; synthetic tests only, no game files, dumps, or captures used.
@r4tedx on GitHub · 2026-11-25 11:30 UTC · original
I built on @nathanbzrr's rebase of this PR (
261d75a5, onmain940d32f), which carries @slatefield's rebase of @wbkepler's #595, and reviewed it for ordering: copy-back has to come before the title can see GPU writes. Branch:r4tedx/VIctory@async/1923-on-main(974639af). nathanbzrr's commit is kept unchanged as its own commit; two commits sit on top.What holds.
Signal/Signal2Xand null-event fence waits are ordered behind in-flight work. Labels and query results come after copy-back.wait_gpuhandlesWAIT_FAILED, and present, resize and page mappings drain.What I fixed (
974639af). With completion on its own thread, copy-back races the title's submitting thread, which onmainis blocked inExecuteXduring copy-back. There were two windows:shadow.rscopy_back,copy_back_marked,copy_back_page). A title write to a byte the GPU didn't touch, made after the copy-back read the piece, was overwritten. Now only the byte runs the GPU changed are written.taken) with the copy holding title memory as read. A title write in between never reached the copy, so later GPU reads saw old bytes. Now the page is compared again aftertaken, and a page that differs counts as changed.Two synthetic tests (declared ranges and marked pages) place a title write between the read and the write-back. Both fail with the whole-piece write put back, and both fail with the recheck removed.
Opt-in.
8df20658makes async opt-in,VICTORY_ASYNC_SUBMIT=1. By default each submission is finished on the submitting thread beforeexecutereturns, as onmain, and no completion thread starts. Both fixes above apply only in async mode. Happy to drop the switch if you'd rather this be always on.Overlaps.
shadow.rs(onediffering/write-runs helper for both).Tracked::disarm_pagemust use #2147's run-basedarmed(if saved.armed(page) { saved.unarmed.insert(page); }).main: there is one in-order host queue and signals finish in order. #32 adds its owntimeline.rs, though, so landing both will need a merge.Still open.
refresh_conflictstill ignores in-flight GPU reads. As far as I can trace, it changes bytes only when the title writes data an in-flight submission reads (a race on the console too), or in pages whose writes were withheld after a missed read. Async widens that window a lot. Narrowing it by waiting for overlapping readers would serialize most world submissions.Checks.
cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without--features diagnostics, is clean.VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1gives 163 passed, 0 failed, 2 ignored (main: 146 / 0 / 2). Not checked: hardware adapters, the debug layer and frame times. An in-game run with the switch on and off is planned and will follow here.The title was not used in these tests.
AI-assisted
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.