diff --git a/runtime/vk.h b/runtime/vk.h index 3efa1048..b1786491 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -174,6 +174,7 @@ typedef struct { uint32_t gp; // NX2NAVI_GPU_PASSES: the timestamp pair of this mark plus one; 0 none uint32_t layer; // NX2NAVI_GPU_PASSES: the first layer of the depth target (a shadow cascade) uint32_t gap; // bits of VK_GAP_*: what the replay recorded between the mark before and this one + uint16_t mesh, mesh_ind; // a pass's mesh draws, with a count and with the GPU's (DrawMeshTasksIndirect) } VkPassMark; void vk_gpu_passes_frame(uint64_t frame); // vk_crumbs.c, each present: NX2NAVI_GPU_PASSES, GPU time per pass and dispatch // NX2NAVI_GPU_PASSES also times what a part of a submission spends outside its passes and dispatches (vk_crumbs.c, "the @@ -184,7 +185,9 @@ void vk_gpu_passes_frame(uint64_t frame); // vk_crumbs.c, each present: NX2NAV enum { VK_GAP_COPY_B2B, VK_GAP_COPY_B2T, VK_GAP_COPY_T2B, VK_GAP_COPY_T2T, VK_GAP_CLEAR_BUF, VK_GAP_CLEAR_TEX, VK_GAP_CLEAR_TARGET, VK_GAP_UPSCALER, VK_GAP_WB_MERGE, VK_GAP_WB_COPY, VK_GAP_TWIN, VK_GAP_POOL_MARKS, - VK_GAP_MESH_RING, VK_GAP_BC_BACK, VK_GAP_N + VK_GAP_MESH_RING, VK_GAP_BC_BACK, + VK_GAP_GROUP, // a group of draws the replay workers recorded (vk_exec.c group_start): passes without marks + VK_GAP_N }; void vk_gpu_passes_part(VkCommandBuffer cb, int end); // Result points (NX2NAVI_GPU_PASSES): the submission whose parts follow (vk_sync.c), a result just recorded (VK_RES_* diff --git a/runtime/vk_crumbs.c b/runtime/vk_crumbs.c index 8c7974ab..df73a53f 100644 --- a/runtime/vk_crumbs.c +++ b/runtime/vk_crumbs.c @@ -208,10 +208,12 @@ static GpGap gp_gaps[GP_GAPS]; static uint32_t gp_ngaps, gp_gap_from = UINT32_MAX, gp_gap_kinds, gp_part = UINT32_MAX; static int gp_in_mark; // between a mark's start and its end static uint64_t gp_kind_n[VK_GAP_N], gp_kind_units[VK_GAP_N]; -static const char *const gp_kind_names[VK_GAP_N] = { +static const char *const gp_kind_names[] = { "buffer copies", "buffer to texture copies", "texture to buffer copies", "texture copies", "buffer fills", "texture clears", "target clears", "the temporal upscaler", "write-back merges", "write-back copies", - "depth twin copies", "texture pool marks", "mesh draw counts", "block-compressed target copies"}; + "depth twin copies", "texture pool marks", "mesh draw counts", "block-compressed target copies", + "groups of draws the replay workers recorded, whose passes have no marks"}; +_Static_assert(sizeof gp_kind_names / sizeof gp_kind_names[0] == VK_GAP_N, "a name for every VK_GAP_* kind"); static VkQueryPool gp_pool, gp_prims; // gp_prims: mesh primitives generated per pass (with meshShaderQueries) static VkQueryPool gp_stats; // fragment shader invocations per pass static int gp_state, gp_phase, gp_capture; // state 0 not set up, 1 on, -1 off; phase 0 idle, 1 capturing, 2 waiting @@ -673,13 +675,19 @@ static void describe_mark(uint32_t id, char *o, size_t size) { if (n < size) n += (size_t)snprintf(o + n, size - n, ", depth format %d", (int)m->depth); if (n >= size) return; if (m->draws == UINT32_MAX) - snprintf(o + n, size - n, ", still recording; first draw vs %016llx fs %016llx", shader_id(m->first[0]), - shader_id(m->first[1])); + n += (size_t)snprintf(o + n, size - n, ", still recording; first draw vs %016llx fs %016llx", shader_id(m->first[0]), + shader_id(m->first[1])); else if (!m->draws) - snprintf(o + n, size - n, ", no draws"); + n += (size_t)snprintf(o + n, size - n, ", no draws"); else - snprintf(o + n, size - n, ", %u draws; first vs %016llx fs %016llx, last vs %016llx fs %016llx", m->draws, - shader_id(m->first[0]), shader_id(m->first[1]), shader_id(m->last[0]), shader_id(m->last[1])); + n += (size_t)snprintf(o + n, size - n, ", %u draws; first vs %016llx fs %016llx, last vs %016llx fs %016llx", + m->draws, shader_id(m->first[0]), shader_id(m->first[1]), shader_id(m->last[0]), + shader_id(m->last[1])); + // The mesh draws among them: the RX 6000 losses whose marks named a pass were in passes that start with one, and + // whether a pass held any (and how many took their count from the GPU) is what tells such a loss from another. + if (n < size && (m->mesh || m->mesh_ind)) + snprintf(o + n, size - n, "; %u mesh draws, %u of them with the GPU's count", (unsigned)m->mesh + m->mesh_ind, + (unsigned)m->mesh_ind); } void vk_pass_marks_format(const char *source, uint32_t started, uint32_t finished, char *o, size_t size) { diff --git a/runtime/vk_device.c b/runtime/vk_device.c index e614ea9b..dde3f939 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -420,10 +420,15 @@ typedef struct { // One line for a fatal error's report (dispatch.h rt_fatal_note_add): the card, its driver, and the settings in effect // that change how the game's memory behaves. A report often arrives as the end of a log alone, or as a picture of it, // and the lines that say these things are at its start. No lock is taken: the failing thread may hold any. +// How the game's task and mesh programs are drawn (create_device decides it): natively, through the mesh fallback, the +// mesh emulation, or not at all. Every RX 6000 loss whose marks named a pass was in one that starts with a mesh draw. +static const char *g_mesh_path = "not decided yet"; + static void fatal_note(void) { char mem[512]; vk_mem_fatal_note(mem, sizeof mem); - rt_log("fatal: gpu %s; %s; texture detail %s", vk_caps_summary(), mem, vk_texture_detail_name()); + rt_log("fatal: gpu %s; %s; texture detail %s; mesh draws %s", vk_caps_summary(), mem, vk_texture_detail_name(), + g_mesh_path); } static int create_device(void) { @@ -607,6 +612,8 @@ static int create_device(void) { const char *mf = cfg_value("NX2NAVI_MESH_FALLBACK"), *me = cfg_value("NX2NAVI_MESH_EMULATION"); int emu = !g_vk.has_mesh_shader && strcmp(me, "0"); g_vk.mesh_fallback = !emu && (!strcmp(mf, "1") || (strcmp(mf, "0") && !g_vk.has_mesh_shader)); + g_mesh_path = emu ? "emulated (mesh_emulation)" : g_vk.mesh_fallback ? "through the mesh fallback (compute passes)" + : g_vk.has_mesh_shader ? "native (VK_EXT_mesh_shader)" : "skipped (no mesh shaders, mesh_fallback = 0)"; if (emu) rt_log("vk: mesh shaders: emulated with compute (mesh_emulation = 1); mesh_fallback is not used"); else if (g_vk.mesh_fallback) rt_log("vk: mesh fallback: task and mesh programs run as compute passes and are drawn from their buffers (%s)", diff --git a/runtime/vk_exec.c b/runtime/vk_exec.c index 62e37966..97fc7d06 100644 --- a/runtime/vk_exec.c +++ b/runtime/vk_exec.c @@ -865,6 +865,7 @@ void vk_exec_pass_begin(VkExec *ex) { VkPassMark *m = ex->mark = rw_chunk ? NULL : vk_pass_mark_begin(ex->cb, VK_MARK_PASS, ex->fence); // one ring if (m) { m->step = ex->mark_passes++; + m->mesh = m->mesh_ind = 0; m->w = ex->pass_w, m->h = ex->pass_h, m->d = ex->pass_layers; m->layer = ex->depth.image ? ex->depth.base_layer : 0; m->vw = m->vh = 0; @@ -1855,8 +1856,10 @@ static void op_one(VkExec *ex, const op_hdr *h) { // 3 workers: on an RX 7900 XT with a Ryzen 7 5800X3D, Hyrule Field standing went from 41.2 to 50.4 fps (2026-11-12, one // batch), with the same pictures there and in Kokiri Forest, Kakariko, Goron City, a graveyard house and Gerudo // Valley; 5 or 7 workers measured the same as 3. Default 0 again after players' games crashed with 3 on by default -// (0.9.1, 0.9.2): an RX 6700 XT lost its device after about 18,000 frames, its last mark a compute dispatch of the -// replay's own, with an occlusion query slot found unavailable after its fence just before; the cause is not known. +// (0.9.1, 0.9.2): an RX 6700 XT lost its device after about 18,000 frames, its last mark the game's own compute +// dispatch (op_dispatch: 20x1x1 groups of cs d7566eb1, a depth probe) and nothing after it marked, since the group of +// draws that followed was recorded by the workers, whose passes have no marks; an occlusion query slot was found +// unavailable after its fence just before. An RX 6600 lost it the same way twice (0.9.2). The cause is not known. // A submission's draws come in runs between ops that have to stay in the replay's order on its own thread (dispatches, // copies, texture and buffer clears, events, the game's barriers, calls). Hyrule Field, standing (NX2NAVI_REPLAY_RUNS, // 2026-11-11): about 3,500 draws a frame in 82 runs, 96% of them in runs of 16 draws or more and 67% in runs of 256 or @@ -2449,6 +2452,9 @@ static const op_hdr *group_start(VkExec *ex, const op_hdr *h, int depth) { uint64_t t0 = kern_now_ns(); gfx_tl_note('g', 0, draws, (uint64_t)n); vk_exec_barrier(ex); // the command buffer so far ends behind a full barrier, every image back in GENERAL + // the chunks' passes get no marks (vk_exec_pass_begin): a lost device's report names the group between the marks. + // After the barrier, whose end of an open pass ends that pass's mark and empties the note. + vk_gpu_gap_note(VK_GAP_GROUP, draws); g->upd = vk_exec_draw_group_begin(ex); // the front pass uint32_t per = (draws + (uint32_t)n - 1) / (uint32_t)n, cd = 0; diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index 18824ed7..ad63844a 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -6068,6 +6068,8 @@ static void mfb_draw(VkExec *ex, uint32_t count, const VkMemSpan *ind) { int prim = c->mi.ipp == 1 ? NVN_DRAW_PRIMITIVE_POINTS : c->mi.ipp == 2 ? NVN_DRAW_PRIMITIVE_LINES : NVN_DRAW_PRIMITIVE_TRIANGLES; if (!prepare_draw_ex(ex, prim, 0x7fffffff, 0, 2)) return; vk_exec_frame.draws++; + if (ex->mark && ind) ex->mark->mesh_ind++; // the pass's mesh draws (vk_crumbs.c describe_mark) + else if (ex->mark) ex->mark->mesh++; vkCmdDrawIndirect(ex->cb, rec, at + 32, 1, sizeof(VkDrawIndirectCommand)); ex->recorded++; } @@ -6117,6 +6119,7 @@ static void op_draw_mesh(VkExec *ex, const p_draw_mesh *d) { if (!prepare_draw_ex(ex, NVN_DRAW_PRIMITIVE_TRIANGLES, 0x7fffffff, 0, 1)) return; if (d->first) warn_once(W_MESH, "a mesh draw from workgroup %u: drawn from workgroup 0", d->first); vk_exec_frame.draws++; + if (ex->mark) ex->mark->mesh++; // the pass's mesh draws, for a lost device's report (vk_crumbs.c describe_mark) static uint32_t n_logged; if (n_logged < 8 && knob_log_mesh()) { n_logged++; @@ -6325,6 +6328,7 @@ static void op_draw_mesh_ind(VkExec *ex, const p_draw_mesh_ind *d) { if (!mesh_ring_entry(ex, ex->cb, d, &ip, &at)) return warn_once(W_MESH, "the indirect mesh ring could not be created: skipped"); if (!prepare_draw_ex(ex, NVN_DRAW_PRIMITIVE_TRIANGLES, 0x7fffffff, 0, 1)) return; vk_exec_frame.draws++; + if (ex->mark) ex->mark->mesh_ind++; // the pass's mesh draws, for a lost device's report (vk_crumbs.c describe_mark) static uint32_t n_logged; if (n_logged < 8 && knob_log_mesh()) { n_logged++;