From: Tomeu Vizoso Date: Fri, 8 Mar 2019 14:24:57 +0000 (+0100) Subject: panfrost: Add support for PAN_MESA_DEBUG X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=97f2d04d5eb93731700c1941c811bb354d057cfc;p=mesa.git panfrost: Add support for PAN_MESA_DEBUG Signed-off-by: Tomeu Vizoso Reviewed-by: Alyssa Rosenzweig --- diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c index 648e84b0350..fadcdecb044 100644 --- a/src/gallium/drivers/panfrost/pan_blend_shaders.c +++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c @@ -24,6 +24,7 @@ #include #include "pan_blend_shaders.h" +#include "pan_util.h" #include "midgard/midgard_compile.h" #include "compiler/nir/nir_builder.h" //#include "gallium/auxiliary/nir/nir_lower_blend.h" @@ -130,7 +131,8 @@ panfrost_make_blend_shader(struct panfrost_context *ctx, struct panfrost_blend_s /* Build a trivial blend shader */ nir_store_var(b, c_out, nir_blending_f(blend, b, s_src, s_dst, s_con), 0xFF); - nir_print_shader(shader, stdout); + if (pan_debug & PAN_DBG_SHADERS) + nir_print_shader(shader, stdout); /* Compile the built shader */ diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 3c8a483b8f5..095f9cf3606 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -41,6 +41,7 @@ #include "pan_screen.h" #include "pan_blending.h" #include "pan_blend_shaders.h" +#include "pan_util.h" #include "pan_wallpaper.h" static int performance_counter_number = 0; @@ -85,7 +86,7 @@ static void panfrost_enable_afbc(struct panfrost_context *ctx, struct panfrost_resource *rsrc, bool ds) { if (ctx->require_sfbd) { - printf("AFBC not supported yet on SFBD\n"); + DBG("AFBC not supported yet on SFBD\n"); assert(0); } @@ -145,7 +146,7 @@ panfrost_set_fragment_afbc(struct panfrost_context *ctx) continue; if (ctx->require_sfbd) { - fprintf(stderr, "Color AFBC not supported on SFBD\n"); + DBG("Color AFBC not supported on SFBD\n"); assert(0); } @@ -169,7 +170,7 @@ panfrost_set_fragment_afbc(struct panfrost_context *ctx) if (rsrc->bo->has_afbc) { if (ctx->require_sfbd) { - fprintf(stderr, "Depth AFBC not supported on SFBD\n"); + DBG("Depth AFBC not supported on SFBD\n"); assert(0); } @@ -193,7 +194,7 @@ panfrost_set_fragment_afbc(struct panfrost_context *ctx) if (ctx->pipe_framebuffer.nr_cbufs == 0) { if (ctx->require_sfbd) { - fprintf(stderr, "Depth-only FBO not supported on SFBD\n"); + DBG("Depth-only FBO not supported on SFBD\n"); assert(0); } @@ -598,7 +599,7 @@ static void panfrost_invalidate_frame(struct panfrost_context *ctx) { unsigned transient_count = ctx->transient_pools[ctx->cmdstream_i].entry_index*ctx->transient_pools[0].entry_size + ctx->transient_pools[ctx->cmdstream_i].entry_offset; - printf("Uploaded transient %d bytes\n", transient_count); + DBG("Uploaded transient %d bytes\n", transient_count); /* Rotate cmdstream */ if ((++ctx->cmdstream_i) == (sizeof(ctx->transient_pools) / sizeof(ctx->transient_pools[0]))) @@ -958,7 +959,7 @@ panfrost_fragment_job(struct panfrost_context *ctx) if (rsrc->bo->has_checksum) { if (ctx->require_sfbd) { - fprintf(stderr, "Checksumming not supported on SFBD\n"); + DBG("Checksumming not supported on SFBD\n"); assert(0); } @@ -1428,7 +1429,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data) break; default: - printf("Unknown shader stage %d in uniform upload\n", i); + DBG("Unknown shader stage %d in uniform upload\n", i); assert(0); } @@ -1459,7 +1460,7 @@ panfrost_queue_draw(struct panfrost_context *ctx) { /* TODO: Expand the array? */ if (ctx->draw_count >= MAX_DRAW_CALLS) { - printf("Job buffer overflow, ignoring draw\n"); + DBG("Job buffer overflow, ignoring draw\n"); assert(0); } @@ -1612,7 +1613,7 @@ g2m_draw_mode(enum pipe_prim_type mode) DEFINE_CASE(POLYGON); default: - printf("Illegal draw mode %d\n", mode); + DBG("Illegal draw mode %d\n", mode); assert(0); return MALI_LINE_LOOP; } @@ -1634,7 +1635,7 @@ panfrost_translate_index_size(unsigned size) return MALI_DRAW_INDEXED_UINT32; default: - printf("Unknown index size %d\n", size); + DBG("Unknown index size %d\n", size); assert(0); return 0; } @@ -1911,7 +1912,7 @@ panfrost_delete_vertex_elements_state(struct pipe_context *pctx, void *hwcso) { struct panfrost_vertex_state *so = (struct panfrost_vertex_state *) hwcso; unsigned bytes = sizeof(struct mali_attr_meta) * so->num_elements; - printf("Vertex elements delete leaks descriptor (%d bytes)\n", bytes); + DBG("Vertex elements delete leaks descriptor (%d bytes)\n", bytes); free(hwcso); } @@ -1939,11 +1940,11 @@ panfrost_delete_shader_state( struct panfrost_shader_variants *cso = (struct panfrost_shader_variants *) so; if (cso->base.type == PIPE_SHADER_IR_TGSI) { - printf("Deleting TGSI shader leaks duplicated tokens\n"); + DBG("Deleting TGSI shader leaks duplicated tokens\n"); } unsigned leak = cso->variant_count * sizeof(struct mali_shader_meta); - printf("Deleting shader state leaks descriptors (%d bytes), and shader bytecode\n", leak); + DBG("Deleting shader state leaks descriptors (%d bytes), and shader bytecode\n", leak); free(so); } @@ -2172,7 +2173,7 @@ panfrost_set_constant_buffer( } else if (buf->user_buffer) { cpu = buf->user_buffer; } else { - printf("No constant buffer?\n"); + DBG("No constant buffer?\n"); return; } @@ -2321,7 +2322,7 @@ panfrost_set_framebuffer_state(struct pipe_context *pctx, if (ctx->pipe_framebuffer.cbufs[i] == cb) continue; if (cb && (i != 0)) { - printf("XXX: Multiple render targets not supported before t7xx!\n"); + DBG("XXX: Multiple render targets not supported before t7xx!\n"); assert(0); } @@ -2436,7 +2437,7 @@ panfrost_delete_blend_state(struct pipe_context *pipe, struct panfrost_blend_state *so = (struct panfrost_blend_state *) blend; if (so->has_blend_shader) { - printf("Deleting blend state leak blend shaders bytecode\n"); + DBG("Deleting blend state leak blend shaders bytecode\n"); } free(blend); @@ -2637,7 +2638,7 @@ panfrost_begin_query(struct pipe_context *pipe, struct pipe_query *q) } default: - fprintf(stderr, "Skipping query %d\n", query->type); + DBG("Skipping query %d\n", query->type); break; } @@ -2683,7 +2684,7 @@ panfrost_get_query_result(struct pipe_context *pipe, break; } default: - fprintf(stderr, "Skipped query get %d\n", query->type); + DBG("Skipped query get %d\n", query->type); break; } diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index abef927ada5..b869170b824 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -42,6 +42,7 @@ #include "pan_screen.h" #include "pan_resource.h" #include "pan_swizzle.h" +#include "pan_util.h" static struct pipe_resource * panfrost_resource_from_handle(struct pipe_screen *pscreen, @@ -125,7 +126,7 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen, static void panfrost_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc) { - //fprintf(stderr, "TODO %s\n", __func__); + //DBG("TODO %s\n", __func__); } static void @@ -133,7 +134,7 @@ panfrost_blit(struct pipe_context *pipe, const struct pipe_blit_info *info) { /* STUB */ - printf("Skipping blit XXX\n"); + DBG("Skipping blit XXX\n"); return; } @@ -243,7 +244,7 @@ panfrost_resource_create(struct pipe_screen *screen, case PIPE_TEXTURE_RECT: break; default: - fprintf(stderr, "Unknown texture target %d\n", template->target); + DBG("Unknown texture target %d\n", template->target); assert(0); } @@ -306,12 +307,12 @@ panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *pbo) if (bo->has_afbc) { /* TODO */ - printf("--leaking afbc (%d bytes)--\n", bo->afbc_metadata_size); + DBG("--leaking afbc (%d bytes)--\n", bo->afbc_metadata_size); } if (bo->has_checksum) { /* TODO */ - printf("--leaking checksum (%zd bytes)--\n", bo->checksum_slab.size); + DBG("--leaking checksum (%zd bytes)--\n", bo->checksum_slab.size); } if (bo->imported) { @@ -450,7 +451,7 @@ panfrost_unmap_bo(struct panfrost_context *ctx, /* Gallium thinks writeback happens here; instead, this is our cue to tile */ if (bo->has_afbc) { - printf("Warning: writes to afbc surface can't possibly work out well for you...\n"); + DBG("Warning: writes to afbc surface can't possibly work out well for you...\n"); } else if (bo->tiled) { struct pipe_context *gallium = (struct pipe_context *) ctx; struct panfrost_screen *screen = pan_screen(gallium->screen); @@ -525,7 +526,7 @@ panfrost_slab_free(void *priv, struct pb_slab *slab) static void panfrost_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc) { - //fprintf(stderr, "TODO %s\n", __func__); + //DBG("TODO %s\n", __func__); } static enum pipe_format diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index b7f2e4bb2e9..9cd65ca8ff8 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -28,6 +28,7 @@ **************************************************************************/ +#include "util/u_debug.h" #include "util/u_memory.h" #include "util/u_format.h" #include "util/u_format_s3tc.h" @@ -46,10 +47,21 @@ #include "pan_screen.h" #include "pan_resource.h" #include "pan_public.h" +#include "pan_util.h" #include "pan_context.h" #include "midgard/midgard_compile.h" +static const struct debug_named_value debug_options[] = { + {"msgs", PAN_DBG_MSGS, "Print debug messages"}, + {"shaders", PAN_DBG_SHADERS, "Dump shaders in NIR"}, + DEBUG_NAMED_VALUE_END +}; + +DEBUG_GET_ONCE_FLAGS_OPTION(pan_debug, "PAN_MESA_DEBUG", debug_options, 0) + +int pan_debug = 0; + struct panfrost_driver *panfrost_create_drm_driver(int fd); struct panfrost_driver *panfrost_create_nondrm_driver(int fd); @@ -531,6 +543,8 @@ panfrost_create_screen(int fd, struct renderonly *ro, bool is_drm) { struct panfrost_screen *screen = CALLOC_STRUCT(panfrost_screen); + pan_debug = debug_get_option_pan_debug(); + if (!screen) return NULL; diff --git a/src/gallium/drivers/panfrost/pan_util.h b/src/gallium/drivers/panfrost/pan_util.h new file mode 100644 index 00000000000..35d95d887c0 --- /dev/null +++ b/src/gallium/drivers/panfrost/pan_util.h @@ -0,0 +1,41 @@ +/************************************************************************** + * + * Copyright 2019 Collabora + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef PAN_UTIL_H +#define PAN_UTIL_H + +#define PAN_DBG_MSGS 0x0001 +#define PAN_DBG_SHADERS 0x0002 + +extern int pan_debug; + +#define DBG(fmt, ...) \ + do { if (pan_debug & PAN_DBG_MSGS) \ + fprintf(stderr, "%s:%d: "fmt, \ + __FUNCTION__, __LINE__, ##__VA_ARGS__); } while (0) + +#endif /* PAN_UTIL_H */ diff --git a/src/gallium/drivers/panfrost/pan_wallpaper.c b/src/gallium/drivers/panfrost/pan_wallpaper.c index 48418012fe8..b402519a767 100644 --- a/src/gallium/drivers/panfrost/pan_wallpaper.c +++ b/src/gallium/drivers/panfrost/pan_wallpaper.c @@ -25,6 +25,7 @@ #include "pan_wallpaper.h" #include "pan_context.h" #include "pan_screen.h" +#include "pan_util.h" //#include "include/panfrost-job.h" #include "midgard/midgard_compile.h" #include "compiler/nir/nir_builder.h" @@ -78,7 +79,8 @@ panfrost_build_wallpaper_program() nir_store_var(b, c_out, texel, 0xFF); - nir_print_shader(shader, stdout); + if (pan_debug & PAN_DBG_SHADERS) + nir_print_shader(shader, stdout); return shader; }