From 06f4aeb6940448823e5a9b65af04b7320e7d2d87 Mon Sep 17 00:00:00 2001 From: chrg6 Date: Mon, 9 Nov 2026 18:49:12 -0500 Subject: [PATCH] Time what a submission spends on the GPU outside the game's passes and dispatches, with gpu_passes = 1. A session with per-pass GPU timestamps showed the game's own render passes and compute dispatches at 1.6 to 2.3 ms of GPU time a frame while the perf line's GPU time was 7.7 to 13.5 ms: most of the frame's GPU time is in commands the replay records between the marks, and nothing said which. The timed frames now also get a timestamp at the start and the end of each part of a submission, and every stretch between two marks (or a mark and the part's edge) is a gap. The replay names the kind of commands it records in a gap: buffer and texture copies, fills and clears, the temporal upscaler, write-back merges and copies, depth twin copies, the texture pool marks, the mesh draw counts and block-compressed target copies, each with a size where it has one. The report adds the gaps' time per frame summed by the kinds noted in them (a gap nobody noted holds barriers and state only), the parts' own time for comparison with the perf line, and each kind's count and size per frame. Nothing runs outside the timed frames. Co-Authored-By: Claude Fable 5.2 --- runtime/vk.h | 11 ++++ runtime/vk_crumbs.c | 120 +++++++++++++++++++++++++++++++++++++++-- runtime/vk_dlaa.c | 1 + runtime/vk_exec.c | 3 ++ runtime/vk_exec_draw.c | 3 ++ runtime/vk_exec_xfer.c | 5 ++ runtime/vk_memory.c | 2 + runtime/vk_sync.c | 4 ++ 8 files changed, 146 insertions(+), 3 deletions(-) diff --git a/runtime/vk.h b/runtime/vk.h index 2218b8f2..9cf5d291 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -117,6 +117,17 @@ typedef struct { uint32_t layer; // NX2NAVI_GPU_PASSES: the first layer of the depth target (a shadow cascade) } 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 +// gap ledger"). vk_gpu_passes_part: vk_sync.c, at the start (end 0) and the end (end 1) of each part's command buffer. +// vk_gpu_gap_note: the replay is about to record commands of this kind outside a pass or dispatch; units is their size +// (bytes for buffers, texels for images, 0 unknown). Both do nothing outside the timed frames. Replay thread only. +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 +}; +void vk_gpu_passes_part(VkCommandBuffer cb, int end); +void vk_gpu_gap_note(int kind, uint64_t units); // Pass marks wanted and possible (NX2NAVI_PASS_CRUMBS and the extensions): set by vk_crumbs_init. extern int vk_pass_marks_on; // vk_device.c create_device, before vkCreateDevice: 1 when NX2NAVI_PASS_CRUMBS asks for NVIDIA checkpoints. diff --git a/runtime/vk_crumbs.c b/runtime/vk_crumbs.c index 1266fafc..03e39f6f 100644 --- a/runtime/vk_crumbs.c +++ b/runtime/vk_crumbs.c @@ -133,6 +133,23 @@ void vk_pass_mark_cmd(VkCommandBuffer cb, uint32_t id, int end) { #define GP_TOP 30 typedef struct { uint8_t kind, used; uint32_t w, h, d, draws, layer; int c0; uint64_t vs, fs; } GpLabel; static GpLabel gp_labels[GP_SLOTS]; +// The gap ledger: what the timed frames' parts spend outside their passes and dispatches. A part (vk_sync.c: one command +// buffer of a submission) takes a slot of its own, kind GP_KIND_PART, with a timestamp at its start and its end. A gap +// runs from the part's start or the end of a mark to the start of the next mark or the part's end; vk_gpu_gap_note +// names the kinds of commands the replay records in the gap it is in (copies, clears, the upscaler, the write-back +// merge). A gap nobody noted holds barriers and state only. The report sums the gaps by the kinds noted in them. A pass +// split over two parts (vk_sync_split) keeps its own time, the wait for the second part included, and makes no gap. +#define GP_KIND_PART 3 // beside VK_MARK_PASS and VK_MARK_DISPATCH +#define GP_GAPS 16384 +typedef struct { uint32_t from, to, kinds; } GpGap; // query numbers in gp_pool; kinds: bits of VK_GAP_* +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] = { + "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"}; 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 @@ -159,9 +176,38 @@ static int kind_is_pass(const VkPassMark *m) { return m->kind == VK_MARK_PASS; } int vk_gpu_passes_capturing(void) { return gp_capture; } +static void gp_gap_close(uint32_t to) { + if (gp_gap_from != UINT32_MAX && gp_ngaps < GP_GAPS) gp_gaps[gp_ngaps++] = (GpGap){gp_gap_from, to, gp_gap_kinds}; + gp_gap_from = UINT32_MAX, gp_gap_kinds = 0; +} + +void vk_gpu_gap_note(int kind, uint64_t units) { + if (!gp_capture || gp_part == UINT32_MAX || kind < 0 || kind >= VK_GAP_N) return; + gp_gap_kinds |= 1u << kind; + gp_kind_n[kind]++, gp_kind_units[kind] += units; +} + +void vk_gpu_passes_part(VkCommandBuffer cb, int end) { + if (!end) { + gp_part = UINT32_MAX, gp_gap_from = UINT32_MAX, gp_gap_kinds = 0; + if (!gp_capture || gp_n >= GP_SLOTS) return; + gp_labels[gp_n] = (GpLabel){.kind = GP_KIND_PART}; + vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, gp_pool, gp_n * 2); + gp_part = gp_n++; + if (!gp_in_mark) gp_gap_from = gp_part * 2; + return; + } + if (gp_part == UINT32_MAX) return; + vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, gp_pool, gp_part * 2 + 1); + if (!gp_in_mark) gp_gap_close(gp_part * 2 + 1); + gp_labels[gp_part].used = 1; + gp_part = UINT32_MAX, gp_gap_from = UINT32_MAX; +} + static void gp_begin(VkCommandBuffer cb, VkPassMark *m) { m->gp = 0; if (!gp_capture || gp_n >= GP_SLOTS) return; + if (gp_part != UINT32_MAX) gp_gap_close(gp_n * 2); // the gap before this mark ends at its start gp_labels[gp_n].used = 0; vkCmdWriteTimestamp2(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, gp_pool, gp_n * 2); if (gp_prims && kind_is_pass(m)) vkCmdBeginQuery(cb, gp_prims, gp_n, 0); @@ -181,6 +227,64 @@ static void gp_end(VkCommandBuffer cb, const VkPassMark *m) { l->c0 = m->kind == VK_MARK_PASS && m->ncolor ? (int)m->color[0] : 0; l->vs = gp_shader_hash(m->first[0]), l->fs = m->kind == VK_MARK_PASS ? gp_shader_hash(m->first[1]) : 0; l->used = 1; + if (gp_part != UINT32_MAX) gp_gap_from = i * 2 + 1, gp_gap_kinds = 0; // the next gap starts at this mark's end +} + +// One timestamp of gp_pool in ticks; 0 when it is not there. +static int gp_tick(VkCtx *c, uint32_t q, uint64_t *t) { + uint64_t v[2] = {0}; + if (vkGetQueryPoolResults(c->device, gp_pool, q, 1, sizeof v, v, sizeof v, + VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) != VK_SUCCESS || !v[1]) + return 0; + *t = v[0]; + return 1; +} + +// The gaps of the timed frames, summed by the kinds noted in them, and the parts' own time for comparison with the +// perf line's GPU time (which counts the mirror prologues too and leaves out the time between parts). +static void gp_report_gaps(double tick_ms, double parts_ms, uint32_t parts) { + enum { MAX_SETS = 64 }; + static struct { uint32_t kinds, n; double ms; } sets[MAX_SETS]; + VkCtx *c = vk_ctx(); + int n = 0; + double total = 0; + uint32_t read = 0; + for (uint32_t i = 0; i < gp_ngaps; i++) { + uint64_t a, b; + if (!gp_tick(c, gp_gaps[i].from, &a) || !gp_tick(c, gp_gaps[i].to, &b) || b < a) continue; + double ms = (double)(b - a) * tick_ms; + int s = 0; + while (s < n && sets[s].kinds != gp_gaps[i].kinds) s++; + if (s == n) { + if (n == MAX_SETS) continue; + sets[n].kinds = gp_gaps[i].kinds, sets[n].n = 0, sets[n].ms = 0, n++; + } + sets[s].ms += ms, sets[s].n++, total += ms, read++; + } + rt_log("gpu passes: outside the passes and dispatches: %.2f ms per frame in %u gaps; the parts themselves %.2f ms per " + "frame in %u parts", total / GP_FRAMES, read, parts_ms / GP_FRAMES, parts); + for (int k = 0; k < n && k < 12; k++) { // the most expensive sets first + int top = k; + for (int j = k + 1; j < n; j++) + if (sets[j].ms > sets[top].ms) top = j; + if (top != k) { + uint32_t tk = sets[k].kinds, tn = sets[k].n; + double tm = sets[k].ms; + sets[k].kinds = sets[top].kinds, sets[k].n = sets[top].n, sets[k].ms = sets[top].ms; + sets[top].kinds = tk, sets[top].n = tn, sets[top].ms = tm; + } + char what[256]; + int o = 0; + what[0] = 0; + for (int b = 0; b < VK_GAP_N && o < (int)sizeof what - 40; b++) + if (sets[k].kinds >> b & 1) o += snprintf(what + o, sizeof what - (size_t)o, "%s%s", o ? ", " : "", gp_kind_names[b]); + rt_log("gpu passes: %7.3f ms x%-5.1f gaps with %s", sets[k].ms / GP_FRAMES, (double)sets[k].n / GP_FRAMES, + o ? what : "barriers and state only"); + } + for (int b = 0; b < VK_GAP_N; b++) + if (gp_kind_n[b]) + rt_log("gpu passes: %s: %.1f per frame, %.2f M units per frame (bytes of buffers, texels of images)", + gp_kind_names[b], (double)gp_kind_n[b] / GP_FRAMES, gp_kind_units[b] / 1e6 / GP_FRAMES); } typedef struct { GpLabel l; double ms; uint32_t n; uint64_t draws, prims, frags; } GpSum; @@ -196,18 +300,23 @@ static void gp_report(uint64_t frame) { VkCtx *c = vk_ctx(); int n = 0; uint32_t read = 0, unread = 0; - double tick_ms = c->props.limits.timestampPeriod / 1e6, total = 0; + double tick_ms = c->props.limits.timestampPeriod / 1e6, total = 0, parts_ms = 0; + uint32_t parts = 0; for (uint32_t i = 0; i < gp_n; i++) { const GpLabel *l = &gp_labels[i]; uint64_t q[4] = {0}; if (!l->used || vkGetQueryPoolResults(c->device, gp_pool, i * 2, 2, sizeof q, q, 2 * sizeof q[0], VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) != VK_SUCCESS || !q[1] || !q[3]) { - unread++; + if (l->kind != GP_KIND_PART) unread++; + continue; + } + double ms = (double)(q[2] - q[0]) * tick_ms; + if (l->kind == GP_KIND_PART) { // a part of a submission: for the gap ledger's line only + parts_ms += ms, parts++; continue; } read++; - double ms = (double)(q[2] - q[0]) * tick_ms; total += ms; // a pass of many draws and its neighbours differ in the draw count: the sum is by targets and shaders alone int s = 0; @@ -249,6 +358,7 @@ static void gp_report(uint64_t frame) { rt_log("gpu passes: indirect mesh draws: %.1f per frame, %.0f workgroups per frame, largest %u; first:%s", (double)mn / GP_FRAMES, (double)sum / GP_FRAMES, top, list); } + gp_report_gaps(tick_ms, parts_ms, parts); for (int s = 0; s < n && s < GP_TOP; s++) { const GpSum *e = &sums[s]; if (e->l.kind == VK_MARK_DISPATCH) @@ -318,6 +428,8 @@ void vk_gpu_passes_frame(uint64_t frame) { vkResetQueryPool(c->device, gp_pool, 0, GP_SLOTS * 2); if (gp_prims) vkResetQueryPool(c->device, gp_prims, 0, GP_SLOTS); if (gp_stats) vkResetQueryPool(c->device, gp_stats, 0, GP_SLOTS); + gp_ngaps = 0, gp_gap_from = UINT32_MAX, gp_gap_kinds = 0, gp_part = UINT32_MAX; + memset(gp_kind_n, 0, sizeof gp_kind_n), memset(gp_kind_units, 0, sizeof gp_kind_units); gp_n = 0, gp_start = frame, gp_capture = 1, gp_phase = 1; } else if (gp_phase == 1) { if (frame < gp_start + GP_FRAMES) return; @@ -336,11 +448,13 @@ VkPassMark *vk_pass_mark_begin(VkCommandBuffer cb, int kind, uint64_t fence) { m->id = id, m->kind = (uint8_t)kind, m->fence = fence, m->draws = UINT32_MAX; rec_pass_mark(cb, id, 0); gp_begin(cb, m); + gp_in_mark = 1; return m; } void vk_pass_mark_end(VkCommandBuffer cb, const VkPassMark *m) { if (!m || !cb) return; + gp_in_mark = 0; gp_end(cb, m); rec_pass_mark(cb, m->id, 1); } diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index 64b0e18e..01af3dcc 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -1325,6 +1325,7 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) { uint32_t w = t->width, h = t->height, ow = dst->width, oh = dst->height; VkCommandBuffer cb = ex->cb; vk_exec_barrier(ex); // what drew the scene is done (no pass is open here) + vk_gpu_gap_note(VK_GAP_UPSCALER, (uint64_t)ow * oh); if (D.preset_dirty) { // another model: features are created with it, so every size gets a new one for (int i = 0; i < DLSS_SIZES; i++) if (D.sizes[i].out) free_size(&D.sizes[i]); diff --git a/runtime/vk_exec.c b/runtime/vk_exec.c index ede9ed23..7c51f424 100644 --- a/runtime/vk_exec.c +++ b/runtime/vk_exec.c @@ -263,6 +263,7 @@ static void bc_copy_back(VkExec *ex, const VkExecTarget *t) { .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, bcs[i].level, 0, 1}, .dstOffset = {0, 0, (int32_t)t->base_layer}, .extent = {bcs[i].w, bcs[i].h, t->layers}}; // texels of the uncompressed source + vk_gpu_gap_note(VK_GAP_BC_BACK, 0); vkCmdCopyImage(ex->cb, t->image, VK_IMAGE_LAYOUT_GENERAL, bcs[i].bc, VK_IMAGE_LAYOUT_GENERAL, 1, &rg); memory_barrier(ex->cb, VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, VK_ACCESS_2_MEMORY_READ_BIT | VK_ACCESS_2_MEMORY_WRITE_BIT); @@ -814,6 +815,7 @@ static void clear_color(VkExec *ex, const p_clear_color *c) { if (whole_target(ex, t)) { vk_exec_barrier(ex); VkImageSubresourceRange r = {VK_IMAGE_ASPECT_COLOR_BIT, t->level, 1, t->base_layer, t->layers}; + vk_gpu_gap_note(VK_GAP_CLEAR_TARGET, (uint64_t)t->width * t->height); vkCmdClearColorImage(ex->cb, t->image, VK_IMAGE_LAYOUT_GENERAL, &cv, 1, &r); ex->recorded++; vk_texture_gpu_written(t->tex); @@ -844,6 +846,7 @@ static void clear_ds(VkExec *ex, const p_clear_ds *c) { if (whole_target(ex, t)) { vk_exec_barrier(ex); VkImageSubresourceRange r = {asp, t->level, 1, t->base_layer, t->layers}; + vk_gpu_gap_note(VK_GAP_CLEAR_TARGET, (uint64_t)t->width * t->height); vkCmdClearDepthStencilImage(ex->cb, t->image, VK_IMAGE_LAYOUT_GENERAL, &v, 1, &r); ex->recorded++; vk_texture_gpu_written(t->tex); diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index c3b6682d..f2c21f5e 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -1868,6 +1868,7 @@ void vk_exec_pool_marks(VkExec *ex) { VkDependencyInfo dep = {.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO, .memoryBarrierCount = 1, .pMemoryBarriers = mb}; vkCmdPipelineBarrier2(cb, &dep); VkBufferCopy region = {0, 0, (VkDeviceSize)VK_POOL_TEX * 4}; + vk_gpu_gap_note(VK_GAP_POOL_MARKS, region.size); vkCmdCopyBuffer(cb, PL.marks, PL.rb[i].buf, 1, ®ion); mb[0] = (VkMemoryBarrier2){.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER_2, .srcStageMask = VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT, .dstStageMask = VK_PIPELINE_STAGE_2_ALL_TRANSFER_BIT}; @@ -2365,6 +2366,7 @@ static Twin *twin_update(VkExec *ex, const VkTexImage *img) { vkCmdPipelineBarrier2(ex->cb, &d0); VkBufferImageCopy src = {.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, layers}, .imageExtent = {img->width, img->height, 1}}; + vk_gpu_gap_note(VK_GAP_TWIN, (uint64_t)img->width * img->height); vkCmdCopyImageToBuffer(ex->cb, img->image, VK_IMAGE_LAYOUT_GENERAL, twin_buf, 1, &src); VkMemoryBarrier2 m1 = {.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER_2, .srcStageMask = VK_PIPELINE_STAGE_2_COPY_BIT, .srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT, .dstStageMask = VK_PIPELINE_STAGE_2_COPY_BIT, @@ -4373,6 +4375,7 @@ static int mesh_ring_entry(VkExec *ex, const VkMemSpan *src, VkDeviceSize *at) { } *at = 12ull * (mesh_ring_next++ % MESH_RING); vk_exec_barrier(ex); // ends the pass (the next draw opens it again) and orders the culling's writes before the copy + vk_gpu_gap_note(VK_GAP_MESH_RING, 12); vkCmdFillBuffer(ex->cb, mesh_ring, *at + 4, 8, 1); VkBufferCopy cp = {src->offset, *at, 4}; vkCmdCopyBuffer(ex->cb, src->buffer, mesh_ring, 1, &cp); diff --git a/runtime/vk_exec_xfer.c b/runtime/vk_exec_xfer.c index a9f45483..f30dcce5 100644 --- a/runtime/vk_exec_xfer.c +++ b/runtime/vk_exec_xfer.c @@ -596,6 +596,7 @@ static int buffer_side(const VkExec *ex, const Sub *s, uint64_t addr, uint64_t * static void copy_buffer_image(VkExec *ex, const p_copy_b2t *p, int to_image) { Sub s; if (!sub_resolve(p->tex, &p->view, p->has_view, &p->r, 1, &s)) return; + vk_gpu_gap_note(to_image ? VK_GAP_COPY_B2T : VK_GAP_COPY_T2B, (uint64_t)s.w * s.h); if (s.img->scale > 1) { // the buffer holds the game's texel count, the image more warn_once(W_REGION, "buffer copy of a shadow map enlarged by NX2NAVI_SHADOW_SCALE: skipped"); return; @@ -619,6 +620,7 @@ static void copy_t2t(VkExec *ex, const p_copy_t2t *p) { if (!sub_resolve(p->src, &p->sv, p->has_sv, &p->sr, 1, &s)) return; if (!sub_resolve(p->dst, &p->dv, p->has_dv, &p->dr, 1, &d)) return; d.nz = s.nz; + vk_gpu_gap_note(VK_GAP_COPY_T2T, (uint64_t)s.w * s.h); int same_size = s.w == d.w && s.h == d.h; int same_format = s.img->format == d.img->format; if (s.img->samples != d.img->samples && !(s.img->samples > 1 && d.img->samples == 1 && same_size && same_format)) { @@ -661,6 +663,7 @@ static void copy_t2t(VkExec *ex, const p_copy_t2t *p) { static void copy_b2b(VkExec *ex, const p_copy_b2b *p) { uint64_t src = p->src, dst = p->dst, left = p->size; + vk_gpu_gap_note(VK_GAP_COPY_B2B, p->size); int started = 0; while (left) { VkMemSpan s, d; @@ -701,6 +704,7 @@ static void clear_buf(VkExec *ex, const p_clear_buf *p) { return; } uint64_t dst = p->addr, left = p->size; + vk_gpu_gap_note(VK_GAP_CLEAR_BUF, p->size); int started = 0; while (left) { VkMemSpan d; @@ -751,6 +755,7 @@ static void clear_tex(VkExec *ex, const p_clear_tex *p) { const VkTexImage *img = s.img; int is3d = img->type == VK_IMAGE_TYPE_3D; uint32_t lw = max1(img->width >> s.level), lh = max1(img->height >> s.level); + vk_gpu_gap_note(VK_GAP_CLEAR_TEX, (uint64_t)lw * lh); int reformat = p->has_view && p->view.set_format && p->view.format != t->d.format; if (s.x || s.y || s.w != lw || s.h != lh || (p->mask & 0xf) != 0xf || reformat || (is3d && (s.z || s.nz != max1(img->depth >> s.level)))) { diff --git a/runtime/vk_memory.c b/runtime/vk_memory.c index effe0686..6d1ea566 100644 --- a/runtime/vk_memory.c +++ b/runtime/vk_memory.c @@ -2335,6 +2335,7 @@ int vk_mem_mirror_end(VkCommandBuffer cb, uint64_t fence) { // the merge reads the mirror the submission's shaders wrote and writes the imported buffers mbarrier(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, VK_ACCESS_2_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT, VK_ACCESS_2_SHADER_STORAGE_READ_BIT); + vk_gpu_gap_note(VK_GAP_WB_MERGE, 0); int m = wb_merge_record(cb); if (!m) { // no range list: copy them plainly for (int i = 0; i < nsnl; i++) range_add(&wbl, &nwbl, &cwbl, snl[i].r, snl[i].off, snl[i].size); @@ -2355,6 +2356,7 @@ int vk_mem_mirror_end(VkCommandBuffer cb, uint64_t fence) { mbarrier(cb, VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT, VK_ACCESS_2_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_READ_BIT); for (int i = 0; i < nwbl; i++) wbl[i].r->wb_sub = msub; + vk_gpu_gap_note(VK_GAP_WB_COPY, 0); mrep.wb_ranges += (uint64_t)nwbl; rec += copy_ranges(cb, wbl, nwbl, 0, &mrep.wb_bytes, &mrep.wb_copies) + 2; mbarrier(cb, VK_PIPELINE_STAGE_2_COPY_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, diff --git a/runtime/vk_sync.c b/runtime/vk_sync.c index 088e0144..4283da8e 100644 --- a/runtime/vk_sync.c +++ b/runtime/vk_sync.c @@ -482,6 +482,7 @@ static VkCommandBuffer prologue(VkCtx *c, uint64_t fence) { VkCommandBuffer vk_sync_split(void) { VkCtx *c = vk_ctx(); VkCommandBuffer cb = slots[cur_slot].cb; + vk_gpu_passes_part(cb, 1); ts_end(cb, cur_fence); if (!rec_end_cb(cb, 0, 0)) vkEndCommandBuffer(cb); // every command of the part is in cb, ended by its recorder vk_upload_flush(0); // the uploads this part asked for precede it in queue order @@ -500,6 +501,7 @@ VkCommandBuffer vk_sync_split(void) { vk_crumb(s->cb, VK_CRUMB_SUBMIT, cur_fence); ts_begin(s->cb); rec_begin(s->cb, cur_fence); + vk_gpu_passes_part(s->cb, 0); return s->cb; } @@ -533,8 +535,10 @@ uint64_t vk_sync_submit(const uint64_t *handles, int n) { vk_crumb(s->cb, VK_CRUMB_SUBMIT, fence); ts_begin(s->cb); rec_begin(s->cb, fence); + vk_gpu_passes_part(s->cb, 0); int recorded = vk_exec_record(s->cb, handles, n, fence); s = &slots[cur_slot]; // the last part (vk_sync_split) + vk_gpu_passes_part(s->cb, 1); if (recorded) ts_end(s->cb, fence); else ts_drop(); // The recorder is done with the part: the end-of-submission crumb, then the end, by the recorder when it records.