From 93cd8bf0987b3267ac61de81d51dd01c2f0d5544 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 7 Oct 2025 12:23:41 -0700 Subject: [PATCH] panvk: add PANVK_DEBUG(category) to simplify debug control In general, the debug flags are served once per proc invocation. So we can make panvk debug flags global and clean up the existing codes in the next change. Meanwhile, this changes improves branch prediction on user builds and logs the enabled debug options when startup is used. Reviewed-by: Boris Brezillon Part-of: --- src/panfrost/vulkan/panvk_instance.c | 27 +++++++++++++++++++++++++++ src/panfrost/vulkan/panvk_instance.h | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/src/panfrost/vulkan/panvk_instance.c b/src/panfrost/vulkan/panvk_instance.c index db8c335aa16..6945addc4ac 100644 --- a/src/panfrost/vulkan/panvk_instance.c +++ b/src/panfrost/vulkan/panvk_instance.c @@ -13,6 +13,7 @@ #include "util/driconf.h" #include "util/mesa-sha1.h" #include "util/os_misc.h" +#include "util/u_call_once.h" #include "vk_alloc.h" #include "vk_log.h" @@ -46,6 +47,30 @@ static const struct debug_control panvk_debug_options[] = { {"force_blackhole", PANVK_DEBUG_FORCE_BLACKHOLE}, {NULL, 0}}; +uint64_t panvk_debug; + +static void +panvk_debug_init_once(void) +{ + panvk_debug = + parse_debug_string(os_get_option("PANVK_DEBUG"), panvk_debug_options); +} + +static void +panvk_debug_init(void) +{ + static once_flag once = ONCE_FLAG_INIT; + call_once(&once, panvk_debug_init_once); + + /* log per VkInstance creation */ + if (PANVK_DEBUG(STARTUP)) { + char debug_string[256]; + dump_debug_control_string(debug_string, sizeof(debug_string), + panvk_debug_options, panvk_debug); + mesa_logi("panvk_debug: %s", debug_string); + } +} + VKAPI_ATTR VkResult VKAPI_CALL panvk_EnumerateInstanceVersion(uint32_t *pApiVersion) { @@ -200,6 +225,8 @@ panvk_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO); + panvk_debug_init(); + const struct build_id_note *note = build_id_find_nhdr_for_addr(panvk_CreateInstance); if (!note) { diff --git a/src/panfrost/vulkan/panvk_instance.h b/src/panfrost/vulkan/panvk_instance.h index 4f3866d83fb..62f84e44032 100644 --- a/src/panfrost/vulkan/panvk_instance.h +++ b/src/panfrost/vulkan/panvk_instance.h @@ -13,6 +13,8 @@ #include "lib/kmod/pan_kmod.h" +#define PANVK_DEBUG(category) (unlikely(panvk_debug & PANVK_DEBUG_##category)) + enum panvk_debug_flags { PANVK_DEBUG_STARTUP = 1 << 0, PANVK_DEBUG_NIR = 1 << 1, @@ -29,6 +31,8 @@ enum panvk_debug_flags { PANVK_DEBUG_FORCE_BLACKHOLE = 1 << 12, }; +extern uint64_t panvk_debug; + #if defined(VK_USE_PLATFORM_WAYLAND_KHR) || \ defined(VK_USE_PLATFORM_XCB_KHR) || \ defined(VK_USE_PLATFORM_XLIB_KHR) || \