pan/decode: Hoist shader-db stats to shared decode
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 21 Aug 2019 21:00:46 +0000 (14:00 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 22 Aug 2019 19:50:14 +0000 (12:50 -0700)
We'll want all this information to validate the shader descriptor.

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

index be26a9c3686929333069810a0d85c2c30cf1b11a..f42e0783b56febd628a4b9186d05de77617e7fb9 100644 (file)
@@ -44,7 +44,7 @@ static bool is_instruction_int = false;
 
 /* Stats */
 
-static unsigned nr_ins = 0;
+static struct midgard_disasm_stats midg_stats;
 
 /* Prints a short form of the tag for branching, the minimum needed to be
  * legible and unambiguous */
@@ -554,7 +554,7 @@ print_vector_field(const char *name, uint16_t *words, uint16_t reg_word,
                                  reg_info->src2_reg, override, is_int);
         }
 
-        nr_ins++;
+        midg_stats.instruction_count++;
         printf("\n");
 }
 
@@ -635,7 +635,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++;
+        midg_stats.instruction_count++;
         printf("\n");
 }
 
@@ -744,7 +744,7 @@ print_compact_branch_writeout_field(uint16_t word)
         }
         }
 
-        nr_ins++;
+        midg_stats.instruction_count++;
 }
 
 static void
@@ -782,7 +782,7 @@ print_extended_branch_writeout_field(uint8_t *words)
         print_tag_short(br.dest_tag);
         printf("\n");
 
-        nr_ins++;
+        midg_stats.instruction_count++;
 }
 
 static unsigned
@@ -1061,7 +1061,7 @@ print_load_store_instr(uint64_t data,
         print_load_store_arg(word->arg_2, 1);
         printf(" /* %X */\n", word->varying_parameters);
 
-        nr_ins++;
+        midg_stats.instruction_count++;
 }
 
 static void
@@ -1349,11 +1349,11 @@ print_texture_word(uint32_t *word, unsigned tabs)
                 printf("// unknown8 = 0x%x\n", texture->unknown8);
         }
 
-        nr_ins++;
+        midg_stats.instruction_count++;
 }
 
-void
-disassemble_midgard(uint8_t *code, size_t size, bool stats, unsigned nr_registers, const char *prefix)
+struct midgard_disasm_stats
+disassemble_midgard(uint8_t *code, size_t size)
 {
         uint32_t *words = (uint32_t *) code;
         unsigned num_words = size / 4;
@@ -1366,9 +1366,7 @@ disassemble_midgard(uint8_t *code, size_t size, bool stats, unsigned nr_register
         unsigned i = 0;
 
         /* Stats for shader-db */
-        unsigned nr_bundles = 0;
-        unsigned nr_quadwords = 0;
-        nr_ins = 0;
+        memset(&midg_stats, 0, sizeof(midg_stats));
 
         while (i < num_words) {
                 unsigned tag = words[i] & 0xF;
@@ -1424,8 +1422,8 @@ disassemble_midgard(uint8_t *code, size_t size, bool stats, unsigned nr_register
                 unsigned next = (words[i] & 0xF0) >> 4;
 
                 /* We are parsing per bundle anyway */
-                nr_bundles++;
-                nr_quadwords += num_quad_words;
+                midg_stats.bundle_count++;
+                midg_stats.quadword_count += num_quad_words;
 
                 /* Break based on instruction prefetch flag */
 
@@ -1439,18 +1437,5 @@ disassemble_midgard(uint8_t *code, size_t size, bool stats, unsigned nr_register
                 i += 4 * num_quad_words;
         }
 
-        if (stats) {
-                unsigned nr_threads =
-                        (nr_registers <= 4) ? 4 :
-                        (nr_registers <= 8) ? 2 :
-                        1;
-
-                printf("%s"
-                        "%u inst, %u bundles, %u quadwords, "
-                        "%u registers, %u threads, 0 loops\n",
-                        prefix,
-                        nr_ins, nr_bundles, nr_quadwords,
-                        nr_registers, nr_threads);
-
-        }
+        return midg_stats;
 }
index ca578b7d3aa27070ef52725958cb1b8549587d1f..dacc7a16d5dcc72ab890de5690411e1b211b0376 100644 (file)
@@ -1,2 +1,23 @@
 #include <stddef.h>
-void disassemble_midgard(uint8_t *code, size_t size, bool stats, unsigned regs, const char *prefix);
+
+struct midgard_disasm_stats {
+        /* Counts gleaned from disassembly, or negative if the field cannot be
+         * inferred, for instance due to indirect access. If negative, the abs
+         * is the upper limit for the count. */
+
+        signed texture_count;
+        signed sampler_count;
+        signed attribute_count;
+        signed varying_count;
+        signed uniform_count;
+        signed uniform_buffer_count;
+        signed work_count;
+
+        /* These are pseudometrics for shader-db */
+        unsigned instruction_count;
+        unsigned bundle_count;
+        unsigned quadword_count;
+};
+
+struct midgard_disasm_stats
+disassemble_midgard(uint8_t *code, size_t size);
index 9d11ad25ea80a18f7dd28c32a7bd78363c9da6d7..8000f72c9cf6f36cdbb37644e24c96c5f281d57a 100644 (file)
@@ -2810,7 +2810,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, false, 0, "");
+                disassemble_midgard(program->compiled.data, program->compiled.size);
 
         if (midgard_debug & MIDGARD_DBG_SHADERDB) {
                 unsigned nr_bundles = 0, nr_ins = 0, nr_quadwords = 0;
index de7365b3932148d15464898e70b38a8f516d46f2..90d205de56ff859be69c8b0ba418ce23d67d8cd4 100644 (file)
@@ -1720,7 +1720,7 @@ pandecode_scratchpad(uintptr_t pscratchpad, int job_no, char *suffix)
 
 static unsigned shader_id = 0;
 
-static void
+static struct midgard_disasm_stats
 pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
                              bool is_bifrost, unsigned nr_regs)
 {
@@ -1735,19 +1735,45 @@ pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
 
         printf("\n\n");
 
-        char prefix[512];
-
-        snprintf(prefix, sizeof(prefix) - 1, "shader%d - %s shader: ",
-                        shader_id++,
-                        (type == JOB_TYPE_TILER) ? "FRAGMENT" : "VERTEX");
+        struct midgard_disasm_stats stats;
 
         if (is_bifrost) {
                 disassemble_bifrost(code, sz, false);
+
+                /* TODO: Extend stats to Bifrost */
+                stats.texture_count = -1;
+                stats.sampler_count = -1;
+                stats.attribute_count = -1;
+                stats.varying_count = -1;
+                stats.uniform_count = -1;
+                stats.uniform_buffer_count = -1;
+                stats.work_count = -1;
+
+                stats.instruction_count = 0;
+                stats.bundle_count = 0;
+                stats.quadword_count = 0;
         } else {
-                disassemble_midgard(code, sz, true, nr_regs, prefix);
+                stats = disassemble_midgard(code, sz);
+                stats.work_count = nr_regs;
         }
 
-        printf("\n\n");
+        /* Print shader-db stats */
+
+        unsigned nr_threads =
+                (stats.work_count <= 4) ? 4 :
+                (stats.work_count <= 8) ? 2 :
+                1;
+
+        printf("shader%d - %s shader: "
+                "%u inst, %u bundles, %u quadwords, "
+                "%u registers, %u threads, 0 loops\n\n\n",
+                shader_id++,
+                (type == JOB_TYPE_TILER) ? "FRAGMENT" : "VERTEX",
+                stats.instruction_count, stats.bundle_count, stats.quadword_count,
+                stats.work_count, nr_threads);
+
+
+        return stats;
 }
 
 static void