![]() |
VPP
0.8
A high-level modern C++ API for Vulkan
|
Generic STL-style vector allocating memory on the GPU. More...
#include <vppContainers.hpp>
Public Types | |
typedef ItemT * | iterator |
Random access iterator. | |
typedef const ItemT * | const_iterator |
Random access const iterator. | |
![]() | |
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 } |
Public Member Functions | |
gvector (size_t maxItemCount, MemProfile::ECharacteristic memProfile, const Device &hDevice) | |
Constructor. More... | |
iterator | begin () |
Iterator to begin of the vector. | |
iterator | end () |
Iterator to the end of the valid range (but not whole area). | |
const_iterator | cbegin () const |
Const iterator to begin of the vector. | |
const_iterator | cend () const |
Const iterator to the end of the valid range (but not whole area). | |
bool | empty () const |
Checks whether the valid range is empty. | |
size_t | size () const |
Returns the size of the valid range. | |
size_t | capacity () const |
Returns the size of the whole allocated area (maximum number of elements). | |
void | push_back (const ItemT &item) |
Adds element to the end of the valid range. | |
template<typename ... ArgsT> | |
void | emplace_back (ArgsT... args) |
Constructs element in place at the end of the valid range. | |
ItemT * | allocate_back () |
Allocates space for new item without constructing it. | |
void | resize (size_t newSize, const ItemT &value=ItemT()) |
Resizes the vector in proper way (constructing/destructing elements). More... | |
void | setSize (size_t newSize) |
Resizes the vector in dumb way (just setting the size without initialization). Use for numeric or vector types only. | |
void | clear () |
Empties the valid range. | |
ItemT & | operator[] (size_t index) const ItemT &operator[](size_t index) const |
Access to indexed element. More... | |
void | cmdCommit (CommandBuffer cmdBuffer, size_t firstItem=0, size_t nItems=std::numeric_limits< size_t >::max()) |
Generates a command ensuring that valid elements have been synchronized from host to device. Optionally can be restricted to a range. | |
void | cmdCommitAll (CommandBuffer cmdBuffer, size_t firstItem=0, size_t nItems=std::numeric_limits< size_t >::max()) |
Generates a command ensuring that entire memory area has been synchronized from host to device. Optionally can be restricted to a range. | |
void | cmdCommit (size_t firstItem=0, size_t nItems=std::numeric_limits< size_t >::max()) |
Generates a command (to implicit context) which ensures valid elements has been synchronized from host to device. | |
void | cmdCommitAll (size_t firstItem=0, size_t nItems=std::numeric_limits< size_t >::max()) |
Generates a command (to implicit context) which ensures that entire buffer area has been synchronized from host to device. | |
void | cmdLoad (CommandBuffer cmdBuffer, size_t firstItem=0, size_t nItems=std::numeric_limits< size_t >::max()) |
Generates a command ensuring that valid elements have been synchronized from device to host. Optionally can be restricted to a range. More... | |
void | cmdLoad (size_t firstItem=0, size_t nItems=std::numeric_limits< size_t >::max()) |
Generates a command (to implicit context) which ensures valid elements have been synchronized from device to host. More... | |
void | commit (EQueueType eQueue=Q_GRAPHICS, const Fence &signalFenceOnEnd=Fence(), const Semaphore &waitOnBegin=Semaphore(), const Semaphore &signalOnEnd=Semaphore()) |
Synchronizes entire buffer from host to device. More... | |
void | commitAndWait (EQueueType eQueue=Q_GRAPHICS) |
Synchronizes entire buffer from host to device and waits for completion. | |
void | load (EQueueType eQueue=Q_GRAPHICS, const Fence &signalFenceOnEnd=Fence(), const Semaphore &waitOnBegin=Semaphore(), const Semaphore &signalOnEnd=Semaphore()) |
Synchronizes entire buffer from device to host. More... | |
void | loadAndWait (EQueueType eQueue=Q_GRAPHICS) |
Synchronizes entire buffer from device to host and waits for completion. More... | |
void | cmdCopyToImage (CommandBuffer hCmdBuffer, const Img &img, VkImageLayout targetLayout, std::uint32_t mipLevel=0, std::uint32_t layer=0, const VkOffset3D &imageOffset=VkOffset3D { 0, 0, 0 }, const VkExtent3D &imageExtent=VkExtent3D { 0, 0, 0 }, VkDeviceSize bufferOffset=0, std::uint32_t bufferRowLength=0, std::uint32_t bufferImageHeight=0) |
Generates a command to copy the buffer contents to specified image. More... | |
void | cmdCopyToImage (const Img &img, VkImageLayout targetLayout, std::uint32_t mipLevel=0, std::uint32_t layer=0, const VkOffset3D &imageOffset=VkOffset3D { 0, 0, 0 }, const VkExtent3D &imageExtent=VkExtent3D { 0, 0, 0 }, VkDeviceSize bufferOffset=0, std::uint32_t bufferRowLength=0, std::uint32_t bufferImageHeight=0) |
Generates a command (to the default context) to copy the buffer contents to specified image. More... | |
void | copyToImage (EQueueType eQueue, const Img &img, VkImageLayout targetLayout, const Fence &signalFenceOnEnd=Fence(), const Semaphore &waitOnBegin=Semaphore(), const Semaphore &signalOnEnd=Semaphore(), std::uint32_t mipLevel=0, std::uint32_t layer=0, const VkOffset3D &imageOffset=VkOffset3D { 0, 0, 0 }, const VkExtent3D &imageExtent=VkExtent3D { 0, 0, 0 }, VkDeviceSize bufferOffset=0, std::uint32_t bufferRowLength=0, std::uint32_t bufferImageHeight=0) |
Submits a command to copy the buffer contents to specified image. More... | |
void | copyToImageAndWait (EQueueType eQueue, const Img &img, VkImageLayout targetLayout, std::uint32_t mipLevel=0, std::uint32_t layer=0, const VkOffset3D &imageOffset=VkOffset3D { 0, 0, 0 }, const VkExtent3D &imageExtent=VkExtent3D { 0, 0, 0 }, VkDeviceSize bufferOffset=0, std::uint32_t bufferRowLength=0, std::uint32_t bufferImageHeight=0) |
Submits a command to copy the buffer contents to specified image, waits for completion. More... | |
void | cmdCopyFromImage (CommandBuffer hCmdBuffer, const Img &img, VkImageLayout sourceImageLayout, std::uint32_t mipLevel=0, std::uint32_t layer=0, const VkOffset3D &imageOffset=VkOffset3D { 0, 0, 0 }, const VkExtent3D &imageExtent=VkExtent3D { 0, 0, 0 }, VkDeviceSize bufferOffset=0, std::uint32_t bufferRowLength=0, std::uint32_t bufferImageHeight=0) |
Generates a command to copy the buffer contents from specified image. More... | |
void | cmdCopyFromImage (const Img &img, VkImageLayout sourceImageLayout, std::uint32_t mipLevel=0, std::uint32_t layer=0, const VkOffset3D &imageOffset=VkOffset3D { 0, 0, 0 }, const VkExtent3D &imageExtent=VkExtent3D { 0, 0, 0 }, VkDeviceSize bufferOffset=0, std::uint32_t bufferRowLength=0, std::uint32_t bufferImageHeight=0) |
Generates a command (to the default context) to copy the buffer contents from specified image. More... | |
void | copyFromImage (EQueueType eQueue, const Img &img, VkImageLayout sourceImageLayout, const Fence &signalFenceOnEnd=Fence(), const Semaphore &waitOnBegin=Semaphore(), const Semaphore &signalOnEnd=Semaphore(), std::uint32_t mipLevel=0, std::uint32_t layer=0, const VkOffset3D &imageOffset=VkOffset3D { 0, 0, 0 }, const VkExtent3D &imageExtent=VkExtent3D { 0, 0, 0 }, VkDeviceSize bufferOffset=0, std::uint32_t bufferRowLength=0, std::uint32_t bufferImageHeight=0) |
Submits a command to copy the buffer contents from specified image. More... | |
void | copyFromImageAndWait (EQueueType eQueue, const Img &img, VkImageLayout sourceImageLayout, std::uint32_t mipLevel=0, std::uint32_t layer=0, const VkOffset3D &imageOffset=VkOffset3D { 0, 0, 0 }, const VkExtent3D &imageExtent=VkExtent3D { 0, 0, 0 }, VkDeviceSize bufferOffset=0, std::uint32_t bufferRowLength=0, std::uint32_t bufferImageHeight=0) |
Submits a command to copy the buffer contents from specified image. Waits for completion. More... | |
![]() | |
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. | |
![]() | |
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 Device & | device () 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. | |
![]() | |
MemoryBinding () | |
Constructs null reference. | |
MemoryBinding (const Buffer< USAGE > &res, const MemProfile &memProfile) | |
Binds memory to a buffer and constructs MemoryBinding object. | |
const Buffer< USAGE > & | resource () const |
Retrieves the buffer. | |
DeviceMemory & | memory () |
Retrieves the memory object. | |
Additional Inherited Members | |
![]() | |
static const unsigned int | usage = USAGE |
Generic STL-style vector allocating memory on the GPU.
gvector is general purpose container for GPU data. Depending on the USAGE template parameter, it can be used for various data buffers used in graphics and compute shaders. Single gvector instance may have multiple uses, hence the parameter is bitwise OR of following values:
The vector usually allocates memory on GPU side, but it is also accessible on CPU side in a way depending on the value of memProfile parameter of the constructor. This parameter can have the following values:
Typically just use DEVICE_STATIC.
Object of this class is reference-counted and may be passed by value. Generally, functions accepting a buffer, bound buffer and certain kinds of views, do accept a gvector instance as well. Therefore you can fill a gvector with e.g. vertex, index, indirect or uniform data and bind it directly. Texel buffers require creating a view explicitly but this view also accepts gvector as data source.
vpp::gvector< ItemT, USAGE >::gvector | ( | size_t | maxItemCount, |
MemProfile::ECharacteristic | memProfile, | ||
const Device & | hDevice | ||
) |
Constructor.
The vector has fixed capacity, but varying number of valid elements (size).
void vpp::gvector< ItemT, USAGE >::cmdCopyFromImage | ( | CommandBuffer | hCmdBuffer, |
const Img & | img, | ||
VkImageLayout | sourceImageLayout, | ||
std::uint32_t | mipLevel = 0 , |
||
std::uint32_t | layer = 0 , |
||
const VkOffset3D & | imageOffset = VkOffset3D { 0, 0, 0 } , |
||
const VkExtent3D & | imageExtent = VkExtent3D { 0, 0, 0 } , |
||
VkDeviceSize | bufferOffset = 0 , |
||
std::uint32_t | bufferRowLength = 0 , |
||
std::uint32_t | bufferImageHeight = 0 |
||
) |
Generates a command to copy the buffer contents from specified image.
Caution: may generate other auxiliary commands as well. Changes the layout of the image from sourceImageLayout
to VK_IMAGE_LAYOUT_GENERAL
.
void vpp::gvector< ItemT, USAGE >::cmdCopyFromImage | ( | const Img & | img, |
VkImageLayout | sourceImageLayout, | ||
std::uint32_t | mipLevel = 0 , |
||
std::uint32_t | layer = 0 , |
||
const VkOffset3D & | imageOffset = VkOffset3D { 0, 0, 0 } , |
||
const VkExtent3D & | imageExtent = VkExtent3D { 0, 0, 0 } , |
||
VkDeviceSize | bufferOffset = 0 , |
||
std::uint32_t | bufferRowLength = 0 , |
||
std::uint32_t | bufferImageHeight = 0 |
||
) |
Generates a command (to the default context) to copy the buffer contents from specified image.
Caution: may generate other auxiliary commands as well. Changes the layout of the image from sourceImageLayout
to VK_IMAGE_LAYOUT_GENERAL
.
void vpp::gvector< ItemT, USAGE >::cmdCopyToImage | ( | CommandBuffer | hCmdBuffer, |
const Img & | img, | ||
VkImageLayout | targetLayout, | ||
std::uint32_t | mipLevel = 0 , |
||
std::uint32_t | layer = 0 , |
||
const VkOffset3D & | imageOffset = VkOffset3D { 0, 0, 0 } , |
||
const VkExtent3D & | imageExtent = VkExtent3D { 0, 0, 0 } , |
||
VkDeviceSize | bufferOffset = 0 , |
||
std::uint32_t | bufferRowLength = 0 , |
||
std::uint32_t | bufferImageHeight = 0 |
||
) |
Generates a command to copy the buffer contents to specified image.
Caution: may generate other auxiliary commands as well. The vector must explicitly list Buf::SOURCE flag in order to be able to use this function.
void vpp::gvector< ItemT, USAGE >::cmdCopyToImage | ( | const Img & | img, |
VkImageLayout | targetLayout, | ||
std::uint32_t | mipLevel = 0 , |
||
std::uint32_t | layer = 0 , |
||
const VkOffset3D & | imageOffset = VkOffset3D { 0, 0, 0 } , |
||
const VkExtent3D & | imageExtent = VkExtent3D { 0, 0, 0 } , |
||
VkDeviceSize | bufferOffset = 0 , |
||
std::uint32_t | bufferRowLength = 0 , |
||
std::uint32_t | bufferImageHeight = 0 |
||
) |
Generates a command (to the default context) to copy the buffer contents to specified image.
Caution: may generate other auxiliary commands as well. The vector must explicitly list Buf::SOURCE flag in order to be able to use this function.
void vpp::gvector< ItemT, USAGE >::cmdLoad | ( | CommandBuffer | cmdBuffer, |
size_t | firstItem = 0 , |
||
size_t | nItems = std::numeric_limits< size_t >::max() |
||
) |
Generates a command ensuring that valid elements have been synchronized from device to host. Optionally can be restricted to a range.
Caution: the vector must explicitly list Buf::SOURCE flag in order to be able to use this function.
void vpp::gvector< ItemT, USAGE >::cmdLoad | ( | size_t | firstItem = 0 , |
size_t | nItems = std::numeric_limits< size_t >::max() |
||
) |
Generates a command (to implicit context) which ensures valid elements have been synchronized from device to host.
Caution: the vector must explicitly list Buf::SOURCE flag in order to be able to use this function.
void vpp::gvector< ItemT, USAGE >::commit | ( | EQueueType | eQueue = Q_GRAPHICS , |
const Fence & | signalFenceOnEnd = Fence() , |
||
const Semaphore & | waitOnBegin = Semaphore() , |
||
const Semaphore & | signalOnEnd = Semaphore() |
||
) |
Synchronizes entire buffer from host to device.
Submits a command to specified queue. Does not wait for completion, uses specified semaphores and fence.
void vpp::gvector< ItemT, USAGE >::copyFromImage | ( | EQueueType | eQueue, |
const Img & | img, | ||
VkImageLayout | sourceImageLayout, | ||
const Fence & | signalFenceOnEnd = Fence() , |
||
const Semaphore & | waitOnBegin = Semaphore() , |
||
const Semaphore & | signalOnEnd = Semaphore() , |
||
std::uint32_t | mipLevel = 0 , |
||
std::uint32_t | layer = 0 , |
||
const VkOffset3D & | imageOffset = VkOffset3D { 0, 0, 0 } , |
||
const VkExtent3D & | imageExtent = VkExtent3D { 0, 0, 0 } , |
||
VkDeviceSize | bufferOffset = 0 , |
||
std::uint32_t | bufferRowLength = 0 , |
||
std::uint32_t | bufferImageHeight = 0 |
||
) |
Submits a command to copy the buffer contents from specified image.
Caution: may generate other auxiliary commands as well. Changes the layout of the image from sourceImageLayout
to VK_IMAGE_LAYOUT_GENERAL
.
void vpp::gvector< ItemT, USAGE >::copyFromImageAndWait | ( | EQueueType | eQueue, |
const Img & | img, | ||
VkImageLayout | sourceImageLayout, | ||
std::uint32_t | mipLevel = 0 , |
||
std::uint32_t | layer = 0 , |
||
const VkOffset3D & | imageOffset = VkOffset3D { 0, 0, 0 } , |
||
const VkExtent3D & | imageExtent = VkExtent3D { 0, 0, 0 } , |
||
VkDeviceSize | bufferOffset = 0 , |
||
std::uint32_t | bufferRowLength = 0 , |
||
std::uint32_t | bufferImageHeight = 0 |
||
) |
Submits a command to copy the buffer contents from specified image. Waits for completion.
Caution: may generate other auxiliary commands as well. Changes the layout of the image from sourceImageLayout
to VK_IMAGE_LAYOUT_GENERAL
.
void vpp::gvector< ItemT, USAGE >::copyToImage | ( | EQueueType | eQueue, |
const Img & | img, | ||
VkImageLayout | targetLayout, | ||
const Fence & | signalFenceOnEnd = Fence() , |
||
const Semaphore & | waitOnBegin = Semaphore() , |
||
const Semaphore & | signalOnEnd = Semaphore() , |
||
std::uint32_t | mipLevel = 0 , |
||
std::uint32_t | layer = 0 , |
||
const VkOffset3D & | imageOffset = VkOffset3D { 0, 0, 0 } , |
||
const VkExtent3D & | imageExtent = VkExtent3D { 0, 0, 0 } , |
||
VkDeviceSize | bufferOffset = 0 , |
||
std::uint32_t | bufferRowLength = 0 , |
||
std::uint32_t | bufferImageHeight = 0 |
||
) |
Submits a command to copy the buffer contents to specified image.
Caution: may generate other auxiliary commands as well. The vector must explicitly list Buf::SOURCE flag in order to be able to use this function.
void vpp::gvector< ItemT, USAGE >::copyToImageAndWait | ( | EQueueType | eQueue, |
const Img & | img, | ||
VkImageLayout | targetLayout, | ||
std::uint32_t | mipLevel = 0 , |
||
std::uint32_t | layer = 0 , |
||
const VkOffset3D & | imageOffset = VkOffset3D { 0, 0, 0 } , |
||
const VkExtent3D & | imageExtent = VkExtent3D { 0, 0, 0 } , |
||
VkDeviceSize | bufferOffset = 0 , |
||
std::uint32_t | bufferRowLength = 0 , |
||
std::uint32_t | bufferImageHeight = 0 |
||
) |
Submits a command to copy the buffer contents to specified image, waits for completion.
Caution: may generate other auxiliary commands as well. The vector must explicitly list Buf::SOURCE flag in order to be able to use this function.
void vpp::gvector< ItemT, USAGE >::load | ( | EQueueType | eQueue = Q_GRAPHICS , |
const Fence & | signalFenceOnEnd = Fence() , |
||
const Semaphore & | waitOnBegin = Semaphore() , |
||
const Semaphore & | signalOnEnd = Semaphore() |
||
) |
Synchronizes entire buffer from device to host.
Submits a command to specified queue. Does not wait for completion, uses specified semaphores and fence.
Caution: the vector must explicitly list Buf::SOURCE flag in order to be able to use this function.
void vpp::gvector< ItemT, USAGE >::loadAndWait | ( | EQueueType | eQueue = Q_GRAPHICS | ) |
Synchronizes entire buffer from device to host and waits for completion.
Caution: the vector must explicitly list Buf::SOURCE flag in order to be able to use this function.
ItemT& vpp::gvector< ItemT, USAGE >::operator[] | ( | size_t | index | ) | const & |
Access to indexed element.
Access to const indexed element.
void vpp::gvector< ItemT, USAGE >::resize | ( | size_t | newSize, |
const ItemT & | value = ItemT() |
||
) |
Resizes the vector in proper way (constructing/destructing elements).
This does not allocate/deallocate any memory nor invalidate iterators. The capacity of the vector is static. Resizing it only affects the number of valid items inside the vector.