From a2fbd2fbd02cc989501496c5fd4d98cb6ee9f33e Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Wed, 11 Jan 2023 11:12:40 -0800 Subject: [PATCH] zink: Add tracing of blit operations. I found this useful in lining up some perfetto traces between zink+anv and iris, and understanding what was going on in them. Also it's a demo of being able to insert annotations for work in the command stream, which I suspect we'll want more of. Part-of: --- src/gallium/drivers/zink/zink_blit.c | 35 +++++++++++++++++++++ src/gallium/drivers/zink/zink_context.c | 41 +++++++++++++++++++++++++ src/gallium/drivers/zink/zink_context.h | 5 +++ src/gallium/drivers/zink/zink_screen.c | 3 ++ 4 files changed, 84 insertions(+) diff --git a/src/gallium/drivers/zink/zink_blit.c b/src/gallium/drivers/zink/zink_blit.c index 59f7fc73c97..ceb89314925 100644 --- a/src/gallium/drivers/zink/zink_blit.c +++ b/src/gallium/drivers/zink/zink_blit.c @@ -56,6 +56,12 @@ blit_resolve(struct zink_context *ctx, const struct pipe_blit_info *info, bool * if (src->format != dst->format) return false; + bool marker = zink_cmd_debug_marker_begin(ctx, "blit_resolve(%s->%s, %dx%d->%dx%d)", + util_format_short_name(info->src.format), + util_format_short_name(info->src.format), + info->src.box.width, info->src.box.height, + info->dst.box.width, info->dst.box.height); + apply_dst_clears(ctx, info, false); zink_fb_clears_apply_region(ctx, info->src.resource, zink_rect_from_box(&info->src.box)); @@ -110,6 +116,7 @@ blit_resolve(struct zink_context *ctx, const struct pipe_blit_info *info, bool * VKCTX(CmdResolveImage)(cmdbuf, src->obj->image, src->layout, dst->obj->image, dst->layout, 1, ®ion); + zink_cmd_debug_marker_end(ctx, marker); return true; } @@ -159,6 +166,12 @@ blit_native(struct zink_context *ctx, const struct pipe_blit_info *info, bool *n !(src->obj->vkfeats & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)) return false; + bool marker = zink_cmd_debug_marker_begin(ctx, "blit_native(%s->%s, %dx%d->%dx%d)", + util_format_short_name(info->src.format), + util_format_short_name(info->src.format), + info->src.box.width, info->src.box.height, + info->dst.box.width, info->dst.box.height); + apply_dst_clears(ctx, info, false); zink_fb_clears_apply_region(ctx, info->src.resource, zink_rect_from_box(&info->src.box)); @@ -254,6 +267,8 @@ blit_native(struct zink_context *ctx, const struct pipe_blit_info *info, bool *n 1, ®ion, zink_filter(info->filter)); + zink_cmd_debug_marker_end(ctx, marker); + return true; } @@ -315,6 +330,12 @@ zink_blit(struct pipe_context *pctx, bool stencil_blit = false; if (!util_blitter_is_blit_supported(ctx->blitter, info)) { if (util_format_is_depth_or_stencil(info->src.resource->format)) { + bool marker = zink_cmd_debug_marker_begin(ctx, "zink_blit(Z %s->%s, %dx%d->%dx%d)", + util_format_short_name(info->src.format), + util_format_short_name(info->dst.format), + info->src.box.width, info->src.box.height, + info->dst.box.width, info->dst.box.height); + struct pipe_blit_info depth_blit = *info; depth_blit.mask = PIPE_MASK_Z; stencil_blit = util_blitter_is_blit_supported(ctx->blitter, &depth_blit); @@ -322,6 +343,7 @@ zink_blit(struct pipe_context *pctx, zink_blit_begin(ctx, ZINK_BLIT_SAVE_FB | ZINK_BLIT_SAVE_FS | ZINK_BLIT_SAVE_TEXTURES); util_blitter_blit(ctx->blitter, &depth_blit); } + zink_cmd_debug_marker_end(ctx, marker); } if (!stencil_blit) { mesa_loge("ZINK: blit unsupported %s -> %s", @@ -348,6 +370,11 @@ zink_blit(struct pipe_context *pctx, zink_blit_begin(ctx, ZINK_BLIT_SAVE_FB | ZINK_BLIT_SAVE_FS | ZINK_BLIT_SAVE_TEXTURES); if (stencil_blit) { + bool marker = zink_cmd_debug_marker_begin(ctx, "zink_blit(S fallback %s->%s, %dx%d->%dx%d)", + util_format_short_name(info->src.format), + util_format_short_name(info->dst.format), + info->src.box.width, info->src.box.height, + info->dst.box.width, info->dst.box.height); struct pipe_surface *dst_view, dst_templ; util_blitter_default_dst_texture(&dst_templ, info->dst.resource, info->dst.level, info->dst.box.z); dst_view = pctx->create_surface(pctx, info->dst.resource, &dst_templ); @@ -366,8 +393,16 @@ zink_blit(struct pipe_context *pctx, info->scissor_enable ? &info->scissor : NULL); pipe_surface_release(pctx, &dst_view); + + zink_cmd_debug_marker_end(ctx, marker); } else { + bool marker = zink_cmd_debug_marker_begin(ctx, "zink_blit(%s->%s, %dx%d->%dx%d)", + util_format_short_name(info->src.format), + util_format_short_name(info->dst.format), + info->src.box.width, info->src.box.height, + info->dst.box.width, info->dst.box.height); util_blitter_blit(ctx->blitter, info); + zink_cmd_debug_marker_end(ctx, marker); } ctx->blitting = false; end: diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index d9bfc965a62..e9d3898560c 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -45,7 +45,9 @@ #include "util/format/u_format.h" #include "util/u_helpers.h" #include "util/u_inlines.h" +#include "util/u_string.h" #include "util/u_thread.h" +#include "util/perf/u_trace.h" #include "util/u_cpu_detect.h" #include "util/strndup.h" #include "nir.h" @@ -5328,3 +5330,42 @@ zink_update_barriers(struct zink_context *ctx, bool is_compute, break; } } + +/** + * Emits a debug marker in the cmd stream to be captured by perfetto during + * execution on the GPU. + */ +bool +zink_cmd_debug_marker_begin(struct zink_context *ctx, const char *fmt, ...) +{ + struct zink_screen *screen = zink_screen(ctx->base.screen); + + if (!screen->instance_info.have_EXT_debug_utils || + !(u_trace_is_enabled(U_TRACE_TYPE_PERFETTO) || u_trace_is_enabled(U_TRACE_TYPE_MARKERS))) + return false; + + char *name; + va_list va; + va_start(va, fmt); + int ret = vasprintf(&name, fmt, va); + va_end(va); + + if (ret == -1) + return false; + + VkDebugUtilsLabelEXT info = { 0 }; + info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; + info.pLabelName = name; + + VKCTX(CmdBeginDebugUtilsLabelEXT)(ctx->batch.state->cmdbuf, &info); + + free(name); + return true; +} + +void +zink_cmd_debug_marker_end(struct zink_context *ctx, bool emitted) +{ + if (emitted) + VKCTX(CmdEndDebugUtilsLabelEXT)(ctx->batch.state->cmdbuf); +} diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h index 50d1bf33762..3f2f16bb2b9 100644 --- a/src/gallium/drivers/zink/zink_context.h +++ b/src/gallium/drivers/zink/zink_context.h @@ -250,6 +250,11 @@ zink_get_dummy_pipe_surface(struct zink_context *ctx, int samples_index); struct zink_surface * zink_get_dummy_surface(struct zink_context *ctx, int samples_index); +bool +zink_cmd_debug_marker_begin(struct zink_context *ctx, const char *fmt, ...); +void +zink_cmd_debug_marker_end(struct zink_context *ctx, bool emitted); + void debug_describe_zink_buffer_view(char *buf, const struct zink_buffer_view *ptr); diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c index 3f24be319ce..37a7e2cb0b5 100644 --- a/src/gallium/drivers/zink/zink_screen.c +++ b/src/gallium/drivers/zink/zink_screen.c @@ -44,6 +44,7 @@ #include "util/u_memory.h" #include "util/u_screen.h" #include "util/u_string.h" +#include "util/perf/u_trace.h" #include "util/u_transfer_helper.h" #include "util/xmlconfig.h" @@ -2617,6 +2618,8 @@ zink_internal_create_screen(const struct pipe_screen_config *config) zink_debug = debug_get_option_zink_debug(); zink_descriptor_mode = debug_get_option_zink_descriptor_mode(); + u_trace_state_init(); + screen->loader_lib = util_dl_open(VK_LIBNAME); if (!screen->loader_lib) goto fail;