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 void VulkanFramebuffer::update(unsigned) const
53 const Framebuffer &self = *static_cast<const Framebuffer *>(this);
54 const VulkanFunctions &vk = device.get_functions();
57 device.get_destroy_queue().destroy(handle);
59 VkImageView vk_attachments[FrameFormat::MAX_ATTACHMENTS] = { };
61 for(const Framebuffer::Attachment &a: self.attachments)
63 if(a.tex->view_type!=VK_IMAGE_VIEW_TYPE_2D || a.level || a.layer)
64 throw logic_error("Unimplemented texture type in VulkanFramebuffer::update");
65 vk_attachments[i++] = a.tex->view_handle;
68 VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(self.format, false, false, false);
70 VkFramebufferCreateInfo framebuffer_info = { };
71 framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
72 framebuffer_info.renderPass = handle_cast<::VkRenderPass>(render_pass);
73 framebuffer_info.attachmentCount = self.format.size();
74 framebuffer_info.pAttachments = handle_cast<::VkImageView *>(vk_attachments);
75 framebuffer_info.width = self.width;
76 framebuffer_info.height = self.height;
77 framebuffer_info.layers = 1;
79 vk.CreateFramebuffer(framebuffer_info, handle);
81 if(!debug_name.empty())
82 set_vulkan_object_name();
85 void VulkanFramebuffer::set_debug_name(const string &name)
90 set_vulkan_object_name();
96 void VulkanFramebuffer::set_vulkan_object_name() const
99 const VulkanFunctions &vk = device.get_functions();
101 VkDebugUtilsObjectNameInfoEXT name_info = { };
102 name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
103 name_info.objectType = VK_OBJECT_TYPE_FRAMEBUFFER;
104 name_info.objectHandle = reinterpret_cast<uint64_t>(handle);
105 name_info.pObjectName = debug_name.c_str();
106 vk.SetDebugUtilsObjectName(name_info);