Skip to content

gpu: parallelize relay card_merge_relay under VICTORY_WIDE_MERGE=1 - #665

Open
JavierBlanco23 wants to merge 1 commit into
fxceless:mainfrom
JavierBlanco23:perf/relay-copy-queue-and-wide-merge
Open

JavierBlanco23 wants to merge 1 commit into
fxceless:mainfrom
JavierBlanco23:perf/relay-copy-queue-and-wide-merge

Conversation

@JavierBlanco23

@JavierBlanco23 JavierBlanco23 commented Nov 25, 2026 •

Copy link
Copy Markdown

Refocused after review feedback from @CuteBooty and @HLVM04:

  • Removed the dedicated D3D12 copy queue (caused WHY_STALE regressions, cross-queue state hazards, and relay_fetched pruning edge cases; 9376fd6's VICTORY_CARD_FETCH_INFLIGHT=1 already removes the fetch wait cleanly inside the flight).
  • Reverted WINDOW_MOST back to 64.
  • Kept parallel 8-thread card_merge_relay under VICTORY_WIDE_MERGE=1 in Host::relay_card_back and extended it per-plan (preserving plan order) to Host::relay_card_inflight.

@CuteBooty

Copy link
Copy Markdown

A landing without pieces can drop notes that a later fetch still needs

Found by reading 1557943, not by a run. Two independent reads agree.

In relay_card_back, when a landing has no pieces, the code calls relay_fetched(QUEUE_ORDER). That was right while
the fetch queued behind the sends on the main queue. On the copy queue it is not: the merge's "after" is the plans'
highest sent_as (S), not the queue's count (N).

  • card_dirty drops every note whose send number is at or below RELAY_FETCHED.
  • card_merge_relay keeps title bytes only where a note's send is above the merge's fetched_after.
  • If sends S+1..N are still in the air at an empty landing and the mark is set to N, the next landing merges with
    "after" S+1, but the notes for S+2..N are gone. It then takes the card's bytes, which are older there, as shader
    writes and puts them over title memory: a stale or wrong picture, silently.

Suggested fix, on the copy-queue path only (the main-queue path keeps QUEUE_ORDER):

// On the copy queue a later fetch merges "after" its own plans' send,
// not the queue's count: notes of sends past these plans' are still needed.
if relay_copy_queue() {
    if let Some(last) = plans.iter().map(|p| p.sent_as).max() {
        crate::shadow::relay_fetched(last);
    }
    return;
}

Plans land in line order, so every later "after" is at least S, and pruning up to S never removes a note a later
merge needs. Empty plans prunes nothing.

Two things I did not verify, both with the copy queue on:

  • The fetch does not wait on the main queue's fence, so it can read a copy that a later flight is still writing.
    I expect stale-for-a-frame, corrected when that flight lands, but have not shown it.
  • The copies are created in COMMON and moved to NON_PIXEL_SHADER_RESOURCE on the main queue; reading them from the
    copy queue meanwhile is outside D3D12's rules. Not tried with the debug layer.

Not run in the game yet on this card.

Setup: RTX 3070 8 GB (driver 621.24, 32-lane waves), Ryzen 5 3600, 32 GB, Windows 11, Series X mode, 1920x1080, relay at its default (stage 2), card buffers 1 / 1024 MB, a diagnostics build.

oceansde012 pushed a commit to oceansde012/victory-gta6 that referenced this pull request Nov 25, 2026
xtask: count \x escapes and 0x hex arrays as encoded runs in the policy check
(cherry picked from commit 644ebeb)
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
The 9e6137f run spent 54 ms a frame copying back on the thread that
lands flights, merging the pushed runs one after another. The runs of a
landing are now noted first and merged once every plan's are, before
the slots are given back: with VICTORY_WIDE_MERGE=1 each copy's runs go
to one thread in their order (a copy's merges take its own lock anyway),
the copies spread over up to eight jobs by their bytes. Without the
switch the runs merge in the same order as before.

The push line now says how many copies the runs were of and how long the
merges took, so a run shows whether the copy-back is spread over enough
copies to gain from the threads.

This takes the parallel-merge part of fxceless fxceless#665 and fxceless#688 for the
push path. Their copy-queue fetch and VRAM staging do not apply with
VICTORY_CARD_PUSH on, where nothing is fetched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBB9Mgcxkr8YRW4LAzi
@HLVM04

HLVM04 commented Nov 25, 2026

Copy link
Copy Markdown

A/B on an RTX 5070 Ti (wave32, NVIDIA 616.64), Series S profile. Tree: 9376fd6 + #798, #783, #799, #780 (with VICTORY_INDIRECT_KEEP=1 VICTORY_INDIRECT_WINDOW=1), #770 and #827, then this PR merged on top. The only conflict was the two newer CardPlan fields (inflight, inflight_landed), and I kept both. One run each, about 4.5 minutes, frame lines after the first 60 s:

p50 ms p75 p90 mean: preparing / on the GPU / copying back
without this PR 149 181 327 90 / 43 / 69
with this PR 177 688 1010 129 / 31 / 24
with this PR, VICTORY_RELAY_COPY_QUEUE=0 167 208 342 92 / 52 / 77
  • What it was written for works:
    • The relay's wait for fetches went from 54.9 to 5.8 ms a frame.
    • "Copying back" went from 69 to 24 ms.
  • But the frame got slower:
    • A new settle appeared: "title memory changed under shader writes" went from 0.1 to 42.8 ms a frame.
    • Preparing went up.
  • With the copy queue off, that settle goes away, but the frame is still about 18 ms slower than without the PR. That may be the WINDOW_MOST 64 → 512 change interacting with VICTORY_INDIRECT_WINDOW=1; I haven't separated it.

No device loss in either run.

@JavierBlanco23
JavierBlanco23 force-pushed the perf/relay-copy-queue-and-wide-merge branch from 1557943 to 34499ae Compare November 25, 2026 11:15
@JavierBlanco23 JavierBlanco23 changed the title gpu: dedicated D3D12 copy queue + parallel wide merge for relay card fetches gpu: parallelize relay card_merge_relay under VICTORY_WIDE_MERGE=1 Nov 25, 2026
@JavierBlanco23

Copy link
Copy Markdown
Author

Thanks @CuteBooty and @HLVM04 for the thorough code review and A/B benchmark — both hit the nail on the head:

  1. Dedicated copy queue (VICTORY_RELAY_COPY_QUEUE): removed from this PR. Between the empty-landing relay_fetched(QUEUE_ORDER) bug, the cross-queue read/state hazard on NON_PIXEL_SHADER_RESOURCE, and the WHY_STALE jump (0.1 → 42.8 ms/frame) pushing preparing up, it isn't the right mechanism — especially now that 9376fd6's VICTORY_CARD_FETCH_INFLIGHT=1 eliminates the fetch wait inside the flight itself.
  2. WINDOW_MOST 64 → 512: reverted back to 64 (didn't belong in this PR and regressed with VICTORY_INDIRECT_WINDOW=1).

I've rebased onto 9376fd6 and refocused the PR strictly on parallelizing card_merge_relay under the existing VICTORY_WIDE_MERGE=1 switch, covering both Host::relay_card_back and Host::relay_card_inflight (per-plan, preserving flight order across plans).

@UwUCammie

Copy link
Copy Markdown

There’s an ordering case in the wide merge worth checking here too. Two declarations can cover different, overlapping parts of one title page, and distinct buffers can name that same page. Splitting the pieces by their position in the vector can put those writes on different workers. I ran into the same issue in #1066 and changed the partition to use the absolute title page. That also handles a buffer starting partway through a page.

PiloteCode pushed a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
xtask: count \x escapes and 0x hex arrays as encoded runs in the policy check
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.

5 participants