VulkanFramebuffer::~VulkanFramebuffer()
{
+ DestroyQueue &dq = device.get_destroy_queue();
if(handle)
- device.get_destroy_queue().destroy(handle);
+ dq.destroy(handle);
+ for(VkImageView h: view_handles)
+ if(h)
+ dq.destroy(h);
}
bool VulkanFramebuffer::is_format_supported(const FrameFormat &fmt)
return true;
}
-void VulkanFramebuffer::update(unsigned) const
+void VulkanFramebuffer::update(unsigned mask) const
{
const Framebuffer &self = *static_cast<const Framebuffer *>(this);
const VulkanFunctions &vk = device.get_functions();
+ if(self.attachments.size()>view_handles.size())
+ view_handles.resize(self.attachments.size());
+
if(handle)
device.get_destroy_queue().destroy(handle);
unsigned i = 0;
for(const Framebuffer::Attachment &a: self.attachments)
{
- if(a.tex->view_type!=VK_IMAGE_VIEW_TYPE_2D || a.level || a.layer)
- throw logic_error("Unimplemented texture type in VulkanFramebuffer::update");
- vk_attachments[i++] = a.tex->view_handle;
+ 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));
+
+ if(mask&(1<<i))
+ {
+ if(use_tex_view)
+ a.tex->refresh_mip_views();
+ else
+ {
+ if(view_handles[i])
+ device.get_destroy_queue().destroy(view_handles[i]);
+
+ PixelFormat tex_format = a.tex->get_format();
+
+ VkImageViewCreateInfo view_info = { };
+ view_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+ view_info.image = handle_cast<::VkImage>(a.tex->handle);
+ view_info.viewType = (a.layer<0 ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D);
+ view_info.format = static_cast<VkFormat>(get_vulkan_pixelformat(tex_format));
+
+ view_info.components.r = VK_COMPONENT_SWIZZLE_R;
+ view_info.components.g = VK_COMPONENT_SWIZZLE_G;
+ view_info.components.b = VK_COMPONENT_SWIZZLE_B;
+ view_info.components.a = VK_COMPONENT_SWIZZLE_A;
+
+ view_info.subresourceRange.aspectMask = get_vulkan_aspect(get_components(tex_format));
+ view_info.subresourceRange.baseMipLevel = a.level;
+ view_info.subresourceRange.levelCount = 1;
+ view_info.subresourceRange.baseArrayLayer = max(a.layer, 0);
+ view_info.subresourceRange.layerCount = (a.layer<0 ? VK_REMAINING_ARRAY_LAYERS : 1);
+
+ vk.CreateImageView(view_info, view_handles[i]);
+ }
+ }
+
+ if(use_tex_view)
+ vk_attachments[i] = a.tex->mip_view_handles[a.level];
+ else if(view_handles[i])
+ vk_attachments[i] = view_handles[i];
+ else
+ throw logic_error("unexpected framebuffer configuration");
+
+ ++i;
}
VkRenderPass render_pass = device.get_pipeline_cache().get_render_pass(self.format, false, false, false);