Skip to content

tools: d3d12_ab_compare reads an A/B of the D3D12 runtime (D3D12-AB-COMPARE) - #2783

Merged
MoonEyes merged 3 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-ab-compare
Nov 30, 2026
Merged

MoonEyes merged 3 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-ab-compare

Conversation

@TheGeogeo

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-AB-COMPARE (#2570 (comment))

Depends on: #2782 for gate run folders (summary.json). Logs work without it. #2779 adds the A/B counters line that phases reads when present.

What and why

docs/measuring_fps.md tells how to read an A/B: neighbouring pairs, the effect with its standard error, and ABBA after a throwaway run. But the scripts it named (ab_pair.py, ab_eff.py) were never in the repository, so everyone computed it by hand. Testers' verdicts from two runs a side turned out to be noise (enlighted on the bridge).

tools/d3d12_ab_compare.py (standard library, reusing tools/d3d12_run_fps.py's reader):

  • abba A:<run> B:<run> B:<run> A:<run> ... takes the runs in the order they ran: a gate folder, whose summary.json gives the world median of the presents and leaves out runs that did not PASS, or a log, whose frame lines at 1,000 draws a frame or more count as the world.
    • The unit is the run: one value each, its median frame time. Frames within a run are not independent.
    • Neighbouring runs pair up and give B − A.
    • It needs at least 4 pairs, as many with A first as with B first, so a linear drift (a cache warming, a machine heating) cancels.
    • It gives the mean difference, its standard error and a 95 % t interval, the median of the differences, and how many pairs agree in sign.
    • With 3 runs a side and no balanced pairs, it fits the side plus a linear trend instead.
    • It says "B faster" or "B slower" only when the interval leaves 0 out and all pairs but one agree in sign. One odd run cannot carry a verdict.
  • phases <log> does the same inside one LEONIDA_AB run, per switch: blocks of 2^s phases off and on, one difference per pair of blocks. It covers the median frame time and every counter of the A/B counters line (d3d12: LEONIDA_AB tells the frame lines' counters by arm (D3D12-AB-COUNTERS) #2779). It leaves out a pair whose draws a frame differ by more than a tenth (a change of scene, not of the switch); --keep-draw-jumps keeps it.
  • plan --pairs 4 [--switch] prints a balanced order: two warm-ups, then a discarded run that ends on the first measured side, then ABBA.
  • Text output, or --json. Numbers only: never a log line, a path or an argument's text.

docs/measuring_fps.md sections 2 and 3 now point to it instead of to the missing scripts.

Tested

On Windows 11:

  • tests/test_d3d12_ab_compare.py, 13 tests, all passing, on synthetic numbers and logs:

    • a worked example with a drift: effect −1.225 ms, standard error 0.149, 95 % [−1.70, −0.75], "B faster";
    • a pure drift in an ABAB order with no effect, which naive pairs would read as "B slower": no clear difference;
    • one odd run: no verdict;
    • three pairs: not the pairs method;
    • three runs a side with a trend: the effect is recovered exactly;
    • a failed gate leaves its pair out;
    • gate folders and logs (menus only, the world);
    • phases with counters, and a scene change left out;
    • plan orders;
    • the command prints no path.

    The file runs in the standard-library CI loop.

  • test_d3d12_run_fps.py, test_docs_design_rows.py, test_ci_registration.py, check_no_game_data.py and git diff --check are clean.

GPUs tested: n/a (a standard-library tool; checked on Windows 11 Pro 10.0.26300).

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable.)

…OMPARE)

docs/measuring_fps.md tells how to read an A/B (neighbouring pairs, the
effect with its standard error, ABBA after a throwaway run), but the
scripts it named were never in the repository, and testers' two-run
verdicts turned out to be noise.

`abba` takes runs in the order they ran (folders of scripts/game-gate.ps1
or logs), one value a run (its world median frame time: frames within a
run are not independent), pairs neighbouring runs and gives the mean
difference with its standard error and a 95 % t interval, the median of the
differences and how many agree in sign. It needs at least 4 pairs, as many
with A first as with B first, so a linear drift cancels; with 3 runs a side
it fits the side and a linear trend instead. It says "B faster" or "B
slower" only when the interval leaves 0 out and all pairs but one agree.
Gate runs that did not PASS are left out with their pair.

`phases` does the same inside one LEONIDA_AB run, per switch, for the
median frame time and the `A/B counters` line, leaving out pairs of blocks
whose draws a frame differ by more than a tenth. `plan` prints a balanced
order. Numbers only, never log text.
@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12.16, main 0f86bd594 merged with head 76b543a09.

  • MEASURED, green: tests/test_d3d12_ab_compare.py 13 passed. Red (main + only the test): 1 error at import, as expected for a new tool.
  • python -I scripts/check_no_game_data.py on tools/d3d12_ab_compare.py and docs/measuring_fps.md: clean.
  • MEASURED, one docs test fails with this PR (5/5 on main): tests/test_docs_repo_paths.py::DocsRepoPaths::test_docs_name_existing_paths, ('docs/measuring_fps.md:67', 'scripts/game-gate.ps1'). That script comes from d3d12: an in-game gate: one command, one run folder, one summary.json (D3D12-GAME-GATE) #2782, which is not merged, so this PR depends on it: either Depends on: #2782 in the body and merge after it, or drop the path from line 67 here.
  • Not covered: a real A/B log from the game.

AI-assisted: Claude Code

test_docs_repo_paths failed: docs/measuring_fps.md named scripts/game-gate.ps1, which only ProjectLeonida#2782 adds.
Name the game gate's run folders instead, here and in the tool's docstring.
@TheGeogeo

Copy link
Copy Markdown
Contributor Author

Thanks for the Mac run. test_docs_repo_paths failed here too: docs/measuring_fps.md named scripts/game-gate.ps1, which only #2782 adds. Fixed in c05f434 by naming the game gate's run folders instead (doc and the tool's docstring), so this PR stays independent of #2782.

On Windows at c05f434: tests/test_docs_repo_paths.py OK, tests/test_docs_cli_flags.py OK, tests/test_d3d12_ab_compare.py OK (13), scripts/check_no_game_data.py on the changed files OK, merge with current main clean.

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Re-checked by OreoFR on the new head c05f43403 merged with main 0f86bd594 (macOS 27.2.1, Apple M5, Python 3.12.16): tests/test_d3d12_ab_compare.py 13 passed; tests/test_docs_*.py 57 passed, 133 subtests passed (the test_docs_repo_paths failure is gone, and the PR no longer depends on #2782); check_no_game_data.py on the three changed files: clean. Not covered: a real A/B log from the game.

AI-assisted: Claude Code

tests/test_tool_stdout_encoding.py (on main since this branch started) wants every tool's __main__
block to do it: under -I a redirected stdout is strict in the console's code page.
@TheGeogeo

Copy link
Copy Markdown
Contributor Author

CI check and linux-python-and-viewer failed on tests/test_tool_stdout_encoding.py: tools/d3d12_ab_compare.py's __main__ block did not set errors="replace" on stdout. Fixed in e4318f0 with the same guard as tools/d3d12_run_fps.py. On Windows: test_tool_stdout_encoding.py OK, test_d3d12_ab_compare.py 13 OK, merge with current main clean.

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Re-checked by OreoFR on the new head e4318f01f merged with main d8ca18240 (macOS 27.2.1, Apple M5, Python 3.12.16): tests/test_d3d12_ab_compare.py 13 passed; tests/test_tool_stdout_encoding.py 4 passed (the new stdout guard); tests/test_docs_*.py 57 passed.

AI-assisted: Claude Code

@MoonEyes

Copy link
Copy Markdown
Collaborator

Verified by MoonEyes (another person than the author) on head e4318f01f merged with main d8ca18240: Windows 11, Python 3.14. tests/test_d3d12_ab_compare.py 13 OK. Docs and test_tool_stdout_encoding OK. Red: the test does not import without the new tool. No game run from me (#2782 was run by enlight3d on an RTX 3090).

AI-assisted (Claude Code).

@MoonEyes

Copy link
Copy Markdown
Collaborator

Merging. Head e4318f01f merges cleanly with main d8ca18240 and does not force a rebase of #2566. Tool and doc, not the runtime; checked by OreoFR and MoonEyes on this head. Merged by MoonEyes.

AI-assisted (Claude Code).

@MoonEyes
MoonEyes merged commit a596adf into ProjectLeonida:main Nov 30, 2026
5 checks passed
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.

3 participants