diff --git a/runtime/cfg.c b/runtime/cfg.c index f18b45b1..c22e5163 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -45,7 +45,7 @@ static const char *const known[] = { "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHECK", "RESOLVE_CHECK", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES", "ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE", - "SHADER_MEMO", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", "SHOTS_FULL", "SPEED_PROBE", "SPLIT_DRAWS", "SWKBD_ANSWER", + "SHADER_MEMO", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", "SHOTS_FULL", "SPEED_PROBE", "SPLIT_DRAWS", "SPLIT_US", "SWKBD_ANSWER", "SWKBD_TEST", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TIMER_1MS", "TRACE", "UPSCALER", "VK_DYN_VERTEX", "VK_NO_FLOAT64", "VK_PRESENT", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION", "VOLUME", "VS_OUTS", "WINDOW_SIZE", "XLATE", "XLATE_ID", "XLATE_PROCS", @@ -68,7 +68,7 @@ static const struct { const char *key, *section; } sections[] = { {"PREWARM_XLATE", "performance"}, {"GPL", "performance"}, {"ASTC", "performance"}, {"MEMORY", "performance"}, {"TEX_ALIAS", "performance"}, {"LOD_GUARD", "performance"}, {"FIX_C0", "performance"}, {"FIX_ZERO", "performance"}, {"BIND_SKIP", "performance"}, {"SHADER_MEMO", "performance"}, {"PIPE_MEMO", "performance"}, {"TEX_MEMO", "performance"}, {"DESC_TEMPLATE", "performance"}, - {"PUSH_SKIP", "performance"}, {"SPLIT_DRAWS", "performance"}, {"VK_VALIDATION", "performance"}, + {"PUSH_SKIP", "performance"}, {"SPLIT_DRAWS", "performance"}, {"SPLIT_US", "performance"}, {"VK_VALIDATION", "performance"}, {"VK_DYN_VERTEX", "performance"}, {"VK_SUBGROUP_PIN", "performance"}, {"TRACE", "diagnostics"}, {"FLIGHT", "diagnostics"}, {"FLIGHT_SPIKE_MS", "diagnostics"}, }; @@ -111,6 +111,7 @@ static const CfgMeta metas[] = { {"BIND_SKIP", "1", "0|1", RESTART}, {"SHADER_MEMO", "1", "0|1", RESTART}, {"PIPE_MEMO", "1", "0|1", RESTART}, {"TEX_MEMO", "1", "0|1", RESTART}, {"DESC_TEMPLATE", "1", "0|1", RESTART}, {"PUSH_SKIP", "1", "0|1", RESTART}, {"SPLIT_DRAWS", "64", "0..1000", RESTART}, + {"SPLIT_US", "1000", "0..20000", RESTART}, // Vulkan {"VK_VALIDATION", "0", "0|1", RESTART}, {"VK_DYN_VERTEX", "", "0|1", RESTART}, {"VK_SUBGROUP_PIN", "1", "0|1", RESTART}, diff --git a/runtime/vk_exec.c b/runtime/vk_exec.c index cdea8a1a..f0dbc146 100644 --- a/runtime/vk_exec.c +++ b/runtime/vk_exec.c @@ -618,20 +618,29 @@ static void set_rt(VkExec *ex, const p_set_rt *r) { // queries are not: a barrier's first scope is everything earlier in submission order, image layouts belong to the image, // and occlusion queries end with their pass. Fences, completion callbacks and reports stay per submission: only the last // part signals the value. nxnative commits every 64 draws between passes; MacNativeGames after 30, then every 40. +// A part also spans at least TOTK_SPLIT_US (1000) of replay time: a split costs about 40 us of the render thread +// (vkQueueSubmit2, a command buffer, the mirror prologue), and a fight frame of 2,000 draws made 15 parts on the 7900X; +// a millisecond of recording is a fraction of a millisecond of GPU work, so the GPU still starts early. static int split_n = -1, split_draws, part_start; +static uint64_t split_ns, part_t0; static uint64_t n_parts, n_subs; static void maybe_split(VkExec *ex) { if (split_n < 0) { split_n = cfg_int("TOTK_SPLIT_DRAWS"); if (split_n < 0) split_n = 0; - rt_log("vk: replay command buffer split every %d draws between passes%s", split_n, split_n ? "" : " (off)"); + int us = cfg_int("TOTK_SPLIT_US"); + split_ns = us > 0 ? (uint64_t)us * 1000 : 0; + rt_log("vk: replay command buffer split every %d draws between passes, parts of at least %d us%s", split_n, + us > 0 ? us : 0, split_n ? "" : " (off)"); } if (!split_n || ex->in_pass || split_draws < split_n) return; + if (split_ns && kern_now_ns() - part_t0 < split_ns) return; // split_draws stays: the next draw asks again split_draws = 0; if (ex->recorded == part_start) return; ex->cb = vk_sync_split(); part_start = ex->recorded; + part_t0 = kern_now_ns(); ex->dirty = VK_EXEC_DIRTY_ALL; vk_exec_draw_new_cb(); n_parts++; @@ -734,6 +743,7 @@ int vk_exec_record(VkCommandBuffer cb, const uint64_t *handles, int n, uint64_t ex->nfbl = 0; // the previous command buffer ended with a full barrier: every image is in GENERAL vk_exec_frame.submits++; split_draws = part_start = 0; + part_t0 = kern_now_ns(); x_here = 1; if (n) vk_mem_mirror_begin(); for (int i = 0; i < n; i++) {