X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Fframebuffer_backend.cpp;h=9395635476025473e182653becb57316737006ed;hb=627d68b024f0d2fed4a03f0d9d3bb4b78358d6f3;hp=5db8c356faff5072d5d612aa94c01a64461070f1;hpb=1b4d387b74b2108f3926796d8115bee134fbf7f1;p=libs%2Fgl.git diff --git a/source/backends/vulkan/framebuffer_backend.cpp b/source/backends/vulkan/framebuffer_backend.cpp index 5db8c356..93956354 100644 --- a/source/backends/vulkan/framebuffer_backend.cpp +++ b/source/backends/vulkan/framebuffer_backend.cpp @@ -3,6 +3,7 @@ #include "framebuffer.h" #include "framebuffer_backend.h" #include "renderpass.h" +#include "swapchaintexture.h" #include "vulkan.h" using namespace std; @@ -32,7 +33,7 @@ VulkanFramebuffer::~VulkanFramebuffer() dq.destroy(h); } -bool VulkanFramebuffer::is_format_supported(const FrameFormat &fmt) +bool VulkanFramebuffer::is_format_supported(const FrameFormat &fmt) const { const VulkanFunctions &vk = device.get_functions(); for(FrameAttachment a: fmt) @@ -53,6 +54,13 @@ bool VulkanFramebuffer::is_format_supported(const FrameFormat &fmt) return true; } +bool VulkanFramebuffer::is_presentable() const +{ + const Framebuffer &self = *static_cast(this); + return std::any_of(self.attachments.begin(), self.attachments.end(), + [](const Framebuffer::Attachment &a){ return dynamic_cast(a.tex); }); +} + void VulkanFramebuffer::update(unsigned mask) const { const Framebuffer &self = *static_cast(this); @@ -64,8 +72,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,17 +118,25 @@ 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; } RenderPass render_pass; render_pass.framebuffer = &self; + render_pass.to_present = is_presentable(); render_pass.update(device); 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; @@ -131,10 +148,14 @@ void VulkanFramebuffer::update(unsigned mask) const set_vulkan_object_name(); } -void VulkanFramebuffer::prepare_image_layouts(bool discard) const +void VulkanFramebuffer::synchronize_resources(bool discard) const { for(const Framebuffer::Attachment &a: static_cast(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)