Added overload for passing command pool to cmd buffer create and flush

This commit is contained in:
Sascha Willems 2020-02-22 11:35:07 +01:00
parent d1fbf8d00a
commit fff003315b

View file

@ -493,38 +493,42 @@ namespace vks
* Allocate a command buffer from the command pool * Allocate a command buffer from the command pool
* *
* @param level Level of the new command buffer (primary or secondary) * @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) * @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 * @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; VkCommandBuffer cmdBuffer;
VK_CHECK_RESULT(vkAllocateCommandBuffers(logicalDevice, &cmdBufAllocateInfo, &cmdBuffer)); VK_CHECK_RESULT(vkAllocateCommandBuffers(logicalDevice, &cmdBufAllocateInfo, &cmdBuffer));
// If requested, also start recording for the new command buffer // If requested, also start recording for the new command buffer
if (begin) if (begin)
{ {
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo(); VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
VK_CHECK_RESULT(vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo)); VK_CHECK_RESULT(vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo));
} }
return cmdBuffer; return cmdBuffer;
} }
VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin = false)
{
return createCommandBuffer(level, commandPool, begin);
}
/** /**
* Finish command buffer recording and submit it to a queue * Finish command buffer recording and submit it to a queue
* *
* @param commandBuffer Command buffer to flush * @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) * @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 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 * @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) if (commandBuffer == VK_NULL_HANDLE)
{ {
@ -536,25 +540,26 @@ namespace vks
VkSubmitInfo submitInfo = vks::initializers::submitInfo(); VkSubmitInfo submitInfo = vks::initializers::submitInfo();
submitInfo.commandBufferCount = 1; submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandBuffer; submitInfo.pCommandBuffers = &commandBuffer;
// Create fence to ensure that the command buffer has finished executing // Create fence to ensure that the command buffer has finished executing
VkFenceCreateInfo fenceInfo = vks::initializers::fenceCreateInfo(VK_FLAGS_NONE); VkFenceCreateInfo fenceInfo = vks::initializers::fenceCreateInfo(VK_FLAGS_NONE);
VkFence fence; VkFence fence;
VK_CHECK_RESULT(vkCreateFence(logicalDevice, &fenceInfo, nullptr, &fence)); VK_CHECK_RESULT(vkCreateFence(logicalDevice, &fenceInfo, nullptr, &fence));
// Submit to the queue // Submit to the queue
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, fence)); VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, fence));
// Wait for the fence to signal that command buffer has finished executing // Wait for the fence to signal that command buffer has finished executing
VK_CHECK_RESULT(vkWaitForFences(logicalDevice, 1, &fence, VK_TRUE, DEFAULT_FENCE_TIMEOUT)); VK_CHECK_RESULT(vkWaitForFences(logicalDevice, 1, &fence, VK_TRUE, DEFAULT_FENCE_TIMEOUT));
vkDestroyFence(logicalDevice, fence, nullptr); vkDestroyFence(logicalDevice, fence, nullptr);
if (free) 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) * Check if an extension is supported by the (physical device)
* *