|
Vulkan Schnee 0.0.1
High-performance rendering engine
|
RAII wrapper for Vulkan buffer and device memory. More...
#include <Buffer.h>
Public Member Functions | |
| Buffer (Buffer &&other) noexcept | |
| Buffer & | operator= (Buffer &&other) noexcept |
| Buffer () | |
| Default constructor - uses EngineManager singleton to get Vulkan handles. | |
| Buffer (VkDevice device, VkPhysicalDevice physicalDevice) | |
| Construct with direct Vulkan handles (decoupled from ApplicationContext) | |
| Buffer (Engine::Core::ApplicationContext *context) | |
| Construct from ApplicationContext (for engine code) | |
| ~Buffer () | |
| void | setDebugName (const std::string &name) |
| Sets the name shown in vulkan validation layer. | |
| std::string | getDebugName () const |
| void | create (size_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties) |
| Creates a buffer with a certain size, usage flags and memory properties. | |
| void | destroy () |
| Destroys all vulkan resources of the buffer. | |
| void * | map () |
| Maps the buffer to be writable by the cpu. The mapped memory range is also stored in the object. | |
| void | unmap () |
| Unmaps the memory if it is mapped. | |
| bool | isMapped () const |
| Checks whether the buffer is already mapped to a memory range. | |
| void | flush (VkDeviceSize mappedOffset=0, VkDeviceSize mappedSize=VK_WHOLE_SIZE) |
| Flushes a mapped memory range to the GPU to make CPU writes visible. | |
| void | uploadData (const void *data, VkDeviceSize dataSize) |
| Helper function to map, copy the data and unmap the buffer. Best used for infrequent updates. | |
| void | uploadDataAtOffset (const void *data, VkDeviceSize dataSize, VkDeviceSize offset) |
| Helper function to map, copy data at an offset and unmap the buffer. | |
| bool | ensureSize (size_t requiredSize, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties) |
| Ensures the buffer has at least the required size, recreating if necessary. | |
| VkBuffer | getBuffer () const |
| VkDeviceAddress | getDeviceAddress () const |
| VkDeviceMemory | getBufferMemory () const |
| Gets the underlying VkDeviceMemory handle (for backward compatibility) | |
| VkDeviceSize | getBufferSize () const |
| void * | getMappedMemory () const |
| bool | isValid () const |
| void | invalidate () |
| void | overrideSize (VkDeviceSize newSize) |
| Overrides the size of a buffer in case the VulkanBuffer is created in place. | |
Private Attributes | |
| std::string | debugName_ = "Buffer" |
| VkDevice | device_ = VK_NULL_HANDLE |
| VkPhysicalDevice | physicalDevice_ = VK_NULL_HANDLE |
| VmaAllocator | allocator_ = VK_NULL_HANDLE |
| Borrowed reference to VMA allocator. | |
| VkBuffer | buffer = VK_NULL_HANDLE |
| VmaAllocation | allocation_ = VK_NULL_HANDLE |
| VMA allocation handle. | |
| VkDeviceSize | size_ = 0 |
| void * | mappedMemory = VK_NULL_HANDLE |
| bool | isHostCoherent_ = false |
| True if buffer uses HOST_COHERENT memory (no flush needed) | |
| bool | isPersistentlyMapped_ = false |
RAII wrapper for Vulkan buffer and device memory.
Supports three construction modes:
|
inlinenoexcept |
Definition at line 32 of file Buffer.h.
References Buffer().
Referenced by Buffer(), and operator=().
| Vulkan::Buffer::Buffer | ( | ) |
Default constructor - uses EngineManager singleton to get Vulkan handles.
| Vulkan::Buffer::Buffer | ( | VkDevice | device, |
| VkPhysicalDevice | physicalDevice ) |
|
explicit |
Construct from ApplicationContext (for engine code)
| context | The application context providing Vulkan handles |
| Vulkan::Buffer::~Buffer | ( | ) |
| void Vulkan::Buffer::create | ( | size_t | size, |
| VkBufferUsageFlags | usage, | ||
| VkMemoryPropertyFlags | properties ) |
Creates a buffer with a certain size, usage flags and memory properties.
| size | size of the buffer to create |
| usage | Vulkan usage flags of the buffer |
| properties | Memory property flags for the buffers memory |
| void Vulkan::Buffer::destroy | ( | ) |
Destroys all vulkan resources of the buffer.
Referenced by operator=().
| bool Vulkan::Buffer::ensureSize | ( | size_t | requiredSize, |
| VkBufferUsageFlags | usage, | ||
| VkMemoryPropertyFlags | properties ) |
Ensures the buffer has at least the required size, recreating if necessary.
If the current buffer is smaller than requiredSize, it will be destroyed and recreated with the new size. If the buffer is already large enough, no action is taken.
| requiredSize | The minimum required size in bytes |
| usage | Vulkan buffer usage flags for recreation |
| properties | Memory property flags for recreation |
| void Vulkan::Buffer::flush | ( | VkDeviceSize | mappedOffset = 0, |
| VkDeviceSize | mappedSize = VK_WHOLE_SIZE ) |
Flushes a mapped memory range to the GPU to make CPU writes visible.
| mappedOffset | The offset within the buffer which was mapped |
| mappedSize | The size of the memory range to flush |
|
inlinenodiscard |
|
nodiscard |
Gets the underlying VkDeviceMemory handle (for backward compatibility)
|
inlinenodiscard |
|
nodiscard |
|
nodiscard |
|
inlinenodiscard |
Definition at line 201 of file Buffer.h.
References mappedMemory.
|
inline |
Definition at line 203 of file Buffer.h.
References allocation_, buffer, isHostCoherent_, isPersistentlyMapped_, mappedMemory, and size_.
|
inlinenodiscard |
Checks whether the buffer is already mapped to a memory range.
Definition at line 153 of file Buffer.h.
References mappedMemory.
|
inlinenodiscard |
| void * Vulkan::Buffer::map | ( | ) |
Maps the buffer to be writable by the cpu. The mapped memory range is also stored in the object.
Definition at line 56 of file Buffer.h.
References allocation_, allocator_, Buffer(), buffer, destroy(), device_, isHostCoherent_, isPersistentlyMapped_, mappedMemory, physicalDevice_, and size_.
|
inline |
| void Vulkan::Buffer::setDebugName | ( | const std::string & | name | ) |
Sets the name shown in vulkan validation layer.
| name | the name which should be shown in validation messages |
| void Vulkan::Buffer::unmap | ( | ) |
Unmaps the memory if it is mapped.
| void Vulkan::Buffer::uploadData | ( | const void * | data, |
| VkDeviceSize | dataSize ) |
Helper function to map, copy the data and unmap the buffer. Best used for infrequent updates.
| data | the data to upload |
| dataSize | the size of the data to upload |
| void Vulkan::Buffer::uploadDataAtOffset | ( | const void * | data, |
| VkDeviceSize | dataSize, | ||
| VkDeviceSize | offset ) |
Helper function to map, copy data at an offset and unmap the buffer.
| data | the data to upload |
| dataSize | the size of the data to upload |
| offset | the offset within the buffer to write at |
|
private |
VMA allocation handle.
Definition at line 231 of file Buffer.h.
Referenced by invalidate(), and operator=().
|
private |
Borrowed reference to VMA allocator.
Definition at line 228 of file Buffer.h.
Referenced by operator=().
|
private |
Definition at line 230 of file Buffer.h.
Referenced by getBuffer(), invalidate(), isValid(), and operator=().
|
private |
Definition at line 226 of file Buffer.h.
Referenced by operator=().
|
private |
True if buffer uses HOST_COHERENT memory (no flush needed)
Definition at line 237 of file Buffer.h.
Referenced by invalidate(), and operator=().
|
private |
True if buffer was created with VMA_ALLOCATION_CREATE_MAPPED_BIT (persistent mapping) Persistent mappings should NOT call vmaUnmapMemory
Definition at line 241 of file Buffer.h.
Referenced by invalidate(), and operator=().
|
private |
Definition at line 234 of file Buffer.h.
Referenced by getMappedMemory(), invalidate(), isMapped(), and operator=().
|
private |
Definition at line 227 of file Buffer.h.
Referenced by operator=().
|
private |
Definition at line 232 of file Buffer.h.
Referenced by getBufferSize(), invalidate(), operator=(), and overrideSize().