vpr::Buffer class

} RAII wrapper around a VkBuffer object. Can be used for anything from VBOs+EBOs to compute storage buffers to uniform buffers. No initialization or resource creation is done until the CreateBuffer method is called: at this point, the size of the object must be submitted as this size is fixed after creating the VkBuffer object.

Public static functions

static void CreateStagingBuffer(const Device* dvc, const VkDeviceSize& size, VkBuffer& dest, Allocation& dest_memory_range)
Creates a staging buffer of given size, using the given (hopefully not used) VkBuffer handle and updating the members of the given Allocation struct.

Public functions

void CreateBuffer(const VkBufferUsageFlags& usage_flags, const VkMemoryPropertyFlags& memory_flags, const VkDeviceSize& size)
Creates underlying handles, binds a memory region from the allocator system, and prepares everything for use.
void CreateBuffer(const VkBufferCreateInfo& create_info, const VkMemoryPropertyFlags& memory_flags)
Creates underlying handles and binds a memory region from the allocator subsystem, but takes a VkBufferCreatInfo structure containing all the relevant required setup information.
void Destroy()
Destroys handles belonging to this object and attempts to free/unbind the memory region it used.
void CopyToMapped(const void* data, const VkDeviceSize& size, const VkDeviceSize& offset)
Maps this object, copies data to this object, then ensures to unmap this object.
void CopyTo(const Buffer* other_buffer, const VkCommandBuffer& cmd, const VkDeviceSize offset)
Copies the data in the given Buffer pointer to this object.
void CopyTo(const void* data, const VkCommandBuffer& transfer_cmd, const VkDeviceSize& copy_size, const VkDeviceSize& copy_offset)
Copys the data pointed to by the relevant parameter into a staging buffer, then records commands copying data from the staging object into the destination object.
void CopyTo(const void* data, CommandPool* cmd_pool, const VkQueue& transfer_queue, const VkDeviceSize& size, const VkDeviceSize& offset) deprecated
Copies data using a single command buffer submission form the given pool to the given queue.
void Update(const VkCommandBuffer& cmd, const VkDeviceSize& data_sz, const VkDeviceSize& offset, const void* data)
Used to update a sub-region of the buffer.
void Fill(const VkCommandBuffer& cmd, const VkDeviceSize sz, const VkDeviceSize offset, const uint32_t value)
Fills buffer with given value.

Function documentation

static void vpr::Buffer::CreateStagingBuffer(const Device* dvc, const VkDeviceSize& size, VkBuffer& dest, Allocation& dest_memory_range)

Creates a staging buffer of given size, using the given (hopefully not used) VkBuffer handle and updating the members of the given Allocation struct.

Adds both of those objects to a static pool, so that they can be cleaned up together independent of individual object scopes and lifetimes.

void vpr::Buffer::CreateBuffer(const VkBufferUsageFlags& usage_flags, const VkMemoryPropertyFlags& memory_flags, const VkDeviceSize& size)

Creates underlying handles, binds a memory region from the allocator system, and prepares everything for use.

Parameters
usage_flags The intended use of this buffer. If memory_flags is VK_MEMORY_PROPERTY_DEVICE_LOCAL, be sure to | your usage flag with VK_BUFFER_USAGE_TRANFER_SRC_BIT/VK_BUFFER_USAGE_TRANFER_DST_BIT based on which way you'll be passing resources
memory_flags for rendering resources larger than ~512 bytes, use VK_MEMORY_PROPERTY_DEVICE_LOCAL. Otherwise, consider using VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |'d with VK_MEMORY_PROPERTY_HOST_COHERENT bit, especially for things that are frequently updated like UBOs.
size

Does not load data, however

void vpr::Buffer::CopyToMapped(const void* data, const VkDeviceSize& size, const VkDeviceSize& offset)

Maps this object, copies data to this object, then ensures to unmap this object.

Parameters
data whatever you intend to copy. Some objects might have to be const_cast'ed
size size of data being copied, which can be much smaller than the total size
offset destination offset, but can be set to 0 if copying to the front of the buffer or if the copy size is equivalent to the buffer's total size.

void vpr::Buffer::CopyTo(const void* data, const VkCommandBuffer& transfer_cmd, const VkDeviceSize& copy_size, const VkDeviceSize& copy_offset)

Copys the data pointed to by the relevant parameter into a staging buffer, then records commands copying data from the staging object into the destination object.

The lifetime of the staging buffer will persist after the command is submitted: make sure to call FreeStagingBuffers() somewhat frequently, in order to ensure that excess host-side memory isn't being occupied/used.

void vpr::Buffer::CopyTo(const void* data, CommandPool* cmd_pool, const VkQueue& transfer_queue, const VkDeviceSize& size, const VkDeviceSize& offset)

Copies data using a single command buffer submission form the given pool to the given queue.

Attempt to use a transfer-specialized queue when available.

void vpr::Buffer::Update(const VkCommandBuffer& cmd, const VkDeviceSize& data_sz, const VkDeviceSize& offset, const void* data)

Used to update a sub-region of the buffer.

Cannot be called in an active renderpass.