vengine  0.1.0
3D graphics engine made with Vulkan
Loading...
Searching...
No Matches
ven::Buffer Class Reference

Class for buffer. More...

#include <Buffer.hpp>

+ Collaboration diagram for ven::Buffer:

Public Member Functions

 Buffer (Device &device, VkDeviceSize instanceSize, uint32_t instanceCount, VkBufferUsageFlags usageFlags, VkMemoryPropertyFlags memoryPropertyFlags, VkDeviceSize minOffsetAlignment=1)
 
 ~Buffer ()
 
 Buffer (const Buffer &)=delete
 
Bufferoperator= (const Buffer &)=delete
 
VkResult map (VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0)
 Map a memory range of this buffer.
 
void unmap ()
 Unmap a mapped memory range.
 
void writeToBuffer (const void *data, VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0) const
 Copies the specified data to the mapped buffer.
 
VkResult flush (VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0) const
 Flush a memory range of the buffer to make it visible to the device.
 
VkDescriptorBufferInfo descriptorInfo (const VkDeviceSize size=VK_WHOLE_SIZE, const VkDeviceSize offset=0) const
 Create a buffer info descriptor.
 
VkResult invalidate (VkDeviceSize size=VK_WHOLE_SIZE, VkDeviceSize offset=0) const
 Invalidate a memory range of the buffer to make it visible to the host.
 
void writeToIndex (const void *data, const VkDeviceSize index) const
 Copies "instanceSize" bytes of data to the mapped buffer at an offset of index * alignmentSize.
 
VkResult flushIndex (const VkDeviceSize index) const
 Flush the memory range at index * alignmentSize of the buffer to make it visible to the device.
 
VkDescriptorBufferInfo descriptorInfoForIndex (const VkDeviceSize index) const
 Create a buffer info descriptor.
 
VkResult invalidateIndex (const VkDeviceSize index) const
 Invalidate a memory range of the buffer to make it visible to the host.
 
VkBuffer getBuffer () const
 
void * getMappedMemory () const
 
uint32_t getInstanceCount () const
 
VkDeviceSize getInstanceSize () const
 
VkDeviceSize getAlignmentSize () const
 
VkBufferUsageFlags getUsageFlags () const
 
VkMemoryPropertyFlags getMemoryPropertyFlags () const
 
VkDeviceSize getBufferSize () const
 

Static Private Member Functions

static VkDeviceSize getAlignment (VkDeviceSize instanceSize, VkDeviceSize minOffsetAlignment)
 Returns the minimum instance size required to be compatible with devices minOffsetAlignment.
 

Private Attributes

Devicem_device
 
void * m_mapped = nullptr
 
VkBuffer m_buffer = VK_NULL_HANDLE
 
VkDeviceMemory m_memory = VK_NULL_HANDLE
 
VkDeviceSize m_bufferSize
 
VkDeviceSize m_instanceSize
 
uint32_t m_instanceCount
 
VkDeviceSize m_alignmentSize
 
VkBufferUsageFlags m_usageFlags
 
VkMemoryPropertyFlags m_memoryPropertyFlags
 

Detailed Description

Class for buffer.

Definition at line 17 of file Buffer.hpp.

Constructor & Destructor Documentation

◆ Buffer() [1/2]

ven::Buffer::Buffer ( Device & device,
VkDeviceSize instanceSize,
uint32_t instanceCount,
VkBufferUsageFlags usageFlags,
VkMemoryPropertyFlags memoryPropertyFlags,
VkDeviceSize minOffsetAlignment = 1 )

Definition at line 13 of file buffer.cpp.

References ven::Device::createBuffer(), m_alignmentSize, m_buffer, m_bufferSize, m_instanceCount, m_memory, m_memoryPropertyFlags, and m_usageFlags.

+ Here is the call graph for this function:

◆ ~Buffer()

ven::Buffer::~Buffer ( )

Definition at line 19 of file buffer.cpp.

◆ Buffer() [2/2]

ven::Buffer::Buffer ( const Buffer & )
delete

Member Function Documentation

◆ descriptorInfo()

VkDescriptorBufferInfo ven::Buffer::descriptorInfo ( const VkDeviceSize size = VK_WHOLE_SIZE,
const VkDeviceSize offset = 0 ) const
inlinenodiscard

Create a buffer info descriptor.

Parameters
size(Optional) Size of the memory range of the descriptor
offset(Optional) Byte offset from beginning
Returns
VkDescriptorBufferInfo of specified offset and range

Definition at line 73 of file Buffer.hpp.

References m_buffer.

Referenced by descriptorInfoForIndex().

+ Here is the caller graph for this function:

◆ descriptorInfoForIndex()

VkDescriptorBufferInfo ven::Buffer::descriptorInfoForIndex ( const VkDeviceSize index) const
inlinenodiscard

Create a buffer info descriptor.

Parameters
indexSpecifies the region given by index * alignmentSize
Returns
VkDescriptorBufferInfo for instance at index

Definition at line 112 of file Buffer.hpp.

References descriptorInfo(), and m_alignmentSize.

+ Here is the call graph for this function:

◆ flush()

VkResult ven::Buffer::flush ( VkDeviceSize size = VK_WHOLE_SIZE,
VkDeviceSize offset = 0 ) const
nodiscard

Flush a memory range of the buffer to make it visible to the device.

Note
Only required for non-coherent memory
Parameters
size(Optional) Size of the memory range to flush. Pass VK_WHOLE_SIZE to flush the complete buffer range.
offset(Optional) Byte offset from beginning
Returns
VkResult of the flush call

Definition at line 53 of file buffer.cpp.

Referenced by flushIndex().

+ Here is the caller graph for this function:

◆ flushIndex()

VkResult ven::Buffer::flushIndex ( const VkDeviceSize index) const
inlinenodiscard

Flush the memory range at index * alignmentSize of the buffer to make it visible to the device.

Parameters
indexUsed in offset calculation

Definition at line 102 of file Buffer.hpp.

References flush(), and m_alignmentSize.

+ Here is the call graph for this function:

◆ getAlignment()

VkDeviceSize ven::Buffer::getAlignment ( VkDeviceSize instanceSize,
VkDeviceSize minOffsetAlignment )
staticprivate

Returns the minimum instance size required to be compatible with devices minOffsetAlignment.

Parameters
instanceSizeThe size of an instance
minOffsetAlignmentThe minimum required alignment, in bytes, for the offset member (eg minUniformBufferOffsetAlignment)
Returns
VkResult of the buffer mapping call

Definition at line 6 of file buffer.cpp.

◆ getAlignmentSize()

VkDeviceSize ven::Buffer::getAlignmentSize ( ) const
inlinenodiscard

Definition at line 129 of file Buffer.hpp.

References m_instanceSize.

◆ getBuffer()

VkBuffer ven::Buffer::getBuffer ( ) const
inlinenodiscard

Definition at line 125 of file Buffer.hpp.

References m_buffer.

◆ getBufferSize()

VkDeviceSize ven::Buffer::getBufferSize ( ) const
inlinenodiscard

Definition at line 132 of file Buffer.hpp.

References m_bufferSize.

◆ getInstanceCount()

uint32_t ven::Buffer::getInstanceCount ( ) const
inlinenodiscard

Definition at line 127 of file Buffer.hpp.

References m_instanceCount.

◆ getInstanceSize()

VkDeviceSize ven::Buffer::getInstanceSize ( ) const
inlinenodiscard

Definition at line 128 of file Buffer.hpp.

References m_instanceSize.

◆ getMappedMemory()

void * ven::Buffer::getMappedMemory ( ) const
inlinenodiscard

Definition at line 126 of file Buffer.hpp.

References m_mapped.

◆ getMemoryPropertyFlags()

VkMemoryPropertyFlags ven::Buffer::getMemoryPropertyFlags ( ) const
inlinenodiscard

Definition at line 131 of file Buffer.hpp.

References m_memoryPropertyFlags.

◆ getUsageFlags()

VkBufferUsageFlags ven::Buffer::getUsageFlags ( ) const
inlinenodiscard

Definition at line 130 of file Buffer.hpp.

References m_usageFlags.

◆ invalidate()

VkResult ven::Buffer::invalidate ( VkDeviceSize size = VK_WHOLE_SIZE,
VkDeviceSize offset = 0 ) const
nodiscard

Invalidate a memory range of the buffer to make it visible to the host.

Note
Only required for non-coherent memory
Parameters
size(Optional) Size of the memory range to invalidate. Pass VK_WHOLE_SIZE to invalidate the complete buffer range.
offset(Optional) Byte offset from beginning
Returns
VkResult of the invalidate call

Definition at line 63 of file buffer.cpp.

Referenced by invalidateIndex().

+ Here is the caller graph for this function:

◆ invalidateIndex()

VkResult ven::Buffer::invalidateIndex ( const VkDeviceSize index) const
inlinenodiscard

Invalidate a memory range of the buffer to make it visible to the host.

Note
Only required for non-coherent memory
Parameters
indexSpecifies the region to invalidate: index * alignmentSize
Returns
VkResult of the invalidate call

Definition at line 123 of file Buffer.hpp.

References invalidate(), and m_alignmentSize.

+ Here is the call graph for this function:

◆ map()

VkResult ven::Buffer::map ( VkDeviceSize size = VK_WHOLE_SIZE,
VkDeviceSize offset = 0 )

Map a memory range of this buffer.

If successful, mapped points to the specified buffer range.

Parameters
size(Optional) Size of the memory range to map. Pass VK_WHOLE_SIZE to map the complete buffer range.
offset(Optional) Byte offset from beginning
Returns
VkResult of the buffer mapping call

Definition at line 26 of file buffer.cpp.

Referenced by ven::Model::createIndexBuffer(), and ven::Model::createVertexBuffer().

+ Here is the caller graph for this function:

◆ operator=()

Buffer & ven::Buffer::operator= ( const Buffer & )
delete

◆ unmap()

void ven::Buffer::unmap ( )

Unmap a mapped memory range.

Note
Does not return a result as vkUnmapMemory can't fail

Definition at line 32 of file buffer.cpp.

◆ writeToBuffer()

void ven::Buffer::writeToBuffer ( const void * data,
VkDeviceSize size = VK_WHOLE_SIZE,
VkDeviceSize offset = 0 ) const

Copies the specified data to the mapped buffer.

Default value writes whole buffer range

Parameters
dataPointer to the data to copy
size(Optional) Size of the data to copy. Pass VK_WHOLE_SIZE to flush the complete buffer range.
offset(Optional) Byte offset from beginning of mapped region

Definition at line 40 of file buffer.cpp.

Referenced by writeToIndex().

+ Here is the caller graph for this function:

◆ writeToIndex()

void ven::Buffer::writeToIndex ( const void * data,
const VkDeviceSize index ) const
inline

Copies "instanceSize" bytes of data to the mapped buffer at an offset of index * alignmentSize.

Parameters
dataPointer to the data to copy
indexUsed in offset calculation

Definition at line 95 of file Buffer.hpp.

References m_alignmentSize, m_instanceSize, and writeToBuffer().

+ Here is the call graph for this function:

Member Data Documentation

◆ m_alignmentSize

VkDeviceSize ven::Buffer::m_alignmentSize
private

Definition at line 154 of file Buffer.hpp.

Referenced by Buffer(), descriptorInfoForIndex(), flushIndex(), invalidateIndex(), and writeToIndex().

◆ m_buffer

VkBuffer ven::Buffer::m_buffer = VK_NULL_HANDLE
private

Definition at line 148 of file Buffer.hpp.

Referenced by Buffer(), descriptorInfo(), and getBuffer().

◆ m_bufferSize

VkDeviceSize ven::Buffer::m_bufferSize
private

Definition at line 151 of file Buffer.hpp.

Referenced by Buffer(), and getBufferSize().

◆ m_device

Device& ven::Buffer::m_device
private

Definition at line 146 of file Buffer.hpp.

◆ m_instanceCount

uint32_t ven::Buffer::m_instanceCount
private

Definition at line 153 of file Buffer.hpp.

Referenced by Buffer(), and getInstanceCount().

◆ m_instanceSize

VkDeviceSize ven::Buffer::m_instanceSize
private

Definition at line 152 of file Buffer.hpp.

Referenced by getAlignmentSize(), getInstanceSize(), and writeToIndex().

◆ m_mapped

void* ven::Buffer::m_mapped = nullptr
private

Definition at line 147 of file Buffer.hpp.

Referenced by getMappedMemory().

◆ m_memory

VkDeviceMemory ven::Buffer::m_memory = VK_NULL_HANDLE
private

Definition at line 149 of file Buffer.hpp.

Referenced by Buffer().

◆ m_memoryPropertyFlags

VkMemoryPropertyFlags ven::Buffer::m_memoryPropertyFlags
private

Definition at line 156 of file Buffer.hpp.

Referenced by Buffer(), and getMemoryPropertyFlags().

◆ m_usageFlags

VkBufferUsageFlags ven::Buffer::m_usageFlags
private

Definition at line 155 of file Buffer.hpp.

Referenced by Buffer(), and getUsageFlags().


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