hello-tool: don't create redundant queues

vulkan prohibits queues with identical ids
This commit is contained in:
Danny Robson 2017-09-07 16:35:14 +10:00
parent 1238ae4914
commit c7302ab423

View File

@ -143,16 +143,24 @@ main (void)
auto queues = pdevice.queue_families ();
int graphics_queue_id = -1, present_queue_id = -1;
for (int i = 0; unsigned (i) != queues.size (); ++i) {
if (queues[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
graphics_queue_id = i;
VkBool32 present_support = false;
cruft::vk::error::try_func (
&vkGetPhysicalDeviceSurfaceSupportKHR, pdevice.id (), i, surface.id (), &present_support
);
if (present_support)
for (int i = 0, last = queues.size (); i != last; ++i)
if (queues[i].queueCount > 0 && queues[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
graphics_queue_id = i;
break;
}
for (int i = 0, last = queues.size (); i != last; ++i) {
if (cruft::vk::error::try_query (vkGetPhysicalDeviceSurfaceSupportKHR,
pdevice.id (), i, surface.id ())) {
present_queue_id = i;
break;
}
}
if (graphics_queue_id == -1 || present_queue_id == -1) {
std::cerr << "unable to find useful queues\n";
return EXIT_FAILURE;
}
float priority = 1.f;
@ -185,7 +193,7 @@ main (void)
VkDeviceCreateInfo device_info {};
device_info.sType = cruft::vk::structure_type_v<VkDeviceCreateInfo>;
device_info.pQueueCreateInfos = std::data (device_queues);
device_info.queueCreateInfoCount = std::size (device_queues);
device_info.queueCreateInfoCount = graphics_queue_id == present_queue_id ? 1 : 2;
device_info.pEnabledFeatures = &device_features;
device_info.enabledLayerCount = std::size (layers);
device_info.ppEnabledLayerNames = layers;