Skip to content

d3d12: frame-time percentiles and what stalls frames, in the log and on the panel (D3D12-FRAME-TIME-STATS) - #2613

Merged
MoonEyes merged 3 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-frame-time-stats
Nov 30, 2026
Merged

MoonEyes merged 3 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-frame-time-stats

Conversation

@TheGeogeo

@TheGeogeo TheGeogeo commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-FRAME-TIME-STATS (#2570 (comment))

What and why

The frame-rate line gives the mean over the last second or more, and the F3 panel shows only the longest frame. A run with smooth frames and a few multi-second stalls therefore looks like a uniformly slow one, and the stalls, which are what players feel, do not show in the log.

New crates/leonida-gpu/src/host/frametime.rs, in every build:

  • It keeps every presented frame's time (Meter::frame).
  • With the frame-rate line, every five seconds, it logs one line, frame times over S s, N frames: median … ms, 95th percentile …, 99th …, longest …; A over 100 ms, B over 1 s; host pipelines Q queued, M made a second; waits for new memory to be resident R ms a frame; commit left C GB.
    • The percentiles are nearest rank, computed with integer ranks so that floats do not round them.
    • Up to 4,096 times are kept per line. Past that, the counts and the longest frame stay exact.
  • The diagnostics panel (F3) shows the last line's numbers, plus the pipeline wait per frame from copystat, on five more lines: P50 … P95 … P99 … MAX … (from 10 s up in whole seconds, 10S), OVER 100 MS … OVER 1 S …, PIPES PENDING … MADE/S … (queued or being made), WAITS PIPES … RESIDENT … MS (the pipeline wait over the panel's half second, the rest over the five-second line), COMMIT LEFT … GB. The box is five lines taller while shown, so the trainer menu below it moves down.
  • pipeline::made() gives host pipelines created or loaded since the start, next to making(). The meter starts from the totals at the first present, so the first line counts only what came after.

An independent review found the panel line past 40 columns for stalls of 10 s or more (the panel cut it without a sign); fixed in the second commit, with the test covering 10 s, 100 s and 10 min.

host.rs changes only by the module line, one field of Meter and two calls (+12 lines).

Tested

On Windows 11, from d3d12\:

  • New unit tests in host::frametime::tests:

    • percentiles, counts and longest frame on 98 smooth frames, one hitch and one stall;
    • nearest-rank percentiles, where 95% of 20 frames is the 19th;
    • exact counts past the kept times;
    • the panel's lines fit its 40 columns, and every character has a glyph in its font.

    All 4 pass. On main they do not build, because the module is new.

  • cargo test -p leonida-gpu --locked: 541 passed. With --features diagnostics: 603 passed.

  • cargo clippy -p leonida-gpu --all-targets --locked, with and without --features diagnostics, reports nothing in the changed files. As noted in d3d12: LEONIDA_WINDOWS_BAR_MB says once that it does nothing without resizable BAR (D3D12-BAR-WINDOWS-WARNING) #2612, workspace clippy -D warnings and cargo fmt --check are already red on main in other files. The new file is formatted with d3d12/rustfmt.toml.

  • git diff --check is clean, and so is python -I scripts/check_no_game_data.py on the four files.

  • In game, I checked the numbers against PresentMon 2.6 run beside it, over the same windows. Run: diag build, Series X profile at 1440p, the launcher's defaults, menus, then a story load and its cutscene.

    • Over 22 five-second windows (17 to 9,046 ms frames), the frame counts agree within 3 frames.
    • The median, p99 and longest agree to the millisecond, except where a single frame sits on a window's edge. That changed one p95 in a window of 82 frames, and one p99 and maximum in the first window.
    • The panel showed the five new lines.
  • leonida-gpu host.rs is already over the 655,360-byte limit that xtask policy::tests::repository_passes_policy checks: it fails on main too. This change adds 12 lines to it and keeps the rest in the new module.

GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300.

AI-assisted: yes

Checklist

…on the panel (D3D12-FRAME-TIME-STATS)

The frame-rate line gives a mean over the last second or more, and the F3
panel only the longest frame, so a run with smooth frames and a few
multi-second stalls looks like a slow one, and the stalls do not show.

host/frametime.rs keeps every presented frame's time. With the frame-rate
line, every five seconds, it logs one line: the median, 95th and 99th
percentiles (nearest rank), the longest frame, how many took over 100 ms
and over a second, and beside them host pipelines queued and made a second,
waits for new memory to be resident per frame, and the commit the system has
left. The panel shows the last line's numbers and the pipeline wait per
frame. Pure parts are unit-tested.
@merzleckeier

Copy link
Copy Markdown
Contributor

Independent Wine check of 5d1d6c85f integrated cleanly with bd643e46e. I cross-built leonida-gpu for Windows x64 with Rust 1.98.1, cargo xwin, profile diag and diagnostics. Runs used CachyOS, Wine 11.22, VKD3D-Proton 71cae091, DXVK 3.1.1-97 and a real DXGI swap chain under headless Gamescope.

The test creates a synthetic 640×360 RGBA8 texture, calls production Host::present and independently timestamps its return. It feeds short delays, 150 ms hitches and 1.12 s stalls, and checks the meter snapshot after each reporting window.

GPU Runs / windows Max difference from caller P50/P95/P99/max
AMD Raphael iGPU, RADV Mesa 26.3.1 2 / 4 0.170 ms
RTX 4070 SUPER, NVIDIA 620.73.04 2 / 4 0.606 ms

Across 880 frame intervals, the frame count and both threshold counters matched exactly. Each run reported 104 intervals with 7 over 100 ms and 2 over 1 s, then 116 intervals with 6 over 100 ms and 2 over 1 s. The resident-ms/frame value also matched the measured residency counter delta, including 1 µs total in each first NVIDIA window. All four stock frametime tests and the live probe passed in every run. The Windows x64 build also passed cargo xwin check without diagnostics.

The Wine process exited 0 in all four verified runs. On NVIDIA, headless Gamescope exited 139 during shutdown after the Wine child completed. The launcher records both statuses separately. AI-assisted, offline, synthetic input.

…from the first present (review)

- Panel: frame times of 10 s or more (the launcher's pipeline budget) made
  the percentile line longer than 40 columns, and the panel cut it without
  a sign ("MAX 10000" showed as "MAX 100"). Times from 10 s up are shown in
  whole seconds ("10S"); the test covers 10 s, 100 s and 10 min.
- The first line's pipelines made a second and residency waits counted
  everything since the process started: the meter now starts from the
  totals at the first present.
- "queued" was queued or being made: the log says so, the panel says
  PIPES PENDING.
- The nearest-rank test covers 95% of 100 frames, where a float ceil would
  take the 96th.
@bobcatchris

Copy link
Copy Markdown
Contributor

Independent native Windows 11 + AMD Radeon RX 7900 XTX (gfx1100, driver 32.0.32029.2010, Windows 11 10.0.26200) check of 5d72958bf merged cleanly onto main 4755667f5 (no game files):

  • Baseline (main 4755667f5): cargo test -p leonida-gpu --lib -- --test-threads=4 -> 544 passed; 0 failed; 47 ignored (12.27 s).
  • PR #2613 (5d72958bf) + main 4755667f5: cargo test -p leonida-gpu --lib -- --test-threads=4 -> 548 passed; 0 failed; 47 ignored (12.30 s, +4 new frametime tests, 0 regressions, 0 new compiler warnings).
  • python -I scripts/check_no_game_data.py on all 4 touched files: clean.

AI-assisted: Antigravity (Gemini 4 Neon).

@enlight3d

Copy link
Copy Markdown
Contributor

RUN (independent run, #2613 head 5d72958 on main 878b024; merged locally with git merge --no-ff, no conflicts; also no conflict with #2566 head 7b5cb29 per git merge-tree --write-tree).

Commands, in d3d12/, target x86_64-pc-windows-msvc, toolchain 1.98.1:

  • cargo check --tests -p leonida-gpu and the same with --features diagnostics (the panel code only builds with it): both OK on the merged tree.
  • cargo test -p leonida-gpu: green, 548 passed / 0 failed / 47 ignored. With --features diagnostics: 610 passed / 0 failed / 47 ignored. The 4 host::frametime::tests pass in both.
  • Red, behavioural (mutants of frametime.rs, tests kept): rank rounded down instead of up (percent * n / 100) makes percentiles_are_nearest_rank_without_float_rounding fail; counting and the longest frame only while times are still kept makes past_the_kept_times_the_counts_stay_exact fail.
  • Red, build: with only the test module left in frametime.rs, the tests do not compile (E0432/E0425, FrameTimes, Summary, KEPT, short not found).
  • Weak spot: a mutant using f64 ceil(p/100 * n) instead of the integer rank passes all 4 tests. The test comment says 0.95 * 100 is 95.00000000000001 in f64; I get exactly 95.0, and the two ways of ranking agree for every n from 1 to 4096 and p in 50/95/99. So the "without float rounding" case guards nothing beyond the floor/ceil direction; harmless, but the comment is inaccurate.
  • Not covered by tests: the wiring in Meter::presented/line (called every 5 s from the frame-rate meter) and the panel box growing from 9 to 14 lines (it grows even when no line exists yet).

No runtime/ C++ or Python in this PR, so no link or import check applies.
Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.

@MoonEyes

Copy link
Copy Markdown
Collaborator

Tested 5d72958bf merged (no commit) with main 060c47160: Windows 11, Rust toolchain from d3d12/rust-toolchain.toml, CPU only, no game run.

  • cargo test -p leonida-gpu --lib --locked: main 549 passed, 47 ignored; with this PR 553 passed, 47 ignored, 0 failed. The 4 new tests in host::frametime pass (percentiles, counts past the kept window, nearest-rank without float rounding, panel lines fit the box).
  • cargo clippy -p leonida-gpu --locked -- -D warnings: 10 findings on main and the same 10 with the PR, all in leonida-lua and leonida-shader; this PR adds none.
  • Merges cleanly with main and does not force a rebase of [integration] PageMirror, GPU detile, async queue & RDNA2->SPIR-V performance stack (INTEGRATION-PERF-CPU-GPU-R6) #2566.
  • No red possible for the new file; the tests are the frame-time module's own.
  • Not covered: an in-game run. It touches host.rs and pipeline.rs, so before merge it should also run in game for 300 s with no device loss, as this project now asks of render-path changes.

AI-assisted (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
main moved the frame meter's five-second lines into a function of their
own that may run on another thread: the frame times are logged where the
meter decides a five-second line is due, on the presenting thread, as
before. The nearest-rank test's comment said 0.95 * 100 is not 95.0 in
f64; it is: ranks are whole numbers so that no float can move one, and
the case pins the rounding direction (review).
@TheGeogeo

Copy link
Copy Markdown
Contributor Author

Updated: main is merged in at c6a8f71, and the conflict is resolved. The pull request's own change is otherwise unchanged.

  • The conflict: main moved the frame meter's five-second lines into Meter::lines. That function may now run on a thread of its own (meter_beside). The frame times belong to the meter, so they are still logged where Meter::frame decides that a five-second line is due, on the presenting thread, as before.
  • enlight3d's point: right, 0.95 * 100 is exactly 95.0 in f64, and for 50, 95 and 99 a float rank ceil(p / 100 * n) agrees with the whole-number rank for every n up to 4096 (I checked the same). The comment now says what the case does: ranks are whole numbers, (percent * n).div_ceil(100), so no float can move one, and the case pins the rounding direction at 100 frames.
  • cargo test -p leonida-gpu --locked: 575 passed. The 4 frametime tests also pass with --features diagnostics. clippy: nothing in the changed lines.
  • Still to do: the in-game run of 300 s with no device loss. I will post it here.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 30, 2026
@TheGeogeo

Copy link
Copy Markdown
Contributor Author

On enlight3d's last note, the panel box growing from 9 to 14 lines even before there is a frame-time line: this is on purpose, and I am leaving it as is. The box has a fixed size (LINES, used once in panel.rs to size its buffers), so it does not need new buffers when the frame-time lines appear. The five extra lines are empty only until the first five-second line, about 5 s after the first present. Making the box grow would mean making its buffers again at that point, for 5 s of empty space. Both branches still merge cleanly with main ad25611b5, and CI is green.

@MoonEyes

Copy link
Copy Markdown
Collaborator

RUN · VERIFY-2613-RTX4060 · by MoonEyes (another person than the author) on head c6a8f7164 merged with main 1d4949d58. Windows 11 Pro 26300, RTX 4060 8 GB, -SeriesS -FrameGen 2, diag build.

  • cargo test -p leonida-gpu --lib --locked: 576 passed, 0 failed.
  • Game: one run of 480 s, the person walking in the world from 345 s (about 50 m), no device loss, no unhandled exception, the process alive at the end. PASS for the gate of 300 s.
  • The new lines work in the running title: every 5 s "frame times over 5.1 s, 101 frames: median 47.8 ms, 95th percentile 68.1, 99th 74.8, longest 84.9 ...". Other work ran on the PC, so these are no benchmark.

AI-assisted (Claude Code).

@MoonEyes

Copy link
Copy Markdown
Collaborator

Merging. Head c6a8f7164 merges cleanly with main 99167bcaf and does not force a rebase of #2566. Run in the game of 480 s without device loss on RTX 4060 posted on this head; cargo test 576 passed. Merged by MoonEyes.

AI-assisted (Claude Code).

@MoonEyes
MoonEyes merged commit afb5115 into ProjectLeonida:main Nov 30, 2026
5 checks passed
@enlight3d

Copy link
Copy Markdown
Contributor

IN-GAME RUN (gate, independent): #2613 head c6a8f71, RTX 3090 24 GB, NVIDIA 621.40, Windows 11.

Setup: leonida.exe built from this head (d3d12/scripts/build-nvidia.ps1, diag profile, no DLSS files). After a 300 s warm-up, the gate run used the game-gate tool from #2782 (head 22e096e) with -WorldSeconds 600 -MaxMinutes 20, -SeriesS -NoDlss -NoFrameGen, Enter pressed through a keys file until the world, nothing after, the same save restored, standing still. Other jobs could run on the PC at the same time, so the frame rates are not comparable with other runs.

Gate: PASS. No device loss, no crash, clean exit (0x0) after 608 s in the world. The stop came through the window close, with no kill. Median 10.1 fps in the world by the runtime's fps lines (the tool's own figure, from presents after world+60 s: median 11.2, p5 6.7). The longest gap between presents was 8.5 s, during a loading dip just after the world was reached.

The late memory build-up that main shows on this card in some runs was moderate here (release queue about 134,000 and mapped scratch 3.7 GB at the end, VRAM peak 14.6 GB). It is not caused by this PR.

Not checked: Series X, walking, picture. The PR's percentile lines were not compared with an independent frame-time source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants