From 52211e6c40f01a545f8be6dbcab899fb43db5e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Thu, 20 Oct 2016 16:38:04 +0200 Subject: [PATCH] libs/vkd3d: Free command buffers on command allocator reset. --- libs/vkd3d/command.c | 30 +++++++++++++++++++++++++----- libs/vkd3d/vkd3d_private.h | 4 ++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 1477e7ae..2381c374 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -586,11 +586,19 @@ static void vkd3d_command_allocator_free_command_list(struct d3d12_command_alloc 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) 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) @@ -707,6 +715,7 @@ static ULONG STDMETHODCALLTYPE d3d12_command_allocator_Release(ID3D12CommandAllo } 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)); vkd3d_free(allocator); @@ -801,6 +810,13 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_allocator_Reset(ID3D12CommandAllo } 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, 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->pipeline_count = 0; + allocator->command_buffers = NULL; + allocator->command_buffers_size = 0; + allocator->command_buffer_count = 0; + allocator->current_command_list = NULL; allocator->device = device; @@ -1246,8 +1266,8 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_list_Close(ID3D12GraphicsCommandL static HRESULT STDMETHODCALLTYPE d3d12_command_list_Reset(ID3D12GraphicsCommandList *iface, 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_list *list = impl_from_ID3D12GraphicsCommandList(iface); HRESULT hr; 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)) { - 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)); return; } diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 26093ed6..b118d9e6 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -268,6 +268,10 @@ struct d3d12_command_allocator size_t pipelines_size; 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_device *device; };