SleakEngine 0.1.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::RenderEngine::VulkanBuffer Class Reference

VMA-backed Vulkan buffer with staging uploads, batched copies, and a size-bucketed recycling pool. More...

#include <VulkanBuffer.hpp>

Inheritance diagram for Sleak::RenderEngine::VulkanBuffer:

Classes

struct  AsyncFlushResult
 Result of an async batched flush: the recorded command buffer plus staging resources to free later. More...
struct  PendingStagingCleanup
 A staging buffer awaiting release once its async copy has completed. More...

Public Member Functions

 VulkanBuffer (VkDevice device, VkPhysicalDevice physicalDevice, uint32_t size, BufferType type, VkCommandPool commandPool, VkQueue graphicsQueue)
 ~VulkanBuffer () override
void Cleanup () override
void * GetData () override
VkBuffer GetVkBuffer () const
bool Initialize (void *data) override
 Allocates the buffer (recycling a pooled one if a match exists) and uploads initial data, if any.
bool Map () override
 Maps host-visible memory for direct CPU writes.
void Unmap () override
void Update () override
void Update (void *data, size_t size) override
 Overwrites buffer contents, staging through a temporary buffer for device-local memory.
Public Member Functions inherited from Sleak::RenderEngine::BufferBase
const void * GetCPUShadowCopy () const
size_t GetCPUShadowCopySize () const
size_t GetSize ()
int GetSlot () const
BufferType GetType ()
uint32_t GetVertexFormat () const
 Registered custom vertex layout of this buffer; 0 means the engine default Vertex.
void SetSlot (int slot)
void SetVertexFormat (uint32_t handle)
 Tags the buffer with a VertexFormatRegistry handle so backends pick the matching pipeline.
void StoreCPUShadowCopy (const void *data, size_t size)
 Copies up to 128 bytes into the inline shadow-copy storage, clamping oversized input.
Public Member Functions inherited from Sleak::ResourceBase
virtual ~ResourceBase ()=default

Static Public Member Functions

static void AdvanceDeletionFrame ()
static void DestroyAllocator ()
 Destroys the staging pool and the allocator once every buffer is freed.
static void DiscardPendingCopies ()
static void DumpPerFrameAllocStats ()
static void FlushAllDeferredDeletions ()
static AsyncFlushResult FlushPendingCopiesAsync (VkSemaphore signalSemaphore)
static VmaAllocator GetAllocator ()
static VkDeviceSize GetDeviceLocalAllocatedBytes ()
static VkDeviceSize GetDeviceLocalHeapSize ()
static VkDeviceSize GetTotalAllocatedBytes ()
static void InitAllocator (VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device)
static void ProcessDeferredDeletions (uint32_t maxFramesInFlight)
static void SetBatchingEnabled (bool enabled)
static void SetPhysicalDevice (VkPhysicalDevice device)
static void UntrackAllocation (VkDeviceSize size)
static void UntrackAllocation (VkDeviceSize size, uint32_t memTypeIdx)

Additional Inherited Members

Protected Attributes inherited from Sleak::RenderEngine::BufferBase
bool bIsMapped = false
void * Data = nullptr
const void * m_cpuShadowCopy = nullptr
size_t m_cpuShadowCopySize = 0
char m_cpuShadowStorage [128] = {}
uint32_t m_vertexFormat = 0
size_t Size = 0
int Slot = 0
BufferType Type
Protected Attributes inherited from Sleak::ResourceBase
bool bIsInitialized
std::string Name

Detailed Description

VMA-backed Vulkan buffer with staging uploads, batched copies, and a size-bucketed recycling pool.

Definition at line 13 of file VulkanBuffer.hpp.

Constructor & Destructor Documentation

◆ VulkanBuffer()

Sleak::RenderEngine::VulkanBuffer::VulkanBuffer ( VkDevice device,
VkPhysicalDevice physicalDevice,
uint32_t size,
BufferType type,
VkCommandPool commandPool,
VkQueue graphicsQueue )

Definition at line 128 of file VulkanBuffer.cpp.

◆ ~VulkanBuffer()

Sleak::RenderEngine::VulkanBuffer::~VulkanBuffer ( )
override

Definition at line 139 of file VulkanBuffer.cpp.

Member Function Documentation

◆ AdvanceDeletionFrame()

void Sleak::RenderEngine::VulkanBuffer::AdvanceDeletionFrame ( )
inlinestatic

Definition at line 170 of file VulkanBuffer.hpp.

◆ Cleanup()

void Sleak::RenderEngine::VulkanBuffer::Cleanup ( )
overridevirtual

Hands the GPU buffer to deferred deletion, which keeps it alive until every frame and upload batch that may reference it has completed.

Implements Sleak::ResourceBase.

Definition at line 342 of file VulkanBuffer.cpp.

◆ DestroyAllocator()

void Sleak::RenderEngine::VulkanBuffer::DestroyAllocator ( )
static

Destroys the staging pool and the allocator once every buffer is freed.

Definition at line 63 of file VulkanBuffer.cpp.

◆ DiscardPendingCopies()

void Sleak::RenderEngine::VulkanBuffer::DiscardPendingCopies ( )
static

Frees an upload batch that was recorded but never submitted, along with its staging buffers. Only valid while the device is idle.

Definition at line 578 of file VulkanBuffer.cpp.

◆ DumpPerFrameAllocStats()

void Sleak::RenderEngine::VulkanBuffer::DumpPerFrameAllocStats ( )
static

Definition at line 817 of file VulkanBuffer.cpp.

◆ FlushAllDeferredDeletions()

void Sleak::RenderEngine::VulkanBuffer::FlushAllDeferredDeletions ( )
static

Definition at line 793 of file VulkanBuffer.cpp.

◆ FlushPendingCopiesAsync()

VulkanBuffer::AsyncFlushResult Sleak::RenderEngine::VulkanBuffer::FlushPendingCopiesAsync ( VkSemaphore signalSemaphore)
static

Definition at line 596 of file VulkanBuffer.cpp.

◆ GetAllocator()

VmaAllocator Sleak::RenderEngine::VulkanBuffer::GetAllocator ( )
inlinestatic

Definition at line 45 of file VulkanBuffer.hpp.

◆ GetData()

void * Sleak::RenderEngine::VulkanBuffer::GetData ( )
overridevirtual

Implements Sleak::RenderEngine::BufferBase.

Definition at line 396 of file VulkanBuffer.cpp.

◆ GetDeviceLocalAllocatedBytes()

VkDeviceSize Sleak::RenderEngine::VulkanBuffer::GetDeviceLocalAllocatedBytes ( )
static

Definition at line 849 of file VulkanBuffer.cpp.

◆ GetDeviceLocalHeapSize()

VkDeviceSize Sleak::RenderEngine::VulkanBuffer::GetDeviceLocalHeapSize ( )
static

Definition at line 819 of file VulkanBuffer.cpp.

◆ GetTotalAllocatedBytes()

VkDeviceSize Sleak::RenderEngine::VulkanBuffer::GetTotalAllocatedBytes ( )
static

Definition at line 813 of file VulkanBuffer.cpp.

◆ GetVkBuffer()

VkBuffer Sleak::RenderEngine::VulkanBuffer::GetVkBuffer ( ) const
inline

Definition at line 35 of file VulkanBuffer.hpp.

◆ InitAllocator()

void Sleak::RenderEngine::VulkanBuffer::InitAllocator ( VkInstance instance,
VkPhysicalDevice physicalDevice,
VkDevice device )
static

Creates the VMA allocator plus a staging pool whose blocks stay resident for the allocator's lifetime.

Definition at line 25 of file VulkanBuffer.cpp.

◆ Initialize()

bool Sleak::RenderEngine::VulkanBuffer::Initialize ( void * data)
overridevirtual

Allocates the buffer (recycling a pooled one if a match exists) and uploads initial data, if any.

Implements Sleak::ResourceBase.

Definition at line 143 of file VulkanBuffer.cpp.

◆ Map()

bool Sleak::RenderEngine::VulkanBuffer::Map ( )
overridevirtual

Maps host-visible memory for direct CPU writes.

Implements Sleak::RenderEngine::BufferBase.

Definition at line 371 of file VulkanBuffer.cpp.

◆ ProcessDeferredDeletions()

void Sleak::RenderEngine::VulkanBuffer::ProcessDeferredDeletions ( uint32_t maxFramesInFlight)
static

Definition at line 644 of file VulkanBuffer.cpp.

◆ SetBatchingEnabled()

void Sleak::RenderEngine::VulkanBuffer::SetBatchingEnabled ( bool enabled)
inlinestatic

Definition at line 72 of file VulkanBuffer.hpp.

◆ SetPhysicalDevice()

void Sleak::RenderEngine::VulkanBuffer::SetPhysicalDevice ( VkPhysicalDevice device)
static

Definition at line 835 of file VulkanBuffer.cpp.

◆ Unmap()

void Sleak::RenderEngine::VulkanBuffer::Unmap ( )
overridevirtual

Implements Sleak::RenderEngine::BufferBase.

Definition at line 384 of file VulkanBuffer.cpp.

◆ UntrackAllocation() [1/2]

void Sleak::RenderEngine::VulkanBuffer::UntrackAllocation ( VkDeviceSize size)
inlinestatic

Definition at line 177 of file VulkanBuffer.hpp.

◆ UntrackAllocation() [2/2]

void Sleak::RenderEngine::VulkanBuffer::UntrackAllocation ( VkDeviceSize size,
uint32_t memTypeIdx )
inlinestatic

Definition at line 180 of file VulkanBuffer.hpp.

◆ Update() [1/2]

void Sleak::RenderEngine::VulkanBuffer::Update ( )
overridevirtual

Implements Sleak::RenderEngine::BufferBase.

Definition at line 301 of file VulkanBuffer.cpp.

◆ Update() [2/2]

void Sleak::RenderEngine::VulkanBuffer::Update ( void * data,
size_t size )
overridevirtual

Overwrites buffer contents, staging through a temporary buffer for device-local memory.

Implements Sleak::RenderEngine::BufferBase.

Definition at line 306 of file VulkanBuffer.cpp.