Repository navigation
perf(gpu): opt-in Wait-Before-Prep Flight-1 GPU overlap and async submit worker - #447
Conversation
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. |
|
I merged main into this twice today and it was clean until #417 landed. Now it conflicts for a design reason, not a textual one: #417 makes |
…ync submit worker (VICTORY_ASYNC_SUBMIT=1) Implement Wait-Before-Prep Flight-1 overlap (VICTORY_FLIGHT1=1) and a dedicated victory-submit worker thread (VICTORY_ASYNC_SUBMIT=1) behind opt-in environment switches (default off), rebased cleanly onto main: - Split Host::execute_with_barriers into prepare_submission, execute_sync, and finish_post_gpu, preserving all main submission behavior across both sync and Flight-1 paths (pragyaangaur#403 SUBMISSIONS_DONE/retire_any/advance_retired, pragyaangaur#417 ReadyDrain/release_worker, pragyaangaur#419 coalesced UAV barriers, pragyaangaur#453 hoisted indirect clamps in prelude, pragyaangaur#457 texback::land, pragyaangaur#474 trim_idle, and unconditional bindless::uploads). - Keep pragyaangaur#417's bindless::Uploads semantics (Holder dirty tracking + ReadyDrain + release_worker) while checking out the upload HostList from LIST so Uploads is genuinely Send across the flight lifecycle without holding a MutexGuard across threads or GPU waits; call release_worker() immediately after the flight's GPU fence completes and return the upload list to LIST on drop. - Enforce Wait-Before-Prep in host/flight.rs: finish_flight_locked drains Flight N-1 completely before Flight N touches any shared Shadow, descriptor heap, upload staging pool, or Mark buffer, and Host::quiet() drains any active flight under Host::submitted before heap creation/null-fill. - Add coalescing Held::take_ready_with / finish_running so victory-submit and Flight-1 never hold HELD across GPU submission, preserving the lock DAG (SUBMIT_DRAIN -> HELD -> Host::submitted -> Host::flight -> Fence::waiters) and draining cleanly at PresentX, CopyPageMappingsBatchX, and synchronous Host::execute calls.
|
Rebased cleanly onto latest
Re-verified checks on
|
41c3a4b to
f366992
Compare
|
Merged. Sorry this sat: I had held it because it splits |
…nc in the wait for a flight (VICTORY_FLIGHT_HEAP_SYNC) In the prison cell a Metal System Trace shows 12-14 synchronous waits a frame, about 8.5 of them small: 53 ms of wall time for 28 ms of GPU work, each paying ~1.8 ms from ExecuteCommandLists to commit and 0.63 ms of start latency, because with Flight-1 the next submission is prepared and given only once the one before has landed. VICTORY_FLIGHTS=2 (with Flight-1): a submission may be prepared and given to the host GPU while the flight before it is still in the air; flights land strictly in order. What is versioned per flight: its lists, upload list and staging, refresh batch and heaps (as before); its mark (a second one for the flight beside); the Signals attached behind it (attach_signal goes to the newest, each delivered at its own landing, after its copy-back); what it may write (declared ranges, the copies its heaps view for unordered access); the number retirement counts it by (its own fence value, not the last one given; SUBMISSIONS_DONE moves by fetch_max), and the bury lag is at least the flight count, so what a later flight uses outlives the earlier landing. What stays one for all, and so keeps the next submission from going beside (Host::beside_refusal, counted by reason in the overlap line): - write marks: the bitmap is taken whole, with plain reads and writes, at a landing, while the GPU may set bits; a flight beside another marks no writes (no marked declared write, no heap with unordered views, no title-memory program); - a copy's pending ranges and snapshot: it declares no write on a copy a flight in the air may write, and title copies and fills stay off that memory; - the upload list's staging (texture::recycle at every preparation), the coalesced pieces' barrier lists and split marks, the same host list, steps of ours. A difference from one flight, by design (as with VICTORY_FLIGHT1_PREWARM): a refresh beside a flight of a copy that flight only reads takes the title's newer bytes, so a flight may read bytes the title rewrote after giving it, which on the console races the GPU too (correct titles keep what in-flight work reads, ring buffers). pragyaangaur#447's flight1_never_clobbers_in_flight_shadow_data asserts Flight-1's stronger order and now pins one flight. Its refreshes of copies a flight in the air may write are put off (flight::defer_beside, from Batch::add) and done once those flights have landed, before it is given; title textures given up and unordered views made again wait for a preparation with nothing in the air. Read marks are taken at a landing too; one set while they are taken is set again at the next read (a view made a frame later at worst). VICTORY_FLIGHT_HEAP_SYNC=1 (with Flight-1, one flight): the next submission's descriptor heap sync runs while the flight before it is in the air, before landing it; with two flights a preparation beside a flight syncs the heaps beside it. What a sync makes are slots the title rewrote after the flight was prepared, for later work (on the console the GPU reads the heap while earlier work runs, and title threads already write views meanwhile); a slot's old view is retired for the bury lag. The overlap line adds: submissions given beside another, the most in the air, refusals by reason, and heap syncs in the wait (count, ms). Prior art, checked: avatarmanz/VIctory-7900XTX b8b30d1 (one ordered line of submissions prepared by a thread of theirs; retirement waits for what is in the line; read-backs drain it) and 37332f4 (consecutive parts prepared as one), after fxceless/victory-fork f85101b6; GPL-3.0. Here the title-side return is pragyaangaur#447's submit worker (VICTORY_ASYNC_SUBMIT=1), and this adds the preparation beside the GPU it lacked. Tests (Wine, D3DMetal; the host queue held by a gate fence where a flight must stay in the air, `victory-flight` held where one must stay unlanded): two flights up together land in order, each copy-back before its own Signal and the next one's (watcher thread); a flight writing what the one in the air writes goes up alone; one whose shaders mark writes does not go beside, one that only reads does; a refresh of a copy the flight in the air wrote waits for its landing (fails, the write lost, if defer_beside is off); a heap slot written while two flights are in the air serves the next; 64 submissions back to back alternating buffers, with conflicts, Signals and bottom-of-pipe counts, lose nothing and keep their order; a record copied into a heap during a flight is made in the wait, before the flight lands. Test isolation: the gate opens itself after 2 s (a submission of another test behind it holds the submission lock the opener may wait for), and what a test sees "while held" is checked only if the gate still was; two more upstream tests that need nothing in the air take ModeGuard::new(false, false). Off (VICTORY_FLIGHTS unset or 1, VICTORY_FLIGHT_HEAP_SYNC unset) nothing changes but the overlap line's new counts (zero). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
In-game check on an M5 Pro (macOS 27.0.1, CrossOver 26.3 Wine with the repo's patches, D3DMetal 4.0 beta 3, Series X), With Update: the run above used
One run, so treat it as a lead. If there's a setting I should add, or something to log, I can run it again. Prepared with Claude Code. |
… writes meanwhile With VICTORY_FLIGHT1=1 alone the first indoor area renders much darker (reported by earpjonathan on pragyaangaur#447: median luma 13/255 against 39 without the switch). The mechanism: shaders that write through a heap's unordered views (the bindless path) or through title-memory programs declare nothing; their writes are marked in the write-mark bitmap and copied back by the pages marked (copy_back_marked). Such pages were never armed, so a title write to one before the copy-back saved nothing, and the copy-back kept the title's page whole and dropped the shader's bytes there (MarkedKept). Waited for, the submitting thread cannot write meanwhile. A flight lets it go on, and it writes the next frame's data into pages the GPU writes too (on the console both land, byte by byte), so GPU-written results, such as the frame's luminance, are lost. The fix, on the Flight-1 path only: before a flight is given to the host GPU, the unordered views of its heaps and the copies its title-memory programs' page tables name are armed (Shadow::arm_undeclared). The first title write to such a page during the flight saves the page's bytes from before, and the copy-back merges both writers' bytes, as for a declared marked write. Once it has landed they are disarmed unless a list still declares writes there. The frame line's "flights armed" line counts the copies. The new test makes a heap-view write and a title write on one page while the flight is held in the air; it failed before (the shader's dword came back as the old value) and passes now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fences VICTORY_ASYNC_SUBMIT=1 (pragyaangaur#447) already lets the title's ExecuteCommandLists, Signal and Wait only queue their work for victory-submit, but its time was invisible: the frame report's "threads held by host GPU work" line counted nothing under it, so it could not be weighed against the default. - queue.rs: the title's calls count what they spend queuing; threads that wait for the worker to drain (PresentX as "presents", our read-backs, captures and page mappings as the new "our syncs") count the drain's lock and run; the Flight-1-only pump on title threads is counted too. - host/flight.rs: per flight, the worker's time waiting for the last flight to land, preparing and launching, and the host GPU's idle time before it, split into nothing to run and preparing; logged as a frame-report line. - Tests: the title's thread is back while its work is held, may reset the list at once, never runs host work, and its fence moves only after the work's bottom-of-pipe write; a queue waiting on another queue's fence completes only after that queue's fence and write show. - docs/macos.md: the switches and the lines. (Upstream pragyaangaur#584 by Nick233x, applied onto two flights: its step enum is Phase here, as flight.rs already uses host's Step; the GPU counts as free after a landing only once no flight is left in the air; the docs row only.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.