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 <nroberts@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6999>
This commit is contained in:
Alejandro Piñeiro
2020-10-02 14:20:07 +02:00
committed by Marge Bot
parent bcb8dd7432
commit 8de380d26a
5 changed files with 45 additions and 16 deletions

View File

@@ -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 }
};

View File

@@ -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"

View File

@@ -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;

View File

@@ -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

View File

@@ -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);