From edc150206f9762facf37b419705ddb8cf21f4e4c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 14 Dec 2021 14:57:34 +0200 Subject: [PATCH] Defer transfer and barriers until the entire render pass is recorded This ensures that all resources needed by the render pass are prepared before executing the pass. --- source/backends/vulkan/commands_backend.cpp | 19 +++++++++++-------- source/backends/vulkan/commands_backend.h | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/source/backends/vulkan/commands_backend.cpp b/source/backends/vulkan/commands_backend.cpp index 137a817d..b7a342de 100644 --- a/source/backends/vulkan/commands_backend.cpp +++ b/source/backends/vulkan/commands_backend.cpp @@ -90,22 +90,17 @@ void VulkanCommands::begin_render_pass(bool clear, const ClearValue *clear_value if(!primary_buffer) begin_buffer(0); - Synchronizer &sync = device.get_synchronizer(); - sync.reset(); - fb_is_swapchain = false; unsigned n_attachments = framebuffer->get_format().size(); for(unsigned i=0; (!fb_is_swapchain && i(framebuffer->get_attachment(i))) fb_is_swapchain = true; - if(!fb_is_swapchain) - framebuffer->prepare_image_layouts(clear && !viewport); - VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(framebuffer->get_format(), clear, (!clear_values && !viewport), fb_is_swapchain); - framebuffer->refresh(); + discard_fb_contents = (clear && !viewport); - sync.barrier(primary_buffer); + framebuffer->refresh(); + VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(framebuffer->get_format(), clear, (!clear_values && !viewport), fb_is_swapchain); begin_buffer(render_pass); StructureBuilder sb(pass_begin_info, 2); @@ -159,6 +154,14 @@ void VulkanCommands::end_render_pass() vk.EndCommandBuffer(pass_buffer); + device.get_transfer_queue().dispatch_transfers(primary_buffer); + + Synchronizer &sync = device.get_synchronizer(); + sync.reset(); + if(!fb_is_swapchain) + framebuffer->prepare_image_layouts(discard_fb_contents); + sync.barrier(primary_buffer); + const VkRenderPassBeginInfo &begin_info = *reinterpret_cast(pass_begin_info.data()); vk.CmdBeginRenderPass(primary_buffer, begin_info, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); vk.CmdExecuteCommands(primary_buffer, 1, &pass_buffer); diff --git a/source/backends/vulkan/commands_backend.h b/source/backends/vulkan/commands_backend.h index f96a441c..3f2c3be9 100644 --- a/source/backends/vulkan/commands_backend.h +++ b/source/backends/vulkan/commands_backend.h @@ -50,6 +50,7 @@ protected: const Framebuffer *framebuffer = 0; const Rect *viewport = 0; bool fb_is_swapchain = false; + bool discard_fb_contents = false; std::vector pass_begin_info; VulkanCommands(); -- 2.45.2