SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
spark::render::vk::VulkanBuffer Class Reference

Vulkan implementation of IBuffer. More...

#include <VulkanBuffer.h>

Inheritance diagram for spark::render::vk::VulkanBuffer:
spark::render::vk::IVulkanBuffer spark::render::Resource< VkBuffer > spark::render::StateResource spark::render::IBuffer spark::render::IResource< VkBuffer > spark::render::IResource< VkBuffer > spark::render::IStateResource spark::render::IDeviceMemory spark::render::IMappable spark::render::IStateResource spark::render::vk::VulkanIndexBuffer spark::render::vk::VulkanVertexBuffer

Classes

struct  Impl
 

Public Member Functions

 VulkanBuffer (VkBuffer buffer, BufferType type, unsigned elements, std::size_t element_size, std::size_t alignment, bool writable, const VmaAllocator &allocator, const VmaAllocation &allocation, const std::string &name)
 
 VulkanBuffer (const VulkanBuffer &other)=delete
 
 VulkanBuffer (VulkanBuffer &&other) noexcept=delete
 
VulkanBufferoperator= (const VulkanBuffer &other)=delete
 
VulkanBufferoperator= (VulkanBuffer &&other) noexcept=delete
 
BufferType type () const override
 Gets the type of the buffer.
 
unsigned elements () const noexcept override
 Get the number of sub-resources in the memory chunk.
 
std::size_t size () const noexcept override
 Gets the size (in bytes) of the memory chunk.
 
std::size_t elementSize () const noexcept override
 Gets the size (in bytes) of one element in the memory chunk. If there is only one element, this equals the result of IDeviceMemory::size().
 
std::size_t elementAlignment () const override
 Gets the alignment of one element in the memory chunk.
 
std::size_t alignedElementSize () const noexcept override
 Gets the real size (in bytes) of the memory chunk.
 
bool writable () const noexcept override
 Checks if the resource can be bound to a read/write descriptor.
 
void map (const void *data, std::size_t size, unsigned element) override
 Maps the memory at data into the internal memory of the object.
 
void map (std::span< const void * > data, std::size_t element_size, unsigned first_element) override
 Maps the memory at data into the internal memory of the object.
 
void map (void *data, size_t size, unsigned element, bool write) override
 Maps the memory at data into the internal memory of the object.
 
void map (std::span< void * > data, size_t element_size, unsigned first_element, bool write) override
 Maps the memory at data into the internal memory of the object.
 
- Public Member Functions inherited from spark::render::IMappable
virtual void map (const void *data, std::size_t size, unsigned int element)=0
 Maps the memory at data into the internal memory of the object.
 
virtual void map (std::span< const void * > data, std::size_t element_size, unsigned int first_element)=0
 Maps the memory blocks within data into the internal memory of the object.
 
virtual void map (void *data, size_t size, unsigned int element=0, bool write=true)=0
 Maps the memory at data into the internal memory of the object.
 
virtual void map (std::span< void * > data, size_t element_size, unsigned int first_element=0, bool write=true)=0
 Maps the memory blocks within data into the internal memory of the object.
 
- Public Member Functions inherited from spark::render::Resource< VkBuffer >
 Resource (VkBuffer handle) noexcept
 Initializes the managed resource with the given handle.
 
 Resource (const Resource &other)=delete
 
 Resource (Resource &&other) noexcept=delete
 
Resourceoperator= (const Resource &other)=delete
 
Resourceoperator= (Resource &&other) noexcept=delete
 
const VkBuffer & handle () const final
 Gets the managed resource handle.
 
- Public Member Functions inherited from spark::render::StateResource
 StateResource (std::string_view name) noexcept
 Initializes a new StateResource instance.
 
 StateResource (const StateResource &other)=delete
 
 StateResource (StateResource &&other) noexcept
 
StateResourceoperator= (const StateResource &other)=delete
 
StateResourceoperator= (StateResource &&other) noexcept
 
const std::string & name () const noexcept final
 Gets the name of the state resource.
 

Static Public Member Functions

static std::unique_ptr< IVulkanBufferAllocate (BufferType type, unsigned elements, std::size_t element_size, std::size_t alignment, bool writable, const VmaAllocator &allocator, const VkBufferCreateInfo &create_info, const VmaAllocationCreateInfo &allocation_info, VmaAllocationInfo *allocation_result=nullptr)
 
static std::unique_ptr< IVulkanBufferAllocate (const std::string &name, BufferType type, unsigned elements, std::size_t element_size, std::size_t alignment, bool writable, const VmaAllocator &allocator, const VkBufferCreateInfo &create_info, const VmaAllocationCreateInfo &allocation_info, VmaAllocationInfo *allocation_result=nullptr)
 

Additional Inherited Members

- Public Types inherited from spark::render::IResource< VkBuffer >
using handle_type
 
- Protected Member Functions inherited from spark::render::Resource< VkBuffer >
VkBuffer & handle () final
 Gets the managed resource handle.
 
- Protected Member Functions inherited from spark::render::StateResource
 StateResource () noexcept
 Initializes a new StateResource instance with an empty name.
 
std::string & name () noexcept
 Gets the name of the state resource.
 

Detailed Description

Vulkan implementation of IBuffer.

Constructor & Destructor Documentation

◆ VulkanBuffer()

spark::render::vk::VulkanBuffer::VulkanBuffer ( VkBuffer buffer,
BufferType type,
unsigned elements,
std::size_t element_size,
std::size_t alignment,
bool writable,
const VmaAllocator & allocator,
const VmaAllocation & allocation,
const std::string & name )
explicit
Parameters
buffer
type
elements
element_size
alignment
writable
allocator
allocation
name

Member Function Documentation

◆ alignedElementSize()

std::size_t spark::render::vk::VulkanBuffer::alignedElementSize ( ) const
nodiscardoverridevirtualnoexcept

Gets the real size (in bytes) of the memory chunk.

Returns
The real size of the memory chunk in bytes.
Note
For images, this method will return a value that equals the result of IDeviceMemory::size(), aligned by IDeviceMemory::elementAlignment().

Implements spark::render::IDeviceMemory.

◆ Allocate() [1/2]

std::unique_ptr< IVulkanBuffer > spark::render::vk::VulkanBuffer::Allocate ( BufferType type,
unsigned elements,
std::size_t element_size,
std::size_t alignment,
bool writable,
const VmaAllocator & allocator,
const VkBufferCreateInfo & create_info,
const VmaAllocationCreateInfo & allocation_info,
VmaAllocationInfo * allocation_result = nullptr )
static
Parameters
type
elements
element_size
alignment
writable
allocator
create_info
allocation_info
allocation_result
Returns

◆ Allocate() [2/2]

std::unique_ptr< IVulkanBuffer > spark::render::vk::VulkanBuffer::Allocate ( const std::string & name,
BufferType type,
unsigned elements,
std::size_t element_size,
std::size_t alignment,
bool writable,
const VmaAllocator & allocator,
const VkBufferCreateInfo & create_info,
const VmaAllocationCreateInfo & allocation_info,
VmaAllocationInfo * allocation_result = nullptr )
static
Parameters
name
type
elements
element_size
alignment
writable
allocator
create_info
allocation_info
allocation_result
Returns

◆ elementAlignment()

std::size_t spark::render::vk::VulkanBuffer::elementAlignment ( ) const
nodiscardoverridevirtual

Gets the alignment of one element in the memory chunk.

Returns
The alignment of one element in the memory chunk.

Implements spark::render::IDeviceMemory.

◆ elements()

unsigned spark::render::vk::VulkanBuffer::elements ( ) const
nodiscardoverridevirtualnoexcept

Get the number of sub-resources in the memory chunk.

Returns
The number of array elements in the memory chunk.
Note
For buffers, this equals the number of array elements. For images, this equals the product of layers, levels and planes. This number represents the number of states, that can be obtained by calling the IDeviceMemory::state() method.

Implements spark::render::IDeviceMemory.

◆ elementSize()

std::size_t spark::render::vk::VulkanBuffer::elementSize ( ) const
nodiscardoverridevirtualnoexcept

Gets the size (in bytes) of one element in the memory chunk. If there is only one element, this equals the result of IDeviceMemory::size().

Returns
The size of one element in the memory chunk.
Note
For images, this method will return a value that equals the result of IDeviceMemory::size().

Implements spark::render::IDeviceMemory.

◆ map() [1/4]

void spark::render::vk::VulkanBuffer::map ( const void * data,
std::size_t size,
unsigned element )
override

Maps the memory at data into the internal memory of the object.

Parameters
dataAddress of the beginning of the data to map (in bytes).
sizeSize of the data to map.
elementThe array element to map the data to.

◆ map() [2/4]

void spark::render::vk::VulkanBuffer::map ( std::span< const void * > data,
std::size_t element_size,
unsigned first_element )
override

Maps the memory at data into the internal memory of the object.

Parameters
dataAddress of the beginning of the data to map (in bytes).
sizeSize of the data to map.
elementThe array element to map the data to.

◆ map() [3/4]

void spark::render::vk::VulkanBuffer::map ( std::span< void * > data,
size_t element_size,
unsigned first_element,
bool write )
override

Maps the memory at data into the internal memory of the object.

Parameters
dataAddress of the beginning of the data to map (in bytes).
sizeSize of the data to map.
elementThe array element to map the data to.

◆ map() [4/4]

void spark::render::vk::VulkanBuffer::map ( void * data,
size_t size,
unsigned element,
bool write )
override

Maps the memory at data into the internal memory of the object.

Parameters
dataAddress of the beginning of the data to map (in bytes).
sizeSize of the data to map.
elementThe array element to map the data to.

◆ size()

std::size_t spark::render::vk::VulkanBuffer::size ( ) const
nodiscardoverridevirtualnoexcept

Gets the size (in bytes) of the memory chunk.

Returns
The size of the memory chunk in bytes.
Note
The size of the device memory block depends on different factors. The actual used memory of one element can be obtained by calling by the IDeviceMemory::elementSize(). For different reasons, though, elements may be required to be aligned to a certain size. The size of one aligned element is returned by IDeviceMemory::alignedElementSize(). The size of the memory block, the elements get aligned to is returned by IDeviceMemory::elementAlignment().

Implements spark::render::IDeviceMemory.

◆ type()

BufferType spark::render::vk::VulkanBuffer::type ( ) const
nodiscardoverridevirtual

Gets the type of the buffer.

Returns
A BufferType representing the type of the buffer.

Implements spark::render::IBuffer.

◆ writable()

bool spark::render::vk::VulkanBuffer::writable ( ) const
nodiscardoverridevirtualnoexcept

Checks if the resource can be bound to a read/write descriptor.

Returns
true if the resource can be bound to a read/write descriptor, false otherwise.
Note
If the resource is not writable, attempting to bind it to a writable descriptor will result in an exception.

Implements spark::render::IDeviceMemory.