1 #include <msp/strings/format.h>
3 #include "framebuffer.h"
4 #include "framebuffer_backend.h"
12 VulkanFramebuffer::VulkanFramebuffer(bool):
13 device(Device::get_current())
16 VulkanFramebuffer::VulkanFramebuffer(VulkanFramebuffer &&other):
19 debug_name(move(other.debug_name))
24 VulkanFramebuffer::~VulkanFramebuffer()
27 device.get_destroy_queue().destroy(handle);
30 bool VulkanFramebuffer::is_format_supported(const FrameFormat &fmt)
32 const VulkanFunctions &vk = device.get_functions();
33 for(FrameAttachment a: fmt)
35 PixelFormat pf = get_attachment_pixelformat(a);
36 PixelComponents comp = get_components(pf);
37 VkFormatProperties props;
38 vk.GetPhysicalDeviceFormatProperties(static_cast<VkFormat>(get_vulkan_pixelformat(pf)), props);
39 if(comp==DEPTH_COMPONENT || comp==STENCIL_INDEX)
41 if(!(props.optimalTilingFeatures&VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
44 else if(!(props.optimalTilingFeatures&VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT))
51 const Texture *VulkanFramebuffer::get_attachment(unsigned i) const
53 return static_cast<const Framebuffer *>(this)->attachments[i].tex;
56 void VulkanFramebuffer::update(unsigned) const
58 const Framebuffer &self = *static_cast<const Framebuffer *>(this);
59 const VulkanFunctions &vk = device.get_functions();
62 device.get_destroy_queue().destroy(handle);
64 VkImageView vk_attachments[FrameFormat::MAX_ATTACHMENTS] = { };
66 for(const Framebuffer::Attachment &a: self.attachments)
68 if(a.tex->view_type!=VK_IMAGE_VIEW_TYPE_2D || a.level || a.layer)
69 throw logic_error("Unimplemented texture type in VulkanFramebuffer::update");
70 vk_attachments[i++] = a.tex->view_handle;
73 VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(self.format, false, false, false);
75 VkFramebufferCreateInfo framebuffer_info = { };
76 framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
77 framebuffer_info.renderPass = handle_cast<::VkRenderPass>(render_pass);
78 framebuffer_info.attachmentCount = self.format.size();
79 framebuffer_info.pAttachments = handle_cast<::VkImageView *>(vk_attachments);
80 framebuffer_info.width = self.width;
81 framebuffer_info.height = self.height;
82 framebuffer_info.layers = 1;
84 vk.CreateFramebuffer(framebuffer_info, handle);
86 if(!debug_name.empty())
87 set_vulkan_object_name();
90 void VulkanFramebuffer::set_debug_name(const string &name)
95 set_vulkan_object_name();
101 void VulkanFramebuffer::set_vulkan_object_name() const
104 const VulkanFunctions &vk = device.get_functions();
106 VkDebugUtilsObjectNameInfoEXT name_info = { };
107 name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
108 name_info.objectType = VK_OBJECT_TYPE_FRAMEBUFFER;
109 name_info.objectHandle = reinterpret_cast<uint64_t>(handle);
110 name_info.pObjectName = debug_name.c_str();
111 vk.SetDebugUtilsObjectName(name_info);