From fa083a2dbcfd6d6815a5a3043d2b08b483be40b1 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 26 Apr 2021 12:02:01 -0700 Subject: [PATCH] vkr: add support for VKR_DEBUG It is an env var that vkr uses to set the debug flags. Currently, the only flag is VKR_DEBUG_VALIDATE that enables the validation layer. Signed-off-by: Chia-I Wu Reviewed-by: Yiwei Zhang --- src/vkr_renderer.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/vkr_renderer.c b/src/vkr_renderer.c index 6a64001..80ea320 100644 --- a/src/vkr_renderer.c +++ b/src/vkr_renderer.c @@ -11,7 +11,9 @@ #include #include "c11/threads.h" +#include "pipe/p_compiler.h" #include "pipe/p_state.h" +#include "util/u_debug.h" #include "util/u_double_list.h" #include "util/u_hash_table.h" #include "util/u_math.h" @@ -41,6 +43,8 @@ */ #define FORCE_ENABLE_DMABUF +#define VKR_DEBUG(category) (unlikely(vkr_debug_flags & VKR_DEBUG_##category)) + /* * TODO Most of the functions are generated. Some of them are then * hand-edited. Find a better/cleaner way to reduce manual works. @@ -332,7 +336,17 @@ struct vkr_context { struct vkr_instance *instance; }; +enum vkr_debug_flags { + VKR_DEBUG_VALIDATE = 1 << 0, +}; + +static const struct debug_named_value vkr_debug_options[] = { + { "validate", VKR_DEBUG_VALIDATE, "Force enabling the validation layer" }, + DEBUG_NAMED_VALUE_END +}; + static uint32_t vkr_renderer_flags; +static uint32_t vkr_debug_flags; struct object_array { uint32_t count; @@ -4574,7 +4588,8 @@ vkr_context_create(size_t debug_len, const char *debug_name) memcpy(ctx->debug_name, debug_name, debug_len); ctx->debug_name[debug_len] = '\0'; - ctx->validate_level = VKR_CONTEXT_VALIDATE_NONE; + ctx->validate_level = + VKR_DEBUG(VALIDATE) ? VKR_CONTEXT_VALIDATE_FORCE_ON : VKR_CONTEXT_VALIDATE_NONE; if (mtx_init(&ctx->mutex, mtx_plain) != thrd_success) { free(ctx->debug_name); @@ -4644,6 +4659,7 @@ vkr_renderer_init(uint32_t flags) /* TODO VKR_RENDERER_MULTI_PROCESS hint */ vkr_renderer_flags = flags; + vkr_debug_flags = debug_get_flags_option("VKR_DEBUG", vkr_debug_options, 0); return 0; } @@ -4652,6 +4668,7 @@ void vkr_renderer_fini(void) { vkr_renderer_flags = 0; + vkr_debug_flags = 0; } void