summaryrefslogtreecommitdiff
path: root/src/vulkan_helper.cpp
diff options
context:
space:
mode:
authorChuyan Zhang <chuyan@ucsb.edu>2024-10-01 17:54:43 -0700
committerChuyan Zhang <chuyan@ucsb.edu>2024-10-01 17:54:43 -0700
commit4bb8fd5ac5c07e8756ae097e7f5d7f34697bc914 (patch)
tree61c452cb89a76cdf368021ec0db5f6e8f5ca0bd8 /src/vulkan_helper.cpp
parent6185c081c1a6ec13b54eab6a12ff72814cf3addb (diff)
downloadiris-4bb8fd5ac5c07e8756ae097e7f5d7f34697bc914.tar.gz
iris-4bb8fd5ac5c07e8756ae097e7f5d7f34697bc914.zip
fix command buffer release issue
Diffstat (limited to 'src/vulkan_helper.cpp')
-rw-r--r--src/vulkan_helper.cpp66
1 files changed, 12 insertions, 54 deletions
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));