MAIN

Vulkan Overview in Code - Part 1

I’ve realized how explicit and involved effort in setting up Vulkan code even prior to the first simple triangle rendered on screen. So here is Part I for code overview in setting up working rendering code with Vulkan. It explores various areas either required or are better to use for performance gained.

Part I covers all essential and basic initializations, and rendering loop leaving some areas which will be working on top the foundation like Vertex buffer, Uniform buffers for later parts. So it is pure stuff required to get a simple triangle able to be rendered on screen. Subsequent parts will expand more gradually.

Initialization Overview

  1. Create instance
  2. (optional) Setup debug messenger
  3. Create Surface
  4. Pick physical device
  5. Create logical device
  6. Create swapchain
  7. Create imageviews
  8. Create renderpass
  9. Create graphics pipeline
  10. Create framebuffers
  11. Create command pool
  12. Create command buffers
  13. Create sync objects

1. Create instance

2. Setup debug messenger

This is different from 1. as this will hook up the entire call chain into the input VkInstance

3. Create surface

This is specifically for window system/library you might be using, in usual case it is probably be glfw by using the following function

4. Pick physical device

5. Create logical device

6. Create swapchain

Relationship for its underlying components

VkFramebuffer -> VkImageView -> VkImage

7. Create imageviews

8. Create renderpass

9. Create grahpics pipeline

10. Create framebuffers

11. Create command pool

12. Create command buffers

13. Create sync objects

This depends on your synchronizing logic, but at the baseline with good performance, it’s good to follow along with synchronizing approach used in GL_vs_VK - Test1.

As such, the number of semaphores (VkSemaphore) is 2 x number of swapchain’s images in which in this case we have 4 for double buffering (2 images), or 6 for tripple buffering (3 images)

As well, the number of fence (VkFence) is just number of swapchain’s images.

Misc

Vector array holder size

Mostly the vector arrays used to hold to-be-created structures across the code base will have the size of swapchain’s images.

Actually we can interchangeably say the size of swapchain’s framebuffers, or imageviews, or images. They are all related deep down to the size of images. All higher-up structures are created on top of the size of images.

Rendering loop in Overview

Clean up

SwapChainSupportDetails structure

It consists of cached surface’s capabilities, formats, and presentation mode. If has the following fields

    VkSurfaceCapabilitiesKHR capabilities;
    std::vector<VkSurfaceFormatKHR> formats;
    std::vector<VkPresentModeKHR> presentModes;

findQueueFamilies(VkPhysicalDevice device)

querySwapChainSupport(VkPhysicalDevice device)

Resource



First published on April, 18, 2020






Written by Wasin Thonkaew
In case of reprinting, comments, suggestions
or to do anything with the article in which you are unsure of, please
write e-mail to wasin[add]wasin[dot]io

Copyright © 2019 Wasin Thonkaew. All Rights Reserved.