nngn
Loading...
Searching...
No Matches
nngn::StagingBuffer Class Reference

Manages staging buffers for a group of frames. More...

#include <staging.h>

Collaboration diagram for nngn::StagingBuffer:

Classes

struct  Allocation
 Result of a block allocation. More...
 
struct  Frame
 Data for a single frame. More...
 
struct  FreeBuffer
 Buffer in the free list, ready to be reused. More...
 
struct  MappedRegion
 Region mapped for writting. More...
 

Public Types

using Stats = GraphicsStats::Staging
 
using Stats = GraphicsStats::Staging
 

Public Member Functions

 StagingBuffer (void)=default
 
 ~StagingBuffer (void)
 Releases all buffers and device memory allocated.
 
void init (const Instance &inst, VkDevice dev, DeviceMemory *dev_mem, VkDeviceSize default_size)
 
Stats stats (std::size_t i) const
 
void resize (std::size_t n)
 Resizes to accommodate n frames.
 
bool write (std::size_t i, VkDeviceSize n, VkDeviceSize size, auto &&f)
 Writes data for a frame, allocating extra memory as necessary.
 
void destroy (std::size_t i)
 Releases resources for frame i.
 
 StagingBuffer (void)=default
 
 ~StagingBuffer (void)
 Releases all buffers and device memory allocated.
 
void init (const Instance &inst, VkDevice dev, DeviceMemory *dev_mem, VkDeviceSize default_size)
 
Stats stats (std::size_t i) const
 
void resize (std::size_t n)
 Resizes to accommodate n frames.
 
bool write (std::size_t i, VkDeviceSize n, VkDeviceSize size, auto &&f)
 Writes data for a frame, allocating extra memory as necessary.
 
void destroy (std::size_t i)
 Releases resources for frame i.
 

Private Member Functions

const DedicatedBuffercur_block (std::size_t i) const
 
DedicatedBuffercur_block (std::size_t i)
 
Allocation alloc (std::size_t i, VkDeviceSize n, VkDeviceSize size)
 Allocates at most n blocks of size bytes for frame i.
 
MappedRegion map (std::size_t i, VkDeviceSize n, VkDeviceSize size)
 Maps a writeable region, allocating if necessary.
 
void retire_free ()
 Removes old unused buffers from the free list.
 
const DedicatedBuffercur_block (std::size_t i) const
 
DedicatedBuffercur_block (std::size_t i)
 
Allocation alloc (std::size_t i, VkDeviceSize n, VkDeviceSize size)
 Allocates at most n blocks of size bytes for frame i.
 
MappedRegion map (std::size_t i, VkDeviceSize n, VkDeviceSize size)
 Maps a writeable region, allocating if necessary.
 
void retire_free ()
 Removes old unused buffers from the free list.
 

Private Attributes

std::vector< Frameframes = {}
 
std::vector< FreeBufferfree = {}
 
const Instanceinst = {}
 
VkDevice dev = {}
 
DeviceMemorydev_mem = {}
 
VkDeviceSize default_size = {}
 

Detailed Description

Manages staging buffers for a group of frames.

Allocates buffers and device memory in blocks as necessary for each new data block that is written.

Member Typedef Documentation

◆ Stats [1/2]

◆ Stats [2/2]

Constructor & Destructor Documentation

◆ StagingBuffer() [1/2]

nngn::StagingBuffer::StagingBuffer ( void  )
default

◆ ~StagingBuffer() [1/2]

nngn::StagingBuffer::~StagingBuffer ( void  )

Releases all buffers and device memory allocated.

◆ StagingBuffer() [2/2]

nngn::StagingBuffer::StagingBuffer ( void  )
default

◆ ~StagingBuffer() [2/2]

nngn::StagingBuffer::~StagingBuffer ( void  )

Releases all buffers and device memory allocated.

Member Function Documentation

◆ alloc() [1/2]

auto nngn::StagingBuffer::alloc ( std::size_t  i,
VkDeviceSize  n,
VkDeviceSize  size 
)
private

Allocates at most n blocks of size bytes for frame i.

Depending on the capacity cap of the current active block:

  1. if cap >= n * size, no allocation is performed
  2. if size <= cap && cap < n * size, no allocation is performed
  3. ifcap < size, a new block of size n * size is allocated In all cases, the returned allocation information has n equal to the number of blocks that should be written to the buffer, which may be less than the n parameter for case 2.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ alloc() [2/2]

Allocation nngn::StagingBuffer::alloc ( std::size_t  i,
VkDeviceSize  n,
VkDeviceSize  size 
)
private

Allocates at most n blocks of size bytes for frame i.

Depending on the capacity cap of the current active block:

  1. if cap >= n * size, no allocation is performed
  2. if size <= cap && cap < n * size, no allocation is performed
  3. ifcap < size, a new block of size n * size is allocated In all cases, the returned allocation information has n equal to the number of blocks that should be written to the buffer, which may be less than the n parameter for case 2.

◆ cur_block() [1/4]

DedicatedBuffer * nngn::StagingBuffer::cur_block ( std::size_t  i)
inlineprivate
Here is the call graph for this function:

◆ cur_block() [2/4]

DedicatedBuffer * nngn::StagingBuffer::cur_block ( std::size_t  i)
private

◆ cur_block() [3/4]

const DedicatedBuffer * nngn::StagingBuffer::cur_block ( std::size_t  i) const
inlineprivate
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cur_block() [4/4]

const DedicatedBuffer * nngn::StagingBuffer::cur_block ( std::size_t  i) const
private

◆ destroy() [1/2]

void nngn::StagingBuffer::destroy ( std::size_t  i)

Releases resources for frame i.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy() [2/2]

void nngn::StagingBuffer::destroy ( std::size_t  i)

Releases resources for frame i.

◆ init() [1/2]

void nngn::StagingBuffer::init ( const Instance inst,
VkDevice  dev,
DeviceMemory dev_mem,
VkDeviceSize  default_size 
)
inline
Here is the caller graph for this function:

◆ init() [2/2]

void nngn::StagingBuffer::init ( const Instance inst,
VkDevice  dev,
DeviceMemory dev_mem,
VkDeviceSize  default_size 
)

◆ map() [1/2]

auto nngn::StagingBuffer::map ( std::size_t  i,
VkDeviceSize  n,
VkDeviceSize  size 
)
private

Maps a writeable region, allocating if necessary.

Parameters
iframe index
nnumber of elements
sizesize of each element
Here is the call graph for this function:

◆ map() [2/2]

MappedRegion nngn::StagingBuffer::map ( std::size_t  i,
VkDeviceSize  n,
VkDeviceSize  size 
)
private

Maps a writeable region, allocating if necessary.

Parameters
iframe index
nnumber of elements
sizesize of each element

◆ resize() [1/2]

void nngn::StagingBuffer::resize ( std::size_t  n)
inline

Resizes to accommodate n frames.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize() [2/2]

void nngn::StagingBuffer::resize ( std::size_t  n)

Resizes to accommodate n frames.

◆ retire_free() [1/2]

void nngn::StagingBuffer::retire_free ( )
private

Removes old unused buffers from the free list.

A buffer is removed if it has not been used for a full cycle of the total number of frames (i.e. size(this->frames)) since it was allocated. Regardless of age, a minimum of size(this->frames) is kept in the list.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ retire_free() [2/2]

void nngn::StagingBuffer::retire_free ( )
private

Removes old unused buffers from the free list.

A buffer is removed if it has not been used for a full cycle of the total number of frames (i.e. size(this->frames)) since it was allocated. Regardless of age, a minimum of size(this->frames) is kept in the list.

◆ stats() [1/2]

auto nngn::StagingBuffer::stats ( std::size_t  i) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stats() [2/2]

Stats nngn::StagingBuffer::stats ( std::size_t  i) const

◆ write() [1/2]

bool nngn::StagingBuffer::write ( std::size_t  i,
VkDeviceSize  n,
VkDeviceSize  size,
auto &&  f 
)
inline

Writes data for a frame, allocating extra memory as necessary.

Parameters
iframe index
nnumber of elements
sizesize of each element
fCallable that generates the data. Parameters:
  • VkBuffer dst: target buffer
  • void *p: memory block
  • VkDeviceSize off: offset in dst
  • VkDeviceSize i: base index (<= n)
  • VkDeviceSize nw: number of elements (<= n - i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [2/2]

bool nngn::StagingBuffer::write ( std::size_t  i,
VkDeviceSize  n,
VkDeviceSize  size,
auto &&  f 
)

Writes data for a frame, allocating extra memory as necessary.

Parameters
iframe index
nnumber of elements
sizesize of each element
fCallable that generates the data. Parameters:
  • VkBuffer dst: target buffer
  • void *p: memory block
  • VkDeviceSize off: offset in dst
  • VkDeviceSize i: base index (<= n)
  • VkDeviceSize nw: number of elements (<= n - i)

Member Data Documentation

◆ default_size

VkDeviceSize nngn::StagingBuffer::default_size = {}
private

◆ dev

VkDevice nngn::StagingBuffer::dev = {}
private

◆ dev_mem

DeviceMemory * nngn::StagingBuffer::dev_mem = {}
private

◆ frames

std::vector< Frame > nngn::StagingBuffer::frames = {}
private

◆ free

std::vector< FreeBuffer > nngn::StagingBuffer::free = {}
private

◆ inst

const Instance * nngn::StagingBuffer::inst = {}
private

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