Skip to content

GPU: collect tracked page runs without temporary trees - #3387

Open
Desamodeth wants to merge 1 commit into
Marvisak:mainfrom
Desamodeth:perf/watch-runtime-page-runs
Open

Desamodeth wants to merge 1 commit into
Marvisak:mainfrom
Desamodeth:perf/watch-runtime-page-runs

Conversation

@Desamodeth

Copy link
Copy Markdown

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.

Emit eligible pages directly during the ordered region walk. A foreign region excludes every overlapping page, including partial edges.

AI-assisted-by: Codex Astra 6.2 High

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants