diff --git a/docs/settings.md b/docs/settings.md index 4a785afe..14f8207b 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -32,6 +32,7 @@ Many rows below are developer tools that only act together with another setting | `menu_cursor_log` | `1` logs what the menu cursor code reads at every screen change. | Only adds log lines. | Safe | | `plugin_tick_offset` (default `0`) | Added to every GetSystemTick in the plugin service run (`totk.exe --plugin-init DIR`), so `tools/exefs_plugins.py` can run a plugin's init twice with other ticks and compare the records. | Has no effect outside `--plugin-init`; a plugin's init at the start of the game gets the plain ticks. | Safe | | `plugin_trace` (default `0`) | `1` logs the first call of each entry of a mod plugin's hooks (its callbacks, replace and call targets) as `plugins: hook entry ... reached`. | Each such call goes through a counting step; nothing changes without a mod plugin. | Safe | +| `perf_census` (default `1`) | With `TOTK_TRACE=perf` and the import memory mode (`TOTK_MEMORY=import`, the automatic mode on an integrated GPU; the mirror mode of a discrete GPU has its own `mem:` lines instead of the census), `0` turns off the dirty census: the `mem: dirty` lines that count, at every submit, the pages the CPU wrote in the pools the replay binds as buffers. | The census queries the write watch at every submit, 3.5-5 ms of the replay thread a frame on a Steam Deck; with `0` a perf trace measures the frame without that cost, and `tools/perf_summary.py` prints no dirty lines. | Safe | | `perf_slow_ms` (default `50`) | Frames at least this many milliseconds long get a `perf: slow frame` log line with the time blocked per cause. | Changes how many frames are logged; a small value fills the log. | Safe | | `replay_check` | `1` reads every texture read-back a second time after a full drain of the replay queue and compares the two. | Stalls the replay queue at every read-back, so frames get much slower; mismatches are only counted and logged. | Caution | | `resolve_check` | `1` compares every cached pool lookup with the locked lookup and stops on a difference. | Slows every pool lookup; the game stops if the two ever differ. | Caution | diff --git a/runtime/cfg.c b/runtime/cfg.c index 9349ac04..74cb8270 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -57,7 +57,7 @@ static const char *const known[] = { "MEM_RESERVE_MIB", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_NO_CODE", "MODS_ORDER", "MODS_REBUILD", "MODS_WITHOUT_CODE", "MOTION", "MOUSE_AIM_SCALE", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_ASPECT", "MOVIE_HOST", "MOVIE_PACE", "MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK", "MV_SURVEY", - "ONE_PER_CORE", "OPERATION_MODE", "OPTREF_GUARD", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "PLUGIN_TICK_OFFSET", "PLUGIN_TRACE", "POINTER_IMAGE", + "ONE_PER_CORE", "OPERATION_MODE", "OPTREF_GUARD", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_CENSUS", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "PLUGIN_TICK_OFFSET", "PLUGIN_TRACE", "POINTER_IMAGE", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_BENCH", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES", "PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "QUICKLOAD_KEY", "QUICKSAVE", "QUICKSAVE_KEY", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", "REFLEX", "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS", diff --git a/runtime/vk.h b/runtime/vk.h index 55094c1d..2e1e20e1 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -244,9 +244,12 @@ void vk_mem_count_flush(int64_t (*acc)[VK_MUSE_N]); // TOTK_TRACE=perf dirty census (vk_memory.c): the replay notes each imported pool it binds as a vertex, index, uniform, // storage or indirect buffer; at the start of every submit the pages the CPU wrote in such pools since the previous // submit are counted from the shared page generations and logged as `mem: dirty` every 60 frames. Nothing when tracing -// is off: VK_MEM_BOUND is one flag test at the call site. +// is off: VK_MEM_BOUND is one flag test at the call site. vk_mem_census_on: tracing perf, no mirror, and +// TOTK_PERF_CENSUS not 0 (set at device selection). The census queries the write watch at every submit, which costs +// the replay thread 3.5-5 ms a frame on a Steam Deck (#946), so measurements of the frame turn it off. +extern int vk_mem_census_on; void vk_mem_bound_note(void *pool); -#define VK_MEM_BOUND(sp) do { if ((rt_trace & RT_TRACE_PERF) && (sp).pool) vk_mem_bound_note((sp).pool); } while (0) +#define VK_MEM_BOUND(sp) do { if (vk_mem_census_on && (sp).pool) vk_mem_bound_note((sp).pool); } while (0) void vk_mem_dirty_submit(void); // vk_sync_submit, under its lock, before the replay // VRAM mirror of buffer-bound pools (vk_memory.c). vk_mirror_on: TOTK_MEMORY=mirror|verify, or the // device class is discrete and TOTK_MEMORY is unset or auto; set at device selection. The replay (submitting thread diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index 305d67a3..ec3af7da 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -2986,7 +2986,7 @@ static void bind_vertex_buffers(VkExec *ex) { ex->recorded++; for (int b = lo; b <= hi; b++) { if (D->B.vcls[b]) vk_mem_count(D->B.vcls[b], VK_MUSE_VB, D->B.vsz[b]); - if ((rt_trace & RT_TRACE_PERF) && D->B.vpool[b]) vk_mem_bound_note(D->B.vpool[b]); + if (vk_mem_census_on && D->B.vpool[b]) vk_mem_bound_note(D->B.vpool[b]); } D->B.vb_valid = 1; } diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index baaabef5..7393583c 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -544,7 +544,7 @@ void vk_mem_census(uint64_t frame) { mirror_frame = frame; static uint64_t window_start; if ((rt_trace & RT_TRACE_PERF) && frame % 600 == 0) vram_log(frame); - if ((rt_trace & RT_TRACE_PERF) && !vk_mirror_on) dirty_frame(frame); + if (vk_mem_census_on) dirty_frame(frame); if ((rt_trace & RT_TRACE_PERF) ? frame % 60 == 0 : frame == 600 || frame == 1800) mirror_log(frame), shadow_log(frame); // mirror_log also logs the write-watch line if (frame == 1200) { // loading is over: the first window starts here @@ -1476,7 +1476,7 @@ static void shadow_log(uint64_t frame) { } void vk_mem_dirty_submit(void) { - if (!(rt_trace & RT_TRACE_PERF) || vk_mirror_on) return; // the mirror's own line replaces the census + if (!vk_mem_census_on) return; // tracing off, TOTK_PERF_CENSUS=0, or a mirror (its own line replaces the census) uint64_t t0 = kern_now_ns(); uint32_t prev = dirty_sub; // the submit whose replay noted the bindings dirty_sub = prev + 1 ? prev + 1 : 1; @@ -1627,6 +1627,7 @@ static void dirty_frame(uint64_t frame) { enum { MR_BUDGET, MR_UNTRACKED, MR_OVERLAP, MR_ALLOC, MR_N }; int vk_mirror_on; +int vk_mem_census_on; // vk.h: the TOTK_TRACE=perf dirty census runs (mirror_mode) static int mirror_verify; static int mirror_gap = 2; // pre-snap: hot pools at most this many 2 MiB regions apart share one query static PoolRec **mlist; // pool_lock: mirrored pools by import_lo @@ -1671,6 +1672,11 @@ static void mirror_mode(int discrete) { } vk_mirror_on = mode > 0; mirror_verify = mode == 2; + // The dirty census is a measurement of its own (what a mirror would upload), not part of the frame: with + // TOTK_PERF_CENSUS=0 a perf trace measures the frame without its write-watch queries. + vk_mem_census_on = (rt_trace & RT_TRACE_PERF) && !vk_mirror_on && rt_knob("PERF_CENSUS", "1"); + if ((rt_trace & RT_TRACE_PERF) && !vk_mirror_on && !vk_mem_census_on) + rt_log("mem: dirty census off (TOTK_PERF_CENSUS=0): no `mem: dirty` lines, no write-watch queries for them"); const char *g = cfg_get("TOTK_MIRROR_GAP"); mirror_gap = g && *g ? atoi(g) : 2; if (mirror_gap < 0) mirror_gap = 0;