Wine/Proton: in-process copies of title memory (VICTORY_DIRECT_COPY=1), with guard pages handled #34

Open
github-bot wants to merge 3 commits from github-bot/gh-34 into beta AGit
Owner

@⁠zocram4cc on GitHub · 2026-11-25 19:01 UTC · original
zocram4cc:up/direct-copy → beta · +317 −7 · 2 files · 3 commits · open

Under Wine/Proton, putting back what shaders wrote is the slowest part of a world frame: Wine's NtWriteVirtualMemory sends every byte through wineserver, even for the calling process (write_process_memory request in dlls/ntdll/unix/virtual.c), so copy-back takes seconds a frame and wineserver sits at ~70 % of a core with the GPU idle. This is the report in #19.

Change

  • GPU: use VEH-guarded in-process copy for copy_mapped and write_mapped: the commit of fxceless/victory-fork#154 by @⁠BitWuehler, cherry-picked unchanged (authorship kept). Reads and copy-back copy in-process; a vectored handler turns a fault inside the copy into a failed copy, as the kernel calls report it.
  • Opt-in: VICTORY_DIRECT_COPY=1 turns it on; without it nothing changes (Windows behaviour untouched).
  • Fix on top: the handler did not catch STATUS_GUARD_PAGE_VIOLATION. Title memory has guard pages, so with the copy on the process ended with unhandled exception 0x80000001 after a minute or two in the world (Shadow::copy → copy_mapped → read → try_copy, symbolised from the PDB). This is the crash in #19's second run. A guard page now fails the copy like an unreadable page, and the guard flag is set again (the fault that reported it cleared it), so the title still sees its own first touch.

Tests (Proton Experimental 11.0-20261112, cross-built with cargo-xwin)

  • New direct_copy_fails_on_a_guard_page_and_keeps_it_guarded: the test process dies without the fix, passes with it.
  • write_mapped_skips_unmapped_and_readonly_pages_and_marks_write_watch passes with and without VICTORY_DIRECT_COPY=1.
  • benchmark_direct_copy_vs_kernel_calls (--ignored --nocapture, under Wine): 64 KiB writes NtWriteVirtualMemory 1,221 MB/s vs in-process 42,068 MB/s; 256 MB read 6.0 vs 10.1 GB/s.

In game (RX 6900 XT, RADV / Mesa 26.3.1, Proton Experimental, Series X, scripted input, fresh profile; world medians of a per-second frame-time log)

Measured on a build of 553bd7c with the Wine fixes listed in #19; the copy path is the same as on this branch.

ms/frame copy-back ms preparing ms
without 5,478 3,420 1,429
VICTORY_DIRECT_COPY=1 1,817 144 1,199
VICTORY_DIRECT_COPY=1 + guard fix 2,053 (~5 min in the world, no 0x80000001) 142 1,378

The run with the fix then stopped at the title's own breakpoint +0x5149aec (INSTANCE_LIST pool full, Marvisak/VIctory#698), which is unrelated.

Not tested on Windows. Off by default, so Windows runs are unchanged unless the switch is set.

No game files, logs or dumps attached. AI-assisted (Claude Code); runs and measurements on my machine.

**@⁠zocram4cc** on GitHub · 2026-11-25 19:01 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/34) `zocram4cc:up/direct-copy` → `beta` · +317 −7 · 2 files · 3 commits · open Under Wine/Proton, putting back what shaders wrote is the slowest part of a world frame: Wine's `NtWriteVirtualMemory` sends every byte through wineserver, even for the calling process (`write_process_memory` request in `dlls/ntdll/unix/virtual.c`), so copy-back takes seconds a frame and wineserver sits at ~70 % of a core with the GPU idle. This is the report in #19. ## Change - `GPU: use VEH-guarded in-process copy for copy_mapped and write_mapped`: the commit of fxceless/victory-fork#154 by @⁠BitWuehler, cherry-picked unchanged (authorship kept). Reads and copy-back copy in-process; a vectored handler turns a fault inside the copy into a failed copy, as the kernel calls report it. - Opt-in: `VICTORY_DIRECT_COPY=1` turns it on; without it nothing changes (Windows behaviour untouched). - Fix on top: the handler did not catch `STATUS_GUARD_PAGE_VIOLATION`. Title memory has guard pages, so with the copy on the process ended with `unhandled exception 0x80000001` after a minute or two in the world (`Shadow::copy` → `copy_mapped` → `read` → `try_copy`, symbolised from the PDB). This is the crash in #19's second run. A guard page now fails the copy like an unreadable page, and the guard flag is set again (the fault that reported it cleared it), so the title still sees its own first touch. ## Tests (Proton Experimental 11.0-20261112, cross-built with cargo-xwin) - New `direct_copy_fails_on_a_guard_page_and_keeps_it_guarded`: the test process dies without the fix, passes with it. - `write_mapped_skips_unmapped_and_readonly_pages_and_marks_write_watch` passes with and without `VICTORY_DIRECT_COPY=1`. - `benchmark_direct_copy_vs_kernel_calls` (`--ignored --nocapture`, under Wine): 64 KiB writes NtWriteVirtualMemory 1,221 MB/s vs in-process 42,068 MB/s; 256 MB read 6.0 vs 10.1 GB/s. ## In game (RX 6900 XT, RADV / Mesa 26.3.1, Proton Experimental, Series X, scripted input, fresh profile; world medians of a per-second frame-time log) Measured on a build of 553bd7c with the Wine fixes listed in #19; the copy path is the same as on this branch. | | ms/frame | copy-back ms | preparing ms | |---|---:|---:|---:| | without | 5,478 | 3,420 | 1,429 | | `VICTORY_DIRECT_COPY=1` | 1,817 | 144 | 1,199 | | `VICTORY_DIRECT_COPY=1` + guard fix | 2,053 (~5 min in the world, no 0x80000001) | 142 | 1,378 | The run with the fix then stopped at the title's own breakpoint `+0x5149aec` (`INSTANCE_LIST` pool full, Marvisak/VIctory#698), which is unrelated. Not tested on Windows. Off by default, so Windows runs are unchanged unless the switch is set. No game files, logs or dumps attached. AI-assisted (Claude Code); runs and measurements on my machine.
(cherry picked from commit 08e3d3011653a057cea3691d52be7777fc0d7a74)
The in-process copy is new on this branch and untested on Windows here, so it
starts off: VICTORY_DIRECT_COPY=1 turns it on, as in the Linux/Proton report
of issue #19.
With VICTORY_DIRECT_COPY=1 the in-process copy's exception handler only
caught access violations and in-page errors. A guard page in title memory
(STATUS_GUARD_PAGE_VIOLATION, 0x80000001) went unhandled and ended the
process (Shadow::copy -> copy_mapped -> read -> try_copy; also klbf-lab
issue #19's crash). It now fails the copy like an unreadable page and sets
the guard flag again, since raising the fault cleared it.

Test: direct_copy_fails_on_a_guard_page_and_keeps_it_guarded (the test process
dies without the fix, passes with it, under Proton Experimental).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:53:01 +00:00
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 19:07 UTC · original

Thanks a lot @⁠zocram4cc for opening these! It's great to have the Wine/Proton side covered. I'll test that nothing changes on Windows (the switch is off by default, right?) and report back here.

**@⁠PastiiJay** on GitHub · 2026-11-25 19:07 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/34#issuecomment-7171845950) Thanks a lot @⁠zocram4cc for opening these! It's great to have the Wine/Proton side covered. I'll test that nothing changes on Windows (the switch is off by default, right?) and report back here.
Author
Owner

@⁠zocram4cc on GitHub · 2026-11-25 19:13 UTC · original

Yes, it stays off by default. Only VICTORY_DIRECT_COPY=1 turns it on (direct_copy_enabled: std::env::var_os("VICTORY_DIRECT_COPY").is_some_and(|v| v == "1"), host.rs:6549); any other value or no variable keeps the old path.

With the switch off, on Windows:

  • read goes to read_kernel, which is the same ReadProcessMemory call as before.
  • write_mapped takes the same NtWriteVirtualMemory / WriteProcessMemory branches as before (in_process is false).
  • The new vectored handler is only registered on the first in-process copy, so it is never installed.
  • The guard-page change sits inside that handler, so it has no effect either.

The one change on the default path is in watch.rs: the body of the write-fault handler moved unchanged into handle_write_fault, so the in-process copy can share it, and the handler now calls it. It is the same logic and lock, just moved.

Thanks for testing on Windows!

**@⁠zocram4cc** on GitHub · 2026-11-25 19:13 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/34#issuecomment-7172003539) Yes, it stays off by default. Only `VICTORY_DIRECT_COPY=1` turns it on (`direct_copy_enabled`: `std::env::var_os("VICTORY_DIRECT_COPY").is_some_and(|v| v == "1")`, host.rs:6549); any other value or no variable keeps the old path. With the switch off, on Windows: - `read` goes to `read_kernel`, which is the same `ReadProcessMemory` call as before. - `write_mapped` takes the same `NtWriteVirtualMemory` / `WriteProcessMemory` branches as before (`in_process` is false). - The new vectored handler is only registered on the first in-process copy, so it is never installed. - The guard-page change sits inside that handler, so it has no effect either. The one change on the default path is in `watch.rs`: the body of the write-fault handler moved unchanged into `handle_write_fault`, so the in-process copy can share it, and the handler now calls it. It is the same logic and lock, just moved. Thanks for testing on Windows!
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 19:19 UTC · original

Perfect, thanks for the precise answer @⁠zocram4cc. That's exactly what I wanted to check. I'll run it with the switch off on our RX 9070 XT to confirm nothing moves, then merge.

**@⁠PastiiJay** on GitHub · 2026-11-25 19:19 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/34#issuecomment-7172144960) Perfect, thanks for the precise answer @⁠zocram4cc. That's exactly what I wanted to check. I'll run it with the switch off on our RX 9070 XT to confirm nothing moves, then merge.
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 19:56 UTC · original

@⁠zocram4cc I've added a "Playing on Linux / Proton?" box at the top of both READMEs (main and beta) pointing Linux players to your work (#34, #35) and asking them to tag you with their results. Thanks for leading the Linux side!

**@⁠PastiiJay** on GitHub · 2026-11-25 19:56 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/34#issuecomment-7172969842) @⁠zocram4cc I've added a "Playing on Linux / Proton?" box at the top of both READMEs (main and beta) pointing Linux players to your work (#34, #35) and asking them to tag you with their results. Thanks for leading the Linux side!
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/34/head:github-bot/gh-34'
git switch 'github-bot/gh-34'

Merge

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