diff options
author | Xuelian Bai <xuelian.bai@samsung.com> | 2022-11-28 09:55:42 +0800 |
---|---|---|
committer | Xuelian Bai <xuelian.bai@samsung.com> | 2023-10-19 10:04:35 +0800 |
commit | 7b9a41f64490c333fb15d640e1690cbb81cf760f (patch) | |
tree | 52ece087560fa719f26bd1a9131e09e6b2ccb087 /util | |
parent | f6c1b8e6c832283b59787b37d4e9bea08bda5740 (diff) | |
download | vulkan-wsi-layer-7b9a41f64490c333fb15d640e1690cbb81cf760f.tar.gz vulkan-wsi-layer-7b9a41f64490c333fb15d640e1690cbb81cf760f.tar.bz2 vulkan-wsi-layer-7b9a41f64490c333fb15d640e1690cbb81cf760f.zip |
Update to latest upstream version
Change-Id: Idaa93081d2f067085145cec4902bac45121a3ba1
Signed-Off-by: Xuelian Bai <xuelian.bai@samsung.com>
Diffstat (limited to 'util')
-rwxr-xr-x | util/helper.cpp | 275 | ||||
-rwxr-xr-x | util/helper.hpp | 12 | ||||
-rwxr-xr-x | util/log.cpp | 28 | ||||
-rw-r--r-- | util/log.hpp | 40 |
4 files changed, 351 insertions, 4 deletions
diff --git a/util/helper.cpp b/util/helper.cpp new file mode 100755 index 0000000..a383b52 --- /dev/null +++ b/util/helper.cpp @@ -0,0 +1,275 @@ + + +#include "helper.hpp" + +namespace util +{ + +#define ENUM_TO_STR(r) \ + case r: return #r + +const char * +vk_result_string(VkResult code) +{ + switch (code) { + ENUM_TO_STR(VK_SUCCESS); + ENUM_TO_STR(VK_NOT_READY); + ENUM_TO_STR(VK_TIMEOUT); + ENUM_TO_STR(VK_EVENT_SET); + ENUM_TO_STR(VK_EVENT_RESET); + ENUM_TO_STR(VK_INCOMPLETE); + ENUM_TO_STR(VK_ERROR_OUT_OF_HOST_MEMORY); + ENUM_TO_STR(VK_ERROR_OUT_OF_DEVICE_MEMORY); + ENUM_TO_STR(VK_ERROR_INITIALIZATION_FAILED); + ENUM_TO_STR(VK_ERROR_DEVICE_LOST); + ENUM_TO_STR(VK_ERROR_MEMORY_MAP_FAILED); + ENUM_TO_STR(VK_ERROR_LAYER_NOT_PRESENT); + ENUM_TO_STR(VK_ERROR_EXTENSION_NOT_PRESENT); + ENUM_TO_STR(VK_ERROR_FEATURE_NOT_PRESENT); + ENUM_TO_STR(VK_ERROR_INCOMPATIBLE_DRIVER); + ENUM_TO_STR(VK_ERROR_TOO_MANY_OBJECTS); + ENUM_TO_STR(VK_ERROR_FORMAT_NOT_SUPPORTED); + ENUM_TO_STR(VK_ERROR_SURFACE_LOST_KHR); + ENUM_TO_STR(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR); + ENUM_TO_STR(VK_SUBOPTIMAL_KHR); + ENUM_TO_STR(VK_ERROR_OUT_OF_DATE_KHR); + ENUM_TO_STR(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR); + ENUM_TO_STR(VK_ERROR_VALIDATION_FAILED_EXT); + ENUM_TO_STR(VK_ERROR_INVALID_SHADER_NV); + ENUM_TO_STR(VK_ERROR_INVALID_EXTERNAL_HANDLE); + ENUM_TO_STR(VK_ERROR_NOT_PERMITTED_EXT); + default: return "UNKNOWN RESULT"; + } +} + +const char * +vk_format_string(VkFormat code) +{ + switch (code) { + ENUM_TO_STR(VK_FORMAT_UNDEFINED); + ENUM_TO_STR(VK_FORMAT_R4G4_UNORM_PACK8); + ENUM_TO_STR(VK_FORMAT_R4G4B4A4_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_B4G4R4A4_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_R5G6B5_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_B5G6R5_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_R5G5B5A1_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_B5G5R5A1_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_A1R5G5B5_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_R8_UNORM); + ENUM_TO_STR(VK_FORMAT_R8_SNORM); + ENUM_TO_STR(VK_FORMAT_R8_USCALED); + ENUM_TO_STR(VK_FORMAT_R8_SSCALED); + ENUM_TO_STR(VK_FORMAT_R8_UINT); + ENUM_TO_STR(VK_FORMAT_R8_SINT); + ENUM_TO_STR(VK_FORMAT_R8_SRGB); + ENUM_TO_STR(VK_FORMAT_R8G8_UNORM); + ENUM_TO_STR(VK_FORMAT_R8G8_SNORM); + ENUM_TO_STR(VK_FORMAT_R8G8_USCALED); + ENUM_TO_STR(VK_FORMAT_R8G8_SSCALED); + ENUM_TO_STR(VK_FORMAT_R8G8_UINT); + ENUM_TO_STR(VK_FORMAT_R8G8_SINT); + ENUM_TO_STR(VK_FORMAT_R8G8_SRGB); + ENUM_TO_STR(VK_FORMAT_R8G8B8_UNORM); + ENUM_TO_STR(VK_FORMAT_R8G8B8_SNORM); + ENUM_TO_STR(VK_FORMAT_R8G8B8_USCALED); + ENUM_TO_STR(VK_FORMAT_R8G8B8_SSCALED); + ENUM_TO_STR(VK_FORMAT_R8G8B8_UINT); + ENUM_TO_STR(VK_FORMAT_R8G8B8_SINT); + ENUM_TO_STR(VK_FORMAT_R8G8B8_SRGB); + ENUM_TO_STR(VK_FORMAT_B8G8R8_UNORM); + ENUM_TO_STR(VK_FORMAT_B8G8R8_SNORM); + ENUM_TO_STR(VK_FORMAT_B8G8R8_USCALED); + ENUM_TO_STR(VK_FORMAT_B8G8R8_SSCALED); + ENUM_TO_STR(VK_FORMAT_B8G8R8_UINT); + ENUM_TO_STR(VK_FORMAT_B8G8R8_SINT); + ENUM_TO_STR(VK_FORMAT_B8G8R8_SRGB); + ENUM_TO_STR(VK_FORMAT_R8G8B8A8_UNORM); + ENUM_TO_STR(VK_FORMAT_R8G8B8A8_SNORM); + ENUM_TO_STR(VK_FORMAT_R8G8B8A8_USCALED); + ENUM_TO_STR(VK_FORMAT_R8G8B8A8_SSCALED); + ENUM_TO_STR(VK_FORMAT_R8G8B8A8_UINT); + ENUM_TO_STR(VK_FORMAT_R8G8B8A8_SINT); + ENUM_TO_STR(VK_FORMAT_R8G8B8A8_SRGB); + ENUM_TO_STR(VK_FORMAT_B8G8R8A8_UNORM); + ENUM_TO_STR(VK_FORMAT_B8G8R8A8_SNORM); + ENUM_TO_STR(VK_FORMAT_B8G8R8A8_USCALED); + ENUM_TO_STR(VK_FORMAT_B8G8R8A8_SSCALED); + ENUM_TO_STR(VK_FORMAT_B8G8R8A8_UINT); + ENUM_TO_STR(VK_FORMAT_B8G8R8A8_SINT); + ENUM_TO_STR(VK_FORMAT_B8G8R8A8_SRGB); + ENUM_TO_STR(VK_FORMAT_A8B8G8R8_UNORM_PACK32); + ENUM_TO_STR(VK_FORMAT_A8B8G8R8_SNORM_PACK32); + ENUM_TO_STR(VK_FORMAT_A8B8G8R8_USCALED_PACK32); + ENUM_TO_STR(VK_FORMAT_A8B8G8R8_SSCALED_PACK32); + ENUM_TO_STR(VK_FORMAT_A8B8G8R8_UINT_PACK32); + ENUM_TO_STR(VK_FORMAT_A8B8G8R8_SINT_PACK32); + ENUM_TO_STR(VK_FORMAT_A8B8G8R8_SRGB_PACK32); + ENUM_TO_STR(VK_FORMAT_A2R10G10B10_UNORM_PACK32); + ENUM_TO_STR(VK_FORMAT_A2R10G10B10_SNORM_PACK32); + ENUM_TO_STR(VK_FORMAT_A2R10G10B10_USCALED_PACK32); + ENUM_TO_STR(VK_FORMAT_A2R10G10B10_SSCALED_PACK32); + ENUM_TO_STR(VK_FORMAT_A2R10G10B10_UINT_PACK32); + ENUM_TO_STR(VK_FORMAT_A2R10G10B10_SINT_PACK32); + ENUM_TO_STR(VK_FORMAT_A2B10G10R10_UNORM_PACK32); + ENUM_TO_STR(VK_FORMAT_A2B10G10R10_SNORM_PACK32); + ENUM_TO_STR(VK_FORMAT_A2B10G10R10_USCALED_PACK32); + ENUM_TO_STR(VK_FORMAT_A2B10G10R10_SSCALED_PACK32); + ENUM_TO_STR(VK_FORMAT_A2B10G10R10_UINT_PACK32); + ENUM_TO_STR(VK_FORMAT_A2B10G10R10_SINT_PACK32); + ENUM_TO_STR(VK_FORMAT_R16_UNORM); + ENUM_TO_STR(VK_FORMAT_R16_SNORM); + ENUM_TO_STR(VK_FORMAT_R16_USCALED); + ENUM_TO_STR(VK_FORMAT_R16_SSCALED); + ENUM_TO_STR(VK_FORMAT_R16_UINT); + ENUM_TO_STR(VK_FORMAT_R16_SINT); + ENUM_TO_STR(VK_FORMAT_R16_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R16G16_UNORM); + ENUM_TO_STR(VK_FORMAT_R16G16_SNORM); + ENUM_TO_STR(VK_FORMAT_R16G16_USCALED); + ENUM_TO_STR(VK_FORMAT_R16G16_SSCALED); + ENUM_TO_STR(VK_FORMAT_R16G16_UINT); + ENUM_TO_STR(VK_FORMAT_R16G16_SINT); + ENUM_TO_STR(VK_FORMAT_R16G16_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R16G16B16_UNORM); + ENUM_TO_STR(VK_FORMAT_R16G16B16_SNORM); + ENUM_TO_STR(VK_FORMAT_R16G16B16_USCALED); + ENUM_TO_STR(VK_FORMAT_R16G16B16_SSCALED); + ENUM_TO_STR(VK_FORMAT_R16G16B16_UINT); + ENUM_TO_STR(VK_FORMAT_R16G16B16_SINT); + ENUM_TO_STR(VK_FORMAT_R16G16B16_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R16G16B16A16_UNORM); + ENUM_TO_STR(VK_FORMAT_R16G16B16A16_SNORM); + ENUM_TO_STR(VK_FORMAT_R16G16B16A16_USCALED); + ENUM_TO_STR(VK_FORMAT_R16G16B16A16_SSCALED); + ENUM_TO_STR(VK_FORMAT_R16G16B16A16_UINT); + ENUM_TO_STR(VK_FORMAT_R16G16B16A16_SINT); + ENUM_TO_STR(VK_FORMAT_R16G16B16A16_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R32_UINT); + ENUM_TO_STR(VK_FORMAT_R32_SINT); + ENUM_TO_STR(VK_FORMAT_R32_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R32G32_UINT); + ENUM_TO_STR(VK_FORMAT_R32G32_SINT); + ENUM_TO_STR(VK_FORMAT_R32G32_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R32G32B32_UINT); + ENUM_TO_STR(VK_FORMAT_R32G32B32_SINT); + ENUM_TO_STR(VK_FORMAT_R32G32B32_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R32G32B32A32_UINT); + ENUM_TO_STR(VK_FORMAT_R32G32B32A32_SINT); + ENUM_TO_STR(VK_FORMAT_R32G32B32A32_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R64_UINT); + ENUM_TO_STR(VK_FORMAT_R64_SINT); + ENUM_TO_STR(VK_FORMAT_R64_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R64G64_UINT); + ENUM_TO_STR(VK_FORMAT_R64G64_SINT); + ENUM_TO_STR(VK_FORMAT_R64G64_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R64G64B64_UINT); + ENUM_TO_STR(VK_FORMAT_R64G64B64_SINT); + ENUM_TO_STR(VK_FORMAT_R64G64B64_SFLOAT); + ENUM_TO_STR(VK_FORMAT_R64G64B64A64_UINT); + ENUM_TO_STR(VK_FORMAT_R64G64B64A64_SINT); + ENUM_TO_STR(VK_FORMAT_R64G64B64A64_SFLOAT); + ENUM_TO_STR(VK_FORMAT_B10G11R11_UFLOAT_PACK32); + ENUM_TO_STR(VK_FORMAT_E5B9G9R9_UFLOAT_PACK32); + ENUM_TO_STR(VK_FORMAT_D16_UNORM); + ENUM_TO_STR(VK_FORMAT_X8_D24_UNORM_PACK32); + ENUM_TO_STR(VK_FORMAT_D32_SFLOAT); + ENUM_TO_STR(VK_FORMAT_S8_UINT); + ENUM_TO_STR(VK_FORMAT_D16_UNORM_S8_UINT); + ENUM_TO_STR(VK_FORMAT_D24_UNORM_S8_UINT); + ENUM_TO_STR(VK_FORMAT_D32_SFLOAT_S8_UINT); + ENUM_TO_STR(VK_FORMAT_BC1_RGB_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC1_RGB_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC1_RGBA_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC1_RGBA_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC2_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC2_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC3_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC3_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC4_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC4_SNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC5_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC5_SNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC6H_UFLOAT_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC6H_SFLOAT_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC7_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_BC7_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_EAC_R11_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_EAC_R11_SNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_EAC_R11G11_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_EAC_R11G11_SNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_4x4_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_4x4_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_5x4_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_5x4_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_5x5_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_5x5_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_6x5_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_6x5_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_6x6_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_6x6_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_8x5_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_8x5_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_8x6_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_8x6_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_8x8_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_8x8_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_10x5_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_10x5_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_10x6_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_10x6_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_10x8_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_10x8_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_10x10_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_10x10_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_12x10_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_12x10_SRGB_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_12x12_UNORM_BLOCK); + ENUM_TO_STR(VK_FORMAT_ASTC_12x12_SRGB_BLOCK); +#ifdef VK_VERSION_1_1 + ENUM_TO_STR(VK_FORMAT_G8B8G8R8_422_UNORM); + ENUM_TO_STR(VK_FORMAT_B8G8R8G8_422_UNORM); + ENUM_TO_STR(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM); + ENUM_TO_STR(VK_FORMAT_G8_B8R8_2PLANE_420_UNORM); + ENUM_TO_STR(VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM); + ENUM_TO_STR(VK_FORMAT_G8_B8R8_2PLANE_422_UNORM); + ENUM_TO_STR(VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM); + ENUM_TO_STR(VK_FORMAT_R10X6_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_R10X6G10X6_UNORM_2PACK16); + ENUM_TO_STR(VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16); + ENUM_TO_STR(VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16); + ENUM_TO_STR(VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16); + ENUM_TO_STR(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_R12X4_UNORM_PACK16); + ENUM_TO_STR(VK_FORMAT_R12X4G12X4_UNORM_2PACK16); + ENUM_TO_STR(VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16); + ENUM_TO_STR(VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16); + ENUM_TO_STR(VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16); + ENUM_TO_STR(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16); + ENUM_TO_STR(VK_FORMAT_G16B16G16R16_422_UNORM); + ENUM_TO_STR(VK_FORMAT_B16G16R16G16_422_UNORM); + ENUM_TO_STR(VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM); + ENUM_TO_STR(VK_FORMAT_G16_B16R16_2PLANE_420_UNORM); + ENUM_TO_STR(VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM); + ENUM_TO_STR(VK_FORMAT_G16_B16R16_2PLANE_422_UNORM); + ENUM_TO_STR(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM); +#endif // VK_VERSION_1_1 + default: return "UNKNOWN FORMAT"; + } +} + + +} /* namespace util */ diff --git a/util/helper.hpp b/util/helper.hpp new file mode 100755 index 0000000..31431cb --- /dev/null +++ b/util/helper.hpp @@ -0,0 +1,12 @@ +#pragma once + + +#include <vulkan/vulkan.h> + + +namespace util +{ + const char *vk_result_string(VkResult code); + const char *vk_format_string(VkFormat code); + +} /* namespace util */ diff --git a/util/log.cpp b/util/log.cpp index eac9e35..889ca28 100755 --- a/util/log.cpp +++ b/util/log.cpp @@ -35,6 +35,32 @@ namespace util #ifndef NDEBUG +#if BUILD_WSI_TIZEN +void wsi_log_message(int level, const char *file, int line, const char *format, ...) +{ + log_priority dlog_prio; + switch (level) { + case 1: + dlog_prio = DLOG_ERROR; + break; + case 2: + dlog_prio = DLOG_WARN; + break; + case 3: + dlog_prio = DLOG_INFO; + break; + default: + dlog_prio = DLOG_DEBUG; + break; + } + + std::va_list args; + va_start(args, format); + __dlog_vprint(LOG_ID_SYSTEM, dlog_prio, LOG_TAG, format, args); + va_end(args); +} + +#else /** * @brief check if a log level is enabled, and print it */ @@ -90,7 +116,7 @@ void wsi_log_message(long level, const char *file, int line, const char *format, std::putc('\n', stderr); } } - +#endif #endif } /* namespace util */ diff --git a/util/log.hpp b/util/log.hpp index 13a2b03..3b6da72 100644 --- a/util/log.hpp +++ b/util/log.hpp @@ -34,9 +34,43 @@ namespace util { +#define WSI_DEFAULT_LOG_LEVEL 1 -#define WSI_LOG_ERROR(fmt, x...) LOGE(fmt, ##x) -#define WSI_LOG_WARNING(fmt, x...) LOGW(fmt, ##x) -#define WSI_LOG_INFO(fmt, x...) LOGI(fmt, ##x) +/** + * @brief Log a message to a certain log level + * + * @details For the log level, we use a bigger integer to represent an increased + * level of verbosity. If this is not specified, the log level is default to 1. + * We use a "staircase" approach with respect to printing logs. We print all log + * messages equal or below the log level set, e.g. if VULKAN_WSI_DEBUG_LEVEL + * is set to 2, messages with log level 1 and 2 are printed. Please note that + * the newline character '\n' is automatically appended. + * + * @param[in] level The log level of this message, you can set an arbitary + * integer however please refer to the included macros for + * the sensible defaults. + * @param[in] file The source file name (``__FILE__``) + * @param[in] line The source file line number (``__LINE__``) + * @param[in] format A C-style formatting string. + */ + +void wsi_log_message(int level, const char *file, int line, const char *format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 4, 5))) +#endif + ; + +#ifdef NDEBUG +static constexpr bool wsi_log_enable = false; +#else +static constexpr bool wsi_log_enable = true; +#endif + +#define WSI_LOG(level, ...) \ + do { if (::util::wsi_log_enable) ::util::wsi_log_message(level, __FILE__, __LINE__, __VA_ARGS__); } while (0) + +#define WSI_LOG_ERROR(...) WSI_LOG(1, __VA_ARGS__) +#define WSI_LOG_WARNING(...) WSI_LOG(2, __VA_ARGS__) +#define WSI_LOG_INFO(...) WSI_LOG(3, __VA_ARGS__) } /* namespace util */ |