|
KarmaEngine
Game Engine for practical learning and research purposes
|
The actual uniform buffer class with implemented function using Vulkan API. More...
#include <VulkanBuffer.h>


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 UniformBufferObject * | Create (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< UBODataPointer > | m_UniformList |
| List of uniforms to be uploaded. | |
| std::vector< ShaderDataType > | m_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. | |
The actual uniform buffer class with implemented function using Vulkan API.
| Karma::VulkanUniformBuffer::VulkanUniformBuffer | ( | std::vector< ShaderDataType > | dataTypes, |
| uint32_t | bindingPointIndex ) |
Constructor for Vulkan buffer. Calls VulkanUniformBuffer::BufferCreation().
| dataTypes | List 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 |
| bindingPointIndex | The binding of shader specified index |
|
virtual |
Destructor. For freeing up UBO resources, use VulkanUniformBuffer::ClearBuffer()
| 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.
| void Karma::VulkanUniformBuffer::ClearBuffer | ( | ) |
Frees up the resources by destroying the buffer object(s) and clearing memory.
| 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.
| size | The size, in bytes, of the buffer to be created |
| properties | The 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) |
| 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.
| typeFilter | A 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. |
| properties | The demanded properties (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkBufferUsageFlagBits.html). |
|
inline |
Getter for the uniform buffers.
|
overridevirtual |
Uploads (copies) the data from buffer memory (m_UniformBuffersMemory) to host-accessible (CPU) pointer, m_UniformList, to the beginning of the mapped range.
| frameIndex | The 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) |
Implements Karma::UniformBufferObject.