Skip to content

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

Open
gdemontalivet wants to merge 2 commits into
pragyaangaur:mainfrom
gdemontalivet:perf/macos-coalesce-held-pieces
Open

gdemontalivet wants to merge 2 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.

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.

3 participants