panfrost: Route shader-db to debug, not stderr
authorAlyssa Rosenzweig <alyssa@collabora.com>
Wed, 31 Aug 2022 19:05:21 +0000 (15:05 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 1 Sep 2022 14:50:24 +0000 (14:50 +0000)
This brings us in line with the rest of Mesa, fixing multithreaded shader-db
reports and the Total CPU Time report at the end.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18351>

src/gallium/drivers/panfrost/pan_assemble.c
src/gallium/drivers/panfrost/pan_compute.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h
src/panfrost/bifrost/bifrost_compile.c
src/panfrost/midgard/midgard_compile.c
src/panfrost/util/pan_ir.h

index 48a4993..f855a5f 100644 (file)
@@ -40,6 +40,7 @@ panfrost_shader_compile(struct pipe_screen *pscreen,
                         struct panfrost_pool *shader_pool,
                         struct panfrost_pool *desc_pool,
                         const nir_shader *ir,
+                        struct util_debug_callback *dbg,
                         struct panfrost_shader_state *state)
 {
         struct panfrost_screen *screen = pan_screen(pscreen);
@@ -54,7 +55,7 @@ panfrost_shader_compile(struct pipe_screen *pscreen,
                 xfb->info.internal = true;
 
                 state->xfb = calloc(1, sizeof(struct panfrost_shader_state));
-                panfrost_shader_compile(pscreen, shader_pool, desc_pool, xfb, state->xfb);
+                panfrost_shader_compile(pscreen, shader_pool, desc_pool, xfb, dbg, state->xfb);
 
                 /* Main shader no longer uses XFB */
                 s->info.has_transform_feedback_varyings = false;
@@ -80,8 +81,8 @@ panfrost_shader_compile(struct pipe_screen *pscreen,
 
         /* Call out to Midgard compiler given the above NIR */
         struct panfrost_compile_inputs inputs = {
+                .debug = dbg,
                 .gpu_id = dev->gpu_id,
-                .shaderdb = !!(dev->debug & PAN_DBG_PRECOMPILE),
                 .fixed_sysval_ubo = -1,
                 .fixed_varying_mask = state->key.fixed_varying_mask
         };
index 1759252..2c5d51b 100644 (file)
@@ -71,7 +71,8 @@ panfrost_create_compute_state(
         }
 
         panfrost_shader_compile(pctx->screen, &ctx->shaders, &ctx->descs,
-                                deserialized ?: cso->prog, v);
+                                deserialized ?: cso->prog,
+                                &ctx->base.debug, v);
 
         /* There are no variants so we won't need the NIR again */
         ralloc_free(deserialized);
index d080686..1ad8d16 100644 (file)
@@ -47,6 +47,7 @@
 #include "tgsi/tgsi_from_mesa.h"
 #include "nir/tgsi_to_nir.h"
 #include "util/u_math.h"
+#include "util/u_debug_cb.h"
 
 #include "pan_screen.h"
 #include "pan_util.h"
@@ -344,7 +345,7 @@ panfrost_create_shader_state(
 
                 panfrost_shader_compile(pctx->screen,
                                         &ctx->shaders, &ctx->descs,
-                                        so->nir, &state);
+                                        so->nir, &ctx->base.debug, &state);
         }
 
         return so;
@@ -516,7 +517,7 @@ panfrost_new_variant_locked(
         /* We finally have a variant, so compile it */
         panfrost_shader_compile(ctx->base.screen,
                                 &ctx->shaders, &ctx->descs,
-                                variants->nir, shader_state);
+                                variants->nir, &ctx->base.debug, shader_state);
 
         /* Fixup the stream out information */
         shader_state->stream_output = variants->stream_output;
@@ -1093,6 +1094,7 @@ panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
         gallium->destroy = panfrost_destroy;
 
         gallium->set_framebuffer_state = panfrost_set_framebuffer_state;
+        gallium->set_debug_callback = u_default_set_debug_callback;
 
         gallium->flush = panfrost_flush;
         gallium->clear = panfrost_clear;
index 870258e..5fc10ca 100644 (file)
@@ -404,6 +404,7 @@ panfrost_shader_compile(struct pipe_screen *pscreen,
                         struct panfrost_pool *shader_pool,
                         struct panfrost_pool *desc_pool,
                         const nir_shader *ir,
+                        struct util_debug_callback *dbg,
                         struct panfrost_shader_state *state);
 
 void
index f794c64..df090f7 100644 (file)
@@ -4191,8 +4191,8 @@ bi_shader_stage_name(bi_context *ctx)
                 return gl_shader_stage_name(ctx->stage);
 }
 
-static void
-bi_print_stats(bi_context *ctx, unsigned size, FILE *fp)
+static char *
+bi_print_stats(bi_context *ctx, unsigned size)
 {
         struct bi_stats stats = { 0 };
 
@@ -4231,11 +4231,10 @@ bi_print_stats(bi_context *ctx, unsigned size, FILE *fp)
         unsigned nr_threads = full_threads ? 2 : 1;
 
         /* Dump stats */
-        char *str = ralloc_asprintf(NULL, "%s - %s shader: "
+        char *str = ralloc_asprintf(NULL, "%s shader: "
                         "%u inst, %u tuples, %u clauses, "
                         "%f cycles, %f arith, %f texture, %f vary, %f ldst, "
                         "%u quadwords, %u threads",
-                        ctx->nir->info.label ?: "",
                         bi_shader_stage_name(ctx),
                         stats.nr_ins, stats.nr_tuples, stats.nr_clauses,
                         cycles_bound, cycles_arith, cycles_texture,
@@ -4246,15 +4245,14 @@ bi_print_stats(bi_context *ctx, unsigned size, FILE *fp)
                 ralloc_asprintf_append(&str, ", %u preloads", bi_count_preload_cost(ctx));
         }
 
-        ralloc_asprintf_append(&str, ", %u loops, %u:%u spills:fills\n",
+        ralloc_asprintf_append(&str, ", %u loops, %u:%u spills:fills",
                         ctx->loop_count, ctx->spills, ctx->fills);
 
-        fputs(str, stderr);
-        ralloc_free(str);
+        return str;
 }
 
-static void
-va_print_stats(bi_context *ctx, unsigned size, FILE *fp)
+static char *
+va_print_stats(bi_context *ctx, unsigned size)
 {
         unsigned nr_ins = 0;
         struct va_stats stats = { 0 };
@@ -4292,11 +4290,10 @@ va_print_stats(bi_context *ctx, unsigned size, FILE *fp)
         unsigned nr_threads = (ctx->info.work_reg_count <= 32) ? 2 : 1;
 
         /* Dump stats */
-        fprintf(stderr, "%s - %s shader: "
+        return ralloc_asprintf(NULL, "%s shader: "
                         "%u inst, %f cycles, %f fma, %f cvt, %f sfu, %f v, "
                         "%f t, %f ls, %u quadwords, %u threads, %u loops, "
-                        "%u:%u spills:fills\n",
-                        ctx->nir->info.label ?: "",
+                        "%u:%u spills:fills",
                         bi_shader_stage_name(ctx),
                         nr_ins, cycles, cycles_fma, cycles_cvt, cycles_sfu,
                         cycles_v, cycles_t, cycles_ls, size / 16, nr_threads,
@@ -5162,13 +5159,23 @@ bi_compile_variant_nir(nir_shader *nir,
                 fflush(stdout);
         }
 
-        if ((bifrost_debug & BIFROST_DBG_SHADERDB || inputs->shaderdb) &&
-            !skip_internal) {
+        if (!skip_internal &&
+            ((bifrost_debug & BIFROST_DBG_SHADERDB) || inputs->debug)) {
+                char *shaderdb;
+
                 if (ctx->arch >= 9) {
-                        va_print_stats(ctx, binary->size - offset, stderr);
+                        shaderdb = va_print_stats(ctx, binary->size - offset);
                 } else {
-                        bi_print_stats(ctx, binary->size - offset, stderr);
+                        shaderdb = bi_print_stats(ctx, binary->size - offset);
                 }
+
+                if (bifrost_debug & BIFROST_DBG_SHADERDB)
+                        fprintf(stderr, "SHADER-DB: %s\n", shaderdb);
+
+                if (inputs->debug)
+                        util_debug_message(inputs->debug, SHADER_INFO, "%s", shaderdb);
+
+                ralloc_free(shaderdb);
         }
 
         return ctx;
index ddd4787..b79813a 100644 (file)
@@ -3348,7 +3348,7 @@ midgard_compile_shader_nir(nir_shader *nir,
         if (binary->size)
                 memset(util_dynarray_grow(binary, uint8_t, 16), 0, 16);
 
-        if ((midgard_debug & MIDGARD_DBG_SHADERDB || inputs->shaderdb) &&
+        if ((midgard_debug & MIDGARD_DBG_SHADERDB || inputs->debug) &&
             !nir->info.internal) {
                 unsigned nr_bundles = 0, nr_ins = 0;
 
@@ -3373,19 +3373,28 @@ midgard_compile_shader_nir(nir_shader *nir,
                         (nr_registers <= 8) ? 2 :
                         1;
 
+                char *shaderdb = NULL;
+
                 /* Dump stats */
 
-                fprintf(stderr, "%s - %s shader: "
+                asprintf(&shaderdb, "%s shader: "
                         "%u inst, %u bundles, %u quadwords, "
                         "%u registers, %u threads, %u loops, "
-                        "%u:%u spills:fills\n",
-                        ctx->nir->info.label ?: "",
+                        "%u:%u spills:fills",
                         ctx->inputs->is_blend ? "PAN_SHADER_BLEND" :
                         gl_shader_stage_name(ctx->stage),
                         nr_ins, nr_bundles, ctx->quadword_count,
                         nr_registers, nr_threads,
                         ctx->loop_count,
                         ctx->spills, ctx->fills);
+
+                if (midgard_debug & MIDGARD_DBG_SHADERDB)
+                        fprintf(stderr, "SHADER-DB: %s\n", shaderdb);
+
+                if (inputs->debug)
+                        util_debug_message(inputs->debug, SHADER_INFO, "%s", shaderdb);
+
+                free(shaderdb);
         }
 
         _mesa_hash_table_u64_destroy(ctx->ssa_constants);
index f456f2d..d7e6b29 100644 (file)
@@ -178,6 +178,8 @@ int
 panfrost_sysval_for_instr(nir_instr *instr, nir_dest *dest);
 
 struct panfrost_compile_inputs {
+        struct util_debug_callback *debug;
+
         unsigned gpu_id;
         bool is_blend, is_blit;
         struct {
@@ -187,7 +189,6 @@ struct panfrost_compile_inputs {
         } blend;
         int fixed_sysval_ubo;
         struct panfrost_sysvals *fixed_sysval_layout;
-        bool shaderdb;
         bool no_idvs;
         bool no_ubo_to_push;