From 786fa3435cd3ca884c65a432cf71a8c6fe818469 Mon Sep 17 00:00:00 2001 From: Charlie Turner Date: Thu, 17 Jun 2021 10:17:26 +0100 Subject: [PATCH] spirv_to_nir: Add environment variable to change default log level MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit During dEQP runs for radv, I see a lot of warnings like, ERROR - dEQP error: SPIR-V WARNING: ERROR - dEQP error: In file ../src/compiler/spirv/spirv_to_nir.c:1073 ERROR - dEQP error: Decoration not allowed on struct members: SpvDecorationRestrict ERROR - dEQP error: 408 bytes into the SPIR-V binary This fails jobs on Gitlab, due to, Job's log exceeded limit of 4194304 bytes. Job execution will continue but no more output will be collected. Since it doesn't seem feasible right now to fix the many shaders in the VK-CTS triggering this warning, add an environment toggle that allows test runners to only see the level of commentary they want. v2 from Martin: - Add my SoB v3 from Martin: - fix the indentation (suggested by Eric) - put the declarations at the top of the function v4 from Martin: - make vtn_default_log_level() static (Marcin) - cache the default level in vtn_log (Marcin) - move vtn_log_level_strings inside vtn_default_log_level() - Fix the build issue on MSC Signed-off-by: Martin Peres Reviewed-by: Eric Engestrom Acked-by: Andres Gomez Acked-by: Samuel Iglesias Gonsálvez Acked-by: Samuel Pitoiset Part-of: --- src/compiler/spirv/nir_spirv.h | 1 + src/compiler/spirv/spirv_to_nir.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h index 9585dbb..3e637ef 100644 --- a/src/compiler/spirv/nir_spirv.h +++ b/src/compiler/spirv/nir_spirv.h @@ -43,6 +43,7 @@ struct nir_spirv_specialization { }; enum nir_spirv_debug_level { + NIR_SPIRV_DEBUG_LEVEL_INVALID = -1, NIR_SPIRV_DEBUG_LEVEL_INFO, NIR_SPIRV_DEBUG_LEVEL_WARNING, NIR_SPIRV_DEBUG_LEVEL_ERROR, diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 2abf114..6690053 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -34,9 +34,36 @@ #include "util/format/u_format.h" #include "util/u_math.h" +#include "util/u_string.h" #include +#ifndef NDEBUG +static enum nir_spirv_debug_level +vtn_default_log_level(void) +{ + enum nir_spirv_debug_level level = NIR_SPIRV_DEBUG_LEVEL_WARNING; + const char *vtn_log_level_strings[] = { + [NIR_SPIRV_DEBUG_LEVEL_WARNING] = "warning", + [NIR_SPIRV_DEBUG_LEVEL_INFO] = "info", + [NIR_SPIRV_DEBUG_LEVEL_ERROR] = "error", + }; + const char *str = getenv("MESA_SPIRV_LOG_LEVEL"); + + if (str == NULL) + return NIR_SPIRV_DEBUG_LEVEL_WARNING; + + for (int i = 0; i < ARRAY_SIZE(vtn_log_level_strings); i++) { + if (strcasecmp(str, vtn_log_level_strings[i]) == 0) { + level = i; + break; + } + } + + return level; +} +#endif + void vtn_log(struct vtn_builder *b, enum nir_spirv_debug_level level, size_t spirv_offset, const char *message) @@ -47,7 +74,13 @@ vtn_log(struct vtn_builder *b, enum nir_spirv_debug_level level, } #ifndef NDEBUG - if (level >= NIR_SPIRV_DEBUG_LEVEL_WARNING) + static enum nir_spirv_debug_level default_level = + NIR_SPIRV_DEBUG_LEVEL_INVALID; + + if (default_level == NIR_SPIRV_DEBUG_LEVEL_INVALID) + default_level = vtn_default_log_level(); + + if (level >= default_level) fprintf(stderr, "%s\n", message); #endif } -- 2.7.4