Vulkan: Allow command buffer level specification on allocation rather than construction.

Free unused descriptor sets properly.
This commit is contained in:
Dr. Chat 2017-05-13 10:03:59 -05:00
parent 0c1a46d708
commit 7fdfb90e3d
2 changed files with 17 additions and 10 deletions

View File

@ -20,9 +20,8 @@ namespace vulkan {
using xe::ui::vulkan::CheckResult; using xe::ui::vulkan::CheckResult;
CommandBufferPool::CommandBufferPool(VkDevice device, CommandBufferPool::CommandBufferPool(VkDevice device,
uint32_t queue_family_index, uint32_t queue_family_index)
VkCommandBufferLevel level) : BaseFencedPool(device) {
: BaseFencedPool(device), level_(level) {
// Create the pool used for allocating buffers. // Create the pool used for allocating buffers.
// They are marked as transient (short-lived) and cycled frequently. // They are marked as transient (short-lived) and cycled frequently.
VkCommandPoolCreateInfo cmd_pool_info; 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.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
command_buffer_info.pNext = nullptr; command_buffer_info.pNext = nullptr;
command_buffer_info.commandPool = command_pool_; 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; command_buffer_info.commandBufferCount = kDefaultCount;
VkCommandBuffer command_buffers[kDefaultCount]; VkCommandBuffer command_buffers[kDefaultCount];
err = err =
@ -64,7 +63,8 @@ VkCommandBuffer CommandBufferPool::AllocateEntry(void* data) {
command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; command_buffer_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
command_buffer_info.pNext = nullptr; command_buffer_info.pNext = nullptr;
command_buffer_info.commandPool = command_pool_; command_buffer_info.commandPool = command_pool_;
command_buffer_info.level = level_; command_buffer_info.level =
VkCommandBufferLevel(reinterpret_cast<uintptr_t>(data));
command_buffer_info.commandBufferCount = 1; command_buffer_info.commandBufferCount = 1;
VkCommandBuffer command_buffer; VkCommandBuffer command_buffer;
auto err = auto err =
@ -115,7 +115,9 @@ VkDescriptorSet DescriptorPool::AllocateEntry(void* data) {
return descriptor_set; return descriptor_set;
} }
void DescriptorPool::FreeEntry(VkDescriptorSet handle) {} void DescriptorPool::FreeEntry(VkDescriptorSet handle) {
vkFreeDescriptorSets(device_, descriptor_pool_, 1, &handle);
}
} // namespace vulkan } // namespace vulkan
} // namespace ui } // namespace ui

View File

@ -211,6 +211,10 @@ class BaseFencedPool {
entry = new Entry(); entry = new Entry();
entry->data = data; entry->data = data;
entry->handle = static_cast<T*>(this)->AllocateEntry(data); entry->handle = static_cast<T*>(this)->AllocateEntry(data);
if (!entry->handle) {
delete entry;
return nullptr;
}
} }
entry->next = nullptr; entry->next = nullptr;
if (!open_batch_->entry_list_head) { if (!open_batch_->entry_list_head) {
@ -281,11 +285,13 @@ class CommandBufferPool
public: public:
typedef BaseFencedPool<CommandBufferPool, VkCommandBuffer> Base; typedef BaseFencedPool<CommandBufferPool, VkCommandBuffer> Base;
CommandBufferPool(VkDevice device, uint32_t queue_family_index, CommandBufferPool(VkDevice device, uint32_t queue_family_index);
VkCommandBufferLevel level);
~CommandBufferPool() override; ~CommandBufferPool() override;
VkCommandBuffer AcquireEntry() { return Base::AcquireEntry(nullptr); } VkCommandBuffer AcquireEntry(
VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
return Base::AcquireEntry(reinterpret_cast<void*>(level));
}
protected: protected:
friend class BaseFencedPool<CommandBufferPool, VkCommandBuffer>; friend class BaseFencedPool<CommandBufferPool, VkCommandBuffer>;
@ -293,7 +299,6 @@ class CommandBufferPool
void FreeEntry(VkCommandBuffer handle); void FreeEntry(VkCommandBuffer handle);
VkCommandPool command_pool_ = nullptr; VkCommandPool command_pool_ = nullptr;
VkCommandBufferLevel level_ = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
}; };
class DescriptorPool : public BaseFencedPool<DescriptorPool, VkDescriptorSet> { class DescriptorPool : public BaseFencedPool<DescriptorPool, VkDescriptorSet> {