victory-gpu: take per-frame allocations, locks and system calls off the frame paths (7 places the profile points at) #2846

Open
pes7 wants to merge 4 commits from upstream-pr/2848 into main
pes7 commented 2026-11-25 22:10:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-25T22:10:32Z.


Seven places in the frame paths that cost allocations, locks or system calls per call site rather than per frame. Each one comes from a number in the diagnostics profile of a world frame (copystat, 8 137 draws a frame), and each is independent.

  1. victory-gpu: read a copy-back's title bytes into a pooled buffer - copy_back_page, copy_back_or_not and copy_back_marked made a fresh Vec of up to 64 KiB for the bytes they read from title memory. The frame report counted ~1 900 page faults per frame in copy-back alone, from committing those buffers from scratch. They come from the pool the snapshots already use and go back to it; the pages a copy-back took are filtered in place instead of being collected into a second Vec.
  2. victory-gpu: sync a heap's slots in passes, without a vector of them - HostHeap::sync_slots collected every slot's record into a Vec, then a Vec<bool> of which name a current view, then a Vec of the differing slots. A world frame asks about 806 912 slots (copystat: "heap slots the title copied"), so that is tens of megabytes of allocation per frame for records read once. 512 slots at a time in stack buffers now; views_current fills a slice.
  3. victory-gpu: let heap readers share the shader heaps' lock - SHADER_HEAPS guards the list of shader-visible heaps. Every title thread that writes a view and every submission's heap sync only ever read it, but they took turns on a mutex, and the frame report put 48 ms per world frame into title threads waiting for it. Readers share an RwLock now; a heap's release still takes it alone and waits for readers, so a heap cannot be freed under a sync.
  4. victory-gpu: ask how many ranges shaders are writing before the lock - Shadow::update runs for every refreshed range (tens of thousands a frame) and locked pending to see whether the range meets a range shaders write. Most meet none, and the set is empty outside the window between a GPU-write step and the copy-back. An atomic count answers that without the lock.
  5. victory-gpu: keep a view's generation away from the view - Views::list held (View, u32), so the per-slot question "does this record still name a current view" touched a whole View (tens of bytes) for 4 bytes of generation. The generations live in a Vec<u32> of their own now: one 4-byte read per slot, and the view itself only for the few hundred slots that get mirrored.
  6. victory-watch: give write access back to guarded pages in runs - open gave access back one page at a time, a VirtualProtect each: the frame report counted 13 624 pages opened and 75.95 ms in the guard handler. Consecutive guarded pages are given back in one call, both where a write of ours opens what it covers and where a released tracker opens what nothing else watches.
  7. victory-gpu: keep a shader's user data on the stack - the dwords a stage's user data sets were collected into a fresh Vec for every stage of every draw (up to 64 dwords). They live in an array on the stack now; a title that asks for more still gets a Vec.

What is measured and what is not: the per-item numbers above are from the diagnostics build's own counters (they pointed at these call sites). The frame-time effect of the stack as a whole is not measured yet - this machine's world frames are TDR-prone and other GPU clients share the adapter, so the plan is one A/B run of the whole stack (diagnostics build, same save, copystat before/after) before anything else here is extended. Nothing in the patches changes what a frame does, only how it does it; cargo test --workspace passes (228 in victory-gpu), clippy is clean.

The tier below this one is design-level and is not in this PR: ReadProcessMemory of 205 MB a frame (117 ms), per-page VirtualProtect of the write watch (40 ms) and the 61 MB of snapshots for ranges shaders write (45 ms).

What it gives (to decide the merge): seven allocations, locks and system calls off the frame paths: a copy-back's 64 KiB buffer from the pool (~1 900 page faults a frame in copy-back alone), a heap sync that collected 806 912 slots into three Vecs per call, SHADER_HEAPS readable by many (48 ms a world frame of title threads waiting on it), a pending count that answers before the lock (25 000 refreshes a frame), view generations apart from the views (800 000 random reads a frame), guarded pages given back in runs (13 624 VirtualProtect a frame), and user data kept on the stack (16 000 allocations a frame).

State: MERGEABLE, CI check green, rebased onto today's main (f3578e3).

Risk: no behaviour change, only how a frame does the same work; each item is independent. The frame-time effect of the stack as a whole is not measured yet - that is the next run.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5500039991 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848). Originally posted by [pes7](https://github.com/pes7) on 2026-11-25T22:10:32Z. --- Seven places in the frame paths that cost allocations, locks or system calls per call site rather than per frame. Each one comes from a number in the diagnostics profile of a world frame (`copystat`, 8 137 draws a frame), and each is independent. 1. **`victory-gpu: read a copy-back's title bytes into a pooled buffer`** - `copy_back_page`, `copy_back_or_not` and `copy_back_marked` made a fresh `Vec` of up to 64 KiB for the bytes they read from title memory. The frame report counted **~1 900 page faults per frame** in copy-back alone, from committing those buffers from scratch. They come from the pool the snapshots already use and go back to it; the pages a copy-back took are filtered in place instead of being collected into a second `Vec`. 2. **`victory-gpu: sync a heap's slots in passes, without a vector of them`** - `HostHeap::sync_slots` collected every slot's record into a `Vec`, then a `Vec<bool>` of which name a current view, then a `Vec` of the differing slots. A world frame asks about **806 912 slots** (`copystat`: "heap slots the title copied"), so that is tens of megabytes of allocation per frame for records read once. 512 slots at a time in stack buffers now; `views_current` fills a slice. 3. **`victory-gpu: let heap readers share the shader heaps' lock`** - `SHADER_HEAPS` guards the list of shader-visible heaps. Every title thread that writes a view and every submission's heap sync only ever *read* it, but they took turns on a mutex, and the frame report put **48 ms per world frame** into title threads waiting for it. Readers share an `RwLock` now; a heap's release still takes it alone and waits for readers, so a heap cannot be freed under a sync. 4. **`victory-gpu: ask how many ranges shaders are writing before the lock`** - `Shadow::update` runs for every refreshed range (tens of thousands a frame) and locked `pending` to see whether the range meets a range shaders write. Most meet none, and the set is empty outside the window between a GPU-write step and the copy-back. An atomic count answers that without the lock. 5. **`victory-gpu: keep a view's generation away from the view`** - `Views::list` held `(View, u32)`, so the per-slot question "does this record still name a current view" touched a whole `View` (tens of bytes) for 4 bytes of generation. The generations live in a `Vec<u32>` of their own now: one 4-byte read per slot, and the view itself only for the few hundred slots that get mirrored. 6. **`victory-watch: give write access back to guarded pages in runs`** - `open` gave access back one page at a time, a `VirtualProtect` each: the frame report counted **13 624 pages opened** and **75.95 ms in the guard handler**. Consecutive guarded pages are given back in one call, both where a write of ours opens what it covers and where a released tracker opens what nothing else watches. 7. **`victory-gpu: keep a shader's user data on the stack`** - the dwords a stage's user data sets were collected into a fresh `Vec` for every stage of every draw (up to 64 dwords). They live in an array on the stack now; a title that asks for more still gets a `Vec`. What is measured and what is not: the per-item numbers above are from the diagnostics build's own counters (they pointed at these call sites). The frame-time effect of the stack as a whole is not measured yet - this machine's world frames are TDR-prone and other GPU clients share the adapter, so the plan is one A/B run of the whole stack (diagnostics build, same save, `copystat` before/after) before anything else here is extended. Nothing in the patches changes what a frame does, only how it does it; `cargo test --workspace` passes (228 in `victory-gpu`), clippy is clean. The tier below this one is design-level and is **not** in this PR: `ReadProcessMemory` of 205 MB a frame (117 ms), per-page `VirtualProtect` of the write watch (40 ms) and the 61 MB of snapshots for ranges shaders write (45 ms). --- **What it gives (to decide the merge):** seven allocations, locks and system calls off the frame paths: a copy-back's 64 KiB buffer from the pool (~1 900 page faults a frame in copy-back alone), a heap sync that collected 806 912 slots into three `Vec`s per call, `SHADER_HEAPS` readable by many (48 ms a world frame of title threads waiting on it), a `pending` count that answers before the lock (25 000 refreshes a frame), view generations apart from the views (800 000 random reads a frame), guarded pages given back in runs (13 624 `VirtualProtect` a frame), and user data kept on the stack (16 000 allocations a frame). **State:** MERGEABLE, CI `check` green, rebased onto today's `main` (`f3578e3`). **Risk:** no behaviour change, only how a frame does the same work; each item is independent. The frame-time effect of the stack as a whole is not measured yet - that is the next run.
fuzeofficlal commented 2026-11-25 23:06:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T22:34:26Z.


Reviewed all 7 commits of f9997fb9 and verified on Windows 11 (RTX 5090 + WARP) against main (f3578e3):

Verification

  • cargo xtask policy (190 ok), cargo clippy --locked -p victory-gpu --all-targets (default & --features diagnostics, 0 warnings).
  • RTX 5090 (--features diagnostics): descriptor::tests 7/7, descriptor::host::tests 14/14, shadow::tests 9/9, watch::tests 15/15, draw::tests 20/20 passed.
  • WARP (--features diagnostics, full crate): 243 passed, 0 failed, 1 ignored.
  • Commits 3dfeb43 (pooled Back), 7f475db (stack-chunked sync_slots), 1c70f4b (SHADER_HEAPS RwLock — verified no prepare() re-entry), 058f995 (split Views::current/list), and f9997fb (stack user_data buffer) look solid.

Two issues found

  1. 6319997 (Shadow::pending_len fast path in shadow.rs): writing() drops the self.pending mutex before calling self.pending_len.fetch_add(1, Ordering::Relaxed), and update() reads pending_len with Ordering::Relaxed outside the lock. If writing/copy_back/update ever overlap across threads, update() can observe 0 right after an insert (or copy_back can remove + fetch_sub before fetch_add, underflowing pending_len to usize::MAX), and Relaxed establishes no happens-before edge with pending. Updating pending_len while holding the pending mutex with Release (and reading with Acquire in update()) closes both the race and ordering gap at zero extra lock cost.
  2. 2851648 (watch::open_runs in watch.rs): open_runs removes [first, last) from g.protected and issues a single VirtualProtect(..., PAGE_READWRITE) ignoring the return value. On Windows, VirtualProtect fails with ERROR_INVALID_ADDRESS (487) across adjacent VirtualAlloc regions or uncommitted pages (verified locally on Windows 11: 128 KiB across two contiguous 64 KiB VirtualAlloc blocks returned 0, err=487), leaving the whole run PAGE_READONLY after dropping it from g.protected -> unhandled 0xc0000005 on next write. Checking the return value and falling back to per-page VirtualProtect (matching protect_noting) fixes it. Also conflicts directly with #2849 in watch.rs.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7176530432 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7176530432). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T22:34:26Z. --- Reviewed all 7 commits of `f9997fb9` and verified on Windows 11 (RTX 5090 + WARP) against `main` (`f3578e3`): ### Verification - `cargo xtask policy` (190 ok), `cargo clippy --locked -p victory-gpu --all-targets` (default & `--features diagnostics`, 0 warnings). - RTX 5090 (`--features diagnostics`): `descriptor::tests` 7/7, `descriptor::host::tests` 14/14, `shadow::tests` 9/9, `watch::tests` 15/15, `draw::tests` 20/20 passed. - WARP (`--features diagnostics`, full crate): 243 passed, 0 failed, 1 ignored. - Commits `3dfeb43` (pooled `Back`), `7f475db` (stack-chunked `sync_slots`), `1c70f4b` (`SHADER_HEAPS` `RwLock` — verified no `prepare()` re-entry), `058f995` (split `Views::current`/`list`), and `f9997fb` (stack `user_data` buffer) look solid. ### Two issues found 1. **`6319997` (`Shadow::pending_len` fast path in `shadow.rs`)**: `writing()` drops the `self.pending` mutex before calling `self.pending_len.fetch_add(1, Ordering::Relaxed)`, and `update()` reads `pending_len` with `Ordering::Relaxed` outside the lock. If `writing`/`copy_back`/`update` ever overlap across threads, `update()` can observe `0` right after an insert (or `copy_back` can `remove` + `fetch_sub` before `fetch_add`, underflowing `pending_len` to `usize::MAX`), and `Relaxed` establishes no happens-before edge with `pending`. Updating `pending_len` **while holding the `pending` mutex** with `Release` (and reading with `Acquire` in `update()`) closes both the race and ordering gap at zero extra lock cost. 2. **`2851648` (`watch::open_runs` in `watch.rs`)**: `open_runs` removes `[first, last)` from `g.protected` and issues a single `VirtualProtect(..., PAGE_READWRITE)` ignoring the return value. On Windows, `VirtualProtect` fails with `ERROR_INVALID_ADDRESS` (`487`) across adjacent `VirtualAlloc` regions or uncommitted pages (verified locally on Windows 11: 128 KiB across two contiguous 64 KiB `VirtualAlloc` blocks returned `0`, `err=487`), leaving the whole run `PAGE_READONLY` after dropping it from `g.protected` -> unhandled `0xc0000005` on next write. Checking the return value and falling back to per-page `VirtualProtect` (matching `protect_noting`) fixes it. Also conflicts directly with #2849 in `watch.rs`.
kotekompotek commented 2026-11-25 23:06:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T22:52:27Z.


Heads-up: this SHADER_HEAPS Mutex->RwLock conversion overlaps #2821, which does the same change (plus VIEWS) and includes a benchmark harness measuring list-call cost on the title's threads. Worth coordinating so one lands cleanly; #2821's measured baseline may be the more useful vehicle.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176886135 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7176886135). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T22:52:27Z. --- Heads-up: this SHADER_HEAPS Mutex->RwLock conversion overlaps #2821, which does the same change (plus VIEWS) and includes a benchmark harness measuring list-call cost on the title's threads. Worth coordinating so one lands cleanly; #2821's measured baseline may be the more useful vehicle.
Therecalloftheonion commented 2026-11-25 23:06:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Therecalloftheonion on 2026-11-25T22:53:00Z.


Review note on item 6 (open_runs), from the same failure found in #2849 (now closed as a duplicate of this item).

Bug: VirtualProtect can return 0 with ERROR_INVALID_ADDRESS (487) when the run crosses two separate VirtualAlloc reservations/allocations, even when the pages are contiguous and all present in g.protected. open_runs removes each page from g.protected before the call and ignores the BOOL. On failure the pages are still read-only but are no longer guarded; the next write faults and can end in an access violation.

Suggested shape: do not make the batch authoritative without checking its result.

let mut old = 0;
let batch = unsafe {
    VirtualProtect((first * PAGE) as *const _, (last - first) * PAGE, PAGE_READWRITE, &mut old)
} != 0;
if !batch {
    // Separate allocations: one page at a time, as the old `open` did.
    for page in first..last {
        let mut old = 0;
        unsafe { VirtualProtect((page * PAGE) as *const _, PAGE, PAGE_READWRITE, &mut old) };
    }
}

Either keep the pages in protected until the batch succeeds and only then remove them, or remove them and rely on the per-page fallback. Keep the OpenPages diagnostic count for the pages actually opened.

Reproduction test: two adjacent 64 KiB VirtualAlloc(..., PAGE_READONLY) regions, add both pages to g.protected, call open_runs; without the fallback the 128 KiB batch fails 487 and both pages stay read-only; with it both become PAGE_READWRITE. writable() in watch::tests can assert the result. This was reproduced on Windows 11 by @fuzeofficlal; I have not pushed a competing branch.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176896219 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7176896219). Originally posted by [Therecalloftheonion](https://github.com/Therecalloftheonion) on 2026-11-25T22:53:00Z. --- Review note on item 6 (`open_runs`), from the same failure found in #2849 (now closed as a duplicate of this item). **Bug:** `VirtualProtect` can return 0 with `ERROR_INVALID_ADDRESS` (487) when the run crosses two separate `VirtualAlloc` reservations/allocations, even when the pages are contiguous and all present in `g.protected`. `open_runs` removes each page from `g.protected` before the call and ignores the `BOOL`. On failure the pages are still read-only but are no longer guarded; the next write faults and can end in an access violation. **Suggested shape:** do not make the batch authoritative without checking its result. ```rust let mut old = 0; let batch = unsafe { VirtualProtect((first * PAGE) as *const _, (last - first) * PAGE, PAGE_READWRITE, &mut old) } != 0; if !batch { // Separate allocations: one page at a time, as the old `open` did. for page in first..last { let mut old = 0; unsafe { VirtualProtect((page * PAGE) as *const _, PAGE, PAGE_READWRITE, &mut old) }; } } ``` Either keep the pages in `protected` until the batch succeeds and only then remove them, or remove them and rely on the per-page fallback. Keep the `OpenPages` diagnostic count for the pages actually opened. **Reproduction test:** two adjacent 64 KiB `VirtualAlloc(..., PAGE_READONLY)` regions, add both pages to `g.protected`, call `open_runs`; without the fallback the 128 KiB batch fails 487 and both pages stay read-only; with it both become `PAGE_READWRITE`. `writable()` in `watch::tests` can assert the result. This was reproduced on Windows 11 by @fuzeofficlal; I have not pushed a competing branch.
pes7 commented 2026-11-26 01:03:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-26T00:10:20Z.


Ran the A/B, and it does not show a win - here is exactly what was reachable and why that is the answer, not a hidden one.

Setup: measure3 = today's main + #2634 (so the per-slot warning does not own the first frame), against the same branch with these seven commits, both --features diagnostics, ABBA (base, pr, pr, base), 240 s each, same save. The title was driven past the account screen with the repo's own VICTORY_KEYS=40:Enter,45:Enter,... (gameinput.rs: scripted keys, independent of focus) - without it the runs sit at "choose a player" forever.

What the runs reached: the loading phase - 6-16 draws a frame, 18 refreshes and 174 MB of title memory copied a frame, 3 submissions. Per frame, medians over the last part of each run:

base1 base2 pr1 pr2
ms/frame 77.5 67.0 63.4 77.7
page faults 3976 3146 3147 3147
guard handler ms 2.5 1.7 1.6 1.6
protect calls / pages 395 / 587 395 / 587 395 / 587 395 / 587
heap slots synced 5 206 4 931 5 009 4 934

That is noise: base2 sits on the PR values, and the first run of the set is the outlier on page faults (cold file cache). No column separates the two builds.

That is also what the numbers predict: this phase syncs ~5 000 heap slots a frame and makes 395 VirtualProtect calls, against the world's 806 912 slots and 13 624 pages opened - the costs these commits remove are ~150 times smaller here than where they were measured.

And the world is unreachable on this machine right now: all four runs die about 110 s in, before a single frame with more than 800 draws. On this build the title faults in its own code (Breakpad upload, frames 1 089-1 704, right after first binds of mesh/vertex/pixel/compute pipelines); the older main 13f91ca + #2634 + #2683 + #2696 build in the same conditions dies with the device removal instead. Either way the prologue does not survive here.

So: no frame-time claim for this PR. What it has is the per-call costs its counters measured (the seven lines in the description) and the fact that none of them changes what a frame does; a before/after needs a run that survives into the world, which is a TDR/machine problem (issues #2310, #2311, #1799 are other people's work on it) rather than something this stack can show.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7178473230 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7178473230). Originally posted by [pes7](https://github.com/pes7) on 2026-11-26T00:10:20Z. --- Ran the A/B, and it does **not** show a win - here is exactly what was reachable and why that is the answer, not a hidden one. Setup: `measure3` = today's `main` + #2634 (so the per-slot warning does not own the first frame), against the same branch with these seven commits, both `--features diagnostics`, ABBA (`base, pr, pr, base`), 240 s each, same save. The title was driven past the account screen with the repo's own `VICTORY_KEYS=40:Enter,45:Enter,...` (`gameinput.rs`: scripted keys, independent of focus) - without it the runs sit at "choose a player" forever. What the runs reached: the loading phase - 6-16 draws a frame, 18 refreshes and **174 MB** of title memory copied a frame, 3 submissions. Per frame, medians over the last part of each run: | | base1 | base2 | pr1 | pr2 | |---|---|---|---|---| | ms/frame | 77.5 | 67.0 | 63.4 | 77.7 | | page faults | 3976 | 3146 | 3147 | 3147 | | guard handler ms | 2.5 | 1.7 | 1.6 | 1.6 | | protect calls / pages | 395 / 587 | 395 / 587 | 395 / 587 | 395 / 587 | | heap slots synced | 5 206 | 4 931 | 5 009 | 4 934 | That is noise: `base2` sits on the PR values, and the first run of the set is the outlier on page faults (cold file cache). No column separates the two builds. That is also what the numbers predict: this phase syncs ~5 000 heap slots a frame and makes 395 `VirtualProtect` calls, against the world's **806 912** slots and **13 624** pages opened - the costs these commits remove are ~150 times smaller here than where they were measured. And the world is unreachable on this machine right now: all four runs die about 110 s in, before a single frame with more than 800 draws. On this build the title faults in its own code (Breakpad upload, frames 1 089-1 704, right after first binds of `mesh`/`vertex`/`pixel`/`compute` pipelines); the older `main` `13f91ca` + #2634 + #2683 + #2696 build in the same conditions dies with the device removal instead. Either way the prologue does not survive here. So: **no frame-time claim for this PR.** What it has is the per-call costs its counters measured (the seven lines in the description) and the fact that none of them changes what a frame does; a before/after needs a run that survives into the world, which is a TDR/machine problem (issues #2310, #2311, #1799 are other people's work on it) rather than something this stack can show.
liandraraiane commented 2026-11-26 03:05:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by liandraraiane on 2026-11-26T02:42:10Z.


Measured on a Ryzen 7 5700G (16 threads) + RTX 3060, Windows 11, release, against their base f3578e3, with a guard-lock contention benchmark (writer threads faulting on guarded pages while a submission thread arms and takes every tracker in rounds, plus a kernel-writer thread opening 8-page ranges with writing every 200 µs; guard_lock_contention_bench on branch liandraraiane/VIctory:perf/guard-lock-contention). Median of 5 rotated runs:

writers fault p99 µs (base / #2848 / #2849) 8-page writing p50 µs p99 µs
8 424 / 406 / 417 387 / 390 / 390 822 / 702 / 754
15 588 / 589 / 607 418 / 414 / 426 1131 / 1125 / 1150

With writers pausing 50 µs between writes the picture is the same. Under contention the time is waiting for the guard lock, not the open calls, so batching them does not show here. Even with one writer, an 8-page writing takes ~270 µs, almost all queued behind takes. Both pass a 12-thread stress test (writes vs takes and copies, no write lost, no stray fault) 20/20. Not tested: the title; ranges longer than 8 pages; #2848's other six changes.

AI use: Claude Code ran the builds and benchmarks on this machine and drafted this comment.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181042510 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7181042510). Originally posted by [liandraraiane](https://github.com/liandraraiane) on 2026-11-26T02:42:10Z. --- Measured on a Ryzen 7 5700G (16 threads) + RTX 3060, Windows 11, release, against their base `f3578e3`, with a guard-lock contention benchmark (writer threads faulting on guarded pages while a submission thread arms and takes every tracker in rounds, plus a kernel-writer thread opening 8-page ranges with `writing` every 200 µs; `guard_lock_contention_bench` on branch `liandraraiane/VIctory:perf/guard-lock-contention`). Median of 5 rotated runs: | writers | fault p99 µs (base / #2848 / #2849) | 8-page `writing` p50 µs | p99 µs | |---|---|---|---| | 8 | 424 / 406 / 417 | 387 / 390 / 390 | 822 / 702 / 754 | | 15 | 588 / 589 / 607 | 418 / 414 / 426 | 1131 / 1125 / 1150 | With writers pausing 50 µs between writes the picture is the same. Under contention the time is waiting for the guard lock, not the open calls, so batching them does not show here. Even with one writer, an 8-page `writing` takes ~270 µs, almost all queued behind takes. Both pass a 12-thread stress test (writes vs takes and copies, no write lost, no stray fault) 20/20. Not tested: the title; ranges longer than 8 pages; #2848's other six changes. AI use: Claude Code ran the builds and benchmarks on this machine and drafted this comment.
Marvisak commented 2026-11-26 04:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T03:20:48Z.


Automated triage for the maintainers.

Reviewed at f9997fb, which merges cleanly. CI: passing. Thanks for running the A/B and reporting the null result plainly.

The pooled Back buffer, the chunked sync_slots, the split generations in Views and the stack user data read correctly. Two of the seven commits have the problems reviewers found, and I confirm both:

  • watch.rs open_runs: the pages are removed from g.protected and then one VirtualProtect covers the whole run, with its result ignored. VirtualProtect fails when a range spans two separate allocations (error 487, reproduced above). The pages then stay read-only but are no longer known as guarded, so the next title write faults with nothing to handle it. Check the result and fall back to one page at a time, as the old open did.
  • shadow.rs: pending_len is changed after the pending lock is released, and update reads it Relaxed. Update it while holding the lock, then read it with Acquire.

Also: the SHADER_HEAPS RwLock change overlaps #2821, so please coordinate with that PR. No frame-time gain is measured, so consider splitting off the clearly safe commits (1, 2, 5, 7) so they can land on their own.

Verdict: needs work. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181633183 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7181633183). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T03:20:48Z. --- <!-- victory-triage v1 head=f9997fb9f36e8824bb971be4f4eaa6cf86073e34 verdict=needs-work at=2026-11-26T03:20:47Z --> Automated triage for the maintainers. Reviewed at `f9997fb`, which merges cleanly. CI: passing. Thanks for running the A/B and reporting the null result plainly. The pooled `Back` buffer, the chunked `sync_slots`, the split generations in `Views` and the stack user data read correctly. Two of the seven commits have the problems reviewers found, and I confirm both: - `watch.rs` `open_runs`: the pages are removed from `g.protected` and then one `VirtualProtect` covers the whole run, with its result ignored. `VirtualProtect` fails when a range spans two separate allocations (error 487, reproduced above). The pages then stay read-only but are no longer known as guarded, so the next title write faults with nothing to handle it. Check the result and fall back to one page at a time, as the old `open` did. - `shadow.rs`: `pending_len` is changed after the `pending` lock is released, and `update` reads it `Relaxed`. Update it while holding the lock, then read it with `Acquire`. Also: the `SHADER_HEAPS` `RwLock` change overlaps #2821, so please coordinate with that PR. No frame-time gain is measured, so consider splitting off the clearly safe commits (1, 2, 5, 7) so they can land on their own. **Verdict: needs work.** CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
crashbashash commented 2026-11-26 11:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by crashbashash on 2026-11-26T10:10:02Z.


In-game confirmation of the open_runs problem the triage describes, from Linux (RX 6800 XT, RADV, Proton): with this
PR on main 219878a plus our Linux commits, both runs crashed entering the world, in VIctory's own write into
title memory:

first-chance exception 0xc0000005 at victory.exe+0x27bd5f (write 0x899480000: read-only)
  #0 miniz_oxide::inflate::output_buffer::OutputBuffer::write_byte

Wine refuses a VirtualProtect whose range is not inside one view, as Windows does across allocations: #2849's
fallback test, ported to this PR's open_runs, fails under Wine too (both pages still read-only afterwards).

On splitting off the safe commits: with open_runs replaced by #2849's version (so nothing crashes), the rest of this
PR ran the same scene with 30.8 submissions a frame instead of 23.3, and frames of 849 and 668 ms instead of 522 and
657 ms (preparing 446 and 388 ms instead of 249 and 292 ms; 2 runs each, interleaved). I haven't found which commit
changes the submission count, but it may help in choosing which ones go first.

AI-assisted (Claude Code). No game data attached.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7188997466 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7188997466). Originally posted by [crashbashash](https://github.com/crashbashash) on 2026-11-26T10:10:02Z. --- In-game confirmation of the `open_runs` problem the triage describes, from Linux (RX 6800 XT, RADV, Proton): with this PR on `main` `219878a` plus our Linux commits, both runs crashed entering the world, in VIctory's own write into title memory: ``` first-chance exception 0xc0000005 at victory.exe+0x27bd5f (write 0x899480000: read-only) #0 miniz_oxide::inflate::output_buffer::OutputBuffer::write_byte ``` Wine refuses a `VirtualProtect` whose range is not inside one view, as Windows does across allocations: #2849's fallback test, ported to this PR's `open_runs`, fails under Wine too (both pages still read-only afterwards). On splitting off the safe commits: with `open_runs` replaced by #2849's version (so nothing crashes), the rest of this PR ran the same scene with 30.8 submissions a frame instead of 23.3, and frames of 849 and 668 ms instead of 522 and 657 ms (preparing 446 and 388 ms instead of 249 and 292 ms; 2 runs each, interleaved). I haven't found which commit changes the submission count, but it may help in choosing which ones go first. AI-assisted (Claude Code). No game data attached.
Creaa commented 2026-11-26 14:01:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Creaa on 2026-11-26T13:32:34Z.


@pes7 a before/after on a machine where the title gets past loading (FIND-34). One finding first: with this PR the title crashes about two minutes in, in 2 of 2 runs; without commit 2851648 ("victory-watch: give write access back to guarded pages in runs") it runs the full 8 minutes.

Setup: RTX 4070 12 GB (32-lane waves, driver 617.14), i7-13700F, 32 GB, Windows 11 26300, diag build. Base: main 63bcca4 + #2176 + #2461 + #2464 + #3115 (the stack that gets this card into the intro's 3D shots), VICTORY_SKIP_PIPELINES with #1968's three programs, scripted Enter every 10 s, 8 minutes, same warm cache for every run. "With" = the base + this PR at f9997fb (merged cleanly).

The crash (both runs with this PR, same place, nothing on the GPU side):

unhandled exception 0xc0000005 at victory.exe+0x51fe00 (write 0x...0000: read-only)
  miniz_oxide::inflate::core::decompress_fast
  miniz_oxide::inflate::core::decompress_with_limit
  miniz_oxide::inflate::core::decompress
  victory_hle::modules::dstorage::execute::closure$5
  victory_hle::modules::dstorage::work

A DirectStorage decompression writes into title memory whose page is still read-only, which looks like a page the run-based open does not give write access back to. With 2851648 reverted on top of this PR (the other six commits kept), the same run went 8 minutes with no crash and no device removal.

Frame time (median ms per frame over the frames above 100 ms, i.e. the intro's 3D part; from the diag build's fps, ms/frame (… preparing …; … on the GPU) lines):

run median ms/frame preparing on the GPU
base, run 1 605 156 335
base, run 3 614 129 421
this PR without 2851648 639 158 421

So in this scene the other six items do not show up in the frame time (within the run-to-run spread); this says nothing about the busier world frames your counters came from.

Counts and times only, no game data. AI use: Claude Code (Claude Opus 5.5) ran the runs, symbolised the crash with the build's PDB and drafted this; the runs were done on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193494739 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7193494739). Originally posted by [Creaa](https://github.com/Creaa) on 2026-11-26T13:32:34Z. --- @pes7 a before/after on a machine where the title gets past loading (FIND-34). One finding first: **with this PR the title crashes about two minutes in, in 2 of 2 runs; without commit `2851648` ("victory-watch: give write access back to guarded pages in runs") it runs the full 8 minutes.** **Setup:** RTX 4070 12 GB (32-lane waves, driver 617.14), i7-13700F, 32 GB, Windows 11 26300, diag build. Base: `main` `63bcca4` + #2176 + #2461 + #2464 + #3115 (the stack that gets this card into the intro's 3D shots), `VICTORY_SKIP_PIPELINES` with #1968's three programs, scripted Enter every 10 s, 8 minutes, same warm cache for every run. "With" = the base + this PR at `f9997fb` (merged cleanly). **The crash** (both runs with this PR, same place, nothing on the GPU side): ``` unhandled exception 0xc0000005 at victory.exe+0x51fe00 (write 0x...0000: read-only) miniz_oxide::inflate::core::decompress_fast miniz_oxide::inflate::core::decompress_with_limit miniz_oxide::inflate::core::decompress victory_hle::modules::dstorage::execute::closure$5 victory_hle::modules::dstorage::work ``` A DirectStorage decompression writes into title memory whose page is still read-only, which looks like a page the run-based `open` does not give write access back to. With `2851648` reverted on top of this PR (the other six commits kept), the same run went 8 minutes with no crash and no device removal. **Frame time** (median ms per frame over the frames above 100 ms, i.e. the intro's 3D part; from the diag build's `fps, ms/frame (… preparing …; … on the GPU)` lines): | run | median ms/frame | preparing | on the GPU | |---|---:|---:|---:| | base, run 1 | 605 | 156 | 335 | | base, run 3 | 614 | 129 | 421 | | this PR without `2851648` | 639 | 158 | 421 | So in this scene the other six items do not show up in the frame time (within the run-to-run spread); this says nothing about the busier world frames your counters came from. Counts and times only, no game data. AI use: Claude Code (Claude Opus 5.5) ran the runs, symbolised the crash with the build's PDB and drafted this; the runs were done on my machine.
pes7 commented 2026-11-26 14:01:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-26T13:37:40Z.


Both confirmed bugs are fixed on the branch, each as its own commit.

4a195c94 - a guarded page leaves the guard set only once the kernel opened it. watch::open_runs removed each page from Guards::protected before VirtualProtect and ignored the result. A page that only left the set that way stays read-only for good (no tracker holds it any more, so nothing opens it again) and the title's next write there faults with no guard to take it - the Wine removal crashbashash reproduced. Now:

  • the set is not touched until the protection is off;
  • a run the kernel refuses (a range crossing two allocations, 487) is retried one page at a time;
  • pages it does open leave the set, the rest stay in it for the next take or the fault handler;
  • what did not open is logged once per run, and copystat's "pages opened" counts what actually opened.

50be8a7c - the pending-range count moves under its lock. Shadow::writing inserted into pending and then bumped pending_len after the mutex was released, while copy_back reads that count to choose the fast path ("nothing pending"). A reader could see 0 with a range already in the set, take the snapshot path without it, and the count could drift below the set's size. The bump is now inside the lock the set moves under; add/sub are Release, the load Acquire.

Verification: cargo test --release -p victory-gpu - 228 passed, 1 ignored; clippy -D warnings clean on the crate and its targets. One GPU test failed once in a full run and passed alone and in the next full run (draw::tests::a_texture_is_uploaded_once_per_submission_and_only_when_written), so it is the load-sensitive kind this machine has, not these changes.

Still open on this PR, and deliberately not mixed in: the SHADER_HEAPS RwLock that duplicates #2821. The triage's advice was to land the safe commits first, and this is that - the two bugs above are the ones that were confirmed in code and in a run.

No frame-time claim: these are correctness fixes on paths the profile pointed at, and the per-call numbers in the PR body are unchanged by them.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193613464 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7193613464). Originally posted by [pes7](https://github.com/pes7) on 2026-11-26T13:37:40Z. --- Both confirmed bugs are fixed on the branch, each as its own commit. **`4a195c94` - a guarded page leaves the guard set only once the kernel opened it.** `watch::open_runs` removed each page from `Guards::protected` *before* `VirtualProtect` and ignored the result. A page that only left the set that way stays read-only for good (no tracker holds it any more, so nothing opens it again) and the title's next write there faults with no guard to take it - the Wine removal `crashbashash` reproduced. Now: - the set is not touched until the protection is off; - a run the kernel refuses (a range crossing two allocations, 487) is retried one page at a time; - pages it does open leave the set, the rest stay in it for the next take or the fault handler; - what did not open is logged once per run, and `copystat`'s "pages opened" counts what actually opened. **`50be8a7c` - the pending-range count moves under its lock.** `Shadow::writing` inserted into `pending` and then bumped `pending_len` after the mutex was released, while `copy_back` reads that count to choose the fast path ("nothing pending"). A reader could see 0 with a range already in the set, take the snapshot path without it, and the count could drift below the set's size. The bump is now inside the lock the set moves under; add/sub are `Release`, the load `Acquire`. Verification: `cargo test --release -p victory-gpu` - 228 passed, 1 ignored; clippy `-D warnings` clean on the crate and its targets. One GPU test failed once in a full run and passed alone and in the next full run (`draw::tests::a_texture_is_uploaded_once_per_submission_and_only_when_written`), so it is the load-sensitive kind this machine has, not these changes. Still open on this PR, and deliberately not mixed in: the `SHADER_HEAPS` `RwLock` that duplicates #2821. The triage's advice was to land the safe commits first, and this is that - the two bugs above are the ones that were confirmed in code *and* in a run. No frame-time claim: these are correctness fixes on paths the profile pointed at, and the per-call numbers in the PR body are unchanged by them.
Creaa commented 2026-11-26 14:01:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Creaa on 2026-11-26T13:56:49Z.


@pes7 confirmed on the same setup as above: with this PR at 50be8a7 (merged onto the same base) the title ran the full 8 minutes, no crash, no device removal, and nothing new in crashes.log (the two earlier runs at f9997fb both died at ~2 min in the DirectStorage decompress).

Frame time in the same intro window (median ms/frame over frames above 100 ms): 573 (preparing 132, GPU 389), against 605 and 614 for the base without this PR and 639 for f9997fb without 2851648. One run each, so read it as "no regression, maybe slightly faster", not as a measured gain.

AI use: Claude Code (Claude Opus 5.5) ran it and drafted this; the run was done on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194058040 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7194058040). Originally posted by [Creaa](https://github.com/Creaa) on 2026-11-26T13:56:49Z. --- @pes7 confirmed on the same setup as above: with this PR at `50be8a7` (merged onto the same base) the title ran the full 8 minutes, no crash, no device removal, and nothing new in `crashes.log` (the two earlier runs at `f9997fb` both died at ~2 min in the DirectStorage decompress). Frame time in the same intro window (median ms/frame over frames above 100 ms): **573** (preparing 132, GPU 389), against 605 and 614 for the base without this PR and 639 for `f9997fb` without `2851648`. One run each, so read it as "no regression, maybe slightly faster", not as a measured gain. AI use: Claude Code (Claude Opus 5.5) ran it and drafted this; the run was done on my machine.
Jackster commented 2026-11-26 15:02:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T14:56:35Z.


On the retail title this tree crashes in miniz_oxide::inflate, writing to a page the guards left read-only

Setup: Windows 10 26300.10075, RX 7900 XTX (1002:744c), driver 32.0.32029.2010, retail 1.0.2.1, diagnostics build. The branch is this PR merged into upstream/main (63bcca4) — the merge was automatic (ort, one auto-merged hunk in draw.rs) — run with VICTORY_KEYS, a warm shader cache and a save that the unpatched tree runs for 300 s. Nothing else differs between the two runs.

tree outcome
upstream/main 63bcca4 300 s to the world, 0.8 fps, 1,229 ms/frame, 0 unhandled exceptions
63bcca4 + this PR exits after ~50 s at the front end, 6 and 7 unhandled exceptions in two runs

Every exception is the same and is reproducible:

unhandled exception 0xc0000005 at victory.exe+0x51d250 (write 0x111f00000: read-only)
unhandled exception 0xc0000005 at victory.exe+0x51d250 (write 0x643d80000: read-only)
unhandled exception 0xc0000005 at victory.exe+0x51d250 (write 0x643e00000: read-only)

The address is the same in both runs; only the write target differs. Symbolised against the build's own PDB (matching GUID, same binary):

+0x51d250 -> miniz_oxide::inflate::core::decompress_fast + 0x1e0

So the faulting instruction is inflate writing its output, and the page it writes to is read-only. Of the seven changes here, the one that matches that shape is item 6 (watch::open giving write access back to guarded pages in runs): a range reopened in a run, then written by a decompressor that is not the title's thread. I cannot prove that from the address alone — the inflate call site is the caller's, not in this symbol — so treat it as the prime suspect, not the conclusion.

Caveat that matters: the branch is 78 commits behind 63bcca4, and I merged rather than rebased, so it is possible this is an interaction my merge created rather than something in the PR as written. Building the PR on its own base and running the same 300 s would separate the two, and I can do that (or bisect the seven items into separate builds) if it is useful.

What I can say with confidence: on this machine, 63bcca4 + this PR does not reach the world, and the write-to-read-only in decompress_fast is what stops it.

Written with an AI assistant.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195555242 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7195555242). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T14:56:35Z. --- **On the retail title this tree crashes in `miniz_oxide::inflate`, writing to a page the guards left read-only** Setup: Windows 10 26300.10075, RX 7900 XTX (`1002:744c`), driver 32.0.32029.2010, retail 1.0.2.1, diagnostics build. The branch is this PR merged into `upstream/main` (`63bcca4`) — the merge was automatic (`ort`, one auto-merged hunk in `draw.rs`) — run with `VICTORY_KEYS`, a warm shader cache and a save that the unpatched tree runs for 300 s. Nothing else differs between the two runs. | tree | outcome | |---|---| | `upstream/main` `63bcca4` | 300 s to the world, 0.8 fps, 1,229 ms/frame, **0 unhandled exceptions** | | `63bcca4` + this PR | exits after ~50 s at the front end, **6 and 7 unhandled exceptions** in two runs | Every exception is the same and is reproducible: ``` unhandled exception 0xc0000005 at victory.exe+0x51d250 (write 0x111f00000: read-only) unhandled exception 0xc0000005 at victory.exe+0x51d250 (write 0x643d80000: read-only) unhandled exception 0xc0000005 at victory.exe+0x51d250 (write 0x643e00000: read-only) ``` The address is the same in both runs; only the write target differs. Symbolised against the build's own PDB (matching GUID, same binary): ``` +0x51d250 -> miniz_oxide::inflate::core::decompress_fast + 0x1e0 ``` So the faulting instruction is inflate writing its output, and the page it writes to is read-only. Of the seven changes here, the one that matches that shape is item 6 (`watch::open` giving write access back to guarded pages in runs): a range reopened in a run, then written by a decompressor that is not the title's thread. I cannot prove that from the address alone — the inflate call site is the caller's, not in this symbol — so treat it as the prime suspect, not the conclusion. Caveat that matters: the branch is 78 commits behind `63bcca4`, and I merged rather than rebased, so it is possible this is an interaction my merge created rather than something in the PR as written. Building the PR on its own base and running the same 300 s would separate the two, and I can do that (or bisect the seven items into separate builds) if it is useful. What I can say with confidence: on this machine, `63bcca4` + this PR does not reach the world, and the write-to-read-only in `decompress_fast` is what stops it. Written with an AI assistant.
Jackster commented 2026-11-26 16:05:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T15:09:24Z.


Bisected: reverting the guard-reopen commit makes the tree run

Follow-up to the note above. Same save, same cache, 300 s runs:

tree outcome
63bcca4 + #2848 (merged) exits ~50 s at the front end, 6 and 7 unhandled exceptions, +0x51d250 (write <addr>: read-only), symbolised to miniz_oxide::inflate::core::decompress_fast + 0x1e0
#2848 on its own base f3578e3, no merge reaches the world, then 1 exception +0x242aa3 (read 0x30: nothing mapped there) — a different fault
63bcca4 + #2848 with 2851648 reverted 300 s to the world, 0.73 fps, 0 exceptions

So the write-to-read-only in decompress_fast comes from 2851648 ("give write access back to guarded pages in runs"), the item I suspected.

The own-base run is a separate question: f3578e3 is three commits behind 63bcca4, and one of those three may be what stops the read 0x30 fault, so I would not read that row as "the PR also has a null fault" until f3578e3 alone has been run. I can do that if it is useful.

With the revert the tree runs at 0.73 fps: preparing 584 ms, copies 305 ms of 496 MB, GPU 163 ms, copy-back 94 ms, 9,202 protect calls for 17,373 pages, 7,074 pages opened. I could not measure the full PR in the same state because it does not survive, so the cost of the reverted item is not yet attributable.

What would settle this quickly: which write paths 2851648 is meant to serve — a page reopened in a run for a title write — and whether a decompressor writing into a host copy is one of them. The faulting instruction is inflate writing its destination, which the run logic had left read-only.

Written with an AI assistant.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195863625 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7195863625). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T15:09:24Z. --- **Bisected: reverting the guard-reopen commit makes the tree run** Follow-up to the note above. Same save, same cache, 300 s runs: | tree | outcome | |---|---| | `63bcca4` + #2848 (merged) | exits ~50 s at the front end, 6 and 7 unhandled exceptions, `+0x51d250 (write <addr>: read-only)`, symbolised to `miniz_oxide::inflate::core::decompress_fast + 0x1e0` | | #2848 on its own base `f3578e3`, no merge | reaches the world, then 1 exception `+0x242aa3 (read 0x30: nothing mapped there)` — a different fault | | `63bcca4` + #2848 with **`2851648` reverted** | 300 s to the world, 0.73 fps, **0 exceptions** | So the write-to-read-only in `decompress_fast` comes from `2851648` ("give write access back to guarded pages in runs"), the item I suspected. The own-base run is a separate question: `f3578e3` is three commits behind `63bcca4`, and one of those three may be what stops the `read 0x30` fault, so I would not read that row as "the PR also has a null fault" until `f3578e3` alone has been run. I can do that if it is useful. With the revert the tree runs at 0.73 fps: preparing 584 ms, copies 305 ms of 496 MB, GPU 163 ms, copy-back 94 ms, 9,202 protect calls for 17,373 pages, 7,074 pages opened. I could not measure the full PR in the same state because it does not survive, so the cost of the reverted item is not yet attributable. What would settle this quickly: which write paths `2851648` is meant to serve — a page reopened in a run for a title write — and whether a decompressor writing into a host copy is one of them. The faulting instruction is inflate writing its destination, which the run logic had left read-only. Written with an AI assistant.
pes7 commented 2026-11-26 21:23:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-26T21:23:09Z.


Thanks @Jackster for the bisect, it was exactly right: 2851648 ("give write access back to guarded pages in runs") is out of this PR, and so is its follow-up 4a195c9, which only patched the same run logic. Guarded pages are opened one at a time again, as on main.

The branch is rebased onto current main (63bcca4, no conflicts) and now has seven commits:

  1. read a copy-back's title bytes into a pooled buffer
  2. sync a heap's slots in passes, without a vector of them
  3. let heap readers share the shader heaps' lock (overlaps #2821; whichever lands second takes the other's)
  4. ask how many ranges shaders are writing before the lock
  5. keep a view's generation away from the view
  6. keep a shader's user data on the stack
  7. the pending-range count moves under its lock (the second review item: updated under pending, read with Acquire)

Checked on this head: cargo clippy --workspace --all-targets -D warnings (also --all-features) clean, cargo test --workspace 872 passed, 0 failed. Not run on the title yet on this head.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203674747 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7203674747). Originally posted by [pes7](https://github.com/pes7) on 2026-11-26T21:23:09Z. --- Thanks @Jackster for the bisect, it was exactly right: `2851648` ("give write access back to guarded pages in runs") is out of this PR, and so is its follow-up `4a195c9`, which only patched the same run logic. Guarded pages are opened one at a time again, as on `main`. The branch is rebased onto current `main` (`63bcca4`, no conflicts) and now has seven commits: 1. read a copy-back's title bytes into a pooled buffer 2. sync a heap's slots in passes, without a vector of them 3. let heap readers share the shader heaps' lock (overlaps #2821; whichever lands second takes the other's) 4. ask how many ranges shaders are writing before the lock 5. keep a view's generation away from the view 6. keep a shader's user data on the stack 7. the pending-range count moves under its lock (the second review item: updated under `pending`, read with `Acquire`) Checked on this head: `cargo clippy --workspace --all-targets -D warnings` (also `--all-features`) clean, `cargo test --workspace` 872 passed, 0 failed. Not run on the title yet on this head.
pes7 commented 2026-11-26 21:38:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-26T21:38:54Z.


Slimmed down to what does not overlap #2821, as the review suggested: four commits, draw.rs and shadow.rs only (+90/-21).

  1. read a copy-back's title bytes into a pooled buffer
  2. ask how many ranges shaders are writing before the lock
  3. keep a shader's user data on the stack
  4. the pending-range count moves under its lock (the review's shadow.rs item: updated under pending, read with Acquire)

Dropped:

  • The three descriptor commits (slot sync in passes, the shared lock for the shader heaps, the split view generation). They conflict with #2821, which covers the same locks more broadly, so that area is left to it.
  • The guard-reopen commit (2851648), as before. All four remaining commits also apply cleanly on top of #2821, so both PRs can land in either order.

On this head (5ac4b72, on main 63bcca4): clippy -D warnings (also --all-features) clean, cargo test --workspace 872 passed, 0 failed. As before, I have no frame-time gain to claim for these; they remove allocations and lock holds from the per-frame path without changing behaviour.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203927745 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7203927745). Originally posted by [pes7](https://github.com/pes7) on 2026-11-26T21:38:54Z. --- Slimmed down to what does not overlap #2821, as the review suggested: four commits, `draw.rs` and `shadow.rs` only (+90/-21). 1. read a copy-back's title bytes into a pooled buffer 2. ask how many ranges shaders are writing before the lock 3. keep a shader's user data on the stack 4. the pending-range count moves under its lock (the review's `shadow.rs` item: updated under `pending`, read with `Acquire`) **Dropped:** - **The three descriptor commits** (slot sync in passes, the shared lock for the shader heaps, the split view generation). They conflict with #2821, which covers the same locks more broadly, so that area is left to it. - **The guard-reopen commit** (`2851648`), as before. All four remaining commits also apply cleanly on top of #2821, so both PRs can land in either order. On this head (`5ac4b72`, on `main` `63bcca4`): clippy `-D warnings` (also `--all-features`) clean, `cargo test --workspace` 872 passed, 0 failed. As before, I have no frame-time gain to claim for these; they remove allocations and lock holds from the per-frame path without changing behaviour.
neonbyte1 commented 2026-11-26 23:00:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-26T23:00:37Z.


In-game on an RTX 5090, Linux, GE-Proton11-14 Wine with vkd3d-proton, GTA VI's opening yard, head 4868c666. Untimed 10-minute runs, medians of the last 30 frame-rate reports, VICTORY_GPU_OVERLAP=1. Measured on two different bases; both got slower, mostly in "preparing":

ms/frame (min) preparing copying back
base A (main + #2958, #3120, #2309, #2461, … + #3318) 575 (542) 64 50
A + this PR 586 (565) 94 47
base B (A + #3312) 372 (359) 81 49
B + this PR 412 (386) 109 46

So about +30 ms of preparing per frame here, on both bases. Copy-back gets a little faster (−3 ms), likely from the pooled buffer. I'm bisecting the 7 commits to see which one costs the time on this setup. The read-shared SHADER_HEAPS lock and the pending count under the lock are my first suspects, since a similar RwLock change was measured slower elsewhere. I'll post which one it is.

AI-assisted (Claude); measured on my machine, no game data shared.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205175114 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7205175114). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-26T23:00:37Z. --- In-game on an RTX 5090, Linux, GE-Proton11-14 Wine with vkd3d-proton, GTA VI's opening yard, head `4868c666`. Untimed 10-minute runs, medians of the last 30 frame-rate reports, `VICTORY_GPU_OVERLAP=1`. Measured on two different bases; both got slower, mostly in "preparing": | | ms/frame (min) | preparing | copying back | |---|---|---|---| | base A (`main` + #2958, #3120, #2309, #2461, … + #3318) | 575 (542) | 64 | 50 | | A + this PR | 586 (565) | **94** | 47 | | base B (A + #3312) | 372 (359) | 81 | 49 | | B + this PR | 412 (386) | **109** | 46 | So about **+30 ms of preparing per frame** here, on both bases. Copy-back gets a little faster (−3 ms), likely from the pooled buffer. I'm bisecting the 7 commits to see which one costs the time on this setup. The read-shared `SHADER_HEAPS` lock and the pending count under the lock are my first suspects, since a similar RwLock change was measured slower elsewhere. I'll post which one it is. _AI-assisted (Claude); measured on my machine, no game data shared._
neonbyte1 commented 2026-11-27 02:40:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T02:40:48Z.


In-game bisect on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm cache. Base: main plus the unmerged PRs this setup needs, #2958, #3120 (overlap on), #3318. Medians of the last 30 frame-rate lines of 600 s runs (the bisect runs were 420 s).

Your earlier seven-commit head (through 4868c666) added about 30 ms of preparing per frame here. One commit carries all of it, the one you have since dropped:

Build Preparing Frame
base 64 ms 575 ms
base + all seven commits 94 ms 586 ms
base + fd7de0f6 only (heap readers share the shader heaps' lock) 93 ms 631 ms
base + dabb3f6c only (pooled copy-back buffer) 68 ms 614 ms
base + all seven minus 4868c666 91 ms 645 ms

So the read-shared SHADER_HEAPS lock was the regression (frame times in this scene vary by up to about ±50 ms between runs, so preparing is the number to read). The current four-commit head at 5ac4b72a doesn't have it; I'll measure that head the same way and add the result here.

AI-assisted (Claude); measured on my machine, no game data shared.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7208338137 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7208338137). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T02:40:48Z. --- In-game bisect on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm cache. Base: `main` plus the unmerged PRs this setup needs, #2958, #3120 (overlap on), #3318. Medians of the last 30 frame-rate lines of 600 s runs (the bisect runs were 420 s). Your earlier seven-commit head (through `4868c666`) added about 30 ms of preparing per frame here. One commit carries all of it, the one you have since dropped: | Build | Preparing | Frame | |---|---|---| | base | 64 ms | 575 ms | | base + all seven commits | 94 ms | 586 ms | | base + `fd7de0f6` only (heap readers share the shader heaps' lock) | **93 ms** | 631 ms | | base + `dabb3f6c` only (pooled copy-back buffer) | 68 ms | 614 ms | | base + all seven minus `4868c666` | 91 ms | 645 ms | So the read-shared `SHADER_HEAPS` lock was the regression (frame times in this scene vary by up to about ±50 ms between runs, so preparing is the number to read). The current four-commit head at `5ac4b72a` doesn't have it; I'll measure that head the same way and add the result here. _AI-assisted (Claude); measured on my machine, no game data shared._
KainanP commented 2026-11-27 12:31:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T12:31:17Z.


For #3425's SHADER_HEAPS wait: the current head (5ac4b72, draw.rs/shadow.rs only) no longer touches the heap sync. On the contention bench it reads 8.6 ms of sync and 44.9 ms/frame of title-thread wait, against 9.6 / 49.5 ms for 63bcca4 over 12 interleaved runs each, which is within this bench's ~1 ms run-to-run noise. No views were lost or stale. The full victory-gpu suite on RTX fails only the two tests that main also fails here.

Bench: sync_contention_bench (#[ignore]d; commit f34bcfb8, cherry-picks onto any tree). A placed, write-watched view heap of 2^20 slots (the host heap caps it at 934,464 here). Each frame, one thread rewrites 200 random 64 KiB pages (50 changed records each) and runs one sync_heaps, while 5 title threads write a placed-buffer SRV every 20 µs into pages of their own. "Wait" is the title threads' time in view writes beyond the uncontended 2–3 µs, summed per frame. Release build, RTX 4060 Laptop, runs interleaved with the base, medians of 30 frames per run. The bench also checks that every view written before a sync is the slot's view address after it, and that every slot is right after a final quiet sync.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218339882 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7218339882). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T12:31:17Z. --- For #3425's `SHADER_HEAPS` wait: the current head (`5ac4b72`, `draw.rs`/`shadow.rs` only) no longer touches the heap sync. On the contention bench it reads 8.6 ms of sync and 44.9 ms/frame of title-thread wait, against 9.6 / 49.5 ms for `63bcca4` over 12 interleaved runs each, which is within this bench's ~1 ms run-to-run noise. No views were lost or stale. The full `victory-gpu` suite on RTX fails only the two tests that `main` also fails here. Bench: [`sync_contention_bench`](https://github.com/KainanP/VIctory/blob/bench/sync-heaps-contention/crates/victory-gpu/src/descriptor/sync_bench.rs) (`#[ignore]`d; commit `f34bcfb8`, cherry-picks onto any tree). A placed, write-watched view heap of 2^20 slots (the host heap caps it at 934,464 here). Each frame, one thread rewrites 200 random 64 KiB pages (50 changed records each) and runs one `sync_heaps`, while 5 title threads write a placed-buffer SRV every 20 µs into pages of their own. "Wait" is the title threads' time in view writes beyond the uncontended 2–3 µs, summed per frame. Release build, RTX 4060 Laptop, runs interleaved with the base, medians of 30 frames per run. The bench also checks that every view written before a sync is the slot's view address after it, and that every slot is right after a final quiet sync. _AI use: Claude Code (Claude Opus 5.5)._
pes7 commented 2026-11-27 12:47:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-27T12:47:59Z.


@neonbyte1 thank you for the bisect, that settles it: the read-shared SHADER_HEAPS lock (fd7de0f6) carries the +30 ms of preparing.

That commit is already gone from this PR. Since 5ac4b72 (pushed before your bisect, on main 63bcca4) the PR is four commits in draw.rs and shadow.rs only: the pooled copy-back buffer (dabb3f6c in your table), asking the pending-range count before the lock, the user data on the stack, and the pending-range count moving under its lock. The three descriptor commits, including the shared lock, are dropped and left to #2821.

If you have the setup at hand, a run of 5ac4b72 on your base would show whether the four remaining commits are neutral on preparing; your dabb3f6c-only row (68 ms vs 64 ms) looks within this scene's noise, but I can't measure it here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218686738 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7218686738). Originally posted by [pes7](https://github.com/pes7) on 2026-11-27T12:47:59Z. --- @neonbyte1 thank you for the bisect, that settles it: the read-shared `SHADER_HEAPS` lock (`fd7de0f6`) carries the +30 ms of preparing. That commit is already gone from this PR. Since `5ac4b72` (pushed before your bisect, on `main` `63bcca4`) the PR is four commits in `draw.rs` and `shadow.rs` only: the pooled copy-back buffer (`dabb3f6c` in your table), asking the pending-range count before the lock, the user data on the stack, and the pending-range count moving under its lock. The three descriptor commits, including the shared lock, are dropped and left to #2821. If you have the setup at hand, a run of `5ac4b72` on your base would show whether the four remaining commits are neutral on preparing; your `dabb3f6c`-only row (68 ms vs 64 ms) looks within this scene's noise, but I can't measure it here.
zed6000 commented 2026-11-27 15:00:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-27T15:00:07Z.


The frame-time measurement this PR was waiting for (FIND-31 / FIND-34 on #1633). There is no measurable effect on frame time here.

Setup: AMD RX 7900 XTX (driver 32.0.32029.2010), Ryzen 9 7900X3D, Windows 11. This PR's head 5ac4b72 against main 63bcca4, both diagnostics builds made the same way, each in its own target folder (checked that the two exes differ). Series X profile, intro cutscene, scripted keys, pipelines cached. Runs in the order main, PR, PR, main. Each figure is the median of 36 frame-report lines. cargo test -p victory-gpu --lib: 231 passed on both.

run ms/frame preparing GPU copying back page faults/frame
main (1) 541 230 159 67 39,372
this PR (1) 440 205 157 65 30,557
this PR (2) 422 202 151 64 37,840
main (2) 410 196 150 60 13,955
  • The first main run is an outlier: it refreshed about 20 GB a frame against about 16 GB in the other three, so it covered a different stretch of the intro. Against the second main run, this PR is not faster (422 and 440 ms against 410 ms). Copying back is unchanged (64–65 ms against 60–67 ms).
  • Page faults per frame vary by a factor of three between runs of the same build, so they can't show this PR's effect at this scale.
  • No errors in any run, 0 dropped draws, and the same warning kinds.

So at the intro's scale (about 4,900 draws a frame, 0.5 GB of title copies a frame), the costs these four commits remove are below run-to-run noise. They may still matter in heavier scenes, but I can't show that from here. Note that this head has four commits: items 1, 4 and 7 of the description, plus one that moves the pending-range count under its lock. Items 2, 3, 5 and 6 (heap sync in passes, the shader heaps' lock shared by readers, view generations apart, guarded pages opened in runs) aren't in it, so this result doesn't cover them.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7221498666 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7221498666). Originally posted by [zed6000](https://github.com/zed6000) on 2026-11-27T15:00:07Z. --- The frame-time measurement this PR was waiting for (FIND-31 / FIND-34 on #1633). There is no measurable effect on frame time here. **Setup:** AMD RX 7900 XTX (driver 32.0.32029.2010), Ryzen 9 7900X3D, Windows 11. This PR's head `5ac4b72` against `main` `63bcca4`, both diagnostics builds made the same way, each in its own target folder (checked that the two exes differ). Series X profile, intro cutscene, scripted keys, pipelines cached. Runs in the order main, PR, PR, main. Each figure is the median of 36 frame-report lines. `cargo test -p victory-gpu --lib`: 231 passed on both. | run | ms/frame | preparing | GPU | copying back | page faults/frame | |---|---:|---:|---:|---:|---:| | `main` (1) | 541 | 230 | 159 | 67 | 39,372 | | this PR (1) | 440 | 205 | 157 | 65 | 30,557 | | this PR (2) | 422 | 202 | 151 | 64 | 37,840 | | `main` (2) | 410 | 196 | 150 | 60 | 13,955 | - The first `main` run is an outlier: it refreshed about 20 GB a frame against about 16 GB in the other three, so it covered a different stretch of the intro. Against the second `main` run, this PR is not faster (422 and 440 ms against 410 ms). Copying back is unchanged (64–65 ms against 60–67 ms). - Page faults per frame vary by a factor of three between runs of the same build, so they can't show this PR's effect at this scale. - No errors in any run, 0 dropped draws, and the same warning kinds. So at the intro's scale (about 4,900 draws a frame, 0.5 GB of title copies a frame), the costs these four commits remove are below run-to-run noise. They may still matter in heavier scenes, but I can't show that from here. Note that this head has four commits: items 1, 4 and 7 of the description, plus one that moves the pending-range count under its lock. Items 2, 3, 5 and 6 (heap sync in passes, the shader heaps' lock shared by readers, view generations apart, guarded pages opened in runs) aren't in it, so this result doesn't cover them.
Testaross commented 2026-11-30 01:29:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Testaross on 2026-11-30T01:29:41Z.


Hey man, saw your work on GPU memory waits. I’ve been decompiling the original Series X memory subsystem to eventually move away from unified memory translation altogether.

I’ve identified six rotating graphics pools and some of the epoch synchronization logic. Right now I’m trying to figure out exactly when the GPU is done with those allocations and when they can safely be reused.

I’d be interested in comparing your findings with mine. Have you been able to identify what’s actually writing to those wait addresses?

Would you be down to collaborate? I think we might be able to help each other out quite a bit.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7266183118 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2848#issuecomment-7266183118). Originally posted by [Testaross](https://github.com/Testaross) on 2026-11-30T01:29:41Z. --- Hey man, saw your work on GPU memory waits. I’ve been decompiling the original Series X memory subsystem to eventually move away from unified memory translation altogether. I’ve identified six rotating graphics pools and some of the epoch synchronization logic. Right now I’m trying to figure out exactly when the GPU is done with those allocations and when they can safely be reused. I’d be interested in comparing your findings with mine. Have you been able to identify what’s actually writing to those wait addresses? Would you be down to collaborate? I think we might be able to help each other out quite a bit.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2848:upstream-pr/2848'
git switch 'upstream-pr/2848'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2848'
git switch 'upstream-pr/2848'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2848'
git switch 'upstream-pr/2848'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2848'
git switch 'main'
git merge --squash 'upstream-pr/2848'
git switch 'main'
git merge --ff-only 'upstream-pr/2848'
git switch 'main'
git merge 'upstream-pr/2848'
git push origin 'main'
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
Marvisak/VIctory!2846
No description provided.