perf(gpu): reservation-aware write-watch batching, lock-free view/non-watched bitsets & Wine/Proton compatibility #207

Closed
jocost4 wants to merge 1 commit from upstream-pr/207 into main
jocost4 commented 2026-11-27 19:43:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jocost4 on 2026-11-27T19:43:23Z.


Summary

A set of low-risk, zero-regression performance and Wine/Proton compatibility improvements for victory-gpu (default Windows behavior is preserved everywhere; all tuning knobs are opt-in via environment variables):

1. Write-watch & guard optimizations (crates/victory-gpu/src/watch.rs)

  • Fused reservation-aware ask_once + RESERVATIONS cache: Caches VirtualAlloc reservation spans (AllocationBase..end) so ask_once only merges GetWriteWatch ranges within the same reservation — eliminating cross-reservation GetWriteWatch failures and binary splits.
  • Fine-grained Asking::hold_many: Replaces Asking::hold_all() (0..usize::MAX) in ask_once with atomic range holding for only the queried spans, allowing unrelated memory (e.g. shader-visible descriptor heaps in sync_heaps and texture refreshes) to proceed concurrently.
  • Lock-free KNOWN_VIEW and SINGLE_NOT_WATCHED bitsets:
    • KNOWN_VIEW marks blocks confirmed as MEM_MAPPED view memory inside protect_here (cleared on g.foreign and all title_memory_* invalidations).
    • SINGLE_NOT_WATCHED only marks isolated single 64 KiB blocks (last - first == 1) where GetWriteWatch failed (never poisoning adjacent write-watched blocks).
    • Adds a lock-free fast path in writes(..., false) before acquiring Asking::hold, avoiding redundant lock/condvar churn on known view memory (e.g. texture.rs).
  • Wine/Proton placeholder() fallback: Falls back to VirtualQuery (MEM_RESERVE && PAGE_NOACCESS) when NtQueryVirtualMemory(class = 7) returns STATUS_INVALID_INFO_CLASS under Wine/Proton (zero impact on native Windows, where NtQueryVirtualMemory succeeds). Reduces hole queries from ~15,000/frame to ~8–48/frame under Proton.
  • Loop termination & lock-order hardening: Adds to <= end progress guards in allocation_end / reservation_of and calls forget_reservations outside the GUARDS lock in title_memory_unmapping / title_memory_freed.
  • Configurable VICTORY_AHEAD_GAP_KB (default 8192 = 8 MiB, unchanged on Windows; setting e.g. 256 on Wine/Proton avoids scanning megabytes of unused pages under Wine's virtual.c lock).

2. Additional low-overhead improvements

  • crates/victory-gpu/src/shadow.rs: Short-circuits wide_each for n == 0 and n == 1 to avoid worker pool wakeups for trivial work.
  • crates/victory-gpu/src/host.rs: Sets hbrBackground to BLACK_BRUSH in make_window to avoid a white/blue uninitialized window flash before the first Present().
  • crates/victory-gpu/src/draw.rs: Makes buffer-heap rescan cadence configurable via VICTORY_HEAP_RESCAN_FRAMES (default 16, unchanged).
  • crates/victory-gpu/src/texture.rs: Makes guarded texture blind-write hash cadence configurable via VICTORY_TEXTURE_HASH_EVERY (default 8, unchanged).

Verification

  • Verified clean cross-compilation for x86_64-pc-windows-msvc (cargo xwin check --release -p victory --target x86_64-pc-windows-msvc, 0 new warnings).
  • Tested on Linux (Ubuntu 26.10, Proton-GE / Wine 11.0 + vkd3d-proton 3.2, Ryzen 5 5600 + RTX 3060 Ti 8 GB): cut frame preparing time from ~200+ ms down to ~50–55 ms/frame (copies ~11–12 ms, textures ~5–6 ms, ask_once ~14–19 ms, heaps_wait ~4–5 ms) with GPU utilization reaching 88–92%.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5532217863 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/207). Originally posted by [jocost4](https://github.com/jocost4) on 2026-11-27T19:43:23Z. --- ## Summary A set of low-risk, zero-regression performance and Wine/Proton compatibility improvements for `victory-gpu` (default Windows behavior is preserved everywhere; all tuning knobs are opt-in via environment variables): ### 1. Write-watch & guard optimizations (`crates/victory-gpu/src/watch.rs`) - **Fused reservation-aware `ask_once` + `RESERVATIONS` cache:** Caches `VirtualAlloc` reservation spans (`AllocationBase..end`) so `ask_once` only merges `GetWriteWatch` ranges within the same reservation — eliminating cross-reservation `GetWriteWatch` failures and binary splits. - **Fine-grained `Asking::hold_many`:** Replaces `Asking::hold_all()` (`0..usize::MAX`) in `ask_once` with atomic range holding for only the queried spans, allowing unrelated memory (e.g. shader-visible descriptor heaps in `sync_heaps` and texture refreshes) to proceed concurrently. - **Lock-free `KNOWN_VIEW` and `SINGLE_NOT_WATCHED` bitsets:** - `KNOWN_VIEW` marks blocks confirmed as `MEM_MAPPED` view memory inside `protect_here` (cleared on `g.foreign` and all `title_memory_*` invalidations). - `SINGLE_NOT_WATCHED` only marks isolated single 64 KiB blocks (`last - first == 1`) where `GetWriteWatch` failed (never poisoning adjacent write-watched blocks). - Adds a lock-free fast path in `writes(..., false)` before acquiring `Asking::hold`, avoiding redundant lock/condvar churn on known view memory (e.g. `texture.rs`). - **Wine/Proton `placeholder()` fallback:** Falls back to `VirtualQuery` (`MEM_RESERVE && PAGE_NOACCESS`) when `NtQueryVirtualMemory(class = 7)` returns `STATUS_INVALID_INFO_CLASS` under Wine/Proton (zero impact on native Windows, where `NtQueryVirtualMemory` succeeds). Reduces hole queries from ~15,000/frame to ~8–48/frame under Proton. - **Loop termination & lock-order hardening:** Adds `to <= end` progress guards in `allocation_end` / `reservation_of` and calls `forget_reservations` outside the `GUARDS` lock in `title_memory_unmapping` / `title_memory_freed`. - **Configurable `VICTORY_AHEAD_GAP_KB`** (default `8192` = 8 MiB, unchanged on Windows; setting e.g. `256` on Wine/Proton avoids scanning megabytes of unused pages under Wine's `virtual.c` lock). ### 2. Additional low-overhead improvements - **`crates/victory-gpu/src/shadow.rs`:** Short-circuits `wide_each` for `n == 0` and `n == 1` to avoid worker pool wakeups for trivial work. - **`crates/victory-gpu/src/host.rs`:** Sets `hbrBackground` to `BLACK_BRUSH` in `make_window` to avoid a white/blue uninitialized window flash before the first `Present()`. - **`crates/victory-gpu/src/draw.rs`:** Makes buffer-heap rescan cadence configurable via `VICTORY_HEAP_RESCAN_FRAMES` (default `16`, unchanged). - **`crates/victory-gpu/src/texture.rs`:** Makes guarded texture blind-write hash cadence configurable via `VICTORY_TEXTURE_HASH_EVERY` (default `8`, unchanged). ## Verification - Verified clean cross-compilation for `x86_64-pc-windows-msvc` (`cargo xwin check --release -p victory --target x86_64-pc-windows-msvc`, 0 new warnings). - Tested on Linux (Ubuntu 26.10, Proton-GE / Wine 11.0 + vkd3d-proton 3.2, Ryzen 5 5600 + RTX 3060 Ti 8 GB): cut frame `preparing` time from ~200+ ms down to ~50–55 ms/frame (`copies` ~11–12 ms, `textures` ~5–6 ms, `ask_once` ~14–19 ms, `heaps_wait` ~4–5 ms) with GPU utilization reaching 88–92%.
domx4q commented 2026-11-27 21:42:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by domx4q on 2026-11-27T21:42:24Z.


Independent confirmation of the Wine/Proton placeholder fallback in this PR, from a separate setup.

Setup: i9-14900KF, RTX 4090 (driver 620.73), Proton with vkd3d-proton, Linux 7.3, headless gamescope, prologue (prison cell), 1080p -> 1440p DLSS Quality. Same save, same scene, 60 s average per run.

I hit the same problem independently. On Wine, NtQueryVirtualMemory(..., MemoryRegionInformationEx) returns STATUS_INVALID_INFO_CLASS, so watch::placeholder() never learns that a hole is a placeholder. In my profile that meant ~16,000 VirtualQuery calls per frame under the guards' lock (ntdll.so:get_basic_memory_info was the hottest symbol in the victory-wide threads).

My local fix was slightly different: a small BTreeMap of the runtime's own MEM_RESERVE_PLACEHOLDER reservations, filled from xmem.rs and cleared in title_memory_freed, used only after the host has once answered STATUS_INVALID_INFO_CLASS. Result on top of VICTORY_PIPELINE_WAIT_MS=0: 18.6 -> 20.5 fps, "preparing" ~45 -> ~31 ms/frame. Your version covers the same case, so I'm not opening a separate PR. I'm happy to post my diff if a second variant is useful for comparison.

Not tested on Windows by me (the new path only runs when the host rejects the info class, which Windows doesn't).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7228682798 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/207#issuecomment-7228682798). Originally posted by [domx4q](https://github.com/domx4q) on 2026-11-27T21:42:24Z. --- Independent confirmation of the Wine/Proton placeholder fallback in this PR, from a separate setup. Setup: i9-14900KF, RTX 4090 (driver 620.73), Proton with vkd3d-proton, Linux 7.3, headless gamescope, prologue (prison cell), 1080p -> 1440p DLSS Quality. Same save, same scene, 60 s average per run. I hit the same problem independently. On Wine, `NtQueryVirtualMemory(..., MemoryRegionInformationEx)` returns `STATUS_INVALID_INFO_CLASS`, so `watch::placeholder()` never learns that a hole is a placeholder. In my profile that meant ~16,000 VirtualQuery calls per frame under the guards' lock (`ntdll.so:get_basic_memory_info` was the hottest symbol in the `victory-wide` threads). My local fix was slightly different: a small `BTreeMap` of the runtime's own `MEM_RESERVE_PLACEHOLDER` reservations, filled from `xmem.rs` and cleared in `title_memory_freed`, used only after the host has once answered `STATUS_INVALID_INFO_CLASS`. Result on top of `VICTORY_PIPELINE_WAIT_MS=0`: 18.6 -> 20.5 fps, "preparing" ~45 -> ~31 ms/frame. Your version covers the same case, so I'm not opening a separate PR. I'm happy to post my diff if a second variant is useful for comparison. Not tested on Windows by me (the new path only runs when the host rejects the info class, which Windows doesn't).
jocost4 commented 2026-11-28 00:34:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jocost4 on 2026-11-28T00:34:45Z.


Thanks for the independent numbers, @domx4q — good to see the same ~16k queries/frame bottleneck confirmed on a 4090 setup too.

Your BTreeMap approach from xmem.rs is actually cleaner for distinguishing real MEM_RESERVE_PLACEHOLDER spans from plain PAGE_NOACCESS reservations (and avoids the VirtualQuery call altogether once STATUS_INVALID_INFO_CLASS is seen). Feel free to drop your diff here if you'd like — happy to compare or fold it in if maintainers prefer that variant.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7231024872 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/207#issuecomment-7231024872). Originally posted by [jocost4](https://github.com/jocost4) on 2026-11-28T00:34:45Z. --- Thanks for the independent numbers, @domx4q — good to see the same ~16k queries/frame bottleneck confirmed on a 4090 setup too. Your `BTreeMap` approach from `xmem.rs` is actually cleaner for distinguishing real `MEM_RESERVE_PLACEHOLDER` spans from plain `PAGE_NOACCESS` reservations (and avoids the `VirtualQuery` call altogether once `STATUS_INVALID_INFO_CLASS` is seen). Feel free to drop your diff here if you'd like — happy to compare or fold it in if maintainers prefer that variant.
POMXARK commented 2026-11-28 02:11:06 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T02:11:06Z.


Testing feedback on Windows 11, AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM, Series X 1440p + DLSS Quality + DLSS MFG 4× (4 MiB windows).

Full disclosure: tested on a fork branch based on v2026.11.27.7 (with local GPU patches + x86-64-v3/ThinLTO), porting only the watch.rs changes (reservation_of, Asking::hold_many, KNOWN_VIEW, SINGLE_NOT_WATCHED, fused ask_once with sorted ahead_normalize preserved for PR #469's binary search) plus wide_each(0/1) in shadow.rs (omitting the Wine/Proton knobs).

Result

  • Unit tests: all 48/48 cargo test -p victory-gpu --lib watch tests passed cleanly (0.78 s) after updating the ask_rest test call to ask_once.
  • 3D workload (reproducible failure at t=169 s, early 3D load):
    • Baseline (same branch without PR #207): 14.0 FPS (~71 ms/frame) in the same 1k–4k draw tier; 12-minute run completes with 0 errors / 0 DeviceRemoved.
    • With PR #207 watch.rs: 3D immediately degraded to 0.2–6.3 FPS (158.9 -> 275.8 -> 1297.7 -> 4072.7 ms/frame, copies up to 67.2 ms vs 28.1 ms baseline, list::thin: 19464 in 12280.4 ms), followed by DXGI_ERROR_DEVICE_REMOVED (0x887A0005) at t=169 s:
      • WARN victory_gpu::streamline: DLSS Frame Generation: a present failed hresult=0x887a0005
      • ERROR victory_gpu::host: a submission sent ahead could not be followed by a signal ... (0x887A0005); device removed
    • Reverting only watch.rs and shadow.rs immediately restored clean 12-minute stability.

Possible root causes to double-check on native Windows:

  1. SINGLE_NOT_WATCHED / KNOWN_VIEW bitsets skipping GetWriteWatch if any 64 KiB block transitions state (e.g., uncommitted -> committed) without hitting one of the title_memory_* clear hooks, or
  2. Asking::hold_many(spans) allowing concurrent sync_heaps / texture refreshes during ask_once, leading to stale buffer/descriptor reads on the GPU and a TDR (0x887A0005).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232188941 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/207#issuecomment-7232188941). Originally posted by [POMXARK](https://github.com/POMXARK) on 2026-11-28T02:11:06Z. --- Testing feedback on **Windows 11, AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM**, Series X 1440p + DLSS Quality + DLSS MFG 4× (`4 MiB` windows). Full disclosure: tested on a fork branch based on `v2026.11.27.7` (with local GPU patches + `x86-64-v3`/ThinLTO), porting only the `watch.rs` changes (`reservation_of`, `Asking::hold_many`, `KNOWN_VIEW`, `SINGLE_NOT_WATCHED`, fused `ask_once` with sorted `ahead_normalize` preserved for PR #469's binary search) plus `wide_each(0/1)` in `shadow.rs` (omitting the Wine/Proton knobs). ### Result - **Unit tests:** all **48/48** `cargo test -p victory-gpu --lib watch` tests passed cleanly (`0.78 s`) after updating the `ask_rest` test call to `ask_once`. - **3D workload (reproducible failure at `t=169 s`, early 3D load):** - Baseline (same branch without PR #207): `14.0 FPS` (`~71 ms/frame`) in the same `1k–4k` draw tier; 12-minute run completes with `0` errors / `0` `DeviceRemoved`. - With PR #207 `watch.rs`: 3D immediately degraded to **`0.2–6.3 FPS`** (`158.9 -> 275.8 -> 1297.7 -> 4072.7 ms/frame`, `copies` up to `67.2 ms` vs `28.1 ms` baseline, `list::thin: 19464 in 12280.4 ms`), followed by **`DXGI_ERROR_DEVICE_REMOVED` (`0x887A0005`)** at `t=169 s`: - `WARN victory_gpu::streamline: DLSS Frame Generation: a present failed hresult=0x887a0005` - `ERROR victory_gpu::host: a submission sent ahead could not be followed by a signal ... (0x887A0005); device removed` - Reverting only `watch.rs` and `shadow.rs` immediately restored clean 12-minute stability. Possible root causes to double-check on native Windows: 1. `SINGLE_NOT_WATCHED` / `KNOWN_VIEW` bitsets skipping `GetWriteWatch` if any 64 KiB block transitions state (e.g., uncommitted -> committed) without hitting one of the `title_memory_*` clear hooks, or 2. `Asking::hold_many(spans)` allowing concurrent `sync_heaps` / texture refreshes during `ask_once`, leading to stale buffer/descriptor reads on the GPU and a TDR (`0x887A0005`).
domx4q commented 2026-11-28 10:38:30 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by domx4q on 2026-11-28T10:38:30Z.


@jocost4 thanks — here is the diff, against current main (a4d05e7). It applies cleanly there; built with cargo xwin build --release -p victory and run on Proton for several 15–20 min sessions without issues traced to it.

How it works:

  • xmem.rs: every MEM_RESERVE_PLACEHOLDER reservation the runtime makes for the title is recorded via title_placeholder_reserved(at, len).
  • watch::placeholder(): the first time the host answers MemoryRegionInformationEx with STATUS_INVALID_INFO_CLASS (Wine/Proton), a flag is set and from then on the answer comes from that BTreeMap (one range(..=at).next_back() lookup), no VirtualQuery at all. On Windows the class is known, so the new path is never taken.
  • title_memory_freed drops the recorded reservations a free covers (splits keep every part a placeholder, so no bookkeeping is needed for them).

Measured on Proton (14900KF, RTX 4090, prologue, 1080p→1440p DLSS Quality): 18.6 → 20.5 fps at the time, "preparing" ~45 → ~31 ms/frame. Not tested on Windows.

diff (65 lines added)
diff --git a/crates/victory-gpu/src/lib.rs b/crates/victory-gpu/src/lib.rs
index b60d28f..aff0e25 100644
--- a/crates/victory-gpu/src/lib.rs
+++ b/crates/victory-gpu/src/lib.rs
@@ -139,5 +139,5 @@ pub use shadow::title_memory_write_combined;
 pub use watch::{
     SoftViews, kernel_writing, soft_view_guards, title_memory_allocated, title_memory_freed, title_memory_made_real,
     title_memory_reading, title_memory_remapped, title_memory_remapping, title_memory_splitting, title_memory_unmapping,
-    title_memory_written, use_lazy_views, use_soft_views, writing as kernel_will_write,
+    title_memory_written, title_placeholder_reserved, use_lazy_views, use_soft_views, writing as kernel_will_write,
 };
diff --git a/crates/victory-gpu/src/watch.rs b/crates/victory-gpu/src/watch.rs
index 151de09..0ece2dc 100644
--- a/crates/victory-gpu/src/watch.rs
+++ b/crates/victory-gpu/src/watch.rs
@@ -1360,6 +1360,17 @@ fn placeholder(block: usize) -> bool {
     // (Class 3 answers with the kind of memory in that word, not the flags.)
     const MEMORY_REGION_INFORMATION_EX: u32 = 7;
     const PLACEHOLDER_RESERVATION: u32 = 1 << 8;
+    // `STATUS_INVALID_INFO_CLASS`: a host that does not know the class
+    // (Wine and Proton). There the runtime's own placeholders tell
+    // ([`title_placeholder_reserved`]); else no hole was ever known and each
+    // asking put a question to the host for each of them (16,000 a frame
+    // under the guards' lock on Proton, 50 ms a frame of all threads' time
+    // waiting for it).
+    const STATUS_INVALID_INFO_CLASS: i32 = 0xC000_0003_u32 as i32;
+    static UNKNOWN_CLASS: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+    if UNKNOWN_CLASS.load(std::sync::atomic::Ordering::Relaxed) {
+        return reserved_placeholder(block);
+    }
     let mut region = Region::default();
     // SAFETY: the answer's room and its size.
     let status = unsafe {
@@ -1372,9 +1383,57 @@ fn placeholder(block: usize) -> bool {
             std::ptr::null_mut(),
         )
     };
+    if status == STATUS_INVALID_INFO_CLASS {
+        if !UNKNOWN_CLASS.swap(true, std::sync::atomic::Ordering::Relaxed) {
+            tracing::info!(
+                "the host does not tell placeholders (MemoryRegionInformationEx): the runtime's own reservations are taken instead"
+            );
+        }
+        return reserved_placeholder(block);
+    }
     status >= 0 && region.region_type & PLACEHOLDER_RESERVATION != 0
 }
 
+/// The title's placeholder reservations as the runtime made them: start to
+/// end, in bytes. Asked only where the host cannot tell placeholders
+/// ([`placeholder`]).
+static PLACEHOLDERS: Mutex<BTreeMap<usize, usize>> = Mutex::new(BTreeMap::new());
+
+/// The runtime reserved `[at, at + len)` for the title as a placeholder,
+/// into which pages come only by mapping a view (or an allocation) in its
+/// place. Splitting it later keeps every part a placeholder.
+pub fn title_placeholder_reserved(at: usize, len: usize) {
+    if len == 0 {
+        return;
+    }
+    PLACEHOLDERS.lock().unwrap_or_else(|e| e.into_inner()).insert(at, at.saturating_add(len));
+}
+
+/// Whether `block` lies in a placeholder the runtime reserved.
+fn reserved_placeholder(block: usize) -> bool {
+    let at = block * BLOCK;
+    let held = PLACEHOLDERS.lock().unwrap_or_else(|e| e.into_inner());
+    held.range(..=at).next_back().is_some_and(|(_, &end)| at + BLOCK <= end)
+}
+
+/// The reservations of [`PLACEHOLDERS`] that `[at, at + len)` frees (with no
+/// length: the one beginning at `at`) are none any more.
+fn placeholders_freed(at: usize, len: usize) {
+    let mut held = PLACEHOLDERS.lock().unwrap_or_else(|e| e.into_inner());
+    if held.is_empty() {
+        return;
+    }
+    if len == 0 {
+        held.remove(&at);
+        return;
+    }
+    let end = at.saturating_add(len);
+    let gone: Vec<usize> = held.range(..end).filter(|&(_, &e)| e > at).map(|(&s, _)| s).collect();
+    for start in gone {
+        held.remove(&start);
+    }
+}
+
 /// The runtime gave the title memory at `[at, at + len)`, allocated or
 /// committed: what was known of holes there is asked again.
 pub fn title_memory_allocated(at: usize, len: usize) {
@@ -2853,6 +2912,7 @@ pub fn title_memory_unmapping(at: usize, len: usize) {
 /// of the next memory at the address.
 pub fn title_memory_freed(at: usize, len: usize) {
     crate::shadow::write_combined_freed(at, len);
+    placeholders_freed(at, len);
     let mut g = guards();
     let first = at / BLOCK;
     let noted = [g.protected.range(first..).next(), g.absent.range(first..).next(), g.foreign.range(first..).next().copied()];
diff --git a/crates/victory-hle/src/modules/xmem.rs b/crates/victory-hle/src/modules/xmem.rs
index 3992784..320b5c0 100644
--- a/crates/victory-hle/src/modules/xmem.rs
+++ b/crates/victory-hle/src/modules/xmem.rs
@@ -184,6 +184,10 @@ pub extern "system" fn XMemVirtualAlloc(
     if !at.is_null() && !placeholder {
         victory_gpu::title_memory_allocated(at as usize, size);
     }
+    // For hosts that cannot be asked whether memory is a placeholder (Wine).
+    if !at.is_null() && kind & MEM_RESERVE_PLACEHOLDER != 0 {
+        victory_gpu::title_placeholder_reserved(at as usize, size);
+    }
     // Write-combined: memory the title's CPU writes and does not read.
     if !at.is_null() && asked & 0x400 != 0 {
         victory_gpu::title_memory_write_combined(at as usize, size);

Unrelated but possibly useful for Linux testers reading this: the "missing heads / dark lighting / missing textures" on Proton experimental 11 came from its vkd3d-proton 3.2.0 hanging on 7 of the title's compute shaders (stack overflow in dxil-spirv; under Wine the worker thread just hangs, the log shows (7 being made) forever). A current vkd3d-proton master build next to victory.exe fixes it; details in a follow-up on #120.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7238027186 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/207#issuecomment-7238027186). Originally posted by [domx4q](https://github.com/domx4q) on 2026-11-28T10:38:30Z. --- @jocost4 thanks — here is the diff, against current main (`a4d05e7`). It applies cleanly there; built with `cargo xwin build --release -p victory` and run on Proton for several 15–20 min sessions without issues traced to it. How it works: - `xmem.rs`: every `MEM_RESERVE_PLACEHOLDER` reservation the runtime makes for the title is recorded via `title_placeholder_reserved(at, len)`. - `watch::placeholder()`: the first time the host answers `MemoryRegionInformationEx` with `STATUS_INVALID_INFO_CLASS` (Wine/Proton), a flag is set and from then on the answer comes from that `BTreeMap` (one `range(..=at).next_back()` lookup), no `VirtualQuery` at all. On Windows the class is known, so the new path is never taken. - `title_memory_freed` drops the recorded reservations a free covers (splits keep every part a placeholder, so no bookkeeping is needed for them). Measured on Proton (14900KF, RTX 4090, prologue, 1080p→1440p DLSS Quality): 18.6 → 20.5 fps at the time, "preparing" ~45 → ~31 ms/frame. Not tested on Windows. <details><summary>diff (65 lines added)</summary> ```diff diff --git a/crates/victory-gpu/src/lib.rs b/crates/victory-gpu/src/lib.rs index b60d28f..aff0e25 100644 --- a/crates/victory-gpu/src/lib.rs +++ b/crates/victory-gpu/src/lib.rs @@ -139,5 +139,5 @@ pub use shadow::title_memory_write_combined; pub use watch::{ SoftViews, kernel_writing, soft_view_guards, title_memory_allocated, title_memory_freed, title_memory_made_real, title_memory_reading, title_memory_remapped, title_memory_remapping, title_memory_splitting, title_memory_unmapping, - title_memory_written, use_lazy_views, use_soft_views, writing as kernel_will_write, + title_memory_written, title_placeholder_reserved, use_lazy_views, use_soft_views, writing as kernel_will_write, }; diff --git a/crates/victory-gpu/src/watch.rs b/crates/victory-gpu/src/watch.rs index 151de09..0ece2dc 100644 --- a/crates/victory-gpu/src/watch.rs +++ b/crates/victory-gpu/src/watch.rs @@ -1360,6 +1360,17 @@ fn placeholder(block: usize) -> bool { // (Class 3 answers with the kind of memory in that word, not the flags.) const MEMORY_REGION_INFORMATION_EX: u32 = 7; const PLACEHOLDER_RESERVATION: u32 = 1 << 8; + // `STATUS_INVALID_INFO_CLASS`: a host that does not know the class + // (Wine and Proton). There the runtime's own placeholders tell + // ([`title_placeholder_reserved`]); else no hole was ever known and each + // asking put a question to the host for each of them (16,000 a frame + // under the guards' lock on Proton, 50 ms a frame of all threads' time + // waiting for it). + const STATUS_INVALID_INFO_CLASS: i32 = 0xC000_0003_u32 as i32; + static UNKNOWN_CLASS: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + if UNKNOWN_CLASS.load(std::sync::atomic::Ordering::Relaxed) { + return reserved_placeholder(block); + } let mut region = Region::default(); // SAFETY: the answer's room and its size. let status = unsafe { @@ -1372,9 +1383,57 @@ fn placeholder(block: usize) -> bool { std::ptr::null_mut(), ) }; + if status == STATUS_INVALID_INFO_CLASS { + if !UNKNOWN_CLASS.swap(true, std::sync::atomic::Ordering::Relaxed) { + tracing::info!( + "the host does not tell placeholders (MemoryRegionInformationEx): the runtime's own reservations are taken instead" + ); + } + return reserved_placeholder(block); + } status >= 0 && region.region_type & PLACEHOLDER_RESERVATION != 0 } +/// The title's placeholder reservations as the runtime made them: start to +/// end, in bytes. Asked only where the host cannot tell placeholders +/// ([`placeholder`]). +static PLACEHOLDERS: Mutex<BTreeMap<usize, usize>> = Mutex::new(BTreeMap::new()); + +/// The runtime reserved `[at, at + len)` for the title as a placeholder, +/// into which pages come only by mapping a view (or an allocation) in its +/// place. Splitting it later keeps every part a placeholder. +pub fn title_placeholder_reserved(at: usize, len: usize) { + if len == 0 { + return; + } + PLACEHOLDERS.lock().unwrap_or_else(|e| e.into_inner()).insert(at, at.saturating_add(len)); +} + +/// Whether `block` lies in a placeholder the runtime reserved. +fn reserved_placeholder(block: usize) -> bool { + let at = block * BLOCK; + let held = PLACEHOLDERS.lock().unwrap_or_else(|e| e.into_inner()); + held.range(..=at).next_back().is_some_and(|(_, &end)| at + BLOCK <= end) +} + +/// The reservations of [`PLACEHOLDERS`] that `[at, at + len)` frees (with no +/// length: the one beginning at `at`) are none any more. +fn placeholders_freed(at: usize, len: usize) { + let mut held = PLACEHOLDERS.lock().unwrap_or_else(|e| e.into_inner()); + if held.is_empty() { + return; + } + if len == 0 { + held.remove(&at); + return; + } + let end = at.saturating_add(len); + let gone: Vec<usize> = held.range(..end).filter(|&(_, &e)| e > at).map(|(&s, _)| s).collect(); + for start in gone { + held.remove(&start); + } +} + /// The runtime gave the title memory at `[at, at + len)`, allocated or /// committed: what was known of holes there is asked again. pub fn title_memory_allocated(at: usize, len: usize) { @@ -2853,6 +2912,7 @@ pub fn title_memory_unmapping(at: usize, len: usize) { /// of the next memory at the address. pub fn title_memory_freed(at: usize, len: usize) { crate::shadow::write_combined_freed(at, len); + placeholders_freed(at, len); let mut g = guards(); let first = at / BLOCK; let noted = [g.protected.range(first..).next(), g.absent.range(first..).next(), g.foreign.range(first..).next().copied()]; diff --git a/crates/victory-hle/src/modules/xmem.rs b/crates/victory-hle/src/modules/xmem.rs index 3992784..320b5c0 100644 --- a/crates/victory-hle/src/modules/xmem.rs +++ b/crates/victory-hle/src/modules/xmem.rs @@ -184,6 +184,10 @@ pub extern "system" fn XMemVirtualAlloc( if !at.is_null() && !placeholder { victory_gpu::title_memory_allocated(at as usize, size); } + // For hosts that cannot be asked whether memory is a placeholder (Wine). + if !at.is_null() && kind & MEM_RESERVE_PLACEHOLDER != 0 { + victory_gpu::title_placeholder_reserved(at as usize, size); + } // Write-combined: memory the title's CPU writes and does not read. if !at.is_null() && asked & 0x400 != 0 { victory_gpu::title_memory_write_combined(at as usize, size); ``` </details> Unrelated but possibly useful for Linux testers reading this: the "missing heads / dark lighting / missing textures" on Proton experimental 11 came from its vkd3d-proton 3.2.0 hanging on 7 of the title's compute shaders (stack overflow in dxil-spirv; under Wine the worker thread just hangs, the log shows `(7 being made)` forever). A current vkd3d-proton master build next to `victory.exe` fixes it; details in a follow-up on #120.
trustno1-coder commented 2026-11-28 19:23:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T19:23:38Z.


Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7244510344 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/207#issuecomment-7244510344). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-28T19:23:38Z. --- Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.

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
trustno1-coder/VIctory-NVIDIA!207
No description provided.