8

I'm trying to understand why we need VkAttachmentReference::layout? Documentation says:

layout is a VkImageLayout value specifying the layout the attachment uses during the subpass.

In other words it tells to which layout the attachment will transition before subpass begins.

But this information already available through VkAttachmentDescription::initialLayout. This is a quote from the documentation:

initialLayout is the layout the attachment image subresource will be in when a render pass instance begins.

Isn't VkAttachmentReference::layout redundand because it exactly repeats VkAttachmentDescription::initialLayout?

plasmacel
  • 8,183
  • 7
  • 53
  • 101
nikitablack
  • 4,359
  • 2
  • 35
  • 68

1 Answers1

9

No, through initialLayout You specify layout the image is in just before a render pass. It can be whatever, for example the finalLayout from a previous render pass. Or an undefined layout of a newly created image. Or a present_src layout of an image acquired from a swapchain.

Then the image is automatically transitioned from the initialLayout to the layout specified for a given subpass. If You have more subpasses, then in each of them You can use images in a different way and You don't have to worry about manual transitions.

These two layout parameters are required for the driver to know what transition it should perform. Vulkan is an explicit API, drivers do not track any information (or track as less as pissible). Without the initialLayout layout automatic transition wouldn't be possible.

Ekzuzy
  • 3,193
  • 1
  • 16
  • 14
  • I didn't get, sorry. Why to specify `VkAttachmentDescription::initialLayout` then if the image will be transitioned to `VkAttachmentReference::layout` anyway? – nikitablack Apr 04 '18 at 14:14
  • 2
    I edited the answer. This defined the transition that needs to be performed by the driver. Without it drivers wouldn't know what transition should be performed as they don't know what layout image has in a given moment. And transitions from different layouts may be performed differently so this knowledge may be crucial for the drivers. – Ekzuzy Apr 04 '18 at 14:19
  • Ok, now I got it. Thanks a lot. The `VkAttachmentDescription::initialLayout` and `VkAttachmentDescription::finalLayout` are specified for the _entire_ pass. And each reference to the same attachment can transition it to another layout with `VkAttachmentReference::layout`. – nikitablack Apr 04 '18 at 14:25
  • 4
    @nikitablack: No, the `initialLayout` says what layout the image is in *before* the renderpass starts. This allows the renderpass system to transition the image from that layout to the layout(s) it is used within the various subpasses (layout transitions require both a source and destination. The source for the first transition is the `initialLayout`). This gives the render pass implementation the freedom to execute subpasses in whatever order they want (within dependency restrictions). And the `finalLayout` says what layout the image will be transitioned into *after* the renderpass. – Nicol Bolas Apr 04 '18 at 14:40
  • @NicolBolas Thank you. Yes, that's exactly what I mean, maybe I used wrong terms. – nikitablack Apr 04 '18 at 14:49