GPU: open guarded pages in runs, not one VirtualProtect at a time #2847

Open
Therecalloftheonion wants to merge 2 commits from upstream-pr/2849 into main
Therecalloftheonion commented 2026-11-25 22:14:01 +00:00 (Migrated from github.com)

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


Problem

Issue #400 puts about 600 ms a frame in the guard lock on an RTX 2080, with ~3,800 VirtualProtect calls a frame. Two hot paths opened guarded pages one call at a time:

  • changed_here (a title write over a range, e.g. a memset or a file read) collected the protected pages of the range and called VirtualProtect per page.
  • Tracked::drop did the same for every page freed when the last tracker let go of it.

The pages are already in sorted order in both callers.

Change

open_pages groups consecutive guarded pages and open_range makes one VirtualProtect call per run. Only runs where every page is guarded are opened; unguarded pages are skipped exactly as before, and the guard set, changed marks and saved snapshots are unchanged.

This is not #1884: that sorts/deduplicates alias pages and replaces active-writer scans; this batches the write-access restore calls themselves. It does not touch the copy path or the listed copy PRs.

Benchmark

cargo test --release -p victory-gpu benchmark_guard_open_runs -- --ignored --test-threads=1 --nocapture, 512 pages, 20 rounds, RX 6700 XT, release:

path VirtualProtect calls time
one call per page (old) 10,240 4.27 ms
one call per run (new) 20 1.79 ms

The test-only switch runs both paths on the same protected pages, so this is a direct before/after. It measures the write-access restore step only, not game FPS; no title data was available here.

Tests

  • New watch::tests::a_bulk_write_opens_guarded_pages_in_one_call: an 8-page write opens the run with one call and every page is read-write again.
  • cargo test -p victory-gpu --lib: 227 passed, 2 ignored. Two unrelated upstream tests are filtered because they fail on main on this machine (the 2^21 view-heap assertion and the copy-pair placement test).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • rustfmt --check on the file reports pre-existing differences (first at line 100, unrelated); the new code follows the surrounding style.

Regressions

  • open_pages relies on the sorted page lists both callers already provide; a future unsorted caller would lose batching but not correctness (unguarded pages are skipped).
  • Opening a run is only done when every page in it is guarded; a gap breaks the run.
  • Runtime behaviour and GPU synchronization are unchanged: this only restores page protection before the write that already caused it.

All Windows D3D12 vendors benefit equally; it is host CPU/kernel work, not GPU-specific.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5500085203 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849). Originally posted by [Therecalloftheonion](https://github.com/Therecalloftheonion) on 2026-11-25T22:14:01Z. --- ## Problem Issue #400 puts about 600 ms a frame in the guard lock on an RTX 2080, with ~3,800 `VirtualProtect` calls a frame. Two hot paths opened guarded pages one call at a time: - `changed_here` (a title write over a range, e.g. a `memset` or a file read) collected the protected pages of the range and called `VirtualProtect` per page. - `Tracked::drop` did the same for every page freed when the last tracker let go of it. The pages are already in sorted order in both callers. ## Change `open_pages` groups consecutive guarded pages and `open_range` makes **one `VirtualProtect` call per run**. Only runs where every page is guarded are opened; unguarded pages are skipped exactly as before, and the guard set, changed marks and saved snapshots are unchanged. This is not #1884: that sorts/deduplicates alias pages and replaces active-writer scans; this batches the write-access restore calls themselves. It does not touch the copy path or the listed copy PRs. ## Benchmark `cargo test --release -p victory-gpu benchmark_guard_open_runs -- --ignored --test-threads=1 --nocapture`, 512 pages, 20 rounds, RX 6700 XT, release: | path | VirtualProtect calls | time | |---|---:|---:| | one call per page (old) | 10,240 | 4.27 ms | | one call per run (new) | **20** | **1.79 ms** | The test-only switch runs both paths on the same protected pages, so this is a direct before/after. It measures the write-access restore step only, not game FPS; no title data was available here. ## Tests - New `watch::tests::a_bulk_write_opens_guarded_pages_in_one_call`: an 8-page write opens the run with one call and every page is read-write again. - `cargo test -p victory-gpu --lib`: **227 passed**, 2 ignored. Two unrelated upstream tests are filtered because they fail on `main` on this machine (the 2^21 view-heap assertion and the copy-pair placement test). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `rustfmt --check` on the file reports pre-existing differences (first at line 100, unrelated); the new code follows the surrounding style. ## Regressions - `open_pages` relies on the sorted page lists both callers already provide; a future unsorted caller would lose batching but not correctness (unguarded pages are skipped). - Opening a run is only done when every page in it is guarded; a gap breaks the run. - Runtime behaviour and GPU synchronization are unchanged: this only restores page protection before the write that already caused it. All Windows D3D12 vendors benefit equally; it is host CPU/kernel work, not GPU-specific.
kotekompotek commented 2026-11-25 22:51:26 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Correct batching: the debug_assert that a run is fully guarded is exactly the safety property needed — one VirtualProtect over a partial run would silently change protection of pages that aren't ours or that another tracker watches. Collecting to_open first keeps the same semantics as the per-page loop. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066073087 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#pullrequestreview-6066073087). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T22:51:26Z. **Review:** COMMENTED --- Correct batching: the debug_assert that a run is fully guarded is exactly the safety property needed — one VirtualProtect over a partial run would silently change protection of pages that aren't ours or that another tracker watches. Collecting to_open first keeps the same semantics as the per-page loop. LGTM.
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:25Z.


Tested 7be4f20d on Windows 11 (RTX 5090 + WARP) and benchmarked --release, but caught a real Windows VirtualProtect boundary bug in open_range:

Bug: VirtualProtect fails across adjacent VirtualAlloc regions without fallback

  • open_range removes [first, last) from g.protected and issues one VirtualProtect((first * PAGE) as ..., (last - first) * PAGE, PAGE_READWRITE, &mut old) while ignoring the BOOL return value.
  • On Windows, VirtualProtect fails with ERROR_INVALID_ADDRESS (487) and leaves all pages untouched whenever the range crosses two separate VirtualAlloc reservations/allocations (even if they are contiguous and all present in g.protected) or contains a freed/uncommitted page.
  • Confirmed locally on Windows 11 with two adjacent 64 KiB VirtualAlloc(..., PAGE_READONLY) regions: a single 128 KiB VirtualProtect(..., PAGE_READWRITE) returned ok=0, err=487, while per-page calls succeeded (ok=1).
  • Because g.protected already removed those pages, the next write hits a still-PAGE_READONLY page outside the guard set and crashes with an unhandled 0xc0000005.
  • Checking VirtualProtect(...) != 0 and falling back to per-page VirtualProtect when last - first > 1 (matching protect_noting in watch.rs) avoids this cleanly.

Local test & benchmark results

  • cargo xtask policy (190 ok), clippy default & diagnostics 0 warnings; watch::tests 16/16 & shadow::tests 9/9 passed on RTX 5090 and WARP.
  • --release benchmark_guard_open_runs: 4.5307 ms (10,240 calls) -> 1.2228 ms (20 calls, ~3.71x faster).
  • Note: overlaps/conflicts directly with #2848 (2851648) in crates/victory-gpu/src/watch.rs.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7176529910 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7176529910). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T22:34:25Z. --- Tested `7be4f20d` on Windows 11 (RTX 5090 + WARP) and benchmarked `--release`, but caught a real Windows `VirtualProtect` boundary bug in `open_range`: ### Bug: `VirtualProtect` fails across adjacent `VirtualAlloc` regions without fallback - `open_range` removes `[first, last)` from `g.protected` and issues one `VirtualProtect((first * PAGE) as ..., (last - first) * PAGE, PAGE_READWRITE, &mut old)` while ignoring the `BOOL` return value. - On Windows, `VirtualProtect` fails with `ERROR_INVALID_ADDRESS` (`487`) and leaves **all** pages untouched whenever the range crosses two separate `VirtualAlloc` reservations/allocations (even if they are contiguous and all present in `g.protected`) or contains a freed/uncommitted page. - Confirmed locally on Windows 11 with two adjacent 64 KiB `VirtualAlloc(..., PAGE_READONLY)` regions: a single 128 KiB `VirtualProtect(..., PAGE_READWRITE)` returned `ok=0, err=487`, while per-page calls succeeded (`ok=1`). - Because `g.protected` already removed those pages, the next write hits a still-`PAGE_READONLY` page outside the guard set and crashes with an unhandled `0xc0000005`. - Checking `VirtualProtect(...) != 0` and falling back to per-page `VirtualProtect` when `last - first > 1` (matching `protect_noting` in `watch.rs`) avoids this cleanly. ### Local test & benchmark results - `cargo xtask policy` (190 ok), clippy default & `diagnostics` 0 warnings; `watch::tests` 16/16 & `shadow::tests` 9/9 passed on RTX 5090 and WARP. - `--release` `benchmark_guard_open_runs`: `4.5307 ms` (10,240 calls) -> `1.2228 ms` (20 calls, **~3.71x faster**). - Note: overlaps/conflicts directly with #2848 (`2851648`) in `crates/victory-gpu/src/watch.rs`.
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:52:43Z.


Thanks @fuzeofficlal. Confirmed and accepted: VirtualProtect can fail across two separate VirtualAlloc regions, and my open_range removed the pages from protected before ignoring the return. A later write then faults on a still-read-only page outside the guard set.

I also see #2848 item 6 implements the same open-runs optimization. This PR is a duplicate of that item, so I am closing it rather than carrying a second copy. The failure and the fallback belong on #2848; I have left the detail there. No credit claimed here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176891007 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7176891007). Originally posted by [Therecalloftheonion](https://github.com/Therecalloftheonion) on 2026-11-25T22:52:43Z. --- Thanks @fuzeofficlal. Confirmed and accepted: `VirtualProtect` can fail across two separate `VirtualAlloc` regions, and my `open_range` removed the pages from `protected` before ignoring the return. A later write then faults on a still-read-only page outside the guard set. I also see #2848 item 6 implements the same open-runs optimization. This PR is a duplicate of that item, so I am closing it rather than carrying a second copy. The failure and the fallback belong on #2848; I have left the detail there. No credit claimed here.
Therecalloftheonion commented 2026-11-25 23:06:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Therecalloftheonion on 2026-11-25T23:02:02Z.


Reopened with the fix for the ERROR_INVALID_ADDRESS (487) failure found by @fuzeofficlal.

open_range now checks the batch VirtualProtect result and, when it is 0, restores the run one page at a time (the pages were already taken out of g.protected; the per-page calls put them back to PAGE_READWRITE and a page that is gone still fails harmlessly, as the old path did).

Added open_runs_falls_back_across_separate_allocations: two adjacent pages allocated separately, both guarded, then open_pages; both must be PAGE_READWRITE and no longer in protected. On this machine the two-page batch is the only run, so the test exercises the fallback path.

Benchmark unchanged when the batch succeeds: 512 pages, 20 rounds, release: 4.13 ms (10,240 calls) vs 1.61 ms (20 calls). The fix adds no work to the success path.

Still overlaps #2848 item 6 (2851648), which has the same batching and the same missing fallback; the fix applies there too. Maintainers can keep either; I am not claiming a separate contribution for the same optimization.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177068876 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7177068876). Originally posted by [Therecalloftheonion](https://github.com/Therecalloftheonion) on 2026-11-25T23:02:02Z. --- Reopened with the fix for the `ERROR_INVALID_ADDRESS` (487) failure found by @fuzeofficlal. `open_range` now checks the batch `VirtualProtect` result and, when it is 0, restores the run one page at a time (the pages were already taken out of `g.protected`; the per-page calls put them back to `PAGE_READWRITE` and a page that is gone still fails harmlessly, as the old path did). Added `open_runs_falls_back_across_separate_allocations`: two adjacent pages allocated separately, both guarded, then `open_pages`; both must be `PAGE_READWRITE` and no longer in `protected`. On this machine the two-page batch is the only run, so the test exercises the fallback path. Benchmark unchanged when the batch succeeds: 512 pages, 20 rounds, release: 4.13 ms (10,240 calls) vs 1.61 ms (20 calls). The fix adds no work to the success path. Still overlaps #2848 item 6 (`2851648`), which has the same batching and the same missing fallback; the fix applies there too. Maintainers can keep either; I am not claiming a separate contribution for the same optimization.
Machad3x commented 2026-11-26 00:03:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-25T23:18:53Z.


Hardware result at head 7be4f20d, cherry-picked onto a fork stack that opens a changed page's aliases too, RTX 3080 Ti, driver 621.24.

  1. A run can cross allocations: with two mapped views of one memory next to each other in the sorted pages, the single VirtualProtect fails (a call cannot span allocations), the pages are already removed from the guard set, and the next write faults for ever (access violation in a two-mapping tracker test the stack carries). Opening page by page when the call returns 0 fixed the test. On main this needs two adjacent views both in one run.
  2. Timing: correction of what this comment first said. We compared one run with the change (724 ms a frame, guard lock 305 ms) against one without (675 ms, 114 ms), but a later run without it measured 325 ms of guard lock, so that figure swings between runs by more than the difference. We have no measured effect either way.

Ran with AI assistance (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177396382 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7177396382). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-25T23:18:53Z. --- Hardware result at head 7be4f20d, cherry-picked onto a fork stack that opens a changed page's aliases too, RTX 3080 Ti, driver 621.24. 1. A run can cross allocations: with two mapped views of one memory next to each other in the sorted pages, the single `VirtualProtect` fails (a call cannot span allocations), the pages are already removed from the guard set, and the next write faults for ever (access violation in a two-mapping tracker test the stack carries). Opening page by page when the call returns 0 fixed the test. On `main` this needs two adjacent views both in one run. 2. Timing: **correction** of what this comment first said. We compared one run with the change (724 ms a frame, guard lock 305 ms) against one without (675 ms, 114 ms), but a later run without it measured 325 ms of guard lock, so that figure swings between runs by more than the difference. We have no measured effect either way. Ran with AI assistance (Claude Code).
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:12Z.


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:7181042769 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7181042769). Originally posted by [liandraraiane](https://github.com/liandraraiane) on 2026-11-26T02:42:12Z. --- 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:17 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Verdict: needs work (small). The batching in open_pages / open_range (crates/victory-gpu/src/watch.rs) looks correct. Runs are opened only when every page is guarded. The per-page fallback when the batched VirtualProtect returns 0 covers the cross-allocation failure fuzeofficlal found. The pages leave protected as before, and OpenPages still counts pages. What needs fixing before a merge:

  • The diff deletes the doc comment of the existing test writes_mark_every_tracker_of_their_page ("Everything is changed at first; …"). Please restore it.
  • The doc comment on open_pages links to [open], which this PR removes.

For the maintainers: #2848 (item 6) makes the same batching change in watch.rs without the fallback, and the two conflict. If that item is kept, it needs the same fallback. The microbenchmark shows the restore step about 2.4x faster. liandraraiane's contention benchmark and Machad3x's title run show no measured effect, so the gain in the title is unproven.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181678704 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7181678704). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T03:23:35Z. --- <!-- victory-triage v1 head=7b1316af3863e83ddba383fe684755eeba76e69a verdict=needs-work at=2026-11-26T03:23:34Z --> Automated triage for the maintainers. **Verdict: needs work (small).** The batching in `open_pages` / `open_range` (`crates/victory-gpu/src/watch.rs`) looks correct. Runs are opened only when every page is guarded. The per-page fallback when the batched `VirtualProtect` returns 0 covers the cross-allocation failure fuzeofficlal found. The pages leave `protected` as before, and `OpenPages` still counts pages. What needs fixing before a merge: - The diff deletes the doc comment of the existing test `writes_mark_every_tracker_of_their_page` ("Everything is changed at first; …"). Please restore it. - The doc comment on `open_pages` links to `[`open`]`, which this PR removes. For the maintainers: #2848 (item 6) makes the same batching change in `watch.rs` without the fallback, and the two conflict. If that item is kept, it needs the same fallback. The microbenchmark shows the restore step about 2.4x faster. liandraraiane's contention benchmark and Machad3x's title run show no measured effect, so the gain in the title is unproven. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
MeMako commented 2026-11-26 07:01:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MeMako on 2026-11-26T06:28:53Z.


Verified #2849 (7b1316a) on Windows 11 (10.0.26200, Ryzen 9 7950X, RX 9070 XT, driver 32.0.32029.2010, 32 GB RAM).

Tests & Microbenchmark

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean.
  • victory-gpu: 272/272 passed (including a_bulk_write_opens_guarded_pages_in_one_call).
  • benchmark_guard_open_runs (--release, 512 pages × 20 rounds):
    • One call per page (10,240 VirtualProtect calls): 5.120 ms
    • One call per run (20 VirtualProtect calls): 1.336 ms (3.83x faster)

Live Title Verification & Integration Note

  • Setup: Local integration branch (main 63bcca4 + #2051 + #2472 + #2918 + #1010 + #2130 with VRAM upload flags off + #3055 + #2914), adding #2985 + #2849 + #3035 together in the same live run (n=54 world frames / n=38 heavy frames vs. n=51 / n=38 baseline).
  • Result: 0 crashes or faults through the intro and opening world scene.
  • Subsystem metrics (steady tail, last 20 heavy frames — 6,186 draws vs. 5,290 draws in baseline):
    • prep → deferred: 92.7 → 71.8 ms (-20.9 ms / -22.5%)
    • copy_back: 99.2 → 75.5 ms (-23.7 ms / -23.9%)
    • (Both watch.rs timers reflect #2849 and #3035 combined; #2985 affects texture detile/upload separately.)
  • Combined frame-time delta (all three PRs #2985 + #2849 + #3035 together): steady-tail frame time dropped 453.3 → 423.6 ms (2.20 → 2.40 fps), even with +17% more draws.
  • Note for combining with #3035: Since #2849 replaces single-page open() with open_range(), #3035's opened(page).fetch_add(1, Ordering::Relaxed) bump simply moves inside open_range()'s if g.protected.remove(&page) loop (the single removal site) so both PRs compose cleanly.

Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184470610 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7184470610). Originally posted by [MeMako](https://github.com/MeMako) on 2026-11-26T06:28:53Z. --- Verified `#2849` (`7b1316a`) on Windows 11 (`10.0.26200`, Ryzen 9 7950X, RX 9070 XT, driver `32.0.32029.2010`, 32 GB RAM). ### Tests & Microbenchmark - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: clean. - `victory-gpu`: **272/272 passed** (including `a_bulk_write_opens_guarded_pages_in_one_call`). - `benchmark_guard_open_runs` (`--release`, 512 pages × 20 rounds): - One call per page (10,240 `VirtualProtect` calls): **5.120 ms** - One call per run (20 `VirtualProtect` calls): **1.336 ms** (**3.83x faster**) ### Live Title Verification & Integration Note - **Setup:** Local integration branch (`main` `63bcca4` + `#2051` + `#2472` + `#2918` + `#1010` + `#2130` with VRAM upload flags off + `#3055` + `#2914`), adding `#2985` + `#2849` + `#3035` together in the same live run (`n=54` world frames / `n=38` heavy frames vs. `n=51` / `n=38` baseline). - **Result:** 0 crashes or faults through the intro and opening world scene. - **Subsystem metrics (steady tail, last 20 heavy frames — `6,186` draws vs. `5,290` draws in baseline):** - `prep → deferred`: **92.7 → 71.8 ms** (**-20.9 ms / -22.5%**) - `copy_back`: **99.2 → 75.5 ms** (**-23.7 ms / -23.9%**) - *(Both `watch.rs` timers reflect `#2849` and `#3035` combined; `#2985` affects texture detile/upload separately.)* - **Combined frame-time delta (all three PRs `#2985` + `#2849` + `#3035` together):** steady-tail frame time dropped **453.3 → 423.6 ms** (**2.20 → 2.40 fps**), even with +17% more draws. - **Note for combining with `#3035`:** Since `#2849` replaces single-page `open()` with `open_range()`, `#3035`'s `opened(page).fetch_add(1, Ordering::Relaxed)` bump simply moves inside `open_range()`'s `if g.protected.remove(&page)` loop (the single removal site) so both PRs compose cleanly. *Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.*
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:01Z.


On "the gain in the title is unproven": here is an in-game A/B from Linux, where every VirtualProtect is a Wine call
plus an mprotect, so the per-call cost the batching saves is larger than on Windows. RX 6800 XT, RADV,
GE-Proton11-14 (with a newer vkd3d-proton and the wineserver view tree), diag build of main 219878a plus our
Linux commits, with and without this PR (7b1316a, merges cleanly), a save in the prison, 120 s in the world, idle
machine, runs interleaved.

without with this PR
runs 2 2
world frame, median 619, 667 ms 490, 530 ms
of it preparing submissions 300, 303 ms 219, 249 ms
submissions per frame 23.3, 23.2 22.8, 23.0

No crash or change in behaviour in those runs, and the crate's tests pass under Wine, the fallback test included
(Wine also refuses a VirtualProtect whose range is not inside one view). Two runs a side is not a precise figure,
but both are well apart.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7188997004 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7188997004). Originally posted by [crashbashash](https://github.com/crashbashash) on 2026-11-26T10:10:01Z. --- On "the gain in the title is unproven": here is an in-game A/B from Linux, where every `VirtualProtect` is a Wine call plus an `mprotect`, so the per-call cost the batching saves is larger than on Windows. RX 6800 XT, RADV, GE-Proton11-14 (with a newer vkd3d-proton and the wineserver view tree), `diag` build of `main` `219878a` plus our Linux commits, with and without this PR (`7b1316a`, merges cleanly), a save in the prison, 120 s in the world, idle machine, runs interleaved. | | without | with this PR | |---|---|---| | runs | 2 | 2 | | world frame, median | 619, 667 ms | 490, 530 ms | | of it preparing submissions | 300, 303 ms | 219, 249 ms | | submissions per frame | 23.3, 23.2 | 22.8, 23.0 | No crash or change in behaviour in those runs, and the crate's tests pass under Wine, the fallback test included (Wine also refuses a `VirtualProtect` whose range is not inside one view). Two runs a side is not a precise figure, but both are well apart. AI-assisted (Claude Code). No game data attached.
RobertAndreiGit commented 2026-11-26 14:01:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RobertAndreiGit on 2026-11-26T13:59:14Z.


RTX 3060 Ti / Proton: batching avoided 380 VirtualProtect calls, but we saw no world-frame improvement in a downstream A/B. We adapted 7be4f20 and the per-block fallback in 7b1316a to cool_fox; this is not a test of the upstream branch unchanged. This fork first uses VirtualQuery to check that a run fits in one committed, uniformly read-only region. The 380 counts avoided protection calls, not net syscalls; 577 candidate runs took the per-block path.

Median of 15 qualifying world intervals Control Batched opens
Frame time (middle 50%) 282.4 ms (176–652) 365.3 ms (182–670)
FPS 3.5 2.7
Draws / dropped for lack of a pipeline 3,903 / 308 3,647 / 308

Same release executable (SHA-256 starts d798074e88b7), same save and initial pipeline cache; only VICTORY_BATCH_OPEN=1 changed. Series S, host temporal 720p → 1080p, 24 ms pipeline wait; Ryzen 5 5600, 32 GB RAM, RTX 3060 Ti 8 GB, NVIDIA 615.78.08, CachyOS Proton / vkd3d-proton 3.2.0. The focused Proton test for uniform and mixed protections passed.

The player preferred the control and found the batching run visibly slower. One non-replayed run per setting, with overlapping frame times; this does not contradict the PR’s isolated open-step benchmark. A useful discriminator would be timing VirtualQuery, successful batches and fallbacks separately during world frames.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7194113918 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7194113918). Originally posted by [RobertAndreiGit](https://github.com/RobertAndreiGit) on 2026-11-26T13:59:14Z. --- <!-- cool-fox-world-3060ti-20261126:victory-2849.md --> **RTX 3060 Ti / Proton: batching avoided 380 `VirtualProtect` calls, but we saw no world-frame improvement in a downstream A/B.** We adapted `7be4f20` and the per-block fallback in `7b1316a` to `cool_fox`; this is not a test of the upstream branch unchanged. This fork first uses `VirtualQuery` to check that a run fits in one committed, uniformly read-only region. The 380 counts avoided protection calls, **not net syscalls**; 577 candidate runs took the per-block path. | Median of 15 qualifying world intervals | Control | Batched opens | |---|---:|---:| | Frame time (middle 50%) | 282.4 ms (176–652) | 365.3 ms (182–670) | | FPS | 3.5 | 2.7 | | Draws / dropped for lack of a pipeline | 3,903 / 308 | 3,647 / 308 | Same release executable (SHA-256 starts `d798074e88b7`), same save and initial pipeline cache; only `VICTORY_BATCH_OPEN=1` changed. Series S, host temporal 720p → 1080p, 24 ms pipeline wait; Ryzen 5 5600, 32 GB RAM, RTX 3060 Ti 8 GB, NVIDIA 615.78.08, CachyOS Proton / vkd3d-proton 3.2.0. The focused Proton test for uniform and mixed protections passed. The player preferred the control and found the batching run visibly slower. One non-replayed run per setting, with overlapping frame times; this does not contradict the PR’s isolated open-step benchmark. A useful discriminator would be timing `VirtualQuery`, successful batches and fallbacks separately during world frames.
KainanP commented 2026-11-27 12:40:23 +00:00 (Migrated from github.com)

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


Contention numbers for this PR from a shared benchmark (for #3425).

Method. The benchmark guard_contention and the check refreshes_under_writes_lose_nothing from #3516, split out as a standalone test-only commit (KainanP/VIctory perf/guard-bench: no behaviour change, guards() only times a lock it finds taken in test builds), applied unchanged to this PR's head (7b1316a) and to main (63bcca4). 256 MB write-watched pool in 64 KiB pages, copies of 32 pages, 1,400 pages dirtied before each refresh, title threads writing a random word every 20 µs while the copies are taken and copied. Release builds, i7-14650HX (24 threads), Windows 11. 31 rounds, builds interleaved and rotated each round, each run = median of 5 refreshes after a warm-up; table = medians over the 31 runs, plus the median (and quartiles) of the per-round PR/main ratio. Foreign load: other agents' rustc jobs were running (≈8 % of the CPU in a spot sample); the paired ratio is what to read.

Config Refresh ms (main → PR) Writers in their writes, ms Writers waiting for GUARDS, ms PR/main, writes PR/main, wait
1 writer 17.4 → 17.2 5.1 → 5.1 2.8 → 2.7 1.03 (0.90–1.15) 0.97 (0.92–1.10)
4 writers 29.1 → 32.0 37.8 → 40.8 24.3 → 26.2 1.05 (0.95–1.08) 1.02 (0.97–1.10)
4 writers, refresh on 4 threads 9.2 → 9.4 28.3 → 29.0 25.7 → 26.6 1.03 (0.95–1.11) 1.04 (0.97–1.12)
4 writers, twin views (aliased) 30.2 → 30.4 56.4 → 55.8 40.1 → 38.8 1.01 (0.93–1.18) 1.00 (0.92–1.19)
4 writers, copies armed (first writes save the page) 43.2 → 41.7 145.3 → 136.0 119.4 → 111.1 0.99 (0.93–1.04) 1.00 (0.92–1.03)

Reading. No measurable change in any config (paired ratios 0.97–1.05, quartiles straddling 1). Expected for this workload: the bench's faults are single-page writes, and a run of one page is still one VirtualProtect; the runs this PR batches come from writing() ranges and tracker drops, which your own benchmark_guard_open_runs covers and this one doesn't. So: no regression on the fault/take contention path, and no gain there either.

Correctness. refreshes_under_writes_lose_nothing passes on this head (3 × 1,000 rounds), as do the existing watch:: tests including your two new ones.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7218535611 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2849#issuecomment-7218535611). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T12:40:23Z. --- Contention numbers for this PR from a shared benchmark (for #3425). **Method.** The benchmark `guard_contention` and the check `refreshes_under_writes_lose_nothing` from #3516, split out as a standalone test-only commit ([KainanP/VIctory `perf/guard-bench`](https://github.com/KainanP/VIctory/commit/ab96ee44e6bf35ec1dc5cd97c0f059797950b2e8): no behaviour change, `guards()` only times a lock it finds taken in test builds), applied unchanged to this PR's head (`7b1316a`) and to `main` (`63bcca4`). 256 MB write-watched pool in 64 KiB pages, copies of 32 pages, 1,400 pages dirtied before each refresh, title threads writing a random word every 20 µs while the copies are taken and copied. Release builds, i7-14650HX (24 threads), Windows 11. 31 rounds, builds interleaved and rotated each round, each run = median of 5 refreshes after a warm-up; table = medians over the 31 runs, plus the median (and quartiles) of the per-round PR/main ratio. Foreign load: other agents' `rustc` jobs were running (≈8 % of the CPU in a spot sample); the paired ratio is what to read. | Config | Refresh ms (main → PR) | Writers in their writes, ms | Writers waiting for `GUARDS`, ms | PR/main, writes | PR/main, wait | |---|---|---|---|---|---| | 1 writer | 17.4 → 17.2 | 5.1 → 5.1 | 2.8 → 2.7 | 1.03 (0.90–1.15) | 0.97 (0.92–1.10) | | 4 writers | 29.1 → 32.0 | 37.8 → 40.8 | 24.3 → 26.2 | 1.05 (0.95–1.08) | 1.02 (0.97–1.10) | | 4 writers, refresh on 4 threads | 9.2 → 9.4 | 28.3 → 29.0 | 25.7 → 26.6 | 1.03 (0.95–1.11) | 1.04 (0.97–1.12) | | 4 writers, twin views (aliased) | 30.2 → 30.4 | 56.4 → 55.8 | 40.1 → 38.8 | 1.01 (0.93–1.18) | 1.00 (0.92–1.19) | | 4 writers, copies armed (first writes save the page) | 43.2 → 41.7 | 145.3 → 136.0 | 119.4 → 111.1 | 0.99 (0.93–1.04) | 1.00 (0.92–1.03) | **Reading.** No measurable change in any config (paired ratios 0.97–1.05, quartiles straddling 1). Expected for this workload: the bench's faults are single-page writes, and a run of one page is still one `VirtualProtect`; the runs this PR batches come from `writing()` ranges and tracker drops, which your own `benchmark_guard_open_runs` covers and this one doesn't. So: no regression on the fault/take contention path, and no gain there either. **Correctness.** `refreshes_under_writes_lose_nothing` passes on this head (3 × 1,000 rounds), as do the existing `watch::` tests including your two new ones. _AI use: Claude Code (Claude Opus 5.5)._
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/2849:upstream-pr/2849'
git switch 'upstream-pr/2849'

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/2849'
git switch 'upstream-pr/2849'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2849'
git switch 'upstream-pr/2849'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2849'
git switch 'main'
git merge --squash 'upstream-pr/2849'
git switch 'main'
git merge --ff-only 'upstream-pr/2849'
git switch 'main'
git merge 'upstream-pr/2849'
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!2847
No description provided.