Skip to content

perf(gpu): coalesce cross-queue and bottom-of-pipe dependent held pieces - #419

Merged
pragyaangaur merged 4 commits into
pragyaangaur:mainfrom
gdemontalivet:perf/macos-coalesce-held-pieces
Nov 27, 2026
Merged

pragyaangaur merged 4 commits into
pragyaangaur:mainfrom
gdemontalivet:perf/macos-coalesce-held-pieces

Conversation

@gdemontalivet

Copy link
Copy Markdown
Contributor

Summary

  • Hoists piece accumulation and deferred Item::Signal delivery across queues inside Held::pump_coalesced() (VICTORY_COALESCE_PIECES, default ON, 0 restores legacy per-queue pump; VICTORY_JOIN_LISTS default 64).
  • Adds HostList::will_write(&ValueWait) and HostList::batch_flags() so held segments waiting on a bottom-of-pipe write or fence signal already queued in the current piece coalesce into the same Host::execute instead of triggering a separate submission, inserting a reusable global uav_barrier() command list at each crossed synchronization boundary.
  • Gates hazard and list-count checks strictly to actual cross-queue / BoP / deferred-signal join boundaries so consecutive ready segments on the same queue are never spuriously split.

Measured M5 Max (CrossOver / D3DMetal) Impact

  • Matched frozen-cache M5 Max warm A/B: host submission pieces per frame dropped from 17.5–18.0 → 11.0–12.0 (-35% to -39%), coalescing 6–8 BoP waits per frame, and median GPU time dropped from 107.5 ms → 89.2–90.8 ms (-17.0%).

Verification

  • cargo xtask policy: pass
  • cargo test -p victory-gpu --lib hold::tests: 17/17 passed (including cross-queue BoP chain, hazard split, deferred signal/fence-wait, and same-queue non-split tests)
  • cargo clippy --target x86_64-pc-windows-gnullvm --workspace --all-targets -- -D warnings (default & --features diagnostics): 0 warnings

Coalesce ready command-list segments across queues inside Held::pump when
a producer segment's deferred bottom-of-pipe write or deferred fence signal
satisfies a waiting segment's dependency, inserting a reusable global UAV
barrier command list at each joined synchronization boundary.

Guard coalescing against submission-phase ordering hazards (title memory
copies or post-execution callbacks before explicit texture uploads; GPU
writes or post-execution callbacks before deferred CPU reads) and cap
joined submissions via VICTORY_JOIN_LISTS (default 64). Toggle with
VICTORY_COALESCE_PIECES (default on unless "0").
… join boundaries

Do not run can_join_batch between consecutive ready segments on the same
queue that already ran together in a single host submission in legacy mode.
Checking can_join on every intra-queue segment shredded multi-list graphics
submissions whenever an earlier list had a GPU write or title copy and a
later list in the same submission had a CPU copy/fill or texture upload.

Restrict can_join checks to actual join boundaries (switching queues,
crossing a BoP-satisfied wait, or crossing a deferred-signal fence wait),
preserving full cross-queue BoP coalescing without spurious intra-queue splits.
@evan-kolberg

Copy link
Copy Markdown
Contributor

Two new scheduler checks find an ordering problem at gdemontalivet’s exact #419 head. With a consumer waiting for >=7, coalescing releases it when queued producers write 7 then 0 to the same word. It also releases the consumer if CPU memory starts at 7 and the only pending write clears it. The legacy pump keeps the consumer held in both cases. A subsequent write of 7 releases it as expected. The former case comes from the backward scan accepting any satisfying write.

A local change that checks the newest overlapping pending write before looking at CPU memory passes 19/19 scheduler tests, including both new cases. On M4 Pro / D3DMetal 4.0 beta 3, a separate generated guest list with two dependent buffer copies and an actual bottom-of-pipe cut reduced 2 fenced native submissions to 1, with both exact output words. That positive result held with the ordering change too. The overwrite checks ran in the CPU scheduler model.

Prepared and tested with Codex.

@earpjonathan

Copy link
Copy Markdown
Contributor

In-game check on an M5 Pro (macOS 27.0.1, CrossOver 26.3 Wine with the repo's current patches, D3DMetal 4.0 beta 3, Series X), with #439 and #419 together on main at bf99e72 plus #401, #435 and #433. Same opening and scripted input in each run, into the first area you control.

  • Median time preparing submissions per frame: 292 ms without these two, 198 and 196 ms in two runs with them.
  • Median frame time went from 687 ms to 541 and 646 ms. Run-to-run spread is about 100 ms, so the CPU-side number is the one to trust.
  • The picture looked the same as without them, with no device loss and no frames over 10 s.

I didn't test them separately, so I can't say how the gain splits between them.

Prepared with Claude Code.

@pragyaangaur

Copy link
Copy Markdown
Owner

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.

@pragyaangaur
pragyaangaur merged commit e678253 into pragyaangaur:main Nov 27, 2026
1 check passed
gdemontalivet added a commit to gdemontalivet/VIctory-macOS that referenced this pull request Nov 27, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants