Skip to content

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 into
Marvisak:mainfrom
Sunkiller-qc:perf-profiler
Open

Sunkiller-qc wants to merge 11 commits into
Marvisak:mainfrom
Sunkiller-qc:perf-profiler

Conversation

@Sunkiller-qc

@Sunkiller-qc Sunkiller-qc commented Nov 24, 2026 •

Copy link
Copy Markdown

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

@jeremygold02

Copy link
Copy Markdown
Contributor

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.

…, memory)

VICTORY_PROFILE=1 logs a summary every few seconds: frame intervals with
avg, p50/p95/p99, max, 1% low, hitches and stutters; the work per frame;
process memory and resident bytes; cache hit rates; the timed scopes that
took longest; the biggest and slowest loads. VICTORY_PROFILE=<dir> also
writes frames.csv (one row per presented frame) and trace.json (Chrome
trace events for Perfetto). Off, every hook is one relaxed load.

Nothing calls it yet; the aggregation is unit-tested without a GPU.
… VRAM)

With VICTORY_PROFILE set: every presented frame (its present number, as
VICTORY_CAPTURE counts, size, format, draws and dispatches since the last
one, time spent presenting), each submission's preparing and fence wait,
shader translations and pipeline creations timed, the shader container
table and the disk cache as caches, texture refreshes (unchanged textures
as hits), descriptor heaps, upload buffers, resident GPU memory and host
textures, the adapter's video memory and budget, and a full dump before a
host GPU failure ends the run.
…start it

victory run calls victory_profile::init. With VICTORY_PROFILE set: ReadFile
and fread timed with their bytes, big (1 MiB) or slow (5 ms) reads named
as file loads, every DirectStorage request a load under the title's name
for it and by what it decodes, XMemAlloc/XMemFree timed, the default
allocator's resident bytes, XMemVirtualAlloc bytes, XMA frames and Opus
packets timed.
VICTORY_PROFILE_DUMP=<seconds>,... now also runs the VICTORY_STACKS dump,
so one report has the frames, memory, caches and where each thread is.
The dump before a host GPU failure does not suspend threads.
…LE_OVERLAY)

The panel is plain data in victory-profile: its lines from the last 120
frames and the samplers, an embedded 5x7 font as '#' strings, a graph of
the frame intervals, and the rows in the back buffer's format (RGBA8,
BGRA8, RGB10A2, RGBA16F). Redrawn at most four times a second. Off unless
VICTORY_PROFILE_OVERLAY=1 or VICTORY_PROFILE=overlay; tests for the text,
the font, the layout and the encodings.
The presenter copies the panel from a kept upload buffer into the back
buffer's corner with CopyTextureRegion, after the frame and before the
present: no shaders or pipelines. F3 while our window has focus shows and
hides it. Host pipeline lookups count as cache hits and misses.
… live lines (VICTORY_PROFILE_LIVE)

For the world hangs of Marvisak#71: the noted commands' GPU times (with
VICTORY_GPU_TIMING) kept by a key without title values, their worst by
max with median, total, runs and their list's time; the slowest
submission of each period with its pipelines; draws and dispatches dropped
or of zero groups per frame (frames.csv gains two columns).

VICTORY_PROFILE_LIVE=1 (or =frame, or a file) writes a line a second to
the console and to a file synced at each line: CPU and GPU time per frame,
the slowest submission and command, the last GPU marker done or the
command the GPU is in, dropped and zero-group work, video and shared
memory against their budgets. Warnings come at once for a command or
submission over VICTORY_PROFILE_LIVE_SLOW_MS and for the GPU on one marker
over VICTORY_PROFILE_LIVE_STALL_MS. Tests for the keys, the tables, the
settings, the lines and the stall watch.
…ve GPU markers

With VICTORY_GPU_TIMING, each list's timed commands go to the profiler;
every submission's GPU wait and pipelines; dropped draws, dispatches and
indirect executions, and those of zero groups. With VICTORY_PROFILE_LIVE
in a diagnostics build with VICTORY_D3D12_DRED, each list has two words in
read-back memory the GPU writes before each noted command and at the end
(WriteBufferImmediate, marker in and out), read while the submission runs:
the live thread names the command the GPU is in before a removal, where
the device-removed data only tells after. A host failure is written to the
live file at once.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

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.

3 participants