perf: under Wine, land copy-back by reading into title memory #276

Closed
github-bot wants to merge 2 commits from github-bot/gh-276 into main AGit
Owner

@⁠Anzymanz on GitHub · 2026-11-26 00:01 UTC · original
Anzymanz:perf/wine-land-by-read → main · +97 −5 · 3 files · 2 commits · closed without merging

What

Under Wine/Proton, write_mapped (copy-back: putting what shaders wrote back into title memory) now lands the bytes with a read into title memory (ReadProcessMemory on our own process, from the host copy) instead of NtWriteVirtualMemory. On Windows nothing changes.

VICTORY_DIRECT_WRITES keeps working and gains a value:

value landing
unset, under Wine read (new default there)
unset, Windows 1, as before
1 NtWriteVirtualMemory
0 WriteProcessMemory
read the read, on Windows too

Why

In Wine, NtWriteVirtualMemory always makes a wineserver request, even for the current process: the bytes go through the request socket and wineserver writes them with process_vm_writev. NtReadVirtualMemory on the current process is a memmove inside the process, under an exception guard. Both refuse an unmapped page the same way, so write_mapped's 64 KiB / 4 KiB fallback over holes keeps working (tested).

Measurements (GE-Proton11-14, RX 9070 XT, RADV; measured)

Microbenchmark, own process, per call:

size NtWriteVirtualMemory memcpy
4 KiB 13.5 µs 1.0 µs
64 KiB 118 µs 19 µs
1 MiB 1134 µs 187 µs

The title in its open world, first 180 s, same save, same scene (diagnostics host lines; medians):

landing copy-back per frame frame
NtWriteVirtualMemory (3 runs) 246 / 255 / 277 ms for ~74 MB 1131 / 1369 / 1129 ms
read 116 ms for ~74 MB 833 ms

Tests

  • host::write_way_tests::wine_lands_by_reading_unless_told_otherwise: mode selection.
  • host::write_way_tests::every_landing_writes_mapped_pages_and_skips_holes: every mode writes the committed pages and skips a reserved, uncommitted hole.

Both pass under Proton (proton runinprefix victory_gpu-*.exe host::). The release and diag --features diagnostics builds of victory succeed (cargo-xwin). descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed fails under Proton both with and without this change; it is not touched here. cargo xtask policy: ok.

Note

On upstream VIctory, write_mapped already lands through read(). This brings the AnyXboxX copy back in line under Wine, while keeping NtWriteVirtualMemory as the default on Windows, where it was measured (run 24).

Docs: VICTORY_DIRECT_WRITES row in docs/running-gta6.md and docs/fr/lancer-gta6.md.

AI assistance: written with Claude (Anthropic, Claude Code); measurements run and checked on my own machine.


🇫🇷 Sous Wine/Proton, le retour de copie passe désormais par une lecture (ReadProcessMemory sur notre propre processus) au lieu de NtWriteVirtualMemory, qui fait toujours un aller-retour au wineserver sous Wine. Sous Windows rien ne change. Mesuré : retour de copie de 246–277 ms à 116 ms par image pour ~74 Mo, image de ~1130 à 833 ms. VICTORY_DIRECT_WRITES=1 garde l'ancien comportement. Tests et documentation EN/FR inclus. Rédigé avec l'aide de Claude (IA).

🤖 Generated with Claude Code

**@⁠Anzymanz** on GitHub · 2026-11-26 00:01 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/276) `Anzymanz:perf/wine-land-by-read` → `main` · +97 −5 · 3 files · 2 commits · closed without merging ## What Under Wine/Proton, `write_mapped` (copy-back: putting what shaders wrote back into title memory) now lands the bytes with a **read into title memory** (`ReadProcessMemory` on our own process, from the host copy) instead of `NtWriteVirtualMemory`. On Windows nothing changes. `VICTORY_DIRECT_WRITES` keeps working and gains a value: | value | landing | |---|---| | unset, under Wine | `read` (new default there) | | unset, Windows | `1`, as before | | `1` | `NtWriteVirtualMemory` | | `0` | `WriteProcessMemory` | | `read` | the read, on Windows too | ## Why In Wine, `NtWriteVirtualMemory` always makes a wineserver request, even for the current process: the bytes go through the request socket and wineserver writes them with `process_vm_writev`. `NtReadVirtualMemory` on the current process is a `memmove` inside the process, under an exception guard. Both refuse an unmapped page the same way, so `write_mapped`'s 64 KiB / 4 KiB fallback over holes keeps working (tested). ## Measurements (GE-Proton11-14, RX 9070 XT, RADV; measured) Microbenchmark, own process, per call: | size | `NtWriteVirtualMemory` | `memcpy` | |---:|---:|---:| | 4 KiB | 13.5 µs | 1.0 µs | | 64 KiB | 118 µs | 19 µs | | 1 MiB | 1134 µs | 187 µs | The title in its open world, first 180 s, same save, same scene (diagnostics host lines; medians): | landing | copy-back per frame | frame | |---|---:|---:| | `NtWriteVirtualMemory` (3 runs) | 246 / 255 / 277 ms for ~74 MB | 1131 / 1369 / 1129 ms | | read | 116 ms for ~74 MB | 833 ms | ## Tests - `host::write_way_tests::wine_lands_by_reading_unless_told_otherwise`: mode selection. - `host::write_way_tests::every_landing_writes_mapped_pages_and_skips_holes`: every mode writes the committed pages and skips a reserved, uncommitted hole. Both pass under Proton (`proton runinprefix victory_gpu-*.exe host::`). The `release` and `diag --features diagnostics` builds of `victory` succeed (cargo-xwin). `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed` fails under Proton both with and without this change; it is not touched here. `cargo xtask policy`: ok. ## Note On upstream VIctory, `write_mapped` already lands through `read()`. This brings the AnyXboxX copy back in line under Wine, while keeping `NtWriteVirtualMemory` as the default on Windows, where it was measured (run 24). Docs: `VICTORY_DIRECT_WRITES` row in `docs/running-gta6.md` and `docs/fr/lancer-gta6.md`. **AI assistance:** written with Claude (Anthropic, Claude Code); measurements run and checked on my own machine. --- 🇫🇷 Sous Wine/Proton, le retour de copie passe désormais par une lecture (`ReadProcessMemory` sur notre propre processus) au lieu de `NtWriteVirtualMemory`, qui fait toujours un aller-retour au wineserver sous Wine. Sous Windows rien ne change. Mesuré : retour de copie de 246–277 ms à 116 ms par image pour ~74 Mo, image de ~1130 à 833 ms. `VICTORY_DIRECT_WRITES=1` garde l'ancien comportement. Tests et documentation EN/FR inclus. Rédigé avec l'aide de Claude (IA). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Under Wine, NtWriteVirtualMemory on our own process is a wineserver round
trip: the bytes go through the request socket and wineserver writes them
with process_vm_writev. ReadProcessMemory on our own process is a memmove
inside the process, and it checks and refuses an unmapped destination page
the same way. write_mapped now lands the bytes with a read under Wine;
VICTORY_DIRECT_WRITES=1 keeps the write, =0 the WriteProcessMemory wrapper,
and =read selects the read on Windows too. Windows behaviour is unchanged.

GE-Proton11-14: 118 us per 64 KiB written vs 19 us read. In the world
(first 180 s, same scene) copy-back fell from 246-277 ms to 116 ms a frame
for the same ~74 MB, and the frame from 1131 to 833 ms.

Tests: write_way_tests (mode selection, and every mode writes mapped pages
and skips a hole), run under Proton.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AI-assisted (Claude Code, Claude Opus 5.5).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:41:39 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 00:02 UTC · original · edited 2026-11-26 00:04 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T00:04:40.437519Z b49127c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 00:02 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/276#issuecomment-7178323920) · edited 2026-11-26 00:04 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"b49127cde704e4769dd3852ea5b2db2ec433ebea","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T00:04:40.437519Z">2026-11-26T00:04:40.437519Z</relative-time> | `b49127c` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 14:01 UTC · original

This PR now conflicts with main in third_party/victory/crates/victory-gpu/src/host.rs. Please rebase on main, re-check the Wine copy-back change against the current code, run cargo test for the crate and force-push your branch.

🤖 Generated with Claude Code

**@⁠LooperSalty** on GitHub · 2026-11-26 14:01 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/276#issuecomment-7194172878) This PR now conflicts with main in `third_party/victory/crates/victory-gpu/src/host.rs`. Please rebase on main, re-check the Wine copy-back change against the current code, run `cargo test` for the crate and force-push your branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot closed this pull request 2026-11-27 02:08:20 +00:00
Author
Owner

@⁠Anzymanz on GitHub · 2026-11-27 01:28 UTC · original

Thanks for the ping. I re-checked the change against current main, and it is superseded, so I'm closing this rather than rebasing it.

On main (the Vice-Tay base), write_mapped lands copy-back through crate::safecopy::copy: one in-process rep movsb whose faults the watch handler takes. It is on by default (VICTORY_SAFE_COPY), and it never goes through the kernel. This PR replaced a wineserver round trip (NtWriteVirtualMemory) with ReadProcessMemory. On the new base it would only change the VICTORY_SAFE_COPY=0 fallback, which isn't worth the extra mode or the docs line.

Not done: no re-measure on the new base and no cargo test there, since the code it changed is no longer on the default path. The numbers in the description (GE-Proton11-14: 118 us per 64 KiB written against 19 us read) were measured on the old base only.

Written with Claude Code.

**@⁠Anzymanz** on GitHub · 2026-11-27 01:28 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/276#issuecomment-7207319771) Thanks for the ping. I re-checked the change against current `main`, and it is superseded, so I'm closing this rather than rebasing it. On `main` (the Vice-Tay base), `write_mapped` lands copy-back through `crate::safecopy::copy`: one in-process `rep movsb` whose faults the watch handler takes. It is on by default (`VICTORY_SAFE_COPY`), and it never goes through the kernel. This PR replaced a wineserver round trip (`NtWriteVirtualMemory`) with `ReadProcessMemory`. On the new base it would only change the `VICTORY_SAFE_COPY=0` fallback, which isn't worth the extra mode or the docs line. Not done: no re-measure on the new base and no `cargo test` there, since the code it changed is no longer on the default path. The numbers in the description (GE-Proton11-14: 118 us per 64 KiB written against 19 us read) were measured on the old base only. Written with Claude Code.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.