Render passes and Framebuffers

Render passes and framebuffers define a set of attachments which will be used to create a final rendered image

Render passes

A render pass describes the set of data necessary to accomplish a rendering operation. In Vulkan, this is a set of framebuffer attachments that will be used during rendering. These attachments include any buffers that will read from or written into during rendering, such as colour, depth, and stencil buffers. This can also include input attachments which are intermediate buffers which are written into in one sub-pass and then read out of by another one.

Following the standard Vulkan paradigm, these attachments have to be explicitly defined when creating a render pass, with information like image format, number of samples, and load and store behaviour specified. This reduces the driver workload during runtime, as it does not have to deduce this information itself.

In addition to attachments, render passes also contain one or more sub-passes that order the rendering operations. Sub-passes essentially represent a phase of rendering in which rendering work is done with a sub-set of the attachments in the render pass. A set of commands are recorded into each sub-pass to describe what work needs to be done in that sub-pass.

The render pass also defines a set of sub-pass dependencies which determine the order of execution for pairs of sub-passes. They act as execution and memory dependencies. Dependencies are vital when two or more sub-passes access the same attachment, as Vulkan does not guarantee the order in which the sub-passes will be executed by the GPU.

It is important to note that while a render pass describes the characteristics of all of the attachments used and what to do with them, it does not point to any actual objects. This is handled by framebuffer objects.

Framebuffers

In OpenGL ES, framebuffers are strictly defined by their use. They are a set of textures or attachments that are rendered on, and later presented on screen.

In Vulkan, all the attachments used by a render pass are defined in framebuffers. Each framebuffer defines the attachments related to it. This can encompass the textures which includes the colour and depth/stencil attachments, and input attachments.

Framebuffers are fairly simple objects. Each new framebuffer contains a reference to a specific render pass, a set of pointers to the attachments (images), and some information on the dimensions of these attachments.

Splitting the description and definition of attachments between the render pass and the framebuffer respectively helps the overall optimisation of operations on the GPU and potentially allows the framebuffer object to swapped without changing the render pass, as long as the framebuffer is compatible with the render pass.