]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/framebuffer_backend.cpp
Implement multisample resolve for Vulkan
[libs/gl.git] / source / backends / vulkan / framebuffer_backend.cpp
index 5db8c356faff5072d5d612aa94c01a64461070f1..9af8a2f7b1a7a9e52464d6d0027da801bee96700 100644 (file)
@@ -64,8 +64,9 @@ void VulkanFramebuffer::update(unsigned mask) const
        if(handle)
                device.get_destroy_queue().destroy(handle);
 
-       VkImageView vk_attachments[FrameFormat::MAX_ATTACHMENTS] = { };
+       VkImageView vk_attachments[FrameFormat::MAX_ATTACHMENTS*2] = { };
        unsigned i = 0;
+       bool any_resolve = false;
        for(const Framebuffer::Attachment &a: self.attachments)
        {
                bool use_tex_view = (a.tex->view_type==VK_IMAGE_VIEW_TYPE_2D || (a.tex->view_type==VK_IMAGE_VIEW_TYPE_2D_ARRAY && a.layer<0));
@@ -109,6 +110,13 @@ void VulkanFramebuffer::update(unsigned mask) const
                else
                        throw logic_error("unexpected framebuffer configuration");
 
+               if(a.resolve)
+               {
+                       a.resolve->refresh_mip_views();
+                       vk_attachments[self.format.size()+i] = a.resolve->mip_view_handles[0];
+                       any_resolve = true;
+               }
+
                ++i;
        }
 
@@ -119,7 +127,7 @@ void VulkanFramebuffer::update(unsigned mask) const
        VkFramebufferCreateInfo framebuffer_info = { };
        framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
        framebuffer_info.renderPass = handle_cast<::VkRenderPass>(render_pass.handle);
-       framebuffer_info.attachmentCount = self.format.size();
+       framebuffer_info.attachmentCount = self.format.size()*(1+any_resolve);
        framebuffer_info.pAttachments = handle_cast<::VkImageView *>(vk_attachments);
        framebuffer_info.width = self.width;
        framebuffer_info.height = self.height;
@@ -134,7 +142,11 @@ void VulkanFramebuffer::update(unsigned mask) const
 void VulkanFramebuffer::prepare_image_layouts(bool discard) const
 {
        for(const Framebuffer::Attachment &a: static_cast<const Framebuffer *>(this)->attachments)
+       {
                a.tex->change_layout(a.level, get_vulkan_attachment_layout(get_components(a.tex->get_format())), (discard && a.layer<0));
+               if(a.resolve)
+                       a.resolve->change_layout(a.level, get_vulkan_attachment_layout(get_components(a.resolve->get_format())), discard);
+       }
 }
 
 void VulkanFramebuffer::set_debug_name(const string &name)