-
Notifications
You must be signed in to change notification settings - Fork 2
/
descriptor_allocator.h
50 lines (36 loc) · 1.61 KB
/
descriptor_allocator.h
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
#include <stdint.h>
#include <vulkan/vulkan_core.h>
namespace vke {
class DescriptorAllocatorPool;
struct DescriptorAllocatorHandle {
friend class DescriptorAllocatorPool;
DescriptorAllocatorHandle() = default;
DescriptorAllocatorHandle& operator=(const DescriptorAllocatorHandle&) = delete;
~DescriptorAllocatorHandle();
DescriptorAllocatorHandle(DescriptorAllocatorHandle&& other);
DescriptorAllocatorHandle& operator=(DescriptorAllocatorHandle&& other);
//return this handle to the pool. Will make this handle orphaned
void Return();
//allocate new descriptor. handle has to be valid
//returns true if allocation succeeded, and false if it didnt
//will mutate the handle if it requires a new vkDescriptorPool
bool Allocate(const VkDescriptorSetLayout& layout, VkDescriptorSet& builtSet);
DescriptorAllocatorPool* ownerPool{nullptr};
VkDescriptorPool vkPool;
int8_t poolIdx;
};
class DescriptorAllocatorPool {
public:
virtual ~DescriptorAllocatorPool(){};
static DescriptorAllocatorPool* Create(const VkDevice& device, int nFrames = 3);
//not thread safe
//switches default allocators to the next frame. When frames loop it will reset the descriptors of that frame
virtual void Flip() = 0;
//not thread safe
//override the pool size for a specific descriptor type. This will be used new pools are allocated
virtual void SetPoolSizeMultiplier(VkDescriptorType type, float multiplier) = 0;
//thread safe, uses lock
//get handle to use when allocating descriptors
virtual DescriptorAllocatorHandle GetAllocator() = 0;
};
}