victory-gpu: opt-in multi-queue async compute and copy timeline engine #266
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!266
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-266"
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?
@Vladimir-Human on GitHub · 2026-11-27 12:57 UTC · original
Vladimir-Human:feat/async-timeline-multi-queue→main· +4928 −98 · 3 files · 2 commits · openSummary
Adds an opt-in (
VICTORY_ASYNC_COMPUTE=1, off by default, A/B-able underdiagnostics) multi-queue GPU timeline engine (crates/victory-gpu/src/async_timeline.rs) wired minimally intocrates/victory-gpu/src/host.rsandcrates/victory-gpu/src/lib.rs, complementing the existingVICTORY_ASYNC_SUBMIT=1pipeline inqueue/behind.rs.Architecture & Soundness
D3D12_COMMAND_LIST_TYPE_COMPUTEandD3D12_COMMAND_LIST_TYPE_COPYqueues paired with reusable per-queue command allocator/list pools (QueueEngine) and per-queueID3D12Fencetimelines.ID3D12FenceafterExecuteCommandLists, and consumer queues issueID3D12CommandQueue::WaitbeforeExecuteCommandListswith zero CPU fence waits in the submission loop. All cross-queue buffers strictly obey D3D12D3D12_RESOURCE_STATE_COMMONimplicit promotion/decay rules (0D3D12 Debug Layer warnings or errors).HazardTracker: Enforces RAW, WAR, and WAW GPU waits across Direct, Compute, and Copy under a single lock order (hazardsouter ->compute/copy/direct_sentinner) viaexecute_direct_trackedandexecute_slot_tracked, eliminating TOCTOU races between submitting and relay-landing threads.host.rs):CARD_COMPARErehash passes and post-title-list compare passes onto the async compute queue, using a dedicated 256-byte compute-only dummy UAV buffer for mode-0 rehash sowork.differs.0is never aliased across queues.syncso preparation errors fall back cleanly to Direct inline rehash, and fails fast on dispatch/synchronization errors instead of leaving hashes or compare flags stale.declared,picked.written,picked.looked, and fallback Direct compare resources (CardPlan::differs_key) throughexecute_direct_tracked.submit_upload_bounce) on the async copy queue (CopyBufferRegionstaging -> VRAM bounce + GPU-sidedirect_queue->Wait).ExecuteCommandListsslots inQueueEngine::abandonedwithout advancingsent, peeks before popping onacquire_openCPU waits so live_keepCOM resources are never prematurely dropped on error, and rejectsu64::MAXfence values inwait_fence_cpu.Multi-Queue Overlap Benchmark (
ID3D12QueryHeap+ Wall Clock)4 flights x 48 MiB staging->VRAM DMA upload on Copy + concurrent Direct compute + 16x
CARD_COMPAREon Async Compute vs serialized Direct queue (bit-exact checksum parity0xadaa30e5):wall=22.72 ms | GPU=22.34 mswall=12.08 ms | GPU_union=11.84 ms9.12 ms1.88x (+88.1%)/1.89x (+88.7%)diagnostics(VICTORY_D3D12_DEBUG=1)wall=24.01 ms | GPU=23.14 mswall=13.17 ms | GPU_union=11.65 ms10.24 ms1.82x (+82.3%)/1.99x (+98.6%)diagnostics(VICTORY_D3D12_DEBUG=1, 2 MiB/flight)wall=42.48 ms | GPU=34.14 mswall=36.98 ms | GPU_union=26.44 ms17.36 ms1.15x (+14.9%)/1.29x (+29.1%)(Independent re-run also confirmed
wall=1.76x / GPU=1.78xon default HW,wall=1.75x / GPU=1.79xon HW diagnostics, andwall=1.30x / GPU=1.35xon WARP diagnostics, all with0D3D12 debug errors.)Verification
cargo clippy -p victory-gpu -- -D warnings,--all-targets, and--features diagnostics --all-targets: 0 warnings.cargo xtask policy --staged&cargo test -p xtask: pass (11/11);git diff --checkclean.NVIDIA GeForce RTX 4070 SUPER,VICTORY_D3D12_DEBUG=1,--test-threads=1):async_timeline(default &--features diagnostics): 10/10 passed (0D3D12 debug errors/warnings; includes 8-flight Copy->Compute->Direct->Readback ordering with0CPU waits in submit loop, RAW/WAR/WAW hazard stress, bit-for-bit async vs DirectCARD_COMPARE, 2-thread 24-round Direct-write vs Copy-readback stress with0torn reads,u64::MAXguard, and calibrated overlap benchmark).VICTORY_ASYNC_COMPUTE=1:host::relay_tests3/3,host::late_tests3/3,queue::behind5/5.Microsoft Basic Render Driver,VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_WARP=1,--test-threads=1):async_timeline(--features diagnostics): 10/10 passed (0D3D12 debug errors/warnings).@TaynanGT on GitHub · 2026-11-27 13:01 UTC · original
@Vladimir-Human The checksum comparison is a useful control for queue overlap. I’ll check cross-queue resource lifetime on the fallback and signal-failure paths, especially that a consumer waits for the producing queue and the allocator is kept through completion. The synthetic overlap result can sit alongside a separate in-game A/B.
Address CI diagnostics failure and cross-queue resource lifetime review: - CI benchmark & software-adapter detection (`async_timeline.rs`): - Mark `benchmark_multi_queue_overlap_vs_serialized_direct` `#[ignore = "hardware multi-queue overlap benchmark"]` so headless CI runs do not run multi-hundred-MiB hardware overlap timing on CPU WARP. - Detect software adapters robustly via `DXGI_ADAPTER_FLAG_SOFTWARE`, `VendorId == 0x1414`, `"basic render"` adapter description, `VICTORY_D3D12_WARP=1`, and safe default `true` on DXGI query failure. - Cross-queue lifetime & ordering on signal-failure and fallback paths: - Track un-signaled producer queues/resources in `HazardTracker` and `DirectState`/`QueueEngine::needs_seal` when `Signal` fails after `ExecuteCommandLists`. Before any cross-queue consumer runs, attempt a recovery `Signal` on the FIFO producer queue (sealing `abandoned` allocators/resources into `in_flight` at `seal_val` and forcing `ConsumerQueue->Wait(producer_fence, seal_val)`); if sealing fails, refuse consumer execution before `ExecuteCommandLists`. - Distinguish pre-execute vs post-execute Copy failures in `submit_upload_bounce` so active bounce buffers are never recycled into the pool after a post-execute `Signal` failure; fall back to `wait_cpu` on `wait_on_gpu` failure and abandon/pin the bounce buffer (returning `None`) if `wait_cpu` also fails. - Track Direct `sync` bounce reads in `host.rs` (`sync_reads` + `BounceHandle::note_direct_consumer`) and route `relay_card_back` Direct fallback through `execute_direct_tracked` when `AsyncTimeline` exists. - Retain unconfirmed slots/resources on live-device `Drop`, avoid double-closing or recycling broken slots on record/reset errors, and add 3 HW/WARP/GBV D3D12 regression tests covering injected Compute, Copy, and Direct Signal/Wait failures plus Direct fallback.@Vladimir-Human on GitHub · 2026-11-27 14:07 UTC · original
@TaynanGT Thanks for reviewing! Pushed
49de7774addressing both the cross-queue fallback/signal-failure lifetime paths you called out and the headless CI diagnostics run (all 4/4 checks green on run46012316630):Signalfailure afterExecuteCommandLists(async_timeline.rs):execute_slot_tracked_detailedpins the producingCommandSlot(ID3D12CommandAllocator+ list) and_keepresources inQueueEngine::abandoned(needs_seal = true,sentnot advanced, never returned toidle), and records affected keys viaHazardTracker::mark_unsignaled(protected fromprune).execute_direct_trackedsimilarly retainsDirectState::unsignaled_queue.seal_unsignaled_producers_lockedattempts a FIFO recoverySignal(producer_fence, seal_val). If sealing succeeds,abandonedslots move intoin_flighttagged withseal_val,hazards.seal_queueupgrades their records, and the consumer emitsConsumerQueue->Wait(producer_fence, seal_val)beforeExecuteCommandLists(allocators reclaim only afterfence >= seal_val). If sealing fails, the consumer returnsErrbeforeExecuteCommandListsso it never runs ahead of an un-signaled producer.AsyncTimeline::droprunsseal_all_unsignaled()+ fence drain +reclaim(), and on a live device (GetDeviceRemovedReason().is_ok()) retains any still-unconfirmed slots/resources rather than destroying an active allocator or buffer.async_timeline.rs,host.rs):submit_upload_bouncedistinguishesSubmitSlotError::BeforeExecute(safe to return bounce to pool) fromSignalFailedAfterExecute(keeps bounce pinned incopy.abandoned._keep, never re-pooled, skipson_placed, falls back to Direct staging copy). Ifwait_on_gpufails, it falls back towait_cpu(copy_token); ifwait_cpualso fails, it abandons the bounce inabandoned_resources, skipson_placed, and falls back to Direct.host.rstracks Directsyncbounce reads viasync_reads+BounceHandle::note_direct_consumer(return_bounceconfirms both Copy producer and Direct consumer completed before pooling) and routesrelay_card_backDirect fallback throughexecute_direct_trackedwheneverasync_timeline::existing()isSome(covering Direct fallback andVICTORY_ABoff-toggles).async_timeline.rs):benchmark_multi_queue_overlap_vs_serialized_direct#[ignore = "hardware multi-queue overlap benchmark"]and hardenedadapter_info()to detect software adapters viaDXGI_ADAPTER_FLAG_SOFTWARE,VendorId == 0x1414,"basic render", andVICTORY_D3D12_WARP=1.VICTORY_D3D12_DEBUG=1+VICTORY_D3D12_GBV=1,0debug/GBV errors):signal_failure_retains_allocator_and_seals_for_consumer,direct_signal_failure_blocks_and_seals_async_consumer, andupload_bounce_fallback_on_signal_and_wait_failure_preserves_lifetime.VICTORY_ASYNC_COMPUTEremains opt-in (0by default) and A/B-able viaVICTORY_ABunderdiagnosticsfor an independent runtime A/B comparison.@TaynanGT on GitHub · 2026-11-27 14:25 UTC · original
@Vladimir-Human The seal gives the consumer a fence to wait on after a producer has executed, and the new tests exercise both queue directions. For the gameplay comparison, keep all other switches fixed and capture the Direct, Compute and Copy queue times alongside frame time. The hardware benchmark can stay outside the normal CI run.
@Garu667 on GitHub · 2026-11-27 18:50 UTC · original
Tested on an RTX 3080 10 GB (Series S,
-Machine auto, boat mission autosave, a fresh copy of the save each run, warm caches). One executable:maine45051a+ #266, #249, #268 and #295, all opt-in. Each run covers the cutscenes plus the steady side view on the water.VICTORY_ASYNC_COMPUTE=1VICTORY_GPU_DETILE=1(#249)VICTORY_TEXBACK_PARALLEL=1+VICTORY_BATCH_RETIRE=1(#268, #295)VICTORY_ASYNC_COMPUTE=1(repeat)VICTORY_ASYNC_COMPUTE=1, 2 runs of 2 had no frame over 0.7 s during the cutscenes. Every other run, without it, had at least one 27–102 s stall while the cutscenes stream in. Small sample, but it's the only switch that changed anything here. No crash or card loss in any run.@TaynanGT on GitHub · 2026-11-27 18:53 UTC · original
@Garu667 Both async runs kept the longest frame under 0.7 s, with the median still around 8 FPS. That’s the stall result to follow on this save. A repeat with just async compute flipped and the same warmed executable would give us the comparison alongside the Direct, Compute and Copy queue times.
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.