3#include <vulkan/vulkan.h>
4#include <vk_mem_alloc.h>
47 other.device_ = VK_NULL_HANDLE;
48 other.physicalDevice_ = VK_NULL_HANDLE;
49 other.allocator_ = VK_NULL_HANDLE;
50 other.buffer = VK_NULL_HANDLE;
51 other.allocation_ = VK_NULL_HANDLE;
53 other.mappedMemory =
nullptr;
54 other.isHostCoherent_ =
false;
55 other.isPersistentlyMapped_ =
false;
80 other.device_ = VK_NULL_HANDLE;
81 other.physicalDevice_ = VK_NULL_HANDLE;
82 other.allocator_ = VK_NULL_HANDLE;
83 other.buffer = VK_NULL_HANDLE;
84 other.allocation_ = VK_NULL_HANDLE;
86 other.mappedMemory = VK_NULL_HANDLE;
87 other.isHostCoherent_ =
false;
88 other.isPersistentlyMapped_ =
false;
109 VulkanBuffer(VkDevice device, VkPhysicalDevice physicalDevice);
141 void create(
size_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties);
188 void flush(VkDeviceSize mappedOffset = 0, VkDeviceSize mappedSize = VK_WHOLE_SIZE);
198 void uploadData(
const void* data, VkDeviceSize dataSize);
214 bool ensureSize(
size_t requiredSize, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties);
The application context is the core class which stores the basic openxr and vulkan objects.
bool isPersistentlyMapped_
void setDebugName(const std::string &name)
Sets the name shown in vulkan validation layer.
VkDeviceSize getBufferSize() const
VkBuffer getBuffer() const
void flush(VkDeviceSize mappedOffset=0, VkDeviceSize mappedSize=VK_WHOLE_SIZE)
Flushes a mapped memory range to the GPU to make CPU writes visible.
void * map()
Maps the buffer to be writable by the cpu. The mapped memory range is also stored in the object.
VmaAllocator allocator_
Borrowed reference to VMA allocator.
void unmap()
Unmaps the memory if it is mapped.
void uploadData(const void *data, VkDeviceSize dataSize)
Helper function to map, copy the data and unmap the buffer. Best used for infrequent updates.
VulkanBuffer()
Default constructor - uses EngineManager singleton to get Vulkan handles.
VmaAllocation allocation_
VMA allocation handle.
bool ensureSize(size_t requiredSize, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties)
Ensures the buffer has at least the required size, recreating if necessary.
bool isMapped() const
Checks whether the buffer is already mapped to a memory range.
std::string getDebugName() const
void destroy()
Destroys all vulkan resources of the buffer.
void overrideSize(VkDeviceSize newSize)
Overrides the size of a buffer in case the VulkanBuffer is created in place.
VkDeviceMemory getBufferMemory() const
Gets the underlying VkDeviceMemory handle (for backward compatibility)
bool isHostCoherent_
True if buffer uses HOST_COHERENT memory (no flush needed)
VulkanBuffer & operator=(VulkanBuffer &&other) noexcept
void create(size_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties)
Creates a buffer with a certain size, usage flags and memory properties.
VkPhysicalDevice physicalDevice_
void * getMappedMemory() const
VulkanBuffer(VulkanBuffer &&other) noexcept
Log category system implementation.