• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* __VK_ARG_N(...) returns the number of arguments provided to it  */
31 #define __VK_ARG_SEQ(_1,_2,_3,_4,_5,_6,_7,_8,N,...) N
32 #define __VK_ARG_N(...) __VK_ARG_SEQ(__VA_ARGS__,8,7,6,5,4,3,2,1,0)
33 
34 #define VK_LOG_OBJS(...)                                        \
35    __VK_ARG_N(__VA_ARGS__), (const void*[]){__VA_ARGS__}
36 
37 #define VK_LOG_NO_OBJS(instance) 0, (const void**)instance
38 
39 #define vk_logd(objects_macro, format, ...)                             \
40    __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT,            \
41             VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT,                \
42             objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__)
43 
44 #define vk_logi(objects_macro, format, ...)                             \
45    __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT,               \
46             VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT,                \
47             objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__)
48 
49 #define vk_logw(objects_macro, format, ...)                             \
50    __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT,            \
51             VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT,                \
52             objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__)
53 
54 #define vk_loge(objects_macro, format, ...)                             \
55    __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,              \
56             VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT,                \
57             objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__)
58 
59 #define vk_perf(objects_macro, format, ...)                             \
60    __vk_log(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT,            \
61             VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,            \
62             objects_macro, __FILE__, __LINE__, format, ## __VA_ARGS__)
63 
64 #define __vk_log(severity, type, object_count,                          \
65                  objects_or_instance, file, line, format, ...)          \
66    __vk_log_impl(severity, type, object_count, objects_or_instance,     \
67                  file, line, format, ## __VA_ARGS__)
68 
69 void PRINTFLIKE(7, 8)
70 __vk_log_impl(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
71               VkDebugUtilsMessageTypeFlagsEXT types,
72               int object_count,
73               const void **objects_or_instance,
74               const char *file,
75               int line,
76               const char *format,
77               ...);
78 
79 #define vk_error(obj, error) \
80    __vk_errorf(obj, error, __FILE__, __LINE__, NULL)
81 
82 #define vk_errorf(obj, error, ...) \
83    __vk_errorf(obj, error, __FILE__, __LINE__, __VA_ARGS__)
84 
85 VkResult
86 __vk_errorv(const void *_obj, VkResult error,
87             const char *file, int line,
88             const char *format, va_list va);
89 
90 VkResult PRINTFLIKE(5, 6)
91 __vk_errorf(const void *_obj, VkResult error,
92             const char *file, int line,
93             const char *format, ...);
94 
95 #ifdef __cplusplus
96 }
97 #endif