diff --git a/docs/envvars.rst b/docs/envvars.rst index 7133739009b..534a30ed1b6 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -886,6 +886,15 @@ Intel driver environment variables If none of widths for particular shader stage was specified, then all widths are allowed. +.. envvar:: MDA_OUTPUT_DIR + + Directory where the mda.tar files generated when using INTEL_DEBUG=mda are + going to be written to. If not set, use the current directory. + +.. envvar:: MDA_PREFIX + + Prefix added to the mda.tar filenames generated when using INTEL_DEBUG=mda. + Anvil(ANV) driver environment variables --------------------------------------- diff --git a/src/intel/mda/debug_archiver.c b/src/intel/mda/debug_archiver.c index 2cc6e0bd800..206037f129b 100644 --- a/src/intel/mda/debug_archiver.c +++ b/src/intel/mda/debug_archiver.c @@ -7,23 +7,71 @@ #include "tar.h" #include "util/ralloc.h" +#include "util/u_debug.h" #include +#include +#include +#include struct debug_archiver { FILE *f; tar_writer *tw; char prefix[128]; + char *archive_path; }; +DEBUG_GET_ONCE_OPTION(mda_output_dir, "MDA_OUTPUT_DIR", ".") +DEBUG_GET_ONCE_OPTION(mda_prefix, "MDA_PREFIX", NULL) + +static bool +ensure_output_dir(const char *dir) +{ + if (!dir || !*dir || !strcmp(dir, ".")) + return true; + + struct stat st; + if (stat(dir, &st) == 0) + return S_ISDIR(st.st_mode); + + return mkdir(dir, 0755) == 0; +} + debug_archiver * debug_archiver_open(void *mem_ctx, const char *name, const char *info) { debug_archiver *da = rzalloc(mem_ctx, debug_archiver); char *filename = ralloc_asprintf(mem_ctx, "%s.mda.tar", name); - da->f = fopen(filename, "wb+"); + + const char *output_dir = debug_get_option_mda_output_dir(); + const char *prefix = debug_get_option_mda_prefix(); + + if (!ensure_output_dir(output_dir)) { + /* Fallback to current directory on failure. */ + output_dir = "."; + } + + if (prefix) { + /* Prefix shouldn't have any `/` characters. */ + if (strchr(prefix, '/')) { + char *safe_prefix = ralloc_strdup(da, prefix); + for (char *p = safe_prefix; *p; p++) { + if (*p == '/') + *p = '_'; + } + prefix = safe_prefix; + } + } + + da->archive_path = ralloc_asprintf(da, "%s/%s%s%s", + output_dir, + prefix ? prefix : "", + prefix ? "." : "", + filename); + + da->f = fopen(da->archive_path, "wb+"); da->tw = rzalloc(da, tar_writer); tar_writer_init(da->tw, da->f); diff --git a/src/intel/mda/meson.build b/src/intel/mda/meson.build index 0b082495308..1fa14d10d1c 100644 --- a/src/intel/mda/meson.build +++ b/src/intel/mda/meson.build @@ -11,6 +11,9 @@ _libmda = static_library( 'tar.h', 'tar.c', ], + dependencies: [ + idep_mesautil + ], include_directories: [inc_src], c_args: [c_msvc_compat_args], gnu_symbol_visibility: 'hidden',