diff --git a/docs/architecture.md b/docs/architecture.md index 4c3eeba5..9e163323 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -85,8 +85,9 @@ keeps per-core data without locks and relies on that, so the host models it (`ru - Shaders: Ampere (SM86) code is lowered to Maxwell (`tools/xlate/AmpereLowering.cs`) and translated to SPIR-V by the pinned shader translator (`tools/vendor/ryujinx`, 1.3.2) with our patches (`tools/xlate/patches/`), built with .NET 10 NativeAOT as `nx2navi_xlate.exe` and run as separate processes. Translations are cached on disk; shaders and pipelines seen in - play are prepared at the next boot, which waits for them at most `NX2NAVI_PREWARM_WAIT_MS` and then lets them finish - in the background. + play are prepared at the next boot. The game waits for all of it (`runtime/boot.c` `boot_wait`): about half a second + when warm; after a translator, GPU or driver change a "Preparing shaders" screen shows the progress (`ui/menu.cpp` + `menu_boot_frame`). `NX2NAVI_PREWARM_WAIT_MS` caps the wait, after which the rest finishes in the background. - Mesh and task shaders run as `VK_EXT_mesh_shader`; indirect mesh draws read NVN's `{count, first}` record through a ring of Vulkan `{x, y, z}` records filled on the GPU. - Pipelines: `VK_EXT_graphics_pipeline_library` where the driver has it: stage libraries compiled ahead, a fast link diff --git a/runtime/boot.c b/runtime/boot.c index fee60ed4..d32ab68b 100644 --- a/runtime/boot.c +++ b/runtime/boot.c @@ -22,6 +22,7 @@ #include "mods.h" #include "nvn_api.h" #include "platform/platform.h" +#include "ui/menu.h" #include "vk.h" #include "platform/platform.h" @@ -348,6 +349,45 @@ static void prewarm_main(void *arg) { return; } +// rt_boot's wait for the prewarm, polled every 50 ms. A warm start is done in about half a second and shows nothing. +// When the prewarm translates shaders (a new translator, GPU or driver, or an emptied cache) or runs past +// BOOT_SCREEN_MS, the window shows the boot screen with its progress at 10 frames a second, and a black frame once it is +// done. cap_ms (NX2NAVI_PREWARM_WAIT_MS) bounds the wait, 0 none. Without progress for BOOT_STALL_MS (a translator or +// driver that hangs) the guest starts anyway; the prewarm then goes on in the background. +#define BOOT_SCREEN_MS 1000 +#define BOOT_STALL_MS 60000 +static void boot_wait(PlatThread *warm, uint64_t cap_ms) { + uint64_t t0 = plat_now_ms(), moved = t0, shown = 0; + VkPrewarmProgress p, last = {.phase = -1}; + int screen = 0; + while (!plat_thread_join_ns(warm, 50000000ull)) { + uint64_t now = plat_now_ms(); + vk_pipeline_prewarm_progress(&p); + if (p.phase != last.phase || p.sh_done != last.sh_done || p.pipe_done != last.pipe_done) last = p, moved = now; + if ((cap_ms && now - t0 >= cap_ms) || now - moved >= BOOT_STALL_MS) { + plat_thread_detach(warm); + rt_log("boot: the prewarm goes on in the background after %llu ms (%s)", (unsigned long long)(now - t0), + cap_ms && now - t0 >= cap_ms ? "NX2NAVI_PREWARM_WAIT_MS" : "no progress for 60 s"); + break; + } + if (!screen && (p.sh_translated > 0 || now - t0 >= BOOT_SCREEN_MS)) { + screen = 1; + rt_log("boot: preparing shaders on the boot screen (%lld of %lld shaders done, %lld translated)", + (long long)p.sh_done, (long long)p.sh_total, (long long)p.sh_translated); + } + if (screen && now - shown >= 100) { + int pipes = p.phase >= 2; + menu_boot_set(p.phase, pipes ? p.pipe_done : p.sh_done, pipes ? p.pipe_total : p.sh_total); + gfx_present_boot(); + shown = now; + } + } + if (screen) { // the window stays black, not on the last count, until the game's first frame + menu_boot_set(-1, 0, 0); + gfx_present_boot(); + } +} + void rt_boot(void) { check_npdm(); if (!rt_config()->shot) vk_pipeline_async_enable(); // a --shot image must not depend on build timing @@ -366,17 +406,16 @@ void rt_boot(void) { ipc_applet_event_init(); hostfn_seal(); uint64_t held = plat_now_ms(); - // At most NX2NAVI_PREWARM_WAIT_MS (default 3000): a warm start is ready in about 0.3 s, but a cold one (a new - // translator, a new driver) translated 2,132 shaders and built 1,579 pipelines for 9.8 s while the window stayed - // black, for shaders the game first needs in play, well after its intro. Past the wait the prewarm goes on in the - // background; 0 waits for all of it. A --shot image waits for all of it, so that it does not depend on build timing. + // The guest waits for all of the prewarm (boot_wait): a warm start is ready in about half a second; a cold one (a new + // translator, GPU or driver) translated 2,987 shaders in about 11 s and then builds the recorded pipelines, with the + // boot screen showing its progress. Started early instead, the game would meet those shaders in play and wait for + // each one there. NX2NAVI_PREWARM_WAIT_MS caps the wait (0, the default: none); past it the prewarm goes on in the + // background. A --shot image waits for all of it without the screen, so that it does not depend on build timing. const char *pw = cfg_get("NX2NAVI_PREWARM_WAIT_MS"); - uint64_t wait_ms = pw && *pw ? strtoull(pw, NULL, 10) : 3000; - if (warm && (rt_config()->shot || !wait_ms)) plat_thread_join(warm); - else if (warm && !plat_thread_join_ns(warm, wait_ms * 1000000ull)) { - plat_thread_detach(warm); - rt_log("boot: the prewarm goes on in the background after %llu ms", (unsigned long long)wait_ms); - } else if (!warm) vk_pipeline_prewarm(); + uint64_t wait_ms = pw && *pw ? strtoull(pw, NULL, 10) : 0; + if (warm && rt_config()->shot) plat_thread_join(warm); + else if (warm) boot_wait(warm, wait_ms); + else vk_pipeline_prewarm(); held = plat_now_ms() - held; rt_log("boot: guest starts %llu ms after process start (%llu ms of it waiting for the prewarm)", (unsigned long long)(plat_process_uptime_ns() / 1000000), (unsigned long long)held); diff --git a/runtime/gfx.h b/runtime/gfx.h index 0a7752da..fe91ad0d 100644 --- a/runtime/gfx.h +++ b/runtime/gfx.h @@ -63,6 +63,12 @@ const GfxShader *gfx_shader_load_input(const uint8_t iid[32], int xlate); // Boot prewarm: out[i] = gfx_shader_load_input(iids[i], 1) on `threads` threads with up to `procs` translators, then // every other stored input not cached under this translator is translated. Logs progress and the total. void gfx_shader_prewarm(const uint8_t (*iids)[32], size_t n, const GfxShader **out, int threads, int procs); +// How far the running (or last) gfx_shader_prewarm is: shaders done of total, and how many of them it translated (the +// rest were cached). Any thread; the numbers lag the workers by at most 100 ms. +void gfx_shader_prewarm_progress(int64_t *done, int64_t *total, int64_t *translated); +// A black frame with the boot screen (ui/menu.cpp menu_boot_frame) over it: boot.c's wait for the prewarm, on the +// boot thread before the guest runs (nothing else presents then). +void gfx_present_boot(void); // Answers met in play: from this call on, every (program, answers) a gfx_shader_get* call resolves is appended // to shader-answers.bin, and its program to shader-programs.bin, in the directory of `keys_path` (pipeline-keys.bin). void gfx_shader_record_at(const char *keys_path); diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index 8d8ef55c..6b837705 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -748,8 +748,10 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w MenuTarget mt = {c->instance, c->phys, c->device, c->gfx_family, c->gfx_queue, g_sc_hdr ? VK_FORMAT_R8G8B8A8_UNORM : g_sc_fmt, g_sc_ext.width, g_sc_ext.height, cw, ch, g_scaler}; + // without a source image (gfx_present_boot): a black frame with the boot screen int overlay = g_sc_view[idx] && - menu_overlay_frame(__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), &mt, &menu_shot); + (src ? menu_overlay_frame(__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), &mt, &menu_shot) + : menu_boot_frame(&mt)); // NX2NAVI_SHOT_EVERY= with NX2NAVI_SHOT_DIR=: the presented frame as shot_.png every s seconds // (a check of what the window shows, for runs nobody watches) static char shot_path[1100]; @@ -771,7 +773,7 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w } } int cap = (g_capture || menu_shot) && ensure_capture_buffer(); - int thumb = g_th_n && ensure_thumbs(); + int thumb = src && g_th_n && ensure_thumbs(); VkCommandBuffer cb = g_cb[slot]; vkResetCommandBuffer(cb, 0); @@ -786,11 +788,11 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w const int rect[4] = {cx, cy, cw, ch}; int to[4]; // where the picture goes in the swapchain image: {x, y, w, h} gfx_fit_rect(cw, ch, (int)g_sc_ext.width, (int)g_sc_ext.height, to); - if (g_sc_ext.width && g_sc_ext.height) { + if (src && g_sc_ext.width && g_sc_ext.height) { for (int i = 0; i < 4; i++) g_pic[i] = (float)to[i] / (float)(i & 1 ? g_sc_ext.height : g_sc_ext.width); __atomic_store_n(&g_pic_ok, 1, __ATOMIC_RELEASE); } - if (to[2] != (int)g_sc_ext.width || to[3] != (int)g_sc_ext.height) { // black bars beside or above and below it + if (!src || to[2] != (int)g_sc_ext.width || to[3] != (int)g_sc_ext.height) { // black bars beside or above and below it VkClearColorValue black = {.float32 = {0, 0, 0, 1}}; VkImageSubresourceRange all = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; vkCmdClearColorImage(cb, dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &all); @@ -809,8 +811,8 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w // FSR (NX2NAVI_UPSCALER): EASU when the picture's rectangle is larger than the crop, the shrink and RCAS when it is // smaller; else the bilinear blit int fsr = general ? vk_fsr_record(cb, slot, psrc, pfmt, graded ? cw : w, graded ? ch : h, prect, dst, to) : 0; - g_scaler = fsr == 2 ? 3 : fsr ? 2 : cw != to[2] || ch != to[3]; - if (!fsr) { + if (src) g_scaler = fsr == 2 ? 3 : fsr ? 2 : cw != to[2] || ch != to[3]; + if (!fsr && src) { if (general) // a GENERAL source (vk_texture.c images): earlier submissions' writes become visible to the blit here sync_barrier(cb, psrc, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, VK_ACCESS_2_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_READ_BIT); @@ -824,7 +826,7 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w sync_barrier(cb, psrc, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_2_TRANSFER_BIT, 0, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, 0); } - if (!g_sc_hdr) movie_overlay(cb, slot, dst); // a movie frame over the game image (SDR swapchains) + if (!g_sc_hdr && src) movie_overlay(cb, slot, dst); // a movie frame over the game image (SDR swapchains) // last: the image's layout, and the stage and access of its last write, as each step leaves it VkImageLayout last = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; VkPipelineStageFlags2 last_stage = VK_PIPELINE_STAGE_2_TRANSFER_BIT; @@ -914,6 +916,10 @@ void vk_present_blit(VkImage src, VkImageLayout layout, VkFormat fmt, int w, int present_image(src, layout, fmt, w, h, crop, 1); } +// The boot screen on a black frame (menu_boot_frame), without a game image: present_image's paths that read a source +// are skipped. The size only places the picture rectangle, which a frame without a picture leaves as it was. +void gfx_present_boot(void) { present_image(VK_NULL_HANDLE, VK_IMAGE_LAYOUT_UNDEFINED, VK_FORMAT_UNDEFINED, 1920, 1080, NULL, 0); } + void vk_present_flip(void) { plat_rmutex_lock(&g_pl); flip_locked(); diff --git a/runtime/gfx_shader.c b/runtime/gfx_shader.c index e918809c..5ccfe053 100644 --- a/runtime/gfx_shader.c +++ b/runtime/gfx_shader.c @@ -1747,6 +1747,16 @@ typedef struct { volatile int32_t missing, other_cached; } Warm; +// The running prewarm's numbers for gfx_shader_prewarm_progress (boot.c's wait screen), copied from its Warm while it +// waits for the workers: the Warm lives on that function's stack. +static int64_t pw_done, pw_total, pw_xlated; + +void gfx_shader_prewarm_progress(int64_t *done, int64_t *total, int64_t *translated) { + *done = __atomic_load_n(&pw_done, __ATOMIC_RELAXED); + *total = __atomic_load_n(&pw_total, __ATOMIC_RELAXED); + *translated = __atomic_load_n(&pw_xlated, __ATOMIC_RELAXED); +} + static void warm_worker(void *arg) { Warm *w = arg; for (;;) { @@ -1822,6 +1832,9 @@ void gfx_shader_prewarm(const uint8_t (*iids)[32], size_t n, const GfxShader **o w.n_other = other_inputs(sorted, sorted ? n : 0, &w.other); free(sorted); size_t total = w.n_named + w.n_other; + __atomic_store_n(&pw_done, 0, __ATOMIC_RELAXED); + __atomic_store_n(&pw_xlated, 0, __ATOMIC_RELAXED); + __atomic_store_n(&pw_total, (int64_t)total, __ATOMIC_RELAXED); threads = threads < 1 ? 1 : threads > 64 ? 64 : threads; if ((size_t)threads > total) threads = (int)(total ? total : 1); svc_set_limit(procs); @@ -1830,10 +1843,18 @@ void gfx_shader_prewarm(const uint8_t (*iids)[32], size_t n, const GfxShader **o for (int i = 0; i < threads; i++) if ((t[k] = plat_thread_new(warm_worker, &w, "shader prewarm"))) k++; if (!k) warm_worker(&w); + double logged = (double)plat_now_ms(); for (int m = 0; m < k; m++) - while (!plat_thread_join_ns(t[m], 2000000000u)) + while (!plat_thread_join_ns(t[m], 100000000u)) { // every 100 ms the numbers, every 2 s a log line + __atomic_store_n(&pw_done, (int64_t)w.done, __ATOMIC_RELAXED); + __atomic_store_n(&pw_xlated, (int64_t)((uint64_t)n_xlated - xl0), __ATOMIC_RELAXED); + if ((double)plat_now_ms() - logged < 2000) continue; + logged = (double)plat_now_ms(); rt_log("gfx_shader: prewarm: %lld of %zu shaders, %llu translated, %.0f ms", (long long)w.done, total, (unsigned long long)((uint64_t)n_xlated - xl0), (double)plat_now_ms() - t0); + } + __atomic_store_n(&pw_done, (int64_t)total, __ATOMIC_RELAXED); + __atomic_store_n(&pw_xlated, (int64_t)((uint64_t)n_xlated - xl0), __ATOMIC_RELAXED); svc_set_limit(svc_runtime_limit()); rt_log("gfx_shader: prewarm: %zu shaders named by pipeline keys (%ld not available), %zu other stored inputs (%ld " "cached); %llu translated, %llu failed, with up to %d translators and %d threads, in %.0f ms", w.n_named, diff --git a/runtime/romfs.c b/runtime/romfs.c index 8f4f01b7..99ef89ed 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -1026,8 +1026,10 @@ const char *romfs_entry(uint64_t i, uint64_t *offset, uint64_t *size) { const char *romfs_image_path(void) { return image_file; } // The whole of a RomFS file by its path from the RomFS root, for host-side readers (menu_sound.c: the game's own // interface sounds); malloc'd, NULL when the file is absent or not in the image (an added mod file). The original -// file, not a mod's replacement. +// file, not a mod's replacement. Opens the RomFS when nothing has yet: the boot screen (ui/menu.cpp menu_boot_frame) +// loads the menu's fonts before the guest's first file access. uint8_t *romfs_load(const char *rel, uint64_t *size_out) { + fs_init(); if (!rel || !image) return NULL; uint64_t i = file_index(rel); if (i >= file_count) return NULL; diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index eff5dcf5..68855d76 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -1407,6 +1407,92 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha return ImGui::GetDrawData()->TotalVtxCount > 0; } +// ---- the boot screen (boot.c's wait for the prewarm; gfx_present_boot presents it on a black frame) + +static std::atomic g_boot_phase; +static std::atomic g_boot_done, g_boot_total; +static uint64_t g_boot_t0; + +extern "C" void menu_boot_set(int phase, long long done, long long total) { + g_boot_done.store(done, std::memory_order_relaxed); + g_boot_total.store(total, std::memory_order_relaxed); + g_boot_phase.store(phase, std::memory_order_release); +} + +// A panel in the middle of the screen in the menu's colours: the title, the step with its count and a bar, and why it +// happens. The input queue is left alone: keys pressed now reach the menu once the game runs. +extern "C" int menu_boot_frame(const MenuTarget *t) { + if (g_failed_flag() || g_boot_phase.load(std::memory_order_acquire) < 0) return 0; // -1: done, a black frame + if (!g_ctx_ok) make_context(); + float scale = menu_scale(t->height); + if (!vk_up(t) || (g_font_scale != scale && !fonts_up(scale))) { + rt_log("menu: Dear ImGui Vulkan back end set-up failed; no boot screen, and the menu stays closed"); + g_failed.store(1); + return 0; + } + if (g_style_scale != scale) { + ImGui::GetStyle() = g_base_style; + ImGui::GetStyle().ScaleAllSizes(scale); + g_style_scale = scale; + } + uint64_t now = plat_now_ns(); + if (!g_boot_t0) g_boot_t0 = now; + ImGuiIO &io = ImGui::GetIO(); + io.DisplaySize = ImVec2((float)t->width, (float)t->height); + double dt = g_last_ns ? (now - g_last_ns) / 1e9 : 1 / 60.0; + io.DeltaTime = (float)(dt < 1e-4 ? 1e-4 : dt > 0.1 ? 0.1 : dt); + g_last_ns = now; + ImGui_ImplVulkan_NewFrame(); + ImGui::NewFrame(); + + int phase = g_boot_phase.load(std::memory_order_acquire); + long long done = g_boot_done.load(std::memory_order_relaxed), total = g_boot_total.load(std::memory_order_relaxed); + char step[160]; + if (phase == 1 || phase == 2) + snprintf(step, sizeof step, ui_text(phase == 1 ? UI_BOOT_SHADERS : UI_BOOT_PIPELINES), done, total); + else + snprintf(step, sizeof step, "%s", ui_text(UI_BOOT_STARTING)); + const char *title = ui_text(UI_BOOT_TITLE), *hint = ui_text(UI_BOOT_HINT); + + ImDrawList *dl = ImGui::GetForegroundDrawList(); + float w = (float)t->width, h = (float)t->height, pad = 34 * scale, gap = 16 * scale; + ImFont *body = ImGui::GetFont(); + float body_px = ImGui::GetFontSize(); + ImFont *head = g_title_font ? g_title_font : body; + float head_px = g_title_font ? g_title_font->FontSize : body_px * 1.2f; + ImVec2 ts = head->CalcTextSizeA(head_px, FLT_MAX, 0, title), ss = body->CalcTextSizeA(body_px, FLT_MAX, 0, step), + hs = body->CalcTextSizeA(body_px * 0.8f, FLT_MAX, 0, hint); + float bar_h = 10 * scale; + float pw = fmaxf(fmaxf(ts.x, hs.x), 560 * scale) + pad * 2; + float ph = pad + ts.y + gap * 1.5f + ss.y + gap * 0.6f + bar_h + gap * 1.4f + hs.y + pad; + ImVec2 a((w - pw) / 2, (h - ph) / 2), b(a.x + pw, a.y + ph); + ImU32 gold = ImGui::GetColorU32(kGold), panel = ImGui::GetColorU32(kNavy); + ImU32 text = IM_COL32(236, 224, 196, 255), dim = IM_COL32(236, 224, 196, 150); + dl->AddRectFilled(a, b, panel, 10 * scale); + dl->AddRect(a, b, IM_COL32(237, 194, 97, 140), 10 * scale, 0, 1.5f * scale); + float y = a.y + pad; + dl->AddText(head, head_px, ImVec2((w - ts.x) / 2, y), gold, title); + y += ts.y + gap * 1.5f; + dl->AddText(body, body_px, ImVec2(a.x + pad, y), text, step); + y += ss.y + gap * 0.6f; + ImVec2 ba(a.x + pad, y), bb(b.x - pad, y + bar_h); + dl->AddRectFilled(ba, bb, IM_COL32(255, 255, 255, 28), bar_h / 2); + if ((phase == 1 || phase == 2) && total > 0) { + float f = (float)done / (float)total; + f = f < 0 ? 0 : f > 1 ? 1 : f; + if (f > 0) dl->AddRectFilled(ba, ImVec2(ba.x + (bb.x - ba.x) * f, bb.y), gold, bar_h / 2); + } else { // no count yet: a short segment sweeps along the bar + float span = (bb.x - ba.x) * 0.2f, run = (bb.x - ba.x) - span; + float s = (float)fmod((now - g_boot_t0) / 1e9 * 0.8, 2.0); + float x = ba.x + run * (s < 1 ? s : 2 - s); + dl->AddRectFilled(ImVec2(x, ba.y), ImVec2(x + span, bb.y), gold, bar_h / 2); + } + y += bar_h + gap * 1.4f; + dl->AddText(body, body_px * 0.8f, ImVec2((w - hs.x) / 2, y), dim, hint); + ImGui::Render(); + return ImGui::GetDrawData()->TotalVtxCount > 0; +} + extern "C" void menu_overlay_draw(VkCommandBuffer cb) { uint64_t t0 = plat_now_ns(); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cb); diff --git a/runtime/ui/menu.h b/runtime/ui/menu.h index d8f207e5..0e37e38b 100644 --- a/runtime/ui/menu.h +++ b/runtime/ui/menu.h @@ -54,6 +54,11 @@ typedef struct { int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const char **shot); // Records the frame menu_overlay_frame laid out into cb, which is inside dynamic rendering on the image. void menu_overlay_draw(VkCommandBuffer cb); +// The boot screen while boot.c waits for the prewarm: phase as VkPrewarmProgress.phase (0 starting, 1 shaders, +// 2 pipelines) with its count. menu_boot_frame lays out the screen for t like menu_overlay_frame (1: draw it with +// menu_overlay_draw); only before the guest runs, from the thread that presents then. +void menu_boot_set(int phase, long long done, long long total); +int menu_boot_frame(const MenuTarget *t); void menu_vk_release(void); // before the device goes away (gfx_window_release_vk) // The check the font atlas runs on a system font, on the embedded font and damaged copies of it: 1 when it takes the // whole font and refuses a cut-off one, one without a character map and one with an unknown tag (--probe-window). diff --git a/runtime/ui_text.c b/runtime/ui_text.c index d5ad958e..c7e7bf92 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -500,6 +500,8 @@ static const char *const text_en[UI_TEXT_COUNT] = { "now.", [UI_MENU_CHEAT_UNSUPPORTED] = "not supported", [UI_MENU_CHEAT_UNSUPPORTED_DESC] = "This cheat cannot be used with this version of the game:", + [UI_BOOT_TITLE] = "Preparing shaders", [UI_BOOT_HINT] = "This happens once after an update or a graphics driver change.", + [UI_BOOT_STARTING] = "Starting", [UI_BOOT_SHADERS] = "Shaders: %lld of %lld", [UI_BOOT_PIPELINES] = "Pipelines: %lld of %lld", [UI_MENU_CHEATS_REBUILD] = "Rebuild the game now", [UI_MENU_CHEATS_REBUILD_DESC] = "Some cheats change the game's code and are not built into it: they are new or " "edited, or their last rebuild failed or was cancelled. Closes the game; the setup " @@ -982,6 +984,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = { "его при следующем запуске (несколько минут), или нажмите «Пересобрать игру сейчас».", [UI_MENU_CHEAT_UNSUPPORTED] = "не поддерживается", [UI_MENU_CHEAT_UNSUPPORTED_DESC] = "Этот чит нельзя использовать с этой версией игры:", + [UI_BOOT_TITLE] = "Подготовка шейдеров", [UI_BOOT_HINT] = "Это происходит один раз после обновления или смены видеодрайвера.", + [UI_BOOT_STARTING] = "Запуск", [UI_BOOT_SHADERS] = "Шейдеры: %lld из %lld", [UI_BOOT_PIPELINES] = "Конвейеры: %lld из %lld", [UI_MENU_CHEATS_REBUILD] = "Пересобрать игру сейчас", [UI_MENU_CHEATS_REBUILD_DESC] = "Некоторые читы меняют код игры и ещё не собраны в неё: они новые или изменены, " "либо прошлая пересборка не удалась или была отменена. Закрывает игру; установщик " @@ -1489,6 +1493,8 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { "Recompilar o jogo agora.", [UI_MENU_CHEAT_UNSUPPORTED] = "não suportado", [UI_MENU_CHEAT_UNSUPPORTED_DESC] = "Este cheat não pode ser usado com esta versão do jogo:", + [UI_BOOT_TITLE] = "Preparando shaders", [UI_BOOT_HINT] = "Isso acontece uma vez após uma atualização ou troca do driver de vídeo.", + [UI_BOOT_STARTING] = "Iniciando", [UI_BOOT_SHADERS] = "Shaders: %lld de %lld", [UI_BOOT_PIPELINES] = "Pipelines: %lld de %lld", [UI_MENU_CHEATS_REBUILD] = "Recompilar o jogo agora", [UI_MENU_CHEATS_REBUILD_DESC] = "Alguns cheats alteram o código do jogo e ainda não foram compilados nele: são " "novos ou editados, ou a última recompilação falhou ou foi cancelada. Fecha o " @@ -2082,6 +2088,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_CHEAT_REBUILD_DESC] = "此金手指修改游戏代码,并且是在游戏构建后新增或修改的。游戏会在下次启动时把它构建进去(几分钟),也可以使用“立即重新构建游戏”。", [UI_MENU_CHEAT_UNSUPPORTED] = "不支持", [UI_MENU_CHEAT_UNSUPPORTED_DESC] = "此金手指不能用于此游戏版本:", + [UI_BOOT_TITLE] = "正在准备着色器", [UI_BOOT_HINT] = "仅在更新或更换显卡驱动后进行一次。", + [UI_BOOT_STARTING] = "正在启动", [UI_BOOT_SHADERS] = "着色器:%lld / %lld", [UI_BOOT_PIPELINES] = "管线:%lld / %lld", [UI_MENU_CHEATS_REBUILD] = "立即重新构建游戏", [UI_MENU_CHEATS_REBUILD_DESC] = "有些金手指会修改游戏代码,但尚未构建进游戏:它们是新增或修改的,或上次重新构建失败或被取消。将关闭游戏;安装程序会把它们构建进去(几分钟)并重新启动游戏。上次存档之后的进度会丢失。", [UI_MENU_MODS_EXEFS_UNSUPPORTED] = "此模组修改游戏代码(exefs)的方式本移植无法应用,因此整个模组保持关闭。%s", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 36f1493b..71836c5b 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -238,6 +238,9 @@ typedef enum { UI_MENU_CHEAT_MASTER, UI_MENU_CHEAT_MASTER_DESC, UI_MENU_CHEAT_RESTORE, UI_MENU_CHEAT_RESTORE_DESC, UI_MENU_CHEAT_REBUILD, UI_MENU_CHEAT_REBUILD_DESC, UI_MENU_CHEAT_UNSUPPORTED, UI_MENU_CHEAT_UNSUPPORTED_DESC, UI_MENU_LAST_ID = UI_MENU_CHEAT_UNSUPPORTED_DESC, + // the boot screen while the boot prewarm prepares shaders and pipelines (boot.c, ui/menu.cpp menu_boot_frame) + UI_BOOT_TITLE, UI_BOOT_HINT, UI_BOOT_STARTING, + UI_BOOT_SHADERS, UI_BOOT_PIPELINES, // printf: "%lld" done, "%lld" total UI_TEXT_COUNT } UiTextId; diff --git a/runtime/vk.h b/runtime/vk.h index fff42311..ed0c15fb 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -584,6 +584,12 @@ int vk_pipeline_async_on(void); // 1 after vk_pipeline_async_enable: graphics // cached under the current translator from their stored inputs, and builds every recorded pipeline, on all cores. // No-op without vk_pipeline_async_enable, with NX2NAVI_PIPE_PREBUILD=0 or with NX2NAVI_GPU=null. void vk_pipeline_prewarm(void); +typedef struct { + int phase; // 0 starting (device, key file), 1 shaders, 2 pipelines, 3 done + int64_t sh_done, sh_total, sh_translated; // gfx_shader_prewarm_progress + int64_t pipe_done, pipe_total; // pipelines built or failed of those queued +} VkPrewarmProgress; +void vk_pipeline_prewarm_progress(VkPrewarmProgress *p); // any thread, while vk_pipeline_prewarm runs or after VkPipeline vk_pipeline_compute(const GfxShader *cs, const VkPipeInfo **info); // Records every dynamic state that VkPipeState determines, after binding a graphics pipeline: cull mode, front face, // topology, depth and stencil tests and ops, depth bias enable, rasterizer discard, vertex input, and, where the GPU diff --git a/runtime/vk_pipeline.c b/runtime/vk_pipeline.c index c0efc67d..24a9d08a 100644 --- a/runtime/vk_pipeline.c +++ b/runtime/vk_pipeline.c @@ -2574,7 +2574,26 @@ static void warm_builder(void *arg) { static void lb_start(const uint32_t pr_hist[16], const uint32_t fs_hist[4]); +// vk_pipeline_prewarm_progress's numbers: the phase, and the pipelines finished (built or failed) of those queued, copied +// while prewarm_run waits for its builders. +static int32_t pw_phase; +static int64_t pw_pipe_done, pw_pipe_total; + +void vk_pipeline_prewarm_progress(VkPrewarmProgress *p) { + p->phase = __atomic_load_n(&pw_phase, __ATOMIC_ACQUIRE); + gfx_shader_prewarm_progress(&p->sh_done, &p->sh_total, &p->sh_translated); + p->pipe_done = __atomic_load_n(&pw_pipe_done, __ATOMIC_RELAXED); + p->pipe_total = __atomic_load_n(&pw_pipe_total, __ATOMIC_RELAXED); +} + +static void prewarm_run(void); + void vk_pipeline_prewarm(void) { + prewarm_run(); + __atomic_store_n(&pw_phase, 3, __ATOMIC_RELEASE); +} + +static void prewarm_run(void) { const char *gpu = rt_config()->gpu; uint32_t pr_hist[16] = {0}, fs_hist[4] = {0}; // library state of the recorded pipelines (lb_start) if (!A.on || (gpu && !strcmp(gpu, "null"))) return; @@ -2609,6 +2628,7 @@ void vk_pipeline_prewarm(void) { int cpus = (int)plat_cpu_usable(); const char *pe = cfg_get("NX2NAVI_PREWARM_XLATE"); // no fixed default: half the CPUs, at most 16, when unset int procs = pe && *pe ? atoi(pe) : cpus / 2 > 16 ? 16 : cpus / 2; + __atomic_store_n(&pw_phase, 1, __ATOMIC_RELEASE); gfx_shader_prewarm((const uint8_t(*)[32])ids, u, sh, cpus, procs < 1 ? 1 : procs); double t1 = now_ms(); @@ -2656,14 +2676,24 @@ void vk_pipeline_prewarm(void) { plat_mutex_unlock(&P.lock); free(ids), free(sh); + __atomic_store_n(&pw_pipe_done, 0, __ATOMIC_RELAXED); + __atomic_store_n(&pw_pipe_total, (int64_t)queued, __ATOMIC_RELAXED); + __atomic_store_n(&pw_phase, 2, __ATOMIC_RELEASE); PlatThread *t[64]; int nt = 0; for (int i = 0; i < cpus && i < 64 && queued; i++) if ((t[nt] = plat_thread_new(warm_builder, NULL, "pipe prewarm"))) nt++; if (!nt) warm_builder(NULL); + double logged = now_ms(); for (int i = 0; i < nt; i++) - while (!plat_thread_join_ns(t[i], 2000000000u)) - rt_log("vk_pipeline: prewarm: %u of %u pipelines, %.0f ms", K.built + K.failed, queued, now_ms() - t1); + while (!plat_thread_join_ns(t[i], 100000000u)) { // every 100 ms the numbers, every 2 s a log line + uint32_t fin = __atomic_load_n(&K.built, __ATOMIC_RELAXED) + __atomic_load_n(&K.failed, __ATOMIC_RELAXED); + __atomic_store_n(&pw_pipe_done, (int64_t)fin, __ATOMIC_RELAXED); + if (now_ms() - logged < 2000) continue; + logged = now_ms(); + rt_log("vk_pipeline: prewarm: %u of %u pipelines, %.0f ms", fin, queued, now_ms() - t1); + } + __atomic_store_n(&pw_pipe_done, (int64_t)queued, __ATOMIC_RELAXED); plat_mutex_lock(&P.lock); while (K.left) plat_cond_wait(&done_cv, &P.lock); // jobs a pool worker took rt_log("vk_pipeline: prewarm: %zu records in %s: %u pipelines built, %u failed, %u already built, %u dropped "