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

Open
zocram4cc wants to merge 81 commits from upstream-pr/34 into main
zocram4cc commented 2026-11-25 19:01:43 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by zocram4cc on 2026-11-25T19:01:43Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5497381745 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/34). Originally posted by [zocram4cc](https://github.com/zocram4cc) on 2026-11-25T19:01:43Z. --- 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.
PastiiJay commented 2026-11-25 19:07:14 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T19:07:14Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7171845950 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/34#issuecomment-7171845950). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T19:07:14Z. --- 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.
zocram4cc commented 2026-11-25 19:13:57 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by zocram4cc on 2026-11-25T19:13:57Z.


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!

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7172003539 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/34#issuecomment-7172003539). Originally posted by [zocram4cc](https://github.com/zocram4cc) on 2026-11-25T19:13:57Z. --- 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!
PastiiJay commented 2026-11-25 19:19:47 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T19:19:47Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7172144960 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/34#issuecomment-7172144960). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T19:19:47Z. --- 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 commented 2026-11-25 19:56:28 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T19:56:28Z.


@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!

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7172969842 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/34#issuecomment-7172969842). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T19:56:28Z. --- @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 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/34:upstream-pr/34'
git switch 'upstream-pr/34'

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/34'
git switch 'upstream-pr/34'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/34'
git switch 'upstream-pr/34'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/34'
git switch 'main'
git merge --squash 'upstream-pr/34'
git switch 'main'
git merge --ff-only 'upstream-pr/34'
git switch 'main'
git merge 'upstream-pr/34'
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
PastiiJay/klbf-lab!34
No description provided.