]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/pipelinecache.cpp
Only do layout transitions in render pass for swapchain images
[libs/gl.git] / source / backends / vulkan / pipelinecache.cpp
index e24c72dbba4944dc6f3180b61af8557f6ac0a8ec..425be40ab776478ecab88df4ed636c9f09fef960 100644 (file)
@@ -44,11 +44,11 @@ PipelineCache::~PipelineCache()
        vk.DestroyDescriptorPool(descriptor_pool);
 }
 
-VkRenderPass PipelineCache::get_render_pass(const FrameFormat &format, bool is_cleared, bool to_present)
+VkRenderPass PipelineCache::get_render_pass(const FrameFormat &format, bool clear, bool discard, bool to_present)
 {
        const VulkanFunctions &vk = device.get_functions();
 
-       uint64_t key = hash<64>(static_cast<uint8_t>(is_cleared | (to_present*2)));
+       uint64_t key = hash<64>(static_cast<uint8_t>(clear | (discard*2) | (to_present*4)));
        for(FrameAttachment a: format)
                key = hash_update<64>(key, a);
 
@@ -67,26 +67,28 @@ VkRenderPass PipelineCache::get_render_pass(const FrameFormat &format, bool is_c
        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 = (is_cleared ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD);
+               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 = (is_cleared ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
-               attachments[i].finalLayout = (to_present ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
+               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;