GPU: attribute the copy term's VirtualQuery work (FIND-49) #3429

Open
Jackster wants to merge 1 commit from upstream-pr/3429 into main
Jackster commented 2026-11-27 01:27:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-27T01:27:44Z.


What

The frame line already prints the copy term's pieces — copies … MB, runs … ms, queries … ms, moves … ms, watch time: … protecting, snapshots … MB in … ms — but C::Queries / C::QueryUs were never incremented, so the "queries" column was always zero. With borosf's measurement on FIND-49 (the ~927 ms copy term is per-page bookkeeping, not the kernel copy), that left MoveUs, watch time and snapshots attributable and the VirtualQuery work invisible.

This wires the two VirtualQuery walks into QueryUs:

  • host.rs copy_mapped: the committed() check on a title destination.
  • watch.rs protect_noting: the unmapped(page) query. It nests inside ProtectUs, which the frame line also prints; the comment says so, and the two mean different things (per-query cost vs the whole protect loop).

Plus copystat::get under cfg(test) and one regression test.

Why

FIND-49 asks for exactly this: "Anyone optimizing that term should attribute it on the frame line (copystat MoveUs vs QueryUs vs SnapshotUs vs WatchUs) before writing code." There is no behaviour change, and copystat is behind feature = "diagnostics", so a release build pays nothing.

Testing (Windows 11, Radeon RX 7900 XTX)

  • cargo test -p victory-gpu --lib --features diagnostics: 247 passed / 0 failed / 1 ignored
  • cargo test -p victory-gpu --lib (no feature): 231 passed / 0 failed / 1 ignored — the plain build is unchanged
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test --workspace --locked: 872 passed / 0 failed (the new test is diagnostics-gated, so the default run is unchanged)

Control: with the two lines removed from protect_noting, watch::tests::a_virtual_query_on_an_unprotectable_page_is_counted fails with its own message ("the unprotectable page's VirtualQuery is attributed to queries").

Synthetic only, no game data. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5519589371 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3429). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-27T01:27:44Z. --- ## What The frame line already prints the copy term's pieces — `copies … MB`, `runs … ms`, `queries … ms`, `moves … ms`, `watch time: … protecting`, `snapshots … MB in … ms` — but `C::Queries` / `C::QueryUs` were **never incremented**, so the "queries" column was always zero. With borosf's measurement on FIND-49 (the ~927 ms copy term is per-page bookkeeping, not the kernel copy), that left `MoveUs`, watch time and snapshots attributable and the `VirtualQuery` work invisible. This wires the two `VirtualQuery` walks into `QueryUs`: - `host.rs` `copy_mapped`: the `committed()` check on a title destination. - `watch.rs` `protect_noting`: the `unmapped(page)` query. It nests inside `ProtectUs`, which the frame line also prints; the comment says so, and the two mean different things (per-query cost vs the whole protect loop). Plus `copystat::get` under `cfg(test)` and one regression test. ## Why FIND-49 asks for exactly this: "Anyone optimizing that term should attribute it on the frame line (copystat MoveUs vs QueryUs vs SnapshotUs vs WatchUs) before writing code." There is no behaviour change, and `copystat` is behind `feature = "diagnostics"`, so a release build pays nothing. ## Testing (Windows 11, Radeon RX 7900 XTX) - `cargo test -p victory-gpu --lib --features diagnostics`: **247 passed / 0 failed / 1 ignored** - `cargo test -p victory-gpu --lib` (no feature): **231 passed / 0 failed / 1 ignored** — the plain build is unchanged - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test --workspace --locked`: 872 passed / 0 failed (the new test is diagnostics-gated, so the default run is unchanged) Control: with the two lines removed from `protect_noting`, `watch::tests::a_virtual_query_on_an_unprotectable_page_is_counted` fails with its own message ("the unprotectable page's VirtualQuery is attributed to queries"). Synthetic only, no game data. AI-assisted.
fuzeofficlal commented 2026-11-27 01:50:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:50:18Z.

Review: APPROVED


Looks good. Both copy-path VirtualQuery sites (crates/victory-gpu/src/host.rs:2515-2517 around texture::committed in copy_mapped and crates/victory-gpu/src/watch.rs:668-670 in protect_noting's unmapped check) are cleanly attributed to the existing C::Queries and C::QueryUs counters without double-counting, and #[cfg(feature = "diagnostics")] gating keeps non-diagnostics builds warning-free.

Verified on commit f7481f4669e6b6efcdf7c4b72e744e5dbb7deebd:

  • cargo xtask policy passed (191 files ok).
  • cargo clippy -p victory-gpu passed cleanly with -D warnings across all four configurations (--lib, --tests, --features diagnostics --lib, and --features diagnostics --tests).
  • watch::tests passed 15/15 (default) and 16/16 (--features diagnostics, including a_virtual_query_on_an_unprotectable_page_is_counted) on both an NVIDIA RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1).
<!-- greyfinch-sync:Marvisak/VIctory:review:6082437145 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3429#pullrequestreview-6082437145). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T01:50:18Z. **Review:** APPROVED --- Looks good. Both copy-path `VirtualQuery` sites (`crates/victory-gpu/src/host.rs:2515-2517` around `texture::committed` in `copy_mapped` and `crates/victory-gpu/src/watch.rs:668-670` in `protect_noting`'s `unmapped` check) are cleanly attributed to the existing `C::Queries` and `C::QueryUs` counters without double-counting, and `#[cfg(feature = "diagnostics")]` gating keeps non-diagnostics builds warning-free. Verified on commit `f7481f4669e6b6efcdf7c4b72e744e5dbb7deebd`: - `cargo xtask policy` passed (`191 files ok`). - `cargo clippy -p victory-gpu` passed cleanly with `-D warnings` across all four configurations (`--lib`, `--tests`, `--features diagnostics --lib`, and `--features diagnostics --tests`). - `watch::tests` passed 15/15 (default) and 16/16 (`--features diagnostics`, including `a_virtual_query_on_an_unprotectable_page_is_counted`) on both an NVIDIA RTX 5090 and WARP (`VICTORY_D3D12_DEBUG=1`).
Dukestar69 commented 2026-11-27 01:52:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T01:52:09Z.

Review: APPROVED


LGTM — verified on Windows:

  • cargo test -p victory-gpu --lib watch:: passed (15/15 default; 16/16 with --features diagnostics, including a_virtual_query_on_an_unprotectable_page_is_counted)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings and --features diagnostics --all-targets -- -D warnings both passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6082452365 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3429#pullrequestreview-6082452365). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T01:52:09Z. **Review:** APPROVED --- LGTM — verified on Windows: - `cargo test -p victory-gpu --lib watch::` passed (15/15 default; 16/16 with `--features diagnostics`, including `a_virtual_query_on_an_unprotectable_page_is_counted`) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` and `--features diagnostics --all-targets -- -D warnings` both passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (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/3429:upstream-pr/3429'
git switch 'upstream-pr/3429'

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