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

Vulkan implementation of the Dynamic RHI. More...

#include <VulkanDynamicRHI.h>

Inheritance diagram for Karma::FVulkanDynamicRHI:
Karma::IVulkanDynamicRHI Karma::FDynamicRHI

Public Member Functions

 FVulkanDynamicRHI ()
 Initialization constructor.
virtual bool Init () override
 For initializing VulkanDynamic RHI.
virtual void Shutdown () override
 Shuts down the RHI.
void InitInstance ()
 Calls FVulkanDevice::InitGPU() to create Vulkan logical device from selected GPU, and created appropriate resources (commandpool, default texture etc).
virtual void Present () override
 Presents the rendered frame to the display.
SwapChainSupportDetails QuerySwapChainSupport (VkPhysicalDevice device)
 Uses Two-Pass Query to gather surface formats (physical device and surface paired color space or pixel format data) and present modes data.
VkInstance GetInstance () const
 Getter for Vulkan instance.
FVulkanDeviceGetDevice () const
 Getter for FVulkanDevice object created in FVulkanDynamicRHI::SelectDevice().
QueueFamilyIndices FindQueueFamilies (VkPhysicalDevice device)
 Queries the graphics card for available queue families and compares against the availability of graphics and presentation queues.
bool GetValidationLayersSetting () const
 Getter for the boolean bEnableValidationLayers.
const VkPhysicalDeviceFeatures & GetGpuDeviceFeatures () const
 Getter for m_SupportedDeviceFeatures which contains boolean values for supported features like availability of geometry shader or sampler anisotropy.
const SwapChainSupportDetailsGetGpuSwapChainSupportDetails () const
 Getter for m_GPUSwapChainSupport struct which gets initialized in FVulkanDynamicRHI::IsDeviceSuitable().
uint32_t SwapChainImageCount () const
 Getter for the number of supported swapchain images.
VkFormat FindSupportedFormat (const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features) const
 Finds a supported format from the list of candidate formats based on the desired tiling and features. Used in depth resource creation.
VkFormat FindDepthFormat () const
 Finds an appropriate depth format for depth resources.
uint32_t FindMemoryType (uint32_t typeFilter, VkMemoryPropertyFlags properties)
 Finds appropriate memory type with demanded properties. Basically a loop is run from counter i = 0 to VkPhysicalDeviceMemoryProperties.memoryTypeCount (number of valid elements in the memoryTypes array) and memoryType[i] is queried for appropriate properties. On condition satisfaction, counter i is returned.
void RegisterUniformBufferObject (VulkanUniformBuffer *ubo)
 Register a uniformbuffer object to curate an array or uniformbuffers.
void UploadUniformBufferObjects (size_t frameIndex)
 Uploads data to the registered VulkanUniformBuffers for the specified frame index.
GLFWwindow * GetSurfaceWindow () const
VkSurfaceKHR GetSurface () const
Public Member Functions inherited from Karma::IVulkanDynamicRHI
virtual ERHIInterfaceType GetInterfaceType () const override
Public Member Functions inherited from Karma::FDynamicRHI
virtual ~FDynamicRHI ()=default
 Virtual destructor for FDynamicRHI.

Static Public Member Functions

static FVulkanDynamicRHIGet ()
 Getter for the FVulkanDynamicRHI instance.
Static Public Member Functions inherited from Karma::FDynamicRHI
static FDynamicRHICreateRHI ()

Static Public Attributes

static std::vector< const char * > deviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }
static const std::vector< const char * > validationLayers = {"VK_LAYER_KHRONOS_validation"}

Protected Member Functions

void CreateInstance ()
 Creates a Vulkan instance.
void SetupDebugMessenger ()
 Sets up the debug messenger for Vulkan instance.
void CreateSurface ()
 Platform agnostic creation of surface to present rendered images to. Typically they are backed by the category of glfw windows (on Linux, MacOS, and Windows).
void SelectDevice ()
 Picks an Engine appropriate GPU and creates FVulkanDevice.

Protected Attributes

uint32_t m_APIVersion
VkInstance m_VulkanInstance
FVulkanDevicem_Device
VkDebugUtilsMessengerEXT m_DebugMessenger
GLFWwindow * m_WindowHandle
VkSurfaceKHR m_Surface
VkPhysicalDeviceFeatures m_SupportedDeviceFeatures
VkPhysicalDevice m_PhysicalDevice = VK_NULL_HANDLE
SwapChainSupportDetails m_GPUSwapChainSupport
uint32_t m_SwapChainImageCount
std::set< VulkanUniformBuffer * > m_VulkanUBO

Static Protected Attributes

static bool bEnableValidationLayers = false

Detailed Description

Vulkan implementation of the Dynamic RHI.

Provides Vulkan-specific implementations for initializing/deinitializing RHI along with Vulkan resources and rendering operations.

Since
Karma 1.0.0

Constructor & Destructor Documentation

◆ FVulkanDynamicRHI()

Karma::FVulkanDynamicRHI::FVulkanDynamicRHI ( )

Initialization constructor.

Does the following

  1. Creates vkInstance
  2. Sets up debug messenger (with Karma's logging callback function)
  3. Creates a Vulkan surface to interface with the Engine's window (Editor window for instance)
  4. Selects a physical device (GPU) based upon the availability of device extensions, swapchain support, and samplerAnisotropy
  5. Creates Vulkan logical device
Note
Smapler anisotorpy is a technique that makes textures on surfaces viewed at steep angles (like roads or floors stretching into the distance) look clearer and sharper, preventing blurriness by taking multiple samples along the texture's axis of elongation rather than a single one.
Since
Karma 1.0.0

Member Function Documentation

◆ CreateInstance()

void Karma::FVulkanDynamicRHI::CreateInstance ( )
protected

Creates a Vulkan instance.

Since
Karma 1.0.0

◆ CreateSurface()

void Karma::FVulkanDynamicRHI::CreateSurface ( )
protected

Platform agnostic creation of surface to present rendered images to. Typically they are backed by the category of glfw windows (on Linux, MacOS, and Windows).

Since
Karma 1.0.0

◆ FindDepthFormat()

VkFormat Karma::FVulkanDynamicRHI::FindDepthFormat ( ) const

Finds an appropriate depth format for depth resources.

See also
KarmaGuiVulkanHandler::MakeRenderPassInfo
Since
Karma 1.0.0

◆ FindMemoryType()

uint32_t Karma::FVulkanDynamicRHI::FindMemoryType ( uint32_t typeFilter,
VkMemoryPropertyFlags properties )

Finds appropriate memory type with demanded properties. Basically a loop is run from counter i = 0 to VkPhysicalDeviceMemoryProperties.memoryTypeCount (number of valid elements in the memoryTypes array) and memoryType[i] is queried for appropriate properties. On condition satisfaction, counter i is returned.

Graphics cards can offer different types of memory to allocate from. Each type of memory varies in terms of allowed operations and performance characteristics. We need to combine the requirements of the buffer and our own application requirements to find the right type of memory to use.

Parameters
typeFilterA bitmask, and contains one bit set for every supported memory type for the resource. Bit i is set if and only if the memory type i in the VkPhysicalDeviceMemoryProperties structure for the physical device is supported for the resource.
propertiesThe demanded properties (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkBufferUsageFlagBits.html).
Returns
Memory type index i
See also
VulkanUniformBuffer::CreateBuffer
Since
Karma 1.0.0

◆ FindQueueFamilies()

QueueFamilyIndices Karma::FVulkanDynamicRHI::FindQueueFamilies ( VkPhysicalDevice device)

Queries the graphics card for available queue families and compares against the availability of graphics and presentation queues.

Parameters
deviceThe graphics card to be queired for queue family
Since
Karma 1.0.0

◆ FindSupportedFormat()

VkFormat Karma::FVulkanDynamicRHI::FindSupportedFormat ( const std::vector< VkFormat > & candidates,
VkImageTiling tiling,
VkFormatFeatureFlags features ) const

Finds a supported format from the list of candidate formats based on the desired tiling and features. Used in depth resource creation.

See also
KarmaGuiVulkanHandler::MakeRenderPassInfo
Since
Karma 1.0.0

◆ Get()

FVulkanDynamicRHI & Karma::FVulkanDynamicRHI::Get ( )
inlinestatic

Getter for the FVulkanDynamicRHI instance.

Since
Karma 1.0.0

◆ GetDevice()

FVulkanDevice * Karma::FVulkanDynamicRHI::GetDevice ( ) const
inline

Getter for FVulkanDevice object created in FVulkanDynamicRHI::SelectDevice().

Since
Karma 1.0.0

◆ GetGpuDeviceFeatures()

const VkPhysicalDeviceFeatures & Karma::FVulkanDynamicRHI::GetGpuDeviceFeatures ( ) const
inline

Getter for m_SupportedDeviceFeatures which contains boolean values for supported features like availability of geometry shader or sampler anisotropy.

Since
Karma 1.0.0

◆ GetGpuSwapChainSupportDetails()

const SwapChainSupportDetails & Karma::FVulkanDynamicRHI::GetGpuSwapChainSupportDetails ( ) const
inline

Getter for m_GPUSwapChainSupport struct which gets initialized in FVulkanDynamicRHI::IsDeviceSuitable().

Since
Karma 1.0.0

◆ GetInstance()

VkInstance Karma::FVulkanDynamicRHI::GetInstance ( ) const
inline

Getter for Vulkan instance.

Since
Karma 1.0.0

◆ GetValidationLayersSetting()

bool Karma::FVulkanDynamicRHI::GetValidationLayersSetting ( ) const
inline

Getter for the boolean bEnableValidationLayers.

For Debug builds bEnableValidationLayers is set to true

Since
Karma 1.0.0

◆ Init()

bool Karma::FVulkanDynamicRHI::Init ( )
overridevirtual

For initializing VulkanDynamic RHI.

Called from RHIInit() declared in KarmaRHI.h and defined in DynamicRHI.cpp

See also
FVulkanDynamicRHI::InitInstance()
Since
Karma 1.0.0

Implements Karma::FDynamicRHI.

◆ InitInstance()

void Karma::FVulkanDynamicRHI::InitInstance ( )

Calls FVulkanDevice::InitGPU() to create Vulkan logical device from selected GPU, and created appropriate resources (commandpool, default texture etc).

See also
FVulkanDevice::InitGPU()
Since
Karma 1.0.0

◆ Present()

virtual void Karma::FVulkanDynamicRHI::Present ( )
inlineoverridevirtual

Presents the rendered frame to the display.

Since
Karma 1.0.0

Implements Karma::FDynamicRHI.

◆ QuerySwapChainSupport()

SwapChainSupportDetails Karma::FVulkanDynamicRHI::QuerySwapChainSupport ( VkPhysicalDevice device)

Uses Two-Pass Query to gather surface formats (physical device and surface paired color space or pixel format data) and present modes data.

See also
VulkanContext::IsDeviceSuitable(), and VulkanContext::CreateSwapChain()
Since
Karma 1.0.0

◆ RegisterUniformBufferObject()

void Karma::FVulkanDynamicRHI::RegisterUniformBufferObject ( VulkanUniformBuffer * ubo)

Register a uniformbuffer object to curate an array or uniformbuffers.

Note
May be abstracted to FDynamicRHI.
In Unreal Engine, there is no single global “array of uniform buffers” that UpdateUniformBuffer walks; instead, each system owns its own uniform buffer(s) and explicitly passes them into UpdateUniformBuffer when something changes. Where the inputs come from Uniform buffers are created and owned by higher-level engine systems: Per-primitive: via FPrimitiveSceneInfo for object transforms, lighting, etc. Per-view / per-pass: view uniforms, fog, shadow parameters, etc. Per-material: FMaterialParameterCollectionInstance and other material parameter structs.

◆ SelectDevice()

void Karma::FVulkanDynamicRHI::SelectDevice ( )
protected

Picks an Engine appropriate GPU and creates FVulkanDevice.

Since
Karma 1.0.0

◆ SetupDebugMessenger()

void Karma::FVulkanDynamicRHI::SetupDebugMessenger ( )
protected

Sets up the debug messenger for Vulkan instance.

This function initializes the debug messenger that will handle debug messages from the Vulkan API. It populates the debug messenger create info structure and creates the debug messenger using the CreateDebugUtilsMessengerEXT function.

See also
FVulkanDynamicRHI::CreateDebugUtilsMessengerEXT()
Since
Karma 1.0.0

◆ Shutdown()

void Karma::FVulkanDynamicRHI::Shutdown ( )
overridevirtual

Shuts down the RHI.

Called from RHIExit() declared in KarmaRHI.h and defined in DynamicRHI.cpp

Cleans up resources and states used by the RHI.

Since
Karma 1.0.0

Implements Karma::FDynamicRHI.

◆ SwapChainImageCount()

uint32_t Karma::FVulkanDynamicRHI::SwapChainImageCount ( ) const
inline

Getter for the number of supported swapchain images.

Since
Karma 1.0.0

◆ UploadUniformBufferObjects()

void Karma::FVulkanDynamicRHI::UploadUniformBufferObjects ( size_t frameIndex)

Uploads data to the registered VulkanUniformBuffers for the specified frame index.

Typically called during rendering to update uniform buffer data for the current frame like so

vkCmdBeginRenderPass
vkCmdBindPipeline
vkCmdBindVertexBuffers
vkCmdBindIndexBuffer
vkCmdBindDescriptorSets // Descriptor sets include UBOs
vkCmdDrawIndexed
vkCmdEndRenderPass
void UploadUniformBufferObjects(size_t frameIndex)
Uploads data to the registered VulkanUniformBuffers for the specified frame index.
Definition VulkanRHI.cpp:563
Parameters
frameIndexThe index of the frame for which to upload UBO data
Note
The frameIndex is used to determine which uniform buffer to update, as multiple buffers may be used for double or triple buffering to avoid synchronization issues between CPU and GPU.
The uniform buffers are resized automatically based on MAX_FRAMES_IN_FLIGHT (number of images (to work upon (CPU side) whilst an image is being rendered (GPU side processing)) + 1)
See also
VulkanUniformBuffer::BufferCreation()
KarmaGuiRenderer::FrameRender, VulkanBuffer::UploadUniformBuffer
Since
Karma 1.0.0

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