src/core/VulkanDevice.cpp
void VulkanDevice::flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, VkCommandPool pool, bool free) {
    if (commandBuffer == VK_NULL_HANDLE) {
        return;
    }

    if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) throw std::runtime_error("Failed to end command buffer");

    VkSubmitInfo submitInfo = Populate::submitInfo();
    submitInfo.commandBufferCount = 1;
    submitInfo.pCommandBuffers = &commandBuffer;
    // Create fence to ensure that the command buffer has finished executing
    VkFenceCreateInfo fenceInfo = Populate::fenceCreateInfo(0);
    VkFence fence;
    if (vkCreateFence(logicalDevice, &fenceInfo, nullptr, &fence) != VK_SUCCESS)
        throw std::runtime_error("Failed to create fence");
    // Submit to the queue
    if (vkQueueSubmit(queue, 1, &submitInfo, fence) != VK_SUCCESS)
        throw std::runtime_error("Failed to submit to queue");
    // Wait for the fence to signal that command buffer has finished executing
    if (vkWaitForFences(logicalDevice, 1, &fence, VK_TRUE, UINT64_MAX) != VK_SUCCESS)
        throw std::runtime_error("Failed to wait for fence");
    vkDestroyFence(logicalDevice, fence, nullptr);
    if (free) {
        vkFreeCommandBuffers(logicalDevice, pool, 1, &commandBuffer);
    }
}
/**
* 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 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
*/
Finish command buffer recording and submit it to a queue
Finish command buffer recording and submit it to a queue
void VulkanDevice::flushCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue, VkCommandPool pool, bool free) {
    if (commandBuffer == VK_NULL_HANDLE) {
        return;
    }
    if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) throw std::runtime_error("Failed to end command buffer");
    VkSubmitInfo submitInfo = Populate::submitInfo();
    submitInfo.commandBufferCount = 1;
    submitInfo.pCommandBuffers = &commandBuffer;
    VkFenceCreateInfo fenceInfo = Populate::fenceCreateInfo(0);
    VkFence fence;
    if (vkCreateFence(logicalDevice, &fenceInfo, nullptr, &fence) != VK_SUCCESS)
        throw std::runtime_error("Failed to create fence");
    if (vkQueueSubmit(queue, 1, &submitInfo, fence) != VK_SUCCESS)
        throw std::runtime_error("Failed to submit to queue");
    if (vkWaitForFences(logicalDevice, 1, &fence, VK_TRUE, UINT64_MAX) != VK_SUCCESS)
        throw std::runtime_error("Failed to wait for fence");
    vkDestroyFence(logicalDevice, fence, nullptr);
    if (free) {
        vkFreeCommandBuffers(logicalDevice, pool, 1, &commandBuffer);
    }
}
void VulkanDevice :: flushCommandBuffer ( VkCommandBuffer commandBuffer , VkQueue queue , VkCommandPool pool , bool free ) { if ( commandBuffer == VK_NULL_HANDLE ) { return ; } if ( vkEndCommandBuffer ( commandBuffer ) != VK_SUCCESS ) throw std :: runtime_error ( " " ) ; VkSubmitInfo submitInfo = Populate :: submitInfo ( ) ; submitInfo . commandBufferCount = 1 ; submitInfo . pCommandBuffers = & commandBuffer ; VkFenceCreateInfo fenceInfo = Populate :: fenceCreateInfo ( 0 ) ; VkFence fence ; if ( vkCreateFence ( logicalDevice , & fenceInfo , nullptr , & fence ) != VK_SUCCESS ) throw std :: runtime_error ( " " ) ; if ( vkQueueSubmit ( queue , 1 , & submitInfo , fence ) != VK_SUCCESS ) throw std :: runtime_error ( " " ) ; if ( vkWaitForFences ( logicalDevice , 1 , & fence , VK_TRUE , UINT64_MAX ) != VK_SUCCESS ) throw std :: runtime_error ( " " ) ; vkDestroyFence ( logicalDevice , fence , nullptr ) ; if ( free ) { vkFreeCommandBuffers ( logicalDevice , pool , 1 , & commandBuffer ) ; } }
Finish command buffer recording and submit it to a queue
Finish command buffer recording and submit it to a queue
// Create fence to ensure that the command buffer has finished executing // Submit to the queue // Wait for the fence to signal that command buffer has finished executing