gpu: parallelize relay card_merge_relay under VICTORY_WIDE_MERGE=1 #665

Open
github-bot wants to merge 1 commit from github-bot/gh-665 into main AGit
Owner

@⁠JavierBlanco23 on GitHub · 2026-11-25 04:14 UTC · original
JavierBlanco23:perf/relay-copy-queue-and-wide-merge → main · +90 −26 · 1 files · 1 commits · open

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.
**@⁠JavierBlanco23** on GitHub · 2026-11-25 04:14 UTC · [original](https://github.com/fxceless/victory-fork/pull/665) `JavierBlanco23:perf/relay-copy-queue-and-wide-merge` → `main` · +90 −26 · 1 files · 1 commits · open 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`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:48:31 +00:00
Author
Owner

@⁠CuteBooty on GitHub · 2026-11-25 05:54 UTC · original

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

Found by reading 15579433, 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.

**@⁠CuteBooty** on GitHub · 2026-11-25 05:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7154260835) **A landing without pieces can drop notes that a later fetch still needs** Found by reading 15579433, 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`): ```rust // 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.
Author
Owner

@⁠HLVM04 on GitHub · 2026-11-25 10:24 UTC · original

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.

**@⁠HLVM04** on GitHub · 2026-11-25 10:24 UTC · [original](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7159651726) 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.
Author
Owner

@⁠JavierBlanco23 on GitHub · 2026-11-25 11:15 UTC · original

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).

**@⁠JavierBlanco23** on GitHub · 2026-11-25 11:15 UTC · [original](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7160802692) 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).
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-25 22:00 UTC · original

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.

**@⁠UwUCammie** on GitHub · 2026-11-25 22:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7175825181) 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.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/665/head:github-bot/gh-665'
git switch 'github-bot/gh-665'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-665'
git switch 'github-bot/gh-665'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-665'
git switch 'github-bot/gh-665'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-665'
git switch 'main'
git merge --squash 'github-bot/gh-665'
git switch 'main'
git merge --ff-only 'github-bot/gh-665'
git switch 'main'
git merge 'github-bot/gh-665'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.