From 4bb8fd5ac5c07e8756ae097e7f5d7f34697bc914 Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Tue, 1 Oct 2024 17:54:43 -0700 Subject: fix command buffer release issue --- src/vulkan_helper.cpp | 66 ++++++++++----------------------------------------- 1 file changed, 12 insertions(+), 54 deletions(-) (limited to 'src/vulkan_helper.cpp') diff --git a/src/vulkan_helper.cpp b/src/vulkan_helper.cpp index f39d867..567d414 100644 --- a/src/vulkan_helper.cpp +++ b/src/vulkan_helper.cpp @@ -278,69 +278,27 @@ CommandBuffer::CommandBuffer(VkDevice device, VK_NULL_HANDLE, &fence)); spdlog::debug("Created command buffer: 0x{:x}", (uint64_t)buffer); + spdlog::debug("Created fence: 0x{:x}", (uint64_t)fence); } -AsyncCommandBuffer::AsyncCommandBuffer(VkDevice device, - uint32_t queue_family_index, - VkQueue queue) - : device(device), queue(queue) -{ - VkCommandPoolCreateInfo pool_info = { - .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, - .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, - .queueFamilyIndex = queue_family_index, // TODO: query capabilities to find a proper queue index - }; - CHECK_VULKAN(vkCreateCommandPool( - device, - &pool_info, - VK_NULL_HANDLE, - &this->pool)); - - VkCommandBufferAllocateInfo buffer_info = { - .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, - .commandPool = this->pool, - .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, - .commandBufferCount = 1, - }; - CHECK_VULKAN(vkAllocateCommandBuffers( - device, - &buffer_info, - &buffer)); - - VkFenceCreateInfo fence_info = { - .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, - }; - CHECK_VULKAN(vkCreateFence( - device, - &fence_info, - VK_NULL_HANDLE, - &fence)); - spdlog::debug("Created async command buffer: 0x{:x}", (uint64_t)buffer); -} - -void AsyncCommandBuffer::destroy() { - vkDestroyFence(device, fence, VK_NULL_HANDLE); - vkFreeCommandBuffers(device, pool, 1, &buffer); - vkDestroyCommandPool(device, pool, VK_NULL_HANDLE); - spdlog::debug("Destroyed async command buffer: 0x{:x}", (uint64_t)buffer); -} - - void CommandBuffer::destroy() { - vkDestroyFence(device, fence, VK_NULL_HANDLE); - vkFreeCommandBuffers(device, pool, 1, &buffer); - vkDestroyCommandPool(device, pool, VK_NULL_HANDLE); - spdlog::debug("Destroyed command buffer: 0x{:x}", (uint64_t)buffer); + if (fence != VK_NULL_HANDLE) { + vkDestroyFence(device, fence, VK_NULL_HANDLE); + vkFreeCommandBuffers(device, pool, 1, &buffer); + vkDestroyCommandPool(device, pool, VK_NULL_HANDLE); + + spdlog::debug("Destroyed fence: 0x{:x}", (uint64_t)fence); + spdlog::debug("Destroyed command buffer: 0x{:x}", (uint64_t)buffer); + fence = VK_NULL_HANDLE; + buffer = VK_NULL_HANDLE; + pool = VK_NULL_HANDLE; + } } CommandBuffer Device::create_command_buffer() { return CommandBuffer(device, main_queue_family_index, graphics_queue); } -AsyncCommandBuffer Device::create_async_command_buffer() { - return AsyncCommandBuffer(device, main_queue_family_index, graphics_queue); -} - void CommandBuffer::begin(VkCommandBufferUsageFlags flags) { CHECK_VULKAN(vkResetFences(device, 1, &fence)); CHECK_VULKAN(vkResetCommandPool(device, pool, 0u)); -- cgit v1.2.3-70-g09d2