CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::TGPUBufferPool< T, B > Class Template Reference

A template class that automatically manages a uniform buffer pool. More...

#include <CeresEngine/RenderAPI/GPUBufferObject.hpp>

Public Types

using BufferType = B< UInt8 >
 The buffer type.
 

Public Member Functions

 TGPUBufferPool (GPUDevice &device)
 Creates a new TBufferPool object.
 
void reserve (const size_t length)
 Reserves space in the pool.
 
Toperator[] (const size_t index)
 Gets a reference to the Uniform Buffer block stored at index.
 
void flush (const GPUBufferSize offset=0, const GPUBufferSize size=GPUBuffer::whole)
 Flushes the cached memory data starting at offset with size bytes.
 
void invalidate (const GPUBufferSize offset=0, const GPUBufferSize size=GPUBuffer::whole)
 Invalidates the cached memory data starting at offset with size bytes.
 

Private Member Functions

void allocateBuffers (const size_t length)
 

Private Attributes

GPUDevicePtr device
 The device to be used when allocating memory.
 
Vector< BufferTypebuffers
 A vector of allocated buffers.
 
const size_t baseAllocationSize = 4 * 1024 * 1024
 The base allocation size used by the pool.
 
size_t mLength = 0
 

Static Private Attributes

static constexpr size_t alignment = ((sizeof(T) + 256 - 1) / 256) * 256
 The alignment to be used for each object in pool.
 

Detailed Description

template<typename T, template< typename > class B = GPUDynamicUniformBufferArray>
class CeresEngine::TGPUBufferPool< T, B >

A template class that automatically manages a uniform buffer pool.

This class will compute the required alignment (required by the GPU) and return references for objects of type T.

Template Parameters
Tthe object type stored inside the uniform buffer

Member Typedef Documentation

◆ BufferType

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
using CeresEngine::TGPUBufferPool< T, B >::BufferType = B<UInt8>

The buffer type.

Constructor & Destructor Documentation

◆ TGPUBufferPool()

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
CeresEngine::TGPUBufferPool< T, B >::TGPUBufferPool ( GPUDevice device)
inlineexplicit

Creates a new TBufferPool object.

Parameters
deviceThe device to be used when allocating memory.

Member Function Documentation

◆ allocateBuffers()

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
void CeresEngine::TGPUBufferPool< T, B >::allocateBuffers ( const size_t  length)
inlineprivate

◆ flush()

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
void CeresEngine::TGPUBufferPool< T, B >::flush ( const GPUBufferSize  offset = 0,
const GPUBufferSize  size = GPUBuffer::whole 
)
inline

Flushes the cached memory data starting at offset with size bytes.

Parameters
offsetThe starting offset to be flushed
sizeThe amount of bytes to be flushed

◆ invalidate()

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
void CeresEngine::TGPUBufferPool< T, B >::invalidate ( const GPUBufferSize  offset = 0,
const GPUBufferSize  size = GPUBuffer::whole 
)
inline

Invalidates the cached memory data starting at offset with size bytes.

Parameters
offsetThe starting offset to be flushed
sizeThe amount of bytes to be flushed

◆ operator[]()

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
T & CeresEngine::TGPUBufferPool< T, B >::operator[] ( const size_t  index)
inline

Gets a reference to the Uniform Buffer block stored at index.

Parameters
indexThe uniform buffer index to fetch
Returns
A reference to the uniform block

◆ reserve()

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
void CeresEngine::TGPUBufferPool< T, B >::reserve ( const size_t  length)
inline

Reserves space in the pool.

Parameters
lengthThe number of uniform objects to fit in the buffer

Member Data Documentation

◆ alignment

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
constexpr size_t CeresEngine::TGPUBufferPool< T, B >::alignment = ((sizeof(T) + 256 - 1) / 256) * 256
staticconstexprprivate

The alignment to be used for each object in pool.

◆ baseAllocationSize

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
const size_t CeresEngine::TGPUBufferPool< T, B >::baseAllocationSize = 4 * 1024 * 1024
private

The base allocation size used by the pool.

◆ buffers

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
Vector<BufferType> CeresEngine::TGPUBufferPool< T, B >::buffers
private

A vector of allocated buffers.

Each buffer has mBaseAllocationSize bytes.

◆ device

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
GPUDevicePtr CeresEngine::TGPUBufferPool< T, B >::device
private

The device to be used when allocating memory.

◆ mLength

template<typename T , template< typename > class B = GPUDynamicUniformBufferArray>
size_t CeresEngine::TGPUBufferPool< T, B >::mLength = 0
private

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