gpu: parallelize relay card_merge_relay under VICTORY_WIDE_MERGE=1 #665

Open
JavierBlanco23 wants to merge 1 commit from upstream-pr/665 into main
JavierBlanco23 commented 2026-11-25 04:14:23 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JavierBlanco23 on 2026-11-25T04:14:23Z.


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.
<!-- greyfinch-sync:fxceless/victory-fork:issue:6597062863 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/665). Originally posted by [JavierBlanco23](https://github.com/JavierBlanco23) on 2026-11-25T04:14:23Z. --- 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 commented 2026-11-25 06:06:41 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CuteBooty on 2026-11-25T05:54:58Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7154260835 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7154260835). Originally posted by [CuteBooty](https://github.com/CuteBooty) on 2026-11-25T05:54:58Z. --- **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.
DoktorTK commented 2026-11-25 08:09:04 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by DoktorTK on 2026-11-25T07:41:26Z.


found this while trying out some optimizations, don't have a lot of experience in this so i figured i just post it here.

The author implemented VICTORY_WIDE_MERGE=1 (wide_merge()) for the non-relay card_back path, but forgot to wire wide_merge() into relay_card_back.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156142568 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7156142568). Originally posted by [DoktorTK](https://github.com/DoktorTK) on 2026-11-25T07:41:26Z. --- found this while trying out some optimizations, don't have a lot of experience in this so i figured i just post it here. The author implemented VICTORY_WIDE_MERGE=1 (wide_merge()) for the non-relay card_back path, but forgot to wire wide_merge() into relay_card_back.
HLVM04 commented 2026-11-25 11:10:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HLVM04 on 2026-11-25T10:24:29Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7159651726 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7159651726). Originally posted by [HLVM04](https://github.com/HLVM04) on 2026-11-25T10:24:29Z. --- 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.
upstream-sync changed title from [PR #665] gpu: dedicated D3D12 copy queue + parallel wide merge for relay card fetches to [PR #665] gpu: parallelize relay card_merge_relay under VICTORY_WIDE_MERGE=1 2026-11-25 12:06:47 +00:00
JavierBlanco23 commented 2026-11-25 12:07:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JavierBlanco23 on 2026-11-25T11:15:21Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7160802692 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7160802692). Originally posted by [JavierBlanco23](https://github.com/JavierBlanco23) on 2026-11-25T11:15:21Z. --- 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 commented 2026-11-25 22:07:26 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UwUCammie on 2026-11-25T22:00:50Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7175825181 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/665#issuecomment-7175825181). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-25T22:00:50Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/665:upstream-pr/665'
git switch 'upstream-pr/665'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/665'
git switch 'upstream-pr/665'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/665'
git switch 'upstream-pr/665'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/665'
git switch 'main'
git merge --squash 'upstream-pr/665'
git switch 'main'
git merge --ff-only 'upstream-pr/665'
git switch 'main'
git merge 'upstream-pr/665'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!665
No description provided.