You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* `VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT`: Informational message like the creation of a resource
235
+
* `VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT`: Message about behavior that is not necessarily an error, but very likely a bug in your application
236
+
* `VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT`: Message about behavior that is invalid and may cause crashes
243
237
244
-
The `objType` parameter specifies the type of object that is the subject of the
245
-
message. For example if `obj` is a `VkPhysicalDevice` then `objType` would be
246
-
`VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT`. This works because internally all
247
-
Vulkan handles are typedef'd as `uint64_t`. The `msg` parameter contains the
248
-
pointer to the message itself. Finally, there's a `userData` parameter to pass
249
-
your own data to the callback.
238
+
The values of this enumeration are set up in such a way that you can use a comparison operation to check if a message is equal or worse compared to some level of severity, for example:
239
+
240
+
```c++
241
+
if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
242
+
// Message is important enough to show
243
+
}
244
+
```
245
+
246
+
The `messageType` parameter can have the following values:
247
+
248
+
*`VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT`: Some event has happened that is unrelated to the specification or performance
249
+
*`VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT`: Something has happened that violates the specification or indicates a possible mistake
250
+
*`VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT`: Potential non-optimal use of Vulkan
251
+
252
+
The `pCallbackData` parameter refers to a `VkDebugUtilsMessengerCallbackDataEXT` struct containing the details of the message itself, with the most important members being:
253
+
254
+
*`pMessage`: The debug message as a null-terminated string
255
+
*`pObjects`: Array of Vulkan object handles related to the message
256
+
*`objectCount`: Number of objects in array
257
+
258
+
Finally, the `pUserData` parameter contains a pointer that was specified during the setup of the callback and allows you to pass your own data to it.
250
259
251
260
The callback returns a boolean that indicates if the Vulkan call that triggered
252
261
the validation layer message should be aborted. If the callback returns true,
@@ -256,11 +265,11 @@ always return `VK_FALSE`.
256
265
257
266
All that remains now is telling Vulkan about the callback function. Perhaps
258
267
somewhat surprisingly, even the debug callback in Vulkan is managed with a
259
-
handle that needs to be explicitly created and destroyed. Add a class member for
268
+
handle that needs to be explicitly created and destroyed. Such a callback is called a *messenger* and you can have as many of them as you want. Add a class member for
260
269
this handle right under `instance`:
261
270
262
271
```c++
263
-
VkDebugReportCallbackEXT callback;
272
+
VkDebugUtilsMessengerEXT callback;
264
273
```
265
274
266
275
Now add a function `setupDebugCallback` to be called from `initVulkan` right
@@ -281,28 +290,32 @@ void setupDebugCallback() {
281
290
We'll need to fill in a structure with details about the callback:
The `flags` field allows you to filter which types of messages you would like to
291
-
receive. The `pfnCallback` field specifies the pointer to the callback function.
292
-
You can optionally pass a pointer to the `pUserData` field which will be passed
293
-
along to the callback function via the `userData` parameter. You could use this
294
-
to pass a pointer to the `HelloTriangleApplication` class, for example.
301
+
The `messageSeverity` field allows you to specify all the types of severities you would like your callback to be called for. I've specified all types except for `VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT` here to receive notifications about possible problems while leaving out verbose general debug info.
302
+
303
+
Similarly the `messageType` field lets you filter which types of messages your callback is notified about. I've simply enabled all types here. You can always disable some if they're not useful to you.
304
+
305
+
Finally, the `pfnUserCallback` field specifies the pointer to the callback function. You can optionally pass a pointer to the `pUserData` field which will be passed along to the callback function via the `pUserData` parameter. You could use this to pass a pointer to the `HelloTriangleApplication` class, for example.
306
+
307
+
Note that there are many more ways to configure validation layer messages and debug callbacks, but this is a good setup to get started with for this tutorial. See the [extension specification](https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VK_EXT_debug_utils) for more info about the possibilities.
295
308
296
-
This struct should be passed to the `vkCreateDebugReportCallbackEXT` function to
297
-
create the `VkDebugReportCallbackEXT` object. Unfortunately, because this
309
+
This struct should be passed to the `vkCreateDebugUtilsMessengerEXT` function to
310
+
create the `VkDebugUtilsMessengerEXT` object. Unfortunately, because this
298
311
function is an extension function, it is not automatically loaded. We have to
299
312
look up its address ourselves using `vkGetInstanceProcAddr`. We're going to
300
313
create our own proxy function that handles this in the background. I've added it
301
314
right above the `HelloTriangleApplication` class definition.
@@ -316,7 +329,7 @@ couldn't be loaded. We can now call this function to create the extension
316
329
object if it's available:
317
330
318
331
```c++
319
-
if (CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &callback) != VK_SUCCESS) {
332
+
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &callback) != VK_SUCCESS) {
320
333
throw std::runtime_error("failed to set up debug callback!");
321
334
}
322
335
```
@@ -332,16 +345,16 @@ window. You'll see that the following messages are printed to the command prompt
332
345

333
346
334
347
Oops, it has already spotted a bug in our program! The
335
-
`VkDebugReportCallbackEXT` object needs to be cleaned up with a call to
336
-
`vkDestroyDebugReportCallbackEXT`. Similarly to `vkCreateDebugReportCallbackEXT`
337
-
the function needs to be explicitly loaded. The reason for there being multiple messages is that multiple validation layers check for the deletion of the debug report callback.
348
+
`VkDebugUtilsMessengerEXT` object needs to be cleaned up with a call to
349
+
`vkDestroyDebugUtilsMessengerEXT`. Similarly to `vkCreateDebugUtilsMessengerEXT`
350
+
the function needs to be explicitly loaded. Note that it is normal for this message to be printed multiple times. This happens because multiple validation layers check for for the deletion of the debug messenger.
0 commit comments