-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVmaHost.h
More file actions
66 lines (52 loc) · 1.84 KB
/
VmaHost.h
File metadata and controls
66 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef KJY_VMA_HOST_H_
#define KJY_VMA_HOST_H_
#include <unordered_map>
#include <vk_mem_alloc.h>
#include "VulkanDevices.h"
#include <functional>
template<>
struct std::hash<VulkanDeviceHandlePair>{
size_t operator()(const VulkanDeviceHandlePair& aDevicePair) const noexcept{
return(
std::hash<VkDevice>()(aDevicePair.device)
^
std::hash<VkPhysicalDevice>()(aDevicePair.physicalDevice)
);
}
};
class VmaHost : public std::unordered_map<VulkanDeviceHandlePair, VmaAllocator>
{
public:
using base_map_t = typename std::unordered_map<VulkanDeviceHandlePair, VmaAllocator>;
~VmaHost(){
for(auto& entry : *this){
vmaDestroyAllocator(entry.second);
}
}
static VmaHost& getInstance(){
static VmaHost instance;
return(instance);
}
static void setVkInstance(VkInstance aVkInstance) {
VmaHost::getInstance()._mInstance = aVkInstance;
}
static bool allocatorExists(const VulkanDeviceHandlePair& aDevicePair){
return(VmaHost::getInstance()._allocatorExists(aDevicePair));
}
static VmaAllocator getAllocator(const VulkanDeviceHandlePair& aDevicePair){
return(VmaHost::getInstance()._getAllocator(aDevicePair));
}
static void destroyAllocator(const VulkanDeviceHandlePair& aDevicePair){
VmaHost::getInstance()._destroyAllocator(aDevicePair);
}
VmaHost(const VmaHost&) = delete;
VmaHost& operator=(const VmaHost&) = delete;
private:
VmaHost(){}
VmaAllocator _getAllocator(const VulkanDeviceHandlePair& aDevicePair);
VmaAllocator _createNewAllocator(const VulkanDeviceHandlePair& aDevicePair);
void _destroyAllocator(const VulkanDeviceHandlePair& aDevicePair);
bool _allocatorExists(const VulkanDeviceHandlePair& aDevicePair);
VkInstance _mInstance = VK_NULL_HANDLE;
};
#endif