From fff003315b65c1a19ded41774700f10df47f1f29 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sat, 22 Feb 2020 11:35:07 +0100 Subject: [PATCH] Added overload for passing command pool to cmd buffer create and flush --- base/VulkanDevice.hpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/base/VulkanDevice.hpp b/base/VulkanDevice.hpp index d3c27924..c2d3392e 100644 --- a/base/VulkanDevice.hpp +++ b/base/VulkanDevice.hpp @@ -493,38 +493,42 @@ namespace vks * Allocate a command buffer from the command pool * * @param level Level of the new command buffer (primary or secondary) + * @param pool Command pool from which the command buffer will be allocated * @param (Optional) begin If true, recording on the new command buffer will be started (vkBeginCommandBuffer) (Defaults to false) * * @return A handle to the allocated command buffer */ - VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin = false) + VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, VkCommandPool pool, bool begin = false) { - VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo(commandPool, level, 1); - + VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo(pool, level, 1); VkCommandBuffer cmdBuffer; VK_CHECK_RESULT(vkAllocateCommandBuffers(logicalDevice, &cmdBufAllocateInfo, &cmdBuffer)); - // If requested, also start recording for the new command buffer if (begin) { VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VK_CHECK_RESULT(vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo)); } - return cmdBuffer; } + + VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin = false) + { + return createCommandBuffer(level, commandPool, begin); + } /** * Finish command buffer recording and submit it to a queue * * @param commandBuffer Command buffer to flush - * @param queue Queue to submit the command buffer to + * @param queue Queue to submit the command buffer to + * @param pool Command pool on which the command buffer has been created * @param free (Optional) Free the command buffer once it has been submitted (Defaults to true) * * @note The queue that the command buffer is submitted to must be from the same family index as the pool it was allocated from * @note Uses a fence to ensure command buffer has finished executing */ - void flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, bool free = true) + void flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, VkCommandPool pool, bool free = true) { if (commandBuffer == VK_NULL_HANDLE) { @@ -536,25 +540,26 @@ namespace vks VkSubmitInfo submitInfo = vks::initializers::submitInfo(); submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &commandBuffer; - // Create fence to ensure that the command buffer has finished executing VkFenceCreateInfo fenceInfo = vks::initializers::fenceCreateInfo(VK_FLAGS_NONE); VkFence fence; VK_CHECK_RESULT(vkCreateFence(logicalDevice, &fenceInfo, nullptr, &fence)); - // Submit to the queue VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, fence)); // Wait for the fence to signal that command buffer has finished executing VK_CHECK_RESULT(vkWaitForFences(logicalDevice, 1, &fence, VK_TRUE, DEFAULT_FENCE_TIMEOUT)); - vkDestroyFence(logicalDevice, fence, nullptr); - if (free) { - vkFreeCommandBuffers(logicalDevice, commandPool, 1, &commandBuffer); + vkFreeCommandBuffers(logicalDevice, pool, 1, &commandBuffer); } } + void flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, bool free = true) + { + return flushCommandBuffer(commandBuffer, queue, commandPool, free); + } + /** * Check if an extension is supported by the (physical device) *