pan/midgard: Implement blobber-db
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 14 Aug 2019 16:11:55 +0000 (09:11 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 14 Aug 2019 17:31:09 +0000 (10:31 -0700)
We wire through some shader-db-style stats on the current shader in the
disassemble so we can get a quick estimate of shader complexity from a
trace.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Suggested-by: Rob Clark <robdclark@chromium.org>
src/panfrost/midgard/disassemble.c
src/panfrost/midgard/disassemble.h
src/panfrost/midgard/midgard_compile.c
src/panfrost/pandecode/decode.c

index 8f2020c4c4cf3c486e1c1510ed342c70a79e6e97..382b4af7cbf2b3ebc2ab68a867ed90b831d2a8a6 100644 (file)
 
 static bool is_instruction_int = false;
 
+/* Stats */
+
+static unsigned nr_ins = 0;
+
 /* Prints a short form of the tag for branching, the minimum needed to be
  * legible and unambiguous */
 
@@ -541,6 +545,7 @@ print_vector_field(const char *name, uint16_t *words, uint16_t reg_word,
                                  reg_info->src2_reg, override, is_int);
         }
 
+        nr_ins++;
         printf("\n");
 }
 
@@ -621,6 +626,7 @@ print_scalar_field(const char *name, uint16_t *words, uint16_t reg_word,
         } else
                 print_scalar_src(alu_field->src2, reg_info->src2_reg);
 
+        nr_ins++;
         printf("\n");
 }
 
@@ -728,6 +734,8 @@ print_compact_branch_writeout_field(uint16_t word)
                 break;
         }
         }
+
+        nr_ins++;
 }
 
 static void
@@ -764,6 +772,8 @@ print_extended_branch_writeout_field(uint8_t *words)
         printf("%d -> ", br.offset);
         print_tag_short(br.dest_tag);
         printf("\n");
+
+        nr_ins++;
 }
 
 static unsigned
@@ -1034,6 +1044,8 @@ print_load_store_instr(uint64_t data,
         printf(", ");
         print_load_store_arg(word->arg_2, 1);
         printf(" /* %X */\n", word->varying_parameters);
+
+        nr_ins++;
 }
 
 static void
@@ -1291,10 +1303,12 @@ print_texture_word(uint32_t *word, unsigned tabs)
                 printf("// unknownA = 0x%x\n", texture->unknownA);
                 printf("// unknown8 = 0x%x\n", texture->unknown8);
         }
+
+        nr_ins++;
 }
 
 void
-disassemble_midgard(uint8_t *code, size_t size)
+disassemble_midgard(uint8_t *code, size_t size, bool stats, unsigned nr_registers)
 {
         uint32_t *words = (uint32_t *) code;
         unsigned num_words = size / 4;
@@ -1306,6 +1320,11 @@ disassemble_midgard(uint8_t *code, size_t size)
 
         unsigned i = 0;
 
+        /* Stats for shader-db */
+        unsigned nr_bundles = 0;
+        unsigned nr_quadwords = 0;
+        nr_ins = 0;
+
         while (i < num_words) {
                 unsigned tag = words[i] & 0xF;
                 unsigned next_tag = (words[i] >> 4) & 0xF;
@@ -1361,6 +1380,10 @@ disassemble_midgard(uint8_t *code, size_t size)
 
                 i += 4 * num_quad_words;
 
+                /* We are parsing per bundle anyway */
+                nr_bundles++;
+                nr_quadwords += num_quad_words;
+
                 /* Break based on instruction prefetch flag */
 
                 if (i < num_words && next == 1) {
@@ -1371,5 +1394,18 @@ disassemble_midgard(uint8_t *code, size_t size)
                 }
         }
 
-        return;
+        if (stats) {
+                unsigned nr_threads =
+                        (nr_registers <= 4) ? 4 :
+                        (nr_registers <= 8) ? 2 :
+                        1;
+
+                printf("%s shader: "
+                        "%u inst, %u bundles, %u quadwords, "
+                        "%u registers, %u threads, 0 loops\n",
+                        "FRAGMENT", /* TODO */
+                        nr_ins, nr_bundles, nr_quadwords,
+                        nr_registers, nr_threads);
+
+        }
 }
index ab1837c201e5ecbba7fa2c71576fcd6bb8449d18..7ccee2649c6c25fc7b175ad5fe31fc1cb2a3ab47 100644 (file)
@@ -1,2 +1,2 @@
 #include <stddef.h>
-void disassemble_midgard(uint8_t *code, size_t size);
+void disassemble_midgard(uint8_t *code, size_t size, bool stats, unsigned regs);
index 460847e8266036094c4a007fdd8ff34aec901fbe..e348ac052347d50050d248c00fabf4158bcef5af 100644 (file)
@@ -2741,7 +2741,7 @@ midgard_compile_shader_nir(struct midgard_screen *screen, nir_shader *nir, midga
         program->tls_size = ctx->tls_size;
 
         if (midgard_debug & MIDGARD_DBG_SHADERS)
-                disassemble_midgard(program->compiled.data, program->compiled.size);
+                disassemble_midgard(program->compiled.data, program->compiled.size, false, 0);
 
         if (midgard_debug & MIDGARD_DBG_SHADERDB) {
                 unsigned nr_bundles = 0, nr_ins = 0, nr_quadwords = 0;
index 5bbff08f728cfe01e579d2944b54a549c25bb99d..b49044cec2b6af86b4fa035ff706a92721f532ce 100644 (file)
@@ -1430,7 +1430,7 @@ pandecode_scratchpad(uintptr_t pscratchpad, int job_no, char *suffix)
 
 static void
 pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
-                             bool is_bifrost)
+                             bool is_bifrost, unsigned nr_regs)
 {
         struct pandecode_mapped_memory *mem = pandecode_find_mapped_gpu_mem_containing(shader_ptr);
         uint8_t *PANDECODE_PTR_VAR(code, mem, shader_ptr);
@@ -1446,7 +1446,7 @@ pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
         if (is_bifrost) {
                 disassemble_bifrost(code, sz, false);
         } else {
-                disassemble_midgard(code, sz);
+                disassemble_midgard(code, sz, true, nr_regs);
         }
 
         printf("\n\n");
@@ -1507,6 +1507,8 @@ pandecode_vertex_tiler_postfix_pre(const struct mali_vertex_tiler_postfix *p,
                 pandecode_prop("attribute_count = %" PRId16, s->attribute_count);
                 pandecode_prop("varying_count = %" PRId16, s->varying_count);
 
+                unsigned nr_registers = 0;
+
                 if (is_bifrost) {
                         pandecode_log(".bifrost1 = {\n");
                         pandecode_indent++;
@@ -1523,6 +1525,7 @@ pandecode_vertex_tiler_postfix_pre(const struct mali_vertex_tiler_postfix *p,
                         pandecode_prop("uniform_count = %" PRId16, s->midgard1.uniform_count);
                         pandecode_prop("uniform_buffer_count = %" PRId16, s->midgard1.uniform_buffer_count);
                         pandecode_prop("work_count = %" PRId16, s->midgard1.work_count);
+                        nr_registers = s->midgard1.work_count;
 
                         pandecode_log(".flags = ");
                         pandecode_log_decoded_flags(shader_midgard1_flag_info, s->midgard1.flags);
@@ -1627,12 +1630,12 @@ pandecode_vertex_tiler_postfix_pre(const struct mali_vertex_tiler_postfix *p,
                                         shader = pandecode_midgard_blend_mrt(blend_base, job_no, i);
 
                                 if (shader & ~0xF)
-                                        pandecode_shader_disassemble(shader, job_no, job_type, false);
+                                        pandecode_shader_disassemble(shader, job_no, job_type, false, 0);
                         }
                 }
 
                 if (shader_ptr & ~0xF)
-                   pandecode_shader_disassemble(shader_ptr, job_no, job_type, is_bifrost);
+                   pandecode_shader_disassemble(shader_ptr, job_no, job_type, is_bifrost, nr_registers);
         } else
                 pandecode_msg("<no shader>\n");