KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::VulkanContext Class Reference

Vulkan API has the following concepts. More...

#include <VulkanContext.h>

Inheritance diagram for Karma::VulkanContext:
Collaboration diagram for Karma::VulkanContext:

Public Member Functions

 VulkanContext (GLFWwindow *windowHandle)
 A constructor to set the m_vulkanRendererAPI (using static_cast, or compilet time cast). Also checks the validity of windowHandle.
 
virtual ~VulkanContext () override
 Destructor of vulkan context. Does the following.
 
virtual void Init () override
 Initializes VulkanContext by creating appropriate Vulkan and glslang specific instruments and allocating resources accordingly.
 
virtual void SwapBuffers () override
 This function swaps the front and back buffers of the specified window. If the swap interval is greater than zero, the GPU driver waits the specified number of screen updates before swapping the buffers.
 
virtual bool OnWindowResize (WindowResizeEvent &event) override
 Calls glViewport function which specifies the affine transformation of x and y from normalized device coordinates to window coordinates.
 
void CreateInstance ()
 
void PrintAvailableExtensions ()
 
void PrintAvailablePhysicalDevices (const std::vector< VkPhysicalDevice > &physicalDevices)
 
bool CheckValidationLayerSupport ()
 
std::vector< const char * > GetRequiredExtensions (VkInstanceCreateFlags &flagsToBeSet)
 
void SetupDebugMessenger ()
 
void PopulateDebugMessengerCreateInfo (VkDebugUtilsMessengerCreateInfoEXT &createInfo)
 
VkResult CreateDebugUtilsMessengerEXT (VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pDebugMessenger)
 
void DestroyDebugUtilsMessengerEXT (VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks *pAllocator)
 
void CreateSurface ()
 
void PickPhysicalDevice ()
 
bool IsDeviceSuitable (VkPhysicalDevice device)
 
QueueFamilyIndices FindQueueFamilies (VkPhysicalDevice device)
 
void CreateLogicalDevice ()
 The so called logical device for interfacing with the physical device. All the machinery (swapchain, graphicspipeline, and all that) are created from logical device.
 
void CreateSwapChain ()
 Vulkan does not have the concept of a "default framebuffer", hence it requires an infrastructure that will own the buffers we will render to before we visualize them on the screen. This infrastructure is known as the swap chain and must be created explicitly in Vulkan. The swap chain is essentially a queue of images that are waiting to be presented to the screen. Our backend will acquire such an image to draw to it, and then return it to the queue.
 
bool CheckDeviceExtensionSupport (VkPhysicalDevice device)
 
SwapChainSupportDetails QuerySwapChainSupport (VkPhysicalDevice device)
 
VkSurfaceFormatKHR ChooseSwapSurfaceFormat (const std::vector< VkSurfaceFormatKHR > &availableFormats)
 
VkPresentModeKHR ChooseSwapPresentMode (const std::vector< VkPresentModeKHR > &availablePresentModes)
 
VkExtent2D ChooseSwapExtent (const VkSurfaceCapabilitiesKHR &capabilities)
 
uint32_t FindMemoryType (uint32_t typeFilter, VkMemoryPropertyFlags properties)
 
void CreateImageViews ()
 An image view is quite literally a view into an image. It describes how to access the image and which part of the image to access, for example if it should be treated as a 2D texture depth texture without any mipmapping levels.
 
void CreateRenderPass ()
 A VkRenderPass is a Vulkan object that encapsulates the state needed to setup the “target” for rendering, and the state of the images we will be rendering to.
 
void CreateFrameBuffers ()
 A framebuffer represents a collection of specific memory attachments that a render pass instance uses.
 
void CreateCommandPool ()
 Command pools are opaque objects that command buffer memory is allocated from, and which allow the implementation to amortize the cost of resource creation.
 
void CreateDepthResources ()
 
VkFormat FindSupportedFormat (const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
 
VkFormat FindDepthFormat ()
 
bool HasStencilComponent (VkFormat format)
 
void TransitionImageLayout (VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout)
 
void CopyBufferToImage (VkBuffer buffer, VkImage image, uint32_t width, uint32_t height)
 
void RecreateSwapChain ()
 
void CleanupSwapChain ()
 
void SetVSync (bool bEnable)
 
void Initializeglslang ()
 
void RegisterUBO (const std::shared_ptr< VulkanUniformBuffer > &ubo)
 
void ClearUBO ()
 
void RecreateUBO ()
 
void UploadUBO (size_t frameIndex)
 
VkDevice GetLogicalDevice () const
 
VkPhysicalDevice GetPhysicalDevice () const
 
VkExtent2D GetSwapChainExtent () const
 
VkRenderPass GetRenderPass () const
 
const std::vector< VkFramebuffer > & GetSwapChainFrameBuffer () const
 
VkSwapchainKHR GetSwapChain () const
 
const std::vector< VkImage > & GetSwapChainImages () const
 
VkFormat GetSwapChainImageFormat () const
 
const std::vector< VkImageView > & GetSwapChainImageViews () const
 
VkSurfaceFormatKHR GetSurfaceFormat () const
 
VkQueue GetGraphicsQueue () const
 
VkQueue GetPresentQueue () const
 
VkCommandPool GetCommandPool () const
 
const VkPhysicalDeviceFeatures & GetSupportedDeviceFeatures () const
 
VkInstance GetInstance () const
 
uint32_t GetImageCount () const
 
uint32_t GetMinImageCount () const
 
VkSurfaceKHR GetSurface () const
 
VkPresentModeKHR GetPresentMode () const
 
- Public Member Functions inherited from Karma::GraphicsContext
virtual ~GraphicsContext ()
 A destructor.
 

Static Public Member Functions

static VKAPI_ATTR VkBool32 VKAPI_CALL DebugCallback (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData)
 

Detailed Description

Vulkan API has the following concepts.

  1. Physical Device (https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Physical_devices_and_queue_families): The software counterpart (VkPhysicalDevice) of a graphics card (GPU). Logical device is created from physical device.
  2. Device (https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Logical_device_and_queues): The so called logical device for interfacing with the physical device. All the machinery (swapchain, graphicspipeline, and all that) are created from logical device.

Host : is CPU the host?

Constructor & Destructor Documentation

◆ VulkanContext()

Karma::VulkanContext::VulkanContext ( GLFWwindow * windowHandle)

A constructor to set the m_vulkanRendererAPI (using static_cast, or compilet time cast). Also checks the validity of windowHandle.

Parameters
windowHandleThe glfw window handle
Since
Karma 1.0.0

◆ ~VulkanContext()

Karma::VulkanContext::~VulkanContext ( )
overridevirtual

Destructor of vulkan context. Does the following.

  1. Free the commandbuffers (VulkanRendererAPI::AllocateCommandBuffers()) and removes synchronicity
  2. Destroy the framebuffers (CreateFrameBuffers())
  3. Destroy depth imageview (CreateDepthResources())
  4. Destroy image (CreateDepthResources())
  5. Free up depthimagememory (CreateDepthResources())
  6. Destroy command pool (CreateCommandPool())
  7. Destroy render pass (CreateRenderPass())
  8. Destroy swapchain imageview (CreateImageViews())
  9. Destroy swapchain (CreateSwapChain())
  10. Destroy the vulkan m_device (CreateLogicalDevice())
  11. Destroy validation layers for debug messages (SetupDebugMessenger())
  12. Destroy surface (CreateSurface())
  13. Destroy instance (CreateInstance())
  14. Destroy glslang memory resources for cleanup
See also
Init()
Since
Karma 1.0.0

Member Function Documentation

◆ CreateCommandPool()

void Karma::VulkanContext::CreateCommandPool ( )

Command pools are opaque objects that command buffer memory is allocated from, and which allow the implementation to amortize the cost of resource creation.

Since
Karma 1.0.0

◆ CreateFrameBuffers()

void Karma::VulkanContext::CreateFrameBuffers ( )

A framebuffer represents a collection of specific memory attachments that a render pass instance uses.

See also
KarmaGui_ImplVulkanH_ImageFrame::Framebuffer

◆ CreateImageViews()

void Karma::VulkanContext::CreateImageViews ( )

An image view is quite literally a view into an image. It describes how to access the image and which part of the image to access, for example if it should be treated as a 2D texture depth texture without any mipmapping levels.

Note
Here we are creating depth images ?
Since
Karma 1.0.0

◆ CreateLogicalDevice()

void Karma::VulkanContext::CreateLogicalDevice ( )

The so called logical device for interfacing with the physical device. All the machinery (swapchain, graphicspipeline, and all that) are created from logical device.

Since
Karma 1.0.0

◆ CreateRenderPass()

void Karma::VulkanContext::CreateRenderPass ( )

A VkRenderPass is a Vulkan object that encapsulates the state needed to setup the “target” for rendering, and the state of the images we will be rendering to.

Since
Karma 1.0.0

◆ CreateSwapChain()

void Karma::VulkanContext::CreateSwapChain ( )

Vulkan does not have the concept of a "default framebuffer", hence it requires an infrastructure that will own the buffers we will render to before we visualize them on the screen. This infrastructure is known as the swap chain and must be created explicitly in Vulkan. The swap chain is essentially a queue of images that are waiting to be presented to the screen. Our backend will acquire such an image to draw to it, and then return it to the queue.

Karma 1.0.0

◆ Init()

void Karma::VulkanContext::Init ( )
overridevirtual

Initializes VulkanContext by creating appropriate Vulkan and glslang specific instruments and allocating resources accordingly.

  1. Create Instance;
  2. Setup Debug Messenger
  3. Create Surface
  4. Pick PhysicalDevice
  5. Create Logical Device
  6. Create Swap Chain
  7. Create ImageViews
  8. Create RenderPass
  9. Create CommandPool
  10. Create DepthResources
  11. Create FrameBuffers
  12. VulkanHolder::SetVulkanContext(this) (VulkanHolder::m_VulkanContext)
  13. m_vulkanRendererAPI->CreateSynchronicity()
  14. Initialize glslang()
See also
~VulkanContext()
Since
Karma 1.0.0

Implements Karma::GraphicsContext.

◆ OnWindowResize()

virtual bool Karma::VulkanContext::OnWindowResize ( WindowResizeEvent & event)
inlineoverridevirtual

Calls glViewport function which specifies the affine transformation of x and y from normalized device coordinates to window coordinates.

Todo
Seems OpenGL specific. Either think about usage in Vulkan or re design
Since
Karma 1.0.0

Implements Karma::GraphicsContext.

◆ SwapBuffers()

void Karma::VulkanContext::SwapBuffers ( )
overridevirtual

This function swaps the front and back buffers of the specified window. If the swap interval is greater than zero, the GPU driver waits the specified number of screen updates before swapping the buffers.

Todo
This seems to be an OpenGL specific call. Need to design api accordingly
Since
Karma 1.0.0

Implements Karma::GraphicsContext.


The documentation for this class was generated from the following files: