What is the meaning of 'attachment' when speaking about the Vulkan API?

Viewed 5427

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.

2 Answers

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.

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).

Related