Skip to content

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

Open
zocram4cc wants to merge 3 commits into
PastiiJay:betafrom
zocram4cc:up/direct-copy
Open

zocram4cc wants to merge 3 commits into
PastiiJay:betafrom
zocram4cc:up/direct-copy

Conversation

@zocram4cc

Copy link
Copy Markdown

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

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.

BitWuehler and others added 3 commits November 25, 2026 20:00
(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 PastiiJay#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 PastiiJay#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).
@PastiiJay

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants