VK_KHR_imageless_framebuffer

在 Vulkan 1.2 中提升为核心功能

在创建 VkFramebuffer 时,通常需要传递 VkFramebufferCreateInfo::pAttachments 中使用的 VkImageView。需要 VkImageView 会强制应用程序为每个交换链图像创建一个帧缓冲。使用 VK_KHR_imageless_framebufferVkImageView 信息在 vkCmdBeginRenderPass 时给出。这意味着所有交换链图像只有一个 VkFramebuffer。需要注意的是,当交换链的大小发生变化时,仍然需要重新创建 VkFramebuffer 以调整诸如 heightwidth 之类的信息。

要使用无图像的 VkFramebuffer

  • 通过查询 VkPhysicalDeviceImagelessFramebufferFeatures::imagelessFramebufferVkPhysicalDeviceVulkan12Features::imagelessFramebuffer 来确保实现支持它

  • VkFramebufferCreateInfo::flags 中设置 VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT

  • VkFramebufferCreateInfo::pNext 中包含一个 VkFramebufferAttachmentsCreateInfo 结构体

  • 当开始渲染过程时,将一个带有兼容附件的 VkRenderPassAttachmentBeginInfo 结构体传递到 VkRenderPassBeginInfo::pNext

// Fill information about attachment
VkFramebufferAttachmentImageInfo attachments_image_info = {};
// ...

VkFramebufferAttachmentsCreateInfo attachments_create_info = {};
// ...
attachments_create_info.attachmentImageInfoCount = 1;
attachments_create_info.pAttachmentImageInfos = &attachments_image_info;

// Create FrameBuffer as imageless
VkFramebufferCreateInfo framebuffer_info = {};
framebuffer_info.pNext = &attachments_create_info;
framebuffer_info.flags |= VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT;
// ...
framebffer_info.pAttachments = NULL; // pAttachments is ignored here now

vkCreateFramebuffer(device, &framebuffer_info, NULL, &framebuffer_object);

// ...

// Start recording a command buffer
VkRenderPassAttachmentBeginInfo attachment_begin_info = {};
// attachment_begin_info.pAttachments contains VkImageView objects

VkRenderPassBeginInfo begin_info = {};
begin_info.pNext = &attachment_begin_info;
// ...

vkCmdBeginRenderPass(command_buffer, &begin_info, VK_SUBPASS_CONTENTS_INLINE);