We'll want all this information to validate the shader descriptor.
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
/* 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 */
reg_info->src2_reg, override, is_int);
}
- nr_ins++;
+ midg_stats.instruction_count++;
printf("\n");
}
} else
print_scalar_src(alu_field->src2, reg_info->src2_reg);
- nr_ins++;
+ midg_stats.instruction_count++;
printf("\n");
}
}
}
- nr_ins++;
+ midg_stats.instruction_count++;
}
static void
print_tag_short(br.dest_tag);
printf("\n");
- nr_ins++;
+ midg_stats.instruction_count++;
}
static unsigned
print_load_store_arg(word->arg_2, 1);
printf(" /* %X */\n", word->varying_parameters);
- nr_ins++;
+ midg_stats.instruction_count++;
}
static void
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;
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;
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 */
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;
}
#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);
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;
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)
{
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