VPP  0.7
A high-level modern C++ API for Vulkan
Public Member Functions | Static Public Attributes | List of all members
vpp::Buffer< USAGE > Class Template Reference

Typed Vulkan buffer of specified purpose. Most functions operating on buffers require typed buffer, therefore this is the class you want to use most of the time. More...

#include <vppBuffer.hpp>

Inheritance diagram for vpp::Buffer< USAGE >:
vpp::Buf vpp::gvector< std::uint32_t, Buf::INDEX > vpp::gvector< VkDispatchIndirectCommand, Buf::INDIRECT > vpp::gvector< VkDrawIndexedIndirectCommand, Buf::INDIRECT > vpp::gvector< VkDrawIndirectCommand, Buf::INDIRECT > vpp::dgvector< ItemT, USAGE > vpp::gvector< ItemT, USAGE > vpp::Indices vpp::DispatchIndirectCommands vpp::IndexedIndirectCommands vpp::IndirectCommands

Public Member Functions

 Buffer ()
 Constructs null reference.
 
 Buffer (VkDeviceSize size, const Device &hDevice, unsigned int flags=0, unsigned int addUsage=0)
 Constructs a buffer of given size and usage (bitwise combination of EUsageFlags values), associated with given device.
 
 Buffer (VkDeviceSize size, const Device &hDevice, const std::vector< unsigned int > &queueFamilyIndices, unsigned int flags=0, unsigned int addUsage=0)
 Constructs a buffer of given size and usage (bitwise combination of EUsageFlags values), associated with given device. This constructor also takes a list of queue families allowed to access the buffer in concurrent mode.
 
template<unsigned int USAGE2>
 Buffer (const Buffer< USAGE2 > &other)
 Construct new reference to existing buffer, with compatible usage.
 
- Public Member Functions inherited from vpp::Buf
 Buf ()
 Constructs null reference.
 
 Buf (VkDeviceSize bufferSize, unsigned int usageMask, const Device &hDevice, unsigned int flags=0)
 Constructs a buffer of given size and usage (bitwise combination of EUsageFlags values), associated with given device.
 
 Buf (VkDeviceSize bufferSize, unsigned int usageMask, const Device &hDevice, const std::vector< unsigned int > &queueFamilyIndices, unsigned int flags=0)
 Constructs a buffer of given size and usage (bitwise combination of EUsageFlags values), associated with given device. This constructor also takes a list of queue families allowed to access the buffer in concurrent mode.
 
 operator bool () const
 Checks whether this is not a null reference.
 
VkBuffer handle () const
 Retrieves Vulkan handle of the buffer.
 
const Devicedevice () const
 Retrieves the device associated with the buffer.
 
VkDeviceSize size () const
 Retrieves the size of the buffer.
 
unsigned int getUsage () const
 Retrieves usage flags of the buffer.
 
template<class MemoryT >
MemoryT bindMemory (const MemProfile &memProfile) const
 Allocates and binds memory for the buffer.
 

Static Public Attributes

static const unsigned int usage = USAGE
 

Additional Inherited Members

- Public Types inherited from vpp::Buf
enum  EUsageFlags {
  SOURCE = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, TARGET = VK_BUFFER_USAGE_TRANSFER_DST_BIT, UNITEX = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, STORTEX = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT,
  UNIFORM = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, STORAGE = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, INDEX = VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VERTEX = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
  INDIRECT = VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT
}
 Buffer usage flags. Can be bitwise-combined to create multipurpose buffers. More...
 
enum  ECreationFlags { SPARSE_BINDING = VK_BUFFER_CREATE_SPARSE_BINDING_BIT, SPARSE_RESIDENCY = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT, SPARSE_ALIASED = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT }
 

Detailed Description

template<unsigned int USAGE>
class vpp::Buffer< USAGE >

Typed Vulkan buffer of specified purpose. Most functions operating on buffers require typed buffer, therefore this is the class you want to use most of the time.

Also note that VPP provides a container class gvector, which is derived from Buffer and offers STL-like interface.

In case of using Buffer class directly, you need to specify appropriate usage flags as the template parameter. It is a bitwise or of enumeration values inherited from Buf base class: Buf::SOURCE, Buf::TARGET, Buf::UNITEX, Buf::STORTEX, Buf::UNIFORM, Buf::STORAGE, Buf::INDEX, Buf::VERTEX, Buf::INDIRECT.

Buffers defined with Buf::INDEX, Buf::VERTEX and Buf::INDIRECT flags can serve as geometric data source for the rendering pipeline. This is the primary method for delivering the geometry.

Uniform buffers (Buf::UNIFORM) can provide auxiliary read-only data for rendering, e.g. transformation matrices.

Storage buffers (Buf::STORAGE) can be read and written in shaders, so they are a good way to define some computation workspace, exchange large block of data between shaders, or read back computation results to the CPU.

Uniform texel buffers (Buf::UNITEX, Buf::STORTEX) are special type of buffers which share some semantics with images, but have less restrictions regarding the size.

Transfer source buffers (Buf::SOURCE) can be used to transfer data on GPU level to other buffers or images. Their specific application is to participate in image or texture loading from the CPU memory to GPU. First, read the image binary data into the buffer on the CPU side, then execute cmdCopyBufferToImage() command.

Transfer target buffers (Buf::TARGET) can serve as data receivers. One possible application is reading rendered images back to CPU memory. This is exactly opposite process to the routine described above.

When the purpose of the buffer is determined, it is convenient to make a typedef like this:

Create the buffer using the constructor, which accepts size and device. The buffer object is reference-counted and may be passed by value.

Newly created buffer does not have any memory allocated yet. In order to allocate memory, you can choose one of the following ways:

See the docs of DeviceMemory, MappableDeviceMemory and MemProfile classes for more information on memory allocation.


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