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

The actual uniform buffer class with implemented function using Vulkan API. More...

#include <VulkanBuffer.h>

Inheritance diagram for Karma::VulkanUniformBuffer:
Collaboration diagram for Karma::VulkanUniformBuffer:

Public Member Functions

 VulkanUniformBuffer (std::vector< ShaderDataType > dataTypes, uint32_t bindingPointIndex)
 Constructor for Vulkan buffer. Calls VulkanUniformBuffer::BufferCreation().
 
virtual ~VulkanUniformBuffer ()
 Destructor. For freeing up UBO resources, use VulkanUniformBuffer::ClearBuffer()
 
void CreateBuffer (VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory)
 Creates Vulkan buffer (VKbuffer) for ubo use and allocates device memory appropriately.
 
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.
 
const std::vector< VkBuffer > & GetUniformBuffers () const
 Getter for the uniform buffers.
 
void ClearBuffer ()
 Frees up the resources by destroying the buffer object(s) and clearing memory.
 
void BufferCreation ()
 Based on MAX_FRAMES_IN_FLIGHT (number of images (to work upon (CPU side) whilst an image is being rendered (GPU side processing)) + 1), uniform buffers are created with appropriate buffer size.
 
void UploadUniformBuffer (size_t frameIndex) override
 Uploads (copies) the data from buffer memory (m_UniformBuffersMemory) to host-accessible (CPU) pointer, m_UniformList, to the beginning of the mapped range.
 
- Public Member Functions inherited from Karma::UniformBufferObject
 UniformBufferObject (std::vector< ShaderDataType > dataTypes, uint32_t bindingPointIndex)
 An agnostic constructor provided for precomputation of offset and buffer size.
 
virtual ~UniformBufferObject ()=default
 Pure virtual destructor and sub class should have appropriate implementation.
 
template<typename... T>
void UpdateUniforms (T &&... uniforms)
 Set the m_UniformList with latest supplied uniforms.
 
uint32_t GetBufferSize () const
 
const std::vector< UBODataPointer > & GetUniformList () const
 
const std::vector< ShaderDataType > & GetUniformDataType () const
 
const std::vector< uint32_t > & GetAlignedOffsets () const
 
const std::vector< uint32_t > & GetUniformSize () const
 
uint32_t GetBindingPointIndex () const
 

Additional Inherited Members

- Static Public Member Functions inherited from Karma::UniformBufferObject
static UniformBufferObjectCreate (std::vector< ShaderDataType > dataTypes, uint32_t bindingPointIndex)
 A function for appropriate initialization of UBO based on programmer selected rendered (Vulkan or OpenGL)
 
- Protected Member Functions inherited from Karma::UniformBufferObject
void CalculateOffsetsAndBufferSize ()
 Calculate offsets and buffer size of the uniform buffer object(s).
 
- Protected Attributes inherited from Karma::UniformBufferObject
uint32_t m_BufferSize
 Total size of the buffer in bytes.
 
uint32_t m_BindingPoint
 The binding point prescribed in vertex shader for instance https://github.com/ravimohan1991/KarmaEngine/blob/5ff57f5747c19efcea050646bc2d217c99d74015/Resources/Shaders/shader.vert#L14-L18.
 
std::vector< UBODataPointerm_UniformList
 List of uniforms to be uploaded.
 
std::vector< ShaderDataTypem_UniformDataType
 List of data types (ShaderDataType) for the m_UniformList.
 
std::vector< uint32_t > m_UniformAlignedOffsets
 List of individual uniform boundary aligned (with multiple of individual uniform size) offsets.
 
std::vector< uint32_t > m_UniformSizes
 List of individual uniform sizes.
 

Detailed Description

The actual uniform buffer class with implemented function using Vulkan API.

Since
Karma 1.0.0

Constructor & Destructor Documentation

◆ VulkanUniformBuffer()

Karma::VulkanUniformBuffer::VulkanUniformBuffer ( std::vector< ShaderDataType > dataTypes,
uint32_t bindingPointIndex )

Constructor for Vulkan buffer. Calls VulkanUniformBuffer::BufferCreation().

Parameters
dataTypesList of data types for uniforms to be uploaded to GPU (like used in shaders), for instance https://github.com/ravimohan1991/KarmaEngine/blob/138c172ccedf31acfab982af51ae130f9a37d3bb/Application/src/KarmaApp.cpp#L39 where Mat4 are for https://github.com/ravimohan1991/KarmaEngine/blob/138c172ccedf31acfab982af51ae130f9a37d3bb/Resources/Shaders/shader.vert#L9-L13
bindingPointIndexThe binding of shader specified index
Since
Karma 1.0.0

◆ ~VulkanUniformBuffer()

Karma::VulkanUniformBuffer::~VulkanUniformBuffer ( )
virtual

Destructor. For freeing up UBO resources, use VulkanUniformBuffer::ClearBuffer()

See also
VulkanContext::ClearUBO
Since
Karma 1.0.0

Member Function Documentation

◆ BufferCreation()

void Karma::VulkanUniformBuffer::BufferCreation ( )

Based on MAX_FRAMES_IN_FLIGHT (number of images (to work upon (CPU side) whilst an image is being rendered (GPU side processing)) + 1), uniform buffers are created with appropriate buffer size.

Since
Karma 1.0.0.

◆ ClearBuffer()

void Karma::VulkanUniformBuffer::ClearBuffer ( )

Frees up the resources by destroying the buffer object(s) and clearing memory.

Since
Karma 1.0.0

◆ CreateBuffer()

void Karma::VulkanUniformBuffer::CreateBuffer ( VkDeviceSize size,
VkBufferUsageFlags usage,
VkMemoryPropertyFlags properties,
VkBuffer & buffer,
VkDeviceMemory & bufferMemory )

Creates Vulkan buffer (VKbuffer) for ubo use and allocates device memory appropriately.

Parameters
sizeThe size, in bytes, of the buffer to be created
propertiesThe demanded properties (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkBufferUsageFlagBits.html). For instance (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
See also
VulkanUniformBuffer::BufferCreation()
Since
Karma 1.0.0

◆ FindMemoryType()

uint32_t Karma::VulkanUniformBuffer::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.

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
Since
Karma 1.0.0

◆ GetUniformBuffers()

const std::vector< VkBuffer > & Karma::VulkanUniformBuffer::GetUniformBuffers ( ) const
inline

Getter for the uniform buffers.

Since
Karma 1.0.0

◆ UploadUniformBuffer()

void Karma::VulkanUniformBuffer::UploadUniformBuffer ( size_t frameIndex)
overridevirtual

Uploads (copies) the data from buffer memory (m_UniformBuffersMemory) to host-accessible (CPU) pointer, m_UniformList, to the beginning of the mapped range.

Parameters
frameIndexThe m_CurrentFrame index representing index of MAX_FRAMES_IN_FLIGHT (number of images (to work upon (CPU side) whilst an image is being rendered (GPU side processing)) + 1)
See also
VulkanRendererAPI::SubmitCommandBuffers()
Since
Karma 1.0.0

Implements Karma::UniformBufferObject.


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