From 0285e734bcba8e1308b75256d78bbae806bf0498 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Thu, 12 Aug 2021 21:45:41 -0700 Subject: [PATCH] Allocate Vulkan command buffers --- kraken/KRContext.cpp | 28 ++++++++++++++++++++++++++++ kraken/KRContext.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/kraken/KRContext.cpp b/kraken/KRContext.cpp index 9c187a7..c4c782d 100755 --- a/kraken/KRContext.cpp +++ b/kraken/KRContext.cpp @@ -1333,6 +1333,34 @@ void KRContext::createDevices() continue; } + const int kMaxGraphicsCommandBuffers = 10; // TODO - This needs to be dynamic? + info.graphicsCommandBuffers.resize(kMaxGraphicsCommandBuffers); + + const int kMaxComputeCommandBuffers = 4; // TODO - This needs to be dynamic? + info.computeCommandBuffers.resize(kMaxComputeCommandBuffers); + + VkCommandBufferAllocateInfo allocInfo{}; + allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + allocInfo.commandPool = info.graphicsCommandPool; + allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + allocInfo.commandBufferCount = (uint32_t)info.graphicsCommandBuffers.size(); + + if (vkAllocateCommandBuffers(info.logicalDevice, &allocInfo, info.graphicsCommandBuffers.data()) != VK_SUCCESS) { + vkDestroyCommandPool(info.logicalDevice, info.computeCommandPool, nullptr); + vkDestroyCommandPool(info.logicalDevice, info.graphicsCommandPool, nullptr); + vkDestroyDevice(info.logicalDevice, nullptr); + // TODO - Log a warning + } + + allocInfo.commandPool = info.computeCommandPool; + allocInfo.commandBufferCount = (uint32_t)info.computeCommandBuffers.size(); + if (vkAllocateCommandBuffers(info.logicalDevice, &allocInfo, info.computeCommandBuffers.data()) != VK_SUCCESS) { + vkDestroyCommandPool(info.logicalDevice, info.computeCommandPool, nullptr); + vkDestroyCommandPool(info.logicalDevice, info.graphicsCommandPool, nullptr); + vkDestroyDevice(info.logicalDevice, nullptr); + // TODO - Log a warning + } + m_devices[++m_topDeviceHandle] = info; } } diff --git a/kraken/KRContext.h b/kraken/KRContext.h index d553681..02aa61a 100755 --- a/kraken/KRContext.h +++ b/kraken/KRContext.h @@ -141,6 +141,8 @@ public: VkQueue computeQueue; VkCommandPool graphicsCommandPool; VkCommandPool computeCommandPool; + std::vector graphicsCommandBuffers; + std::vector computeCommandBuffers; } DeviceInfo; typedef struct {