From 9bc30e6937c15206925bf2d5e917ab074ccbea88 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Thu, 12 Aug 2021 21:31:20 -0700 Subject: [PATCH] Create vulkan command pools --- kraken/KRContext.cpp | 22 ++++++++++++++++++++++ kraken/KRContext.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/kraken/KRContext.cpp b/kraken/KRContext.cpp index 3228b66..9c187a7 100755 --- a/kraken/KRContext.cpp +++ b/kraken/KRContext.cpp @@ -785,6 +785,8 @@ KRContext::destroyDeviceContexts() { for (auto itr = m_devices.begin(); itr != m_devices.end(); itr++) { DeviceInfo* deviceInfo = &(*itr).second; + vkDestroyCommandPool(deviceInfo->logicalDevice, deviceInfo->graphicsCommandPool, nullptr); + vkDestroyCommandPool(deviceInfo->logicalDevice, deviceInfo->computeCommandPool, nullptr); vkDestroyDevice(deviceInfo->logicalDevice, nullptr); } @@ -1311,6 +1313,26 @@ void KRContext::createDevices() } vkGetDeviceQueue(info.logicalDevice, info.graphicsFamilyQueueIndex, 0, &info.graphicsQueue); vkGetDeviceQueue(info.logicalDevice, info.computeFamilyQueueIndex, 0, &info.computeQueue); + + VkCommandPoolCreateInfo poolInfo{}; + poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + poolInfo.queueFamilyIndex = info.graphicsFamilyQueueIndex; + poolInfo.flags = 0; + + if (vkCreateCommandPool(info.logicalDevice, &poolInfo, nullptr, &info.graphicsCommandPool) != VK_SUCCESS) { + vkDestroyDevice(info.logicalDevice, nullptr); + // TODO - Log a warning... + continue; + } + + poolInfo.queueFamilyIndex = info.computeFamilyQueueIndex; + if (vkCreateCommandPool(info.logicalDevice, &poolInfo, nullptr, &info.computeCommandPool) != VK_SUCCESS) { + vkDestroyCommandPool(info.logicalDevice, info.graphicsCommandPool, nullptr); + vkDestroyDevice(info.logicalDevice, nullptr); + // TODO - Log a warning... + continue; + } + m_devices[++m_topDeviceHandle] = info; } } diff --git a/kraken/KRContext.h b/kraken/KRContext.h index 62389ff..d553681 100755 --- a/kraken/KRContext.h +++ b/kraken/KRContext.h @@ -139,6 +139,8 @@ public: VkQueue graphicsQueue; uint32_t computeFamilyQueueIndex; VkQueue computeQueue; + VkCommandPool graphicsCommandPool; + VkCommandPool computeCommandPool; } DeviceInfo; typedef struct {