24
24
#include " platform/window.h"
25
25
26
26
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
27
- // / @brief A debug callback called from Vulkan validation layers.
28
- static VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback (VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT type ,
29
- uint64_t object, size_t location, int32_t message_code ,
30
- const char *layer_prefix, const char *message, void *user_data)
27
+ // / @brief A debug callback used to report messages from the validation layers. See instance creation for details on how this is set up
28
+ static VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, VkDebugUtilsMessageTypeFlagsEXT message_type ,
29
+ const VkDebugUtilsMessengerCallbackDataEXT *callback_data ,
30
+ void *user_data)
31
31
{
32
- if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT)
32
+ (void ) user_data;
33
+
34
+ if (message_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
33
35
{
34
- LOGE (" Validation Layer: Error: {}: {}" , layer_prefix, message);
36
+ LOGE (" {} Validation Layer: Error: {}: {}" , callback_data-> messageIdNumber , callback_data-> pMessageIdName , callback_data-> pMessage )
35
37
}
36
- else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT )
38
+ else if (message_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT )
37
39
{
38
- LOGE (" Validation Layer: Warning: {}: {}" , layer_prefix, message);
40
+ LOGE (" {} Validation Layer: Warning: {}: {}" , callback_data-> messageIdNumber , callback_data-> pMessageIdName , callback_data-> pMessage )
39
41
}
40
- else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT )
42
+ else if (message_type & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT )
41
43
{
42
- LOGI (" Validation Layer: Performance warning: {}: {}" , layer_prefix, message);
44
+ LOGI (" {} Validation Layer: Performance warning: {}: {}" , callback_data-> messageIdNumber , callback_data-> pMessageIdName , callback_data-> pMessage )
43
45
}
44
46
else
45
47
{
46
- LOGI (" Validation Layer: Information: {}: {}" , layer_prefix, message);
48
+ LOGI (" {} Validation Layer: Information: {}: {}" , callback_data-> messageIdNumber , callback_data-> pMessageIdName , callback_data-> pMessage )
47
49
}
48
50
return VK_FALSE;
49
51
}
@@ -176,22 +178,22 @@ void HelloTriangle::init_instance(Context &context,
176
178
std::vector<const char *> active_instance_extensions (required_instance_extensions);
177
179
178
180
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
179
- bool has_debug_report = false ;
181
+ // Validation layers help finding wrong api usage, we enable them when explicitly requested or in debug builds
182
+ // For this we use the debug utils extension if it is supported
183
+ bool has_debug_utils = false ;
180
184
for (const auto &ext : available_instance_extensions)
181
185
{
182
- if (strcmp (ext.extensionName , VK_EXT_DEBUG_REPORT_EXTENSION_NAME ) == 0 )
186
+ if (strcmp (ext.extensionName , VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) == 0 )
183
187
{
184
- has_debug_report = true ;
188
+ has_debug_utils = true ;
189
+ active_instance_extensions.push_back (VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
185
190
break ;
186
191
}
187
192
}
188
- if (has_debug_report )
193
+ if (!has_debug_utils )
189
194
{
190
- active_instance_extensions.push_back (VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
191
- }
192
- else
193
- {
194
- LOGW (" {} is not available; disabling debug reporting" , VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
195
+ LOGW (" {} not supported or available" , VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
196
+ LOGW (" Make sure to compile the sample in debug mode and/or enable the validation layers" );
195
197
}
196
198
#endif
197
199
@@ -238,7 +240,7 @@ void HelloTriangle::init_instance(Context &context,
238
240
239
241
std::vector<const char *> requested_validation_layers (required_validation_layers);
240
242
241
- #ifdef VKB_VALIDATION_LAYERS
243
+ #if defined(VKB_DEBUG) || defined( VKB_VALIDATION_LAYERS)
242
244
// Determine the optimal validation layers to enable that are necessary for useful debugging
243
245
std::vector<const char *> optimal_validation_layers = vkb::get_optimal_validation_layers (supported_validation_layers);
244
246
requested_validation_layers.insert (requested_validation_layers.end (), optimal_validation_layers.begin (), optimal_validation_layers.end ());
@@ -270,13 +272,16 @@ void HelloTriangle::init_instance(Context &context,
270
272
instance_info.ppEnabledLayerNames = requested_validation_layers.data ();
271
273
272
274
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
273
- VkDebugReportCallbackCreateInfoEXT debug_report_create_info = {VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT};
274
- if (has_debug_report)
275
+ // Validation layers help finding wrong api usage, we enable them when explicitly requested or in debug builds
276
+ // For this we use the debug utils extension if it is supported
277
+ VkDebugUtilsMessengerCreateInfoEXT debug_utils_create_info = {VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT};
278
+ if (has_debug_utils)
275
279
{
276
- debug_report_create_info.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
277
- debug_report_create_info.pfnCallback = debug_callback;
280
+ debug_utils_create_info.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
281
+ debug_utils_create_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
282
+ debug_utils_create_info.pfnUserCallback = debug_callback;
278
283
279
- instance_info.pNext = &debug_report_create_info ;
284
+ instance_info.pNext = &debug_utils_create_info ;
280
285
}
281
286
#endif
282
287
@@ -293,9 +298,9 @@ void HelloTriangle::init_instance(Context &context,
293
298
volkLoadInstance (context.instance );
294
299
295
300
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
296
- if (has_debug_report )
301
+ if (has_debug_utils )
297
302
{
298
- VK_CHECK (vkCreateDebugReportCallbackEXT (context.instance , &debug_report_create_info , nullptr , &context.debug_callback ));
303
+ VK_CHECK (vkCreateDebugUtilsMessengerEXT (context.instance , &debug_utils_create_info , nullptr , &context.debug_callback ));
299
304
}
300
305
#endif
301
306
}
@@ -1062,7 +1067,7 @@ void HelloTriangle::teardown(Context &context)
1062
1067
1063
1068
if (context.debug_callback != VK_NULL_HANDLE)
1064
1069
{
1065
- vkDestroyDebugReportCallbackEXT (context.instance , context.debug_callback , nullptr );
1070
+ vkDestroyDebugUtilsMessengerEXT (context.instance , context.debug_callback , nullptr );
1066
1071
context.debug_callback = VK_NULL_HANDLE;
1067
1072
}
1068
1073
0 commit comments