From ace1ccf8545751e0a10ff9c44470fd74ff050ec8 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Sun, 19 Apr 2020 02:03:15 -0600 Subject: [PATCH] Explicit swapchain constructor no longer uses queue indexes The second constructor for vkb::Swapchain now queries for the index of the graphics and present queue by itself. This removes the need to users to manually specify it and limits the strict dependency between swapchain and the rest of the vkb structs (Instance & Device mainly) --- src/VkBootstrap.cpp | 17 ++++++++++------- src/VkBootstrap.h | 6 +----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/VkBootstrap.cpp b/src/VkBootstrap.cpp index b04dbd3..4398b39 100644 --- a/src/VkBootstrap.cpp +++ b/src/VkBootstrap.cpp @@ -1192,16 +1192,19 @@ SwapchainBuilder::SwapchainBuilder (Device const& device) { info.present_queue_index = graphics.value (); } -SwapchainBuilder::SwapchainBuilder (VkPhysicalDevice const physical_device, - VkDevice const device, - VkSurfaceKHR const surface, - uint32_t graphics_queue_index, - uint32_t present_queue_index) { +SwapchainBuilder::SwapchainBuilder ( + VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface) { info.physical_device = physical_device; info.device = device; info.surface = surface; - info.graphics_queue_index = graphics_queue_index; - info.present_queue_index = present_queue_index; + auto queue_families = detail::get_vector_noerror ( + vkGetPhysicalDeviceQueueFamilyProperties, physical_device); + + int graphics_queue_index = detail::get_graphics_queue_index (queue_families); + int present_queue_index = detail::get_present_queue_index (physical_device, surface, queue_families); + // TODO: handle queue indexes being below zero + info.graphics_queue_index = static_cast (graphics_queue_index); + info.present_queue_index = static_cast (present_queue_index); } detail::Expected> SwapchainBuilder::build () const { return build (VK_NULL_HANDLE); diff --git a/src/VkBootstrap.h b/src/VkBootstrap.h index 79220d1..93bec53 100644 --- a/src/VkBootstrap.h +++ b/src/VkBootstrap.h @@ -523,11 +523,7 @@ void destroy_swapchain (Swapchain const& swapchain); class SwapchainBuilder { public: SwapchainBuilder (Device const& device); - SwapchainBuilder (VkPhysicalDevice const physical_device, - VkDevice const device, - VkSurfaceKHR const surface, - uint32_t graphics_queue_index, - uint32_t present_queue_index); + SwapchainBuilder (VkPhysicalDevice const physical_device, VkDevice const device, VkSurfaceKHR const surface); detail::Expected> build () const; detail::Expected> recreate (Swapchain const& swapchain) const;