From 81477f3809b36d8b160f70fd9803f59792904524 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 12 Apr 2022 18:05:59 -0400 Subject: [PATCH] agx: Implement some shader-db stats Instructions, bytes, and registers -- this should hold us over until we can reverse the underlying uarch and get proper cycle estimations. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.c | 26 +++++++++++++++++----- src/asahi/compiler/agx_compiler.h | 2 ++ src/asahi/compiler/agx_register_allocate.c | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index 1d6bb2a2cef..dc418fd6484 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -1152,13 +1152,29 @@ agx_set_st_vary_final(agx_context *ctx) static void agx_print_stats(agx_context *ctx, unsigned size, FILE *fp) { - unsigned nr_ins = 0, nr_bytes = 0, nr_threads = 1; + unsigned nr_ins = 0, max_reg = 0; - /* TODO */ - fprintf(stderr, "%s shader: %u inst, %u bytes, %u threads, %u loops," - "%u:%u spills:fills\n", + agx_foreach_instr_global(ctx, I) { + /* Count instructions */ + nr_ins++; + + /* Count registers */ + agx_foreach_dest(I, d) { + if (I->dest[d].type == AGX_INDEX_REGISTER) { + max_reg = MAX2(max_reg, + I->dest[d].value + agx_write_registers(I, d) - 1); + } + } + } + + /* TODO: Pipe through occupancy */ + unsigned nr_threads = 1; + + fprintf(stderr, "%s - %s shader: %u inst, %u bytes, %u halfregs, %u threads, " + "%u loops, %u:%u spills:fills\n", ctx->nir->info.label ?: "", - nr_ins, nr_bytes, nr_threads, ctx->loop_count, + gl_shader_stage_name(ctx->stage), + nr_ins, size, max_reg, nr_threads, ctx->loop_count, ctx->spills, ctx->fills); } diff --git a/src/asahi/compiler/agx_compiler.h b/src/asahi/compiler/agx_compiler.h index 466b17c7f12..3c609b2c065 100644 --- a/src/asahi/compiler/agx_compiler.h +++ b/src/asahi/compiler/agx_compiler.h @@ -661,6 +661,8 @@ void agx_dce(agx_context *ctx); void agx_ra(agx_context *ctx); void agx_pack_binary(agx_context *ctx, struct util_dynarray *emission); +unsigned agx_write_registers(agx_instr *I, unsigned d); + void agx_compute_liveness(agx_context *ctx); void agx_liveness_ins_update(BITSET_WORD *live, agx_instr *I); diff --git a/src/asahi/compiler/agx_register_allocate.c b/src/asahi/compiler/agx_register_allocate.c index 917e476c809..9042f4a2a9a 100644 --- a/src/asahi/compiler/agx_register_allocate.c +++ b/src/asahi/compiler/agx_register_allocate.c @@ -31,7 +31,7 @@ */ /** Returns number of registers written by an instruction */ -static unsigned +unsigned agx_write_registers(agx_instr *I, unsigned d) { unsigned size = I->dest[d].size == AGX_SIZE_32 ? 2 : 1;