panfrost: Add support for PAN_MESA_DEBUG
authorTomeu Vizoso <tomeu.vizoso@collabora.com>
Fri, 8 Mar 2019 14:24:57 +0000 (15:24 +0100)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Tue, 12 Mar 2019 00:30:27 +0000 (00:30 +0000)
Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/gallium/drivers/panfrost/pan_blend_shaders.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_resource.c
src/gallium/drivers/panfrost/pan_screen.c
src/gallium/drivers/panfrost/pan_util.h [new file with mode: 0644]
src/gallium/drivers/panfrost/pan_wallpaper.c

index 648e84b0350af0156a528da71f2110fb9c6ff8f5..fadcdecb044842a8cd19d586a26a6b73b5cdb29b 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <stdio.h>
 #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 */
 
index 3c8a483b8f584e47f978d90a6f69fea9a8937ee0..095f9cf3606d72dad93699dcbe2b67fe58d5bc5e 100644 (file)
@@ -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;
         }
 
index abef927ada55b3b17ac3a4b1a5497dab9898093c..b869170b8249a3499282acf8d879213b364da4a8 100644 (file)
@@ -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
index b7f2e4bb2e9b19197129697168f712928962ea2e..9cd65ca8ff8f935f80aab16d4f70c19accde7999 100644 (file)
@@ -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"
 #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 (file)
index 0000000..35d95d8
--- /dev/null
@@ -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 */
index 48418012fe846f64271ae12647460392d5ffdd9b..b402519a7673491ebbc348bfde5dc6b7cf7f6e77 100644 (file)
@@ -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;
 }