]> git.tdb.fi Git - libs/gl.git/commitdiff
Only do layout transitions in render pass for swapchain images
authorMikko Rasa <tdb@tdb.fi>
Sun, 21 Nov 2021 12:41:29 +0000 (14:41 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 21 Nov 2021 23:03:09 +0000 (01:03 +0200)
Transitions for other images will be handles through Synchronizer.

source/backends/vulkan/pipelinecache.cpp
source/backends/vulkan/pixelformat_backend.cpp
source/backends/vulkan/pixelformat_backend.h

index 22356c7388248937179196b93cb5e55211f20567..425be40ab776478ecab88df4ed636c9f09fef960 100644 (file)
@@ -62,32 +62,33 @@ VkRenderPass PipelineCache::get_render_pass(const FrameFormat &format, bool clea
        depth_stencil_ref.attachment = VK_ATTACHMENT_UNUSED;
 
        VkSampleCountFlagBits vk_samples = static_cast<VkSampleCountFlagBits>(get_vulkan_samples(format.get_samples()));
-       VkImageLayout default_layout = (to_present ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
 
        unsigned i = 0;
        unsigned color_count = 0;
        for(FrameAttachment a: format)
        {
+               VkImageLayout subpass_layout = static_cast<VkImageLayout>(get_vulkan_attachment_layout(get_components(get_attachment_pixelformat(a))));
+               VkImageLayout external_layout = (to_present ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR : subpass_layout);
+
                attachments[i].format = static_cast<VkFormat>(get_vulkan_pixelformat(get_attachment_pixelformat(a)));
                attachments[i].samples = vk_samples;
                attachments[i].loadOp = (clear ? discard ? VK_ATTACHMENT_LOAD_OP_DONT_CARE : VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD);
                attachments[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
                attachments[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
                attachments[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
-               attachments[i].initialLayout = (clear ? VK_IMAGE_LAYOUT_UNDEFINED : default_layout);
-               attachments[i].finalLayout = default_layout;
+               attachments[i].initialLayout = (clear ? VK_IMAGE_LAYOUT_UNDEFINED : external_layout);
+               attachments[i].finalLayout = external_layout;
 
-               unsigned attach_pt = get_attach_point(a);
-               if(attach_pt==get_attach_point(COLOR_ATTACHMENT))
+               if(subpass_layout==VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
                {
                        color_refs[color_count].attachment = i;
-                       color_refs[color_count].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+                       color_refs[color_count].layout = subpass_layout;
                        ++color_count;
                }
-               else if(attach_pt==get_attach_point(DEPTH_ATTACHMENT))
+               else
                {
                        depth_stencil_ref.attachment = i;
-                       depth_stencil_ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+                       depth_stencil_ref.layout = subpass_layout;
                }
 
                ++i;
index 13df7ee8692fe871c3843921ea780d1c0cb6bdf6..1da1435705c6dad4f55819a2f08577cbe7819fe3 100644 (file)
@@ -74,6 +74,16 @@ unsigned get_vulkan_aspect(PixelComponents comp)
        }
 }
 
+unsigned get_vulkan_attachment_layout(PixelComponents comp)
+{
+       switch(comp)
+       {
+       case DEPTH_COMPONENT:
+       case STENCIL_INDEX: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+       default: return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+       }
+}
+
 PixelFormat pixelformat_from_vulkan(unsigned vkf)
 {
        switch(vkf)
index 8641824e1520a1a9804506fc5bd58e1b07d2d80f..1cfc013393dc202937de73cdc39244afbc14ecf0 100644 (file)
@@ -10,6 +10,7 @@ namespace GL {
 
 unsigned get_vulkan_pixelformat(PixelFormat);
 unsigned get_vulkan_aspect(PixelComponents);
+unsigned get_vulkan_attachment_layout(PixelComponents);
 PixelFormat pixelformat_from_vulkan(unsigned);
 const unsigned *get_vulkan_swizzle(ComponentSwizzle);