diff options
author | Danny Holman <dholman@gymli.org> | 2024-10-28 15:52:52 -0500 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2024-10-28 15:55:49 -0500 |
commit | 2965bdde04eaa0012b29695aa015c354deb30bed (patch) | |
tree | 27a74440014ec67c35695dd355fdb1995937cef9 /render/vulkan/vkassert.h | |
parent | 075efbc3c4603246a9fb6c0e2e8ede051d444cd6 (diff) |
render: move get_vkerr_str into vkassert.h
Move get_vkerr_str into vkassert.h and use its output in the vkassert
function. This reduces the need for an error message argument when
calling vkassert and makes error messages in logs consistent across the
entire Vulkan renderer.
Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'render/vulkan/vkassert.h')
-rw-r--r-- | render/vulkan/vkassert.h | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/render/vulkan/vkassert.h b/render/vulkan/vkassert.h index 393e2de..4d4f99b 100644 --- a/render/vulkan/vkassert.h +++ b/render/vulkan/vkassert.h @@ -4,10 +4,42 @@ #include <rune/core/logging.h> #include <rune/core/abort.h> #include <vulkan/vulkan.h> +#include <string.h> -static inline void vkassert(VkResult value, const char *str) { +static char* get_vkerr_str(VkResult res) { + char *ret; + switch (res) { + case VK_SUCCESS: + ret = "SUCCESS"; + break; + case VK_ERROR_OUT_OF_HOST_MEMORY: + ret = "OUT OF HOST MEMORY"; + break; + case VK_ERROR_OUT_OF_DEVICE_MEMORY: + ret = "OUT OF DEVICE MEMORY"; + break; + case VK_ERROR_INITIALIZATION_FAILED: + ret = "INITIALIZATION FAILED"; + break; + case VK_ERROR_LAYER_NOT_PRESENT: + ret = "VALIDATION LAYER NOT PRESENT"; + break; + case VK_ERROR_EXTENSION_NOT_PRESENT: + ret = "EXTENSION NOT PRESENT"; + break; + case VK_ERROR_INCOMPATIBLE_DRIVER: + ret = "INCOMPATIBLE DRIVER"; + break; + default: + ret = "UNKNOWN RESULT"; + break; + } + return strdup(ret); +} + +static inline void vkassert(VkResult value) { if (value != VK_SUCCESS) { - log_output(LOG_ERROR, "Vulkan assertion failed: %s", str); + log_output(LOG_FATAL, "Vulkan error: %s", get_vkerr_str(value)); rune_abort(); } } |