Skip to content

Commit b4f923f

Browse files
committed
Replace deprecated debug reports extension with debug utils
Fix validation layers not being enabled in debug builds Refs KhronosGroup#1168
1 parent 6505639 commit b4f923f

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

samples/api/hello_triangle/hello_triangle.cpp

+34-29
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,28 @@
2424
#include "platform/window.h"
2525

2626
#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)
3131
{
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)
3335
{
34-
LOGE("Validation Layer: Error: {}: {}", layer_prefix, message);
36+
LOGE("{} Validation Layer: Error: {}: {}", callback_data->messageIdNumber, callback_data->pMessageIdName, callback_data->pMessage)
3537
}
36-
else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT)
38+
else if (message_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
3739
{
38-
LOGE("Validation Layer: Warning: {}: {}", layer_prefix, message);
40+
LOGE("{} Validation Layer: Warning: {}: {}", callback_data->messageIdNumber, callback_data->pMessageIdName, callback_data->pMessage)
3941
}
40-
else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)
42+
else if (message_type & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
4143
{
42-
LOGI("Validation Layer: Performance warning: {}: {}", layer_prefix, message);
44+
LOGI("{} Validation Layer: Performance warning: {}: {}", callback_data->messageIdNumber, callback_data->pMessageIdName, callback_data->pMessage)
4345
}
4446
else
4547
{
46-
LOGI("Validation Layer: Information: {}: {}", layer_prefix, message);
48+
LOGI("{} Validation Layer: Information: {}: {}", callback_data->messageIdNumber, callback_data->pMessageIdName, callback_data->pMessage)
4749
}
4850
return VK_FALSE;
4951
}
@@ -176,22 +178,22 @@ void HelloTriangle::init_instance(Context &context,
176178
std::vector<const char *> active_instance_extensions(required_instance_extensions);
177179

178180
#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;
180184
for (const auto &ext : available_instance_extensions)
181185
{
182-
if (strcmp(ext.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0)
186+
if (strcmp(ext.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0)
183187
{
184-
has_debug_report = true;
188+
has_debug_utils = true;
189+
active_instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
185190
break;
186191
}
187192
}
188-
if (has_debug_report)
193+
if (!has_debug_utils)
189194
{
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");
195197
}
196198
#endif
197199

@@ -238,7 +240,7 @@ void HelloTriangle::init_instance(Context &context,
238240

239241
std::vector<const char *> requested_validation_layers(required_validation_layers);
240242

241-
#ifdef VKB_VALIDATION_LAYERS
243+
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
242244
// Determine the optimal validation layers to enable that are necessary for useful debugging
243245
std::vector<const char *> optimal_validation_layers = vkb::get_optimal_validation_layers(supported_validation_layers);
244246
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,
270272
instance_info.ppEnabledLayerNames = requested_validation_layers.data();
271273

272274
#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)
275279
{
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;
278283

279-
instance_info.pNext = &debug_report_create_info;
284+
instance_info.pNext = &debug_utils_create_info;
280285
}
281286
#endif
282287

@@ -293,9 +298,9 @@ void HelloTriangle::init_instance(Context &context,
293298
volkLoadInstance(context.instance);
294299

295300
#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
296-
if (has_debug_report)
301+
if (has_debug_utils)
297302
{
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));
299304
}
300305
#endif
301306
}
@@ -1062,7 +1067,7 @@ void HelloTriangle::teardown(Context &context)
10621067

10631068
if (context.debug_callback != VK_NULL_HANDLE)
10641069
{
1065-
vkDestroyDebugReportCallbackEXT(context.instance, context.debug_callback, nullptr);
1070+
vkDestroyDebugUtilsMessengerEXT(context.instance, context.debug_callback, nullptr);
10661071
context.debug_callback = VK_NULL_HANDLE;
10671072
}
10681073

samples/api/hello_triangle/hello_triangle.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018-2023, Arm Limited and Contributors
1+
/* Copyright (c) 2018-2024, Arm Limited and Contributors
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -110,7 +110,7 @@ class HelloTriangle : public vkb::Application
110110
VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
111111

112112
/// The debug report callback.
113-
VkDebugReportCallbackEXT debug_callback = VK_NULL_HANDLE;
113+
VkDebugUtilsMessengerEXT debug_callback = VK_NULL_HANDLE;
114114

115115
/// A set of semaphores that can be reused.
116116
std::vector<VkSemaphore> recycled_semaphores;

0 commit comments

Comments
 (0)