GPU: a frame line says how many copy calls the refresh made, and note_use stops allocating #3212

Closed
borosf wants to merge 2 commits from upstream-pr/3214 into main
borosf commented 2026-11-26 13:15:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T13:15:33Z.


Summary

  • A frame line now says how many copy calls the refresh made, not only how many bytes. The world's copy term is published as "copies into host buffers: 927 ms of a 1,842 ms frame, 265 MB" (#407) with "97 % of 10.4 GB of checked ranges unchanged". Those bytes are either ~4,240 whole-page copies or ~135,000 small copies, and on this card the two cost very different totals: a 64 KiB page through ReadProcessMemory is 7.99 µs, a 4 KiB run is 2.39 µs (measured here). The fixes are different too — sub-page dirty extents versus fewer/larger calls — so the split has to be readable before either is written. RefreshCalls counts the copy calls the refresh made: one per run of pages the tracker brought back (Shadow::update_tracked), one per stretch of untracked memory copied whole (Shadow::update_untracked). It prints next to the bytes checked and unchanged, so bytes / calls is the average call size.
  • memory::note_use stops allocating. It runs once per stage of every draw whose shader reads title memory — thousands of times a frame in the world — and named its pipeline with to_owned() on every call: a String heap allocation and free per stage for a key that is almost always already in the map. It now looks the key up first and only names a pipeline the first time one is seen. Same counts, same title memory this frame: … line.

Verification

Intel Arc B580, Windows 11, -p victory-gpu:

  • cargo test -p victory-gpu --lib --features diagnostics --locked -- --test-threads=1 → 244 passed, 2 failed, 1 ignored. The two failures are the known Intel heap-cap pair (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views — #1744/#1829) that pristine main 63bcca4 also fails on this card.
  • The counter's wiring was checked against a real refresh, not just compilation: a registered copy's Shadow::update was observed to raise RefreshCalls, and the probe was then removed (the diff touches three files, +21/−4).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings clean on both feature sets.
  • cargo xtask policy → 193 files ok.

No game data used; synthetic tests only.

The note_use saving is modelled from call rate × (mutex + allocation) cost, not measured: that needs a world frame, which needs the title. The counter is what makes the larger decision measurable on the first run anyone has.

claiming: GPU diagnostics: count the copy calls a submission's refresh makes (RefreshCalls on the frame line) beside the bytes, so a frame's copy cost can be told apart as bytes or as calls; and stop memory::note_use allocating a String per stage per draw

<!-- greyfinch-sync:Marvisak/VIctory:issue:5510705738 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3214). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T13:15:33Z. --- ## Summary - **A frame line now says how many copy calls the refresh made, not only how many bytes.** The world's copy term is published as "copies into host buffers: 927 ms of a 1,842 ms frame, 265 MB" (#407) with "97 % of 10.4 GB of checked ranges unchanged". Those bytes are either **~4,240 whole-page copies** or **~135,000 small copies**, and on this card the two cost very different totals: a 64 KiB page through `ReadProcessMemory` is 7.99 µs, a 4 KiB run is 2.39 µs (measured here). The fixes are different too — sub-page dirty extents versus fewer/larger calls — so the split has to be readable before either is written. `RefreshCalls` counts the copy calls the refresh made: one per run of pages the tracker brought back (`Shadow::update_tracked`), one per stretch of untracked memory copied whole (`Shadow::update_untracked`). It prints next to the bytes checked and unchanged, so `bytes / calls` is the average call size. - **`memory::note_use` stops allocating.** It runs once per stage of every draw whose shader reads title memory — thousands of times a frame in the world — and named its pipeline with `to_owned()` on *every* call: a `String` heap allocation and free per stage for a key that is almost always already in the map. It now looks the key up first and only names a pipeline the first time one is seen. Same counts, same `title memory this frame: …` line. ## Verification Intel Arc B580, Windows 11, `-p victory-gpu`: - `cargo test -p victory-gpu --lib --features diagnostics --locked -- --test-threads=1` → **244 passed, 2 failed, 1 ignored**. The two failures are the known Intel heap-cap pair (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views` — #1744/#1829) that pristine `main` `63bcca4` also fails on this card. - The counter's wiring was checked against a real refresh, not just compilation: a registered copy's `Shadow::update` was observed to raise `RefreshCalls`, and the probe was then removed (the diff touches three files, +21/−4). - `cargo clippy -p victory-gpu --all-targets -- -D warnings` clean on both feature sets. - `cargo xtask policy` → 193 files ok. No game data used; synthetic tests only. The `note_use` saving is modelled from call rate × (mutex + allocation) cost, not measured: that needs a world frame, which needs the title. The counter is what makes the larger decision measurable on the first run anyone has. claiming: GPU diagnostics: count the copy calls a submission's refresh makes (RefreshCalls on the frame line) beside the bytes, so a frame's copy cost can be told apart as bytes or as calls; and stop `memory::note_use` allocating a String per stage per draw
Dukestar69 commented 2026-11-26 13:28:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:28:24Z.

Review: APPROVED


Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 10/10 passed; draw::: 20/20 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings & --features diagnostics: clean.
  • cargo xtask policy: 191 files ok.

Cleanly reports refresh copy call counts and avoids allocating in note_use.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6074951459 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3214#pullrequestreview-6074951459). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T13:28:24Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: 10/10 passed; `draw::`: 20/20 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` & `--features diagnostics`: clean. - `cargo xtask policy`: 191 files ok. Cleanly reports refresh copy call counts and avoids allocating in `note_use`. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
borosf commented 2026-11-26 14:01:51 +00:00 (Migrated from github.com)

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


CI note for reviewers: the check job's only failure is frame::tests::waits_end_on_ticks_and_count_frames at frame.rs:231 (left: 0, right: 1 — a wait that returned S_OK where the test expects S_FALSE).

This PR does not touch frame.rs; it changes victory-gpu/src/{copystat,memory,shadow}.rs only (3 files, +21/−4), and 230 of the job's tests passed. This is the intermittent runner-timing failure already documented in #2861 and #2877: a runner woken a little late finds the next tick has passed and the following timeout_ms = 0 poll returns S_OK instead of TIMEOUT. Both Clippy steps — plain and the diagnostics build — passed, which is what this change needed to prove.

Not re-running from here; leaving that to whoever triages, since a re-run can fail the same way on a loaded runner.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193239240 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3214#issuecomment-7193239240). Originally posted by [borosf](https://github.com/borosf) on 2026-11-26T13:21:37Z. --- CI note for reviewers: the `check` job's only failure is `frame::tests::waits_end_on_ticks_and_count_frames` at `frame.rs:231` (`left: 0`, `right: 1` — a wait that returned `S_OK` where the test expects `S_FALSE`). This PR does not touch `frame.rs`; it changes `victory-gpu/src/{copystat,memory,shadow}.rs` only (3 files, +21/−4), and 230 of the job's tests passed. This is the intermittent runner-timing failure already documented in #2861 and #2877: a runner woken a little late finds the next tick has passed and the following `timeout_ms = 0` poll returns `S_OK` instead of `TIMEOUT`. Both Clippy steps — plain and the diagnostics build — passed, which is what this change needed to prove. Not re-running from here; leaving that to whoever triages, since a re-run can fail the same way on a loaded runner.
borosf commented 2026-11-27 13:20:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T13:20:29Z.


Closing this and keeping #3238 for the same ground, so the two do not collide.

The note_use rewrite here (memory.rs:302-316) is superseded by #3238, which makes the diagnostics map itself diagnostics-only — no lock, no String, no BTreeMap in release — where this version still takes STATS's mutex in a release build for a map nothing prints.

The RefreshCalls half is worth having, but as written it undercounts: shadow.rs:663-674 copies each untracked stretch whole while only update_untracked (shadow.rs:678) adds RefreshCalls, so bytes/calls overstates the average call size exactly for the stretches the comment says it counts. And whichever of this, #3224 and #3233 lands first, the others conflict on const COUNTERS and the single frame-line literal.

I will re-offer RefreshCalls on its own once the counter block stops being a three-way collision, with the untracked path counted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7219358462 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3214#issuecomment-7219358462). Originally posted by [borosf](https://github.com/borosf) on 2026-11-27T13:20:29Z. --- Closing this and keeping #3238 for the same ground, so the two do not collide. The `note_use` rewrite here (`memory.rs:302-316`) is superseded by #3238, which makes the diagnostics map itself diagnostics-only — no lock, no `String`, no `BTreeMap` in release — where this version still takes `STATS`'s mutex in a release build for a map nothing prints. The `RefreshCalls` half is worth having, but as written it undercounts: `shadow.rs:663-674` copies each untracked stretch whole while only `update_untracked` (`shadow.rs:678`) adds `RefreshCalls`, so `bytes/calls` overstates the average call size exactly for the stretches the comment says it counts. And whichever of this, #3224 and #3233 lands first, the others conflict on `const COUNTERS` and the single frame-line literal. I will re-offer `RefreshCalls` on its own once the counter block stops being a three-way collision, with the untracked path counted.

Pull request closed

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!3212
No description provided.