NAP
Public Member Functions | Public Attributes | List of all members
TypedGPUBufferNumeric< T > Class Template Reference

#include <gpubuffer.h>

Public Member Functions

 TypedGPUBufferNumeric (Core &core)
 
 TypedGPUBufferNumeric (Core &core, EMemoryUsage usage, bool storage)
 
virtual bool init (utility::ErrorState &errorState) override
 
bool setData (const std::vector< T > &data, utility::ErrorState &errorState)
 
virtual bool isInitialized () const override
 
- Public Member Functions inherited from GPUBufferNumeric
 GPUBufferNumeric (Core &core, VkFormat format, uint32 elementSize)
 
 GPUBufferNumeric (Core &core, VkFormat format, uint32 elementSize, EMemoryUsage usage)
 
virtual uint getCount () const override
 
virtual uint32 getElementSize () const override
 
virtual size_t getSize () const override
 
virtual VkFormat getFormat () const
 
virtual void setCount (uint32 count)
 
virtual bool setData (const void *data, size_t elementCount, size_t reservedElementCount, utility::ErrorState &errorState)
 
- 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< FillPolicy< T > > mFillPolicy = nullptr
 Property: 'FillPolicy' Optional fill policy to fill the buffer with on initialization. More...
 
- Public Attributes inherited from GPUBufferNumeric
uint32 mCount = 0
 Property: 'Count' The number of elements to initialize/allocate the buffer with. 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

template<typename T>
class nap::TypedGPUBufferNumeric< T >

Typed class for GPU numeric buffers.

Allocates all required host (staging) and device buffers based on the specified properties. 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.

This buffer (when 'storage' is set to 'true' on construction) can be bound to a descriptor in a shader. This allows the buffer be read and set inside a shader program.

Template Parameters
Tprimitive value data type
Inheritance diagram for TypedGPUBufferNumeric< T >:
[legend]
Collaboration diagram for TypedGPUBufferNumeric< T >:
[legend]

Constructor & Destructor Documentation

◆ TypedGPUBufferNumeric() [1/2]

Every numeric buffer needs to have access to the render engine.

Parameters
corereference to core

◆ TypedGPUBufferNumeric() [2/2]

TypedGPUBufferNumeric ( Core core,
EMemoryUsage  usage,
bool  storage 
)

Every numeric 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. Storage controls if the buffer can be bound to a shader using a descriptor, allowing it to be read / set inside a shader program.

Parameters
corereference to core
usagehow the buffer is used at runtime.
storageif the buffer can be bound to a shader using a descriptor

Member Function Documentation

◆ init()

bool init ( utility::ErrorState errorState)
overridevirtual

Initialize this buffer. This will allocate all required staging and device buffers based on the specified properties. 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.

Parameters
errorStatecontains the error if initialization fails

Reimplemented from GPUBuffer.

Reimplemented in IndexBuffer, and VertexBuffer< T >.

◆ isInitialized()

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

Implements GPUBuffer.

◆ setData()

bool setData ( const std::vector< T > &  data,
utility::ErrorState errorState 
)

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

Parameters
datavector containing the data to upload
errorStatecontains 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().

◆ mFillPolicy

ResourcePtr<FillPolicy<T> > mFillPolicy = nullptr

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