perf(xmem,resource): add opt-in MEM_WRITE_WATCH for large private allocations #321

Merged
FredDietrich merged 1 commit from upstream-pr/321 into main 2026-11-27 17:49:29 +00:00
FredDietrich commented 2026-11-27 16:35:38 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by FredDietrich on 2026-11-27T16:35:38Z.


Summary

Split out from #294 as requested so the two write-watch allocation switches can be measured independently on Windows and Linux/Wine before changing any defaults.

Adds two opt-in switches (both OFF by default):

  1. VICTORY_WATCH_HEAP=1 (crates/victory-gpu/src/resource.rs): backs ≥ 64 KiB (align <= 64 KiB) Memory::new allocations with VirtualAlloc(..., MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) instead of alloc_zeroed, and frees them via title_memory_freed + VirtualFree in Drop.
  2. VICTORY_WATCH_XMEM_ALLOC=1 (crates/victory-hle/src/modules/xmem.rs): backs ≥ 64 KiB (align <= 64 KiB) XMemAllocDefault allocations (when ALLOC_32BIT == 0) with VirtualAlloc(..., MEM_WRITE_WATCH) (using a leading 64 KiB page for the [usize::MAX, base] header), and releases them via title_memory_freed + VirtualFree in XMemFreeDefault.

Measured Trade-off (Why Opt-In)

  • Linux / Proton Experimental (RTX 3060 Ti 8 GB, Series S, diag): In GTA VI, the 21 MB private buffer (+0x1412200, allocated via XMemAllocDefault) previously fell back to copied whole (memory not watched) 2×/frame (42.09 MB/frame, ~12.5 ms CPU + 21.05 MB GPU upload). Enabling both switches dropped copied whole from 43.3 MB / 13.1 ms → 0.0 MB / 0.0 ms and its upload from 21.05 MB → 0.00 MB, raising steady-state median FPS from 9.00 → 9.80 fps (-9.0 ms/frame).
  • Windows (RTX 3080 10 GB, boat scene, tested by @Garu667 in #294): land copying ~20.6 MB back from the GPU into that buffer re-dirties ~5,100 4 KiB pages every frame (GetWriteWatch dirty pages doubled from ~5,140 → ~10,250/frame), which on Windows can add ~7–14 ms to preparing (81 → 95 ms with steady FPS unchanged). Keeping both switches opt-in allows independent A/B measurement across scenes and platforms.
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5530006687 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/321). Originally posted by [FredDietrich](https://github.com/FredDietrich) on 2026-11-27T16:35:38Z. --- ## Summary Split out from #294 as requested so the two write-watch allocation switches can be measured independently on Windows and Linux/Wine before changing any defaults. Adds two **opt-in** switches (both **OFF by default**): 1. **`VICTORY_WATCH_HEAP=1`** (`crates/victory-gpu/src/resource.rs`): backs ≥ 64 KiB (`align <= 64 KiB`) `Memory::new` allocations with `VirtualAlloc(..., MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE)` instead of `alloc_zeroed`, and frees them via `title_memory_freed` + `VirtualFree` in `Drop`. 2. **`VICTORY_WATCH_XMEM_ALLOC=1`** (`crates/victory-hle/src/modules/xmem.rs`): backs ≥ 64 KiB (`align <= 64 KiB`) `XMemAllocDefault` allocations (when `ALLOC_32BIT == 0`) with `VirtualAlloc(..., MEM_WRITE_WATCH)` (using a leading 64 KiB page for the `[usize::MAX, base]` header), and releases them via `title_memory_freed` + `VirtualFree` in `XMemFreeDefault`. ## Measured Trade-off (Why Opt-In) - **Linux / Proton Experimental (RTX 3060 Ti 8 GB, Series S, `diag`):** In GTA VI, the 21 MB private buffer (`+0x1412200`, allocated via `XMemAllocDefault`) previously fell back to `copied whole (memory not watched)` 2×/frame (**42.09 MB/frame, ~12.5 ms CPU + 21.05 MB GPU upload**). Enabling both switches dropped `copied whole` from **43.3 MB / 13.1 ms → 0.0 MB / 0.0 ms** and its upload from **21.05 MB → 0.00 MB**, raising steady-state median FPS from **9.00 → 9.80 fps** (-9.0 ms/frame). - **Windows (RTX 3080 10 GB, boat scene, tested by @Garu667 in #294):** `land` copying ~20.6 MB back from the GPU into that buffer re-dirties ~5,100 4 KiB pages every frame (`GetWriteWatch` dirty pages doubled from ~5,140 → ~10,250/frame), which on Windows can add ~7–14 ms to `preparing` (`81 → 95 ms` with steady FPS unchanged). Keeping both switches opt-in allows independent A/B measurement across scenes and platforms.
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
TaynanGT/Vice-Tay!321
No description provided.