libs/vkd3d: Free command buffers on command allocator reset.

This commit is contained in:
Józef Kucia 2016-10-20 16:38:04 +02:00
parent 278cb0103c
commit 52211e6c40
2 changed files with 29 additions and 5 deletions

View File

@ -586,11 +586,19 @@ static void vkd3d_command_allocator_free_command_list(struct d3d12_command_alloc
TRACE("allocator %p, list %p.\n", allocator, list); TRACE("allocator %p, list %p.\n", allocator, list);
VK_CALL(vkFreeCommandBuffers(device->vk_device, allocator->vk_command_pool,
1, &list->vk_command_buffer));
if (allocator->current_command_list == list) if (allocator->current_command_list == list)
allocator->current_command_list = NULL; allocator->current_command_list = NULL;
if (!vkd3d_array_reserve((void **)&allocator->command_buffers, &allocator->command_buffers_size,
allocator->command_buffer_count + 1, sizeof(*allocator->command_buffers)))
{
WARN("Failed to add command buffer.\n");
VK_CALL(vkFreeCommandBuffers(device->vk_device, allocator->vk_command_pool,
1, &list->vk_command_buffer));
return;
}
allocator->command_buffers[allocator->command_buffer_count++] = list->vk_command_buffer;
} }
static bool d3d12_command_allocator_add_render_pass(struct d3d12_command_allocator *allocator, VkRenderPass pass) static bool d3d12_command_allocator_add_render_pass(struct d3d12_command_allocator *allocator, VkRenderPass pass)
@ -707,6 +715,7 @@ static ULONG STDMETHODCALLTYPE d3d12_command_allocator_Release(ID3D12CommandAllo
} }
vkd3d_free(allocator->passes); vkd3d_free(allocator->passes);
/* All command buffers are implicitly freed when a pool is destroyed. */
VK_CALL(vkDestroyCommandPool(device->vk_device, allocator->vk_command_pool, NULL)); VK_CALL(vkDestroyCommandPool(device->vk_device, allocator->vk_command_pool, NULL));
vkd3d_free(allocator); vkd3d_free(allocator);
@ -801,6 +810,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_allocator_Reset(ID3D12CommandAllo
} }
allocator->pass_count = 0; allocator->pass_count = 0;
if (allocator->command_buffer_count)
{
VK_CALL(vkFreeCommandBuffers(device->vk_device, allocator->vk_command_pool,
allocator->command_buffer_count, allocator->command_buffers));
allocator->command_buffer_count = 0;
}
if ((vr = VK_CALL(vkResetCommandPool(device->vk_device, allocator->vk_command_pool, if ((vr = VK_CALL(vkResetCommandPool(device->vk_device, allocator->vk_command_pool,
VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT)))) VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT))))
{ {
@ -884,6 +900,10 @@ static HRESULT d3d12_command_allocator_init(struct d3d12_command_allocator *allo
allocator->pipelines_size = 0; allocator->pipelines_size = 0;
allocator->pipeline_count = 0; allocator->pipeline_count = 0;
allocator->command_buffers = NULL;
allocator->command_buffers_size = 0;
allocator->command_buffer_count = 0;
allocator->current_command_list = NULL; allocator->current_command_list = NULL;
allocator->device = device; allocator->device = device;
@ -1246,8 +1266,8 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_list_Close(ID3D12GraphicsCommandL
static HRESULT STDMETHODCALLTYPE d3d12_command_list_Reset(ID3D12GraphicsCommandList *iface, static HRESULT STDMETHODCALLTYPE d3d12_command_list_Reset(ID3D12GraphicsCommandList *iface,
ID3D12CommandAllocator *allocator, ID3D12PipelineState *initial_state) ID3D12CommandAllocator *allocator, ID3D12PipelineState *initial_state)
{ {
struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList(iface);
struct d3d12_command_allocator *allocator_impl = unsafe_impl_from_ID3D12CommandAllocator(allocator); struct d3d12_command_allocator *allocator_impl = unsafe_impl_from_ID3D12CommandAllocator(allocator);
struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList(iface);
HRESULT hr; HRESULT hr;
TRACE("iface %p, allocator %p, initial_state %p.\n", TRACE("iface %p, allocator %p, initial_state %p.\n",
@ -2171,7 +2191,7 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearRenderTargetView(ID3D12Gra
if (!d3d12_command_allocator_add_render_pass(list->allocator, vk_render_pass)) if (!d3d12_command_allocator_add_render_pass(list->allocator, vk_render_pass))
{ {
WARN("Failed to add render pass,\n"); WARN("Failed to add render pass.\n");
VK_CALL(vkDestroyRenderPass(list->device->vk_device, vk_render_pass, NULL)); VK_CALL(vkDestroyRenderPass(list->device->vk_device, vk_render_pass, NULL));
return; return;
} }

View File

@ -268,6 +268,10 @@ struct d3d12_command_allocator
size_t pipelines_size; size_t pipelines_size;
size_t pipeline_count; size_t pipeline_count;
VkCommandBuffer *command_buffers;
size_t command_buffers_size;
size_t command_buffer_count;
struct d3d12_command_list *current_command_list; struct d3d12_command_list *current_command_list;
struct d3d12_device *device; struct d3d12_device *device;
}; };