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

Manually merged
github merged 1 commit from github-bot/gh-321 into gh-pr/321/base 2026-11-27 17:53:51 +00:00 AGit
Owner

@⁠FredDietrich on GitHub · 2026-11-27 16:35 UTC · original
FredDietrich:perf/write-watch-private-allocs → main · +103 −0 · 2 files · 1 commits · merged 2026-11-27 17:49 UTC

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.
**@⁠FredDietrich** on GitHub · 2026-11-27 16:35 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/321) `FredDietrich:perf/write-watch-private-allocs` → `main` · +103 −0 · 2 files · 1 commits · merged 2026-11-27 17:49 UTC ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 16:36:27 +00:00
github-bot changed target branch from main to gh-pr/321/base 2026-11-27 17:53:50 +00:00
github manually merged commit 40d970e59b into gh-pr/321/base 2026-11-27 17:53:51 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.