Skip to content

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

Open
yayameowmeow wants to merge 1 commit into
fxceless:mainfrom
yayameowmeow:linux/wine-self-writes
Open

yayameowmeow wants to merge 1 commit into
fxceless:mainfrom
yayameowmeow:linux/wine-self-writes

Conversation

@yayameowmeow

Copy link
Copy Markdown

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 GPU: compile our run-time HLSL with DXC when the system compiler refuses it (Wine/Proton) #20 / GPU: compile internal HLSL and serialize root signatures natively under Wine/Proton #127. I couldn't run the suite on Windows.

🤖 Generated with Claude Code

write_mapped puts what shaders wrote back into title memory with
NtWriteVirtualMemory (or WriteProcessMemory), which on Windows is a
kernel copy. Wine implements both as a wineserver request (the server
writes /proc/<pid>/mem), even for the calling process, so in gameplay
every frame sent thousands of requests to one server thread that every
other thread of the process also waits on. A read of the calling process
is copied in place by Wine, after it checks the destination is writable,
so under Wine the write is that read, from the host copy into the title
page. Windows is unchanged; VICTORY_WINE_WRITES=0 writes as there.

A test writes across committed pages around an uncommitted one: the
pages around the hole get the bytes and nothing faults (both paths
checked under Wine 11.20).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@ErRusso ErRusso left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

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.

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