GPU: parallelize relay copy-back merges with VICTORY_WIDE_MERGE=1 #1066

Open
github-bot wants to merge 4 commits from github-bot/gh-1066 into main AGit
Owner

@⁠UwUCammie on GitHub · 2026-11-25 18:18 UTC · original
UwUCammie:pr/relay-wide-merge → main · +275 −40 · 3 files · 4 commits · open

VICTORY_WIDE_MERGE=1 fans out piece merges via shadow::wide_run in Host::card_back, but under VICTORY_RELAY=2 the three relay landing loops (relay_card_back, relay_card_inflight, and relay_hand_back) still ran one piece at a time on the single landing thread (~28–33 ms/frame here).

  • Adds card_merge_lock: RwLock<()> on Shadow so merge_under_writes (carded path) takes the write lock and concurrent card_merge_relay workers take the read lock instead of serializing on self.before.
  • Wires wide_merge() (VICTORY_WIDE_MERGE=1) into relay_card_back, relay_card_inflight, and relay_hand_back when there are >= 8 pieces/spans.
  • Buckets pieces by (shadow_ptr, 64 KiB page) for carded merges (and by shadow_ptr for PC copies) into up to 8 wide_run jobs so any pieces touching the same (copy, 64 KiB page) always land in the same bucket in their original plan order.

Tested on Linux + Wine 11.22 + RX 7900 XT (RADV, VICTORY_RELAY=2, VICTORY_WIDE_MERGE=1, VICTORY_BACK_OWN_VIEW=1, 480 s run into the cell scene):

  • Copy-back dropped from ~28.2–32.8 ms to 17.2–17.6 ms/frame (~45% faster)
  • 0 GPUVM faults, 0 refused waits, picture unchanged.
**@⁠UwUCammie** on GitHub · 2026-11-25 18:18 UTC · [original](https://github.com/fxceless/victory-fork/pull/1066) `UwUCammie:pr/relay-wide-merge` → `main` · +275 −40 · 3 files · 4 commits · open `VICTORY_WIDE_MERGE=1` fans out piece merges via `shadow::wide_run` in `Host::card_back`, but under `VICTORY_RELAY=2` the three relay landing loops (`relay_card_back`, `relay_card_inflight`, and `relay_hand_back`) still ran one piece at a time on the single landing thread (~28–33 ms/frame here). - Adds `card_merge_lock: RwLock<()>` on `Shadow` so `merge_under_writes` (carded path) takes the write lock and concurrent `card_merge_relay` workers take the read lock instead of serializing on `self.before`. - Wires `wide_merge()` (`VICTORY_WIDE_MERGE=1`) into `relay_card_back`, `relay_card_inflight`, and `relay_hand_back` when there are >= 8 pieces/spans. - Buckets pieces by `(shadow_ptr, 64 KiB page)` for carded merges (and by `shadow_ptr` for PC copies) into up to 8 `wide_run` jobs so any pieces touching the same `(copy, 64 KiB page)` always land in the same bucket in their original plan order. Tested on Linux + Wine 11.22 + RX 7900 XT (RADV, `VICTORY_RELAY=2`, `VICTORY_WIDE_MERGE=1`, `VICTORY_BACK_OWN_VIEW=1`, 480 s run into the cell scene): - Copy-back dropped from ~28.2–32.8 ms to **17.2–17.6 ms/frame** (~45% faster) - 0 GPUVM faults, 0 refused waits, picture unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:56 +00:00
Author
Owner

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

I fixed the worker assignment in ad4fb00. Card pieces are cut at 64 KiB boundaries in title memory, but the original code chose a worker by the offset from the buffer base. Two declarations could overlap in the same page and land on different workers when the buffer started partway into a page. The workers now use the title page, including when two buffers name it. Overlapping CPU-side spans land in their original order.

The two regression tests cover clipped ranges, two buffer bases on the same page, and adjacent CPU spans. Windows host tests under Wine: 39 passed, one ignored.

**@⁠UwUCammie** on GitHub · 2026-11-25 22:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/1066#issuecomment-7175824935) I fixed the worker assignment in ad4fb00. Card pieces are cut at 64 KiB boundaries in title memory, but the original code chose a worker by the offset from the buffer base. Two declarations could overlap in the same page and land on different workers when the buffer started partway into a page. The workers now use the title page, including when two buffers name it. Overlapping CPU-side spans land in their original order. The two regression tests cover clipped ranges, two buffer bases on the same page, and adjacent CPU spans. Windows host tests under Wine: 39 passed, one ignored.
Author
Owner

@⁠Proudnoob4 on GitHub · 2026-11-25 22:16 UTC · original

AI-assisted testing (Gemini in OpenCode); measured locally on my own machine.

RTX 4080 Windows 10 measurement (ad4fb00 + VICTORY_WIDE_MERGE=1): copy-back 38.2 -> 23.2 ms (-39%)

Setup: Windows 10 Pro 22H2 (Agility SDK 1.620.2), i5-13600K (6P+8E), 32 GB RAM, RTX 4080 16 GB (driver 621.01), Series X profile, diagnostics release build, warm cache, VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_QUEUE2=1 VICTORY_WIDE_BACK=1 VICTORY_COPY_PLAIN=1 VICTORY_CARD_BUFFERS_MIN_KB=64 VICTORY_CARD_BUFFERS_MB=1536 VICTORY_CARD_HASH_LEN=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_INDIRECT_GATHER=1 VICTORY_JOIN_PARTS=1 VICTORY_ASYNC_SUBMIT=1.

Comparing two runs on the same 9c184b3-based bundled speed stack before and after adding #1066 (ad4fb00, VICTORY_WIDE_MERGE=1) alongside #1058, #1146, #1158, #1159:

Metric (framelog usual frame / fps lines) Before (fxnext_win, no #1066) After (fxnext_turbo, #1066 VICTORY_WIDE_MERGE=1)
copy-back (framelog usual frame) 38.2 ms (62.85 MB) 23.2 ms (62.52 MB) (-39%)
copying back (median across world lines) 39.4 ms 24.3 ms
Relay landing time (the relay per frame) — 25.4 ms landing in all (8.0 landings, 4.4 ms fetch wait, 1,372.9 pieces fetched)
World FPS (27 world lines, 330 s) 5.20 med / 9.40 max (18 lines) 8.50 med / 9.20 p90 / 9.30 max (last10: 8.3–9.3)
Stability / unit tests — Clean (0 device loss, 0 crashes); 66/66 targeted victory-gpu tests pass

(Note: bundled run with #1058, #1146, #1158, #1159 added in the same rebuild, so this is a bundled measurement rather than an isolated single-PR A/B; #1058 also dropped <256 B kernel copy fallbacks 5,266 -> 47/frame.)

**@⁠Proudnoob4** on GitHub · 2026-11-25 22:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/1066#issuecomment-7176156840) *AI-assisted testing (Gemini in OpenCode); measured locally on my own machine.* ### RTX 4080 Windows 10 measurement (`ad4fb00` + `VICTORY_WIDE_MERGE=1`): copy-back `38.2 -> 23.2 ms` (-39%) **Setup:** Windows 10 Pro 22H2 (Agility SDK 1.620.2), i5-13600K (6P+8E), 32 GB RAM, RTX 4080 16 GB (driver 621.01), Series X profile, diagnostics release build, warm cache, `VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_QUEUE2=1 VICTORY_WIDE_BACK=1 VICTORY_COPY_PLAIN=1 VICTORY_CARD_BUFFERS_MIN_KB=64 VICTORY_CARD_BUFFERS_MB=1536 VICTORY_CARD_HASH_LEN=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_INDIRECT_GATHER=1 VICTORY_JOIN_PARTS=1 VICTORY_ASYNC_SUBMIT=1`. Comparing two runs on the same `9c184b3`-based bundled speed stack before and after adding `#1066` (`ad4fb00`, `VICTORY_WIDE_MERGE=1`) alongside `#1058`, `#1146`, `#1158`, `#1159`: | Metric (`framelog` usual frame / `fps` lines) | Before (`fxnext_win`, no `#1066`) | After (`fxnext_turbo`, `#1066` `VICTORY_WIDE_MERGE=1`) | |---|---|---| | `copy-back` (`framelog` usual frame) | `38.2 ms` (`62.85 MB`) | **`23.2 ms` (`62.52 MB`) (-39%)** | | `copying back` (median across world lines) | `39.4 ms` | **`24.3 ms`** | | Relay landing time (`the relay per frame`) | — | `25.4 ms` landing in all (`8.0` landings, `4.4 ms` fetch wait, `1,372.9` pieces fetched) | | World FPS (`27` world lines, 330 s) | `5.20` med / `9.40` max (18 lines) | **`8.50` med / `9.20` p90 / `9.30` max** (`last10`: `8.3–9.3`) | | Stability / unit tests | — | Clean (`0` device loss, `0` crashes); `66/66` targeted `victory-gpu` tests pass | *(Note: bundled run with `#1058`, `#1146`, `#1158`, `#1159` added in the same rebuild, so this is a bundled measurement rather than an isolated single-PR A/B; `#1058` also dropped `<256 B` kernel copy fallbacks `5,266 -> 47/frame`.)*
Author
Owner

@⁠SkillIssueXO on GitHub · 2026-11-26 02:27 UTC · original

AI-assisted source review and native Windows fixture. I checked ad4fb005 and reran modules::xmem::tests::physical_pages_map_alias_and_unmap successfully. The title-page bucket fixes overlapping declarations at the same virtual page. The HLE test also confirms that two distinct title virtual pages can show the same physical bytes. relay_merge_bucket can place those two views on different workers because it hashes the virtual page. For example, views at 0x100000 and 0x210000 hash to buckets 0 and 1.

Could the parallel card paths keep writes to the same backing section page in plan order, or fall back to serial for aliased ranges? A fixture that maps one 64 KiB page twice and lands overlapping updates from two copies would cover the remaining case. This is a source-level ordering concern. I have not reproduced a gameplay corruption from it.

**@⁠SkillIssueXO** on GitHub · 2026-11-26 02:27 UTC · [original](https://github.com/fxceless/victory-fork/pull/1066#issuecomment-7180826881) AI-assisted source review and native Windows fixture. I checked `ad4fb005` and reran `modules::xmem::tests::physical_pages_map_alias_and_unmap` successfully. The title-page bucket fixes overlapping declarations at the same virtual page. The HLE test also confirms that two distinct title virtual pages can show the same physical bytes. `relay_merge_bucket` can place those two views on different workers because it hashes the virtual page. For example, views at `0x100000` and `0x210000` hash to buckets 0 and 1. Could the parallel card paths keep writes to the same backing section page in plan order, or fall back to serial for aliased ranges? A fixture that maps one 64 KiB page twice and lands overlapping updates from two copies would cover the remaining case. This is a source-level ordering concern. I have not reproduced a gameplay corruption from it.
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-26 13:52 UTC · original

@⁠SkillIssueXO The two virtual addresses in your example could go to different workers. Fixed in 9029467d. The relay and direct card paths now check the section-page map before splitting a landing. A span touching a page with multiple live views takes the serial path in plan order.

The regression maps one anonymous section twice under Wine, makes two overlapping writes through the different views, and checks the five resulting bytes. It also checks that the unaliased neighboring page stays eligible and that removing the second view restores eligibility. All three relay bucket tests passed.

**@⁠UwUCammie** on GitHub · 2026-11-26 13:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/1066#issuecomment-7193949450) @⁠SkillIssueXO The two virtual addresses in your example could go to different workers. Fixed in `9029467d`. The relay and direct card paths now check the section-page map before splitting a landing. A span touching a page with multiple live views takes the serial path in plan order. The regression maps one anonymous section twice under Wine, makes two overlapping writes through the different views, and checks the five resulting bytes. It also checks that the unaliased neighboring page stays eligible and that removing the second view restores eligibility. All three relay bucket tests passed.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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