diff --git a/tools/hello.cpp b/tools/hello.cpp index 5642fe4..cb3158d 100644 --- a/tools/hello.cpp +++ b/tools/hello.cpp @@ -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; 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;