Monado OpenXR Runtime
Loading...
Searching...
No Matches
vk_pretty_print.h
Go to the documentation of this file.
1// Copyright 2019-2024, Collabora, Ltd.
2// Copyright 2025-2026, NVIDIA CORPORATION.
3// Copyright 2026, Beyley Cardellio
4// SPDX-License-Identifier: BSL-1.0
5/*!
6 * @file
7 * @brief Pretty printing various Vulkan things.
8 *
9 * @author Jakob Bornecrantz <jakob@collabora.com>
10 * @author Christoph Haag <christoph.haag@collabora.com>
11 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
12 * @ingroup aux_vk
13 */
14
15#pragma once
16
17#include "xrt/xrt_compiler.h"
19
20#include "util/u_pretty_print.h"
21
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27
28/*
29 *
30 * String helper functions.
31 *
32 */
33
34/*!
35 * @name Enum string functions
36 *
37 * Returns a string of the enum value, or NULL if unknown. The versions without
38 * the `_or_null` suffix return 'UNKNOWN <TYPE>' instead of NULL.
39 *
40 * @ingroup aux_vk
41 * @{
42 */
43
44XRT_CHECK_RESULT const char *
45vk_str_result_or_null(VkResult code);
46
47XRT_CHECK_RESULT const char *
48vk_str_object_type_or_null(VkObjectType type);
49
50XRT_CHECK_RESULT const char *
51vk_str_physical_device_type_or_null(VkPhysicalDeviceType device_type);
52
53XRT_CHECK_RESULT const char *
54vk_str_format_or_null(VkFormat code);
55
56XRT_CHECK_RESULT const char *
57vk_str_sharing_mode_or_null(VkSharingMode code);
58
59XRT_CHECK_RESULT const char *
60vk_str_present_mode_or_null(VkPresentModeKHR code);
61
62XRT_CHECK_RESULT const char *
63vk_str_color_space_or_null(VkColorSpaceKHR code);
64
65XRT_CHECK_RESULT const char *
66vk_str_display_power_state_or_null(VkDisplayPowerStateEXT code);
67
68XRT_CHECK_RESULT const char *
69vk_str_queue_global_priority_or_null(VkQueueGlobalPriorityEXT priority);
70
71/*!
72 * @}
73 */
74
75#define VK_STR_NO_NULL(NAME, TYPE, UNKNOWN_STR) \
76 static inline const char *NAME(TYPE enumerate) \
77 { \
78 const char *str = NAME##_or_null(enumerate); \
79 return str != NULL ? str : UNKNOWN_STR; \
80 }
81
82VK_STR_NO_NULL(vk_str_result, VkResult, "UNKNOWN RESULT")
83VK_STR_NO_NULL(vk_str_object_type, VkObjectType, "UNKNOWN OBJECT TYPE")
84VK_STR_NO_NULL(vk_str_physical_device_type, VkPhysicalDeviceType, "UNKNOWN PHYSICAL DEVICE TYPE")
85VK_STR_NO_NULL(vk_str_format, VkFormat, "UNKNOWN FORMAT")
86VK_STR_NO_NULL(vk_str_sharing_mode, VkSharingMode, "UNKNOWN SHARING MODE")
87VK_STR_NO_NULL(vk_str_present_mode, VkPresentModeKHR, "UNKNOWN PRESENT MODE")
88VK_STR_NO_NULL(vk_str_color_space, VkColorSpaceKHR, "UNKNOWN COLOR SPACE")
89VK_STR_NO_NULL(vk_str_display_power_state, VkDisplayPowerStateEXT, "UNKNOWN DISPLAY POWER STATE")
90VK_STR_NO_NULL(vk_str_queue_global_priority, VkQueueGlobalPriorityEXT, "UNKNOWN QUEUE GLOBAL PRIORITY")
91
92
93/*
94 *
95 * Flag bits string functions.
96 *
97 */
98
99/*!
100 * @name Flag bits string functions
101 *
102 * Returns a string of the flag bit, or NULL if unknown or if zero or multiple
103 * bits are set. The versions without the `_or_null` suffix instead return
104 * '<TYPE>: NO BITS SET', '<TYPE>: MULTIPLE BITS SET' or '<TYPE>: UNKNOWN BIT'.
105 *
106 * @ingroup aux_vk
107 * @{
108 */
109
110XRT_CHECK_RESULT const char *
111vk_str_format_feature_flag_bits_or_null(VkFormatFeatureFlagBits bits);
112
113XRT_CHECK_RESULT const char *
114vk_str_swapchain_create_flag_bits_or_null(VkSwapchainCreateFlagBitsKHR bits);
115
116XRT_CHECK_RESULT const char *
117vk_str_image_usage_flag_bits_or_null(VkImageUsageFlagBits bits);
118
119XRT_CHECK_RESULT const char *
120vk_str_composite_alpha_flag_bits_or_null(VkCompositeAlphaFlagBitsKHR bits);
121
122XRT_CHECK_RESULT const char *
123vk_str_surface_transform_flag_bits_or_null(VkSurfaceTransformFlagBitsKHR bits);
124
125#ifdef VK_KHR_display
126XRT_CHECK_RESULT const char *
127vk_str_display_plane_alpha_flag_bits_or_null(VkDisplayPlaneAlphaFlagBitsKHR bits);
128#endif // VK_KHR_display
129
130/*!
131 * @}
132 */
133
134#define VK_STR_FLAG_BITS_NO_NULL(NAME, TYPE, PREFIX) \
135 static inline const char *NAME(TYPE bits) \
136 { \
137 const char *str = NAME##_or_null(bits); \
138 uint32_t value = (uint32_t)bits; \
139 if (str != NULL) { \
140 return str; \
141 } else if (value == 0) { \
142 return PREFIX ": NO BITS SET"; \
143 } else if ((value & (value - 1)) != 0) { \
144 return PREFIX ": MULTIPLE BITS SET"; \
145 } else { \
146 return PREFIX ": UNKNOWN BIT"; \
147 } \
148 }
149
150VK_STR_FLAG_BITS_NO_NULL(vk_str_format_feature_flag_bits, VkFormatFeatureFlagBits, "FORMAT FEATURE")
151VK_STR_FLAG_BITS_NO_NULL(vk_str_swapchain_create_flag_bits, VkSwapchainCreateFlagBitsKHR, "SWAPCHAIN CREATE")
152VK_STR_FLAG_BITS_NO_NULL(vk_str_image_usage_flag_bits, VkImageUsageFlagBits, "IMAGE USAGE")
153VK_STR_FLAG_BITS_NO_NULL(vk_str_composite_alpha_flag_bits, VkCompositeAlphaFlagBitsKHR, "COMPOSITE ALPHA")
154VK_STR_FLAG_BITS_NO_NULL(vk_str_surface_transform_flag_bits, VkSurfaceTransformFlagBitsKHR, "SURFACE TRANSFORM")
155#ifdef VK_KHR_display
156VK_STR_FLAG_BITS_NO_NULL(vk_str_display_plane_alpha_flag_bits, VkDisplayPlaneAlphaFlagBitsKHR, "DISPLAY PLANE ALPHA")
157#endif // VK_KHR_display
158
159#undef VK_STR_FLAG_BITS_NO_NULL
160#undef VK_STR_NO_NULL
161
162
163/*
164 *
165 * Pretty print functions.
166 *
167 */
168
169/*!
170 * @name Pretty print functions
171 *
172 * Pretty prints the value to the delegate, unknown values are printed as hex
173 * with a prefix, like `VK_FORMAT_0x12345678`. The flag bits printers expect a
174 * single bit to be set, if no, multiple or an unknown bit is set they say so
175 * and print the hex value, like `VK_IMAGE_USAGE: UNKNOWN BIT 0x00000100`.
176 *
177 * @ingroup aux_vk
178 * @{
179 */
180
181void
182vk_pp_result(u_pp_delegate_t dg, VkResult ret);
183
184void
185vk_pp_object_type(u_pp_delegate_t dg, VkObjectType type);
186
187void
188vk_pp_physical_device_type(u_pp_delegate_t dg, VkPhysicalDeviceType device_type);
189
190void
191vk_pp_format(u_pp_delegate_t dg, VkFormat format);
192
193void
194vk_pp_sharing_mode(u_pp_delegate_t dg, VkSharingMode mode);
195
196void
197vk_pp_present_mode(u_pp_delegate_t dg, VkPresentModeKHR mode);
198
199void
200vk_pp_color_space(u_pp_delegate_t dg, VkColorSpaceKHR color_space);
201
202void
203vk_pp_display_power_state(u_pp_delegate_t dg, VkDisplayPowerStateEXT state);
204
205void
206vk_pp_queue_global_priority(u_pp_delegate_t dg, VkQueueGlobalPriorityEXT priority);
207
208void
209vk_pp_format_feature_flag_bits(u_pp_delegate_t dg, VkFormatFeatureFlagBits bits);
210
211void
212vk_pp_swapchain_create_flag_bits(u_pp_delegate_t dg, VkSwapchainCreateFlagBitsKHR bits);
213
214void
215vk_pp_image_usage_flag_bits(u_pp_delegate_t dg, VkImageUsageFlagBits bits);
216
217void
218vk_pp_composite_alpha_flag_bits(u_pp_delegate_t dg, VkCompositeAlphaFlagBitsKHR bits);
219
220void
221vk_pp_surface_transform_flag_bits(u_pp_delegate_t dg, VkSurfaceTransformFlagBitsKHR bits);
222
223#ifdef VK_KHR_display
224void
225vk_pp_display_plane_alpha_flag_bits(u_pp_delegate_t dg, VkDisplayPlaneAlphaFlagBitsKHR bits);
226#endif // VK_KHR_display
227
228/*!
229 * @}
230 */
231
232#ifdef __cplusplus
233}
234#endif
Helper struct to hold a function pointer and data pointer.
Definition u_pretty_print.h:102
Pretty printing various Monado things.
Header holding common defines.
Include all of the Vulkan headers in one place, and cope with any "messy" includes implied by it.