From e0aeee946004685527dfa0a4f5f141b85ae076dd Mon Sep 17 00:00:00 2001 From: Erico Nunes Date: Sat, 3 Aug 2019 10:56:12 +0200 Subject: [PATCH] lima: add summary report for shader-db Very basic summary, loops and gpir spills:fills are not updated yet and are only there to comply with the strings to shader-db report.py regex. For now it can be used to analyze the impact of changes in instruction count in both gpir and ppir. The LIMA_DEBUG=shaderdb setting can be useful to output stats on applications other than shader-db. Signed-off-by: Erico Nunes Reviewed-by: Qiang Yu --- src/gallium/drivers/lima/ir/gp/codegen.c | 1 + src/gallium/drivers/lima/ir/gp/gpir.h | 6 +++++ src/gallium/drivers/lima/ir/gp/nir.c | 28 ++++++++++++++++++++++- src/gallium/drivers/lima/ir/lima_ir.h | 6 +++-- src/gallium/drivers/lima/ir/pp/nir.c | 28 ++++++++++++++++++++++- src/gallium/drivers/lima/ir/pp/ppir.h | 5 ++++ src/gallium/drivers/lima/ir/pp/regalloc.c | 3 +++ src/gallium/drivers/lima/lima_program.c | 6 +++-- src/gallium/drivers/lima/lima_screen.c | 2 ++ src/gallium/drivers/lima/lima_screen.h | 1 + 10 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/lima/ir/gp/codegen.c b/src/gallium/drivers/lima/ir/gp/codegen.c index 19eb38c18a7..76e360b4fb1 100644 --- a/src/gallium/drivers/lima/ir/gp/codegen.c +++ b/src/gallium/drivers/lima/ir/gp/codegen.c @@ -602,6 +602,7 @@ bool gpir_codegen_prog(gpir_compiler *comp) comp->prog->shader = code; comp->prog->shader_size = num_instr * sizeof(gpir_codegen_instr); + comp->num_instr = num_instr; if (lima_debug & LIMA_DEBUG_GP) { gpir_codegen_print_prog(comp); diff --git a/src/gallium/drivers/lima/ir/gp/gpir.h b/src/gallium/drivers/lima/ir/gp/gpir.h index e7707814b7c..36553a7e169 100644 --- a/src/gallium/drivers/lima/ir/gp/gpir.h +++ b/src/gallium/drivers/lima/ir/gp/gpir.h @@ -388,6 +388,12 @@ typedef struct gpir_compiler { struct lima_vs_shader_state *prog; int constant_base; + + /* shaderdb */ + int num_instr; + int num_loops; + int num_spills; + int num_fills; } gpir_compiler; #define GPIR_VALUE_REG_NUM 11 diff --git a/src/gallium/drivers/lima/ir/gp/nir.c b/src/gallium/drivers/lima/ir/gp/nir.c index 18121b9a914..c208d735b9d 100644 --- a/src/gallium/drivers/lima/ir/gp/nir.c +++ b/src/gallium/drivers/lima/ir/gp/nir.c @@ -24,6 +24,8 @@ #include "util/ralloc.h" #include "compiler/nir/nir.h" +#include "pipe/p_state.h" + #include "gpir.h" #include "lima_context.h" @@ -396,7 +398,29 @@ static int gpir_glsl_type_size(enum glsl_base_type type) return 4; } -bool gpir_compile_nir(struct lima_vs_shader_state *prog, struct nir_shader *nir) +static void gpir_print_shader_db(struct nir_shader *nir, gpir_compiler *comp, + struct pipe_debug_callback *debug) +{ + const struct shader_info *info = &nir->info; + char *shaderdb; + int ret = asprintf(&shaderdb, + "%s shader: %d inst, %d loops, %d:%d spills:fills\n", + gl_shader_stage_name(info->stage), + comp->num_instr, + comp->num_loops, + comp->num_spills, + comp->num_fills); + assert(ret >= 0); + + if (lima_debug & LIMA_DEBUG_SHADERDB) + fprintf(stderr, "SHADER-DB: %s\n", shaderdb); + + pipe_debug_message(debug, SHADER_INFO, "%s", shaderdb); + free(shaderdb); +} + +bool gpir_compile_nir(struct lima_vs_shader_state *prog, struct nir_shader *nir, + const struct pipe_debug_callback *debug) { nir_function_impl *func = nir_shader_get_entrypoint(nir); gpir_compiler *comp = gpir_compiler_create(prog, func->reg_alloc, func->ssa_alloc); @@ -446,6 +470,8 @@ bool gpir_compile_nir(struct lima_vs_shader_state *prog, struct nir_shader *nir) v->components += glsl_get_components(var->type); } + gpir_print_shader_db(nir, comp, debug); + ralloc_free(comp); return true; diff --git a/src/gallium/drivers/lima/ir/lima_ir.h b/src/gallium/drivers/lima/ir/lima_ir.h index 9ef4b68235e..8685b5db300 100644 --- a/src/gallium/drivers/lima/ir/lima_ir.h +++ b/src/gallium/drivers/lima/ir/lima_ir.h @@ -53,12 +53,14 @@ struct lima_vs_shader_state; struct lima_fs_shader_state; /* gpir interface */ -bool gpir_compile_nir(struct lima_vs_shader_state *prog, struct nir_shader *nir); +bool gpir_compile_nir(struct lima_vs_shader_state *prog, struct nir_shader *nir, + const struct pipe_debug_callback *debug); /* ppir interface */ bool ppir_compile_nir(struct lima_fs_shader_state *prog, struct nir_shader *nir, - struct ra_regs *ra); + struct ra_regs *ra, + const struct pipe_debug_callback *debug); struct ra_regs *ppir_regalloc_init(void *mem_ctx); void lima_nir_lower_uniform_to_scalar(nir_shader *shader); diff --git a/src/gallium/drivers/lima/ir/pp/nir.c b/src/gallium/drivers/lima/ir/pp/nir.c index b0714c8363f..e73a7967dc9 100644 --- a/src/gallium/drivers/lima/ir/pp/nir.c +++ b/src/gallium/drivers/lima/ir/pp/nir.c @@ -27,6 +27,8 @@ #include "util/ralloc.h" #include "util/bitscan.h" #include "compiler/nir/nir.h" +#include "pipe/p_state.h" + #include "ppir.h" @@ -562,8 +564,30 @@ static void ppir_add_ordering_deps(ppir_compiler *comp) } } +static void ppir_print_shader_db(struct nir_shader *nir, ppir_compiler *comp, + const struct pipe_debug_callback *debug) +{ + const struct shader_info *info = &nir->info; + char *shaderdb; + int ret = asprintf(&shaderdb, + "%s shader: %d inst, %d loops, %d:%d spills:fills\n", + gl_shader_stage_name(info->stage), + comp->cur_instr_index, + comp->num_loops, + comp->num_spills, + comp->num_fills); + assert(ret >= 0); + + if (lima_debug & LIMA_DEBUG_SHADERDB) + fprintf(stderr, "SHADER-DB: %s\n", shaderdb); + + pipe_debug_message(debug, SHADER_INFO, "%s", shaderdb); + free(shaderdb); +} + bool ppir_compile_nir(struct lima_fs_shader_state *prog, struct nir_shader *nir, - struct ra_regs *ra) + struct ra_regs *ra, + const struct pipe_debug_callback *debug) { nir_function_impl *func = nir_shader_get_entrypoint(nir); ppir_compiler *comp = ppir_compiler_create(prog, func->reg_alloc, func->ssa_alloc); @@ -611,6 +635,8 @@ bool ppir_compile_nir(struct lima_fs_shader_state *prog, struct nir_shader *nir, if (!ppir_codegen_prog(comp)) goto err_out0; + ppir_print_shader_db(nir, comp, debug); + ralloc_free(comp); return true; diff --git a/src/gallium/drivers/lima/ir/pp/ppir.h b/src/gallium/drivers/lima/ir/pp/ppir.h index d03b48a828b..e8c6e015f0e 100644 --- a/src/gallium/drivers/lima/ir/pp/ppir.h +++ b/src/gallium/drivers/lima/ir/pp/ppir.h @@ -346,6 +346,11 @@ typedef struct ppir_compiler { /* for regalloc spilling debug */ int force_spilling; + /* shaderdb */ + int num_loops; + int num_spills; + int num_fills; + ppir_block *discard_block; } ppir_compiler; diff --git a/src/gallium/drivers/lima/ir/pp/regalloc.c b/src/gallium/drivers/lima/ir/pp/regalloc.c index 46903840099..c1c3736aff5 100644 --- a/src/gallium/drivers/lima/ir/pp/regalloc.c +++ b/src/gallium/drivers/lima/ir/pp/regalloc.c @@ -392,6 +392,7 @@ static ppir_alu_node* ppir_update_spilled_src(ppir_compiler *comp, if (!load_node) return NULL; list_addtail(&load_node->list, &node->list); + comp->num_fills++; ppir_load_node *load = ppir_node_to_load(load_node); @@ -484,6 +485,7 @@ static bool ppir_update_spilled_dest(ppir_compiler *comp, ppir_block *block, if (!load_node) return NULL; list_addtail(&load_node->list, &node->list); + comp->num_fills++; ppir_load_node *load = ppir_node_to_load(load_node); @@ -533,6 +535,7 @@ static bool ppir_update_spilled_dest(ppir_compiler *comp, ppir_block *block, if (!store_node) return false; list_addtail(&store_node->list, &node->list); + comp->num_spills++; ppir_store_node *store = ppir_node_to_store(store_node); diff --git a/src/gallium/drivers/lima/lima_program.c b/src/gallium/drivers/lima/lima_program.c index c22636fc50e..367ccb8a4e0 100644 --- a/src/gallium/drivers/lima/lima_program.c +++ b/src/gallium/drivers/lima/lima_program.c @@ -214,6 +214,7 @@ static void * lima_create_fs_state(struct pipe_context *pctx, const struct pipe_shader_state *cso) { + struct lima_context *ctx = lima_context(pctx); struct lima_screen *screen = lima_screen(pctx->screen); struct lima_fs_shader_state *so = rzalloc(NULL, struct lima_fs_shader_state); @@ -234,7 +235,7 @@ lima_create_fs_state(struct pipe_context *pctx, if (lima_debug & LIMA_DEBUG_PP) nir_print_shader(nir, stdout); - if (!ppir_compile_nir(so, nir, screen->pp_ra)) { + if (!ppir_compile_nir(so, nir, screen->pp_ra, &ctx->debug)) { ralloc_free(so); return NULL; } @@ -306,6 +307,7 @@ static void * lima_create_vs_state(struct pipe_context *pctx, const struct pipe_shader_state *cso) { + struct lima_context *ctx = lima_context(pctx); struct lima_vs_shader_state *so = rzalloc(NULL, struct lima_vs_shader_state); if (!so) @@ -325,7 +327,7 @@ lima_create_vs_state(struct pipe_context *pctx, if (lima_debug & LIMA_DEBUG_GP) nir_print_shader(nir, stdout); - if (!gpir_compile_nir(so, nir)) { + if (!gpir_compile_nir(so, nir, &ctx->debug)) { ralloc_free(so); return NULL; } diff --git a/src/gallium/drivers/lima/lima_screen.c b/src/gallium/drivers/lima/lima_screen.c index 26a7051e67e..8e337425f7a 100644 --- a/src/gallium/drivers/lima/lima_screen.c +++ b/src/gallium/drivers/lima/lima_screen.c @@ -440,6 +440,8 @@ static const struct debug_named_value debug_options[] = { "print PP shader compiler result of each stage" }, { "dump", LIMA_DEBUG_DUMP, "dump GPU command stream to $PWD/lima.dump" }, + { "shaderdb", LIMA_DEBUG_SHADERDB, + "print shader information for shaderdb" }, { NULL } }; diff --git a/src/gallium/drivers/lima/lima_screen.h b/src/gallium/drivers/lima/lima_screen.h index 7d1f6f82924..29693168828 100644 --- a/src/gallium/drivers/lima/lima_screen.h +++ b/src/gallium/drivers/lima/lima_screen.h @@ -36,6 +36,7 @@ #define LIMA_DEBUG_GP (1 << 0) #define LIMA_DEBUG_PP (1 << 1) #define LIMA_DEBUG_DUMP (1 << 2) +#define LIMA_DEBUG_SHADERDB (1 << 3) extern uint32_t lima_debug; extern FILE *lima_dump_command_stream; -- 2.30.2