diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c index 48a4993e991..f855a5f079a 100644 --- a/src/gallium/drivers/panfrost/pan_assemble.c +++ b/src/gallium/drivers/panfrost/pan_assemble.c @@ -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 }; diff --git a/src/gallium/drivers/panfrost/pan_compute.c b/src/gallium/drivers/panfrost/pan_compute.c index 1759252e542..2c5d51b5475 100644 --- a/src/gallium/drivers/panfrost/pan_compute.c +++ b/src/gallium/drivers/panfrost/pan_compute.c @@ -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); diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index d080686d5de..1ad8d16b412 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -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; diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 870258e3594..5fc10cab675 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -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 diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index f794c648c57..df090f78e56 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -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; diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index ddd4787dd97..b79813a2370 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -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); diff --git a/src/panfrost/util/pan_ir.h b/src/panfrost/util/pan_ir.h index f456f2d636c..d7e6b298ab2 100644 --- a/src/panfrost/util/pan_ir.h +++ b/src/panfrost/util/pan_ir.h @@ -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;