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

Closed
github-bot wants to merge 1 commit from github-bot/gh-2929 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 00:19 UTC · original
0xkn0wh3r3:gpu/copy-heat → main · +311 −7 · 5 files · 1 commits · closed without merging

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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 00:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2929) `0xkn0wh3r3:gpu/copy-heat` → `main` · +311 −7 · 5 files · 1 commits · closed without merging ### 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.
Host copies of title memory live in system memory, so every shader access
crosses the bus on a discrete GPU. To choose what belongs in video memory,
victory_gpu::heat counts per copy (title start, length), since the last
frame-rate line:
- GPU time: with per-command timing (VICTORY_GPU_TIMING and
  VICTORY_D3D12_DRED), each command's time split over the copies it binds,
  by bytes. Commands reading heap views or title memory by address are
  counted as rows of their own.
- bytes copied in by refreshes;
- bytes copied back.

The line lists the copies by estimated gain: GPU time x (1 - 1/20), less
moving the changed bytes at 28.7 GB/s. Both constants come from synthetic
measurements on an RTX 5070 Ti (#2912). It ranks and moves nothing.
Diagnostics builds only.

HostList::slowest now builds on a new command_times, which gives each
command's time in order.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:45 +00:00
github-bot closed this pull request 2026-11-26 08:07:36 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 00:27 UTC · original · reviewed

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.

**@⁠kotekompotek** on GitHub · 2026-11-26 00:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2929#pullrequestreview-6066903767) · **reviewed** 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:28 UTC · original · reviewed

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2929#pullrequestreview-6066910719) · **reviewed** 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:25 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 04:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2929#issuecomment-7182579648) <!-- 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)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 08:05 UTC · original

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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 08:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2929#issuecomment-7186179708) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2929
No description provided.