GPU: under Wine, write title memory without a wineserver request #256

Open
yayameowmeow wants to merge 1 commit from upstream-pr/256 into main
yayameowmeow commented 2026-11-24 23:01:55 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by yayameowmeow on 2026-11-24T23:01:55Z.


Problem

Under Wine (Linux, Proton), write_mapped sends a wineserver request for every write. It puts shader results back into title memory with NtWriteVirtualMemory, or WriteProcessMemory with VICTORY_DIRECT_WRITES=0. On Windows that is a kernel copy. Wine implements both as the server request write_process_memory, which writes /proc/<pid>/mem, even when the process writes into itself. wineserver is one thread, and the process's other server calls (mappings, handles, timers) queue behind it.

Counted with WINEDEBUG=+server in the opening gameplay scene (Wine 11.20, RX 7900 XTX / RADV): 3,400–24,000 write_process_memory requests per 30 s.

Fix

Under Wine (ntdll!wine_get_version present), the write becomes a read of our own process, from the host copy into the title page: ReadProcessMemory(GetCurrentProcess(), host, title, n).

  • Wine copies such a read in place, without the server.
  • It checks the destination is writable first, so a failure is reported exactly as before. The existing 64 KiB / 4 KiB piece fallback still leaves unmapped pages alone.
  • VICTORY_WINE_WRITES=0 restores the old call.
  • Windows does not change.

Verification

  • Server traffic: after the change, write_process_memory no longer appears among the server requests (same scene, +server count).
  • No frame-rate claim: in that run the stock wineserver stayed saturated by map_view/unmap_view. Its per-process view list is searched linearly, which this PR doesn't address. With that also fixed locally, the scene runs at 0.6–0.9 s per frame instead of 2–6 s, but that number belongs to both changes.
  • New test host::writes::writes_skip_pages_that_are_not_mapped: writes across two committed 64 KiB blocks around an uncommitted one and checks the committed ones got the bytes. Passes under Wine on both paths, the default and VICTORY_WINE_WRITES=0.
  • Clippy: cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features are clean (cross-built with cargo-xwin).
  • Tests: cargo test -p victory-gpu under Wine gives 107 passed, 4 failed. The same 4 fail on unmodified main under Wine: argument clamp, depth-plane twin, pipeline library, scratch reuse. Those are the Wine shader-compiler issues covered by #20 / #127. I couldn't run the suite on Windows.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593154172 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/256). Originally posted by [yayameowmeow](https://github.com/yayameowmeow) on 2026-11-24T23:01:55Z. --- ### Problem Under Wine (Linux, Proton), `write_mapped` sends a **wineserver request for every write**. It puts shader results back into title memory with `NtWriteVirtualMemory`, or `WriteProcessMemory` with `VICTORY_DIRECT_WRITES=0`. On Windows that is a kernel copy. Wine implements both as the server request `write_process_memory`, which writes `/proc/<pid>/mem`, even when the process writes into itself. wineserver is one thread, and the process's other server calls (mappings, handles, timers) queue behind it. Counted with `WINEDEBUG=+server` in the opening gameplay scene (Wine 11.20, RX 7900 XTX / RADV): **3,400–24,000 `write_process_memory` requests per 30 s**. ### Fix Under Wine (`ntdll!wine_get_version` present), the write becomes a read of our own process, from the host copy into the title page: `ReadProcessMemory(GetCurrentProcess(), host, title, n)`. - Wine copies such a read in place, without the server. - It checks the destination is writable first, so a failure is reported exactly as before. The existing 64 KiB / 4 KiB piece fallback still leaves unmapped pages alone. - `VICTORY_WINE_WRITES=0` restores the old call. - **Windows does not change.** ### Verification - **Server traffic:** after the change, `write_process_memory` no longer appears among the server requests (same scene, `+server` count). - **No frame-rate claim:** in that run the stock wineserver stayed saturated by `map_view`/`unmap_view`. Its per-process view list is searched linearly, which this PR doesn't address. With that also fixed locally, the scene runs at 0.6–0.9 s per frame instead of 2–6 s, but that number belongs to both changes. - **New test** `host::writes::writes_skip_pages_that_are_not_mapped`: writes across two committed 64 KiB blocks around an uncommitted one and checks the committed ones got the bytes. Passes under Wine on both paths, the default and `VICTORY_WINE_WRITES=0`. - **Clippy:** `cargo clippy --workspace --all-targets --locked -- -D warnings` and the same with `--all-features` are clean (cross-built with cargo-xwin). - **Tests:** `cargo test -p victory-gpu` under Wine gives 107 passed, 4 failed. The same 4 fail on unmodified `main` under Wine: argument clamp, depth-plane twin, pipeline library, scratch reuse. Those are the Wine shader-compiler issues covered by #20 / #127. I couldn't run the suite on Windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ErRusso commented 2026-11-25 00:09:32 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ErRusso on 2026-11-24T23:43:41Z.

Review: APPROVED


Reviewed at d945776 against 2119b0e.

The Wine path is sound: ReadProcessMemory(GetCurrentProcess(), host, title, n) copies into the title page in-process, while the existing 64 KiB/4 KiB fallback still leaves unmapped pages alone. VICTORY_WINE_WRITES=0 preserves the old call and on_wine() is cached.

Verified: host::writes::writes_skip_pages_that_are_not_mapped passes under Wine on the new path (the hole is skipped, the committed blocks receive the bytes). The author's server-count and title measurements cover the performance claim.

LGTM.

<!-- greyfinch-sync:fxceless/victory-fork:review:6049236717 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/256#pullrequestreview-6049236717). Originally posted by [ErRusso](https://github.com/ErRusso) on 2026-11-24T23:43:41Z. **Review:** APPROVED --- Reviewed at `d945776` against `2119b0e`. The Wine path is sound: `ReadProcessMemory(GetCurrentProcess(), host, title, n)` copies into the title page in-process, while the existing 64 KiB/4 KiB fallback still leaves unmapped pages alone. `VICTORY_WINE_WRITES=0` preserves the old call and `on_wine()` is cached. Verified: `host::writes::writes_skip_pages_that_are_not_mapped` passes under Wine on the new path (the hole is skipped, the committed blocks receive the bytes). The author's server-count and title measurements cover the performance claim. LGTM.
Filip722 commented 2026-11-26 02:08:42 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-26T01:20:27Z.


I tested d945776 under GE-Proton11-14 on Bazzite 44, vkd3d-proton cae8353ed7959c4+, and an RTX 5060 Laptop GPU with NVIDIA 615.78.08. The local integration is based on dc4c0fc and adds copy-back timing. The mapped–unmapped–mapped writes test passed with each API selected, and the title log confirmed wine_runtime=true and the expected API in both launches.

The two offline Series S runs used the same binary, warm seed, memory/VRAM limits and NVMe caps. Four comparable post-upscale opening frames wrote about 0.8–4.5 MB each. With the legacy NtWriteVirtualMemory path their copy-back times were 3.03, 2.98, 9.64 and 10.14 s. With Wine's in-process ReadProcessMemory path the corresponding observations were 0.52, 0.56, 0.67 and 0.45 s. Median copy-back wall time across those four frames fell from 6.33 s to 0.54 s. The control's minimum free-disk reserve was reduced for replay and was inactive through the measured frames.

The in-process run returned 58 post-upscale Presents and rendered the opening sequence. It ended on the local NVMe contention guard. This was one run per API and its performance measurements cover copy-back during the opening.

Codex assisted with the integration and tests.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7179675800 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/256#issuecomment-7179675800). Originally posted by [Filip722](https://github.com/Filip722) on 2026-11-26T01:20:27Z. --- I tested `d945776` under GE-Proton11-14 on Bazzite 44, vkd3d-proton `cae8353ed7959c4+`, and an RTX 5060 Laptop GPU with NVIDIA 615.78.08. The local integration is based on `dc4c0fc` and adds copy-back timing. The mapped–unmapped–mapped writes test passed with each API selected, and the title log confirmed `wine_runtime=true` and the expected API in both launches. The two offline Series S runs used the same binary, warm seed, memory/VRAM limits and NVMe caps. Four comparable post-upscale opening frames wrote about 0.8–4.5 MB each. With the legacy `NtWriteVirtualMemory` path their copy-back times were 3.03, 2.98, 9.64 and 10.14 s. With Wine's in-process `ReadProcessMemory` path the corresponding observations were 0.52, 0.56, 0.67 and 0.45 s. Median copy-back wall time across those four frames fell from 6.33 s to 0.54 s. The control's minimum free-disk reserve was reduced for replay and was inactive through the measured frames. The in-process run returned 58 post-upscale Presents and rendered the opening sequence. It ended on the local NVMe contention guard. This was one run per API and its performance measurements cover copy-back during the opening. Codex assisted with the integration and tests.
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/256:upstream-pr/256'
git switch 'upstream-pr/256'

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/256'
git switch 'upstream-pr/256'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/256'
git switch 'upstream-pr/256'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/256'
git switch 'main'
git merge --squash 'upstream-pr/256'
git switch 'main'
git merge --ff-only 'upstream-pr/256'
git switch 'main'
git merge 'upstream-pr/256'
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
fxceless/victory-fork!256
No description provided.