From 76b543a09772d754d6d08789aa777ae68d5b3b46 Mon Sep 17 00:00:00 2001 From: TheGeogeo <57634077+TheGeogeo@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:44:09 +0100 Subject: [PATCH 1/3] tools: d3d12_ab_compare reads an A/B of the D3D12 runtime (D3D12-AB-COMPARE) 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. --- docs/measuring_fps.md | 8 +- tests/test_d3d12_ab_compare.py | 144 +++++++++++++++ tools/d3d12_ab_compare.py | 313 +++++++++++++++++++++++++++++++++ 3 files changed, 464 insertions(+), 1 deletion(-) create mode 100644 tests/test_d3d12_ab_compare.py create mode 100644 tools/d3d12_ab_compare.py diff --git a/docs/measuring_fps.md b/docs/measuring_fps.md index 1a8f902efd..5c018b015d 100644 --- a/docs/measuring_fps.md +++ b/docs/measuring_fps.md @@ -41,7 +41,9 @@ there goes round views of about 24 s with different draw counts, so phases of 15 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**. The scripts it names for this (`ab_pair.py`, `ab_eff.py`) are not in the repository. +error**. `python -I tools/d3d12_ab_compare.py phases ` 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 @@ -61,6 +63,10 @@ A change of code, or a switch that cannot be turned in play, needs separate runs - 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: B: B: A: ...` + reads the runs in that order (folders of `scripts/game-gate.ps1`, docs/game_gate.md, or logs): 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 diff --git a/tests/test_d3d12_ab_compare.py b/tests/test_d3d12_ab_compare.py new file mode 100644 index 0000000000..7d9c15e946 --- /dev/null +++ b/tests/test_d3d12_ab_compare.py @@ -0,0 +1,144 @@ +"""tools/d3d12_ab_compare.py on synthetic numbers and synthetic logs (no game data).""" +import io +import json +import os +import sys +import tempfile +import unittest +from contextlib import redirect_stdout + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, os.path.join(ROOT, "tools")) +import d3d12_ab_compare as ab # noqa: E402 + + +def items(order, values): + return [(arm, v, 4000.0, None) for arm, v in zip(order, values)] + + +class Pairs(unittest.TestCase): + def test_the_worked_example_is_b_faster(self): + # A B B A A B B A with A about 1.2 ms slower and a drift between runs. + r = ab.abba(items("ABBAABBA", [20.4, 19.1, 19.6, 20.9, 21.3, 19.8, 20.2, 21.0])) + e = r["result"] + self.assertEqual(r["method"], "pairs") + self.assertAlmostEqual(e["effect"], -1.225, places=3) + self.assertAlmostEqual(e["se"], 0.1493, places=3) + self.assertAlmostEqual(e["ci95"][0], -1.700, places=2) + self.assertAlmostEqual(e["ci95"][1], -0.750, places=2) + self.assertEqual(e["agree"], 4) + self.assertEqual(r["verdict"], "B faster") + + def test_a_drift_alone_in_an_unbalanced_order_is_no_effect(self): + # A B A B A B A B with every run 0.25 ms slower than the one before and no effect at all: each pair would + # read B 0.25 ms slower. The pairs are not balanced, so the side and a trend are fitted instead. + r = ab.abba(items("ABABABAB", [20.0 + 0.25 * i for i in range(8)])) + self.assertNotEqual(r["method"], "pairs") + self.assertAlmostEqual(r["result"]["effect"], 0.0, places=6) + self.assertEqual(r["verdict"], "no clear difference") + + def test_one_odd_run_gives_no_verdict(self): + r = ab.abba(items("ABBAABBA", [20.0, 16.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0])) + self.assertEqual(r["verdict"], "no clear difference") + + def test_three_pairs_are_not_enough_for_pairs(self): + r = ab.abba(items("ABBAAB", [20.4, 19.1, 19.6, 20.9, 21.3, 19.8])) + self.assertNotEqual(r["method"], "pairs") + + def test_three_runs_a_side_fit_the_side_and_a_trend(self): + # B is 1 ms faster, and every run is 0.3 ms slower than the one before. + order = "ABBAAB" + values = [20.0 + 0.3 * i - (1.0 if arm == "B" else 0.0) for i, arm in enumerate(order)] + r = ab.abba(items(order, values)) + self.assertEqual(r["method"], "side and linear trend") + self.assertAlmostEqual(r["result"]["effect"], -1.0, places=6) + self.assertAlmostEqual(r["result"]["trend_per_run"], 0.3, places=6) + + def test_a_run_left_out_drops_its_pair(self): + it = items("ABBAABBAAB", [20.4, 19.1, 19.6, 20.9, 21.3, 19.8, 20.2, 21.0, 20.6, 19.4]) + it[2] = ("B", None, None, "gate FAIL") + r = ab.abba(it) + self.assertEqual(len(r["pairs"]), 4) + self.assertEqual(r["runs"][2]["left_out"], "gate FAIL") + + +class Runs(unittest.TestCase): + def setUp(self): + self.dir = tempfile.mkdtemp(prefix="ab-test-") + + def gate(self, name, fps, result="PASS"): + d = os.path.join(self.dir, name) + os.makedirs(d) + with open(os.path.join(d, "summary.json"), "w", encoding="utf-8") as f: + json.dump({"fps": {"median": fps, "draws_median": 4400}, "verdict": {"result": result}}, f) + return d + + def log(self, name, fps_values, draws): + path = os.path.join(self.dir, name) + with open(path, "w", encoding="utf-8") as f: + for fps in fps_values: + f.write(f"2026-11-30T18:00:00.000000Z INFO leonida_gpu::host: {fps:.1f} fps, {1000 / fps:.1f} ms/frame " + f"(1.0 preparing: copies 0.1 ms 0.1 MB, textures 0.1 ms 0.1 MB; 5.0 on the GPU; 0.0 copying back " + f"0.0 MB), {draws} draws/frame, dropped 0 without a host pipeline (0 being made) and 0 indirect\n") + f.write("a line the title printed: keep it out\n") + return path + + def test_a_gate_folder_gives_its_world_median_and_a_failed_gate_is_left_out(self): + self.assertAlmostEqual(ab.run_value(self.gate("ok", 25.0))[0], 40.0) + self.assertEqual(ab.run_value(self.gate("bad", 25.0, "FAIL"))[2], "gate FAIL") + + def test_a_log_gives_the_median_of_its_world_lines(self): + menus = self.log("menus.log", [60.0] * 5, 13) + world = self.log("world.log", [20.0, 25.0, 25.0], 4000) + self.assertEqual(ab.run_value(menus)[2], "no frame line in the world") + self.assertAlmostEqual(ab.run_value(world)[0], 40.0) + + def test_the_command_prints_numbers_only(self): + runs = [] + for i, (arm, fps) in enumerate(zip("ABBAABBA", [25, 26, 26, 25, 25, 26, 26, 25])): + runs.append(f"{arm}:" + self.gate(f"r{i}", float(fps))) + out = io.StringIO() + with redirect_stdout(out): + self.assertEqual(ab.main(["abba"] + runs), 0) + text = out.getvalue() + self.assertIn("verdict: B faster", text) + self.assertNotIn(self.dir, text) + + +class Phases(unittest.TestCase): + def test_a_switch_effect_and_its_counters_per_pair_of_blocks(self): + path = os.path.join(tempfile.mkdtemp(prefix="ab-phases-"), "run.log") + with open(path, "w", encoding="utf-8") as f: + for n in range(12): + on = n % 2 + median = 30.0 - (1.0 if on else 0.0) + 0.01 * n + f.write(f"2026-11-30T18:00:{n:02d}.000000Z INFO leonida_gpu::ab: A/B phase {n} bits {on} on [{'LEONIDA_X' if on else ''}]: " + f"200 frames, mean {median:.1f} ms, median {median:.2f}, p90 {median + 5:.1f}, 4400 draws a frame; rest\n") + f.write(f"2026-11-30T18:00:{n:02d}.500000Z INFO leonida_gpu::ab: A/B counters phase {n} bits {on}: " + f"protect_ms={(2.0 if on else 8.0):.3f} kernel_asks=3.00\n") + r = ab.phase_effects(ab.read_phases(path)) + s = r["switches"][0] + self.assertEqual(s["pairs"], 6) + self.assertAlmostEqual(s["effects"]["median"]["effect"], -0.99, places=2) + self.assertAlmostEqual(s["effects"]["protect_ms"]["effect"], -6.0, places=6) + self.assertEqual(s["verdict"], "B faster") + + def test_a_scene_change_between_blocks_is_left_out(self): + phases = {0: {"bits": 0, "median": 30.0, "draws": 4000.0, "counters": {}}, + 1: {"bits": 1, "median": 20.0, "draws": 9000.0, "counters": {}}} + s = ab.phase_effects(phases)["switches"][0] + self.assertEqual((s["pairs"], s["left_out_for_draws"]), (0, 1)) + + +class Plan(unittest.TestCase): + def test_builds_end_the_warm_up_on_the_first_measured_side(self): + p = ab.plan(4, switch=False) + self.assertEqual(p["warm_up_and_discarded"], ["warm-up A", "warm-up B", "discarded B", "discarded A"]) + self.assertEqual("".join(p["measured"]), "ABBAABBA") + + def test_one_exe_two_settings_discards_one_run(self): + self.assertEqual(ab.plan(2, switch=True)["warm_up_and_discarded"], ["warm-up A", "warm-up B", "discarded A"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/d3d12_ab_compare.py b/tools/d3d12_ab_compare.py new file mode 100644 index 0000000000..266f346d40 --- /dev/null +++ b/tools/d3d12_ab_compare.py @@ -0,0 +1,313 @@ +"""Reads an A/B of the D3D12 runtime: numbers only, never log text. + + python -I tools/d3d12_ab_compare.py abba A: B: B: A: ... [--json] + python -I tools/d3d12_ab_compare.py phases [--keep-draw-jumps] [--json] + python -I tools/d3d12_ab_compare.py plan --pairs 4 [--switch] [--json] + +`abba` compares separate runs given in the order they were run (docs/measuring_fps.md, section 3). A run is a +folder of scripts/game-gate.ps1 (its summary.json: the median of the presents' frame times in the world, and a run +whose verdict is not PASS is left out) or a log (the frame lines of tools/d3d12_run_fps.py with 1,000 draws a frame +or more: the world). Each run gives one value, its median frame time in ms: frames within a run follow each other +and are not independent samples, so a run is the unit. + +Neighbouring runs pair up, (1, 2), (3, 4), ...: each pair gives B - A. With an ABBA order a linear drift (a cache +warming, a machine heating) adds as much to the pairs where A came first as it takes from those where B did, so the +pairs must be balanced. The effect is the mean of the differences with its standard error and a 95 % t interval, +from at least 4 pairs. 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 but at most one pair agree in sign; +otherwise "no clear difference", or why it could not tell. + +`phases` reads one run with LEONIDA_AB (section 2): each `A/B phase bits ` line, and the `A/B counters` +line after it where the runtime writes one. For switch number s the phases come in blocks of 2^s off then 2^s on; +each neighbouring pair of blocks gives one difference (on - off) of the median frame time and of each counter. A +pair whose draws a frame differ by more than a tenth is a change of scene, not of the switch, and is left out +(--keep-draw-jumps keeps it). + +`plan` prints a balanced order: warm-up runs, a discarded run of the first measured side, then ABBA pairs. + +Standard library only; reads files, never runs them; prints no log line, path or argument text. +""" + +from __future__ import annotations + +import argparse +import json +import math +import os +import re +import statistics +import sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import d3d12_run_fps # noqa: E402 (the frame line reader) + +# Two-sided 95 % Student t, by degrees of freedom. +T95 = [12.706, 4.303, 3.182, 2.776, 2.571, 2.447, 2.365, 2.306, 2.262, 2.228, 2.201, 2.179, 2.160, 2.145, 2.131, + 2.120, 2.110, 2.101, 2.093, 2.086, 2.080, 2.074, 2.069, 2.064, 2.060, 2.056, 2.052, 2.048, 2.045, 2.042] +WORLD_DRAWS = 1000 +PHASE = re.compile(r"A/B phase (\d+) bits (\d+) on \[[^\]]*\]: (\d+) frames, mean ([\d.]+) ms, median ([\d.]+), " + r"p90 ([\d.]+), ([\d.]+) draws a frame") +COUNTERS = re.compile(r"A/B counters phase (\d+) bits (\d+): (.*)$") +COUNTER = re.compile(r"([a-z_]+)=([\d.]+)") + + +def t95(df): + return T95[df - 1] if 1 <= df <= len(T95) else 1.96 + + +def effect(diffs): + """Mean, standard error, 95 % interval, median and sign agreement of pair differences.""" + k = len(diffs) + mean = statistics.fmean(diffs) + se = statistics.stdev(diffs) / math.sqrt(k) if k > 1 else None + half = t95(k - 1) * se if se is not None else None + agree = max(sum(1 for d in diffs if d < 0), sum(1 for d in diffs if d > 0)) + return {"k": k, "effect": mean, "se": se, "ci95": [mean - half, mean + half] if half is not None else None, + "median": statistics.median(diffs), "agree": agree} + + +def verdict(e, lower_is_faster=True): + if e["ci95"] is None: + return "not enough runs" + lo, hi = e["ci95"] + if (lo > 0 or hi < 0) and e["agree"] >= e["k"] - 1: + faster = (hi < 0) == lower_is_faster + return "B faster" if faster else "B slower" + return "no clear difference" + + +def solve3(m, v): + """Solves a 3x3 system by Gauss-Jordan; also returns the inverse's diagonal.""" + a = [row[:] + [v[i]] + [1.0 if j == i else 0.0 for j in range(3)] for i, row in enumerate(m)] + for c in range(3): + p = max(range(c, 3), key=lambda r: abs(a[r][c])) + if abs(a[p][c]) < 1e-12: + return None, None + a[c], a[p] = a[p], a[c] + pivot = a[c][c] + a[c] = [x / pivot for x in a[c]] + for r in range(3): + if r != c: + f = a[r][c] + a[r] = [x - f * y for x, y in zip(a[r], a[c])] + return [a[i][3] for i in range(3)], [a[i][4 + i] for i in range(3)] + + +def trend_fit(runs): + """value = a + b*[B] + c*position, least squares: the effect b, its standard error and interval.""" + xs = [(1.0, 1.0 if arm == "B" else 0.0, float(pos)) for pos, arm, _ in runs] + ys = [value for _, _, value in runs] + xtx = [[sum(x[i] * x[j] for x in xs) for j in range(3)] for i in range(3)] + xty = [sum(x[i] * y for x, y in zip(xs, ys)) for i in range(3)] + beta, diag = solve3(xtx, xty) + df = len(runs) - 3 + if beta is None or df < 1: + return None + sse = sum((y - sum(b * xi for b, xi in zip(beta, x))) ** 2 for x, y in zip(xs, ys)) + se = math.sqrt(sse / df * diag[1]) + half = t95(df) * se + return {"k": len(runs), "effect": beta[1], "se": se, "ci95": [beta[1] - half, beta[1] + half], "median": None, + "agree": len(runs), "trend_per_run": beta[2], "df": df} + + +def run_value(path): + """(frame ms, draws a frame, why left out or None) of one run.""" + summary = os.path.join(path, "summary.json") if os.path.isdir(path) else None + if summary: + if not os.path.exists(summary): + return None, None, "no summary" + with open(summary, encoding="utf-8") as f: + s = json.load(f) + fps = (s.get("fps") or {}).get("median") + result = (s.get("verdict") or {}).get("result") + if result != "PASS": + return None, None, f"gate {result or 'unknown'}" + if not fps: + return None, None, "no frame rate" + return 1000.0 / fps, (s.get("fps") or {}).get("draws_median"), None + world = [x for x in d3d12_run_fps.read_samples(path) if x["draws"] >= WORLD_DRAWS] + if not world: + return None, None, "no frame line in the world" + return statistics.median(x["frame_ms"] for x in world), statistics.median(x["draws"] for x in world), None + + +def abba(items): + """items: [(arm, frame ms or None, draws, why)] in run order.""" + runs = [{"position": i + 1, "arm": arm, "frame_ms": ms, "draws": draws, "left_out": why} + for i, (arm, ms, draws, why) in enumerate(items)] + pairs = [] + for a, b in zip(runs[0::2], runs[1::2]): + if a["arm"] == b["arm"] or a["left_out"] or b["left_out"]: + continue + first, second = (a, b) if a["arm"] == "A" else (b, a) + pairs.append({"positions": [a["position"], b["position"]], "a_first": a["arm"] == "A", + "diff": second["frame_ms"] - first["frame_ms"]}) + used = [r for r in runs if not r["left_out"]] + out = {"metric": "world median frame time, ms (B - A; below 0: B faster)", "runs": runs, "pairs": pairs} + a_first = sum(1 for p in pairs if p["a_first"]) + balanced = bool(pairs) and a_first * 2 == len(pairs) + if len(pairs) >= 4 and balanced: + e = effect([p["diff"] for p in pairs]) + out["method"] = "pairs" + out["result"] = e + out["verdict"] = verdict(e) + elif sum(1 for r in used if r["arm"] == "A") >= 3 and sum(1 for r in used if r["arm"] == "B") >= 3: + fit = trend_fit([(r["position"], r["arm"], r["frame_ms"]) for r in used]) + out["method"] = "side and linear trend" + out["result"] = fit + out["verdict"] = verdict(fit) if fit else "not enough runs" + else: + out["method"] = None + out["result"] = None + out["verdict"] = "unbalanced pairs" if pairs and not balanced else "not enough runs" + means = {arm: statistics.fmean(r["frame_ms"] for r in used if r["arm"] == arm) + for arm in ("A", "B") if any(r["arm"] == arm for r in used)} + out["means"] = means + if out["result"] and "A" in means: + out["percent"] = 100.0 * out["result"]["effect"] / means["A"] + return out + + +def read_phases(path): + """{phase number: {"bits", "median", "draws", counters...}} from a LEONIDA_AB run's log.""" + phases = {} + for line in d3d12_run_fps._lines(path): + text = d3d12_run_fps.ANSI.sub("", line) + m = PHASE.search(text) + if m: + n = int(m.group(1)) + phases[n] = {"bits": int(m.group(2)), "median": float(m.group(5)), "draws": float(m.group(7)), + "counters": {}} + continue + m = COUNTERS.search(text) + if m and int(m.group(1)) in phases: + phases[int(m.group(1))]["counters"] = {k: float(v) for k, v in COUNTER.findall(m.group(3))} + return phases + + +def phase_effects(phases, keep_jumps=False): + if not phases: + return {"switches": []} + switches = max(p["bits"] for p in phases.values()).bit_length() or 1 + out = [] + for s in range(switches): + size = 1 << s + blocks = {} + for n, p in phases.items(): + blocks.setdefault(n // size, []).append(p) + diffs, jumps, names = [], 0, set() + for j in sorted(blocks): + if j % 2 or j + 1 not in blocks: + continue + off, on = blocks[j], blocks[j + 1] + draws_off = statistics.fmean(p["draws"] for p in off) + draws_on = statistics.fmean(p["draws"] for p in on) + if not keep_jumps and abs(draws_on - draws_off) > 0.1 * max(draws_off, 1.0): + jumps += 1 + continue + row = {"median": statistics.fmean(p["median"] for p in on) - statistics.fmean(p["median"] for p in off)} + for p in off + on: + names.update(p["counters"]) + for name in names: + row[name] = (statistics.fmean(p["counters"].get(name, 0.0) for p in on) + - statistics.fmean(p["counters"].get(name, 0.0) for p in off)) + diffs.append(row) + effects = {} + for name in ["median"] + sorted(names): + values = [d[name] for d in diffs if name in d] + if len(values) >= 2: + effects[name] = effect(values) + out.append({"switch": s, "pairs": len(diffs), "left_out_for_draws": jumps, "effects": effects, + "verdict": verdict(effects["median"]) if "median" in effects else "not enough phases"}) + return {"switches": out} + + +def plan(pairs, switch): + warm = ["warm-up A", "warm-up B"] + discard = ["discarded A"] if switch else ["discarded B", "discarded A"] + order = [] + for i in range(pairs): + order += ["A", "B"] if i % 2 == 0 else ["B", "A"] + return {"warm_up_and_discarded": warm + discard, "measured": order, + "note": "pairs (1,2), (3,4), ... of the measured runs; an even count balances the drift"} + + +def number(x, digits=2): + return "-" if x is None else f"{x:+.{digits}f}" if digits else f"{x}" + + +def render_abba(r): + lines = [f"metric: {r['metric']}"] + for run in r["runs"]: + value = "left out" if run["left_out"] else f"{run['frame_ms']:.2f} ms" + lines.append(f" run {run['position']} {run['arm']}: {value}" + (f" ({run['left_out']})" if run["left_out"] else "")) + for arm, mean in r["means"].items(): + lines.append(f" mean {arm}: {mean:.2f} ms") + e = r["result"] + if e: + ci = e["ci95"] + lines.append(f"{r['method']}: effect {number(e['effect'])} ms ({number(r.get('percent'), 1)} %), standard error " + f"{e['se']:.2f}, 95 % [{ci[0]:+.2f}, {ci[1]:+.2f}], {e['k']} " + ("pairs" if r["method"] == "pairs" else "runs") + + (f", {e['agree']} of {e['k']} agree in sign" if r["method"] == "pairs" else "")) + lines.append(f"verdict: {r['verdict']}") + return "\n".join(lines) + "\n" + + +def render_phases(r): + lines = [] + for s in r["switches"]: + lines.append(f"switch {s['switch']}: {s['pairs']} pairs of blocks, {s['left_out_for_draws']} left out for a draw jump; " + f"verdict on the median frame time: {s['verdict']}") + for name, e in s["effects"].items(): + lines.append(f" {name}: {number(e['effect'], 3)} +- {e['se']:.3f} ({e['k']} pairs)") + return "\n".join(lines) + "\n" if lines else "no A/B phase lines\n" + + +def main(argv=None): + parser = argparse.ArgumentParser(description="Reads an A/B of the D3D12 runtime.") + sub = parser.add_subparsers(dest="command", required=True) + p = sub.add_parser("abba") + p.add_argument("runs", nargs="+") + p.add_argument("--json", action="store_true") + p = sub.add_parser("phases") + p.add_argument("log") + p.add_argument("--keep-draw-jumps", action="store_true") + p.add_argument("--json", action="store_true") + p = sub.add_parser("plan") + p.add_argument("--pairs", type=int, default=4) + p.add_argument("--switch", action="store_true") + p.add_argument("--json", action="store_true") + args = parser.parse_args(argv) + if args.command == "abba": + items = [] + for item in args.runs: + arm, sep, path = item.partition(":") + if not sep or arm not in ("A", "B") or not path: + print("each run is A: or B:", file=sys.stderr) + return 2 + if not os.path.exists(path): + print("a run given does not exist", file=sys.stderr) + return 2 + items.append((arm,) + run_value(path)) + result = abba(items) + print(json.dumps(result, indent=2) if args.json else render_abba(result), end="" if not args.json else "\n") + return 0 + if args.command == "phases": + if not os.path.exists(args.log): + print("the log given does not exist", file=sys.stderr) + return 2 + result = phase_effects(read_phases(args.log), args.keep_draw_jumps) + print(json.dumps(result, indent=2) if args.json else render_phases(result), end="" if not args.json else "\n") + return 0 + result = plan(args.pairs, args.switch) + if args.json: + print(json.dumps(result, indent=2)) + else: + print("first: " + ", ".join(result["warm_up_and_discarded"])) + print("then: " + " ".join(result["measured"])) + print(result["note"]) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) From c05f43403a3e9547c8e1f3776fd3f2174bed3af1 Mon Sep 17 00:00:00 2001 From: TheGeogeo <57634077+TheGeogeo@users.noreply.github.com> Date: Mon, 30 Nov 2026 20:57:07 +0100 Subject: [PATCH 2/3] docs: measuring_fps names no file of another pull request 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. --- docs/measuring_fps.md | 2 +- tools/d3d12_ab_compare.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/measuring_fps.md b/docs/measuring_fps.md index 5c018b015d..c12087226e 100644 --- a/docs/measuring_fps.md +++ b/docs/measuring_fps.md @@ -64,7 +64,7 @@ A change of code, or a switch that cannot be turned in play, needs separate runs 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: B: B: A: ...` - reads the runs in that order (folders of `scripts/game-gate.ps1`, docs/game_gate.md, or logs): one value a run (its + 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. diff --git a/tools/d3d12_ab_compare.py b/tools/d3d12_ab_compare.py index 266f346d40..afb9c039b2 100644 --- a/tools/d3d12_ab_compare.py +++ b/tools/d3d12_ab_compare.py @@ -5,7 +5,7 @@ python -I tools/d3d12_ab_compare.py plan --pairs 4 [--switch] [--json] `abba` compares separate runs given in the order they were run (docs/measuring_fps.md, section 3). A run is a -folder of scripts/game-gate.ps1 (its summary.json: the median of the presents' frame times in the world, and a run +folder of the game gate (its summary.json: the median of the presents' frame times in the world, and a run whose verdict is not PASS is left out) or a log (the frame lines of tools/d3d12_run_fps.py with 1,000 draws a frame or more: the world). Each run gives one value, its median frame time in ms: frames within a run follow each other and are not independent samples, so a run is the unit. From e4318f01f78e8381697ca137ce6434b7e2b4f8c3 Mon Sep 17 00:00:00 2001 From: TheGeogeo <57634077+TheGeogeo@users.noreply.github.com> Date: Mon, 30 Nov 2026 21:29:37 +0100 Subject: [PATCH 3/3] tools: the gate and A/B tools set errors="replace" on stdout 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. --- tools/d3d12_ab_compare.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/d3d12_ab_compare.py b/tools/d3d12_ab_compare.py index afb9c039b2..84e45a27f2 100644 --- a/tools/d3d12_ab_compare.py +++ b/tools/d3d12_ab_compare.py @@ -310,4 +310,8 @@ def main(argv=None): if __name__ == "__main__": + try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode + sys.stdout.reconfigure(errors="replace") + except (AttributeError, ValueError, OSError): + pass sys.exit(main())