iris: Create archive file when using INTEL_DEBUG=mda

Acked-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29146>
This commit is contained in:
Caio Oliveira 2024-06-06 09:49:05 -07:00
parent 6c90a9c8e3
commit dedbe0e826

View file

@ -54,6 +54,7 @@
#include "iris_context.h" #include "iris_context.h"
#include "iris_pipe.h" #include "iris_pipe.h"
#include "nir/tgsi_to_nir.h" #include "nir/tgsi_to_nir.h"
#include "git_sha1.h"
static inline enum intel_vue_layout static inline enum intel_vue_layout
vue_layout(bool separate_shader) vue_layout(bool separate_shader)
@ -1832,6 +1833,36 @@ iris_schedule_compile(struct iris_screen *screen,
} }
} }
static debug_archiver *
iris_debug_archiver_open(void *tmp_ctx, struct iris_screen *screen,
struct iris_uncompiled_shader *ish, const void *key,
unsigned key_size)
{
if (!INTEL_DEBUG(DEBUG_MDA) || !screen->brw)
return NULL;
char name[SHA1_DIGEST_STRING_LENGTH + 5] = {};
{
struct mesa_sha1 ctx;
unsigned char hash[SHA1_DIGEST_LENGTH];
_mesa_sha1_init(&ctx);
_mesa_sha1_update(&ctx, ish->nir->info.source_blake3, BLAKE3_OUT_LEN);
_mesa_sha1_update(&ctx, key, key_size);
_mesa_sha1_final(&ctx, hash);
_mesa_sha1_format(name, hash);
}
memcpy(&name[SHA1_DIGEST_STRING_LENGTH - 1], ".iris", 5);
debug_archiver *debug_archiver =
debug_archiver_open(tmp_ctx, name, PACKAGE_VERSION MESA_GIT_SHA1);
debug_archiver_set_prefix(debug_archiver,
_mesa_shader_stage_to_abbrev(ish->nir->info.stage));
return debug_archiver;
}
/** /**
* Compile a vertex shader, and upload the assembly. * Compile a vertex shader, and upload the assembly.
*/ */
@ -1851,6 +1882,9 @@ iris_compile_vs(struct iris_screen *screen,
nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir); nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
const struct iris_vs_prog_key *const key = &shader->key.vs; const struct iris_vs_prog_key *const key = &shader->key.vs;
debug_archiver *debug_archiver =
iris_debug_archiver_open(mem_ctx, screen, ish, key, sizeof(*key));
if (key->vue.nr_userclip_plane_consts) { if (key->vue.nr_userclip_plane_consts) {
nir_function_impl *impl = nir_shader_get_entrypoint(nir); nir_function_impl *impl = nir_shader_get_entrypoint(nir);
/* Check if variables were found. */ /* Check if variables were found. */
@ -1888,6 +1922,7 @@ iris_compile_vs(struct iris_screen *screen,
.nir = nir, .nir = nir,
.log_data = dbg, .log_data = dbg,
.source_hash = ish->source_hash, .source_hash = ish->source_hash,
.archiver = debug_archiver,
}, },
.key = &brw_key, .key = &brw_key,
.prog_data = brw_prog_data, .prog_data = brw_prog_data,
@ -1938,6 +1973,8 @@ iris_compile_vs(struct iris_screen *screen,
#endif #endif
} }
debug_archiver_close(debug_archiver);
if (program == NULL) { if (program == NULL) {
dbg_printf("Failed to compile vertex shader: %s\n", error); dbg_printf("Failed to compile vertex shader: %s\n", error);
ralloc_free(mem_ctx); ralloc_free(mem_ctx);
@ -2104,6 +2141,9 @@ iris_compile_tcs(struct iris_screen *screen,
source_hash = *(uint32_t*)nir->info.source_blake3; source_hash = *(uint32_t*)nir->info.source_blake3;
} }
debug_archiver *debug_archiver =
iris_debug_archiver_open(mem_ctx, screen, ish, key, sizeof(*key));
iris_setup_uniforms(devinfo, mem_ctx, nir, &system_values, iris_setup_uniforms(devinfo, mem_ctx, nir, &system_values,
&num_system_values, &num_cbufs); &num_system_values, &num_cbufs);
iris_setup_binding_table(devinfo, nir, &bt, /* num_render_targets */ 0, iris_setup_binding_table(devinfo, nir, &bt, /* num_render_targets */ 0,
@ -2122,6 +2162,7 @@ iris_compile_tcs(struct iris_screen *screen,
.nir = nir, .nir = nir,
.log_data = dbg, .log_data = dbg,
.source_hash = source_hash, .source_hash = source_hash,
.archiver = debug_archiver,
}, },
.key = &brw_key, .key = &brw_key,
.prog_data = brw_prog_data, .prog_data = brw_prog_data,
@ -2164,6 +2205,8 @@ iris_compile_tcs(struct iris_screen *screen,
#endif #endif
} }
debug_archiver_close(debug_archiver);
if (program == NULL) { if (program == NULL) {
dbg_printf("Failed to compile control shader: %s\n", error); dbg_printf("Failed to compile control shader: %s\n", error);
ralloc_free(mem_ctx); ralloc_free(mem_ctx);
@ -2287,6 +2330,9 @@ iris_compile_tes(struct iris_screen *screen,
nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir); nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
const struct iris_tes_prog_key *const key = &shader->key.tes; const struct iris_tes_prog_key *const key = &shader->key.tes;
debug_archiver *debug_archiver =
iris_debug_archiver_open(mem_ctx, screen, ish, key, sizeof(*key));
if (key->vue.nr_userclip_plane_consts) { if (key->vue.nr_userclip_plane_consts) {
nir_function_impl *impl = nir_shader_get_entrypoint(nir); nir_function_impl *impl = nir_shader_get_entrypoint(nir);
nir_lower_clip_vs(nir, (1 << key->vue.nr_userclip_plane_consts) - 1, nir_lower_clip_vs(nir, (1 << key->vue.nr_userclip_plane_consts) - 1,
@ -2325,6 +2371,7 @@ iris_compile_tes(struct iris_screen *screen,
.nir = nir, .nir = nir,
.log_data = dbg, .log_data = dbg,
.source_hash = ish->source_hash, .source_hash = ish->source_hash,
.archiver = debug_archiver,
}, },
.key = &brw_key, .key = &brw_key,
.prog_data = brw_prog_data, .prog_data = brw_prog_data,
@ -2375,6 +2422,8 @@ iris_compile_tes(struct iris_screen *screen,
#endif #endif
} }
debug_archiver_close(debug_archiver);
if (program == NULL) { if (program == NULL) {
dbg_printf("Failed to compile evaluation shader: %s\n", error); dbg_printf("Failed to compile evaluation shader: %s\n", error);
ralloc_free(mem_ctx); ralloc_free(mem_ctx);
@ -2476,6 +2525,9 @@ iris_compile_gs(struct iris_screen *screen,
nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir); nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
const struct iris_gs_prog_key *const key = &shader->key.gs; const struct iris_gs_prog_key *const key = &shader->key.gs;
debug_archiver *debug_archiver =
iris_debug_archiver_open(mem_ctx, screen, ish, key, sizeof(*key));
if (key->vue.nr_userclip_plane_consts) { if (key->vue.nr_userclip_plane_consts) {
nir_function_impl *impl = nir_shader_get_entrypoint(nir); nir_function_impl *impl = nir_shader_get_entrypoint(nir);
nir_lower_clip_gs(nir, (1 << key->vue.nr_userclip_plane_consts) - 1, nir_lower_clip_gs(nir, (1 << key->vue.nr_userclip_plane_consts) - 1,
@ -2513,6 +2565,7 @@ iris_compile_gs(struct iris_screen *screen,
.nir = nir, .nir = nir,
.log_data = dbg, .log_data = dbg,
.source_hash = ish->source_hash, .source_hash = ish->source_hash,
.archiver = debug_archiver,
}, },
.key = &brw_key, .key = &brw_key,
.prog_data = brw_prog_data, .prog_data = brw_prog_data,
@ -2561,6 +2614,8 @@ iris_compile_gs(struct iris_screen *screen,
#endif #endif
} }
debug_archiver_close(debug_archiver);
if (program == NULL) { if (program == NULL) {
dbg_printf("Failed to compile geometry shader: %s\n", error); dbg_printf("Failed to compile geometry shader: %s\n", error);
ralloc_free(mem_ctx); ralloc_free(mem_ctx);
@ -2659,6 +2714,9 @@ iris_compile_fs(struct iris_screen *screen,
nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir); nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
const struct iris_fs_prog_key *const key = &shader->key.fs; const struct iris_fs_prog_key *const key = &shader->key.fs;
debug_archiver *debug_archiver =
iris_debug_archiver_open(mem_ctx, screen, ish, key, sizeof(*key));
iris_setup_uniforms(devinfo, mem_ctx, nir, &system_values, iris_setup_uniforms(devinfo, mem_ctx, nir, &system_values,
&num_system_values, &num_cbufs); &num_system_values, &num_cbufs);
@ -2696,6 +2754,7 @@ iris_compile_fs(struct iris_screen *screen,
.nir = nir, .nir = nir,
.log_data = dbg, .log_data = dbg,
.source_hash = ish->source_hash, .source_hash = ish->source_hash,
.archiver = debug_archiver,
}, },
.key = &brw_key, .key = &brw_key,
.prog_data = brw_prog_data, .prog_data = brw_prog_data,
@ -2748,6 +2807,8 @@ iris_compile_fs(struct iris_screen *screen,
#endif #endif
} }
debug_archiver_close(debug_archiver);
if (program == NULL) { if (program == NULL) {
dbg_printf("Failed to compile fragment shader: %s\n", error); dbg_printf("Failed to compile fragment shader: %s\n", error);
ralloc_free(mem_ctx); ralloc_free(mem_ctx);
@ -3002,6 +3063,9 @@ iris_compile_cs(struct iris_screen *screen,
nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir); nir_shader *nir = nir_shader_clone(mem_ctx, ish->nir);
const struct iris_cs_prog_key *const key = &shader->key.cs; const struct iris_cs_prog_key *const key = &shader->key.cs;
debug_archiver *debug_archiver =
iris_debug_archiver_open(mem_ctx, screen, ish, key, sizeof(*key));
if (screen->brw) if (screen->brw)
NIR_PASS(_, nir, brw_nir_lower_cs_intrinsics, devinfo, NULL); NIR_PASS(_, nir, brw_nir_lower_cs_intrinsics, devinfo, NULL);
else else
@ -3033,6 +3097,7 @@ iris_compile_cs(struct iris_screen *screen,
.nir = nir, .nir = nir,
.log_data = dbg, .log_data = dbg,
.source_hash = ish->source_hash, .source_hash = ish->source_hash,
.archiver = debug_archiver,
}, },
.key = &brw_key, .key = &brw_key,
.prog_data = brw_prog_data, .prog_data = brw_prog_data,
@ -3073,6 +3138,8 @@ iris_compile_cs(struct iris_screen *screen,
#endif #endif
} }
debug_archiver_close(debug_archiver);
if (program == NULL) { if (program == NULL) {
dbg_printf("Failed to compile compute shader: %s\n", error); dbg_printf("Failed to compile compute shader: %s\n", error);