Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
foray::util::DualBuffer Class Reference

Helper class for organizing CPU -> GPU data synchronisation. In flight data is stored on host side, and copied to GPU right before being used. More...

#include <foray_dualbuffer.hpp>

Inheritance diagram for foray::util::DualBuffer:
foray::NoMoveDefaults

Public Member Functions

void Create (core::Context *context, const core::ManagedBuffer::CreateInfo &devicebufferCreateInfo, uint32_t stageBufferCount=INFLIGHT_FRAME_COUNT)
 Creates the dualbuffer setup.
 
virtual void StageFullBuffer (uint32_t frameIndex, const void *data)
 Updates the entire staging buffer.
 
virtual void StageSection (uint32_t frameIndex, const void *data, size_t destOffset, size_t size)
 Updates a section of a staging buffer.
 
virtual void CmdCopyToDevice (uint32_t frameIndex, VkCommandBuffer cmdBuffer)
 Writes commands required to copy the changes recorded in the indexed staging buffer to the device buffer.
 
virtual void CmdPrepareForRead (VkCommandBuffer cmdBuffer, VkPipelineStageFlags2 dstStageMask, VkAccessFlags2 dstAccessMask) const
 Prepares the device buffer for read access with a pipeline barrier (must be called before read access happens to the buffer)
 
virtual VkBufferMemoryBarrier2 MakeBarrierPrepareForRead (VkPipelineStageFlags2 dstStageMask, VkAccessFlags2 dstAccessMask) const
 Returns a barrier which prepares the device buffer for read access.
 
bool Exists () const
 
std::string GetName () const
 
DualBufferSetName (std::string_view name)
 
VkDescriptorBufferInfo GetVkDescriptorInfo () const
 
VkBuffer GetDeviceVkBuffer () const
 
void Destroy ()
 
virtual ~DualBuffer ()
 
- Public Member Functions inherited from foray::NoMoveDefaults
 NoMoveDefaults ()=default
 
 NoMoveDefaults (const NoMoveDefaults &other)=delete
 
 NoMoveDefaults (NoMoveDefaults &&other)=default
 
NoMoveDefaultsoperator= (const NoMoveDefaults &other)=delete
 

Protected Attributes

std::vector< void * > mStagingBufferMaps
 Memory locations the permanently mapped staging buffers are mapped to.
 
std::vector< std::unique_ptr< core::ManagedBuffer > > mStagingBuffers
 Permanently mapped host-local staging buffers (one per frame in flight)
 
std::vector< std::vector< VkBufferCopy > > mBufferCopies
 Record of all buffer copies submitted. Added to when writing to staging buffers, cleared when building the commandbuffer.
 
core::ManagedBuffer mDeviceBuffer
 The buffer used by the device.
 

Detailed Description

Helper class for organizing CPU -> GPU data synchronisation. In flight data is stored on host side, and copied to GPU right before being used.

Temporarily stores CPU-calculated states in staging buffers (1x per frame in flight) The GPU can retrieve the CPU-side data as needed via a copy command

Uploading Data

Reading data

Constructor & Destructor Documentation

◆ ~DualBuffer()

virtual foray::util::DualBuffer::~DualBuffer ( )
inlinevirtual

Member Function Documentation

◆ CmdCopyToDevice()

virtual void foray::util::DualBuffer::CmdCopyToDevice ( uint32_t  frameIndex,
VkCommandBuffer  cmdBuffer 
)
virtual

Writes commands required to copy the changes recorded in the indexed staging buffer to the device buffer.

Remarks
This will mirror any buffer copies submitted via 'StageSection'/'StageFullBuffer' calls before

◆ CmdPrepareForRead()

virtual void foray::util::DualBuffer::CmdPrepareForRead ( VkCommandBuffer  cmdBuffer,
VkPipelineStageFlags2  dstStageMask,
VkAccessFlags2  dstAccessMask 
) const
virtual

Prepares the device buffer for read access with a pipeline barrier (must be called before read access happens to the buffer)

◆ Create()

void foray::util::DualBuffer::Create ( core::Context context,
const core::ManagedBuffer::CreateInfo devicebufferCreateInfo,
uint32_t  stageBufferCount = INFLIGHT_FRAME_COUNT 
)

Creates the dualbuffer setup.

Parameters
devicebufferCreateInfoUsed to initate the drawside buffer. Same size is used for staging buffers

◆ Destroy()

void foray::util::DualBuffer::Destroy ( )

◆ Exists()

bool foray::util::DualBuffer::Exists ( ) const
inline

◆ GetDeviceVkBuffer()

VkBuffer foray::util::DualBuffer::GetDeviceVkBuffer ( ) const
inline

◆ GetName()

std::string foray::util::DualBuffer::GetName ( ) const
inline

◆ GetVkDescriptorInfo()

VkDescriptorBufferInfo foray::util::DualBuffer::GetVkDescriptorInfo ( ) const
inline

◆ MakeBarrierPrepareForRead()

virtual VkBufferMemoryBarrier2 foray::util::DualBuffer::MakeBarrierPrepareForRead ( VkPipelineStageFlags2  dstStageMask,
VkAccessFlags2  dstAccessMask 
) const
virtual

Returns a barrier which prepares the device buffer for read access.

◆ SetName()

DualBuffer & foray::util::DualBuffer::SetName ( std::string_view  name)

◆ StageFullBuffer()

virtual void foray::util::DualBuffer::StageFullBuffer ( uint32_t  frameIndex,
const void *  data 
)
virtual

Updates the entire staging buffer.

◆ StageSection()

virtual void foray::util::DualBuffer::StageSection ( uint32_t  frameIndex,
const void *  data,
size_t  destOffset,
size_t  size 
)
virtual

Updates a section of a staging buffer.

Member Data Documentation

◆ mBufferCopies

std::vector<std::vector<VkBufferCopy> > foray::util::DualBuffer::mBufferCopies
protected

Record of all buffer copies submitted. Added to when writing to staging buffers, cleared when building the commandbuffer.

◆ mDeviceBuffer

core::ManagedBuffer foray::util::DualBuffer::mDeviceBuffer
protected

The buffer used by the device.

◆ mStagingBufferMaps

std::vector<void*> foray::util::DualBuffer::mStagingBufferMaps
protected

Memory locations the permanently mapped staging buffers are mapped to.

◆ mStagingBuffers

std::vector<std::unique_ptr<core::ManagedBuffer> > foray::util::DualBuffer::mStagingBuffers
protected

Permanently mapped host-local staging buffers (one per frame in flight)


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