From b7d594349f94aedfd07a20dee8e8a2f90a0752b8 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 5 Oct 2016 15:29:12 +0200 Subject: [PATCH] libs/vkd3d: Delay destroying framebuffers until the command list is destroyed. Like render passes, these should only be destroyed after all submitted commands referring to them have completed execution. --- libs/vkd3d/command.c | 29 +++++++++++++++++++++++++++-- libs/vkd3d/vkd3d_private.h | 4 ++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 1c45f114..964d4916 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -667,6 +667,17 @@ static bool d3d12_command_list_add_render_pass(struct d3d12_command_list *list, return true; } +static bool d3d12_command_list_add_framebuffer(struct d3d12_command_list *list, VkFramebuffer framebuffer) +{ + if (!vkd3d_array_reserve((void **)&list->framebuffers, &list->framebuffers_size, + list->framebuffer_count + 1, sizeof(*list->framebuffers))) + return false; + + list->framebuffers[list->framebuffer_count++] = framebuffer; + + return true; +} + static HRESULT STDMETHODCALLTYPE d3d12_command_list_QueryInterface(ID3D12GraphicsCommandList *iface, REFIID riid, void **object) { @@ -718,6 +729,11 @@ static ULONG STDMETHODCALLTYPE d3d12_command_list_Release(ID3D12GraphicsCommandL if (list->allocator) vkd3d_command_allocator_free_command_list(list->allocator, list); + for (i = 0; i < list->framebuffer_count; ++i) + { + VK_CALL(vkDestroyFramebuffer(device->vk_device, list->framebuffers[i], NULL)); + } + for (i = 0; i < list->pass_count; ++i) { VK_CALL(vkDestroyRenderPass(device->vk_device, list->passes[i], NULL)); @@ -1253,6 +1269,13 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearRenderTargetView(ID3D12Gra return; } + if (!d3d12_command_list_add_framebuffer(list, vk_framebuffer)) + { + WARN("Failed to add framebuffer.\n"); + VK_CALL(vkDestroyFramebuffer(list->device->vk_device, vk_framebuffer, NULL)); + return; + } + begin_desc.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; begin_desc.pNext = NULL; begin_desc.renderPass = vk_render_pass; @@ -1269,8 +1292,6 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearRenderTargetView(ID3D12Gra VK_CALL(vkCmdBeginRenderPass(list->vk_command_buffer, &begin_desc, VK_SUBPASS_CONTENTS_INLINE)); VK_CALL(vkCmdEndRenderPass(list->vk_command_buffer)); } - - VK_CALL(vkDestroyFramebuffer(list->device->vk_device, vk_framebuffer, NULL)); } static void STDMETHODCALLTYPE d3d12_command_list_ClearUnorderedAccessViewFloat(ID3D12GraphicsCommandList *iface, @@ -1441,6 +1462,10 @@ static HRESULT d3d12_command_list_init(struct d3d12_command_list *list, struct d list->passes_size = 0; list->pass_count = 0; + list->framebuffers = NULL; + list->framebuffers_size = 0; + list->framebuffer_count = 0; + if (initial_pipeline_state) FIXME("Ignoring initial pipeline state %p.\n", initial_pipeline_state); diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index fbbec1ea..03291d52 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -210,6 +210,10 @@ struct d3d12_command_list size_t passes_size; size_t pass_count; + VkFramebuffer *framebuffers; + size_t framebuffers_size; + size_t framebuffer_count; + struct d3d12_command_allocator *allocator; struct d3d12_device *device; };