1 /* 2 * Copyright © 2021 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #include "vk_instance.h" 25 #include "vk_enum_to_str.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /* __VK_ARG_N(...) returns the number of arguments provided to it */ 32 #define __VK_ARG_SEQ(_1,_2,_3,_4,_5,_6,_7,_8,N,...) N 33 #define __VK_ARG_N(...) __VK_ARG_SEQ(__VA_ARGS__,8,7,6,5,4,3,2,1,0) 34 35 #define VK_LOG_OBJS(...) \ 36 __VK_ARG_N(__VA_ARGS__), (const void*[]){__VA_ARGS__} 37 38 #define VK_LOG_NO_OBJS(instance) 0, (const void**)instance 39 40 #define vk_logd(objects_macro, format, ...) \ 41 __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT, \ 42 VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT, \ 43 objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__) 44 45 #define vk_logi(objects_macro, format, ...) \ 46 __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT, \ 47 VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT, \ 48 objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__) 49 50 #define vk_logw(objects_macro, format, ...) \ 51 __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT, \ 52 VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT, \ 53 objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__) 54 55 #define vk_loge(objects_macro, format, ...) \ 56 __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT, \ 57 VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT, \ 58 objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__) 59 60 #define vk_perf(objects_macro, format, ...) \ 61 __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT, \ 62 VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT, \ 63 objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__) 64 65 #define __vk_log(severity, type, object_count, \ 66 objects_or_instance, file, line, format, ...) \ 67 __vk_log_impl(severity, type, object_count, objects_or_instance, \ 68 file, line, format, ## __VA_ARGS__) 69 70 void PRINTFLIKE(7, 8) 71 __vk_log_impl(VkDebugUtilsMessageSeverityFlagBitsEXT severity, 72 VkDebugUtilsMessageTypeFlagsEXT types, 73 int object_count, 74 const void **objects_or_instance, 75 const char *file, 76 int line, 77 const char *format, 78 ...); 79 80 #define vk_error(obj, error) \ 81 __vk_errorf(obj, error, __FILE__, __LINE__, NULL) 82 83 #define vk_errorf(obj, error, ...) \ 84 __vk_errorf(obj, error, __FILE__, __LINE__, __VA_ARGS__) 85 86 VkResult 87 __vk_errorv(const void *_obj, VkResult error, 88 const char *file, int line, 89 const char *format, va_list va); 90 91 VkResult PRINTFLIKE(5, 6) 92 __vk_errorf(const void *_obj, VkResult error, 93 const char *file, int line, 94 const char *format, ...); 95 96 /** 97 * Warn on ignored extension structs. 98 * 99 * The Vulkan spec requires us to ignore unsupported or unknown structs in 100 * a pNext chain. In debug mode, emitting warnings for ignored structs may 101 * help us discover structs that we should not have ignored. 102 * 103 * From the Vulkan 1.0.38 spec: 104 * 105 * Any component of the implementation (the loader, any enabled layers, 106 * and drivers) must skip over, without processing (other than reading the 107 * sType and pNext members) any chained structures with sType values not 108 * defined by extensions supported by that component. 109 */ 110 #define vk_debug_ignored_stype(sType) \ 111 do { \ 112 const VkStructureType _type = (sType); \ 113 mesa_logd("%s: ignored VkStructureType %s(%u)\n", __func__, \ 114 vk_StructureType_to_str(_type), _type); \ 115 } while (0) 116 117 #ifdef __cplusplus 118 } 119 #endif