11#ifdef CORRELATION_USE_VULKAN
12#include <vulkan/vulkan.h>
21#ifdef CORRELATION_USE_VULKAN
27struct BufferAllocationDesc {
29 VkBufferUsageFlags usage{0};
30 VkMemoryPropertyFlags properties{0};
39 VulkanBuffer() noexcept = default;
40 ~VulkanBuffer() noexcept { destroy(); }
42 VulkanBuffer(
const VulkanBuffer &) =
delete;
43 VulkanBuffer &operator=(
const VulkanBuffer &) =
delete;
45 VulkanBuffer(VulkanBuffer &&other)
noexcept { moveFrom(other); }
47 VulkanBuffer &operator=(VulkanBuffer &&other)
noexcept {
58 void create(VkDevice device, VkPhysicalDevice physical_device,
const BufferAllocationDesc &desc);
63 void destroy() noexcept;
69 [[nodiscard]]
void *map();
74 void unmap() noexcept;
80 void upload(std::span<const std::
byte> data);
86 bool ensureCapacity(VkDevice device, VkPhysicalDevice physical_device,
87 const BufferAllocationDesc &desc);
89 [[nodiscard]] VkBuffer buffer() const noexcept {
return buffer_; }
90 [[nodiscard]] VkDeviceMemory memory() const noexcept {
return memory_; }
91 [[nodiscard]] VkDeviceSize size() const noexcept {
return size_; }
92 [[nodiscard]]
void *mappedData() const noexcept {
return mapped_data_; }
93 [[nodiscard]]
bool isValid() const noexcept {
return buffer_ != VK_NULL_HANDLE; }
96 void moveFrom(VulkanBuffer &other)
noexcept {
97 device_ = std::exchange(other.device_, VK_NULL_HANDLE);
98 buffer_ = std::exchange(other.buffer_, VK_NULL_HANDLE);
99 memory_ = std::exchange(other.memory_, VK_NULL_HANDLE);
100 size_ = std::exchange(other.size_, 0);
101 mapped_data_ = std::exchange(other.mapped_data_,
nullptr);
104 VkDevice device_{VK_NULL_HANDLE};
105 VkBuffer buffer_{VK_NULL_HANDLE};
106 VkDeviceMemory memory_{VK_NULL_HANDLE};
107 VkDeviceSize size_{0};
108 void *mapped_data_{
nullptr};
Definition VulkanComputeService.hpp:24