GPU: collect tracked page runs without temporary trees #3387

Open
Desamodeth wants to merge 1 commit from upstream-pr/3387 into main
Desamodeth commented 2026-11-26 21:23:12 +00:00 (Migrated from github.com)

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


The fallback in watch::runtime_pages inserted each 64 KiB page into a temporary BTreeSet of eligible or foreign pages, then took their difference. Even a range consisting entirely of ordinary committed memory allocated tree nodes to return an empty vector. This follows borosf's measurement of the cost of building those sets. Original finding · Coordination claim.

Walk the VirtualQuery regions in address order. When a foreign region appears, emit the eligible run before its first page and resume after its last page. A 4 KiB foreign region therefore excludes its entire overlapping 64 KiB page. The final run ends at the last successfully queried region. The Windows queries, classification predicate, write-watched fast path and caller are unchanged.

CPU measurements

Median µs per call to runtime_pages, base 63bcca43 vs this patch. The range of medians is from two runs in opposite order.

Synthetic Windows mapping Base Patched Heap allocations per call, base → patched
64 MiB ordinary private committed memory, views disabled 22.9–24.8 1.4–1.5 171 → 0
64 MiB mixed reservation, views enabled 110.5–113.5 83.8–86.3 177 → 7
64 MiB write-watched allocation, views disabled 13.0–13.4 13.1–13.4 1 → 1

Windows x64, Ryzen 7 9800X3D, rustc 1.98.1, -C opt-level=3. The isolated benchmark called the old and new functions on the same native VirtualAlloc mapping, alternating order and taking 21 samples per variant after two warm-ups. For the mixed case, reserve 64 MiB, then commit one 4 KiB block at offset i * 65536 + 4096 for i = 1, 33, 65, …. Both versions return the same 992 page numbers. Allocation counts came from a separate counting-allocator build. These measurements cover page classification only.

Correctness

  • Added a Windows regression for an ordinary 4 KiB committed block inside a 64 KiB page. Checks both sides of the block, partially covered end pages and both values of views.
  • Compared both implementations with an independent page-membership oracle on 3,200 range/mode combinations over a real mixed Windows reservation.
  • All 16 victory-gpu watch tests passed on Windows. Workspace Clippy passed for all targets with default and all features, with warnings denied. cargo xtask policy passed (191 files).

AI-assisted with Codex. No game data or GPU used for local verification.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5517317376 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3387). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-26T21:23:12Z. --- The fallback in `watch::runtime_pages` inserted each 64 KiB page into a temporary `BTreeSet` of eligible or foreign pages, then took their difference. Even a range consisting entirely of ordinary committed memory allocated tree nodes to return an empty vector. This follows borosf's measurement of the cost of building those sets. [Original finding](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7202084116) · [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7203533817). Walk the `VirtualQuery` regions in address order. When a foreign region appears, emit the eligible run before its first page and resume after its last page. A 4 KiB foreign region therefore excludes its entire overlapping 64 KiB page. The final run ends at the last successfully queried region. The Windows queries, classification predicate, write-watched fast path and caller are unchanged. ### CPU measurements Median µs per call to `runtime_pages`, base `63bcca43` vs this patch. The range of medians is from two runs in opposite order. | Synthetic Windows mapping | Base | Patched | Heap allocations per call, base → patched | |---|---:|---:|---:| | 64 MiB ordinary private committed memory, views disabled | 22.9–24.8 | 1.4–1.5 | 171 → 0 | | 64 MiB mixed reservation, views enabled | 110.5–113.5 | 83.8–86.3 | 177 → 7 | | 64 MiB write-watched allocation, views disabled | 13.0–13.4 | 13.1–13.4 | 1 → 1 | Windows x64, Ryzen 7 9800X3D, rustc 1.98.1, `-C opt-level=3`. The isolated benchmark called the old and new functions on the same native `VirtualAlloc` mapping, alternating order and taking 21 samples per variant after two warm-ups. For the mixed case, reserve 64 MiB, then commit one 4 KiB block at offset `i * 65536 + 4096` for `i = 1, 33, 65, …`. Both versions return the same 992 page numbers. Allocation counts came from a separate counting-allocator build. These measurements cover page classification only. ### Correctness - Added a Windows regression for an ordinary 4 KiB committed block inside a 64 KiB page. Checks both sides of the block, partially covered end pages and both values of `views`. - Compared both implementations with an independent page-membership oracle on 3,200 range/mode combinations over a real mixed Windows reservation. - All 16 `victory-gpu` watch tests passed on Windows. Workspace Clippy passed for all targets with default and all features, with warnings denied. `cargo xtask policy` passed (191 files). AI-assisted with Codex. No game data or GPU used for local verification.
Dukestar69 commented 2026-11-26 21:27:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T21:27:51Z.

Review: APPROVED


LGTM — verified on Windows against origin/main (63bcca4).

  • Collecting tracked page runs without temporary trees cleanly reduces allocation overhead while still excluding pages split by private regions.
  • cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 16 passed, 0 failed (including runtime_pages_excludes_a_page_split_by_a_private_region).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6080635426 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3387#pullrequestreview-6080635426). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T21:27:51Z. **Review:** APPROVED --- LGTM — verified on Windows against `origin/main` (`63bcca4`). - Collecting tracked page runs without temporary trees cleanly reduces allocation overhead while still excluding pages split by private regions. - `cargo test -p victory-gpu --lib watch:: -- --test-threads=1`: 16 passed, 0 failed (including `runtime_pages_excludes_a_page_split_by_a_private_region`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 21:51:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:51:19Z.

Review: APPROVED


Clean replacement that preserves exact equivalence with the previous BTreeSet::difference logic while avoiding temporary tree allocations.

Checked all boundary cases in runtime_pages (crates/victory-gpu/src/watch.rs:382-423): split 64 KiB pages containing one or more 4 KiB foreign regions, back-to-back foreign regions (run_start > at / PAGE safely yields an empty range), unaligned start/end, and early VirtualQuery == 0 termination on either the first or a later iteration (scanned_end tracks only queried regions).

Verification on origin/main (63bcca43):

  • cargo xtask policy: ok (191 files ok)
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics): clean
  • cargo test --locked -p victory-gpu --features diagnostics -- watch::tests:: --test-threads=1: 16/16 passed on RTX 5090 and 16/16 passed on WARP (including runtime_pages_excludes_a_page_split_by_a_private_region)
  • Additional 2,000-case randomized differential oracle comparing the previous BTreeSet::difference implementation against the new run accumulator (including unaligned ranges, mixed 4 KiB sub-page regions, and simulated VirtualQuery == 0 early breaks): 2,000/2,000 matched identically.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080875604 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3387#pullrequestreview-6080875604). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T21:51:19Z. **Review:** APPROVED --- Clean replacement that preserves exact equivalence with the previous `BTreeSet::difference` logic while avoiding temporary tree allocations. Checked all boundary cases in `runtime_pages` (`crates/victory-gpu/src/watch.rs:382-423`): split 64 KiB pages containing one or more 4 KiB foreign regions, back-to-back foreign regions (`run_start > at / PAGE` safely yields an empty range), unaligned `start`/`end`, and early `VirtualQuery == 0` termination on either the first or a later iteration (`scanned_end` tracks only queried regions). Verification on `origin/main` (`63bcca43`): - `cargo xtask policy`: ok (`191 files ok`) - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`): clean - `cargo test --locked -p victory-gpu --features diagnostics -- watch::tests:: --test-threads=1`: 16/16 passed on RTX 5090 and 16/16 passed on WARP (including `runtime_pages_excludes_a_page_split_by_a_private_region`) - Additional 2,000-case randomized differential oracle comparing the previous `BTreeSet::difference` implementation against the new run accumulator (including unaligned ranges, mixed 4 KiB sub-page regions, and simulated `VirtualQuery == 0` early breaks): 2,000/2,000 matched identically.
Jackster commented 2026-11-26 22:34:17 +00:00 (Migrated from github.com)

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


Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • watch::tests::runtime_pages_excludes_a_page_split_by_a_private_region by name: 1 passed.
  • cargo test -p victory-gpu --lib: 232 passed / 0 failed / 1 ignored (unpatched 63bcca4 here: 231).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204796582 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3387#issuecomment-7204796582). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:34:17Z. --- Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - `watch::tests::runtime_pages_excludes_a_page_split_by_a_private_region` by name: 1 passed. - `cargo test -p victory-gpu --lib`: 232 passed / 0 failed / 1 ignored (unpatched `63bcca4` here: 231). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. Synthetic only. AI-assisted.
cloph-dsp commented 2026-11-27 06:17:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T06:17:09Z.


Independent CPU-only verification of PR #3387 (Loader/GPU: keep private-region pages out of the runtime page-run list).

  • Windows, rustc/cargo 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR (D:\Victory-Contrib\target-3387-watch), CARGO_BUILD_JOBS=2.
  • Head daf761cd29bfdee9842625b0f867dcf367b52010, merge base 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • Command: cargo test --locked -p victory-gpu --lib -- watch::tests::runtime_pages_excludes_a_page_split_by_a_private_region --exact --test-threads=1 --quiet -> 1 passed; 0 failed; 232 filtered.
  • Negative control: git grep -F for the new test name on 63bcca4 returned no hits (test absent on base).
  • git diff --check 63bcca4 HEAD exit 0 (clean).
  • Only the named synthetic test was replayed; the full crate suite and real title-memory page tables were not exercised.
  • AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only synthetic page-run logic). No game data, assets, shaders, DRM or decrypt used.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7211387967 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3387#issuecomment-7211387967). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T06:17:09Z. --- Independent CPU-only verification of PR #3387 (`Loader/GPU: keep private-region pages out of the runtime page-run list`). - Windows, rustc/cargo 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR` (`D:\Victory-Contrib\target-3387-watch`), `CARGO_BUILD_JOBS=2`. - Head `daf761cd29bfdee9842625b0f867dcf367b52010`, merge base `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - Command: `cargo test --locked -p victory-gpu --lib -- watch::tests::runtime_pages_excludes_a_page_split_by_a_private_region --exact --test-threads=1 --quiet` -> `1 passed; 0 failed; 232 filtered`. - Negative control: `git grep -F` for the new test name on `63bcca4` returned no hits (test absent on base). - `git diff --check 63bcca4 HEAD` exit 0 (clean). - Only the named synthetic test was replayed; the full crate suite and real title-memory page tables were not exercised. - AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only synthetic page-run logic). No game data, assets, shaders, DRM or decrypt used.
neonbyte1 commented 2026-11-27 07:05:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T07:05:47Z.


Measured in game 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 is main plus the unmerged PRs this setup needs (#3312, #3318, #2472 and others, listed in #3425). This PR merged on top, 600 s runs, medians of the last 30 frame-rate lines, against a control run of the same base taken next to it (frame times drift by up to ~25 ms between runs hours apart).

Frame Preparing Copy-back
control 402 ms 81 ms 53 ms
+ this PR 399 ms 80 ms 53 ms

No measurable change here. Its own runtime_pages test passes under Wine.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7212138100 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3387#issuecomment-7212138100). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T07:05:47Z. --- Measured in game 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 is `main` plus the unmerged PRs this setup needs (#3312, #3318, #2472 and others, listed in #3425). This PR merged on top, 600 s runs, medians of the last 30 frame-rate lines, against a control run of the same base taken next to it (frame times drift by up to ~25 ms between runs hours apart). | | Frame | Preparing | Copy-back | |---|---|---|---| | control | 402 ms | 81 ms | 53 ms | | + this PR | 399 ms | 80 ms | 53 ms | No measurable change here. Its own `runtime_pages` test passes under Wine. _AI-assisted (Claude); measured on my machine, no game data shared._
Desamodeth commented 2026-11-30 06:34:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-30T06:34:04Z.


Handoff note: I'm stepping away from this project. This PR is clean on main (63bcca43) with green CI and 2 approvals — maintainers or other contributors are welcome to merge or take it over.

AI-assisted with Gemini 4 Neon

<!-- greyfinch-sync:Marvisak/VIctory:comment:7270780929 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3387#issuecomment-7270780929). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-30T06:34:04Z. --- **Handoff note:** I'm stepping away from this project. This PR is clean on `main` (`63bcca43`) with green CI and 2 approvals — maintainers or other contributors are welcome to merge or take it over. *AI-assisted with Gemini 4 Neon*
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/3387:upstream-pr/3387'
git switch 'upstream-pr/3387'

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