SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
VulkanBuffer.h
1#pragma once
2
3#include "spark/render/Buffer.h"
4#include "spark/render/Resource.h"
5#include "spark/render/vk/Export.h"
6#include "spark/render/vk/Helpers.h"
7
8#include "spark/base/Macros.h"
9
10SPARK_FWD_DECLARE_VK_HANDLE(VkBuffer)
11SPARK_FWD_DECLARE_VK_HANDLE(VmaAllocator)
12SPARK_FWD_DECLARE_VK_HANDLE(VmaAllocation)
13struct VkBufferCreateInfo;
14struct VmaAllocationCreateInfo;
15struct VmaAllocationInfo;
16
17namespace spark::render::vk
18{
22 class SPARK_RENDER_VK_EXPORT IVulkanBuffer : public virtual IBuffer, public virtual IResource<VkBuffer> {};
23
24 SPARK_WARNING_PUSH
25 SPARK_DISABLE_MSVC_WARNING(4250) // 'VulkanBuffer': inherits 'Resource<VkBuffer>::handle' via dominance
26
27
30 class SPARK_RENDER_VK_EXPORT VulkanBuffer : public virtual IVulkanBuffer, public Resource<VkBuffer>, public StateResource
31 {
32 public:
45 explicit VulkanBuffer(VkBuffer buffer,
46 BufferType type,
47 unsigned elements,
48 std::size_t element_size,
49 std::size_t alignment,
50 bool writable,
51 const VmaAllocator& allocator,
52 const VmaAllocation& allocation,
53 const std::string& name);
54 ~VulkanBuffer() override;
55
56 VulkanBuffer(const VulkanBuffer& other) = delete;
57 VulkanBuffer(VulkanBuffer&& other) noexcept = delete;
58 VulkanBuffer& operator=(const VulkanBuffer& other) = delete;
59 VulkanBuffer& operator=(VulkanBuffer&& other) noexcept = delete;
60
74 static std::unique_ptr<IVulkanBuffer> Allocate(BufferType type,
75 unsigned elements,
76 std::size_t element_size,
77 std::size_t alignment,
78 bool writable,
79 const VmaAllocator& allocator,
80 const VkBufferCreateInfo& create_info,
81 const VmaAllocationCreateInfo& allocation_info,
82 VmaAllocationInfo* allocation_result = nullptr);
83
98 static std::unique_ptr<IVulkanBuffer> Allocate(const std::string& name,
99 BufferType type,
100 unsigned elements,
101 std::size_t element_size,
102 std::size_t alignment,
103 bool writable,
104 const VmaAllocator& allocator,
105 const VkBufferCreateInfo& create_info,
106 const VmaAllocationCreateInfo& allocation_info,
107 VmaAllocationInfo* allocation_result = nullptr);
108
110 [[nodiscard]] BufferType type() const override;
111
113 [[nodiscard]] unsigned elements() const noexcept override;
114
116 [[nodiscard]] std::size_t size() const noexcept override;
117
119 [[nodiscard]] std::size_t elementSize() const noexcept override;
120
122 [[nodiscard]] std::size_t elementAlignment() const override;
123
125 [[nodiscard]] std::size_t alignedElementSize() const noexcept override;
126
128 [[nodiscard]] bool writable() const noexcept override;
129
131 void map(const void* data, std::size_t size, unsigned element) override;
132
134 void map(std::span<const void*> data, std::size_t element_size, unsigned first_element) override;
135
137 void map(void* data, size_t size, unsigned element, bool write) override;
138
140 void map(std::span<void*> data, size_t element_size, unsigned first_element, bool write) override;
141
142 private:
143 struct Impl;
144 std::unique_ptr<Impl> m_impl;
145 };
146
147 SPARK_WARNING_POP
148}
Base interface for all buffers.
Definition Buffer.h:151
Provides access to a resource managed by the derived class.
Definition Resource.h:11
Definition Resource.h:34
Base class for a resource that can be identified by a name in a DeviceState.
Definition StateResource.h:29
Vulkan interface for a IBuffer.
Definition VulkanBuffer.h:22
Vulkan implementation of IBuffer.
Definition VulkanBuffer.h:31
void map(std::span< const void * > data, std::size_t element_size, unsigned first_element) override
Maps the memory at data into the internal memory of the object.
Definition VulkanBuffer.cpp:16