7.2. Render Pass 兼容性
帧缓冲区和图形管线是基于特定render pass对象创建的。它们必须只能被用于该render pass对象,或者 与之兼容的对象。
如果两个reference指向的附件有相同的格式和采样数量,或者两个都是VK_ATTACHMENT_UNUSED
,又或都指向`NULL`, 它们就是兼容的。
如果两个附件数组中对应位置元素都是是兼容的,那么这两个数组就是兼容的。 如果数组有不同的长度,个数少的数组中没有对应元素的位置都被当作VK_ATTACHMENT_UNUSED
对待。
两个render pass是兼容的,如果它们对应的颜色、输入、解析和深度/模板附件的引用是兼容的, 如果符合除了以下的条件,它们就是完全相同的: * 附件描述中初始和最终的图像布局 * 附件描述中load 和 store操作 * 附件一用的图像布局
如果帧缓冲区和render pass是通过相同的或者兼容的render pass创建的,那么它们是兼容的。
7.3. 帧缓冲区
render pass操作通过 帧缓存区 联系在一起。帧缓存区表示一个render pass实例使用的多个特定内存附件。
帧缓冲区通过VkFramebuffer
handle表示:
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFramebuffer)
可调用如下命令来创建帧缓冲区:
VkResult vkCreateFramebuffer(
VkDevice device,
const VkFramebufferCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkFramebuffer* pFramebuffer);
-
device
是创建帧缓冲区的逻辑设备。 -
pCreateInfo
指向了一个VkFramebufferCreateInfo
数据结构,它描述了创建帧缓冲区的附加信息。 -
pAllocator
控制了CPU端内存分配,如 Memory Allocation 一章所描述。 -
pFramebuffer
指向了一个VkFramebuffer
handle,它接收生成的帧缓冲区对象。
VkFramebufferCreateInfo
类型数据结构定义如下:
typedef struct VkFramebufferCreateInfo {
VkStructureType sType;
const void* pNext;
VkFramebufferCreateFlags flags;
VkRenderPass renderPass;
uint32_t attachmentCount;
const VkImageView* pAttachments;
uint32_t width;
uint32_t height;
uint32_t layers;
} VkFramebufferCreateInfo;
-
sType
是数据结构的类型。 -
pNext
是NULL
或者一个指向拓展特定的数据结构的指针。 -
flags
被保留。 -
renderPass
is a render pass that defines what render passes the framebuffer will be compatible with. See Render Pass Compatibility for details. -
attachmentCount
is the number of attachments. -
pAttachments
is an array ofVkImageView
handles, each of which will be used as the corresponding attachment in a render pass instance. -
width
,height
andlayers
define the dimensions of the framebuffer.
被当作图像子资源使用的附件不能通过非附件用途的方式在render pass实例内部被使用。
注意
这个限制意味着render pass完全知道所有附件的所有用途,所以Vulkan实现能够正确的决定 何时及如何进行布局转变,何时并行执行subpass等。 |
It is legal for a subpass to use no color or depth/stencil attachments, and rather use shader side effects such as image stores and atomics to produce an output. In this case, the subpass continues to use the width
, height
, and layers
of the framebuffer to define the dimensions of the rendering area, and the rasterizationSamples
from each pipeline’sVkPipelineMultisampleStateCreateInfo
to define the number of samples used in rasterization; however, ifVkPhysicalDeviceFeatures
::variableMultisampleRate
is VK_FALSE
, then all pipelines to be bound with a given zero-attachment subpass must have the same value forVkPipelineMultisampleStateCreateInfo
::rasterizationSamples
.
可调用如下命令来销毁帧缓冲区:
void vkDestroyFramebuffer(
VkDevice device,
VkFramebuffer framebuffer,
const VkAllocationCallbacks* pAllocator);
-
device
是销毁帧缓冲区的逻辑设备。 -
framebuffer
是需要被销毁的帧缓冲区的handle。 -
pAllocator
控制了CPU端内存分配,如 Memory Allocation 一章所描述。