mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-20 20:55:56 +00:00
Run and measure by game time instead of presents: totk.exe --seconds S ends a run once the world clock passed S seconds (run_game.py --seconds, regress.py routes in world seconds), TOTK_AB blocks are seconds of world clock, the perf line carries the world clock, and TOTK_SHOTS=w<lo>-<hi>:<step> takes shots by it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3fb4b8d4b9
commit
72253abcc0
8 files changed
+102
-69
No files matched your search
+25
-11
@@ -8,7 +8,7 @@
|
||||
// reads 2
|
||||
// nvnBootstrapLoader called from main+0xe7eb2c (1.4.3: +0xbe0360) in the graphics bring-up; logs the run
|
||||
// statistics, exits 0
|
||||
// With --frames N the run continues past that call; rt_frame_presented ends it at the Nth present.
|
||||
// With --seconds S the run continues past that call; rt_frame_presented ends it once the world clock passed S.
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -124,7 +124,7 @@ void rt_boot_event(const char *what, Cpu *c, const char *detail) {
|
||||
rt_fatal("boot: first NVN call before the SetFocusHandlingMode checkpoint");
|
||||
printf("boot: first NVN call nvnBootstrapLoader(\"%s\") from main+%#llx\n", detail,
|
||||
(unsigned long long)(ret - main_mod->base));
|
||||
if (rt_config()->frames) return; // --frames: the run goes on to the Nth present
|
||||
if (rt_config()->seconds) return; // --seconds: the run goes on into the world
|
||||
if (rt_trace & RT_TRACE_HOSTCALL) hostfn_report();
|
||||
stats_line();
|
||||
fflush(stdout);
|
||||
@@ -134,7 +134,7 @@ void rt_boot_event(const char *what, Cpu *c, const char *detail) {
|
||||
rt_fatal("boot: unknown boot event %s (%s) from %s", what, detail ? detail : "", at);
|
||||
}
|
||||
|
||||
// ---- --frames N
|
||||
// ---- --seconds S
|
||||
// A PNG with stored (uncompressed) deflate blocks: no compression library, and the shot is only read by tools.
|
||||
// rt_write_png (declared in vk.h) is shared with the TOTK_DUMP frame dump (vk_dump.c).
|
||||
static uint32_t crc32_update(uint32_t crc, const uint8_t *p, size_t n) {
|
||||
@@ -221,23 +221,34 @@ static void save_shot(const tex_t *t, const char *path) {
|
||||
printf("boot: shot %s (%ux%u)\n", path, w, h);
|
||||
}
|
||||
|
||||
// TOTK_SHOTS=lo-hi:step [TOTK_SHOTS_DIR=dir]: every step-th present in [lo, hi] saved as <dir>/f<n>.png, box-filtered
|
||||
// to 480x270 (full size with TOTK_SHOTS_FULL=1), for finding short glitches. Pipeline builds stay asynchronous, so the
|
||||
// TOTK_SHOTS=lo-hi:step [TOTK_SHOTS_DIR=dir]: every step-th present in [lo, hi] saved as <dir>/f<n>.png (n the
|
||||
// present), box-filtered to 480x270; TOTK_SHOTS=w<lo>-<hi>:<step> takes them by world-clock seconds instead, the first
|
||||
// present at or after each step (full size with TOTK_SHOTS_FULL=1), for finding short glitches. Pipeline builds stay asynchronous, so the
|
||||
// pictures show what a player sees.
|
||||
static void series_shot(const tex_t *t, uint64_t n) {
|
||||
static int parsed;
|
||||
static unsigned long long lo, hi, step;
|
||||
static unsigned long long lo, hi, step, next;
|
||||
static const char *dir;
|
||||
static int full;
|
||||
static int full, world;
|
||||
if (!parsed) {
|
||||
full = cfg_get("TOTK_SHOTS_FULL") != NULL;
|
||||
const char *e = cfg_get("TOTK_SHOTS");
|
||||
if (!e || sscanf(e, "%llu-%llu:%llu", &lo, &hi, &step) != 3 || !step) hi = 0;
|
||||
double wl, wh, ws;
|
||||
if (e && e[0] == 'w' && sscanf(e + 1, "%lf-%lf:%lf", &wl, &wh, &ws) == 3 && ws > 0) // world-clock seconds
|
||||
world = 1, lo = (unsigned long long)(wl * 1e6), hi = (unsigned long long)(wh * 1e6),
|
||||
step = (unsigned long long)(ws * 1e6), next = lo;
|
||||
else if (!e || sscanf(e, "%llu-%llu:%llu", &lo, &hi, &step) != 3 || !step) hi = 0;
|
||||
dir = cfg_get("TOTK_SHOTS_DIR") ? cfg_get("TOTK_SHOTS_DIR") : ".";
|
||||
if (hi) CreateDirectoryA(dir, NULL);
|
||||
parsed = 1;
|
||||
}
|
||||
if (n < lo || n > hi || (n - lo) % step) return;
|
||||
if (world) { // the first present at or after each step of the world clock
|
||||
int64_t w = frame_step_world_us();
|
||||
if (w < 0 || (unsigned long long)w < next || next > hi) return;
|
||||
while (next <= (unsigned long long)w) next += step;
|
||||
} else if (n < lo || n > hi || (n - lo) % step) {
|
||||
return;
|
||||
}
|
||||
int fmt = t->d.format;
|
||||
int bgra = fmt == NVN_FORMAT_BGRA8 || fmt == NVN_FORMAT_BGRA8_SRGB;
|
||||
if (!bgra && fmt != NVN_FORMAT_RGBA8 && fmt != NVN_FORMAT_RGBA8_SRGB) return;
|
||||
@@ -269,11 +280,14 @@ static void series_shot(const tex_t *t, uint64_t n) {
|
||||
free(px);
|
||||
}
|
||||
|
||||
// The Nth present ends a --frames run; any other frame is counted by the back end only.
|
||||
// A --seconds run ends at the first present after the world clock (game time since the save's first frame,
|
||||
// frame_step_world_us) passed S seconds, so a run covers the same game time at any frame rate; any other frame is
|
||||
// counted by the back end only.
|
||||
void rt_frame_presented(const tex_t *t, uint64_t n) {
|
||||
const RtConfig *cfg = rt_config();
|
||||
series_shot(t, n);
|
||||
if (!cfg->frames || n != (uint64_t)cfg->frames) return;
|
||||
int64_t w = cfg->seconds ? frame_step_world_us() : -1;
|
||||
if (w < 0 || (double)w < cfg->seconds * 1e6) return;
|
||||
if (cfg->shot) save_shot(t, cfg->shot);
|
||||
GfxStats g = gfx_stats();
|
||||
printf("boot: frames %llu presented (nvn calls %llu, distinct %llu, unimplemented %llu, validation errors %llu, "
|
||||
|
||||
+4
-3
@@ -250,8 +250,9 @@ double frame_step_limit_hz(void); // the frame rate the
|
||||
int64_t frame_step_world_us(void); // game time since the loaded save's first frame, -1 before
|
||||
// (TOTK_FPS_LIMIT, live)
|
||||
uint64_t frame_step_ticks(void); // game time since the first present in 60 Hz ticks (input scripts)
|
||||
// In-launch A/B measurement: TOTK_AB=<presents> splits the run into blocks of that many presents in the order A B B A
|
||||
// (repeated); rt_ab() is 1 in the B blocks, 0 in A blocks and without TOTK_AB. rt_knob(name, def) reads the switch
|
||||
// In-launch A/B measurement: TOTK_AB=<seconds> splits the world clock (frame_step_world_us) into blocks of that much
|
||||
// game time in the order A B B A (repeated); rt_ab() is 1 in the B blocks, 0 in A blocks, before the world clock and
|
||||
// without TOTK_AB. rt_knob(name, def) reads the switch
|
||||
// TOTK_<name> once per call (def when unset): 0 off, 2 for "ab" (on in the B blocks only), 1 for anything else;
|
||||
// callers keep it and test it with RT_KNOB_ON. The perf line counts the B frames of its window (tools/ab_summary.py
|
||||
// compares the windows that are wholly A or wholly B).
|
||||
@@ -261,7 +262,7 @@ int rt_knob(const char *name, const char *def);
|
||||
void frame_step_present(uint64_t display_ns, int interval); // nvnQueuePresentTexture: the frame's display time and
|
||||
// present interval (60 Hz ticks)
|
||||
// ---- boot (boot.c, main.c)
|
||||
typedef struct { const char *exefs, *romfs, *profile; int boot; int frames; const char *shot, *gpu; } RtConfig;
|
||||
typedef struct { const char *exefs, *romfs, *profile; int boot; double seconds; const char *shot, *gpu; } RtConfig;
|
||||
// romfs: directory with romfs.bin and index.json;
|
||||
// frames: --frames N (0 = no limit); shot: --shot
|
||||
// PATH; gpu: TOTK_GPU
|
||||
|
||||
+11
-10
@@ -9,8 +9,9 @@
|
||||
// --probe-astc the compute ASTC decoder against astc_decode_ldr; needs no game files
|
||||
// --probe-movie host VP9 movie::Decoder on one RomFS movie; skips without game data
|
||||
// --boot run the game to the first NVN call
|
||||
// --frames N run the game (implies --boot's start-up) until the Nth present, then exit 0
|
||||
// --shot PNG with --frames: save the Nth frame; env TOTK_GPU=null|vulkan selects the back end
|
||||
// --seconds S run the game (implies --boot's start-up) until the world clock (game time since the loaded
|
||||
// save's first frame) passed S seconds, then exit 0 at that present
|
||||
// --shot PNG with --seconds: save that frame; env TOTK_GPU=null|vulkan selects the back end
|
||||
// (no mode) run the game
|
||||
//
|
||||
// Also here: the runtime services the generated code calls besides rt_dispatch and rt_svc (rt_brk, rt_udf,
|
||||
@@ -390,7 +391,7 @@ static int usage(const char *argv0) {
|
||||
fprintf(stderr, "usage: %s [--exefs DIR] [--romfs DIR] [--profile DIR] [--selftest | --probe-loader | "
|
||||
"--probe-cfg | --probe-kernel | --probe-ipc | --probe-services | --probe-fs | --probe-gfx-abi | "
|
||||
"--probe-nvn | --probe-nvn-tex | --probe-window | --probe-shader | --probe-vkmem | "
|
||||
"--probe-vkexec | --probe-astc | --probe-movie | --prepare-shaders | --warm-shaders | --boot |--frames N [--shot PNG]]\n", argv0);
|
||||
"--probe-vkexec | --probe-astc | --probe-movie | --prepare-shaders | --warm-shaders | --boot |--seconds S [--shot PNG]]\n", argv0);
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -450,12 +451,12 @@ int main(int argc, char **argv) {
|
||||
if (path) {
|
||||
if (++i == argc) return usage(argv[0]);
|
||||
*path = argv[i];
|
||||
} else if (!strcmp(argv[i], "--frames")) {
|
||||
} else if (!strcmp(argv[i], "--seconds")) {
|
||||
char *end;
|
||||
if (++i == argc) return usage(argv[0]);
|
||||
long n = strtol(argv[i], &end, 10);
|
||||
if (*end || n < 1 || n > INT_MAX) return usage(argv[0]);
|
||||
cfg.frames = (int)n;
|
||||
double s = strtod(argv[i], &end);
|
||||
if (*end || !(s > 0) || s > 1e6) return usage(argv[0]);
|
||||
cfg.seconds = s;
|
||||
} else if (!strcmp(argv[i], "--shot")) {
|
||||
if (++i == argc) return usage(argv[0]);
|
||||
cfg.shot = argv[i];
|
||||
@@ -465,10 +466,10 @@ int main(int argc, char **argv) {
|
||||
return usage(argv[0]);
|
||||
}
|
||||
}
|
||||
if (cfg.shot && !cfg.frames) return usage(argv[0]);
|
||||
if (cfg.frames && mode) return usage(argv[0]);
|
||||
if (cfg.shot && !cfg.seconds) return usage(argv[0]);
|
||||
if (cfg.seconds && mode) return usage(argv[0]);
|
||||
if (!mode) {
|
||||
cfg.boot = cfg.frames > 0; // --frames starts the game like --boot, with its checkpoints
|
||||
cfg.boot = cfg.seconds > 0; // --seconds starts the game like --boot, with its checkpoints
|
||||
rt_boot();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ static void ov_nvn_bootstrap(Cpu *c) {
|
||||
if (!name) name = "(null)";
|
||||
static LONG first = 1;
|
||||
if (rt_config()->boot && InterlockedExchange(&first, 0)) rt_boot_event("nvn", c, name); // ends --boot; returns
|
||||
// when --frames goes on
|
||||
// when --seconds goes on
|
||||
ret_x(c, nvn_proc_address(name));
|
||||
}
|
||||
|
||||
|
||||
+9
-8
@@ -369,7 +369,7 @@ void prof_start(void) {
|
||||
out_path = NULL;
|
||||
return;
|
||||
}
|
||||
atexit(prof_write); // a --frames run ends in _exit: boot.c calls prof_write itself first
|
||||
atexit(prof_write); // a --seconds run ends in _exit: boot.c calls prof_write itself first
|
||||
}
|
||||
|
||||
// ---- TOTK_TRACE=perf: frame interval and the time the render thread spends waiting, logged every 60 presents. The
|
||||
@@ -528,13 +528,14 @@ static void perf_gpu_line(uint64_t frame, double interval_ms, double pace_share,
|
||||
}
|
||||
|
||||
int rt_ab(void) {
|
||||
static uint64_t period = UINT64_MAX; // 0: off
|
||||
if (period == UINT64_MAX) {
|
||||
static int64_t period = -1; // us of world clock; 0: off
|
||||
if (period < 0) {
|
||||
const char *e = cfg_get("TOTK_AB");
|
||||
period = e && *e ? strtoull(e, NULL, 10) : 0;
|
||||
period = e && *e ? (int64_t)(atof(e) * 1e6) : 0;
|
||||
}
|
||||
if (!period) return 0;
|
||||
uint64_t k = cur_frame / period % 4;
|
||||
int64_t w = period ? frame_step_world_us() : -1;
|
||||
if (w < 0) return 0; // before the world clock: A
|
||||
int64_t k = w / period % 4;
|
||||
return k == 1 || k == 2;
|
||||
}
|
||||
|
||||
@@ -636,7 +637,7 @@ void perf_present(uint64_t frame) {
|
||||
uint64_t shader_keys, shader_xlated;
|
||||
gfx_shader_counts(&shader_keys, &shader_xlated);
|
||||
if (n && span)
|
||||
rt_log("perf: frame %llu: interval avg %.2f ms max %.2f ms (%.1f fps); render thread blocked: pacing %.0f%% fence %.0f%% drain %.0f%% pipeline build %.0f%% shader xlate %.0f%% texture %.0f%% (astc %.0f%%); pipelines built in background %lld, draws skipped pending %lld, waited %lld, waiting for a shader %lld, one-shot waited %lld; textures uploaded %lld re-uploaded %lld; slowest frame: xlate %.1f ms texture %.1f ms (astc %.1f) pipeline %.1f ms fence %.1f ms; shaders: %llu keys, %llu translated; render busy avg %.2f ms; replay avg %.2f ms; ab %llu/%llu",
|
||||
rt_log("perf: frame %llu: interval avg %.2f ms max %.2f ms (%.1f fps); render thread blocked: pacing %.0f%% fence %.0f%% drain %.0f%% pipeline build %.0f%% shader xlate %.0f%% texture %.0f%% (astc %.0f%%); pipelines built in background %lld, draws skipped pending %lld, waited %lld, waiting for a shader %lld, one-shot waited %lld; textures uploaded %lld re-uploaded %lld; slowest frame: xlate %.1f ms texture %.1f ms (astc %.1f) pipeline %.1f ms fence %.1f ms; shaders: %llu keys, %llu translated; render busy avg %.2f ms; replay avg %.2f ms; ab %llu/%llu; world %.1f s",
|
||||
(unsigned long long)frame, sum / 1e6 / n, max / 1e6, n * 1e9 / sum, 100.0 * wait_ns[PERF_PACE] / span,
|
||||
100.0 * wait_ns[PERF_FENCE] / span, 100.0 * wait_ns[PERF_DRAIN] / span,
|
||||
100.0 * wait_ns[PERF_PIPE] / span, 100.0 * wait_ns[PERF_XLATE] / span,
|
||||
@@ -645,7 +646,7 @@ void perf_present(uint64_t frame) {
|
||||
worst_ns[PERF_ASTC] / 1e6, worst_ns[PERF_PIPE] / 1e6, worst_ns[PERF_FENCE] / 1e6,
|
||||
(unsigned long long)shader_keys, (unsigned long long)shader_xlated,
|
||||
(span > wait_ns[PERF_PACE] ? span - wait_ns[PERF_PACE] : 0) / 1e6 / n,
|
||||
InterlockedExchange64(&replay_ns, 0) / 1e6 / n, (unsigned long long)ab_b, (unsigned long long)n);
|
||||
InterlockedExchange64(&replay_ns, 0) / 1e6 / n, (unsigned long long)ab_b, (unsigned long long)n, frame_step_world_us() / 1e6);
|
||||
if (n && span) perf_gpu_line(frame, sum / 1e6 / n, (double)wait_ns[PERF_PACE] / span, n);
|
||||
sum = max = n = ab_b = 0;
|
||||
memset(wait_ns, 0, sizeof wait_ns);
|
||||
|
||||
+12
-13
@@ -1,40 +1,39 @@
|
||||
"""In-launch A/B summary of a TOTK_AB run (runtime/prof_win.c rt_ab): per perf window of 60 presents wholly in an A or a
|
||||
B block, the frame interval and the replay time; their means per side, and the B - A difference per A B B A cycle.
|
||||
B block, the frame interval and the replay time; their means per frame on each side, and B - A.
|
||||
|
||||
usage: ab_summary.py <log> [--from <frame>]
|
||||
usage: ab_summary.py <log> [--skip <seconds>]
|
||||
"""
|
||||
import argparse
|
||||
import re
|
||||
import statistics
|
||||
import sys
|
||||
|
||||
LINE = re.compile(r'perf: frame (\d+): interval avg ([0-9.]+) ms .*replay avg ([0-9.]+) ms; ab (\d+)/(\d+)')
|
||||
LINE = re.compile(r'perf: frame (\d+): interval avg ([0-9.]+) ms .*replay avg ([0-9.]+) ms; ab (\d+)/(\d+); world (-?[0-9.]+) s')
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument('log')
|
||||
ap.add_argument('--from', dest='lo', type=int, default=0, help='first frame counted (after the load)')
|
||||
ap.add_argument('--skip', type=float, default=10, help='seconds of world clock left out after the load')
|
||||
a = ap.parse_args()
|
||||
side = {0: [], 1: []}
|
||||
for line in open(a.log, encoding='utf-8', errors='replace'):
|
||||
m = LINE.search(line)
|
||||
if not m or int(m.group(1)) < a.lo:
|
||||
if not m or float(m.group(6)) < a.skip:
|
||||
continue
|
||||
b, n = int(m.group(4)), int(m.group(5))
|
||||
if b and b != n:
|
||||
continue # a window across a block edge
|
||||
side[1 if b else 0].append((int(m.group(1)), float(m.group(2)), float(m.group(3))))
|
||||
side[1 if b else 0].append((n, float(m.group(2)), float(m.group(3))))
|
||||
if not side[0] or not side[1]:
|
||||
print('no whole A and B windows (TOTK_AB unset, or the run too short)')
|
||||
return 1
|
||||
def means(w): # per frame over the side's frames: each window weighs its frames
|
||||
frames = sum(x[0] for x in w)
|
||||
return sum(x[0] * x[1] for x in w) / frames, sum(x[0] * x[2] for x in w) / frames, sum(x[0] * x[1] for x in w) / 1000
|
||||
for k, name in ((0, 'A'), (1, 'B')):
|
||||
w = side[k]
|
||||
iv = statistics.mean(x[1] for x in w)
|
||||
rp = statistics.mean(x[2] for x in w)
|
||||
print(f'{name}: {len(w):3d} windows, interval {iv:6.2f} ms ({1000 / iv:5.1f} fps), replay {rp:5.2f} ms')
|
||||
ia, ib = statistics.mean(x[1] for x in side[0]), statistics.mean(x[1] for x in side[1])
|
||||
ra, rb = statistics.mean(x[2] for x in side[0]), statistics.mean(x[2] for x in side[1])
|
||||
iv, rp, secs = means(side[k])
|
||||
print(f'{name}: {len(side[k]):3d} windows ({secs:5.1f} s), interval {iv:6.2f} ms ({1000 / iv:5.1f} fps), replay {rp:5.2f} ms')
|
||||
(ia, ra, _), (ib, rb, _) = means(side[0]), means(side[1])
|
||||
print(f'B - A: interval {ib - ia:+.2f} ms ({100 * (ib - ia) / ia:+.1f}%), replay {rb - ra:+.2f} ms ({100 * (rb - ra) / ra:+.1f}%)')
|
||||
return 0
|
||||
|
||||
|
||||
+34
-19
@@ -14,6 +14,7 @@ own files stay as they are (TOTK_SHADER_CACHE still points at the build's direct
|
||||
import argparse
|
||||
import datetime
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import statistics
|
||||
import subprocess
|
||||
@@ -28,18 +29,20 @@ from regress_score import far_gradient, is_scored, parse_perf, score_frames, vui
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
SAVES = ROOT / 'build' / 'save-backup'
|
||||
SLOW_MS = 50
|
||||
SHOT_STEP = 5
|
||||
SHOT_STEP = 1 / 12 # seconds of world clock between shots
|
||||
TAIL_FRAMES = 30 # shots examined for a dead or stuck ending
|
||||
TAIL_BLACK = 0.9
|
||||
BLACK_LUMA = 12
|
||||
END_SLACK = 120 # frames the log may stop short of the requested count
|
||||
END_SLACK = 2 # seconds of world clock the log may stop short of the requested run
|
||||
|
||||
# name: (save, script, seconds of world clock to run, scored window in world seconds)
|
||||
WORLD = re.compile(r'perf: frame (\d+): interval avg .*; world (-?[0-9.]+) s')
|
||||
|
||||
# name: (save, script, frames, scored window)
|
||||
ROUTES = {
|
||||
'fight': ('user-save-2026-10-21-monsters', 'tools/input/fight.txt', 2600, (1560, 2600)),
|
||||
'rock': ('user-save-2026-10-21-monsters', 'build/recordings/rock-2026-10-22.txt', 3300, (1500, 3300)),
|
||||
'island': ('user-save-2026-10-22-island', 'tools/input/island.txt', 3600, (1500, 3600)),
|
||||
'field': ('user-save-2026-10-21-field', 'tools/input/load_save.txt', 2400, (1560, 2400)),
|
||||
'fight': ('user-save-2026-10-21-monsters', 'tools/input/fight.txt', 18, (1, 18)),
|
||||
'rock': ('user-save-2026-10-21-monsters', 'build/recordings/rock-2026-10-22.txt', 30, (0, 30)),
|
||||
'island': ('user-save-2026-10-22-island', 'tools/input/island.txt', 35, (0, 35)),
|
||||
'field': ('user-save-2026-10-21-field', 'tools/input/load_save.txt', 14, (1, 14)),
|
||||
}
|
||||
|
||||
# metric: (label, lower is better, absolute tolerance, relative tolerance)
|
||||
@@ -74,7 +77,7 @@ def seed_caches(build, base):
|
||||
|
||||
|
||||
def run_route(build, route, i, out, cold, validation):
|
||||
save, script, frames, (lo, hi) = ROUTES[route]
|
||||
save, script, seconds, (lo, hi) = ROUTES[route]
|
||||
run = out / build.name / f'{route}-{i}'
|
||||
shutil.rmtree(run, ignore_errors=True)
|
||||
shots = run / 'shots'
|
||||
@@ -87,7 +90,7 @@ def run_route(build, route, i, out, cold, validation):
|
||||
shutil.copy2(build / name, cache / name)
|
||||
env = {
|
||||
'TOTK_TRACE': 'perf,sched',
|
||||
'TOTK_SHOTS': f'{lo}-{hi}:{SHOT_STEP}',
|
||||
'TOTK_SHOTS': f'w{lo}-{hi}:{SHOT_STEP:.4f}',
|
||||
'TOTK_SHOTS_DIR': str(shots),
|
||||
'TOTK_PIPELINE_CACHE': str(cache / 'pipeline-cache.bin'),
|
||||
}
|
||||
@@ -97,12 +100,12 @@ def run_route(build, route, i, out, cold, validation):
|
||||
env['TOTK_VK_VALIDATION'] = '1'
|
||||
log = run / 'log.txt'
|
||||
cmd = [sys.executable, str(ROOT / 'tools' / 'run_game.py'), str(build), '--save', save,
|
||||
'--script', str(ROOT / script), '--frames', str(frames), '--quiet', '--tag', f'rg-{route}-{i}',
|
||||
'--script', str(ROOT / script), '--seconds', str(seconds), '--quiet', '--tag', f'rg-{route}-{i}',
|
||||
'--log', str(log)]
|
||||
for k, v in env.items():
|
||||
cmd += ['--env', f'{k}={v}']
|
||||
rc = subprocess.run(cmd, cwd=ROOT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
|
||||
score = score_run(log, shots, lo, hi, frames, rc)
|
||||
score = score_run(log, shots, lo, hi, seconds, rc)
|
||||
score['run'] = str(run)
|
||||
(run / 'score.json').write_text(json.dumps(score, indent=1))
|
||||
return score
|
||||
@@ -113,9 +116,25 @@ def black_fraction(img):
|
||||
return sum(grey.histogram()[:BLACK_LUMA]) / (grey.width * grey.height)
|
||||
|
||||
|
||||
def score_run(log, shots, lo, hi, frames, rc):
|
||||
perf = parse_perf(log, lo, hi)
|
||||
def world_frames(text, lo, hi):
|
||||
"""The presents of the world-clock window [lo, hi] seconds, from the perf lines (one per 60 presents), and the
|
||||
world clock of the last one."""
|
||||
lo_n = hi_n = None
|
||||
last = -1.0
|
||||
for m in WORLD.finditer(text):
|
||||
n, w = int(m[1]), float(m[2])
|
||||
last = w
|
||||
if w >= lo and lo_n is None:
|
||||
lo_n = n - 60
|
||||
if w <= hi:
|
||||
hi_n = n
|
||||
return (lo_n or 0), (hi_n or 0), last
|
||||
|
||||
|
||||
def score_run(log, shots, lo, hi, seconds, rc):
|
||||
text = log.read_text(encoding='utf-8', errors='replace') if log.exists() else ''
|
||||
lo, hi, last_world = world_frames(text, lo, hi)
|
||||
perf = parse_perf(log, lo, hi)
|
||||
paths = {int(p.stem[1:]): p for p in shots.glob('f*.png')}
|
||||
fr = score_frames(paths) if paths else {'black_counts': {}, 'flat_frames': [], 'scored': 0, 'total': 0}
|
||||
vuids = vuid_counts(text)
|
||||
@@ -127,10 +146,6 @@ def score_run(log, shots, lo, hi, frames, rc):
|
||||
with Image.open(paths[n]) as im:
|
||||
fractions.append(black_fraction(im.convert('RGB')))
|
||||
tail_black = statistics.mean(fractions)
|
||||
last_frame = 0
|
||||
for line in text.splitlines():
|
||||
if 'perf: frame ' in line:
|
||||
last_frame = int(line.split('perf: frame ')[1].split(':')[0])
|
||||
reasons = []
|
||||
if tail_black > TAIL_BLACK:
|
||||
reasons.append(f'last {len(last)} shots {tail_black:.0%} black (game over?)')
|
||||
@@ -138,8 +153,8 @@ def score_run(log, shots, lo, hi, frames, rc):
|
||||
reasons.append('crashed or no perf lines')
|
||||
if rc != 0:
|
||||
reasons.append(f'exit code {rc}')
|
||||
if last_frame < frames - END_SLACK:
|
||||
reasons.append(f'log stops at frame {last_frame} of {frames}')
|
||||
if last_world < seconds - END_SLACK:
|
||||
reasons.append(f'log stops at {last_world:.1f} s of world clock of {seconds}')
|
||||
return {
|
||||
'rc': rc, 'fps_mean': perf['fps_mean'], 'max_frame_ms': perf['max_frame_ms'],
|
||||
'slow_count': sum(1 for _, ms, _ in perf['slow_frames'] if ms >= SLOW_MS),
|
||||
|
||||
+6
-4
@@ -4,9 +4,9 @@ The user's profile (build/profile) is never written: each run copies it to <exe
|
||||
backup, and deletes the copy afterwards. The log records how many other totk.exe and ninja.exe processes ran, because
|
||||
timings taken next to them are not comparable.
|
||||
|
||||
python tools/run_game.py build/v121 --save user-save-2026-10-21-field --frames 2401 --tag idle --env TOTK_TRACE=perf
|
||||
python tools/run_game.py build/v121 --save user-save-2026-10-21-field --seconds 15 --tag idle --env TOTK_TRACE=perf
|
||||
python tools/run_game.py build/v121-pf --save user-save-2026-10-21-monsters --script tools/input/fight.txt \
|
||||
--frames 2601 --tag fight --quiet --env TOTK_TRACE=perf,sched
|
||||
--seconds 18 --tag fight --quiet --env TOTK_TRACE=perf,sched
|
||||
"""
|
||||
import argparse
|
||||
import ctypes
|
||||
@@ -151,7 +151,9 @@ def main():
|
||||
ap.add_argument('exe_dir', type=Path, help='build directory holding totk.exe')
|
||||
ap.add_argument('--save', help='directory name under build/save-backup; default: the profile as it is')
|
||||
ap.add_argument('--script', type=Path, default=ROOT / 'tools' / 'input' / 'load_save.txt', help='TOTK_INPUT_SCRIPT')
|
||||
ap.add_argument('--frames', type=int, required=True, help='frames to run (shot is taken of the last)')
|
||||
ap.add_argument('--seconds', type=float, required=True,
|
||||
help='game time to run: the run ends once the world clock (game time since the save loaded) passed '
|
||||
'this many seconds (shot is taken of that frame)')
|
||||
ap.add_argument('--tag', default='run', help='names the profile copy and the log')
|
||||
ap.add_argument('--shot', type=Path, help='PNG of the last frame; turns async pipeline builds off (boot.c)')
|
||||
ap.add_argument('--log', type=Path, help='default: <exe dir>/logs/<tag>.log')
|
||||
@@ -178,7 +180,7 @@ def main():
|
||||
for kv in a.env:
|
||||
k, _, v = kv.partition('=')
|
||||
env[k] = v
|
||||
args = [str(exe_dir / 'totk.exe'), '--profile', str(prof), '--frames', str(a.frames)]
|
||||
args = [str(exe_dir / 'totk.exe'), '--profile', str(prof), '--seconds', str(a.seconds)]
|
||||
if a.shot:
|
||||
args += ['--shot', str(a.shot.resolve())]
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user