GPU (diagnostics): the frame-rate line ranks host copies by what video memory would save #2927

Closed
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/2929 into main
0xkn0wh3r3 commented 2026-11-26 00:19:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T00:19:13Z.


Problem

Host copies of title memory are in system memory (Host::shared_buffer), so on a discrete GPU every shader access crosses the bus. Synthetic measurements on an RTX 5070 Ti (#2912's uma_bench) put video memory at:

  • 30× faster for linear reads;
  • 300× faster for scattered 64-byte lines;
  • 12–18× faster for scattered writes and atomics.

The placement PRs choose copies by other criteria:

Nothing on main says which copies a frame actually spends its GPU time on, or how many of their bytes change every frame. Moving a copy that changes every frame costs a copy up and a copy down.

What this adds (diagnostics builds; moves nothing)

crate::heat counts per host copy (title start, length) since the last frame-rate line:

  • GPU time: with per-command timing (VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1), each command's time is split over the copies it binds, by bytes bound.
    • A command's copies are the refreshes it asks for (HostList::defer_refresh, recorded with the index of the command that follows).
    • Commands that take views from the heap itself (defer_heap), or reach title memory at computed addresses (defer_memory), may read any copy. They are counted as two rows of their own.
  • bytes copied in: refreshes (Batch::flush);
  • bytes copied back: snapshot copy-back, marked pages, and pages written at computed addresses.

The frame-rate line gains:

host copies per frame: 214 used, 31.0 ms of GPU time bound to them, 4.1 ms in 12 commands reading heap views, ...;
by gain: 0x...+0x...: GPU 9.80 ms in 40 commands, in 0.0 MB, back 0.1 MB, -9.30 ms in video memory; ...

That example shows the format only; it is not a measurement.

The estimate per copy is GPU time × (1 − 1/20), less (bytes in + bytes back) / 28.7 GB/s:

  • 20 is the low end of the measured speedups;
  • 28.7 GB/s is the measured GPU copy rate between system and video memory, the same for separate 64 KiB pages.

The rows are ranked by that estimate. #2734's resident copies, or #2130's, can then be chosen by it. The heat-based placement itself would be a later PR.

HostList::slowest now builds on a new command_times, which gives each command's time in order.

Tests

  • heat::tests::a_command_s_time_is_split_by_the_bytes_it_binds: splitting by bytes, the heap row, and commands past the timed ones.

  • heat::tests::copies_rank_by_what_video_memory_would_save: a read-only copy ranks before an equally read copy rewritten whole every frame, and a barely read copy comes last. Also covers the totals and the heap row.

  • I traced the counters through the existing GPU tests in a diagnostics build. Refresh and copy-back bytes reach the right copies.

    GPU-time attribution is covered only by the unit test: no existing test runs a translated dispatch through State with bound copies and command notes. It needs a run with the switches above.

  • Workspace clippy (both configurations) is clean.

  • victory-gpu lib tests, normal build: 233 passed, 2 failed. The failures, dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, also fail on clean main on this machine.

  • Diagnostics build: host::present_plane_tests::compositor_failure_presents_primary_in_the_same_frame exits the test process (code 2173) on clean main as well.

  • #2912: detection of unified memory. On a unified host there is nothing to promote.
  • #2921: release of title memory held in place.
  • #2734 / #2130 / #2870: placements that could rank by this.
  • #2721: the slow-frame report. This is the per-copy view under the same timing.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6616556711 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2929). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T00:19:13Z. --- ### Problem Host copies of title memory are in system memory (`Host::shared_buffer`), so on a discrete GPU every shader access crosses the bus. Synthetic measurements on an RTX 5070 Ti (#2912's `uma_bench`) put video memory at: - 30× faster for linear reads; - 300× faster for scattered 64-byte lines; - 12–18× faster for scattered writes and atomics. The placement PRs choose copies by other criteria: - #2120 / #2130 / #2870: by the buffer's UAV flag; - #2734: by size. Nothing on main says which copies a frame actually spends its GPU time on, or how many of their bytes change every frame. Moving a copy that changes every frame costs a copy up and a copy down. ### What this adds (diagnostics builds; moves nothing) `crate::heat` counts per host copy (title start, length) since the last frame-rate line: - **GPU time**: with per-command timing (`VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1`), each command's time is split over the copies it binds, by bytes bound. - A command's copies are the refreshes it asks for (`HostList::defer_refresh`, recorded with the index of the command that follows). - Commands that take views from the heap itself (`defer_heap`), or reach title memory at computed addresses (`defer_memory`), may read any copy. They are counted as two rows of their own. - **bytes copied in**: refreshes (`Batch::flush`); - **bytes copied back**: snapshot copy-back, marked pages, and pages written at computed addresses. The frame-rate line gains: ``` host copies per frame: 214 used, 31.0 ms of GPU time bound to them, 4.1 ms in 12 commands reading heap views, ...; by gain: 0x...+0x...: GPU 9.80 ms in 40 commands, in 0.0 MB, back 0.1 MB, -9.30 ms in video memory; ... ``` That example shows the format only; it is not a measurement. The estimate per copy is GPU time × (1 − 1/20), less (bytes in + bytes back) / 28.7 GB/s: - 20 is the low end of the measured speedups; - 28.7 GB/s is the measured GPU copy rate between system and video memory, the same for separate 64 KiB pages. The rows are ranked by that estimate. #2734's resident copies, or #2130's, can then be chosen by it. The heat-based placement itself would be a later PR. `HostList::slowest` now builds on a new `command_times`, which gives each command's time in order. ### Tests - `heat::tests::a_command_s_time_is_split_by_the_bytes_it_binds`: splitting by bytes, the heap row, and commands past the timed ones. - `heat::tests::copies_rank_by_what_video_memory_would_save`: a read-only copy ranks before an equally read copy rewritten whole every frame, and a barely read copy comes last. Also covers the totals and the heap row. - I traced the counters through the existing GPU tests in a diagnostics build. Refresh and copy-back bytes reach the right copies. GPU-time attribution is covered only by the unit test: no existing test runs a translated dispatch through `State` with bound copies and command notes. It needs a run with the switches above. - Workspace clippy (both configurations) is clean. - victory-gpu lib tests, normal build: 233 passed, 2 failed. The failures, `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, also fail on clean main on this machine. - Diagnostics build: `host::present_plane_tests::compositor_failure_presents_primary_in_the_same_frame` exits the test process (code 2173) on clean main as well. ### Related - #2912: detection of unified memory. On a unified host there is nothing to promote. - #2921: release of title memory held in place. - #2734 / #2130 / #2870: placements that could rank by this. - #2721: the slow-frame report. This is the per-copy view under the same timing.
kotekompotek commented 2026-11-26 01:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T00:27:23Z.

Review: COMMENTED


Scoped review: ranks candidates without moving anything — the safe shape for this. The accounting is honest about its limits (heap-internal view reads and computed-address reads counted as separate rows, not smeared over copies), and the constants come from the new uma_bench numbers rather than guesses. Diagnostics-only. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066903767 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2929#pullrequestreview-6066903767). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T00:27:23Z. **Review:** COMMENTED --- Scoped review: ranks candidates without moving anything — the safe shape for this. The accounting is honest about its limits (heap-internal view reads and computed-address reads counted as separate rows, not smeared over copies), and the constants come from the new uma_bench numbers rather than guesses. Diagnostics-only. LGTM.
fuzeofficlal commented 2026-11-26 01:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:28:25Z.

Review: COMMENTED


Verified head 2087d734 cleanly on origin/main (63bcca43) on Windows 11 x64.

Code Review

  • All heat.rs plumbing and call sites are cleanly gated behind #[cfg(feature = "diagnostics")], leaving default non-diagnostics builds with zero overhead.
  • HostList::note_use only records when both dred_on() and timing() are active, and heat::log moves the map out under HEAT.lock().take() before sorting and formatting so the lock is never held across sorting/logging.

Local Verification

  • Default build (shadow::tests): 9/9 passed.
  • --features diagnostics (heat:: + shadow::tests + host::tests non-descriptor): 23/23 passed (including a_command_s_time_is_split_by_the_bytes_it_binds and copies_rank_by_what_video_memory_would_save).
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings (default and --features diagnostics) & cargo xtask policy (192 files ok): clean.

Looks clean and ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066910719 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2929#pullrequestreview-6066910719). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:28:25Z. **Review:** COMMENTED --- Verified head `2087d734` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64. ### Code Review - All `heat.rs` plumbing and call sites are cleanly gated behind `#[cfg(feature = "diagnostics")]`, leaving default non-diagnostics builds with zero overhead. - `HostList::note_use` only records when both `dred_on()` and `timing()` are active, and `heat::log` moves the map out under `HEAT.lock().take()` before sorting and formatting so the lock is never held across sorting/logging. ### Local Verification - Default build (`shadow::tests`): **9/9 passed**. - `--features diagnostics` (`heat::` + `shadow::tests` + `host::tests` non-descriptor): **23/23 passed** (including `a_command_s_time_is_split_by_the_bytes_it_binds` and `copies_rank_by_what_video_memory_would_save`). - `cargo clippy --locked -p victory-gpu --tests -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`192 files ok`): clean. Looks clean and ready to merge.
Marvisak commented 2026-11-26 05:04:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:25:16Z.


Automated triage for the maintainers.

Merge candidate. Adds a diagnostics-only report (victory-gpu/src/heat.rs) ranking host copies of title memory by what moving them to video memory might save, from per-command GPU time (HostList::command_times, split out of slowest without behaviour change), bytes refreshed and bytes copied back; it is all behind cfg(feature = "diagnostics"). note_use attributes a refresh to the next noted command, which is right for the draw and dispatch paths in draw.rs; a barrier note recorded between binding and the draw would take that time instead, and commands double-counts when one command binds two ranges of one copy. Both are minor for a ranking aid.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182579648 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2929#issuecomment-7182579648). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:25:16Z. --- <!-- victory-triage v1 head=2087d7340acae68f73559306156c6678187880c0 verdict=merge-candidate at=2026-11-26T04:25:08Z --> Automated triage for the maintainers. **Merge candidate.** Adds a diagnostics-only report (`victory-gpu/src/heat.rs`) ranking host copies of title memory by what moving them to video memory might save, from per-command GPU time (`HostList::command_times`, split out of `slowest` without behaviour change), bytes refreshed and bytes copied back; it is all behind `cfg(feature = "diagnostics")`. `note_use` attributes a refresh to the next noted command, which is right for the draw and dispatch paths in `draw.rs`; a barrier note recorded between binding and the draw would take that time instead, and `commands` double-counts when one command binds two ranges of one copy. Both are minor for a ranking aid. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-26 09:05:27 +00:00
0xkn0wh3r3 commented 2026-11-26 09:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T08:05:45Z.


Replaced by #3102, which combines this with the rest of the host-memory placement work in one PR, with measurements on a discrete and an integrated GPU. Closing here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186179708 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2929#issuecomment-7186179708). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T08:05:45Z. --- Replaced by #3102, which combines this with the rest of the host-memory placement work in one PR, with measurements on a discrete and an integrated GPU. Closing here.

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