VideoBackends:Vulkan: Associate descriptor pool with frame rather than command buffer
This commit is contained in:
parent
ed75a58061
commit
fba7d35f94
|
@ -93,7 +93,10 @@ bool CommandBufferManager::CreateCommandBuffers()
|
||||||
LOG_VULKAN_ERROR(res, "vkCreateSemaphore failed: ");
|
LOG_VULKAN_ERROR(res, "vkCreateSemaphore failed: ");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (VkDescriptorPool& descriptor_pool : m_descriptor_pools)
|
||||||
|
{
|
||||||
// TODO: A better way to choose the number of descriptors.
|
// TODO: A better way to choose the number of descriptors.
|
||||||
const std::array<VkDescriptorPoolSize, 5> pool_sizes{{
|
const std::array<VkDescriptorPoolSize, 5> pool_sizes{{
|
||||||
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 500000},
|
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 500000},
|
||||||
|
@ -112,7 +115,7 @@ bool CommandBufferManager::CreateCommandBuffers()
|
||||||
pool_sizes.data(),
|
pool_sizes.data(),
|
||||||
};
|
};
|
||||||
|
|
||||||
res = vkCreateDescriptorPool(device, &pool_create_info, nullptr, &resources.descriptor_pool);
|
res = vkCreateDescriptorPool(device, &pool_create_info, nullptr, &descriptor_pool);
|
||||||
if (res != VK_SUCCESS)
|
if (res != VK_SUCCESS)
|
||||||
{
|
{
|
||||||
LOG_VULKAN_ERROR(res, "vkCreateDescriptorPool failed: ");
|
LOG_VULKAN_ERROR(res, "vkCreateDescriptorPool failed: ");
|
||||||
|
@ -155,9 +158,12 @@ void CommandBufferManager::DestroyCommandBuffers()
|
||||||
|
|
||||||
if (resources.fence != VK_NULL_HANDLE)
|
if (resources.fence != VK_NULL_HANDLE)
|
||||||
vkDestroyFence(device, resources.fence, nullptr);
|
vkDestroyFence(device, resources.fence, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
if (resources.descriptor_pool != VK_NULL_HANDLE)
|
for (VkDescriptorPool descriptor_pool : m_descriptor_pools)
|
||||||
vkDestroyDescriptorPool(device, resources.descriptor_pool, nullptr);
|
{
|
||||||
|
if (descriptor_pool != VK_NULL_HANDLE)
|
||||||
|
vkDestroyDescriptorPool(device, descriptor_pool, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDestroySemaphore(device, m_present_semaphore, nullptr);
|
vkDestroySemaphore(device, m_present_semaphore, nullptr);
|
||||||
|
@ -340,6 +346,12 @@ void CommandBufferManager::SubmitCommandBuffer(bool submit_on_worker_thread,
|
||||||
}
|
}
|
||||||
cmd_buffer_index = (cmd_buffer_index + 1) % NUM_COMMAND_BUFFERS;
|
cmd_buffer_index = (cmd_buffer_index + 1) % NUM_COMMAND_BUFFERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the descriptor pool
|
||||||
|
VkResult res =
|
||||||
|
vkResetDescriptorPool(g_vulkan_context->GetDevice(), GetCurrentDescriptorPool(), 0);
|
||||||
|
if (res != VK_SUCCESS)
|
||||||
|
LOG_VULKAN_ERROR(res, "vkResetDescriptorPool failed: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to next cmdbuffer.
|
// Switch to next cmdbuffer.
|
||||||
|
@ -457,11 +469,6 @@ void CommandBufferManager::BeginCommandBuffer()
|
||||||
LOG_VULKAN_ERROR(res, "vkBeginCommandBuffer failed: ");
|
LOG_VULKAN_ERROR(res, "vkBeginCommandBuffer failed: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also can do the same for the descriptor pools
|
|
||||||
res = vkResetDescriptorPool(g_vulkan_context->GetDevice(), resources.descriptor_pool, 0);
|
|
||||||
if (res != VK_SUCCESS)
|
|
||||||
LOG_VULKAN_ERROR(res, "vkResetDescriptorPool failed: ");
|
|
||||||
|
|
||||||
// Reset upload command buffer state
|
// Reset upload command buffer state
|
||||||
resources.init_command_buffer_used = false;
|
resources.init_command_buffer_used = false;
|
||||||
resources.semaphore_used = false;
|
resources.semaphore_used = false;
|
||||||
|
|
|
@ -43,11 +43,7 @@ public:
|
||||||
const CmdBufferResources& cmd_buffer_resources = m_command_buffers[m_current_cmd_buffer];
|
const CmdBufferResources& cmd_buffer_resources = m_command_buffers[m_current_cmd_buffer];
|
||||||
return cmd_buffer_resources.command_buffers[1];
|
return cmd_buffer_resources.command_buffers[1];
|
||||||
}
|
}
|
||||||
VkDescriptorPool GetCurrentDescriptorPool() const
|
VkDescriptorPool GetCurrentDescriptorPool() const { return m_descriptor_pools[m_current_frame]; }
|
||||||
{
|
|
||||||
const CmdBufferResources& cmd_buffer_resources = m_command_buffers[m_current_cmd_buffer];
|
|
||||||
return cmd_buffer_resources.descriptor_pool;
|
|
||||||
}
|
|
||||||
// Allocates a descriptors set from the pool reserved for the current frame.
|
// Allocates a descriptors set from the pool reserved for the current frame.
|
||||||
VkDescriptorSet AllocateDescriptorSet(VkDescriptorSetLayout set_layout);
|
VkDescriptorSet AllocateDescriptorSet(VkDescriptorSetLayout set_layout);
|
||||||
|
|
||||||
|
@ -114,7 +110,6 @@ private:
|
||||||
// [0] - Init (upload) command buffer, [1] - draw command buffer
|
// [0] - Init (upload) command buffer, [1] - draw command buffer
|
||||||
VkCommandPool command_pool = VK_NULL_HANDLE;
|
VkCommandPool command_pool = VK_NULL_HANDLE;
|
||||||
std::array<VkCommandBuffer, 2> command_buffers = {};
|
std::array<VkCommandBuffer, 2> command_buffers = {};
|
||||||
VkDescriptorPool descriptor_pool = VK_NULL_HANDLE;
|
|
||||||
VkFence fence = VK_NULL_HANDLE;
|
VkFence fence = VK_NULL_HANDLE;
|
||||||
VkSemaphore semaphore = VK_NULL_HANDLE;
|
VkSemaphore semaphore = VK_NULL_HANDLE;
|
||||||
u64 fence_counter = 0;
|
u64 fence_counter = 0;
|
||||||
|
@ -133,6 +128,7 @@ private:
|
||||||
u64 m_next_fence_counter = 1;
|
u64 m_next_fence_counter = 1;
|
||||||
u64 m_completed_fence_counter = 0;
|
u64 m_completed_fence_counter = 0;
|
||||||
|
|
||||||
|
std::array<VkDescriptorPool, NUM_FRAMES_IN_FLIGHT> m_descriptor_pools;
|
||||||
std::array<CmdBufferResources, NUM_COMMAND_BUFFERS> m_command_buffers;
|
std::array<CmdBufferResources, NUM_COMMAND_BUFFERS> m_command_buffers;
|
||||||
u32 m_current_frame = 0;
|
u32 m_current_frame = 0;
|
||||||
u32 m_current_cmd_buffer = 0;
|
u32 m_current_cmd_buffer = 0;
|
||||||
|
|
Loading…
Reference in New Issue