Search code examples
c++vulkan

Vulkan - Get multiple queues from the same family


I am currently following the vulkan tutorial series and stumbeled uppon this thing.

When the author introduces a second queue (presentation) he creates VkDeviceQueueCreateInfo for every unique kind of queue family. But he always sets the queueCount property to 1. Later, when getting the queue handles with vkGetDeviceQueue he has the third (queueIndex) parameter always set to 0.

In the case that both graphics and present queue come from the same queue family, which is very likely to my understanding, are the two queue handles not the same. Since both point to the queue in the graphics family at index 0

VkQueue graphicsQueue;
VkQueue presentQueue;

vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);
vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);

And if that is the goal, why bother with having an "extra" present queue? What could be the benefits from doing it like this?


Solution

  • Because the graphics queue may not support presentation, it's easier from a code perspective to not assume that the graphics queue and presentation queue are the same. Instead, this code assumes that they are different. It's OK to get the same queue more than once. It's called vkGetDeviceQueue rather than vkCreateDeviceQueue for a reason. The queue already exists; you're just getting a pointer to it.

    This is also why there is no vkDestroyDeviceQueue.