Repository navigation
perf(gpu): opt-in Wait-Before-Prep Flight-1 GPU overlap and async submit worker - #447
gdemontalivet wants to merge 2 commits into
Conversation
…async submit worker (VICTORY_ASYNC_SUBMIT=1) Implement Wait-Before-Prep Flight-1 overlap (Phase A, VICTORY_FLIGHT1=1) and a dedicated victory-submit worker thread (Phase B, VICTORY_ASYNC_SUBMIT=1) behind opt-in environment switches (default off): - Move Flight-1 state, launch, background victory-flight finisher thread, signal attachment, and GPU regression tests into host/flight.rs. - Enforce Wait-Before-Prep: finish_flight_locked always drains Flight N-1 (GPU fence wait, Mark check, copy-back, defer_after, BoP writes, upload list return, HostList recycling, and atomic pending_signals delivery) before Flight N touches any shared Shadow, descriptor heap, texture staging pool, or Mark buffer. - Keep Vec<Arc<HostList>> and owned bindless::Uploads inside InFlight so list::restart preserves strong_count > 1 on early title Reset and bindless::LIST / texture::recycle never reset in-flight resources. - Drain any active flight inside Host::quiet() after locking submitted so the GPU is idle during shader-visible descriptor heap creation/null-fill. - Add Held::take_ready / finish_running so victory-submit and Flight-1 never hold HELD across GPU submission, strictly preserving the lock DAG (SUBMIT_DRAIN -> HELD -> Host::submitted -> Host::flight -> Fence::waiters) and draining cleanly at PresentX, CopyPageMappingsBatchX, and sync Host::execute calls.
hackgods
left a comment
There was a problem hiding this comment.
Thanks for this. A single flight with wait-before-prep keeps shadow and snapshot state one submission at a time, which is the hard part. These notes come from reading c67735c and from a trial merge onto a branch that carries more of the open PRs:
- Test isolation.
TEST_FLIGHT1andTEST_ASYNC_SUBMITare process-global (flight.rs:83–121), so other tests running in parallel see the modes flip mid-run. On a branch that also has the BVH/upload tests,list::tests::allocate_upload_survives_early_reset…fails because it expectspump_heldto run synchronously. A test that pumps while holdingHELDdeadlocks throughbefore_sync→drain_submit→held(). Thread-scoped overrides or a serial test binary would fix both. - Bigger pieces under the worker.
take_ready_with(..., false)(queue.rs:307) →take_ready_per_queue(hold.rs:421) joins every ready segment of a queue into one submission. Within one submission, every list's CPU-side steps (stand-in copies, moves, fills, refreshes) run before any of its GPU work. So a later list'sCopyBufferRegioninto a buffer that an earlier list reads on the GPU now lands before that read, where they used to be separate submissions. A gate like #419'scan_join, or a cap, plus a test for that order, would settle it. - A
SetEventOnCompletionwith a null event still returnsE_NOTIMPL(fence.rs:104). With fences now lagging, it returns instead of blocking. None of our runs hit it, but it's now reachable. - Preparing still never overlaps the GPU (
flight.rs:187). The waits that remain (flight.rs:362and the one inexecute_sync) can be used to make the next submission's descriptor-heap sync. We have that as a small separate switch (VICTORY_SYNC_IN_WAIT). It is −19 to −21% in a synthetic test; our in-game numbers are still inside run-to-run noise. It merges with yours with one conflict inhost.rs, so the two compose. - Slot remakes on title threads while a flight is in the air (
make_read, texture upgrades) caused device losses in a Windows fork (avatarmanz3bab23c, held until earlier submissions finish). Exposure grows now that title threads no longer block. VICTORY_ASYNC_SUBMIT=1also turns on Flight-1 (flight.rs:46). Worth a line in the docs.
Prepared with Claude Code; review of the code plus a local trial merge, no game data.
|
Preparing an M5 Pro comparison: could you identify the exact combined commit used for the reported 2.70× run? At I can test this head's actual async/Flight-1 path independently. A pinned combined revision, or a note that the coalescing flag was inert in the measured build, would make the published comparison reproducible. Prepared by GPT-6 Astra from the pinned public source. |
|
M5 Pro (48 GB), macOS 27.2.1, Rosetta + Wine 11.0, mapped D3DMetal 4.0 beta 3: no frame-time improvement in this standalone async/Flight-1 toggle pair. Tested Each run used the same initial-room pose, 20 seconds settling followed by 120 seconds stationary with no manual input. Values below are medians of paired reporting-interval averages; frame time comes from presented-frame wall time, not a sum of the overlapping component counters.
The 1.1% frame-time difference in one sequential pair is not evidence of a general regression or speedup. This does not reproduce the PR description's combined/coalesced workload: as noted above, the pinned standalone head's production call selects Both reached the room with no logged unhandled title exception or Metal completion error. Camera/backward input response was observed after the enabled measurement, but this variant has no full control/stability/relaunch qualification. The control stopped intentionally. The enabled run ended at 601 seconds because I missed renewing the operator's visibility heartbeat during the post-measurement input checks, after the full measurement had completed; the watchdog recovered Wine, the lock and inference. That was an operator-supervision expiry, not a diagnosed title crash. Integration gates: native 600 passed / 0 failed / 17 ignored; serial Wine 1,170 passed / 0 failed / 29 ignored, no SKIPPED lines, including all four Prepared and tested by GPT-6 Astra on Michael's Mac; game artifacts and raw logs stay local. |
|
Tested
One pair, -4%, close to my run-to-run noise, so I would not call it a gain yet; it agrees with the M5 Pro result above. Two cautions from this machine (#442): without timing, 3 of my last 6 runs hung for good (Metal's submission thread stuck in IOGPU), including an earlier run of this same executable with both switches off (~420 s). With both on, the 5 ended command buffers are more than I have seen in any other run (0 to 3), but one run is not enough to blame the overlap. AI-assisted testing. |
|
Correction to my comment above: the old "ended a submission" warning is only logged at powers of two, so the counts were lower bounds. With both switches on it was 4 to 7 command buffers ended, and an earlier run on my lab build with timing on also had 4 to 7. So it is not more than in other runs, and nothing points at the overlap from that. The frame-time result (-4%, near noise) stands. |
|
Thanks for this. Many pull requests landed today, and this one now conflicts with main. Could you merge or rebase main into it, rerun the checks and ping here? I will review and merge it as soon as CI is green. |
Summary
Adds opt-in Wait-Before-Prep single-flight GPU overlap (
VICTORY_FLIGHT1=1) and a dedicated async queue submission worker (VICTORY_ASYNC_SUBMIT=1) so title command recording overlaps with host D3D12/D3DMetal GPU execution while preserving full shadow-buffer, descriptor-heap, staging-pool, and fence ordering invariants:crates/victory-gpu/src/host/flight.rs&crates/victory-gpu/src/host.rs:prepare_submission) and post-GPU completion (finish_post_gpu) cleanly from synchronous execution.VICTORY_FLIGHT1=1, drains FlightN-1completely before FlightNtouches sharedShadow, descriptor-heap, upload-staging, orMarkstate (Wait-Before-Prep), then returns immediately afterExecuteCommandLists+Signalwhile a backgroundvictory-flightfinisher lands GPU copy-backs, bottom-of-pipe writes, and attached fence signals.fence.GetCompletedValue() >= valuebeforeWaitForSingleObjectinwait_for_on_eventto avoid spurious poll delays, and records pure GPU execution time (gpu_done - launched) separately from lock wait and copy-back timing.before_sync/drain_submit/Quietbarriers for synchronous host callers (present, readbacks, captures, page-mapping batches).crates/victory-gpu/src/hold.rs&crates/victory-gpu/src/queue.rs:Held::take_ready_withsupporting multi-queue coalesced segments, chained bottom-of-pipe waits, deferred mid-batch fence signals, and hazard-split restoration whileHELDis unlocked around host GPU calls.VICTORY_ASYNC_SUBMIT=1, titleExecuteCommandLists/Signal/Waitcalls enqueue intoHELDand wakevictory-submitinstead of blocking the title thread on host GPU execution.0), keeping default synchronous behavior unchanged.Verification
cargo xtask policy: passed (263 files ok)cargo clippy --target x86_64-pc-windows-gnullvm --workspace --all-targets -- -D warnings(default and--features diagnostics): cleantools/macos/test-wine.sh -p victory-gpu):host::flight::tests:::4 passed; 0 failed(including 10-iteration back-to-back GPU write/refresh non-clobber and signal-ordering tests)hold::tests:::12 passed; 0 failed(includingtake_ready_coalesced_merges_cross_queue_bop_and_deferred_signals)VICTORY_COALESCE_PIECES=1):VICTORY_FLIGHT1=0 VICTORY_ASYNC_SUBMIT=0):75.85s(0.527 FPS) across+8..+48,13–17host submissions/frameVICTORY_FLIGHT1=1 VICTORY_ASYNC_SUBMIT=1):28.13s(1.422 FPS, 2.70× faster) across+8..+48and60.29s(1.360 FPS) across+8..+90,7–8host submissions/frame,-26.5sfaster to world entry, zero stalls or crashes.