Creating a swapchain
Swapchain creation
In Daxa, the swapchain is a key element in rendering graphics, acting as a bridge between your application and the display. It’s a collection of buffers used for displaying images on the screen. Unlike other/older APIs, Vulkan requires explicit management of these, which Daxa luckily handles for you.
The following code sample creates a new swapchain using a native window handle and a native window platform. Both of these values are supposed to be supplied by your windowing library of choice.
In the sample code, the native window handle can be obtained by 2 of the helper-functions we created AppWindow::get_native_handle()
and AppWindow::get_native_platform()
daxa::PresentMode
This defines how the rendered images are supplied to your screen. daxa::PresentMode::FIFO
is the recommended default option for most use cases.
mode | meaning |
---|---|
daxa::PresentMode::IMMEDIATE | Images submitted by your application are transferred to the screen right away, which may result in tearing |
daxa::PresentMode::FIFO | The swapchain 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”. |
daxa::PresentMode::FIFO_RELAXED | 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. |
daxa::PresentMode::MAILBOX | 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. Although this may be desirable, it has limited support on AMD devices |
Swapchain usage
You can now acquire a new swapchain image by later running
If all swapchain images are used in queued submissions to the GPU, the present call will block. The Swapchain will also control frames in flight. It controls the acquire, present and frames in flight semaphores. Each of those can be queried with a function from the swapchain.