Aqoole_Hateenaの技術日記

vulkan+raytraceで色々描いてます

Render Passの作成について

Render passの作成

render passの作成に当たりattachmentとsubpassの記述が必要。subpassとはattachmentにアクセスするrender passのsubsetである。
Render PassとFramebufferについて - Aqoole_Hateenaの技術日記
subpassの記述にもattachmentの記述が必要で、attachmentの記述にはdescription構造体とreference構造体の2種類ある。

Attachmentについて

Attachmentとは

VkAttachmentDescriptionで定義されるimage resourcesのこと。VkAttachmentReferenceのVkImageLayoutではlayoutを指定する際に、どの用途のimageかを指定する。(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMALやVK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMALなど)

VkAttachmentDescription


VkAttachmentDescription - Structure specifying an attachment description

// Provided by VK_VERSION_1_0
typedef struct VkAttachmentDescription {
    VkAttachmentDescriptionFlags    flags;
    VkFormat                        format;
    VkSampleCountFlagBits           samples;
    VkAttachmentLoadOp              loadOp;
    VkAttachmentStoreOp             storeOp;
    VkAttachmentLoadOp              stencilLoadOp;
    VkAttachmentStoreOp             stencilStoreOp;
    VkImageLayout                   initialLayout;
    VkImageLayout                   finalLayout;
} VkAttachmentDescription;

  • flags is a bitmask of VkAttachmentDescriptionFlagBits specifying additional properties of the attachment.
  • format is a VkFormat value specifying the format of the image view that will be used for the attachment.
  • samples is a VkSampleCountFlagBits value specifying the number of samples of the image.
  • loadOp is a VkAttachmentLoadOp value specifying how the contents of color and depth components of the attachment are treated at the beginning of the subpass where it is first used.
  • storeOp is a VkAttachmentStoreOp value specifying how the contents of color and depth components of the attachment are treated at the end of the subpass where it is last used.
  • stencilLoadOp is a VkAttachmentLoadOp value specifying how the contents of stencil components of the attachment are treated at the beginning of the subpass where it is first used.
  • stencilStoreOp is a VkAttachmentStoreOp value specifying how the contents of stencil components of the attachment are treated at the end of the last subpass where it is used.
  • initialLayout is the layout the attachment image subresource will be in when a render pass instance begins.
  • finalLayout is the layout the attachment image subresource will be transitioned to when a render pass instance ends.

VkAttachmentDescription(3)

formatだったりsamplesだったりで、imageに関わるパラメータが定義されていることがわかる。loadOpやstoreOpはsubpassに関わるパラメータである。

VkAttachmentReference


VkAttachmentReference - Structure specifying an attachment reference

// Provided by VK_VERSION_1_0
typedef struct VkAttachmentReference {
    uint32_t         attachment;
    VkImageLayout    layout;
} VkAttachmentReference;

  • attachment is either an integer value identifying an attachment at the corresponding index in VkRenderPassCreateInfo::pAttachments, or VK_ATTACHMENT_UNUSED to signify that this attachment is not used.
  • layout is a VkImageLayout value specifying the layout the attachment uses during the subpass.

VkAttachmentReference(3)

attachmentはcreateinfoに登録するindex, layoutはattachementのlayoutでVK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMALやVK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMALなど。

Subpassの作成


VkSubpassDescription - Structure specifying a subpass description

// Provided by VK_VERSION_1_0
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;

  • flags is a bitmask of VkSubpassDescriptionFlagBits specifying usage of the subpass.
  • pipelineBindPoint is a VkPipelineBindPoint value specifying the pipeline type supported for this subpass.
  • inputAttachmentCount is the number of input attachments.
  • pInputAttachments is a pointer to an array of VkAttachmentReference structures defining the input attachments for this subpass and their layouts.
  • colorAttachmentCount is the number of color attachments.
  • pColorAttachments is a pointer to an array of colorAttachmentCount VkAttachmentReference structures defining the color attachments for this subpass and their layouts.
  • pResolveAttachments is NULL or a pointer to an array of colorAttachmentCount VkAttachmentReference structures defining the resolve attachments for this subpass and their layouts.
  • pDepthStencilAttachment is a pointer to a VkAttachmentReference structure specifying the depth/stencil attachment for this subpass and its layout.
  • preserveAttachmentCount is the number of preserved attachments.
  • pPreserveAttachments is a pointer to an array of preserveAttachmentCount render pass attachment indices identifying attachments that are not used by this subpass, but whose contents must be preserved throughout the subpass.

VkSubpassDescription(3)

resolveについて、これはmultisamplingのときに使われるパラメータで、samplingに使用されるcolor attachmentを定義する。


If flags does not include VK_SUBPASS_DESCRIPTION_SHADER_RESOLVE_BIT_QCOM, and if pResolveAttachments is not NULL, each of its elements corresponds to a color attachment (the element in pColorAttachments at the same index), and a multisample resolve operation is defined for each attachment. At the end of each subpass, multisample resolve operations read the subpass’s color attachments, and resolve the samples for each pixel within the render area to the same pixel location in the corresponding resolve attachments, unless the resolve attachment index is VK_ATTACHMENT_UNUSED.
VkSubpassDescription(3)


Therefore we will have to add only one new attachment for color which is a so-called resolve attachment:
Multisampling - Vulkan Tutorial

multisamplingのtutorialを紹介しているページでは、multisamplingを有効にするために、resolve attachmentを追加する例が紹介されている。