]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/framebuffer_backend.cpp
Add support for alpha to coverage
[libs/gl.git] / source / backends / vulkan / framebuffer_backend.cpp
index 48b25f2ac456dec0e1816308cd16ac2916839804..9af8a2f7b1a7a9e52464d6d0027da801bee96700 100644 (file)
@@ -2,6 +2,7 @@
 #include "device.h"
 #include "framebuffer.h"
 #include "framebuffer_backend.h"
+#include "renderpass.h"
 #include "vulkan.h"
 
 using namespace std;
@@ -63,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));
@@ -108,15 +110,24 @@ 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;
        }
 
-       VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(self.format, false, false, false);
+       RenderPass render_pass;
+       render_pass.framebuffer = &self;
+       render_pass.update(device);
 
        VkFramebufferCreateInfo framebuffer_info = { };
        framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
-       framebuffer_info.renderPass = handle_cast<::VkRenderPass>(render_pass);
-       framebuffer_info.attachmentCount = self.format.size();
+       framebuffer_info.renderPass = handle_cast<::VkRenderPass>(render_pass.handle);
+       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;
@@ -131,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)