|
Vulkan Schnee 0.0.1
High-performance rendering engine
|
#include <VulkanStagedBuffer.h>
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 VulkanBuffer & | getBuffer () const |
| VulkanBuffer & | getBufferRef () |
| const VulkanBuffer & | getStagingBuffer () const |
| VulkanBuffer & | getStagingBufferRef () |
| 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 | |
| ApplicationContext * | context_ = nullptr |
| std::optional< VulkanBuffer > | buffer |
| std::optional< VulkanBuffer > | stagingBuffer |
| std::string | debugName_ |
| bool | usePersistentMapping_ = false |
| std::vector< PendingDeletion > | pendingDeletions |
Static Private Attributes | |
| static constexpr uint32_t | DELETION_DELAY_FRAMES = 6 |
Definition at line 14 of file VulkanStagedBuffer.h.
|
default |
| void EngineCore::VulkanStagedBuffer::create | ( | ApplicationContext * | context, |
| VkDeviceSize | size, | ||
| VkBufferUsageFlags | usage, | ||
| bool | persistentMapping = false ) |
Creates the staged buffer with device and staging buffers.
| context | Application context |
| size | Initial size in bytes |
| usage | Vulkan buffer usage flags |
| persistentMapping | If 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_.
| void EngineCore::VulkanStagedBuffer::destroy | ( | ) |
Definition at line 41 of file VulkanStagedBuffer.cpp.
References buffer, and stagingBuffer.
| 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.
| requiredSize | Minimum required size in bytes |
| usage | Vulkan buffer usage flags |
Definition at line 112 of file VulkanStagedBuffer.cpp.
References buffer, context_, debugName_, DELETION_DELAY_FRAMES, EngineCore::MIN_BUFFER_SIZE, pendingDeletions, stagingBuffer, and usePersistentMapping_.
|
inlinenodiscard |
Definition at line 62 of file VulkanStagedBuffer.h.
References buffer.
|
inlinenodiscard |
Definition at line 63 of file VulkanStagedBuffer.h.
References buffer.
|
nodiscard |
Gets the current size of the device buffer.
Definition at line 193 of file VulkanStagedBuffer.cpp.
References buffer.
|
inlinenodiscard |
Definition at line 64 of file VulkanStagedBuffer.h.
References stagingBuffer.
|
inlinenodiscard |
Definition at line 65 of file VulkanStagedBuffer.h.
References stagingBuffer.
|
inlinenodiscard |
Checks if there are buffers pending deletion.
Definition at line 60 of file VulkanStagedBuffer.h.
References pendingDeletions.
| 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.
| 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.
| VulkanStagedBufferSyncObjects EngineCore::VulkanStagedBuffer::upload | ( | const ApplicationContext * | context, |
| const void * | data, | ||
| VkDeviceSize | size ) |
Definition at line 47 of file VulkanStagedBuffer.cpp.
References 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)
| context | Application context |
| data | Pointer to data to upload |
| size | Size of data in bytes |
| offset | Offset into the device buffer where data should be written |
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().
|
private |
Definition at line 77 of file VulkanStagedBuffer.h.
Referenced by create(), destroy(), ensureSize(), getBuffer(), getBufferRef(), getSize(), setDebugName(), and uploadPartial().
|
private |
Definition at line 76 of file VulkanStagedBuffer.h.
Referenced by create(), and ensureSize().
|
private |
Definition at line 79 of file VulkanStagedBuffer.h.
Referenced by ensureSize(), and setDebugName().
|
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().
|
private |
Definition at line 88 of file VulkanStagedBuffer.h.
Referenced by ensureSize(), hasPendingDeletions(), and processPendingDeletions().
|
private |
Definition at line 78 of file VulkanStagedBuffer.h.
Referenced by create(), destroy(), ensureSize(), getStagingBuffer(), getStagingBufferRef(), setDebugName(), and uploadPartial().
|
private |
Definition at line 80 of file VulkanStagedBuffer.h.
Referenced by create(), ensureSize(), and uploadPartial().