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

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

#include <CeresEngine/RenderAPI/GPUBufferObject.hpp>

Public Types

using RawBuffer = B< UInt8[]>
 The buffer type.
 

Public Member Functions

 GPUBufferPool (GPUDevice &device)
 Creates a new BufferPool object.
 
 GPUBufferPool (GPUDevice &device, const GPUBufferSize baseAllocationSize)
 Creates a new BufferPool object.
 
void reserve (const GPUBufferSize length)
 Reserves space in the pool.
 
template<typename T >
B< Tallocate ()
 Allocates a new object from the pool.
 
void reset () noexcept
 Resets the buffer pool.
 
bool empty () const noexcept
 Checks if the buffer pool is empty.
 
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 newLength)
 

Private Attributes

GPUDevicePtr device = nullptr
 The device to be used when allocating memory.
 
Vector< RawBufferbuffers {}
 A vector of allocated buffers.
 
GPUBufferSize next = 0
 The offset of the next allocated object.
 
GPUBufferSize length = 0
 The maximum buffer length.
 
const GPUBufferSize baseAlignment = 256
 The base alignment to be used for each object in pool.
 
const GPUBufferSize baseAllocationSize = 4 * 1024 * 1024
 The base allocation size used by the pool.
 

Detailed Description

template<template< typename > class B>
class CeresEngine::GPUBufferPool< B >

A template class that automatically manages a buffer pool.

This class will compute the required alignment (required by the GPU) and return references for objects of type T. In this pool, object sizes can vary and a call to allocate() will allocate a new buffer object.

Template Parameters
Bthe underlying buffer storage type

Member Typedef Documentation

◆ RawBuffer

template<template< typename > class B>
using CeresEngine::GPUBufferPool< B >::RawBuffer = B<UInt8[]>

The buffer type.

Constructor & Destructor Documentation

◆ GPUBufferPool() [1/2]

template<template< typename > class B>
CeresEngine::GPUBufferPool< B >::GPUBufferPool ( GPUDevice device)
inlineexplicit

Creates a new BufferPool object.

Parameters
deviceThe device to be used when allocating memory.

◆ GPUBufferPool() [2/2]

template<template< typename > class B>
CeresEngine::GPUBufferPool< B >::GPUBufferPool ( GPUDevice device,
const GPUBufferSize  baseAllocationSize 
)
inlineexplicit

Creates a new BufferPool object.

Parameters
deviceThe device to be used when allocating memory.
baseAllocationSizeThe base allocation size used by the pool.

Member Function Documentation

◆ allocate()

template<template< typename > class B>
template<typename T >
B< T > CeresEngine::GPUBufferPool< B >::allocate ( )
inline

Allocates a new object from the pool.

Returns
A buffer object pointing to the newly allocated object

◆ allocateBuffers()

template<template< typename > class B>
void CeresEngine::GPUBufferPool< B >::allocateBuffers ( const size_t  newLength)
inlineprivate

◆ empty()

template<template< typename > class B>
bool CeresEngine::GPUBufferPool< B >::empty ( ) const
inlinenoexcept

Checks if the buffer pool is empty.

Returns
true if the buffer pool is empty and has no allocated objects on it.

◆ flush()

template<template< typename > class B>
void CeresEngine::GPUBufferPool< 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<template< typename > class B>
void CeresEngine::GPUBufferPool< 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

◆ reserve()

template<template< typename > class B>
void CeresEngine::GPUBufferPool< B >::reserve ( const GPUBufferSize  length)
inline

Reserves space in the pool.

Parameters
lengthThe number of objects to fit in the buffer pool

◆ reset()

template<template< typename > class B>
void CeresEngine::GPUBufferPool< B >::reset ( )
inlinenoexcept

Resets the buffer pool.

Does not release any allocated buffer. This method must be called every frame to ensure that old buffers are reused.

Member Data Documentation

◆ baseAlignment

template<template< typename > class B>
const GPUBufferSize CeresEngine::GPUBufferPool< B >::baseAlignment = 256
private

The base alignment to be used for each object in pool.

◆ baseAllocationSize

template<template< typename > class B>
const GPUBufferSize CeresEngine::GPUBufferPool< B >::baseAllocationSize = 4 * 1024 * 1024
private

The base allocation size used by the pool.

◆ buffers

template<template< typename > class B>
Vector<RawBuffer> CeresEngine::GPUBufferPool< B >::buffers {}
private

A vector of allocated buffers.

Each buffer has mBaseAllocationSize bytes.

◆ device

The device to be used when allocating memory.

◆ length

template<template< typename > class B>
GPUBufferSize CeresEngine::GPUBufferPool< B >::length = 0
private

The maximum buffer length.

◆ next

template<template< typename > class B>
GPUBufferSize CeresEngine::GPUBufferPool< B >::next = 0
private

The offset of the next allocated object.


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