SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
VulkanImage.h
1#pragma once
2
3#include "spark/base/Macros.h"
4#include "spark/render/Format.h"
5#include "spark/render/Image.h"
6#include "spark/render/Resource.h"
7#include "spark/render/StateResource.h"
8#include "spark/render/vk/Export.h"
9#include "spark/render/vk/Helpers.h"
10
11#include "spark/math/Vector3.h"
12
13#include <memory>
14#include <string>
15
16SPARK_FWD_DECLARE_VK_HANDLE(VkImage)
17SPARK_FWD_DECLARE_VK_HANDLE(VkImageView)
18SPARK_FWD_DECLARE_VK_HANDLE(VmaAllocator)
19SPARK_FWD_DECLARE_VK_HANDLE(VmaAllocation)
20using VkImageAspectFlags = uint32_t;
21struct VkImageCreateInfo;
22struct VmaAllocationCreateInfo;
23struct VmaAllocationInfo;
24
25namespace spark::render::vk
26{
27 class VulkanDevice;
28
32 class SPARK_RENDER_VK_EXPORT IVulkanImage : public IImage, public virtual IResource<VkImage>
33 {
34 public:
35 ~IVulkanImage() noexcept override = default;
36
41 [[nodiscard]] virtual VkImageAspectFlags aspectMask() const noexcept = 0;
42
48 [[nodiscard]] virtual VkImageAspectFlags aspectMask(unsigned int plane = 0) const = 0;
49
55 [[nodiscard]] virtual const VkImageView& imageView(unsigned int plane = 0) const = 0;
56 };
57
58 SPARK_WARNING_PUSH
59 SPARK_DISABLE_MSVC_WARNING(4250) // 'VulkanImage': inherits 'StateResource::name' via dominance
60
64 class SPARK_RENDER_VK_EXPORT VulkanImage final : public IVulkanImage, public Resource<VkImage>, public StateResource
65 {
66 public:
83 explicit VulkanImage(const VulkanDevice& device,
84 VkImage image,
85 const math::Vector3<unsigned>& extent,
86 Format format,
87 ImageDimensions dimensions,
88 unsigned levels,
89 unsigned layers,
90 MultiSamplingLevel samples,
91 bool writable,
92 ImageLayout initial_layout,
93 VmaAllocator allocator = nullptr,
94 VmaAllocation allocation = nullptr,
95 const std::string& name = "");
96 ~VulkanImage() override;
97
98 VulkanImage(const VulkanImage& other) = delete;
99 VulkanImage(VulkanImage&& other) noexcept = delete;
100 VulkanImage& operator=(const VulkanImage& other) = delete;
101 VulkanImage& operator=(VulkanImage&& other) noexcept = delete;
102
120 static std::unique_ptr<VulkanImage> Allocate(const VulkanDevice& device,
121 const math::Vector3<unsigned>& extent,
122 Format format,
123 ImageDimensions dimensions,
124 unsigned levels,
125 unsigned layers,
126 MultiSamplingLevel samples,
127 bool writable,
128 ImageLayout initial_layout,
129 VmaAllocator& allocator,
130 const VkImageCreateInfo& create_info,
131 const VmaAllocationCreateInfo& allocation_info,
132 VmaAllocationInfo* allocation_result = nullptr);
133
152 static std::unique_ptr<VulkanImage> Allocate(const std::string& name,
153 const VulkanDevice& device,
154 const math::Vector3<unsigned>& extent,
155 Format format,
156 ImageDimensions dimensions,
157 unsigned levels,
158 unsigned layers,
159 MultiSamplingLevel samples,
160 bool writable,
161 ImageLayout initial_layout,
162 VmaAllocator& allocator,
163 const VkImageCreateInfo& create_info,
164 const VmaAllocationCreateInfo& allocation_info,
165 VmaAllocationInfo* allocation_result = nullptr);
166
168 [[nodiscard]] VkImageAspectFlags aspectMask() const noexcept override;
169
171 [[nodiscard]] VkImageAspectFlags aspectMask(unsigned plane) const override;
172
174 [[nodiscard]] const VkImageView& imageView(unsigned plane = 0) const override;
175
177 [[nodiscard]] unsigned elements() const noexcept override;
178
180 [[nodiscard]] std::size_t size() const noexcept override;
181
183 [[nodiscard]] std::size_t elementSize() const noexcept override;
184
186 [[nodiscard]] std::size_t elementAlignment() const override;
187
189 [[nodiscard]] std::size_t alignedElementSize() const noexcept override;
190
192 [[nodiscard]] bool writable() const noexcept override;
193
195 [[nodiscard]] std::size_t size(unsigned level) const override;
196
198 [[nodiscard]] math::Vector3<unsigned> extent(unsigned level) const noexcept override;
199
201 [[nodiscard]] Format format() const noexcept override;
202
204 [[nodiscard]] ImageDimensions dimensions() const noexcept override;
205
207 [[nodiscard]] unsigned levels() const noexcept override;
208
210 [[nodiscard]] unsigned layers() const noexcept override;
211
213 [[nodiscard]] unsigned planes() const noexcept override;
214
216 [[nodiscard]] MultiSamplingLevel samples() const noexcept override;
217
219 [[nodiscard]] ImageLayout layout(unsigned sub_resource) const override;
220
221 private:
222 struct Impl;
223 std::unique_ptr<Impl> m_impl;
224 };
225
226 SPARK_WARNING_POP
227}
A vector with three components.
Definition Vector3.h:13
Definition Image.h:131
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
Represents a Vulkan image.
Definition VulkanImage.h:33
virtual VkImageAspectFlags aspectMask() const noexcept=0
Gets the image aspect mask for all sub-resources.
Vulkan implementation of IGraphicsDevice.
Definition VulkanDevice.h:25
Vulkan implementation of IImage.
Definition VulkanImage.h:65
Definition VulkanImage.cpp:16