From f82d85a685733ff6fe830782b3cb4276358c1e9f Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 10 May 2024 13:44:44 -0700 Subject: [PATCH] brw: Use debug archive file with INTEL_DEBUG=mda Instead of dumping multiple files with the optimizer passes, write a single archive file with all the contents. The actual file is created by the drivers, so later commits will actually enable the feature in anv and iris. This removes the use of INTEL_DEBUG=optimizer (and the corresponding enum value) in brw. That environment variable is still used by ELK -- which currently doesn't support mda. Acked-by: Kenneth Graunke Acked-by: Lionel Landwerlin Part-of: --- docs/envvars.rst | 5 +++- src/intel/compiler/brw_compile_bs.cpp | 1 + src/intel/compiler/brw_compile_cs.cpp | 1 + src/intel/compiler/brw_compile_fs.cpp | 1 + src/intel/compiler/brw_compile_gs.cpp | 1 + src/intel/compiler/brw_compile_mesh.cpp | 2 ++ src/intel/compiler/brw_compile_tcs.cpp | 1 + src/intel/compiler/brw_compile_tes.cpp | 1 + src/intel/compiler/brw_compile_vs.cpp | 1 + src/intel/compiler/brw_compiler.h | 3 +++ src/intel/compiler/brw_shader.cpp | 32 ++++++++----------------- src/intel/compiler/brw_shader.h | 4 ++++ src/intel/compiler/meson.build | 2 +- src/intel/dev/intel_debug.c | 1 + src/intel/dev/intel_debug.h | 1 + 15 files changed, 33 insertions(+), 24 deletions(-) diff --git a/docs/envvars.rst b/docs/envvars.rst index 4a4ff3d22ff..7133739009b 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -565,6 +565,9 @@ Intel driver environment variables print instruction hex dump with the disassembly ``l3`` emit messages about the new L3 state during transitions + ``mda`` + generate mda.tar files containing shader at each optimization + pass and iteration that make progress (Gfx >= 9) ``mesh`` dump shader assembly for mesh shaders ``no8`` @@ -588,7 +591,7 @@ Intel driver environment variables disable lossless color compression ``optimizer`` dump shader assembly to files at each optimization pass and - iteration that make progress + iteration that make progress (Gfx < 9) ``pc`` emit messages about PIPE_CONTROL instruction usage ``perf`` diff --git a/src/intel/compiler/brw_compile_bs.cpp b/src/intel/compiler/brw_compile_bs.cpp index 707dcb36c6b..ae23d25c097 100644 --- a/src/intel/compiler/brw_compile_bs.cpp +++ b/src/intel/compiler/brw_compile_bs.cpp @@ -97,6 +97,7 @@ compile_single_bs(const struct brw_compiler *compiler, .needs_register_pressure = stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; brw_shader s(&shader_params); diff --git a/src/intel/compiler/brw_compile_cs.cpp b/src/intel/compiler/brw_compile_cs.cpp index 4483bc537e3..f018fe9647e 100644 --- a/src/intel/compiler/brw_compile_cs.cpp +++ b/src/intel/compiler/brw_compile_cs.cpp @@ -221,6 +221,7 @@ brw_compile_cs(const struct brw_compiler *compiler, .needs_register_pressure = params->base.stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; v[simd] = std::make_unique(&shader_params); brw_adjust_uniforms(*v[simd]); diff --git a/src/intel/compiler/brw_compile_fs.cpp b/src/intel/compiler/brw_compile_fs.cpp index ce9128d114c..6eef9eb497c 100644 --- a/src/intel/compiler/brw_compile_fs.cpp +++ b/src/intel/compiler/brw_compile_fs.cpp @@ -1595,6 +1595,7 @@ brw_compile_fs(const struct brw_compiler *compiler, .needs_register_pressure = params->base.stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; if (devinfo->ver < 20) { diff --git a/src/intel/compiler/brw_compile_gs.cpp b/src/intel/compiler/brw_compile_gs.cpp index 0e7853119c2..ec4f57fc233 100644 --- a/src/intel/compiler/brw_compile_gs.cpp +++ b/src/intel/compiler/brw_compile_gs.cpp @@ -370,6 +370,7 @@ brw_compile_gs(const struct brw_compiler *compiler, .needs_register_pressure = params->base.stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; brw_shader v(&shader_params); v.gs.control_data_bits_per_vertex = control_data_bits_per_vertex; diff --git a/src/intel/compiler/brw_compile_mesh.cpp b/src/intel/compiler/brw_compile_mesh.cpp index bfdcc05085a..da3b41d82f7 100644 --- a/src/intel/compiler/brw_compile_mesh.cpp +++ b/src/intel/compiler/brw_compile_mesh.cpp @@ -416,6 +416,7 @@ brw_compile_task(const struct brw_compiler *compiler, .needs_register_pressure = params->base.stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; v[simd] = std::make_unique(&shader_params); @@ -1270,6 +1271,7 @@ brw_compile_mesh(const struct brw_compiler *compiler, .needs_register_pressure = params->base.stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; v[simd] = std::make_unique(&shader_params); diff --git a/src/intel/compiler/brw_compile_tcs.cpp b/src/intel/compiler/brw_compile_tcs.cpp index 9f2490a8977..9d5e303dbce 100644 --- a/src/intel/compiler/brw_compile_tcs.cpp +++ b/src/intel/compiler/brw_compile_tcs.cpp @@ -281,6 +281,7 @@ brw_compile_tcs(const struct brw_compiler *compiler, .needs_register_pressure = params->base.stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; brw_shader v(&shader_params); if (!run_tcs(v)) { diff --git a/src/intel/compiler/brw_compile_tes.cpp b/src/intel/compiler/brw_compile_tes.cpp index 7c48684f030..fa1acdc8a6e 100644 --- a/src/intel/compiler/brw_compile_tes.cpp +++ b/src/intel/compiler/brw_compile_tes.cpp @@ -183,6 +183,7 @@ brw_compile_tes(const struct brw_compiler *compiler, .needs_register_pressure = params->base.stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; brw_shader v(&shader_params); if (!run_tes(v)) { diff --git a/src/intel/compiler/brw_compile_vs.cpp b/src/intel/compiler/brw_compile_vs.cpp index a5ef4258097..5c8f1361879 100644 --- a/src/intel/compiler/brw_compile_vs.cpp +++ b/src/intel/compiler/brw_compile_vs.cpp @@ -363,6 +363,7 @@ brw_compile_vs(const struct brw_compiler *compiler, .needs_register_pressure = params->base.stats != NULL, .log_data = params->base.log_data, .debug_enabled = debug_enabled, + .archiver = params->base.archiver, }; brw_shader v(&shader_params); if (!run_vs(v)) { diff --git a/src/intel/compiler/brw_compiler.h b/src/intel/compiler/brw_compiler.h index ad20e4b87fa..191699e478f 100644 --- a/src/intel/compiler/brw_compiler.h +++ b/src/intel/compiler/brw_compiler.h @@ -27,6 +27,7 @@ #include "c11/threads.h" #include "dev/intel_device_info.h" #include "isl/isl.h" +#include "mda/debug_archiver.h" #include "util/macros.h" #include "util/mesa-sha1.h" #include "util/enum_operators.h" @@ -1478,6 +1479,8 @@ struct brw_compile_params { uint64_t debug_flag; uint32_t source_hash; + + debug_archiver *archiver; }; /** diff --git a/src/intel/compiler/brw_shader.cpp b/src/intel/compiler/brw_shader.cpp index 2e7e6d7a977..24d1d8b36d3 100644 --- a/src/intel/compiler/brw_shader.cpp +++ b/src/intel/compiler/brw_shader.cpp @@ -408,7 +408,8 @@ brw_shader::brw_shader(const brw_shader_params *params) needs_register_pressure(params->needs_register_pressure), dispatch_width(params->dispatch_width), max_polygons(params->num_polygons), - api_subgroup_size(brw_nir_api_subgroup_size(params->nir, dispatch_width)) + api_subgroup_size(brw_nir_api_subgroup_size(params->nir, dispatch_width)), + archiver(params->archiver) { assert(api_subgroup_size == 0 || api_subgroup_size == 8 || @@ -1009,31 +1010,18 @@ brw_shader::debug_optimizer(const nir_shader *nir, const char *pass_name, int iteration, int pass_num) const { - /* source_hash is not readily accessible in this context */ - if (!brw_should_print_shader(nir, DEBUG_OPTIMIZER, 0)) + if (!archiver) return; - char *filename; - int ret = asprintf(&filename, "%s/%s%d-%s-%02d-%02d-%s", - debug_get_option("INTEL_SHADER_OPTIMIZER_PATH", "./"), - _mesa_shader_stage_to_abbrev(stage), dispatch_width, nir->info.name, + /* TODO: Add replacement for INTEL_SHADER_OPTIMIZER_PATH. */ + const char *filename = + ralloc_asprintf(mem_ctx, "BRW%d/%02d-%02d-%s", + dispatch_width, iteration, pass_num, pass_name); - if (ret == -1) - return; - FILE *file = stderr; - if (__normal_user()) { - file = fopen(filename, "w"); - if (!file) - file = stderr; - } - - brw_print_instructions(*this, file); - - if (file != stderr) - fclose(file); - - free(filename); + FILE *f = debug_archiver_start_file(archiver, filename); + brw_print_instructions(*this, f); + debug_archiver_finish_file(archiver); } static uint32_t diff --git a/src/intel/compiler/brw_shader.h b/src/intel/compiler/brw_shader.h index 99bb3dd163b..b1f71651637 100644 --- a/src/intel/compiler/brw_shader.h +++ b/src/intel/compiler/brw_shader.h @@ -77,6 +77,8 @@ struct brw_shader_params bool needs_register_pressure; void *log_data; bool debug_enabled; + + debug_archiver *archiver; }; struct brw_shader @@ -223,6 +225,8 @@ public: struct brw_shader_stats shader_stats; + debug_archiver *archiver; + void debug_optimizer(const nir_shader *nir, const char *pass_name, int iteration, int pass_num) const; diff --git a/src/intel/compiler/meson.build b/src/intel/compiler/meson.build index 22e5c5d283d..89d23645fe0 100644 --- a/src/intel/compiler/meson.build +++ b/src/intel/compiler/meson.build @@ -159,7 +159,7 @@ libintel_compiler_brw = static_library( c_args : [no_override_init_args], cpp_args : ['-Werror=vla'], gnu_symbol_visibility : 'hidden', - dependencies : [idep_nir_headers, idep_mesautil, idep_intel_dev, idep_vtn], + dependencies : [idep_nir_headers, idep_mesautil, idep_intel_dev, idep_vtn, idep_mda], build_by_default : false, ) diff --git a/src/intel/dev/intel_debug.c b/src/intel/dev/intel_debug.c index ed2afdcd975..6c520419a8d 100644 --- a/src/intel/dev/intel_debug.c +++ b/src/intel/dev/intel_debug.c @@ -71,6 +71,7 @@ static const struct debug_control_bitset debug_control[] = { OPT1("blorp", DEBUG_BLORP), OPT1("nodualobj", DEBUG_NO_DUAL_OBJECT_GS), OPT1("optimizer", DEBUG_OPTIMIZER), + OPT1("mda", DEBUG_MDA), OPT1("ann", DEBUG_ANNOTATION), OPT1("no8", DEBUG_NO8), OPT1("no-oaconfig", DEBUG_NO_OACONFIG), diff --git a/src/intel/dev/intel_debug.h b/src/intel/dev/intel_debug.h index 19ccfe1a880..695f53ae2ca 100644 --- a/src/intel/dev/intel_debug.h +++ b/src/intel/dev/intel_debug.h @@ -57,6 +57,7 @@ enum intel_debug_flag { DEBUG_BLORP, DEBUG_NO_DUAL_OBJECT_GS, DEBUG_OPTIMIZER, + DEBUG_MDA, DEBUG_ANNOTATION, DEBUG_NO_OACONFIG, DEBUG_SPILL_FS,