Files
mandy/docs/measuring_fps.md
TheGeogeo af89a79c10 scripts: game-abba.ps1 takes a value the settings line hides as an arm, keeps a name's last value, refuses a checkout in -Out (review)
- arm_settings applies the space and length rules only to a value the runtime's settings line shows as it is:
  one of ASCII letters, digits and " ._,:+=*-", the `plain` test of d3d12/apps/leonida/src/leonida.rs line 65,
  mirrored and quoted in d3d12_ab_compare.py's new SOURCES, which a contract test checks against leonida.rs.
  Any other value (a folder with a space, a long path) shows as "<hidden, N chars>", which `check` takes as
  shown, so it can be an arm.
- A name given twice in one arm counts with its last value, as the gate keeps it.
- `settings` names an item by its position (and its LEONIDA_ name), never by its text, so no path is said back.
- The runner refuses a checkout inside -Out, where a re-run's clean-up could reach it.
- The files the runner writes are written beside themselves and moved over, so abba.json, rewritten after every
  run, is never found cut short; an -Out whose abba.json exists but is not readable as this runner's is refused
  as such ("no readable abba.json of this runner").
- docs/measuring_fps.md and the script's header say the same.
2026-12-02 12:04:48 +01:00

11 KiB

Measuring frame rates of the D3D12 runtime

How to find out whether a change or a switch moves the frame of the Rust D3D12 runtime (d3d12/), and how not to fool yourself. It is about method; the measurements are in d3d12/docs/findings.md and the list of switches in d3d12/docs/switches.md.

1. Look first

Search findings.md for the switch or the function you have in mind, on a fresh main. Many switches have been measured there, with the card, the scene, the method and the spread. LEONIDA_COPYBACK_ELIDE, for one, has an entry that says "not usable here".

2. Turn the switch inside one run

LEONIDA_AB=<seconds>,<switch>[,<switch>..] turns switches on and off every so many seconds while the title runs, so both sides are measured in one scene, at one cache temperature, beside the same programs (ab.rs):

  • It needs a build with diagnostics (the one d3d12/scripts/build-nvidia.ps1 makes) and more than one second a phase.
  • Up to eight switches; switch number n is on in the phases whose number has bit n, so every combination comes round.
  • Give it to the launcher: -More @{LEONIDA_AB='4,LEONIDA_STORE_BESIDE'}. play-nvidia.ps1 removes the LEONIDA_* variables of the window it starts in (four paths aside), so $env:LEONIDA_AB = ... before it is lost without a word. The same goes for every variable of section 5.
  • More than eight names, or a phase of one second or less, and there is no A/B at all, again without a word. Look for the A/B phase lines in the log.
  • A plain on/off switch named there goes by the phase instead of its own variable. For a switch with a value or a list the phase only says whether that value counts, so give the value too, in the same -More: without LEONIDA_GUARD_HOT=<ms> or the hashes of LEONIDA_SKIP_TRY_A both sides are off and the A/B compares nothing with nothing. The same goes for another switch it needs (LEONIDA_PORT_GUARD for LEONIDA_GUARD_HOT). "See the code" under Kind in switches.md is a sign to look there first.
  • Only switches the code reads that way follow it; for any other name the phases are logged and nothing changes, so check the name in switches.md or the code before you believe a "no difference".
  • Not every switch may be turned in play: findings.md has one that ends the title (LEONIDA_ASYNC_SUBMIT).
  • Each phase ends with a line A/B phase <n> bits <b> on [...]: frames, mean, median, p90, draws a frame, the card's idle and busy time a frame and the submitting thread's work a frame. The first second of a phase is left out.

Phases of 3.5 to 4 s worked in the runs of findings.md (one PC, one save: "about measuring there"). The idle camera there goes round views of about 24 s with different draw counts, so phases of 15 s measured the views, not the switch.

Standing, findings.md cuts the phases into stretches where the draw count jumps, leaves out the first phase of a stretch and fits a level for each stretch; walking, the switch of bit b has runs of 2^b phases off and 2^b on: each pair of neighbouring runs gives one difference, and their mean is the effect. Give the effect with its standard error. python -I tools/d3d12_ab_compare.py phases <log> does the walking way for every switch of the run (pairs of blocks, a pair whose draws a frame differ by more than a tenth left out), for the median frame time and for each counter of the A/B counters line the runtime writes after a phase line (with diagnostics).

The standard errors in findings.md are mostly 0.2 to 0.6 ms for a standing run of some minutes (up to 0.94) and 1 to 2 ms for a walking one (up to 2.24). Two separate runs of one setting differed by 7 ms in one of its tables (75.0 and 82.1 ms).

3. When only separate runs will do

A change of code, or a switch that cannot be turned in play, needs separate runs:

  • The same save for every start. The title rewrites its autosave, so keep a copy and put it back before each start (and the player's own back afterwards).
  • Alternate (A B B A), in one sitting, with a throwaway run first: on one PC the first measured run after a warm-up came out slowest in both of two series (seen once, 2026-11-30, not in findings.md, not explained).
  • After a translator change, or on a new build, play a while first. Until its pipelines are made, a run measures that.
  • The same programs in the background, and nothing heavy beside it: no compiler, no test suite. findings.md has one build at 16.2 to 17.3 and then 12.8 frames a second; what had changed was the programs that start with Windows.
  • Check every run for the state you think it was in: it reached the world, it did not stay in the menu, it did not end early. One that stayed in the menu showed 60 throughout (seen once, 2026-11-30).
  • With two runs a side, do not claim a difference smaller than the spread between runs of the same side.
  • python -I tools/d3d12_ab_compare.py plan --pairs 4 prints such an order; abba A:<run> B:<run> B:<run> A:<run> ... reads the runs in that order (logs, or the game gate's run folders with their summary.json): one value a run (its world median frame time), neighbouring pairs, the effect with its standard error and 95 % interval from at least 4 balanced pairs, and "B faster" or "B slower" only when the interval leaves 0 out and all pairs but one agree.
  • scripts/game-abba.ps1 does all of it in game: the gate runs in that order, for one exe with two settings (-Data, -MoreA, -MoreB) or two builds (-CheckoutA, -DataA, -CheckoutB, -DataB: a data folder each, their caches differ), then abba into <Out>\comparison.txt. In two-build mode each arm runs its own checkout's gate, so each checkout needs scripts\game-gate.ps1 (added on 2026-11-30): an older checkout is refused before any run. It leaves out a measured run that abba would leave out (its gate failed, its summary.json cannot be read, it has no frame rate), whose pipeline cache was not warm before the measured window, whose exe is not its arm's, or whose -MoreA/-MoreB settings do not show in the runtime's settings line, and runs that slot again (-Retry, 1, 0 or more). A slot left out on every try stays in its place, left out. A warm-up or discarded run whose gate fails stops it at once, before the measured runs. -DryRun prints the plan and the gate commands; it checks no folder and deletes nothing. Set both arms' switch explicitly (LEONIDA_X=0 against LEONIDA_X=1): only what an arm sets is checked. -Pairs is 4, and 3 at least: 2 pairs are 2 runs a side, which abba can never compare (it needs 3 runs a side, or 4 pairs for a verdict from the pairs themselves), so they are refused before any run. At 4 pairs and 300 s in the world it is 11 or 12 runs, about an hour.
  • Refused before any run, besides the above: an -Out inside a checkout or holding one, or the same folder as -Game, -DataTemplate or a data folder, inside one or holding one; a -MoreA/-MoreB item the settings line could never show, read the way the gate reads -More (split at ;, name and value trimmed, a name's last value kept): anything but LEONIDA_NAME=value with the name in capitals, digits and _, or a value the line shows as it is (ASCII letters, digits and ._,:+=*- only) with a space in it or longer than its 120 characters (d3d12_ab_compare.py settings --more=<text> says which item, by its position). A value with any other character, such as a folder (LEONIDA_DLSS_DIR=C:\Program Files\NVIDIA), shows as hidden, which counts as shown, so it can be an arm. Also refused: a missing -Game, -DataTemplate or data folder.
  • <Out>\abba.json records the arms' inputs (more, more_a, more_b, play_args, world_seconds, max_minutes, retry, pairs, and this machine's game, data_template, checkout_a, checkout_b, data_a, data_b) and each run: its folder, exe, commit and why it was left out. It is written at the start and after each run, so a run that stops on an error leaves it as far as it went. A run into an -Out whose abba.json this runner wrote first deletes what the earlier one wrote there (runs, abba.json, comparison.txt, comparison.json), and nothing else; an -Out holding any of those without a readable abba.json of the runner is refused. The files it writes are LF text, each written beside itself and moved over it, so none is ever found cut short. Exit code 0 with a comparison ("no clear difference" is one); 1 without one: too few runs left or unbalanced pairs (the comparison files say why), or an error (a refusal, a failed warm-up, a gate that did not start, a comparator that failed), which writes no comparison.

4. Which number means what

  • Frame time, not only frames a second. The line leonida_gpu::host: <n> fps, <ms> ms/frame (...) counts rendered frames. With frame generation the screen shows more; say which you mean, or measure with -NoFrameGen.
  • Report the median and a low percentile, and leave the menu and the loading out.
  • A sum over all threads is not a part of the frame. "All threads", "list calls ... ms", the process's CPU time and a whole-process profile add up work that runs side by side. They can exceed the frame many times over.
  • A thread that waits because it has nothing to do costs nothing. The relay line says its thread waits "beside the submitting thread"; what other threads lost to it is in the line about settles.
  • Draws "left out on purpose" are not missing pipelines; the line gives both counts.
  • The frame stands at the longest of its walls (the card, the submitting thread, the title). Work taken off another one does not show. Cards and CPUs differ: say the card, driver, CPU, memory, profile, resolution, scene and commit.

5. Where a frame goes

All in builds with diagnostics; each costs something, so do not read frame rates from the same run.

Tool What it answers
LEONIDA_TIMELINE=<file> (with LEONIDA_TIMELINE_AT, LEONIDA_TIMELINE_FRAMES) A trace of a few frames for chrome://tracing or Perfetto, and a text summary with the chain of work and waits each present came out of: the tool for "what does the frame wait for".
LEONIDA_PROFILE=<from>,<to>,<ms>,<file> (with LEONIDA_PROFILE_ONLY=<thread name>) Stack samples by thread, waits included, from inside the process. Always with LEONIDA_PROFILE_ONLY and a thread of the runtime: without it the busiest threads are taken, the title's among them, and findings.md has a run that a walk of a title's stack ended. For those, use the timeline.
LEONIDA_GPU_TIMING=1 with LEONIDA_D3D12_DRED=1 The commands' time on the card. The launcher sets LEONIDA_D3D12_DRED to faults, which is not enough, so give both. Each list is then submitted on its own and LEONIDA_LATE_WAIT is off: good for which command costs what, not for how long the frame is.

6. Before you report a cause

  1. Write the prediction and what would refute it before the run.
  2. Say MEASURED (with n), READ IN CODE or ASSUMED.
  3. Try to refute it: if this were the cause, what else would have to be true? Is it on the submitting thread's chain?
  4. Post numbers only: no logs, captures, shader or pipeline names that are not already in the repository, addresses of the title, or other game data.