#pragma once #include #include #include "vertex.hpp" #include "vk_mem_alloc.h" #include #include using std::unique_ptr; using std::shared_ptr; using std::make_shared; using std::make_unique; using std::optional; class Image; class Buffer { public: Buffer(VkDeviceSize bufferSize, VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags vmaAllocationFlags); Buffer(VkDeviceSize bufferSize, void* initialData, VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage, VmaAllocationCreateFlags vmaAllocationFlags); static unique_ptr Append(const Buffer& old, void* data, VkDeviceSize size, VkCommandBuffer commandBuffer=VK_NULL_HANDLE); static unique_ptr Replace(const Buffer& old, void* data, VkDeviceSize size, VkCommandBuffer commandBuffer=VK_NULL_HANDLE); virtual ~Buffer(); VkBuffer handle = VK_NULL_HANDLE; VmaAllocation allocation = VK_NULL_HANDLE; VmaAllocationInfo allocationInfo {}; VkDeviceSize size; void setName(const std::string& newName); template T& access(){ return *reinterpret_cast(allocationInfo.pMappedData); } void copyTo(Buffer* buffer) const; void copyTo(Image* image) const; void setData(void* data, VkDeviceSize offset, VkDeviceSize size, VkCommandBuffer commandBuffer=VK_NULL_HANDLE); shared_ptr getStagingBuffer(); Buffer(const Buffer& other) = delete; Buffer& operator =(const Buffer& other) = delete; private: optional> stagingBufferOptional; std::string name; VkBufferUsageFlags bufferUsageFlags; VmaMemoryUsage memoryUsage; VmaAllocationCreateFlags allocationCreateFlags; }; class SimulationBuffer : public Buffer { public: SimulationBuffer(VkDeviceSize bufferSize, VkBufferUsageFlags bufferUsage=0): Buffer(bufferSize, initialData, bufferUsage | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE, 0) {} };