perf(watch): skip refused view askings without PORT_GUARD and track xmem placeholders directly #294

Manually merged
github merged 3 commits from github-bot/gh-294 into gh-pr/294/base 2026-11-27 17:36:37 +00:00 AGit
Owner

@⁠FredDietrich on GitHub · 2026-11-27 13:58 UTC · original
FredDietrich:perf/write-watch-and-view-tracking → main · +108 −20 · 3 files · 3 commits · merged 2026-11-27 17:20 UTC

Summary

Split out from the earlier combined PR as requested (the two opt-in MEM_WRITE_WATCH allocation switches are now in a separate PR).

This PR contains two memory-watch improvements in victory-gpu / victory-hle:

  1. Skip refused GetWriteWatch calls on known views without VICTORY_PORT_GUARD=1 (VICTORY_SKIP_VIEW_ASK, default ON)

    • Decouples the VIEWS bitmap (refused_as_view, known_views, VIEWS.set) from port_guard() in crates/victory-gpu/src/watch.rs.
    • Previously, runs without VICTORY_PORT_GUARD=1 issued ~215 refused GetWriteWatch syscalls/frame against view memory.
    • Opt-out: VICTORY_SKIP_VIEW_ASK=0.
  2. Track MEM_RESERVE_PLACEHOLDER reservations directly in an atomic PLACEHOLDERS bitmap

    • Adds victory_gpu::title_memory_placeholder(at, len) called from XMemVirtualAlloc when reserving placeholders (placeholder || kind & MEM_RESERVE_PLACEHOLDER != 0), with fallback to NtQueryVirtualMemory(MemoryRegionInformationEx = 7).
    • Wine/Proton does not implement NtQueryVirtualMemory class 7, so placeholder() always returned false, silently disabling VICTORY_KNOWN_HOLES (~13,700 VirtualQuery syscalls/frame and ~1,340 block-by-block guard acquisitions/frame).
    • title_memory_freed(at, 0) now always resolves the full freed allocation end via allocation_end(at, at) and clears VIEWS and PLACEHOLDERS across [first, freed_end) even if the first block was already cleared.

Measured Results (Proton Experimental, RTX 3060 Ti 8 GB, Series S, diag)

Stage Median FPS (p10–p90; max) Frame ms prep copies guards GWW Notable metric
Baseline (PORT_CONSTANTS/CBV/DESCRIPTORS/JOURNAL + COPY/STORE_BESIDE) 7.70 (1.2–8.0; 8.2) 130.2 102.0 71.1 ms / 86 MB 21.8 33.8 215 refused GWW/frame
+ Commit 1 (VICTORY_SKIP_VIEW_ASK) 8.10 (3.7–8.5; 8.9) 123.5 96.2 63.6 ms / 86 MB 24.8 17.8 0 refused GWW/frame; texture refreshes 44.7 → 16.3 ms
+ Commit 2 (PLACEHOLDERS bitmap) 8.50 (2.3–8.9; 9.5) 117.9 89.5 44.2 ms / 87 MB 11.3 26.4 questions about holes 13,711 → 1–2/frame (-99.99%); block by block 1,340 → 60–67/frame (-95%)
**@⁠FredDietrich** on GitHub · 2026-11-27 13:58 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294) `FredDietrich:perf/write-watch-and-view-tracking` → `main` · +108 −20 · 3 files · 3 commits · merged 2026-11-27 17:20 UTC ## Summary Split out from the earlier combined PR as requested (the two opt-in `MEM_WRITE_WATCH` allocation switches are now in a separate PR). This PR contains two memory-watch improvements in `victory-gpu` / `victory-hle`: 1. **Skip refused `GetWriteWatch` calls on known views without `VICTORY_PORT_GUARD=1` (`VICTORY_SKIP_VIEW_ASK`, default ON)** - Decouples the `VIEWS` bitmap (`refused_as_view`, `known_views`, `VIEWS.set`) from `port_guard()` in `crates/victory-gpu/src/watch.rs`. - Previously, runs without `VICTORY_PORT_GUARD=1` issued ~215 refused `GetWriteWatch` syscalls/frame against view memory. - Opt-out: `VICTORY_SKIP_VIEW_ASK=0`. 2. **Track `MEM_RESERVE_PLACEHOLDER` reservations directly in an atomic `PLACEHOLDERS` bitmap** - Adds `victory_gpu::title_memory_placeholder(at, len)` called from `XMemVirtualAlloc` when reserving placeholders (`placeholder || kind & MEM_RESERVE_PLACEHOLDER != 0`), with fallback to `NtQueryVirtualMemory(MemoryRegionInformationEx = 7)`. - Wine/Proton does not implement `NtQueryVirtualMemory` class 7, so `placeholder()` always returned `false`, silently disabling `VICTORY_KNOWN_HOLES` (~13,700 `VirtualQuery` syscalls/frame and ~1,340 block-by-block guard acquisitions/frame). - `title_memory_freed(at, 0)` now always resolves the full freed allocation end via `allocation_end(at, at)` and clears `VIEWS` and `PLACEHOLDERS` across `[first, freed_end)` even if the first block was already cleared. ## Measured Results (Proton Experimental, RTX 3060 Ti 8 GB, Series S, `diag`) | Stage | Median FPS (p10–p90; max) | Frame ms | `prep` | `copies` | `guards` | `GWW` | Notable metric | |---|---|---:|---:|---|---:|---:|---| | Baseline (`PORT_CONSTANTS/CBV/DESCRIPTORS/JOURNAL + COPY/STORE_BESIDE`) | 7.70 (1.2–8.0; 8.2) | 130.2 | 102.0 | 71.1 ms / 86 MB | 21.8 | 33.8 | 215 refused `GWW`/frame | | + Commit 1 (`VICTORY_SKIP_VIEW_ASK`) | 8.10 (3.7–8.5; 8.9) | 123.5 | 96.2 | 63.6 ms / 86 MB | 24.8 | 17.8 | **0 refused `GWW`/frame**; texture refreshes 44.7 → 16.3 ms | | + Commit 2 (`PLACEHOLDERS` bitmap) | 8.50 (2.3–8.9; 9.5) | 117.9 | 89.5 | 44.2 ms / 87 MB | 11.3 | 26.4 | `questions about holes` **13,711 → 1–2/frame (-99.99%)**; `block by block` **1,340 → 60–67/frame (-95%)** |
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:01:57 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 14:11 UTC · original

@⁠FredDietrich The isolated Proton Experimental run ties the write-watch change to the drop from 43.3 MB of whole-buffer copies to zero. The 10.6 FPS result belongs to the custom Proton build. I'll keep the changes independently testable and check the placeholder map/unmap cycle and address reuse before changing defaults.

**@⁠TaynanGT** on GitHub · 2026-11-27 14:11 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7220458718) @⁠FredDietrich The isolated Proton Experimental run ties the write-watch change to the drop from 43.3 MB of whole-buffer copies to zero. The 10.6 FPS result belongs to the custom Proton build. I'll keep the changes independently testable and check the placeholder map/unmap cycle and address reuse before changing defaults.
Author
Owner

@⁠Garu667 on GitHub · 2026-11-27 15:30 UTC · original

Tested on an RTX 3080 10 GB (Series S, -Machine auto, boat mission autosave, warm shader cache), one run each:

Run Build Steady side view on the water Preparing ms (median, last lines) Crash / card loss
159 main e45051a 6.4–8.0 fps 81 none
165 main + #294 7.3–8.0 fps 95 none
  • No measurable gain on this scene: steady-state fps is the same, within noise. The longest stalls in cutscenes look like main's (runs on main also had single frames of 30–69 s while cutscenes stream in).
  • The picture was normal (faces included), and no "placeholder … filled with nobody telling" warning in this run.
  • For context, an earlier combined build with #284 and #272 froze, but that came from #272 (see there).
**@⁠Garu667** on GitHub · 2026-11-27 15:30 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7222145851) Tested on an **RTX 3080 10 GB** (Series S, `-Machine auto`, boat mission autosave, warm shader cache), one run each: | Run | Build | Steady side view on the water | Preparing ms (median, last lines) | Crash / card loss | |---|---|---|---|---| | 159 | `main` e45051a | 6.4–8.0 fps | 81 | none | | 165 | `main` + #294 | 7.3–8.0 fps | 95 | none | - No measurable gain on this scene: steady-state fps is the same, within noise. The longest stalls in cutscenes look like `main`'s (runs on `main` also had single frames of 30–69 s while cutscenes stream in). - The picture was normal (faces included), and no "placeholder … filled with nobody telling" warning in this run. - For context, an earlier combined build with #284 and #272 froze, but that came from #272 (see there).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 15:54 UTC · original

@⁠Garu667 The warm-cache boat run gives us a clean image and a useful timing result. Preparation went from 81 to 95 ms while steady FPS stayed in the same range. Keep that run as the Windows comparison when looking at the placeholder and write-watch changes separately.

**@⁠TaynanGT** on GitHub · 2026-11-27 15:54 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7222616019) @⁠Garu667 The warm-cache boat run gives us a clean image and a useful timing result. Preparation went from 81 to 95 ms while steady FPS stayed in the same range. Keep that run as the Windows comparison when looking at the placeholder and write-watch changes separately.
Author
Owner

@⁠FredDietrich on GitHub · 2026-11-27 15:55 UTC · original

Thanks @⁠TaynanGT and @⁠Garu667 for the review and the Windows RTX 3080 test!

@⁠Garu667's preparing delta (81 → 95 ms) matches an interesting trade-off we also saw in our Linux diag logs on commit 3 (MEM_WRITE_WATCH on XMemAllocDefault):

  • Watching the 21 MB private buffer (+0x1412200) dropped copied whole (memory not watched) from 43.3 MB / 13.1 ms to 0.0 MB and its GPU upload from 21.05 MB to 0.00 MB.
  • However, because land copies ~20.6 MB back from the GPU into that buffer every frame, those writes re-dirty ~5,100 4 KiB pages, doubling GetWriteWatch dirty pages (~5,140 → ~10,250/frame). On Linux/Wine the saved whole-buffer copy + upload outweighed the extra GetWriteWatch cost (+0.80 fps), whereas on Windows (where GetWriteWatch reset cost is ~1.4 µs/page and NtQueryVirtualMemory class 7 already works natively) the extra dirty pages can add ~7–10 ms to preparing.

That completely validates @⁠TaynanGT's point about keeping all three changes independently testable and opt-in first before changing any defaults. Happy to:

  1. Flip the switches to opt-in (=1) and harden title_memory_freed(at, 0) so it clears PLACEHOLDERS across the full freed allocation even if the first block was already cleared, and/or
  2. Split this into separate PRs (e.g. PLACEHOLDERS + VICTORY_SKIP_VIEW_ASK vs. VICTORY_WATCH_HEAP/VICTORY_WATCH_XMEM_ALLOC).

Let me know which shape works best for you!

**@⁠FredDietrich** on GitHub · 2026-11-27 15:55 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7222642201) Thanks @⁠TaynanGT and @⁠Garu667 for the review and the Windows RTX 3080 test! @⁠Garu667's `preparing` delta (`81 → 95 ms`) matches an interesting trade-off we also saw in our Linux diag logs on commit 3 (`MEM_WRITE_WATCH` on `XMemAllocDefault`): - Watching the 21 MB private buffer (`+0x1412200`) dropped `copied whole (memory not watched)` from `43.3 MB / 13.1 ms` to `0.0 MB` and its GPU upload from `21.05 MB` to `0.00 MB`. - However, because `land` copies `~20.6 MB` back from the GPU into that buffer every frame, those writes re-dirty ~5,100 4 KiB pages, doubling `GetWriteWatch` dirty pages (`~5,140 → ~10,250/frame`). On Linux/Wine the saved whole-buffer copy + upload outweighed the extra `GetWriteWatch` cost (+0.80 fps), whereas on Windows (where `GetWriteWatch` reset cost is ~1.4 µs/page and `NtQueryVirtualMemory` class 7 already works natively) the extra dirty pages can add ~7–10 ms to `preparing`. That completely validates @⁠TaynanGT's point about keeping all three changes independently testable and opt-in first before changing any defaults. Happy to: 1. Flip the switches to opt-in (`=1`) and harden `title_memory_freed(at, 0)` so it clears `PLACEHOLDERS` across the full freed allocation even if the first block was already cleared, and/or 2. Split this into separate PRs (e.g. `PLACEHOLDERS` + `VICTORY_SKIP_VIEW_ASK` vs. `VICTORY_WATCH_HEAP`/`VICTORY_WATCH_XMEM_ALLOC`). Let me know which shape works best for you!
Use the runtime unmap path so later test allocations can reuse the address without inheriting the previous view.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 16:04 UTC · original

@⁠FredDietrich I’d take two PRs. Put placeholder tracking and skipped view queries in the first, including cleanup of the full freed allocation when its first block is already clear. Put the two write-watch options in the second, each opt-in. The Windows and Wine results give us a clear reason to measure them independently.

**@⁠TaynanGT** on GitHub · 2026-11-27 16:04 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7222827647) @⁠FredDietrich I’d take two PRs. Put placeholder tracking and skipped view queries in the first, including cleanup of the full freed allocation when its first block is already clear. Put the two write-watch options in the second, each opt-in. The Windows and Wine results give us a clear reason to measure them independently.
github-bot changed title from perf(watch,xmem): write-watch large private buffers, skip refused view askings, and track placeholders directly to perf(watch): skip refused view askings without PORT_GUARD and track xmem placeholders directly 2026-11-27 16:36:34 +00:00
github-bot force-pushed github-bot/gh-294 from 141e379663 to 503034cff2 2026-11-27 16:36:34 +00:00 Compare
Author
Owner

@⁠FredDietrich on GitHub · 2026-11-27 16:36 UTC · original

Split as requested:

  • This PR (#294) now contains only VICTORY_SKIP_VIEW_ASK and PLACEHOLDERS tracking, with title_memory_freed(at, 0) resolving the full freed allocation end via allocation_end(at, at) even when the first block is already clear.
  • Opened #321 with VICTORY_WATCH_HEAP=1 and VICTORY_WATCH_XMEM_ALLOC=1, both opt-in (off by default).
**@⁠FredDietrich** on GitHub · 2026-11-27 16:36 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7223456834) Split as requested: - This PR (#294) now contains only `VICTORY_SKIP_VIEW_ASK` and `PLACEHOLDERS` tracking, with `title_memory_freed(at, 0)` resolving the full freed allocation end via `allocation_end(at, at)` even when the first block is already clear. - Opened #321 with `VICTORY_WATCH_HEAP=1` and `VICTORY_WATCH_XMEM_ALLOC=1`, both opt-in (off by default).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 16:58 UTC · original

@⁠FredDietrich Resolving the full allocation when its first block is already clear covers the free-path case I was concerned about. The same warm-cache boat run with the smaller #294 will give us a Windows check for the skipped view queries and placeholder tracking. The two switches in #321 can each use that baseline.

**@⁠TaynanGT** on GitHub · 2026-11-27 16:58 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7223888944) @⁠FredDietrich Resolving the full allocation when its first block is already clear covers the free-path case I was concerned about. The same warm-cache boat run with the smaller #294 will give us a Windows check for the skipped view queries and placeholder tracking. The two switches in #321 can each use that baseline.
Author
Owner

@⁠urielbeaupre on GitHub · 2026-11-27 17:06 UTC · original

Measured on Windows 11, RTX 4070 Ti 12 GB, Ryzen 9 7900X, 64 GB, driver 621.40. Setup: scripts/play.ps1 -Machine 4070 -Console series-s -Windowed, ray tracing off.

The base is 8137f71, from #305 (on top of main at b06fdd5). #284 and #294 were merged together onto it, so the result below is the two combined. I haven't separated them.

Method: unattended opening (the game's own intro sequence, A pressed by VICTORY_KEYS_FILE); a warm-up run first so no pipelines were being made (checked in the log); then 100 s of the frame lines.

median fps slowest quarter fastest quarter
base, run 1 16.9 12.5 20.7
base, run 2 16.5 13.7 20.7
base + #284 + #294 20.0 16.2 21.8

That's about +20% at the median, with the slow quarter gaining the most. There was no crash, and the picture looked unchanged. I can split the two PRs into separate runs if that helps.

**@⁠urielbeaupre** on GitHub · 2026-11-27 17:06 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7224027223) Measured on Windows 11, RTX 4070 Ti 12 GB, Ryzen 9 7900X, 64 GB, driver 621.40. Setup: `scripts/play.ps1 -Machine 4070 -Console series-s -Windowed`, ray tracing off. The base is `8137f71`, from #305 (on top of `main` at `b06fdd5`). **#284 and #294 were merged together** onto it, so the result below is the two combined. I haven't separated them. Method: unattended opening (the game's own intro sequence, A pressed by `VICTORY_KEYS_FILE`); a warm-up run first so no pipelines were being made (checked in the log); then 100 s of the frame lines. | | median fps | slowest quarter | fastest quarter | |---|---|---|---| | base, run 1 | 16.9 | 12.5 | 20.7 | | base, run 2 | 16.5 | 13.7 | 20.7 | | base + #284 + #294 | **20.0** | **16.2** | **21.8** | That's about +20% at the median, with the slow quarter gaining the most. There was no crash, and the picture looked unchanged. I can split the two PRs into separate runs if that helps.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 17:08 UTC · original · edited 2026-11-27 17:13 UTC

@⁠urielbeaupre Please run #294 alone on the same 8137f71 setup. Include the refused GetWriteWatch count and preparation and copy times if available. Windows CI also hit two write-watch test failures on the split head. A stale view entry can hide a direct query after Windows reuses the address. bcd771b restores the direct query and clears the entry when the kernel accepts it. The native check failed on the previous head and passed with the fix.

**@⁠TaynanGT** on GitHub · 2026-11-27 17:08 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/294#issuecomment-7224079499) · edited 2026-11-27 17:13 UTC @⁠urielbeaupre Please run #294 alone on the same `8137f71` setup. Include the refused `GetWriteWatch` count and preparation and copy times if available. Windows CI also hit two write-watch test failures on the split head. A stale view entry can hide a direct query after Windows reuses the address. `bcd771b` restores the direct query and clears the entry when the kernel accepts it. The native check failed on the previous head and passed with the fix.
Keep the direct no-query shortcut under renderer port #6. When the kernel accepts a direct write-watch query, forget any view cached for that range so the next batch can see it. Cover reused addresses with the Windows regression.
github-bot changed target branch from main to gh-pr/294/base 2026-11-27 17:36:36 +00:00
github manually merged commit bcd771b4e5 into gh-pr/294/base 2026-11-27 17:36:37 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.