#include <gpubuffer.h>
Public Member Functions | |
GPUBuffer (Core &core) | |
GPUBuffer (Core &core, EMemoryUsage usage) | |
virtual | ~GPUBuffer () |
virtual VkBuffer | getBuffer () const |
virtual const BufferData & | getBufferData () const |
virtual bool | init (utility::ErrorState &errorState) override |
virtual uint | getCount () const =0 |
virtual size_t | getSize () const =0 |
virtual uint32 | getElementSize () const =0 |
virtual VkBufferUsageFlags | getBufferUsageFlags () const |
void | ensureUsage (VkBufferUsageFlags usage) |
virtual bool | isInitialized () const =0 |
void | asyncGetData (std::function< void(const void *, size_t)> copyFunction) |
![]() | |
Resource () | |
![]() | |
Object () | |
virtual | ~Object () |
virtual void | onDestroy () |
Object (Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&)=delete | |
Object & | operator= (Object &&)=delete |
Public Attributes | |
nap::Signal | bufferChanged |
EMemoryUsage | mMemoryUsage = EMemoryUsage::Static |
Property 'Usage' How the buffer is used: initialized once (Static), updated frequently from CPU to GPU (DynamicWrite) or read from GPU to CPU (DynamicRead). More... | |
![]() | |
std::string | mID |
Property: 'mID' unique name of the object. Used as an identifier by the system. More... | |
Protected Member Functions | |
bool | allocateInternal (size_t size, utility::ErrorState &errorState) |
bool | setDataInternal (const void *data, size_t size, size_t reservedSize, utility::ErrorState &errorState) |
void | requestClear () |
Protected Attributes | |
RenderService * | mRenderService = nullptr |
Handle to the render service. More... | |
std::vector< BufferData > | mRenderBuffers |
Render accessible buffers. More... | |
std::vector< BufferData > | mStagingBuffers |
Staging buffers, used when uploading or downloading data. More... | |
uint32 | mSize = 0 |
Current used buffer size in bytes. More... | |
int | mCurrentRenderBufferIndex = 0 |
Current render buffer index. More... | |
int | mCurrentStagingBufferIndex = 0 |
Current staging buffer index. More... | |
std::vector< int > | mDownloadStagingBufferIndices |
Staging buffer indices associated with a frameindex. More... | |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
Defines a Vulkan buffer object on the GPU.
A static buffer is updated (uploaded to) only once, a dynamic buffer can be updated more frequently but requires more resources and is 'generally' slower to draw, depending of the memory layout of the underlying hardware. It is not allowed to update a static buffer after the initial upload!
Note that static data is often placed in a different cache on the GPU, not accessible by the CPU, which allows for faster drawing times. 'DynamicWrite' buffers are uploaded into shared CPU / GPU memory and are therefore slower to access. Keep this in mind when selecting the appropriate memory usage.
Every buffer needs to have access to the render engine. The given 'usage' controls if a buffer can be updated more than once and in which memory space it is placed.
core | the nap core |
GPUBuffer | ( | Core & | core, |
EMemoryUsage | usage | ||
) |
Every buffer needs to have access to the render engine. The given 'usage' controls if a buffer can be updated more than once and in which memory space it is placed.
core | the nap core |
usage | how the buffer is used at runtime. |
|
virtual |
|
protected |
Allocates buffers, called by derived classes
size | size in bytes of the buffer to allocate |
errorState | contains error when data could not be set. |
void asyncGetData | ( | std::function< void(const void *, size_t)> | copyFunction | ) |
Starts a transfer of buffer data from GPU to CPU. Use this overload to pass your own copy function. This is a non blocking call.
copyFunction | the copy function to call when the buffer data is available for download. |
void ensureUsage | ( | VkBufferUsageFlags | usage | ) |
Ensures the given buffer usage flags are applied when allocating and creating the buffer, next to the flags derived from the 'Usage' property. Call this function before allocation.
usage | buffer usage flags required on allocation |
|
virtual |
|
virtual |
|
virtual |
|
pure virtual |
Implemented in GPUBufferNumeric, and StructBuffer.
|
pure virtual |
Implemented in GPUBufferNumeric, and StructBuffer.
|
pure virtual |
Implemented in GPUBufferNumeric, and StructBuffer.
|
overridevirtual |
Initialize the buffer
Reimplemented from Object.
Reimplemented in IndexBuffer, VertexBuffer< T >, TypedGPUBufferNumeric< T >, TypedGPUBufferNumeric< uint >, and StructBuffer.
|
pure virtual |
Implemented by derived classes
Implemented in TypedGPUBufferNumeric< T >, and StructBuffer.
|
protected |
Helper function that calls requestBufferClear() in RenderService for derived classes
|
protected |
Allocates and updates GPU buffer content, called by derived classes.
data | pointer to the data to upload. |
size | size in bytes of the data to upload |
reservedSize | allows the buffer to allocate more memory than required, needs to be >= size |
errorState | contains error when data could not be set. |
nap::Signal bufferChanged |
Called right after the buffer on the GPU has been updated.
|
protected |
Current render buffer index.
|
protected |
Current staging buffer index.
|
protected |
Staging buffer indices associated with a frameindex.
EMemoryUsage mMemoryUsage = EMemoryUsage::Static |
Property 'Usage' How the buffer is used: initialized once (Static), updated frequently from CPU to GPU (DynamicWrite) or read from GPU to CPU (DynamicRead).
|
protected |
Render accessible buffers.
|
protected |
Handle to the render service.
|
protected |
Current used buffer size in bytes.
|
protected |
Staging buffers, used when uploading or downloading data.