NAP
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Public Attributes | List of all members
StructBuffer Class Referencefinal

#include <structbuffer.h>

Public Member Functions

 StructBuffer (Core &core)
 
 StructBuffer (Core &core, EMemoryUsage usage)
 
virtual bool init (utility::ErrorState &errorState) override
 
virtual uint getCount () const override
 
virtual size_t getSize () const override
 
virtual uint32 getElementSize () const override
 
virtual bool isInitialized () const override
 
bool setData (void *data, size_t size, utility::ErrorState &error)
 
- Public Member Functions inherited from GPUBuffer
 GPUBuffer (Core &core)
 
 GPUBuffer (Core &core, EMemoryUsage usage)
 
virtual ~GPUBuffer ()
 
virtual VkBuffer getBuffer () const
 
virtual const BufferDatagetBufferData () const
 
virtual VkBufferUsageFlags getBufferUsageFlags () const
 
void ensureUsage (VkBufferUsageFlags usage)
 
void asyncGetData (std::function< void(const void *, size_t)> copyFunction)
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

bool mClear = false
 Property 'Clear' If no fill policy is set, performs an initial clear-to-zero transfer operation on the device buffer on init() More...
 
ResourcePtr< StructFillPolicymFillPolicy = nullptr
 Property 'FillPolicy' Optional fill policy to fill the buffer with on initialization. More...
 
StructBufferDescriptor mDescriptor
 Property 'Descriptor' The descriptor that defines the buffer layout. More...
 
- Public Attributes inherited from GPUBuffer
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...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 
- Protected Member Functions inherited from GPUBuffer
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 inherited from GPUBuffer
RenderServicemRenderService = nullptr
 Handle to the render service. More...
 
std::vector< BufferDatamRenderBuffers
 Render accessible buffers. More...
 
std::vector< BufferDatamStagingBuffers
 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...
 

Description

GPU Buffer for storing (nested) data structures.

Allocates all required host (staging) and device buffers based on the specified properties.

The layout of the struct buffer is defined by a StructBufferDescriptor. This descriptor is used to denote the buffer layout, allocate the right amount of memory, and possibly store information on how fill the buffer accordingly. As the size of the buffer is determined by the descriptor, it is important that it matches the declaration of the shader variable it is bound to. Initialization of buffer bindings may fail otherwise.

If a 'FillPolicy' is available, the buffer will also be uploaded to immediately. Alternatively, 'Clear' sets all of the buffer values to zero on init(). 'FillPolicy' and 'Clear' are mutually exclusive and the former has priority over the latter.

Supported types are primitive types that can be mapped to VkFormat.

Template Parameters
Tprimitive value data type
PROPERTYproperty for identifying the buffer usage and access type
Inheritance diagram for StructBuffer:
StructBuffer Node1 StructBuffer Node2 GPUBuffer Node2->Node1 Node3 Resource Node3->Node2 Node4 Object Node4->Node3
[legend]
Collaboration diagram for StructBuffer:
StructBuffer Node1 StructBuffer Node2 GPUBuffer Node2->Node1 Node3 Resource Node3->Node2 Node4 Object Node4->Node3 Node5 RenderService Node5->Node2 mRenderService Node6 Service Node6->Node5 Node7 Signal< nap::RenderWindow & > Node7->Node5 windowRemoved windowAdded Node8 Signal< Args > Node8->Node2 bufferChanged Node9 ObjectPtr< nap::StructFill Policy > Node9->Node1 mFillPolicy Node10 ObjectPtrBase Node10->Node9 Node12 ObjectPtr< nap::UniformStruct > Node10->Node12 Node11 StructBufferDescriptor Node11->Node1 mDescriptor Node12->Node11 mElement
[legend]

Constructor & Destructor Documentation

◆ StructBuffer() [1/2]

StructBuffer ( Core core)

◆ StructBuffer() [2/2]

StructBuffer ( Core core,
EMemoryUsage  usage 
)

Member Function Documentation

◆ getCount()

virtual uint getCount ( ) const
overridevirtual
Returns
the number of elements in the buffer

Implements GPUBuffer.

◆ getElementSize()

virtual uint32 getElementSize ( ) const
overridevirtual
Returns
the element size in bytes

Implements GPUBuffer.

◆ getSize()

virtual size_t getSize ( ) const
overridevirtual
Returns
the size of the buffer in bytes

Implements GPUBuffer.

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initialize this buffer. This will allocate all required staging and device buffers based on the buffer properties. If a fill policy is available, the buffer will also be uploaded to immediately.

Reimplemented from GPUBuffer.

◆ isInitialized()

virtual bool isInitialized ( ) const
overridevirtual
Returns
whether this buffer is initialized

Implements GPUBuffer.

◆ setData()

bool setData ( void *  data,
size_t  size,
utility::ErrorState error 
)

Uploads data to the GPU based on the settings provided. This function automatically allocates GPU memory if required.

Parameters
datapointer to the block of data that needs to be uploaded.
sizethe size of the data in bytes
errorcontains the error if upload operation failed
Returns
if upload succeeded

Member Data Documentation

◆ mClear

bool mClear = false

Property 'Clear' If no fill policy is set, performs an initial clear-to-zero transfer operation on the device buffer on init()

◆ mDescriptor

Property 'Descriptor' The descriptor that defines the buffer layout.

◆ mFillPolicy

ResourcePtr<StructFillPolicy> mFillPolicy = nullptr

Property 'FillPolicy' Optional fill policy to fill the buffer with on initialization.