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

Closed
Anzymanz wants to merge 2 commits from upstream-pr/276 into main
Anzymanz commented 2026-11-26 00:01:56 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Anzymanz on 2026-11-26T00:01:56Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5501351194 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/276). Originally posted by [Anzymanz](https://github.com/Anzymanz) on 2026-11-26T00:01:56Z. --- ## 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)
chatgpt-codex-connector[bot] commented 2026-11-26 00:02:09 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T00:02:09Z.


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.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7178323920 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/276#issuecomment-7178323920). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-26T00:02:09Z. --- <!-- 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>
LooperSalty commented 2026-11-26 14:01:43 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-26T14:01:43Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7194172878 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/276#issuecomment-7194172878). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T14:01:43Z. --- 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)
Anzymanz commented 2026-11-27 01:28:44 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Anzymanz on 2026-11-27T01:28:44Z.


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.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7207319771 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/276#issuecomment-7207319771). Originally posted by [Anzymanz](https://github.com/Anzymanz) on 2026-11-27T01:28:44Z. --- 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

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
LooperSalty/AnyXboxX!276
No description provided.