Profile: opt-in VICTORY_PROFILE (frame times, memory, caches, loads; frames.csv, a Perfetto trace and an on-screen overlay) #130

Open
Sunkiller-qc wants to merge 11 commits from upstream-pr/130 into main
Sunkiller-qc commented 2026-11-24 00:48:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T00:48:07Z.


An opt-in profiler, so performance and hang reports (#71, #16/#29) can start from aggregate numbers that anyone can collect and paste without game data. It now also covers the GPU side of #71: the worst GPU commands, dropped and zero-group work per frame, and a live log that names the command the GPU is stuck in before a TDR.

Status: rebased onto main at 70564ae. On Windows with Rust 1.98.1, cargo build and cargo clippy --all-targets are clean, both plain and with --features victory-gpu/diagnostics. cargo test passes for victory-profile (33 tests), victory-hle and victory. victory-gpu has 76 passing and 2 failing (descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views); both fail the same way on 70564ae alone. Not yet run in game against a hang.

What it does

  • Off unless a VICTORY_PROFILE* variable is set when victory run starts. When it's off, each hook costs one relaxed atomic load. It works in any build, release included.
  • VICTORY_PROFILE=1: a summary every 5 s in the log (target victory_profile):
    • frames: fps, 1% low, frame interval percentiles, hitches and stutters;
    • per frame: preparing, fence wait, present; submissions, lists, draws, dispatches; dropped commands and zero-group work;
    • memory: process memory, VRAM and shared memory against their budgets, resident bytes (GPU memory, shader containers, the XMem allocator), and host texture counts and bytes from resource::texture_counts;
    • caches (shader containers, shader disk cache, host pipelines, detiled textures), the slowest timed scopes, and loads (DirectStorage, big or slow ReadFiles);
    • with VICTORY_GPU_TIMING=1 and DRED markers (diagnostics build): the worst 8 GPU commands of the period and of the run. Each row has max / median / total ms, runs, the list's GPU time, and the command as its marker names it (indirect kind 2 max 1 [compute ...], mesh 3 [mesh ..., pixel ...]), with hex values blanked. It also shows the slowest submission with its list count and pipelines.
  • VICTORY_PROFILE=<dir> (refused inside the repo) also writes frames.csv (one row per frame, now with dropped and zero_groups) and trace.json (Perfetto).
  • VICTORY_PROFILE_OVERLAY=1: an on-screen panel (F3 toggles it) with the same frame, memory and cache data.
  • VICTORY_PROFILE_DUMP=30,90: a full report at those seconds, with every thread's stack in a diagnostics build. One is also logged in host::fail.
  • VICTORY_PROFILE_LIVE=1 (=frame for one line per frame, =<file> for a path): one line a second on the console and in <dir>\live.log (or %TEMP%\victory-live.log), with sync_data after every line so the file survives a TDR. Each line has CPU and GPU time per frame, the slowest submission and command of the window, the last marker the GPU finished (or the one it is in), dropped and zero-group work per frame, and VRAM and shared memory against their budgets. Warnings are written at once (at most 10 a second): SLOW COMMAND and SLOW SUBMISSION over VICTORY_PROFILE_LIVE_SLOW_MS (default 100), STALL when no marker passes for VICTORY_PROFILE_LIVE_STALL_MS (default 1000, then at each doubling), and FAILURE when the host GPU fails.

How it uses what's on main

  • GPU command times come from VICTORY_GPU_TIMING's timestamps (HostList::slowest), and command names come from the DRED markers (HostList::note). They are aggregated, not measured again. The slowest submission lists its pipelines the same way as the "slow host submission" log.
  • Live progress: when live mode and DRED markers are on, and the device reports WriteBufferImmediate for direct queues, each marker also writes two words (commands begun, commands finished) into a mapped read-back buffer for its list. They are cleared at submit and read by the live thread while the submission is in flight. The DRED breadcrumbs keep giving the post-removal view, and this gives the same position while the run is still alive.
  • Dropped counts reuse draw.rs's drop sites (one helper instead of six adds) and list.rs's indirect drop. Zero groups are counted for direct draws and dispatches only. For indirect arguments, the docs point to VICTORY_CAPTURE_FRAMES + VICTORY_DUMP_TARGETS, which already log them.
  • The earlier host-texture estimate was dropped, since main now tracks real bytes. 6d021fe (world frame cost) changes page tables and copy statistics and does not overlap.

Design

  • New crate victory-profile, depending only on victory-core, tracing and windows-sys. Each call site's macro looks up its stat once into a static OnceLock; after that, updates are relaxed atomic adds. A background thread writes the summaries; another (live mode only) ticks every 100 ms.
  • The live markers and their buffers exist only in diagnostics builds. Writing them waits for earlier work, so the GPU runs slower with them on, and like VICTORY_GPU_TIMING they can move a hang.
  • Unit tests (no GPU, no game data) cover the aggregation, settings parsing, CSV/JSON output, the overlay's text, font and pixel encodings, command keys (hex blanked, the user-data tail cut), the worst-commands table, live settings, the live line, stall warnings at the threshold and each doubling, and the warning rate limit.
  • 11 commits: crate, GPU hooks, HLE hooks, docs, dumps with stacks; the overlay's data, GPU copy and docs; then GPU commands and live lines in the crate, their GPU hooks, and their docs. The overlay commits and the last three can each be taken or dropped as a group.

Known limits

  • A command's time can include waiting for work queued before it (seen on an RTX 5060 in #71). Per-list and per-submission times are more reliable.
  • There is no separate pipeline hash in the command rows, only the shader hashes the marker holds. There are no pipeline-statistics counters either; a statistics query like the one in #1723 would fit next to it.
  • Indirect zero-group work isn't counted per frame, because its arguments are only on the GPU.
  • F3 also reaches the title. Title-side fence waits aren't measured yet (#32).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572023260 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/130). Originally posted by [Sunkiller-qc](https://github.com/Sunkiller-qc) on 2026-11-24T00:48:07Z. --- An opt-in profiler, so performance and hang reports (#71, #16/#29) can start from aggregate numbers that anyone can collect and paste without game data. It now also covers the GPU side of #71: the worst GPU commands, dropped and zero-group work per frame, and a live log that names the command the GPU is stuck in before a TDR. Status: rebased onto `main` at `70564ae`. On Windows with Rust 1.98.1, `cargo build` and `cargo clippy --all-targets` are clean, both plain and with `--features victory-gpu/diagnostics`. `cargo test` passes for `victory-profile` (33 tests), `victory-hle` and `victory`. `victory-gpu` has 76 passing and 2 failing (`descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`); both fail the same way on `70564ae` alone. Not yet run in game against a hang. What it does - Off unless a `VICTORY_PROFILE*` variable is set when `victory run` starts. When it's off, each hook costs one relaxed atomic load. It works in any build, release included. - `VICTORY_PROFILE=1`: a summary every 5 s in the log (target `victory_profile`): - frames: fps, 1% low, frame interval percentiles, hitches and stutters; - per frame: preparing, fence wait, present; submissions, lists, draws, dispatches; dropped commands and zero-group work; - memory: process memory, VRAM and shared memory against their budgets, resident bytes (GPU memory, shader containers, the XMem allocator), and host texture counts and bytes from `resource::texture_counts`; - caches (shader containers, shader disk cache, host pipelines, detiled textures), the slowest timed scopes, and loads (DirectStorage, big or slow `ReadFile`s); - with `VICTORY_GPU_TIMING=1` and DRED markers (diagnostics build): the worst 8 GPU commands of the period and of the run. Each row has max / median / total ms, runs, the list's GPU time, and the command as its marker names it (`indirect kind 2 max 1 [compute ...]`, `mesh 3 [mesh ..., pixel ...]`), with hex values blanked. It also shows the slowest submission with its list count and pipelines. - `VICTORY_PROFILE=<dir>` (refused inside the repo) also writes `frames.csv` (one row per frame, now with `dropped` and `zero_groups`) and `trace.json` (Perfetto). - `VICTORY_PROFILE_OVERLAY=1`: an on-screen panel (F3 toggles it) with the same frame, memory and cache data. - `VICTORY_PROFILE_DUMP=30,90`: a full report at those seconds, with every thread's stack in a diagnostics build. One is also logged in `host::fail`. - `VICTORY_PROFILE_LIVE=1` (`=frame` for one line per frame, `=<file>` for a path): one line a second on the console and in `<dir>\live.log` (or `%TEMP%\victory-live.log`), with `sync_data` after every line so the file survives a TDR. Each line has CPU and GPU time per frame, the slowest submission and command of the window, the last marker the GPU finished (or the one it is in), dropped and zero-group work per frame, and VRAM and shared memory against their budgets. Warnings are written at once (at most 10 a second): `SLOW COMMAND` and `SLOW SUBMISSION` over `VICTORY_PROFILE_LIVE_SLOW_MS` (default 100), `STALL` when no marker passes for `VICTORY_PROFILE_LIVE_STALL_MS` (default 1000, then at each doubling), and `FAILURE` when the host GPU fails. How it uses what's on main - GPU command times come from `VICTORY_GPU_TIMING`'s timestamps (`HostList::slowest`), and command names come from the DRED markers (`HostList::note`). They are aggregated, not measured again. The slowest submission lists its pipelines the same way as the "slow host submission" log. - Live progress: when live mode and DRED markers are on, and the device reports `WriteBufferImmediate` for direct queues, each marker also writes two words (commands begun, commands finished) into a mapped read-back buffer for its list. They are cleared at submit and read by the live thread while the submission is in flight. The DRED breadcrumbs keep giving the post-removal view, and this gives the same position while the run is still alive. - Dropped counts reuse `draw.rs`'s drop sites (one helper instead of six adds) and `list.rs`'s indirect drop. Zero groups are counted for direct draws and dispatches only. For indirect arguments, the docs point to `VICTORY_CAPTURE_FRAMES` + `VICTORY_DUMP_TARGETS`, which already log them. - The earlier host-texture estimate was dropped, since main now tracks real bytes. `6d021fe` (world frame cost) changes page tables and copy statistics and does not overlap. Design - New crate `victory-profile`, depending only on `victory-core`, `tracing` and `windows-sys`. Each call site's macro looks up its stat once into a static `OnceLock`; after that, updates are relaxed atomic adds. A background thread writes the summaries; another (live mode only) ticks every 100 ms. - The live markers and their buffers exist only in diagnostics builds. Writing them waits for earlier work, so the GPU runs slower with them on, and like `VICTORY_GPU_TIMING` they can move a hang. - Unit tests (no GPU, no game data) cover the aggregation, settings parsing, CSV/JSON output, the overlay's text, font and pixel encodings, command keys (hex blanked, the user-data tail cut), the worst-commands table, live settings, the live line, stall warnings at the threshold and each doubling, and the warning rate limit. - 11 commits: crate, GPU hooks, HLE hooks, docs, dumps with stacks; the overlay's data, GPU copy and docs; then GPU commands and live lines in the crate, their GPU hooks, and their docs. The overlay commits and the last three can each be taken or dropped as a group. Known limits - A command's time can include waiting for work queued before it (seen on an RTX 5060 in #71). Per-list and per-submission times are more reliable. - There is no separate pipeline hash in the command rows, only the shader hashes the marker holds. There are no pipeline-statistics counters either; a statistics query like the one in #1723 would fit next to it. - Indirect zero-group work isn't counted per frame, because its arguments are only on the GPU. - F3 also reaches the title. Title-side fence waits aren't measured yet (#32).
jeremygold02 commented 2026-11-24 06:55:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:28:44Z.


Tested head 0ba0851dea0f9452c104c4f71888232dd1958fd1:

  • cargo test -p victory-profile --lib -- --test-threads=1 — 24 passed, including overlay::tests::colors_in_every_format, stats::tests::nearest_rank_percentiles, and tests::settings_from_the_variables; these cover overlay pixel encodings, summary statistics, and settings parsing (overlay, stats).
  • cargo test -p victory-hle --lib -- --test-threads=1 — 86 passed, including existing XMem reporting and allocation tests.
  • cargo check -p victory-gpu and cargo check -p victory — both passed, compiling the changed GPU overlay and app startup call sites (GPU overlay, app startup).
    No GPU unit tests or title run was performed, so live GPU interaction and on-screen overlay appearance remain unverified.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7122056275 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/130#issuecomment-7122056275). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:28:44Z. --- Tested head `0ba0851dea0f9452c104c4f71888232dd1958fd1`: - `cargo test -p victory-profile --lib -- --test-threads=1` — **24 passed**, including `overlay::tests::colors_in_every_format`, `stats::tests::nearest_rank_percentiles`, and `tests::settings_from_the_variables`; these cover overlay pixel encodings, summary statistics, and settings parsing ([overlay](https://github.com/Marvisak/VIctory/blob/0ba0851dea0f9452c104c4f71888232dd1958fd1/crates/victory-profile/src/overlay.rs), [stats](https://github.com/Marvisak/VIctory/blob/0ba0851dea0f9452c104c4f71888232dd1958fd1/crates/victory-profile/src/stats.rs)). - `cargo test -p victory-hle --lib -- --test-threads=1` — **86 passed**, including existing XMem reporting and allocation tests. - `cargo check -p victory-gpu` and `cargo check -p victory` — both passed, compiling the changed GPU overlay and app startup call sites ([GPU overlay](https://github.com/Marvisak/VIctory/blob/0ba0851dea0f9452c104c4f71888232dd1958fd1/crates/victory-gpu/src/overlay.rs), [app startup](https://github.com/Marvisak/VIctory/blob/0ba0851dea0f9452c104c4f71888232dd1958fd1/apps/victory/src/run.rs)). No GPU unit tests or title run was performed, so live GPU interaction and on-screen overlay appearance remain unverified.
Marvisak commented 2026-11-25 01:07:46 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in apps/victory/src/run.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/texture.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148495351 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/130#issuecomment-7148495351). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:29Z. --- <!-- victory-triage v1 head=1a807d28abe12bb1835a94f9e26c71aa8bfe75d8 verdict=needs-rebase at=2026-11-25T15:54:50Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `apps/victory/src/run.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/texture.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/130:upstream-pr/130'
git switch 'upstream-pr/130'

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