Skip to content

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

Closed
0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/copy-heat
Closed

0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/copy-heat

Conversation

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor

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.

Related

…o memory would save

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 (Marvisak#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.

@kotekompotek kotekompotek 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.

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 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.

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.

0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
With Marvisak#2721 and Marvisak#2051: the list keeps both the frame budget's timing and the heat's uses, and each parallel refresh reports its copied bytes to the heat.

Copy link
Copy Markdown
Owner

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

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

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 0xkn0wh3r3 closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants