vk: Make vk_error a little more helpful
authorKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Wed, 26 Aug 2015 10:41:37 +0000 (03:41 -0700)
committerKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Thu, 3 Sep 2015 18:53:08 +0000 (11:53 -0700)
Print out file and line number and translate the error code to the
symbolic name.

Signed-off-by: Kristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
src/vulkan/anv_private.h
src/vulkan/anv_util.c

index a27b2e5ed92b5842e24a1a48747413678a131f10..b662af6cf5fa7cd97cf119e7804551d0f2e10373 100644 (file)
@@ -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);
index 0311fbcd84f3440cb8669bfd417ec9daae39b366..a78847acec6e4bffd9817b6bdffe7334042054c9 100644 (file)
@@ -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)
 {