From 8de380d26a0d68c21f6b86e7de5d4bcd7b226a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Fri, 2 Oct 2020 14:20:07 +0200 Subject: [PATCH] broadcom/compiler: add V3D_DEBUG_RA option To ask to debug a registr allocation failure (V3D_DEBUG_REGISTER_ALLOCATION seemed too long to me). When a fallback register allocation algorithm was added, if the register allocation fails, it only dumpg the current vir with the register pressure info with the failed fallback. But if we want do debug the problem, we would be interested on both. Additionally, it was strange that we got the full vir dump with the failure even if no debug option was set. Additionally we add shaderdb like stats for those failures, to make easier to compare one and the other. v2: keep a small warning message in case both register allocation algorithms fails (Neil) Reviewed-by: Neil Roberts Part-of: --- src/broadcom/common/v3d_debug.c | 1 + src/broadcom/common/v3d_debug.h | 1 + src/broadcom/compiler/nir_to_vir.c | 20 +++++++++++++-- src/broadcom/compiler/v3d_compiler.h | 2 ++ src/broadcom/compiler/vir.c | 37 +++++++++++++++++----------- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/broadcom/common/v3d_debug.c b/src/broadcom/common/v3d_debug.c index d4fc648a85b..748c3fbafa5 100644 --- a/src/broadcom/common/v3d_debug.c +++ b/src/broadcom/common/v3d_debug.c @@ -56,6 +56,7 @@ static const struct debug_control debug_control[] = { { "cs", V3D_DEBUG_CS}, { "always_flush", V3D_DEBUG_ALWAYS_FLUSH}, { "precompile", V3D_DEBUG_PRECOMPILE}, + { "ra", V3D_DEBUG_RA}, { NULL, 0 } }; diff --git a/src/broadcom/common/v3d_debug.h b/src/broadcom/common/v3d_debug.h index 78578cfd8e5..f7afb457469 100644 --- a/src/broadcom/common/v3d_debug.h +++ b/src/broadcom/common/v3d_debug.h @@ -57,6 +57,7 @@ extern uint32_t V3D_DEBUG; #define V3D_DEBUG_ALWAYS_FLUSH (1 << 13) #define V3D_DEBUG_CLIF (1 << 14) #define V3D_DEBUG_PRECOMPILE (1 << 15) +#define V3D_DEBUG_RA (1 << 16) #ifdef HAVE_ANDROID_PLATFORM #define LOG_TAG "BROADCOM-MESA" diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c index 25b3230a2e7..65d6d4df280 100644 --- a/src/broadcom/compiler/nir_to_vir.c +++ b/src/broadcom/compiler/nir_to_vir.c @@ -3046,13 +3046,29 @@ v3d_nir_to_vir(struct v3d_compile *c) if (temp_registers) break; + if (c->threads == min_threads && + (V3D_DEBUG & V3D_DEBUG_RA)) { + fprintf(stderr, + "Failed to register allocate using %s\n", + c->fallback_scheduler ? "the fallback scheduler:" : + "the normal scheduler: \n"); + + vir_dump(c); + + char *shaderdb; + int ret = v3d_shaderdb_dump(c, &shaderdb); + if (ret > 0) { + fprintf(stderr, "%s\n", shaderdb); + free(shaderdb); + } + } + if (c->threads == min_threads) { if (c->fallback_scheduler) { fprintf(stderr, "Failed to register allocate at %d " - "threads:\n", + "threads with any strategy.\n", c->threads); - vir_dump(c); } c->compilation_result = V3D_COMPILATION_FAILED_REGISTER_ALLOCATION; diff --git a/src/broadcom/compiler/v3d_compiler.h b/src/broadcom/compiler/v3d_compiler.h index 9061a095bd0..05591f9eb48 100644 --- a/src/broadcom/compiler/v3d_compiler.h +++ b/src/broadcom/compiler/v3d_compiler.h @@ -900,6 +900,8 @@ void qpu_validate(struct v3d_compile *c); struct qpu_reg *v3d_register_allocate(struct v3d_compile *c, bool *spilled); bool vir_init_reg_sets(struct v3d_compiler *compiler); +int v3d_shaderdb_dump(struct v3d_compile *c, char **shaderdb_str); + bool v3d_gl_format_is_return_32(GLenum format); uint32_t diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index a0b08918f32..34f63a573da 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -1167,6 +1167,28 @@ v3d_prog_data_size(gl_shader_stage stage) return prog_data_size[stage]; } +int v3d_shaderdb_dump(struct v3d_compile *c, + char **shaderdb_str) +{ + if (c == NULL) + return -1; + + return asprintf(shaderdb_str, + "%s shader: %d inst, %d threads, %d loops, " + "%d uniforms, %d max-temps, %d:%d spills:fills, " + "%d sfu-stalls, %d inst-and-stalls", + vir_get_stage_name(c), + c->qpu_inst_count, + c->threads, + c->loops, + c->num_uniforms, + vir_get_max_temps(c), + c->spills, + c->fills, + c->qpu_inst_stalled_count, + c->qpu_inst_count + c->qpu_inst_stalled_count); +} + uint64_t *v3d_compile(const struct v3d_compiler *compiler, struct v3d_key *key, struct v3d_prog_data **out_prog_data, @@ -1217,20 +1239,7 @@ uint64_t *v3d_compile(const struct v3d_compiler *compiler, *out_prog_data = prog_data; char *shaderdb; - int ret = asprintf(&shaderdb, - "%s shader: %d inst, %d threads, %d loops, " - "%d uniforms, %d max-temps, %d:%d spills:fills, " - "%d sfu-stalls, %d inst-and-stalls", - vir_get_stage_name(c), - c->qpu_inst_count, - c->threads, - c->loops, - c->num_uniforms, - vir_get_max_temps(c), - c->spills, - c->fills, - c->qpu_inst_stalled_count, - c->qpu_inst_count + c->qpu_inst_stalled_count); + int ret = v3d_shaderdb_dump(c, &shaderdb); if (ret >= 0) { if (V3D_DEBUG & V3D_DEBUG_SHADERDB) fprintf(stderr, "SHADER-DB: %s\n", shaderdb);