21

In relation to the Vulkan API, what does an 'attachment' mean? I see that word used in relation to render passes (i.e.: color attachments). I have vague idea of what I think they are, but would like to hear the definition from an expert.

I'm doing graphics programming for the first time and decided to jump straight into the deep end by starting with Vulkan.

Braiam
  • 1
  • 11
  • 47
  • 78
Dess
  • 2,064
  • 19
  • 35
  • 1
    I'm no expert, but from what I know of OpenGL you have objects called Framebuffers, which can include attachments that you can add to it. For example usually you do your drawing on the colour attachment, that's normally your image. Other attachments are usually a stencil buffer and a depth buffer. – Zebrafish Sep 23 '17 at 20:34
  • "*would like to hear the definition from an expert*" The Vulkan specification has an actual glossary, where this particular term (among others) is defined. – Nicol Bolas Sep 24 '17 at 02:50
  • 4
    @Nicol Bolas: Ah, the good ole RTFM. I did read it, but description is less than clear. It says this: A zero-based integer index name used in render pass creation to refer to a framebuffer attachment that is accessed by one or more subpasses. The index also refers to an attachment description which includes information about the properties of the image view that will later be attached. – Dess Sep 24 '17 at 07:13
  • The subject is also touched on in the [What is the difference between framebuffer and image in Vulkan?](https://stackoverflow.com/questions/39557141/what-is-the-difference-between-framebuffer-and-image-in-vulkan/39559418#39559418) Question. – krOoze Sep 25 '17 at 17:57

2 Answers2

42

To understand attachments in Vulkan, You first need to understand render-passes and sub-passes.

Render-pass is a general description of steps Your drawing commands are divided into and of resources used during rendering. We can't render anything in Vulkan without a render pass. And each render pass must have one or more steps. These steps are called,

Sub-passes and each sub-pass uses a (sub)collection of resources defined for the render-pass. Render-pass's resources may include render-targets (color, depth/stencil, resolve) and input data (resources that, potentially, were render-targets in previous sub-passes of the same render-pass). And these resources are called,

Attachments (they don't include descriptors/textures/samplers and buffers).

Why don't we call them just render-targets or images? Because we not only render into them (input attachments) and because they are only descriptions (meta data). Images that should be used as attachments inside render-passes are provided through framebuffers.

So, in general, we can call them images, because (as far as I know) only images can be used for attachments. But if we want to be fully correct: images are specific Vulkan resources that can be used for many purposes (descriptors/textures, attachments, staging resources); attachments are descriptions of resources used during rendering.

Sadern Alwis
  • 104
  • 1
  • 4
  • 17
Ekzuzy
  • 3,193
  • 1
  • 16
  • 14
  • 2
    Thank you! I really appreciate that you also explained the concepts around the attachment. Not only does this help explain attachment themselves, but also give a little hint about the other concepts. I've been reading the Vulkan spec. It's a very well written document, but it kind of assumes that the reader is already familiar with OpenGL. Some of us are complete noobs! – Dess Sep 24 '17 at 00:37
  • 3
    I've been reading /r/vulkan, and I see that you also post there. I hope you keep it up, because your writing is very clear and it's a treat to read. You're like a natural teacher and a real asset for us graphic noobs. – Dess Sep 24 '17 at 00:39
  • 1
    @Dess Thanks for Your kind words! :-) I can't say that I know every single feature or aspect of the Vulkan API. But if there are parts of it that I know well and if someone needs a help in understanding them, I try to explain them as best as I can. Whether I do it in a good way or not, I cannot judge. But if You think so - it's very nice to hear that :-). I must say that I like helping others and explaining things to others. Probably that's why I agreed when a PacktPub asked if I can write a "Vulkan Cookbook" ;-). Nevertheless - good luck in learning and understanding Vulkan API! – Ekzuzy Sep 26 '17 at 06:46
12

There are actually several types of attachments. I will explain the two most common.

Color / Depth Attachment

These you write images into. As Zebrafish said, they allow you to draw something (via vkCmdDraw*) into them. You can later read from them. They are outputs.

Input Attachment :

These, as the name implies, are used as inputs and not as outputs. For example, let's say you are building a deferred renderer, you will have several subpasses (2 to be simple).

Your first subpass will draw to several images (your G_BUFFER) : albedo / normal / depth.

Once you have finished this subpass, you can begin another one (the lighting one) and to do lighting computation, you need to give this pass some inputs (your G-Buffer). You set your G-Buffer images as an input attachment.

What is the difference between an input attachment and "sampler" ? Input Attachments are not addressable, and you can get only the pixel you are working on. It probably allows drivers to make some optimizations, and could be used as a transient attachment to optimize rendering using Tiled GPU (but that is another question).

theRPGmaster
  • 107
  • 1
  • 6
Antoine Morrier
  • 3,930
  • 16
  • 37