mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 12:38:38 +00:00
test_docs_repo_paths failed: docs/measuring_fps.md named scripts/game-gate.ps1, which only #2782 adds. Name the game gate's run folders instead, here and in the tool's docstring.
100 lines
8.0 KiB
Markdown
100 lines
8.0 KiB
Markdown
# 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](../d3d12/docs/findings.md) and the list
|
|
of switches in [d3d12/docs/switches.md](../d3d12/docs/switches.md).
|
|
|
|
## 1. Look first
|
|
|
|
Search [findings.md](../d3d12/docs/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`](../d3d12/crates/leonida-gpu/src/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](../d3d12/docs/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](../d3d12/docs/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.
|
|
|
|
## 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.
|