GPU: wake the copy-batch caller once when its last job finishes #1172

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

@⁠UwUCammie on GitHub · 2026-11-25 22:41 UTC · original
UwUCammie:perf/parallel-copy-job-completion → main · +64 −19 · 1 files · 1 commits · open

A batch of parallel refreshes took the same completion mutex once for every job. Each already-boxed job was also boxed a second time to carry its completion count. The submitting thread could keep draining other batches after its own had finished.

Queue the job with its group, count completions atomically, and have the last job wake the caller. The caller still helps execute queued work while waiting for its own batch.

On a Ryzen 7 9700X I timed the two pool implementations in a native Linux release harness. Each caller submitted 64 batches. These are medians of eight alternating pairs.

Work per batch Before After
1 caller, 64 counter jobs 1.41 ms 1.06 ms
2 callers, 512 counter jobs each 21.40 ms 11.15 ms
2 callers, 128 jobs each updating 1–5 KiB 7.77 ms 5.13 ms

All 31 shadow tests passed on the Windows x64 build under Wine 11.22, including the new test with three overlapping callers. The times above measure the worker pool. The first-room frame-rate comparison is still pending.

Runnable benchmark and commands

I also timed the first room on the RX 7900 XT, with the same 16 KiB readback setting and scratch-reuse patch on both builds. The parent build accepted 588 presents in 73.89 s (7.96 FPS, 4,881 draws/frame). With this change it accepted 693 in 74.37 s (9.32 FPS, 4,919 draws/frame). Each value is one run on a shared desktop. The paired synthetic measurements above isolate the worker code more closely.

**@⁠UwUCammie** on GitHub · 2026-11-25 22:41 UTC · [original](https://github.com/fxceless/victory-fork/pull/1172) `UwUCammie:perf/parallel-copy-job-completion` → `main` · +64 −19 · 1 files · 1 commits · open A batch of parallel refreshes took the same completion mutex once for every job. Each already-boxed job was also boxed a second time to carry its completion count. The submitting thread could keep draining other batches after its own had finished. Queue the job with its group, count completions atomically, and have the last job wake the caller. The caller still helps execute queued work while waiting for its own batch. On a Ryzen 7 9700X I timed the two pool implementations in a native Linux release harness. Each caller submitted 64 batches. These are medians of eight alternating pairs. | Work per batch | Before | After | | --- | ---: | ---: | | 1 caller, 64 counter jobs | 1.41 ms | 1.06 ms | | 2 callers, 512 counter jobs each | 21.40 ms | 11.15 ms | | 2 callers, 128 jobs each updating 1–5 KiB | 7.77 ms | 5.13 ms | All 31 shadow tests passed on the Windows x64 build under Wine 11.22, including the new test with three overlapping callers. The times above measure the worker pool. The first-room frame-rate comparison is still pending. [Runnable benchmark and commands](https://github.com/UwUCammie/victory-amd/tree/bench/first-room-radv/benchmarks#copy-worker-benchmark) I also timed the first room on the RX 7900 XT, with the same 16 KiB readback setting and scratch-reuse patch on both builds. The parent build accepted 588 presents in 73.89 s (7.96 FPS, 4,881 draws/frame). With this change it accepted 693 in 74.37 s (9.32 FPS, 4,919 draws/frame). Each value is one run on a shared desktop. The paired synthetic measurements above isolate the worker code more closely.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:52 +00:00
Author
Owner

@⁠Proudnoob4 on GitHub · 2026-11-25 23:17 UTC · original · edited 2026-11-25 23:26 UTC

AI-assisted (Claude Opus 5.5 in OpenCode), measured on my own machine. This replaces two overlapping AI-written reports I posted here earlier; on re-auditing the logs, some of their numbers were single samples or misattributed, and one said there were no visual artifacts, which was wrong.

Setup: RTX 4080 16 GB, Windows 10 22H2, Series X build, diagnostics release, prison-cell scene (~4,800 draws/frame). Three single 360 s runs, so this is a bundle comparison, not an isolated A/B:

  • A fxceless stack, f32 path
  • B = A + a local port of Marvisak/VIctory#2825 native f16
  • C = B + #1168 + #1147 + #1164 (VICTORY_CARD_PIECE_KB=16) + #1171 + #1172 + a local commit (skip clean card_dirty copies; chunk wide compare dispatches to ≤ 65,535 groups)
In-world, from the logs A B C
FPS, 2nd-half median (max) 8.8 (9.3) 8.8 (9.7) 8.9 (9.4)
Usual frame, median 112 ms 111 ms 113 ms
GPU title lists (all other lists), 2nd-half median 40.0 ms 38.1 ms 31.8 ms
cardmeter, 256-frame mean, steady 40.8 ms 40.9 ms 31.6–33.7 ms
Copy-back (last usual-frame summary) 23.2 ms / 62.5 MB 22.4 ms / 60.9 MB 28.4 ms / 49.4 MB
Pieces fetched on the copy queue / frame ~1,370 ~1,388 ~4,138
Writes back in place / frame 1,386 1,390 4,150
Card idle per frame 62.5 ms 68.7 ms 68.8 ms
  • GPU: title-list time fell by ~8 ms between B and C. Native f16 alone (A→B) changed it by ~2 ms at most (cardmeter unchanged). Which of C's additions gave the 8 ms is not isolated.
  • No FPS change: the frame is CPU-bound on the submit thread (copies ~63 ms + copy-back 22–28 ms of a ~110 ms frame), so the GPU saving does not reach the screen.
  • Artifacts in C: a frame grabbed at 330 s shows blocky corrupted tiles along the bottom of the screen and a stair-stepped edge on the character's shoulder. Which change causes it is not isolated. B's earlier frame looked clean.
  • Stability: no panic, device-removed or ERROR lines in C's log, no crash in 360 s.

For this PR: ran in C with VICTORY_QUEUE2=1 VICTORY_RELAY=2, no hang in 360 s. The relay thread's wait for card-copy piece fetches stayed at 4.4–4.5 ms in A, B and C, even with 3× the pieces in C. That fits this PR but does not isolate it. An earlier note here said unit tests passed; I have no record of running them, so please disregard that.

**@⁠Proudnoob4** on GitHub · 2026-11-25 23:17 UTC · [original](https://github.com/fxceless/victory-fork/pull/1172#issuecomment-7177370283) · edited 2026-11-25 23:26 UTC *AI-assisted (Claude Opus 5.5 in OpenCode), measured on my own machine. **This replaces two overlapping AI-written reports I posted here earlier; on re-auditing the logs, some of their numbers were single samples or misattributed, and one said there were no visual artifacts, which was wrong.*** **Setup:** RTX 4080 16 GB, Windows 10 22H2, Series X build, diagnostics release, prison-cell scene (~4,800 draws/frame). Three single 360 s runs, so this is a bundle comparison, not an isolated A/B: - **A** fxceless stack, f32 path - **B** = A + a local port of `Marvisak/VIctory#2825` native f16 - **C** = B + `#1168` + `#1147` + `#1164` (`VICTORY_CARD_PIECE_KB=16`) + `#1171` + `#1172` + a local commit (skip clean `card_dirty` copies; chunk wide compare dispatches to ≤ 65,535 groups) | In-world, from the logs | A | B | C | |---|---:|---:|---:| | FPS, 2nd-half median (max) | 8.8 (9.3) | 8.8 (9.7) | 8.9 (9.4) | | Usual frame, median | 112 ms | 111 ms | 113 ms | | GPU title lists (`all other lists`), 2nd-half median | 40.0 ms | 38.1 ms | **31.8 ms** | | `cardmeter`, 256-frame mean, steady | 40.8 ms | 40.9 ms | **31.6–33.7 ms** | | Copy-back (last usual-frame summary) | 23.2 ms / 62.5 MB | 22.4 ms / 60.9 MB | **28.4 ms** / 49.4 MB | | Pieces fetched on the copy queue / frame | ~1,370 | ~1,388 | **~4,138** | | Writes back in place / frame | 1,386 | 1,390 | 4,150 | | Card idle per frame | 62.5 ms | 68.7 ms | 68.8 ms | - **GPU:** title-list time fell by ~8 ms between B and C. Native f16 alone (A→B) changed it by ~2 ms at most (`cardmeter` unchanged). Which of C's additions gave the 8 ms is **not isolated**. - **No FPS change:** the frame is CPU-bound on the submit thread (copies ~63 ms + copy-back 22–28 ms of a ~110 ms frame), so the GPU saving does not reach the screen. - **Artifacts in C:** a frame grabbed at 330 s shows blocky corrupted tiles along the bottom of the screen and a stair-stepped edge on the character's shoulder. Which change causes it is **not isolated**. B's earlier frame looked clean. - **Stability:** no panic, device-removed or ERROR lines in C's log, no crash in 360 s. **For this PR:** ran in C with `VICTORY_QUEUE2=1 VICTORY_RELAY=2`, no hang in 360 s. The relay thread's wait for card-copy piece fetches stayed at 4.4–4.5 ms in A, B and C, even with 3× the pieces in C. That fits this PR but does not isolate it. An earlier note here said unit tests passed; I have no record of running them, so please disregard that.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.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/1172/head:github-bot/gh-1172'
git switch 'github-bot/gh-1172'

Merge

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