Cortex0101
Cortex0101

Reputation: 927

Understanding flags in Vulkan

In trying to set up a debug callback in Vulkan I noticed something weird about the LunarG SDK validation layers.

In setting it up the create info struct, I do the following:

VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo;
debugCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
debugCreateInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
debugCreateInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
debugCreateInfo.pfnUserCallback = debugCallback;

Everything works, but when I run it the application I get the following message:

VUID-VkDebugUtilsMessengerCreateInfoEXT-flags-zerobitmask(ERROR / SPEC): msgNum: 1138790405 - vkCreateDebugUtilsMessengerEXT: parameter pCreateInfo->flags must be 0. The spec valid usage text states 'flags must be 0' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-VkDebugUtilsMessengerCreateInfoEXT-flags-zerobitmask)

I do not really understand the message and the link just takes me to the start of the Vulkan specification page. So all I can understand is:

vkCreateDebugUtilsMessengerEXT: parameter pCreateInfo->flags must be 0

If I do set debugCreateInfo.flags = 0; explicitly the error goes away. But this has not been necessary anywhere else? I have never used the flags and I don't understand them at all either.

What I then found is that the error also dissappears if I change the struct declaration from:

VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo;
// to
VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo = {};

So my question is what are flags, and what is the connection between the way I declare the struct and the declaration of the flag?

Upvotes: 0

Views: 1336

Answers (1)

Sascha Willems
Sascha Willems

Reputation: 5808

Flags in Vulkan work just like flags anywhere else and are simple bit masks to pass information to the implementation, just like the ones you pass via messageSeverity in your above example.

But as of now, there are no valid flags you can actually set for the debug utils create info structure as per the specs:

flags is 0 and reserved for future use.

And the valid usage chapter clearly states:

flags must be 0

This member is reserved for future usage, e.g. for extensions, so right now it must always be zero.

In your initial code snippet you don't explicitly clear the VkDebugUtilsMessengerCreateInfoEXT structure which may result in pFlags having some random value that does not fit within the rules set by the spec.

This also applies for all other Vulkan structures that use e.g. flags. So if you don't explicitly set any flags you should always clear the create info structures so that any pFlags member is set to zero. Not doing so may result in undefined behavior.

Upvotes: 1

Related Questions