Plasma Engine  2.0
Loading...
Searching...
No Matches
MemoryAllocatorVulkan.h
1#pragma once
2
3#include <Foundation/Types/Bitflags.h>
4#include <RendererVulkan/RendererVulkanDLL.h>
5
6#include <vulkan/vulkan.hpp>
7
10{
11 typedef plUInt32 StorageType;
12 enum Enum
13 {
14 DedicatedMemory = 0x00000001,
15 NeverAllocate = 0x00000002,
16 Mapped = 0x00000004,
17 CanAlias = 0x00000200,
18 HostAccessSequentialWrite = 0x00000400,
19 HostAccessRandom = 0x00000800,
20 StrategyMinMemory = 0x00010000,
21 StrategyMinTime = 0x00020000,
22 Default = 0,
23 };
24
25 struct Bits
26 {
27 StorageType DedicatedMemory : 1;
28 StorageType NeverAllocate : 1;
29 StorageType Mapped : 1;
30 StorageType UnusedBit3 : 1;
31
32 StorageType UnusedBit4 : 1;
33 StorageType UnusedBit5 : 1;
34 StorageType UnusedBit6 : 1;
35 StorageType UnusedBit7 : 1;
36
37 StorageType UnusedBit8 : 1;
38 StorageType CanAlias : 1;
39 StorageType HostAccessSequentialWrite : 1;
40 StorageType HostAccessRandom : 1;
41
42 StorageType UnusedBit12 : 1;
43 StorageType UnusedBit13 : 1;
44 StorageType UnusedBit14 : 1;
45 StorageType StrategyMinMemory : 1;
46
47 StorageType StrategyMinTime : 1;
48 };
49};
50PL_DECLARE_FLAGS_OPERATORS(plVulkanAllocationCreateFlags);
51
54{
55 typedef plUInt8 StorageType;
56 enum Enum
57 {
58 Unknown = 0,
59 GpuLazilyAllocated = 6,
60 Auto = 7,
61 AutoPreferDevice = 8,
62 AutoPreferHost = 9,
63 Default = Unknown,
64 };
65};
66
69{
72 const char* m_pUserData = nullptr;
73 bool m_bExportSharedAllocation = false; // If this allocation should be exported so other processes can access it.
74};
75
78{
79 uint32_t m_memoryType;
80 vk::DeviceMemory m_deviceMemory;
81 vk::DeviceSize m_offset;
82 vk::DeviceSize m_size;
83 void* m_pMappedData;
84 void* m_pUserData;
85 const char* m_pName;
86};
87
88
89VK_DEFINE_HANDLE(plVulkanAllocation)
90
91
93class PL_RENDERERVULKAN_DLL plMemoryAllocatorVulkan
94{
95public:
96 static vk::Result Initialize(vk::PhysicalDevice physicalDevice, vk::Device device, vk::Instance instance);
97 static void DeInitialize();
98
99 static vk::Result CreateImage(const vk::ImageCreateInfo& imageCreateInfo, const plVulkanAllocationCreateInfo& allocationCreateInfo, vk::Image& out_image, plVulkanAllocation& out_alloc, plVulkanAllocationInfo* pAllocInfo = nullptr);
100 static void DestroyImage(vk::Image& image, plVulkanAllocation& alloc);
101
102 static vk::Result CreateBuffer(const vk::BufferCreateInfo& bufferCreateInfo, const plVulkanAllocationCreateInfo& allocationCreateInfo, vk::Buffer& out_buffer, plVulkanAllocation& out_alloc, plVulkanAllocationInfo* pAllocInfo = nullptr);
103 static void DestroyBuffer(vk::Buffer& buffer, plVulkanAllocation& alloc);
104
105 static plVulkanAllocationInfo GetAllocationInfo(plVulkanAllocation alloc);
106 static void SetAllocationUserData(plVulkanAllocation alloc, const char* pUserData);
107
108 static vk::Result MapMemory(plVulkanAllocation alloc, void** pData);
109 static void UnmapMemory(plVulkanAllocation alloc);
110 static vk::Result FlushAllocation(plVulkanAllocation alloc, vk::DeviceSize offset = 0, vk::DeviceSize size = VK_WHOLE_SIZE);
111 static vk::Result InvalidateAllocation(plVulkanAllocation alloc, vk::DeviceSize offset = 0, vk::DeviceSize size = VK_WHOLE_SIZE);
112
113
114private:
115 struct Impl;
116 static Impl* m_pImpl;
117};
Thin abstraction layer over VulkanMemoryAllocator to allow for abstraction and prevent pulling in its...
Definition MemoryAllocatorVulkan.h:94
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition MemoryAllocatorVulkan.h:26
Subset of VmaAllocationCreateFlagBits. Duplicated for abstraction purposes.
Definition MemoryAllocatorVulkan.h:10
Subset of VmaAllocationCreateInfo. Duplicated for abstraction purposes.
Definition MemoryAllocatorVulkan.h:69
Subset of VmaAllocationInfo. Duplicated for abstraction purposes.
Definition MemoryAllocatorVulkan.h:78
Subset of VmaMemoryUsage. Duplicated for abstraction purposes.
Definition MemoryAllocatorVulkan.h:54