Vulkan Swapchain

Poby’s Home
3 min readDec 30, 2021

Vulkan extensions: VK_KHR_swapchain

Resource

https://vulkan-tutorial.com/Drawing_a_triangle/Presentation/Swap_chain

Image representation

  • Since image presentation is heavily tied into the window system and the surfaces associated with windows, it is not actually part of the Vulkan core.

What is “Swapchain”?

  • The swap chain is essentially a queue of images that are waiting to be presented to the screen.
  • The general purpose of the swap chain is to synchronize the presentation of images with the refresh rate of the screen.

Three properties we need to check to use swapchain

  • Basic surface capabilities (min/max number of images in swap chain, min/max width and height of images)
  • Surface formats (pixel format, color space)
  • Available presentation modes

Presentation Mode

The presentation mode is arguably the most important setting for the swap chain, because it represents the actual conditions for showing images to the screen. There are four possible modes available in Vulkan:

  • VK_PRESENT_MODE_IMMEDIATE_KHR: Images submitted by your application are transferred to the screen right away, which may result in tearing.
  • VK_PRESENT_MODE_FIFO_KHR: The swap chain is a queue where the display takes an image from the front of the queue when the display is refreshed and the program inserts rendered images at the back of the queue. If the queue is full then the program has to wait. This is most similar to vertical sync as found in modern games. The moment that the display is refreshed is known as "vertical blank".
  • VK_PRESENT_MODE_FIFO_RELAXED_KHR: This mode only differs from the previous one if the application is late and the queue was empty at the last vertical blank. Instead of waiting for the next vertical blank, the image is transferred right away when it finally arrives. This may result in visible tearing.
  • VK_PRESENT_MODE_MAILBOX_KHR: This is another variation of the second mode. Instead of blocking the application when the queue is full, the images that are already queued are simply replaced with the newer ones. This mode can be used to render frames as fast as possible while still avoiding tearing, resulting in fewer latency issues than standard vertical sync. This is commonly known as "triple buffering", although the existence of three buffers alone does not necessarily mean that the framerate is unlocked.

This is a note taking from Vulkan conference.

VK_KHR_swapchain

  • The VK_KHR_swapchain extension is the device-level companion to the VK_KHR_surface extension.
  • It introduces VkSwapchainKHR objects, which provide the ability to present rendering results to a surface.

VK_KHR_display_swapchain

  • This extension provides an API to create a swapchain directly on a device’s display without any underlying window system.

Vulkan surface != EGL surface

instance_extensions.push_back("VK_KHR_surface");
instance_extensions.push_back("VK_KHR_android_surface");

--

--