panfrost/midgard: Dump shader-db stats
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 8 Jul 2019 23:42:29 +0000 (16:42 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 10 Jul 2019 13:45:20 +0000 (06:45 -0700)
All the kool kids are doing it.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/midgard/midgard.h
src/gallium/drivers/panfrost/midgard/midgard_compile.c

index d632063e8a44170d58f1584a99f3e744819b958f..ab10b9b8cb121c6c0991c1e9cf6a9b90747b234f 100644 (file)
@@ -33,6 +33,7 @@
 
 #define MIDGARD_DBG_MSGS               0x0001
 #define MIDGARD_DBG_SHADERS            0x0002
+#define MIDGARD_DBG_SHADERDB            0x0004
 
 extern int midgard_debug;
 
index 9c86f19fd0602ef6718aac2cbc4fe63699b13a49..43f451c79db2af92e260abd008a1d5a1d36c0bdd 100644 (file)
 static const struct debug_named_value debug_options[] = {
        {"msgs",      MIDGARD_DBG_MSGS,         "Print debug messages"},
        {"shaders",   MIDGARD_DBG_SHADERS,      "Dump shaders in NIR and MIR"},
+        {"shaderdb",  MIDGARD_DBG_SHADERDB,     "Prints shader-db statistics"},
        DEBUG_NAMED_VALUE_END
 };
 
 DEBUG_GET_ONCE_FLAGS_OPTION(midgard_debug, "MIDGARD_MESA_DEBUG", debug_options, 0)
 
+unsigned SHADER_DB_COUNT = 0;
+
 int midgard_debug = 0;
 
 #define DBG(fmt, ...) \
@@ -2852,5 +2855,41 @@ midgard_compile_shader_nir(nir_shader *nir, midgard_program *program, bool is_bl
        if (midgard_debug & MIDGARD_DBG_SHADERS)
                disassemble_midgard(program->compiled.data, program->compiled.size);
 
+        if (midgard_debug & MIDGARD_DBG_SHADERDB) {
+                unsigned nr_bundles = 0, nr_ins = 0;
+
+                /* Count instructions and bundles */
+
+                mir_foreach_instr_global(ctx, ins) {
+                        nr_ins++;
+                }
+
+                mir_foreach_block(ctx, block) {
+                        nr_bundles += util_dynarray_num_elements(
+                                        &block->bundles, midgard_bundle);
+                }
+
+                /* Calculate thread count. There are certain cutoffs by
+                 * register count for thread count */
+
+                unsigned nr_registers = program->work_register_count;
+
+                unsigned nr_threads =
+                        (nr_registers <= 4) ? 4 :
+                        (nr_registers <= 8) ? 2 :
+                                              1;
+
+                /* Dump stats */
+
+                fprintf(stderr, "shader%d - %s shader: "
+                                "%u inst, %u bundles, "
+                                "%u registers, %u threads, 0 loops\n",
+                                SHADER_DB_COUNT++,
+                                gl_shader_stage_name(ctx->stage),
+                                nr_ins, nr_bundles,
+                                nr_registers, nr_threads);
+        }
+
+
         return 0;
 }