Vulkan编程指南翻译 第七章 图形管线 第2节 Renderpasses(未完成)

81 篇文章 2 订阅
33 篇文章 1 订阅

7.2  renderpass

Vulkan图形管线和计算管线的区别之一是,你使用图形管线来渲染出像素,组成图像以供处理或显示给用户。在复杂的图形应用程序中,图片经过很多遍构建,每一遍都生成场景的一部分,应用全帧效果如后期处理、合成、渲染用户界面元素等等。

这样的一遍可以使用Vulkan renderpass 对象表示。一个单一的的renderpass对象封装了多个pass或者一系列最终图像的几个渲染阶段,renderpass对象包含输出图像所需的信息。

所有的绘制必须被包含在一个renderpass中。甚至,图形管线需要知道他们把渲染结果发往哪儿,因此,有必要在创建图形管线之前创建一个renderpass对象,一边我们可以告诉正在生成图像的管线有关图像的信息。在第十三章将会深度的讲解renderpass。在本章,我们创建一个最简单的renderpass对象,我们可以把渲染结果写到一张图像。

可调用vkCreateRenderPass()来创建renderpass对象,其原型如下:

VkResult vkCreateRenderPass (

VkDevice device,

const VkRenderPassCreateInfo* pCreateInfo,

const VkAllocationCallbacks* pAllocator,

VkRenderPass* pRenderPass);

vkCreateRenderPass()device参数指定了将要创建renderpass对象的设备,pCreateInfo指向了一个定义renderpass的结构。它是VkRenderPassCreateInfo类型的一个实例,定义如下:

typedef struct VkRenderPassCreateInfo {

VkStructureType sType;

const void* pNext;

VkRenderPassCreateFlags flags;

uint32_t attachmentCount;

const VkAttachmentDescription* pAttachments;

uint32_t subpassCount;

const VkSubpassDescription* pSubpasses;

uint32_t dependencyCount;

const VkSubpassDependency* pDependencies;

} VkRenderPassCreateInfo;

VkRenderPassCreateInfosType应置为VK_STRUCTURE_TYPE_RENDERPASS_CREATE_INFOpNext应置为nullptrflags域被保留使用,应置为0pAttachments是一个指向大小为attachmentCountVkAttachmentDescription类型数组的指针,数组定义了和renderpass关联的多个附件。数组中的每一个元素定义了在一个renderpass中多个subpasses里一张用作输入、输出或者二者兼具的图像。如果真的没有和renderpass关联的附件,你可以设置attachmentCount0pAttachmentsnullptr。然而,除了一些高级使用场景,几乎所有的图形渲染都将使用至少一个附件。VkAttachmentDescription定义是:

typedef struct VkAttachmentDescription {

VkAttachmentDescriptionFlags flags;

VkFormat format;

VkSampleCountFlagBits samples;

VkAttachmentLoadOp loadOp;

VkAttachmentStoreOp storeOp;

VkAttachmentLoadOp stencilLoadOp;

VkAttachmentStoreOp stencilStoreOp;

VkImageLayout initialLayout;

VkImageLayout finalLayout;

} VkAttachmentDescription;

flags用来给Vulkan提供关于附件的附加信息。当前只有一个定义VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT,如果被设置了这个值,表示附件可能被同一个renderpass引用的其他附件共享一块内存。这告诉Vulkan不要对做任何可能导致附件的数据不一致的事情。这个标志位可以用于一些高级场景,如内存很稀少,你视图优化它的使用。绝大多数场景下,flags可以设置为0

format域指定了附件的格式。这是VkFormat枚举类型的一个成员,应该和用作附件的图像的格式相同。同样,samples表示图像的采样的个数,被用于多重采样。当不使用多重采样时,把samples设置为VK_SAMPLE_COUNT_1_BIT

接下来的四个域指定了在renderpass的开始与结束时如何处理附件。加载操作告诉Vulkanrenderpass开始时如何处理附件。可以设置为如下值:

 

VK_ATTACHMENT_LOAD_OP_LOAD indicates that the attachment has data in it already and

that you want to keep rendering to it. This causes Vulkan to treat the contents of the attachment

as valid when the renderpass begins.

VK_ATTACHMENT_LOAD_OP_CLEAR indicates that you want Vulkan to clear the attachment

for you when the renderpass begins. The color to which you want to clear the attachments is

specified when the renderpass has begun.

VK_ATTACHMENT_LOAD_OP_DONT_CARE indicates that you dont care about the content of

the attachment at the beginning of the renderpass and that Vulkan is free to do whatever it

wishes with it. You can use this if you plan to explicitly clear the attachment or if you know that

youll replace the content of the attachment inside the renderpass.

 

同样,存储操作告诉Vulkanrenderpass结束时如何处理附件的内容。可以设置为如下值:

VK_ATTACHMENT_STORE_OP_STORE indicates that you want Vulkan to keep the contents

of the attachment for later use, which usually means that it should write them out into memory.

This is usually the case for images you want to display to the user, read from later, or use as an

attachment in another renderpass (with the VK_ATTACHMENT_LOAD_OP_LOAD load

operation).

VK_ATTACHMENT_STORE_OP_DONT_CARE indicates that you dont need the content after

the renderpass has ended. This is normally used for intermediate storage or for the depth or

stencil buffers

 

如果附件是一个被绑定的depth-stenci附件,那么stencilLoadOpstencilStoreOp与告诉Vulkan如何处理附件的stencil部分(常规的loadOp storeOp域指定了如何处理附件等哦depth部分),和depth部分不同。

initialLayoutfinalLayout域告诉Vulkan期待的imagerenderpass开始时域结束时处于哪种布局。注意,renderpass对象不会自动把图像转变到初始布局。这个布局是当renderpass使用它时期待的布局。尽管,renderpass结束时会改变图像的最终布局。

你可以使用屏障,显式的把图像从一个布局转移到另外一个布局,但是,可能的话,最好尝试在renderpass内部转移布局。这可以让Vulkan有很好的机会可以在其他渲染工作进行时并行的改变图像的布局。这个域的高级使用方式和renderpass在第十三章讲解。

在你定义了将在renderpass中使用的所有的附件后,你需要定义所有的subpasses。每一个subpass都引用了一些数量的附件()作为输入或者输出。这些描述通过一个VkSubpassDescription类型的数组描述,每一个元素对应renderpass中的一个subpassVkSubpassDescription定义如下:

typedef struct VkSubpassDescription {

VkSubpassDescriptionFlags flags;

VkPipelineBindPoint pipelineBindPoint;

uint32_t inputAttachmentCount;

const VkAttachmentReference* pInputAttachments;

uint32_t colorAttachmentCount;

const VkAttachmentReference* pColorAttachments;

const VkAttachmentReference* pResolveAttachments;

const VkAttachmentReference* pDepthStencilAttachment;

uint32_t preserveAttachmentCount;

const uint32_t* pPreserveAttachments;

} VkSubpassDescription;

 

 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值