Overv / VulkanTutorial

Tutorial for the Vulkan graphics and compute API
https://vulkan-tutorial.com
Creative Commons Attribution Share Alike 4.0 International
3.06k stars 511 forks source link

Non unique queue family indices in findQueueFamilies #318

Closed ruscito closed 1 year ago

ruscito commented 1 year ago

Not sure if this an issue or me doing something wrong but when creating the device (vkCreateDevice) I get a vulkan specification error:

"The Vulkan spec states: The queueFamilyIndex member of each element of pQueueCreateInfos must be unique within pQueueCreateInfos (https://vulkan.lunarg.com/d..."

I believe this is because the queueFamilyIndices, for the graphicsFamily and presentFamily are same, and this is the result of the function findQueueFamilies.

I modified the findQueueFamilies function for loop, to continue once the first family supporting graphics operation is found; with this change the presentFamily get a different index, and this fix the vulkan validation error.

Am I doing something wrong or there is a bug to the findQueueFamilies function?

Thanks

SaschaWillems commented 1 year ago

At what line of code does that validation layer message occur? The findQueueFamilies function uses a set, so even if graphics and compute queue family indices are the same, you only get one value in that set:

std::set<uint32_t> uniqueQueueFamilies = {indices.graphicsFamily.value(), indices.presentFamily.value()};
ruscito commented 1 year ago

The validation error occur at the physical device creation; vkCreateDevice return is successful but it generate a validation error.

Vulkan [SPECIFICATION] Validation Error: [ VUID-VkDeviceCreateInfo-queueFamilyIndex-00372 ] Object 0: handle = 0x10e222380, type = VK_OBJECT_TYPE_PHYSICAL_DEVICE; | MessageID = 0xde3cbaf | CreateDevice(): pCreateInfo->pQueueCreateInfos[1].queueFamilyIndex (=0) is not unique and was also used in pCreateInfo->pQueueCreateInfos[0]. The Vulkan spec states: The queueFamilyIndex member of each element of pQueueCreateInfos must be unique within pQueueCreateInfos (https://vulkan.lunarg.com/doc/view/1.3.231.1/mac/1.3-extensions/vkspec.html#VUID-VkDeviceCreateInfo-queueFamilyIndex-00372

I did some reading and looks like the family that support present and graphics can't be same. In my case they were both 0 (zero). After changing the findQueueFamilies I now get 0 for the graphics and 2 for the presenter and the validation error is gone.

Looking at the comments in the tutorial (05 surface) other people had the same issue. I open a pull request #319 with the change

Thanks

Overv commented 1 year ago

If you see that message then there is a mistake in your code, since the queue family indices are already deduplicated by the std::set.

ruscito commented 1 year ago

I think I understand the issue. I'm implementing the tutorial in C and somehow I skipped the unique set creation. @SaschaWillems pointed out but I'm traveling and didn't have time to close the issue. Thanks