From 7d8b2c4128fc8adeb82569a7358fe33f734ae169 Mon Sep 17 00:00:00 2001 From: Lorenzo Rossi Date: Mon, 30 Mar 2026 18:54:45 +0200 Subject: [PATCH] pan/compiler: Split bi_debug.c from bifrost_compile.c Signed-off-by: Lorenzo Rossi Reviewed-by: Faith Ekstrand Reviewed-by: Christoph Pillmayer Part-of: --- src/panfrost/compiler/bifrost/bi_debug.c | 58 +++++++++++++++++++ src/panfrost/compiler/bifrost/bi_debug.h | 47 +++++++++++++++ src/panfrost/compiler/bifrost/bi_ra.c | 1 + src/panfrost/compiler/bifrost/bi_validate.c | 1 + src/panfrost/compiler/bifrost/bifrost.h | 21 ------- .../compiler/bifrost/bifrost/bi_schedule.c | 1 + .../compiler/bifrost/bifrost/bi_scoreboard.c | 1 + .../compiler/bifrost/bifrost_compile.c | 42 +------------- .../compiler/bifrost/bifrost_compile.h | 4 -- src/panfrost/compiler/bifrost/meson.build | 1 + .../compiler/bifrost/valhall/va_insert_flow.c | 1 + src/panfrost/compiler/pan_compiler.c | 1 + 12 files changed, 113 insertions(+), 66 deletions(-) create mode 100644 src/panfrost/compiler/bifrost/bi_debug.c create mode 100644 src/panfrost/compiler/bifrost/bi_debug.h diff --git a/src/panfrost/compiler/bifrost/bi_debug.c b/src/panfrost/compiler/bifrost/bi_debug.c new file mode 100644 index 00000000000..7ec56e62e04 --- /dev/null +++ b/src/panfrost/compiler/bifrost/bi_debug.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 Collabora Ltd. + * Copyright (C) 2022 Alyssa Rosenzweig + * Copyright (C) 2025 Arm Ltd. + * SPDX-License-Identifier: MIT + */ + +#include "util/u_debug.h" +#include "bi_debug.h" + + +/* clang-format off */ +static const struct debug_named_value bifrost_debug_options[] = { + {"shaders", BIFROST_DBG_SHADERS, "Dump shaders in NIR and MIR"}, + {"shaderdb", BIFROST_DBG_SHADERDB, "Print statistics"}, + {"verbose", BIFROST_DBG_VERBOSE, "Disassemble verbosely"}, + {"internal", BIFROST_DBG_INTERNAL, "Dump even internal shaders"}, + {"nosched", BIFROST_DBG_NOSCHED, "Force trivial bundling"}, + {"nopsched", BIFROST_DBG_NOPSCHED, "Disable scheduling for pressure"}, + {"inorder", BIFROST_DBG_INORDER, "Force in-order bundling"}, + {"novalidate", BIFROST_DBG_NOVALIDATE, "Skip IR validation"}, + {"noopt", BIFROST_DBG_NOOPT, "Skip optimization passes"}, + {"noidvs", BIFROST_DBG_NOIDVS, "Disable IDVS"}, + {"nosb", BIFROST_DBG_NOSB, "Disable scoreboarding"}, + {"nopreload", BIFROST_DBG_NOPRELOAD, "Disable message preloading"}, + {"spill", BIFROST_DBG_SPILL, "Test register spilling"}, + {"nossara", BIFROST_DBG_NOSSARA, "Disable SSA in register allocation"}, + {"statsabs", BIFROST_DBG_STATSABS, "Don't normalize statistics"}, + {"statsfull", BIFROST_DBG_STATSFULL, "Print verbose statistics"}, + {"debuginfo", BIFROST_DBG_DEBUGINFO, "Print debug information"}, + DEBUG_NAMED_VALUE_END +}; +/* clang-format on */ + +DEBUG_GET_ONCE_FLAGS_OPTION(bifrost_debug, "BIFROST_MESA_DEBUG", + bifrost_debug_options, 0) + +unsigned bifrost_debug = 0; + +void +bifrost_init_debug_options() { + bifrost_debug = debug_get_option_bifrost_debug(); +} + +bool +bifrost_will_dump_shaders(void) +{ + bifrost_init_debug_options(); + return bifrost_debug & BIFROST_DBG_SHADERS; +} + +bool +bifrost_want_debug_info(void) +{ + bifrost_init_debug_options(); + return bifrost_debug & BIFROST_DBG_DEBUGINFO; +} + diff --git a/src/panfrost/compiler/bifrost/bi_debug.h b/src/panfrost/compiler/bifrost/bi_debug.h new file mode 100644 index 00000000000..3360e235161 --- /dev/null +++ b/src/panfrost/compiler/bifrost/bi_debug.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2019 Connor Abbott + * Copyright (C) 2019 Lyude Paul + * Copyright (C) 2019 Ryan Houdek + * SPDX-License-Identifier: MIT + */ + +#ifndef __bi_debug_h__ +#define __bi_debug_h__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define BIFROST_DBG_MSGS 0x0001 +#define BIFROST_DBG_SHADERS 0x0002 +#define BIFROST_DBG_SHADERDB 0x0004 +#define BIFROST_DBG_VERBOSE 0x0008 +#define BIFROST_DBG_INTERNAL 0x0010 +#define BIFROST_DBG_NOSCHED 0x0020 +#define BIFROST_DBG_INORDER 0x0040 +#define BIFROST_DBG_NOVALIDATE 0x0080 +#define BIFROST_DBG_NOOPT 0x0100 +#define BIFROST_DBG_NOIDVS 0x0200 +#define BIFROST_DBG_NOSB 0x0400 +#define BIFROST_DBG_NOPRELOAD 0x0800 +#define BIFROST_DBG_SPILL 0x1000 +#define BIFROST_DBG_NOPSCHED 0x2000 +#define BIFROST_DBG_NOSSARA 0x4000 +#define BIFROST_DBG_STATSABS 0x8000 +#define BIFROST_DBG_STATSFULL 0x10000 +#define BIFROST_DBG_DEBUGINFO 0x20000 + +extern unsigned bifrost_debug; + +void bifrost_init_debug_options(void); + +bool bifrost_will_dump_shaders(void); +bool bifrost_want_debug_info(void); + +#ifdef __cplusplus +} /* extern C */ +#endif + +#endif diff --git a/src/panfrost/compiler/bifrost/bi_ra.c b/src/panfrost/compiler/bifrost/bi_ra.c index de068936ca4..b056ec8c9a8 100644 --- a/src/panfrost/compiler/bifrost/bi_ra.c +++ b/src/panfrost/compiler/bifrost/bi_ra.c @@ -4,6 +4,7 @@ */ #include "util/u_memory.h" +#include "bi_debug.h" #include "bi_builder.h" #include "compiler.h" #include "nodearray.h" diff --git a/src/panfrost/compiler/bifrost/bi_validate.c b/src/panfrost/compiler/bifrost/bi_validate.c index 4afeb537915..66a13c43d71 100644 --- a/src/panfrost/compiler/bifrost/bi_validate.c +++ b/src/panfrost/compiler/bifrost/bi_validate.c @@ -4,6 +4,7 @@ */ #include "util/u_memory.h" +#include "bi_debug.h" #include "compiler.h" /* Validatation doesn't make sense in release builds */ diff --git a/src/panfrost/compiler/bifrost/bifrost.h b/src/panfrost/compiler/bifrost/bifrost.h index d90d7a679a4..4d333c13d5b 100644 --- a/src/panfrost/compiler/bifrost/bifrost.h +++ b/src/panfrost/compiler/bifrost/bifrost.h @@ -17,27 +17,6 @@ extern "C" { #endif -#define BIFROST_DBG_MSGS 0x0001 -#define BIFROST_DBG_SHADERS 0x0002 -#define BIFROST_DBG_SHADERDB 0x0004 -#define BIFROST_DBG_VERBOSE 0x0008 -#define BIFROST_DBG_INTERNAL 0x0010 -#define BIFROST_DBG_NOSCHED 0x0020 -#define BIFROST_DBG_INORDER 0x0040 -#define BIFROST_DBG_NOVALIDATE 0x0080 -#define BIFROST_DBG_NOOPT 0x0100 -#define BIFROST_DBG_NOIDVS 0x0200 -#define BIFROST_DBG_NOSB 0x0400 -#define BIFROST_DBG_NOPRELOAD 0x0800 -#define BIFROST_DBG_SPILL 0x1000 -#define BIFROST_DBG_NOPSCHED 0x2000 -#define BIFROST_DBG_NOSSARA 0x4000 -#define BIFROST_DBG_STATSABS 0x8000 -#define BIFROST_DBG_STATSFULL 0x10000 -#define BIFROST_DBG_DEBUGINFO 0x20000 - -extern unsigned bifrost_debug; - enum bifrost_message_type { BIFROST_MESSAGE_NONE = 0, BIFROST_MESSAGE_VARYING = 1, diff --git a/src/panfrost/compiler/bifrost/bifrost/bi_schedule.c b/src/panfrost/compiler/bifrost/bifrost/bi_schedule.c index e8c0adeccc8..c655956afae 100644 --- a/src/panfrost/compiler/bifrost/bifrost/bi_schedule.c +++ b/src/panfrost/compiler/bifrost/bifrost/bi_schedule.c @@ -3,6 +3,7 @@ * SPDX-License-Identifier: MIT */ +#include "bi_debug.h" #include "bi_builder.h" #include "compiler.h" diff --git a/src/panfrost/compiler/bifrost/bifrost/bi_scoreboard.c b/src/panfrost/compiler/bifrost/bifrost/bi_scoreboard.c index 505774fcb79..a8d4650f851 100644 --- a/src/panfrost/compiler/bifrost/bifrost/bi_scoreboard.c +++ b/src/panfrost/compiler/bifrost/bifrost/bi_scoreboard.c @@ -4,6 +4,7 @@ */ #include "compiler.h" +#include "bi_debug.h" /* Assign dependency slots to each clause and calculate dependencies, This pass * must be run after scheduling. diff --git a/src/panfrost/compiler/bifrost/bifrost_compile.c b/src/panfrost/compiler/bifrost/bifrost_compile.c index c393fd16121..3fd5ece4d81 100644 --- a/src/panfrost/compiler/bifrost/bifrost_compile.c +++ b/src/panfrost/compiler/bifrost/bifrost_compile.c @@ -15,6 +15,7 @@ #include "util/u_debug.h" #include "util/u_qsort.h" +#include "bifrost/bi_debug.h" #include "bifrost/disassemble.h" #include "panfrost/lib/pan_props.h" #include "valhall/disassemble.h" @@ -29,52 +30,11 @@ static void pan_stats_verbose(FILE *f, const char *prefix, bi_context *ctx, const struct pan_stats *stats, const struct pan_shader_info *info); -/* clang-format off */ -static const struct debug_named_value bifrost_debug_options[] = { - {"shaders", BIFROST_DBG_SHADERS, "Dump shaders in NIR and MIR"}, - {"shaderdb", BIFROST_DBG_SHADERDB, "Print statistics"}, - {"verbose", BIFROST_DBG_VERBOSE, "Disassemble verbosely"}, - {"internal", BIFROST_DBG_INTERNAL, "Dump even internal shaders"}, - {"nosched", BIFROST_DBG_NOSCHED, "Force trivial bundling"}, - {"nopsched", BIFROST_DBG_NOPSCHED, "Disable scheduling for pressure"}, - {"inorder", BIFROST_DBG_INORDER, "Force in-order bundling"}, - {"novalidate", BIFROST_DBG_NOVALIDATE, "Skip IR validation"}, - {"noopt", BIFROST_DBG_NOOPT, "Skip optimization passes"}, - {"noidvs", BIFROST_DBG_NOIDVS, "Disable IDVS"}, - {"nosb", BIFROST_DBG_NOSB, "Disable scoreboarding"}, - {"nopreload", BIFROST_DBG_NOPRELOAD, "Disable message preloading"}, - {"spill", BIFROST_DBG_SPILL, "Test register spilling"}, - {"nossara", BIFROST_DBG_NOSSARA, "Disable SSA in register allocation"}, - {"statsabs", BIFROST_DBG_STATSABS, "Don't normalize statistics"}, - {"statsfull", BIFROST_DBG_STATSFULL, "Print verbose statistics"}, - {"debuginfo", BIFROST_DBG_DEBUGINFO, "Print debug information"}, - DEBUG_NAMED_VALUE_END -}; -/* clang-format on */ - -DEBUG_GET_ONCE_FLAGS_OPTION(bifrost_debug, "BIFROST_MESA_DEBUG", - bifrost_debug_options, 0) /* How many bytes are prefetched by the Bifrost shader core. From the final * clause of the shader, this range must be valid instructions or zero. */ #define BIFROST_SHADER_PREFETCH 128 -unsigned bifrost_debug = 0; - -bool -bifrost_will_dump_shaders(void) -{ - bifrost_debug = debug_get_option_bifrost_debug(); - return bifrost_debug & BIFROST_DBG_SHADERS; -} - -bool -bifrost_want_debug_info(void) -{ - bifrost_debug = debug_get_option_bifrost_debug(); - return bifrost_debug & BIFROST_DBG_DEBUGINFO; -} - static bi_block *emit_cf_list(bi_context *ctx, struct exec_list *list); static bi_index diff --git a/src/panfrost/compiler/bifrost/bifrost_compile.h b/src/panfrost/compiler/bifrost/bifrost_compile.h index 96f115da4e3..abe2622c8e7 100644 --- a/src/panfrost/compiler/bifrost/bifrost_compile.h +++ b/src/panfrost/compiler/bifrost/bifrost_compile.h @@ -18,7 +18,6 @@ struct bifrost_precompiled_kernel_sysvals { } num_workgroups; uint64_t printf_buffer_address; } __attribute__((aligned(8))); -; #define BIFROST_PRECOMPILED_KERNEL_SYSVALS_SIZE \ sizeof(struct bifrost_precompiled_kernel_sysvals) @@ -69,9 +68,6 @@ void bifrost_postprocess_nir(nir_shader *nir, unsigned gpu_id); void bifrost_lower_texture_nir(nir_shader *nir, unsigned gpu_id); void bifrost_lower_texture_late_nir(nir_shader *nir, unsigned gpu_id); -bool bifrost_will_dump_shaders(void); -bool bifrost_want_debug_info(void); - void bifrost_compile_shader_nir(nir_shader *nir, const struct pan_compile_inputs *inputs, struct util_dynarray *binary, diff --git a/src/panfrost/compiler/bifrost/meson.build b/src/panfrost/compiler/bifrost/meson.build index 3b9f3416e47..77c2e76fc84 100644 --- a/src/panfrost/compiler/bifrost/meson.build +++ b/src/panfrost/compiler/bifrost/meson.build @@ -31,6 +31,7 @@ libpanfrost_bifrost_files = files( 'bi_repair_ssa.c', 'bi_validate.c', 'bi_dominance.c', + 'bi_debug.c', 'bir.c', 'bifrost_compile.c', 'bifrost/bi_opt_message_preload.c', diff --git a/src/panfrost/compiler/bifrost/valhall/va_insert_flow.c b/src/panfrost/compiler/bifrost/valhall/va_insert_flow.c index b571b130843..9f3e7881ac3 100644 --- a/src/panfrost/compiler/bifrost/valhall/va_insert_flow.c +++ b/src/panfrost/compiler/bifrost/valhall/va_insert_flow.c @@ -5,6 +5,7 @@ #include "panfrost/lib/pan_props.h" +#include "bi_debug.h" #include "bi_builder.h" #include "va_compiler.h" #include "valhall_enums.h" diff --git a/src/panfrost/compiler/pan_compiler.c b/src/panfrost/compiler/pan_compiler.c index c5fb2235017..c71a811c319 100644 --- a/src/panfrost/compiler/pan_compiler.c +++ b/src/panfrost/compiler/pan_compiler.c @@ -6,6 +6,7 @@ #include "pan_compiler.h" #include "pan_nir.h" +#include "bifrost/bi_debug.h" #include "bifrost/bifrost_compile.h" #include "bifrost/bifrost/disassemble.h" #include "bifrost/valhall/disassemble.h"