diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index ca055fb9e08..ea596b4f03e 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -30,6 +30,7 @@ #include "util/u_debug.h" #include "agx_builder.h" #include "agx_compiler.h" +#include "agx_debug.h" #include "agx_internal_formats.h" #include "agx_nir.h" @@ -51,13 +52,14 @@ static const struct debug_named_value agx_debug_options[] = { }; /* clang-format on */ -DEBUG_GET_ONCE_FLAGS_OPTION(agx_debug, "AGX_MESA_DEBUG", agx_debug_options, 0) +DEBUG_GET_ONCE_FLAGS_OPTION(agx_compiler_debug, "AGX_MESA_DEBUG", + agx_debug_options, 0) -int agx_debug = 0; +int agx_compiler_debug = 0; #define DBG(fmt, ...) \ do { \ - if (agx_debug & AGX_DBG_MSGS) \ + if (agx_compiler_debug & AGX_DBG_MSGS) \ fprintf(stderr, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__); \ } while (0) @@ -1931,7 +1933,7 @@ agx_optimize_nir(nir_shader *nir, unsigned *preamble_size) } while (progress); } - if (likely(!(agx_debug & AGX_DBG_NOPREAMBLE))) + if (likely(!(agx_compiler_debug & AGX_DBG_NOPREAMBLE))) NIR_PASS_V(nir, agx_nir_opt_preamble, preamble_size); /* Forming preambles may dramatically reduce the instruction count @@ -2079,8 +2081,8 @@ agx_fp32_varying_mask(nir_shader *nir) static bool agx_should_dump(nir_shader *nir, unsigned agx_dbg_bit) { - return (agx_debug & agx_dbg_bit) && - !(nir->info.internal && !(agx_debug & AGX_DBG_INTERNAL)); + return (agx_compiler_debug & agx_dbg_bit) && + !(nir->info.internal && !(agx_compiler_debug & AGX_DBG_INTERNAL)); } static unsigned @@ -2123,7 +2125,7 @@ agx_compile_function_nir(nir_shader *nir, nir_function_impl *impl, agx_validate(ctx, "IR translation"); - if (likely(!(agx_debug & AGX_DBG_NOOPT))) { + if (likely(!(agx_compiler_debug & AGX_DBG_NOOPT))) { /* Dead code eliminate before instruction combining so use counts are * right */ agx_dce(ctx); @@ -2303,7 +2305,7 @@ agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key, struct util_dynarray *binary, struct agx_shader_info *out) { - agx_debug = debug_get_option_agx_debug(); + agx_compiler_debug = debug_get_option_agx_compiler_debug(); memset(out, 0, sizeof *out); diff --git a/src/asahi/compiler/agx_compiler.h b/src/asahi/compiler/agx_compiler.h index 25ae85d2d9a..5eb3441f0c5 100644 --- a/src/asahi/compiler/agx_compiler.h +++ b/src/asahi/compiler/agx_compiler.h @@ -38,22 +38,6 @@ extern "C" { #endif -/* clang-format off */ -enum agx_dbg { - AGX_DBG_MSGS = BITFIELD_BIT(0), - AGX_DBG_SHADERS = BITFIELD_BIT(1), - AGX_DBG_SHADERDB = BITFIELD_BIT(2), - AGX_DBG_VERBOSE = BITFIELD_BIT(3), - AGX_DBG_INTERNAL = BITFIELD_BIT(4), - AGX_DBG_NOVALIDATE = BITFIELD_BIT(5), - AGX_DBG_NOOPT = BITFIELD_BIT(6), - AGX_DBG_WAIT = BITFIELD_BIT(7), - AGX_DBG_NOPREAMBLE = BITFIELD_BIT(8), -}; -/* clang-format on */ - -extern int agx_debug; - /* r0-r127 inclusive, as pairs of 16-bits, gives 256 registers */ #define AGX_NUM_REGS (256) diff --git a/src/asahi/compiler/agx_debug.h b/src/asahi/compiler/agx_debug.h new file mode 100644 index 00000000000..d0aeb7e3c57 --- /dev/null +++ b/src/asahi/compiler/agx_debug.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 Alyssa Rosenzweig + * Copyright (C) 2020 Collabora Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef __AGX_DEBUG_H +#define __AGX_DEBUG_H + +#include "util/macros.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* clang-format off */ +enum agx_compiler_dbg { + AGX_DBG_MSGS = BITFIELD_BIT(0), + AGX_DBG_SHADERS = BITFIELD_BIT(1), + AGX_DBG_SHADERDB = BITFIELD_BIT(2), + AGX_DBG_VERBOSE = BITFIELD_BIT(3), + AGX_DBG_INTERNAL = BITFIELD_BIT(4), + AGX_DBG_NOVALIDATE = BITFIELD_BIT(5), + AGX_DBG_NOOPT = BITFIELD_BIT(6), + AGX_DBG_WAIT = BITFIELD_BIT(7), + AGX_DBG_NOPREAMBLE = BITFIELD_BIT(8), +}; +/* clang-format on */ + +extern int agx_compiler_debug; + +#ifdef __cplusplus +} /* extern C */ +#endif + +#endif diff --git a/src/asahi/compiler/agx_insert_waits.c b/src/asahi/compiler/agx_insert_waits.c index 348204b3357..716c4a31406 100644 --- a/src/asahi/compiler/agx_insert_waits.c +++ b/src/asahi/compiler/agx_insert_waits.c @@ -5,6 +5,7 @@ #include "agx_builder.h" #include "agx_compiler.h" +#include "agx_debug.h" #define AGX_MAX_PENDING (8) @@ -136,7 +137,7 @@ void agx_insert_waits(agx_context *ctx) { agx_foreach_block(ctx, block) { - if (agx_debug & AGX_DBG_WAIT) + if (agx_compiler_debug & AGX_DBG_WAIT) agx_insert_waits_trivial(ctx, block); else agx_insert_waits_local(ctx, block); diff --git a/src/asahi/compiler/agx_validate.c b/src/asahi/compiler/agx_validate.c index 08e98555b84..9b2599cadc2 100644 --- a/src/asahi/compiler/agx_validate.c +++ b/src/asahi/compiler/agx_validate.c @@ -23,6 +23,7 @@ */ #include "agx_compiler.h" +#include "agx_debug.h" /* Validatation doesn't make sense in release builds */ #ifndef NDEBUG @@ -190,7 +191,7 @@ agx_validate(agx_context *ctx, const char *after) { bool fail = false; - if (agx_debug & AGX_DBG_NOVALIDATE) + if (agx_compiler_debug & AGX_DBG_NOVALIDATE) return; agx_foreach_block(ctx, block) {