Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
EngineCore::VulkanStagedBuffer Class Reference

#include <VulkanStagedBuffer.h>

Collaboration diagram for EngineCore::VulkanStagedBuffer:

Classes

struct  PendingDeletion
 Old buffers waiting to be deleted after all frames complete. More...

Public Member Functions

 VulkanStagedBuffer ()
void create (ApplicationContext *context, VkDeviceSize size, VkBufferUsageFlags usage, bool persistentMapping=false)
 Creates the staged buffer with device and staging buffers.
void destroy ()
VulkanStagedBufferSyncObjects upload (const ApplicationContext *context, const void *data, VkDeviceSize size)
VulkanStagedBufferSyncObjects uploadPartial (const ApplicationContext *context, const void *data, VkDeviceSize size, VkDeviceSize offset)
 Upload data to a specific offset in the buffer (for incremental updates)
bool ensureSize (VkDeviceSize requiredSize, VkBufferUsageFlags usage)
 Ensures the buffer is at least the required size. If resizing is needed, the old buffers are moved to pending deletion rather than destroyed immediately.
void processPendingDeletions ()
 Destroys all buffers that were pending deletion. Call this after all frames that might reference old buffers have completed.
bool hasPendingDeletions () const
 Checks if there are buffers pending deletion.
const VulkanBuffergetBuffer () const
VulkanBuffergetBufferRef ()
const VulkanBuffergetStagingBuffer () const
VulkanBuffergetStagingBufferRef ()
VkDeviceSize getSize () const
 Gets the current size of the device buffer.
void setDebugName (const std::string &name, std::optional< uint32_t > index=std::nullopt)

Private Attributes

ApplicationContextcontext_ = nullptr
std::optional< VulkanBufferbuffer
std::optional< VulkanBufferstagingBuffer
std::string debugName_
bool usePersistentMapping_ = false
std::vector< PendingDeletionpendingDeletions

Static Private Attributes

static constexpr uint32_t DELETION_DELAY_FRAMES = 6

Detailed Description

Definition at line 14 of file VulkanStagedBuffer.h.

Constructor & Destructor Documentation

◆ VulkanStagedBuffer()

EngineCore::VulkanStagedBuffer::VulkanStagedBuffer ( )
default

Member Function Documentation

◆ create()

void EngineCore::VulkanStagedBuffer::create ( ApplicationContext * context,
VkDeviceSize size,
VkBufferUsageFlags usage,
bool persistentMapping = false )

Creates the staged buffer with device and staging buffers.

Parameters
contextApplication context
sizeInitial size in bytes
usageVulkan buffer usage flags
persistentMappingIf true, staging buffer stays mapped for faster uploads. Use for frequently updated buffers. Default is false for backwards compatibility.

Definition at line 25 of file VulkanStagedBuffer.cpp.

References buffer, context_, stagingBuffer, and usePersistentMapping_.

◆ destroy()

void EngineCore::VulkanStagedBuffer::destroy ( )

Definition at line 41 of file VulkanStagedBuffer.cpp.

References buffer, and stagingBuffer.

◆ ensureSize()

bool EngineCore::VulkanStagedBuffer::ensureSize ( VkDeviceSize requiredSize,
VkBufferUsageFlags usage )

Ensures the buffer is at least the required size. If resizing is needed, the old buffers are moved to pending deletion rather than destroyed immediately.

Parameters
requiredSizeMinimum required size in bytes
usageVulkan buffer usage flags
Returns
true if the buffer was recreated (descriptor sets need updating)

Definition at line 112 of file VulkanStagedBuffer.cpp.

References buffer, context_, debugName_, DELETION_DELAY_FRAMES, EngineCore::MIN_BUFFER_SIZE, pendingDeletions, stagingBuffer, and usePersistentMapping_.

◆ getBuffer()

const VulkanBuffer & EngineCore::VulkanStagedBuffer::getBuffer ( ) const
inlinenodiscard

Definition at line 62 of file VulkanStagedBuffer.h.

References buffer.

◆ getBufferRef()

VulkanBuffer & EngineCore::VulkanStagedBuffer::getBufferRef ( )
inlinenodiscard

Definition at line 63 of file VulkanStagedBuffer.h.

References buffer.

◆ getSize()

VkDeviceSize EngineCore::VulkanStagedBuffer::getSize ( ) const
nodiscard

Gets the current size of the device buffer.

Returns
Buffer size in bytes, or 0 if not created

Definition at line 193 of file VulkanStagedBuffer.cpp.

References buffer.

◆ getStagingBuffer()

const VulkanBuffer & EngineCore::VulkanStagedBuffer::getStagingBuffer ( ) const
inlinenodiscard

Definition at line 64 of file VulkanStagedBuffer.h.

References stagingBuffer.

◆ getStagingBufferRef()

VulkanBuffer & EngineCore::VulkanStagedBuffer::getStagingBufferRef ( )
inlinenodiscard

Definition at line 65 of file VulkanStagedBuffer.h.

References stagingBuffer.

◆ hasPendingDeletions()

bool EngineCore::VulkanStagedBuffer::hasPendingDeletions ( ) const
inlinenodiscard

Checks if there are buffers pending deletion.

Returns
true if there are old buffers waiting to be deleted

Definition at line 60 of file VulkanStagedBuffer.h.

References pendingDeletions.

◆ processPendingDeletions()

void EngineCore::VulkanStagedBuffer::processPendingDeletions ( )

Destroys all buffers that were pending deletion. Call this after all frames that might reference old buffers have completed.

Definition at line 177 of file VulkanStagedBuffer.cpp.

References pendingDeletions.

◆ setDebugName()

void EngineCore::VulkanStagedBuffer::setDebugName ( const std::string & name,
std::optional< uint32_t > index = std::nullopt )

Definition at line 106 of file VulkanStagedBuffer.cpp.

References buffer, debugName_, and stagingBuffer.

◆ upload()

VulkanStagedBufferSyncObjects EngineCore::VulkanStagedBuffer::upload ( const ApplicationContext * context,
const void * data,
VkDeviceSize size )

Definition at line 47 of file VulkanStagedBuffer.cpp.

References uploadPartial().

Here is the call graph for this function:

◆ uploadPartial()

VulkanStagedBufferSyncObjects EngineCore::VulkanStagedBuffer::uploadPartial ( const ApplicationContext * context,
const void * data,
VkDeviceSize size,
VkDeviceSize offset )

Upload data to a specific offset in the buffer (for incremental updates)

Parameters
contextApplication context
dataPointer to data to upload
sizeSize of data in bytes
offsetOffset into the device buffer where data should be written
Returns
Sync objects for the transfer

Definition at line 53 of file VulkanStagedBuffer.cpp.

References EngineCore::VulkanStagedBufferSyncObjects::acquireBarrier, buffer, EngineCore::VulkanStagedBufferSyncObjects::copyObject, BufferCopyObject::destinationBuffer, BufferCopyObject::dstOffset, EngineCore::ApplicationContext::getVkGraphicsQueueFamilyIndex(), EngineCore::ApplicationContext::getVkTransferQueueFamilyIndex(), EngineCore::VulkanStagedBufferSyncObjects::releaseBarrier, BufferCopyObject::size, BufferCopyObject::sourceBuffer, EngineCore::STAGED_BUFFER_DST_STAGES, stagingBuffer, and usePersistentMapping_.

Referenced by upload().

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

Member Data Documentation

◆ buffer

std::optional<VulkanBuffer> EngineCore::VulkanStagedBuffer::buffer
private

◆ context_

ApplicationContext* EngineCore::VulkanStagedBuffer::context_ = nullptr
private

Definition at line 76 of file VulkanStagedBuffer.h.

Referenced by create(), and ensureSize().

◆ debugName_

std::string EngineCore::VulkanStagedBuffer::debugName_
private

Definition at line 79 of file VulkanStagedBuffer.h.

Referenced by ensureSize(), and setDebugName().

◆ DELETION_DELAY_FRAMES

uint32_t EngineCore::VulkanStagedBuffer::DELETION_DELAY_FRAMES = 6
staticconstexprprivate

Number of frames to keep old buffers alive Must be > MAX_FRAMES_IN_FLIGHT to ensure GPU work completes before deletion. Using 6 to account for: 2 frames in flight + transfer/graphics queue depth + safety margin.

Definition at line 93 of file VulkanStagedBuffer.h.

Referenced by ensureSize().

◆ pendingDeletions

std::vector<PendingDeletion> EngineCore::VulkanStagedBuffer::pendingDeletions
private

Definition at line 88 of file VulkanStagedBuffer.h.

Referenced by ensureSize(), hasPendingDeletions(), and processPendingDeletions().

◆ stagingBuffer

std::optional<VulkanBuffer> EngineCore::VulkanStagedBuffer::stagingBuffer
private

◆ usePersistentMapping_

bool EngineCore::VulkanStagedBuffer::usePersistentMapping_ = false
private

Definition at line 80 of file VulkanStagedBuffer.h.

Referenced by create(), ensureSize(), and uploadPartial().


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