Nameless Engine
Loading...
Searching...
No Matches
VulkanResourceManager.h
1#pragma once
2
3// Standard.
4#include <atomic>
5#include <optional>
6
7// Custom.
8#include "render/general/resource/GpuResourceManager.h"
9
10// External.
11#include "VulkanMemoryAllocator/include/vk_mem_alloc.h"
12
13namespace ne {
14 class VulkanRenderer;
15 class VulkanResource;
16
19 // Resource will request a memory allocator object during destruction.
20 friend class VulkanResource;
21
22 // Upload buffer needs access to memory allocator object for map/unmap operations.
23 friend class UploadBuffer;
24
25 // Uses memory allocator to load KTX textures.
26 friend class KtxLoadingCallbackManager;
27
28 public:
29 VulkanResourceManager() = delete;
31 VulkanResourceManager& operator=(const VulkanResourceManager&) = delete;
32
33 virtual ~VulkanResourceManager() override;
34
42 static VkFormat convertTextureResourceFormatToVkFormat(ShaderReadWriteTextureResourceFormat format);
43
51 static std::variant<std::unique_ptr<VulkanResourceManager>, Error> create(VulkanRenderer* pRenderer);
52
58 virtual size_t getTotalVideoMemoryInMb() const override;
59
65 virtual size_t getUsedVideoMemoryInMb() const override;
66
80 std::variant<std::unique_ptr<VulkanResource>, Error> createBuffer(
81 const std::string& sResourceName,
82 const VkBufferCreateInfo& bufferInfo,
83 const VmaAllocationCreateInfo& allocationInfo,
84 unsigned int iElementSizeInBytes,
85 unsigned int iElementCount);
86
103 std::variant<std::unique_ptr<VulkanResource>, Error> createImage(
104 const std::string& sResourceName,
105 uint32_t iImageWidth,
106 uint32_t iImageHeight,
107 uint32_t iTextureMipLevelCount,
108 VkSampleCountFlagBits sampleCount,
109 VkFormat imageFormat,
110 VkImageTiling imageTilingMode,
111 VkImageUsageFlags imageUsage,
112 std::optional<VkImageAspectFlags> viewDescription,
113 bool bIsCubeMap = false);
114
123 virtual std::variant<std::unique_ptr<GpuResource>, Error> loadTextureFromDisk(
124 const std::string& sResourceName, const std::filesystem::path& pathToTextureFile) override;
125
154 virtual std::variant<std::unique_ptr<UploadBuffer>, Error> createResourceWithCpuWriteAccess(
155 const std::string& sResourceName,
156 size_t iElementSizeInBytes,
157 size_t iElementCount,
158 std::optional<bool> isUsedInShadersAsArrayResource) override;
159
185 virtual std::variant<std::unique_ptr<GpuResource>, Error> createResourceWithData(
186 const std::string& sResourceName,
187 const void* pBufferData,
188 size_t iElementSizeInBytes,
189 size_t iElementCount,
190 ResourceUsageType usage,
191 bool bIsShaderReadWriteResource) override;
192
208 virtual std::variant<std::unique_ptr<GpuResource>, Error> createResource(
209 const std::string& sResourceName,
210 size_t iElementSizeInBytes,
211 size_t iElementCount,
212 ResourceUsageType usage,
213 bool bIsShaderReadWriteResource) override;
214
225 virtual std::variant<std::unique_ptr<GpuResource>, Error> createShaderReadWriteTextureResource(
226 const std::string& sResourceName,
227 unsigned int iWidth,
228 unsigned int iHeight,
229 ShaderReadWriteTextureResourceFormat format) override;
230
236 virtual std::string getCurrentStateInfo() override;
237
238 private:
246
254 static std::optional<VkBufferUsageFlagBits>
255 convertResourceUsageTypeToVkBufferUsageType(ResourceUsageType usage);
256
268 virtual std::variant<std::unique_ptr<GpuResource>, Error> createShadowMapTexture(
269 const std::string& sResourceName,
270 unsigned int iTextureSize,
271 bool bPointLightColorCubemap) override;
272
289 std::variant<std::unique_ptr<VulkanResource>, Error> createBuffer(
290 const std::string& sResourceName,
291 VkDeviceSize iBufferSize,
292 VkBufferUsageFlags bufferUsage,
293 bool bAllowCpuWrite,
294 unsigned int iElementSizeInBytes,
295 unsigned int iElementCount);
296
298 VmaAllocator pMemoryAllocator = nullptr;
299 };
300} // namespace ne
Definition: Error.h:27
Definition: GpuResourceManager.h:43
Renderer *const pRenderer
Definition: GpuResourceManager.h:300
Definition: KtxLoadingCallbackManager.h:17
Definition: UploadBuffer.h:14
Definition: VulkanRenderer.h:26
Definition: VulkanResourceManager.h:18
static std::optional< VkBufferUsageFlagBits > convertResourceUsageTypeToVkBufferUsageType(ResourceUsageType usage)
Definition: VulkanResourceManager.cpp:63
virtual std::variant< std::unique_ptr< GpuResource >, Error > loadTextureFromDisk(const std::string &sResourceName, const std::filesystem::path &pathToTextureFile) override
Definition: VulkanResourceManager.cpp:604
virtual std::variant< std::unique_ptr< UploadBuffer >, Error > createResourceWithCpuWriteAccess(const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, std::optional< bool > isUsedInShadersAsArrayResource) override
Definition: VulkanResourceManager.cpp:281
virtual std::variant< std::unique_ptr< GpuResource >, Error > createShadowMapTexture(const std::string &sResourceName, unsigned int iTextureSize, bool bPointLightColorCubemap) override
Definition: VulkanResourceManager.cpp:519
std::variant< std::unique_ptr< VulkanResource >, Error > createBuffer(const std::string &sResourceName, const VkBufferCreateInfo &bufferInfo, const VmaAllocationCreateInfo &allocationInfo, unsigned int iElementSizeInBytes, unsigned int iElementCount)
Definition: VulkanResourceManager.cpp:258
VmaAllocator pMemoryAllocator
Definition: VulkanResourceManager.h:298
virtual std::variant< std::unique_ptr< GpuResource >, Error > createResourceWithData(const std::string &sResourceName, const void *pBufferData, size_t iElementSizeInBytes, size_t iElementCount, ResourceUsageType usage, bool bIsShaderReadWriteResource) override
Definition: VulkanResourceManager.cpp:347
virtual std::variant< std::unique_ptr< GpuResource >, Error > createShaderReadWriteTextureResource(const std::string &sResourceName, unsigned int iWidth, unsigned int iHeight, ShaderReadWriteTextureResourceFormat format) override
Definition: VulkanResourceManager.cpp:466
static VkFormat convertTextureResourceFormatToVkFormat(ShaderReadWriteTextureResourceFormat format)
Definition: VulkanResourceManager.cpp:117
virtual std::string getCurrentStateInfo() override
Definition: VulkanResourceManager.cpp:824
std::variant< std::unique_ptr< VulkanResource >, Error > createImage(const std::string &sResourceName, uint32_t iImageWidth, uint32_t iImageHeight, uint32_t iTextureMipLevelCount, VkSampleCountFlagBits sampleCount, VkFormat imageFormat, VkImageTiling imageTilingMode, VkImageUsageFlags imageUsage, std::optional< VkImageAspectFlags > viewDescription, bool bIsCubeMap=false)
Definition: VulkanResourceManager.cpp:559
virtual size_t getUsedVideoMemoryInMb() const override
Definition: VulkanResourceManager.cpp:219
virtual std::variant< std::unique_ptr< GpuResource >, Error > createResource(const std::string &sResourceName, size_t iElementSizeInBytes, size_t iElementCount, ResourceUsageType usage, bool bIsShaderReadWriteResource) override
Definition: VulkanResourceManager.cpp:428
static std::variant< std::unique_ptr< VulkanResourceManager >, Error > create(VulkanRenderer *pRenderer)
Definition: VulkanResourceManager.cpp:142
virtual size_t getTotalVideoMemoryInMb() const override
Definition: VulkanResourceManager.cpp:180
Definition: VulkanResource.h:23