From 2e346c882ddbea68db6dc0b6a05a9e9186624c04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg=20Kristensen?= Date: Wed, 26 Aug 2015 03:41:37 -0700 Subject: [PATCH] vk: Make vk_error a little more helpful MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Print out file and line number and translate the error code to the symbolic name. Signed-off-by: Kristian Høgsberg Kristensen --- src/vulkan/anv_private.h | 12 +++++----- src/vulkan/anv_util.c | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index a27b2e5ed92..b662af6cf5f 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -120,16 +120,14 @@ struct anv_common { * propagating errors. Might be useful to plug in a stack trace here. */ -static inline VkResult -vk_error(VkResult error) -{ +VkResult __vk_error(VkResult error, const char *file, int line); + #ifdef DEBUG - fprintf(stderr, "vk_error: %x\n", error); +#define vk_error(error) __vk_error(error, __FILE__, __LINE__); +#else +#define vk_error(error) error #endif - return error; -} - void __anv_finishme(const char *file, int line, const char *format, ...) anv_printflike(3, 4); void anv_loge(const char *format, ...) anv_printflike(1, 2); diff --git a/src/vulkan/anv_util.c b/src/vulkan/anv_util.c index 0311fbcd84f..a78847acec6 100644 --- a/src/vulkan/anv_util.c +++ b/src/vulkan/anv_util.c @@ -82,6 +82,53 @@ anv_abortfv(const char *format, va_list va) abort(); } +VkResult +__vk_error(VkResult error, const char *file, int line) +{ + static const char *error_names[] = { + "VK_ERROR_UNKNOWN", + "VK_ERROR_UNAVAILABLE", + "VK_ERROR_INITIALIZATION_FAILED", + "VK_ERROR_OUT_OF_HOST_MEMORY", + "VK_ERROR_OUT_OF_DEVICE_MEMORY", + "VK_ERROR_DEVICE_ALREADY_CREATED", + "VK_ERROR_DEVICE_LOST", + "VK_ERROR_INVALID_POINTER", + "VK_ERROR_INVALID_VALUE", + "VK_ERROR_INVALID_HANDLE", + "VK_ERROR_INVALID_ORDINAL", + "VK_ERROR_INVALID_MEMORY_SIZE", + "VK_ERROR_INVALID_EXTENSION", + "VK_ERROR_INVALID_FLAGS", + "VK_ERROR_INVALID_ALIGNMENT", + "VK_ERROR_INVALID_FORMAT", + "VK_ERROR_INVALID_IMAGE", + "VK_ERROR_INVALID_DESCRIPTOR_SET_DATA", + "VK_ERROR_INVALID_QUEUE_TYPE", + "VK_ERROR_UNSUPPORTED_SHADER_IL_VERSION", + "VK_ERROR_BAD_SHADER_CODE", + "VK_ERROR_BAD_PIPELINE_DATA", + "VK_ERROR_NOT_MAPPABLE", + "VK_ERROR_MEMORY_MAP_FAILED", + "VK_ERROR_MEMORY_UNMAP_FAILED", + "VK_ERROR_INCOMPATIBLE_DEVICE", + "VK_ERROR_INCOMPATIBLE_DRIVER", + "VK_ERROR_INCOMPLETE_COMMAND_BUFFER", + "VK_ERROR_BUILDING_COMMAND_BUFFER", + "VK_ERROR_MEMORY_NOT_BOUND", + "VK_ERROR_INCOMPATIBLE_QUEUE", + "VK_ERROR_INVALID_LAYER", + }; + + if (error <= VK_ERROR_UNKNOWN && error >= VK_ERROR_INVALID_LAYER) + fprintf(stderr, "%s:%d: %s\n", + file, line, error_names[-error - VK_ERROR_UNKNOWN]); + else + fprintf(stderr, "%s:%d: vk error %d\n", file, line, error); + + return error; +} + int anv_vector_init(struct anv_vector *vector, uint32_t element_size, uint32_t size) { -- 2.30.2