GPU: cut the per-frame copy and pipeline-library churn #363

Open
github-bot wants to merge 7 commits from github-bot/gh-363 into main AGit
Owner

@⁠meeyao on GitHub · 2026-11-24 23:56 UTC · original
meeyao:linux-copy-perf → main · +175 −18 · 5 files · 7 commits · open

Changes from the Linux/Proton run, where the frame is host-side copies and waits (the GPU is ~10% busy):

  • read title memory through NtReadVirtualMemory instead of a kernel copy per call;
  • memcpy committed ranges instead of a kernel copy per call;
  • copy the committed runs of a view, not just the whole range;
  • ask VirtualQuery only for large reads, and count what memcpy moves;
  • split an unwatchable range instead of copying the whole buffer (shadow);
  • stop keeping a kind of pipeline the host's library refuses to load (mesh pipelines are compiled every run and refused on load), and load the keep check through the library's own handle.

The last two pipeline-library commits are Pablo Barros' from Pablo-Barros/VIctory#1683. The zero-padding fix from that series is deliberately left to #238.

Measured on the RTX 3070 host: world frames 0.3–0.5 fps, 2.1–3.6 s/frame; copies 1.1–2.1 s; copied whole (memory not watched): 0.0 ms/frame; the library logs once refuses a mesh pipeline it just stored and stops growing (231 MB here). Nothing in shadow is fixed by this.

This is the copy/pipeline part of the original #28, split as asked.

Checked with cargo xwin check --all-targets -p victory-gpu --target x86_64-pc-windows-msvc. Behaviour on Windows is unchanged except NtReadVirtualMemory, which is the same kernel path ReadProcessMemory uses; not run in the title here.

**@⁠meeyao** on GitHub · 2026-11-24 23:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/363) `meeyao:linux-copy-perf` → `main` · +175 −18 · 5 files · 7 commits · open Changes from the Linux/Proton run, where the frame is host-side copies and waits (the GPU is ~10% busy): - read title memory through `NtReadVirtualMemory` instead of a kernel copy per call; - `memcpy` committed ranges instead of a kernel copy per call; - copy the committed runs of a view, not just the whole range; - ask `VirtualQuery` only for large reads, and count what `memcpy` moves; - split an unwatchable range instead of copying the whole buffer (shadow); - stop keeping a kind of pipeline the host's library refuses to load (mesh pipelines are compiled every run and refused on load), and load the keep check through the library's own handle. The last two pipeline-library commits are Pablo Barros' from Pablo-Barros/VIctory#1683. The zero-padding fix from that series is deliberately left to #238. Measured on the RTX 3070 host: world frames 0.3–0.5 fps, 2.1–3.6 s/frame; copies 1.1–2.1 s; `copied whole (memory not watched): 0.0 ms/frame`; the library logs once `refuses a mesh pipeline it just stored` and stops growing (231 MB here). Nothing in shadow is fixed by this. This is the copy/pipeline part of the original #28, split as asked. Checked with `cargo xwin check --all-targets -p victory-gpu --target x86_64-pc-windows-msvc`. Behaviour on Windows is unchanged except `NtReadVirtualMemory`, which is the same kernel path `ReadProcessMemory` uses; not run in the title here.
GetWriteWatch refuses a range spanning two reservations; one such range
marked the buffer NOT_WATCHED and every later frame copied 100-750 MB of it.
Halving the range keeps the rest watched and only the failing piece is
copied whole.
D3D12's pipeline library does not load mesh pipelines. A mesh pipeline
stored and at once loaded back under its name, with the description that
created it, is refused (E_INVALIDARG; the debug layer: the pipeline state
desc provided does not match the one used to create the PSO). So it is
with trivial shaders and an empty root signature, without the title: on
an RTX 3070 with the system runtime (10.0.26100.10068), on WARP, and with
the Agility SDK runtime 1.618.1, while graphics and compute pipelines
load back on each. Every form of the stream tried fails: the minimum,
with an empty amplification shader, without a pixel shader, and the ten
subobjects we hand over.

In the game, of the 1,800 pipelines the early start makes, the 723 mesh
pipelines are compiled in every run (the others load), each is stored
again and refused (already exists), and its entry stays in a library
that only grows (231 MB here).

The first pipeline of a kind that is stored is now loaded back at once;
refused, the library gets no more of that kind in the run, and says so
once. With the debug layer on, the run's library errors go from 712
"already exists" and 717 "does not match" to one and two.

Co-Authored-By: Claude <[email protected]>
(cherry picked from commit cae3f32d7edfe4ed3aa9e10382678143bc7fe185)
The kernel copy through ReadProcessMemory is one call per copy; the
world makes thousands of small ones a frame. Read NtReadVirtualMemory
directly for the title's own process.
The kernel read/write copied at 40 MB/s and 10 MB/s here (93 MB a frame
read, 35 MB written back: 5.5 s of a 7.2 s world frame). One VirtualQuery
per region says the bytes are committed and readable/writable, and the
copy is then memory speed; anything else still goes through the kernel
call and its page-by-page fallback.
Title memory is view memory with holes, so a whole-range fast path never
matched and every put-back went through NtWriteVirtualMemory per 64 KiB
piece (~6 ms a call). Walk the runs instead: memcpy what is committed and
writable, kernel only for the holes.
A world frame makes ~9,000 title copies of ~600 bytes; one query each cost
5.4 s a frame against 53 ms through the kernel. Below 256 KiB the kernel
call is the cheap one. The copystat line now says how many bytes took the
memcpy path.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:41:42 +00:00
Author
Owner

@⁠pepezin-ai on GitHub · 2026-11-25 00:57 UTC · original

Regression on native Windows: copy back goes from ~34 ms to ~3.6 s per frame with this PR

Tested on Windows 11, AMD Ryzen 7 5700X (8C/16T), 32 GB RAM (DDR4-3200), NVIDIA RTX 5070 12 GB, Series X profile, release build.

  • Base: fxceless/victory-fork main @ 2119b0e + #156 + #213 + d214807 (R9G9B9E5 stand-in), VICTORY_HOST_WAVE=32, AnyXboxX tuned settings (LATE_WAIT=3, WIDE_BACK=1, CARD_BUFFERS_MB=1024, loop limit 256).
  • Same base + #363 + #203, same settings, same prison cell scene.
base base + #363 (+ #203)
world fps (avg of ~60-100 samples) 2.5-3.3 0.24
copying back per frame 33.7-34.9 ms 3596-3871 ms
preparing per frame 155-160 ms 214-216 ms
on the GPU per frame 79-95 ms 76-98 ms

Frame-line samples (victory_gpu::host):

base:   3.3 fps, 303.5 ms/frame (160.7 preparing: copies 78.3 ms 125.8 MB, textures 32.5 ms 25.5 MB; 79.4 on the GPU; 33.7 copying back 54.8 MB), 6843 draws/frame
#363:   0.3 fps, 3938.8 ms/frame (214.1 preparing: copies 137.4 ms 163.0 MB, textures 58.8 ms 134.5 MB; 76.1 on the GPU; 3596.4 copying back 83.1 MB), 4830 draws/frame

A build with #203 but without #363 (newer main a803c87 + #156 + #213 + #203) averaged 2.3 fps (max 3.8) in the same scene, with copy back at ~52 ms per frame, so the copy-back regression points at #363's copy changes (NtReadVirtualMemory reads / memcpy of committed ranges). The PR was measured under Linux/Proton; on native Windows it seems to make the copy back far slower. Maybe gate the new read path behind a switch or keep the old path on Windows.

No game files or personal data in this report.

**@⁠pepezin-ai** on GitHub · 2026-11-25 00:57 UTC · [original](https://github.com/fxceless/victory-fork/pull/363#issuecomment-7149067082) **Regression on native Windows: copy back goes from ~34 ms to ~3.6 s per frame with this PR** Tested on Windows 11, AMD Ryzen 7 5700X (8C/16T), 32 GB RAM (DDR4-3200), NVIDIA RTX 5070 12 GB, Series X profile, release build. - Base: `fxceless/victory-fork` main @ 2119b0e + #156 + #213 + d214807 (R9G9B9E5 stand-in), `VICTORY_HOST_WAVE=32`, AnyXboxX tuned settings (`LATE_WAIT=3`, `WIDE_BACK=1`, `CARD_BUFFERS_MB=1024`, loop limit 256). - Same base + #363 + #203, same settings, same prison cell scene. | | base | base + #363 (+ #203) | |---|---|---| | world fps (avg of ~60-100 samples) | 2.5-3.3 | 0.24 | | copying back per frame | 33.7-34.9 ms | 3596-3871 ms | | preparing per frame | 155-160 ms | 214-216 ms | | on the GPU per frame | 79-95 ms | 76-98 ms | Frame-line samples (`victory_gpu::host`): ``` base: 3.3 fps, 303.5 ms/frame (160.7 preparing: copies 78.3 ms 125.8 MB, textures 32.5 ms 25.5 MB; 79.4 on the GPU; 33.7 copying back 54.8 MB), 6843 draws/frame #363: 0.3 fps, 3938.8 ms/frame (214.1 preparing: copies 137.4 ms 163.0 MB, textures 58.8 ms 134.5 MB; 76.1 on the GPU; 3596.4 copying back 83.1 MB), 4830 draws/frame ``` A build with #203 but without #363 (newer main a803c87 + #156 + #213 + #203) averaged 2.3 fps (max 3.8) in the same scene, with copy back at ~52 ms per frame, so the copy-back regression points at #363's copy changes (`NtReadVirtualMemory` reads / memcpy of committed ranges). The PR was measured under Linux/Proton; on native Windows it seems to make the copy back far slower. Maybe gate the new read path behind a switch or keep the old path on Windows. No game files or personal data in this report.
Author
Owner

@⁠meeyao on GitHub · 2026-11-25 01:16 UTC · original

Thanks for the measurement - this is a real regression and the numbers point straight at it.

The copy-back path in this PR writes title memory through write_mapped, which now first asks VirtualQuery for each piece's committed run to use a plain memcpy. The fork's own comment records what that query costs in the title's big pools: about 2 ms per call, because it walks the page tables to the region's end. Under Wine the piece count per frame was small enough that it hid; on native Windows, at ~100 pieces a frame, 2 ms each is the 3.6 s you measured. The 34 ms base path was NtWriteVirtualMemory per 64 KiB piece with no query at all.

Fix: gate the mapped-run/memcpy path on Wine (ntdll!wine_get_version present) and keep the kernel piece path on native Windows, where it was already the fast one. The same applies to the read side.

I will push that to linux-copy-perf and ask you to re-run the same prison-cell scene.

**@⁠meeyao** on GitHub · 2026-11-25 01:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/363#issuecomment-7149383890) Thanks for the measurement - this is a real regression and the numbers point straight at it. The copy-back path in this PR writes title memory through `write_mapped`, which now first asks `VirtualQuery` for each piece's committed run to use a plain `memcpy`. The fork's own comment records what that query costs in the title's big pools: about 2 ms per call, because it walks the page tables to the region's end. Under Wine the piece count per frame was small enough that it hid; on native Windows, at ~100 pieces a frame, 2 ms each is the 3.6 s you measured. The 34 ms base path was `NtWriteVirtualMemory` per 64 KiB piece with no query at all. Fix: gate the mapped-run/memcpy path on Wine (`ntdll!wine_get_version` present) and keep the kernel piece path on native Windows, where it was already the fast one. The same applies to the read side. I will push that to `linux-copy-perf` and ask you to re-run the same prison-cell scene.
Author
Owner

@⁠Jonirulah on GitHub · 2026-11-25 01:17 UTC · original

I tested this PR on native Windows, and here it makes frames about 6-15x slower than without it.

Setup

  • NVIDIA RTX 3070 Laptop GPU (8 GB), Ryzen 7 5800H, 32 GB RAM, Windows 11 LTSC 26100.
  • Release build, Series S mode (--console series-s).
  • Env: VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024 VICTORY_LEAN_WINDOWS=1 VICTORY_PIPELINE_WAIT_MS=24.
  • Base branch: fork main (2119b0e) + #188, #270, #186, #159, #265, #97, #258, #241, #203, #261.
  • The only difference between the two runs is this PR merged on top.

Opening cutscene, same scene, warm pipeline library

ms/frame fps "on the GPU" "copying back"
without #363 230-257 3.9-4.3 77-111 ms 115-140 ms
with #363 1,513-3,724 0.3-0.7 1,121-2,367 ms 1,281-3,284 ms

Diagnostics build (earlier run, this PR together with #194; the regression later reproduced with #363 alone, above), per frame:

  • "watches": 42 ms ? 198 ms.
  • fallbacks: 0.4 ? 142.
  • page faults: ~470 ? ~13,800.
  • moves: 24 ms ? 84 ms ("79.4 MB by memcpy").

My guess, untested: the memcpy path faults on pages we guard/write-watch, which would explain the page faults and fallbacks. I did not bisect the seven commits, so I can't say whether it's the copy commits or the pipeline-library ones. The jump in GPU time is odd, though: it may be the library change forcing mesh pipelines to be rebuilt every run, or host copies landing differently.

The Proton/Linux numbers in the description may well hold there. On native Windows, though, this should probably be gated behind a switch, or kept to Wine only.

**@⁠Jonirulah** on GitHub · 2026-11-25 01:17 UTC · [original](https://github.com/fxceless/victory-fork/pull/363#issuecomment-7149396401) I tested this PR on native Windows, and here it makes frames about 6-15x slower than without it. **Setup** - NVIDIA RTX 3070 Laptop GPU (8 GB), Ryzen 7 5800H, 32 GB RAM, Windows 11 LTSC 26100. - Release build, Series S mode (`--console series-s`). - Env: `VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024 VICTORY_LEAN_WINDOWS=1 VICTORY_PIPELINE_WAIT_MS=24`. - Base branch: fork `main` (`2119b0e`) + #188, #270, #186, #159, #265, #97, #258, #241, #203, #261. - The only difference between the two runs is this PR merged on top. **Opening cutscene, same scene, warm pipeline library** | | ms/frame | fps | "on the GPU" | "copying back" | |---|---|---|---|---| | without #363 | 230-257 | 3.9-4.3 | 77-111 ms | 115-140 ms | | with #363 | 1,513-3,724 | 0.3-0.7 | 1,121-2,367 ms | 1,281-3,284 ms | **Diagnostics build** (earlier run, this PR together with #194; the regression later reproduced with #363 alone, above), per frame: - "watches": 42 ms ? 198 ms. - fallbacks: 0.4 ? 142. - page faults: ~470 ? ~13,800. - moves: 24 ms ? 84 ms ("79.4 MB by memcpy"). My guess, untested: the `memcpy` path faults on pages we guard/write-watch, which would explain the page faults and fallbacks. I did not bisect the seven commits, so I can't say whether it's the copy commits or the pipeline-library ones. The jump in GPU time is odd, though: it may be the library change forcing mesh pipelines to be rebuilt every run, or host copies landing differently. The Proton/Linux numbers in the description may well hold there. On native Windows, though, this should probably be gated behind a switch, or kept to Wine only.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/pipeline/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/363/head:github-bot/gh-363'
git switch 'github-bot/gh-363'

Merge

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