From 7fdfb90e3dbb456ff9e1d4473ecfb6e863e769ac Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Sat, 13 May 2017 10:03:59 -0500 Subject: [PATCH] Vulkan: Allow command buffer level specification on allocation rather than construction. Free unused descriptor sets properly. --- src/xenia/ui/vulkan/fenced_pools.cc | 14 ++++++++------ src/xenia/ui/vulkan/fenced_pools.h | 13 +++++++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/xenia/ui/vulkan/fenced_pools.cc b/src/xenia/ui/vulkan/fenced_pools.cc index 8f4ecaee7..f7aeffff3 100644 --- a/src/xenia/ui/vulkan/fenced_pools.cc +++ b/src/xenia/ui/vulkan/fenced_pools.cc @@ -20,9 +20,8 @@ namespace vulkan { using xe::ui::vulkan::CheckResult; CommandBufferPool::CommandBufferPool(VkDevice device, - uint32_t queue_family_index, - VkCommandBufferLevel level) - : BaseFencedPool(device), level_(level) { + uint32_t queue_family_index) + : BaseFencedPool(device) { // Create the pool used for allocating buffers. // They are marked as transient (short-lived) and cycled frequently. VkCommandPoolCreateInfo cmd_pool_info; @@ -41,7 +40,7 @@ CommandBufferPool::CommandBufferPool(VkDevice device, command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; command_buffer_info.pNext = nullptr; command_buffer_info.commandPool = command_pool_; - command_buffer_info.level = level; + command_buffer_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; command_buffer_info.commandBufferCount = kDefaultCount; VkCommandBuffer command_buffers[kDefaultCount]; err = @@ -64,7 +63,8 @@ VkCommandBuffer CommandBufferPool::AllocateEntry(void* data) { command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; command_buffer_info.pNext = nullptr; command_buffer_info.commandPool = command_pool_; - command_buffer_info.level = level_; + command_buffer_info.level = + VkCommandBufferLevel(reinterpret_cast(data)); command_buffer_info.commandBufferCount = 1; VkCommandBuffer command_buffer; auto err = @@ -115,7 +115,9 @@ VkDescriptorSet DescriptorPool::AllocateEntry(void* data) { return descriptor_set; } -void DescriptorPool::FreeEntry(VkDescriptorSet handle) {} +void DescriptorPool::FreeEntry(VkDescriptorSet handle) { + vkFreeDescriptorSets(device_, descriptor_pool_, 1, &handle); +} } // namespace vulkan } // namespace ui diff --git a/src/xenia/ui/vulkan/fenced_pools.h b/src/xenia/ui/vulkan/fenced_pools.h index 7413086a2..3c45bd792 100644 --- a/src/xenia/ui/vulkan/fenced_pools.h +++ b/src/xenia/ui/vulkan/fenced_pools.h @@ -211,6 +211,10 @@ class BaseFencedPool { entry = new Entry(); entry->data = data; entry->handle = static_cast(this)->AllocateEntry(data); + if (!entry->handle) { + delete entry; + return nullptr; + } } entry->next = nullptr; if (!open_batch_->entry_list_head) { @@ -281,11 +285,13 @@ class CommandBufferPool public: typedef BaseFencedPool Base; - CommandBufferPool(VkDevice device, uint32_t queue_family_index, - VkCommandBufferLevel level); + CommandBufferPool(VkDevice device, uint32_t queue_family_index); ~CommandBufferPool() override; - VkCommandBuffer AcquireEntry() { return Base::AcquireEntry(nullptr); } + VkCommandBuffer AcquireEntry( + VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY) { + return Base::AcquireEntry(reinterpret_cast(level)); + } protected: friend class BaseFencedPool; @@ -293,7 +299,6 @@ class CommandBufferPool void FreeEntry(VkCommandBuffer handle); VkCommandPool command_pool_ = nullptr; - VkCommandBufferLevel level_ = VK_COMMAND_BUFFER_LEVEL_PRIMARY; }; class DescriptorPool : public BaseFencedPool {