From b2ad0b616f0583408c95992ec230bd7e44be6127 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 19 Jul 2021 22:18:33 +0200 Subject: [PATCH] search for a queue on vkCreateDevice --- src/basalt.cpp | 106 +++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 74 deletions(-) diff --git a/src/basalt.cpp b/src/basalt.cpp index 3dfaf5b..49f015b 100644 --- a/src/basalt.cpp +++ b/src/basalt.cpp @@ -150,6 +150,7 @@ namespace vkBasalt const VkAllocationCallbacks* pAllocator, VkDevice* pDevice) { + scoped_lock l(globalLock); Logger::trace("vkCreateDevice"); VkLayerDeviceCreateInfo* layerCreateInfo = (VkLayerDeviceCreateInfo*) pCreateInfo->pNext; @@ -232,101 +233,60 @@ namespace vkBasalt fillDispatchTableDevice(*pDevice, gdpa, &pLogicalDevice->vkd); - // store the table by key - { - scoped_lock l(globalLock); - deviceMap[GetKey(*pDevice)] = pLogicalDevice; - } - - return ret; - } - - VK_LAYER_EXPORT void VKAPI_CALL vkBasalt_DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) - { - scoped_lock l(globalLock); - - Logger::trace("vkDestroyDevice"); - - LogicalDevice* pLogicalDevice = deviceMap[GetKey(device)].get(); - if (pLogicalDevice->commandPool != VK_NULL_HANDLE) - { - Logger::debug("DestroyCommandPool"); - pLogicalDevice->vkd.DestroyCommandPool(device, pLogicalDevice->commandPool, pAllocator); - } - - pLogicalDevice->vkd.DestroyDevice(device, pAllocator); - - deviceMap.erase(GetKey(device)); - } - - static void saveDeviceQueue(LogicalDevice* pLogicalDevice, uint32_t queueFamilyIndex, VkQueue* pQueue) - { - if (pLogicalDevice->queue != VK_NULL_HANDLE) - { - return; // we allready have a queue - } - - // Save the first graphic capable queue in our deviceMap uint32_t count; - VkBool32 graphicsCapable = VK_FALSE; - // TODO also check if the queue is present capable + pLogicalDevice->vki.GetPhysicalDeviceQueueFamilyProperties(pLogicalDevice->physicalDevice, &count, nullptr); std::vector queueProperties(count); - if (count > 0) + pLogicalDevice->vki.GetPhysicalDeviceQueueFamilyProperties(pLogicalDevice->physicalDevice, &count, queueProperties.data()); + for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) { - pLogicalDevice->vki.GetPhysicalDeviceQueueFamilyProperties(pLogicalDevice->physicalDevice, &count, queueProperties.data()); - if ((queueProperties[queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) + auto& queueInfo = pCreateInfo->pQueueCreateInfos[i]; + if ((queueProperties[queueInfo.queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT)) { - graphicsCapable = VK_TRUE; - } - } - else - { - // TODO - graphicsCapable = VK_TRUE; - } + pLogicalDevice->vkd.GetDeviceQueue(pLogicalDevice->device, queueInfo.queueFamilyIndex, 0, &pLogicalDevice->queue); - if (graphicsCapable) - { - VkCommandPoolCreateInfo commandPoolCreateInfo; - commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - commandPoolCreateInfo.pNext = nullptr; - commandPoolCreateInfo.flags = 0; - commandPoolCreateInfo.queueFamilyIndex = queueFamilyIndex; + VkCommandPoolCreateInfo commandPoolCreateInfo; + commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + commandPoolCreateInfo.pNext = nullptr; + commandPoolCreateInfo.flags = 0; + commandPoolCreateInfo.queueFamilyIndex = queueInfo.queueFamilyIndex; - Logger::debug("found graphic capable queue"); - pLogicalDevice->vkd.CreateCommandPool(pLogicalDevice->device, &commandPoolCreateInfo, nullptr, &pLogicalDevice->commandPool); - pLogicalDevice->queue = *pQueue; - pLogicalDevice->queueFamilyIndex = queueFamilyIndex; - } - } + Logger::debug("Found graphics capable queue"); + pLogicalDevice->vkd.CreateCommandPool(pLogicalDevice->device, &commandPoolCreateInfo, nullptr, &pLogicalDevice->commandPool); + pLogicalDevice->queueFamilyIndex = queueInfo.queueFamilyIndex; - VKAPI_ATTR void VKAPI_CALL vkBasalt_GetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue) - { - scoped_lock l(globalLock); + initializeDispatchTable(pLogicalDevice->queue, pLogicalDevice->device); - Logger::trace("vkGetDeviceQueue2"); + break; + } + } - LogicalDevice* pLogicalDevice = deviceMap[GetKey(device)].get(); + if (!pLogicalDevice->queue) + Logger::err("Did not find a graphics queue!"); - pLogicalDevice->vkd.GetDeviceQueue2(device, pQueueInfo, pQueue); + deviceMap[GetKey(*pDevice)] = pLogicalDevice; - saveDeviceQueue(pLogicalDevice, pQueueInfo->queueFamilyIndex, pQueue); + return ret; } - VKAPI_ATTR void VKAPI_CALL vkBasalt_GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue) + VK_LAYER_EXPORT void VKAPI_CALL vkBasalt_DestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator) { scoped_lock l(globalLock); - Logger::trace("vkGetDeviceQueue"); + Logger::trace("vkDestroyDevice"); LogicalDevice* pLogicalDevice = deviceMap[GetKey(device)].get(); + if (pLogicalDevice->commandPool != VK_NULL_HANDLE) + { + Logger::debug("DestroyCommandPool"); + pLogicalDevice->vkd.DestroyCommandPool(device, pLogicalDevice->commandPool, pAllocator); + } - pLogicalDevice->vkd.GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue); + pLogicalDevice->vkd.DestroyDevice(device, pAllocator); - saveDeviceQueue(pLogicalDevice, queueFamilyIndex, pQueue); + deviceMap.erase(GetKey(device)); } VKAPI_ATTR VkResult VKAPI_CALL vkBasalt_CreateSwapchainKHR(VkDevice device, @@ -876,8 +836,6 @@ extern "C" GETPROCADDR(EnumerateDeviceExtensionProperties); \ GETPROCADDR(CreateDevice); \ GETPROCADDR(DestroyDevice); \ - GETPROCADDR(GetDeviceQueue); \ - GETPROCADDR(GetDeviceQueue2); \ GETPROCADDR(CreateSwapchainKHR); \ GETPROCADDR(GetSwapchainImagesKHR); \ GETPROCADDR(QueuePresentKHR); \