]> git.tdb.fi Git - libs/gl.git/commitdiff
Defer transfer and barriers until the entire render pass is recorded
authorMikko Rasa <tdb@tdb.fi>
Tue, 14 Dec 2021 12:57:34 +0000 (14:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 14 Dec 2021 12:57:34 +0000 (14:57 +0200)
This ensures that all resources needed by the render pass are prepared
before executing the pass.

source/backends/vulkan/commands_backend.cpp
source/backends/vulkan/commands_backend.h

index 137a817deac20764fa860e2c338eb172b37e1ffb..b7a342defb5ab741eb16f3b9c3bc06af6f8d7555 100644 (file)
@@ -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<n_attachments); ++i)
                if(dynamic_cast<const SwapChainTexture *>(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<const VkRenderPassBeginInfo *>(pass_begin_info.data());
        vk.CmdBeginRenderPass(primary_buffer, begin_info, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
        vk.CmdExecuteCommands(primary_buffer, 1, &pass_buffer);
index f96a441c434c5375cc8d0af4df25232ee39a128f..3f2c3be9bbf243029028f519360c4e5523f4b642 100644 (file)
@@ -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<char> pass_begin_info;
 
        VulkanCommands();