Vulkan规范:第七章 7.2 ~ 7.3

来源:互联网 发布:摩托吧app软件 编辑:程序博客网 时间:2024/06/07 00:35

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,它接收生成的帧缓冲区对象。

Valid Usage (Implicit)
  • device must be a valid VkDevice handle

  • pCreateInfo must be a pointer to a valid VkFramebufferCreateInfo structure

  • If pAllocator is not NULLpAllocator must be a pointer to a valid VkAllocationCallbacks structure

  • pFramebuffer must be a pointer to a VkFramebuffer handle

Return Codes
Success
  • VK_SUCCESS

Failure
  • VK_ERROR_OUT_OF_HOST_MEMORY

  • VK_ERROR_OUT_OF_DEVICE_MEMORY

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 of VkImageView handles, each of which will be used as the corresponding attachment in a render pass instance.

  • widthheight and layers 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 widthheight, 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.

正确使用
  • attachmentCount must be equal to the attachment count specified in renderPass

  • Any given element of pAttachments that is used as a color attachment or resolve attachment by renderPass musthave been created with a usage value including VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT

  • Any given element of pAttachments that is used as a depth/stencil attachment by renderPass must have been created with a usage value including VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT

  • Any given element of pAttachments that is used as an input attachment by renderPass must have been created with a usage value including VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT

  • Any given element of pAttachments must have been created with an VkFormat value that matches the VkFormatspecified by the corresponding VkAttachmentDescription in renderPass

  • Any given element of pAttachments must have been created with a samples value that matches the samples value specified by the corresponding VkAttachmentDescription in renderPass

  • Any given element of pAttachments must have dimensions at least as large as the corresponding framebuffer dimension

  • Any given element of pAttachments must only specify a single mip level

  • Any given element of pAttachments must have been created with the identity swizzle

  • width must be greater than 0.

  • width must be less than or equal to VkPhysicalDeviceLimits::maxFramebufferWidth

  • height must be greater than 0.

  • height must be less than or equal to VkPhysicalDeviceLimits::maxFramebufferHeight

  • layers must be greater than 0.

  • layers must be less than or equal to VkPhysicalDeviceLimits::maxFramebufferLayers

Valid Usage (Implicit)
  • sType must be VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO

  • pNext must be NULL

  • flags must be 0

  • renderPass must be a valid VkRenderPass handle

  • If attachmentCount is not 0pAttachments must be a pointer to an array of attachmentCount valid VkImageViewhandles

  • Both of renderPass, and the elements of pAttachments that are valid handles must have been created, allocated, or retrieved from the same VkDevice

可调用如下命令来销毁帧缓冲区:

void vkDestroyFramebuffer(    VkDevice                                    device,    VkFramebuffer                               framebuffer,    const VkAllocationCallbacks*                pAllocator);
  • device 是销毁帧缓冲区的逻辑设备。

  • framebuffer 是需要被销毁的帧缓冲区的handle。

  • pAllocator 控制了CPU端内存分配,如 Memory Allocation 一章所描述。

正确使用
  • All submitted commands that refer to framebuffer must have completed execution

  • If VkAllocationCallbacks were provided when framebuffer was created, a compatible set of callbacks must be provided here

  • If no VkAllocationCallbacks were provided when framebuffer was created, pAllocator must be NULL

Valid Usage (Implicit)
  • device must be a valid VkDevice handle

  • If framebuffer is not VK_NULL_HANDLEframebuffer must be a valid VkFramebuffer handle

  • If pAllocator is not NULLpAllocator must be a pointer to a valid VkAllocationCallbacks structure

  • If framebuffer is a valid handle, it must have been created, allocated, or retrieved from device

Host Synchronization
  • Host access to framebuffer must be externally synchronized