Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Renderer::Backend::Vulkan::CRingCommandContext Class Reference

A simple helper class to decouple command buffers rotation from frames presenting. More...

#include <RingCommandContext.h>

Collaboration diagram for Renderer::Backend::Vulkan::CRingCommandContext:

Classes

struct  RingItem
 

Public Types

using UploadBufferFunction = std::function< void(u8 *)>
 

Public Member Functions

 CRingCommandContext (CDevice *device, const size_t size, const uint32_t queueFamilyIndex, CSubmitScheduler &submitScheduler)
 
 ~CRingCommandContext ()
 
VkCommandBuffer GetCommandBuffer ()
 
void Flush ()
 Submits the current command buffer to the SubmitScheduler. More...
 
void FlushAndWait ()
 The same as Flush but also waits until it's completed. More...
 
void ScheduleUpload (CTexture *texture, const Format dataFormat, const void *data, const size_t dataSize, const uint32_t level, const uint32_t layer)
 Schedules uploads until next render pass or flush. More...
 
void ScheduleUpload (CTexture *texture, const Format dataFormat, const void *data, const size_t dataSize, const uint32_t xOffset, const uint32_t yOffset, const uint32_t width, const uint32_t height, const uint32_t level, const uint32_t layer)
 
void ScheduleUpload (CBuffer *buffer, const void *data, const uint32_t dataOffset, const uint32_t dataSize)
 
void ScheduleUpload (CBuffer *buffer, const uint32_t dataOffset, const uint32_t dataSize, const UploadBufferFunction &uploadFunction)
 

Private Member Functions

void Begin ()
 
void End ()
 
void ScheduleUpload (CBuffer *buffer, const uint32_t dataOffset, const uint32_t dataSize, const uint32_t acquiredOffset)
 
uint32_t AcquireFreeSpace (const uint32_t requiredSize, const uint32_t requiredAlignment)
 
uint32_t GetFreeSpaceOffset (const uint32_t requiredSize, const uint32_t requiredAlignment) const
 
void WaitUntilFree (RingItem &item)
 

Private Attributes

CDevicem_Device = nullptr
 
CSubmitSchedulerm_SubmitScheduler
 
std::unique_ptr< CBufferm_StagingBuffer
 
uint32_t m_StagingBufferFirst = 0
 
uint32_t m_StagingBufferCurrentFirst = 0
 
uint32_t m_StagingBufferLast = 0
 
uint32_t m_OptimalBufferCopyOffsetAlignment = 1
 
uint32_t m_MaxStagingBufferCapacity = 0
 
std::vector< RingItemm_Ring
 
size_t m_RingIndex = 0
 

Detailed Description

A simple helper class to decouple command buffers rotation from frames presenting.

It might be useful when sometimes we need to submit more work than we can usually have during a frame. For example if we need to upload something, an upload buffer is full and we can't extend it at the moment. Then the only way is to wait until uploading is done and submit more work.

Note
not thread-safe, should be created and used from the same thread.

Member Typedef Documentation

◆ UploadBufferFunction

Constructor & Destructor Documentation

◆ CRingCommandContext()

Renderer::Backend::Vulkan::CRingCommandContext::CRingCommandContext ( CDevice device,
const size_t  size,
const uint32_t  queueFamilyIndex,
CSubmitScheduler submitScheduler 
)

◆ ~CRingCommandContext()

Renderer::Backend::Vulkan::CRingCommandContext::~CRingCommandContext ( )

Member Function Documentation

◆ AcquireFreeSpace()

uint32_t Renderer::Backend::Vulkan::CRingCommandContext::AcquireFreeSpace ( const uint32_t  requiredSize,
const uint32_t  requiredAlignment 
)
private

◆ Begin()

void Renderer::Backend::Vulkan::CRingCommandContext::Begin ( )
private

◆ End()

void Renderer::Backend::Vulkan::CRingCommandContext::End ( )
private

◆ Flush()

void Renderer::Backend::Vulkan::CRingCommandContext::Flush ( )

Submits the current command buffer to the SubmitScheduler.

◆ FlushAndWait()

void Renderer::Backend::Vulkan::CRingCommandContext::FlushAndWait ( )

The same as Flush but also waits until it's completed.

It means it forces SubmitScheduler to submit all previously queued work to GPU.

◆ GetCommandBuffer()

VkCommandBuffer Renderer::Backend::Vulkan::CRingCommandContext::GetCommandBuffer ( )
Returns
the current available command buffer. If there is none waits until it appeared.

◆ GetFreeSpaceOffset()

uint32_t Renderer::Backend::Vulkan::CRingCommandContext::GetFreeSpaceOffset ( const uint32_t  requiredSize,
const uint32_t  requiredAlignment 
) const
private

◆ ScheduleUpload() [1/5]

void Renderer::Backend::Vulkan::CRingCommandContext::ScheduleUpload ( CBuffer buffer,
const uint32_t  dataOffset,
const uint32_t  dataSize,
const uint32_t  acquiredOffset 
)
private

◆ ScheduleUpload() [2/5]

void Renderer::Backend::Vulkan::CRingCommandContext::ScheduleUpload ( CBuffer buffer,
const uint32_t  dataOffset,
const uint32_t  dataSize,
const UploadBufferFunction uploadFunction 
)

◆ ScheduleUpload() [3/5]

void Renderer::Backend::Vulkan::CRingCommandContext::ScheduleUpload ( CBuffer buffer,
const void *  data,
const uint32_t  dataOffset,
const uint32_t  dataSize 
)

◆ ScheduleUpload() [4/5]

void Renderer::Backend::Vulkan::CRingCommandContext::ScheduleUpload ( CTexture texture,
const Format  dataFormat,
const void *  data,
const size_t  dataSize,
const uint32_t  level,
const uint32_t  layer 
)

Schedules uploads until next render pass or flush.

Note
doesn't save a command buffer returned by GetCommandBuffer during scheduling uploads, because it might be changed.

◆ ScheduleUpload() [5/5]

void Renderer::Backend::Vulkan::CRingCommandContext::ScheduleUpload ( CTexture texture,
const Format  dataFormat,
const void *  data,
const size_t  dataSize,
const uint32_t  xOffset,
const uint32_t  yOffset,
const uint32_t  width,
const uint32_t  height,
const uint32_t  level,
const uint32_t  layer 
)

◆ WaitUntilFree()

void Renderer::Backend::Vulkan::CRingCommandContext::WaitUntilFree ( RingItem item)
private

Member Data Documentation

◆ m_Device

CDevice* Renderer::Backend::Vulkan::CRingCommandContext::m_Device = nullptr
private

◆ m_MaxStagingBufferCapacity

uint32_t Renderer::Backend::Vulkan::CRingCommandContext::m_MaxStagingBufferCapacity = 0
private

◆ m_OptimalBufferCopyOffsetAlignment

uint32_t Renderer::Backend::Vulkan::CRingCommandContext::m_OptimalBufferCopyOffsetAlignment = 1
private

◆ m_Ring

std::vector<RingItem> Renderer::Backend::Vulkan::CRingCommandContext::m_Ring
private

◆ m_RingIndex

size_t Renderer::Backend::Vulkan::CRingCommandContext::m_RingIndex = 0
private

◆ m_StagingBuffer

std::unique_ptr<CBuffer> Renderer::Backend::Vulkan::CRingCommandContext::m_StagingBuffer
private

◆ m_StagingBufferCurrentFirst

uint32_t Renderer::Backend::Vulkan::CRingCommandContext::m_StagingBufferCurrentFirst = 0
private

◆ m_StagingBufferFirst

uint32_t Renderer::Backend::Vulkan::CRingCommandContext::m_StagingBufferFirst = 0
private

◆ m_StagingBufferLast

uint32_t Renderer::Backend::Vulkan::CRingCommandContext::m_StagingBufferLast = 0
private

◆ m_SubmitScheduler

CSubmitScheduler& Renderer::Backend::Vulkan::CRingCommandContext::m_SubmitScheduler
private

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