Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
descriptor_allocator.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2020 vblanco20-1
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23
24*/
25
26#pragma once
27#ifndef DVD_DESCRIPTOR_ALLOCATOR_H_
28#define DVD_DESCRIPTOR_ALLOCATOR_H_
29
30#include <vulkan/vulkan_core.h>
31
32namespace vke {
33 struct PoolSize
34 {
35 VkDescriptorType type;
37 };
38
39 struct PoolSizes
40 {
42 {
43 { VK_DESCRIPTOR_TYPE_SAMPLER, 1.f },
44 { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 4.f },
45 { VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 4.f },
46 { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1.f },
47 { VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1.f },
48 { VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1.f },
49 { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1.f },
50 { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1.f },
51 { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 2.f },
52 { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 2.f },
53 { VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1.f }
54 };
55 };
56
58 {
59 VkDescriptorPool pool{ VK_NULL_HANDLE };
60 };
61
63 {
66 };
67
69
71 {
75
79
81 void Return();
82
84 [[nodiscard]] bool Allocate(const VkDescriptorSetLayout& layout, VkDescriptorSet& builtSet, Divide::U8 retryCount = 0u);
85
87 VkDescriptorPool vkPool{VK_NULL_HANDLE};
89 };
90
92 {
93 public:
95
96 [[nodiscard]] static DescriptorAllocatorPool* Create(const VkDevice& device, Divide::I32 nFrames = 3);
97
99 void Flip();
100
102 void SetPoolSizeMultiplier(VkDescriptorType type, float multiplier);
103
104 // Thread safe, uses lock! Get handle to use when allocating descriptors.
106
107 protected:
109 void ReturnAllocator( DescriptorAllocatorHandle& handle, bool bIsFull );
110 VkDescriptorPool createPool( Divide::I32 count, VkDescriptorPoolCreateFlags flags );
111
112 private:
113 VkDevice _device{ 0 };
117
121 };
122}
123
124#endif //DVD_DESCRIPTOR_ALLOCATOR_H_
static DescriptorAllocatorPool * Create(const VkDevice &device, Divide::I32 nFrames=3)
void SetPoolSizeMultiplier(VkDescriptorType type, float multiplier)
Not thread safe! Override the pool size for a specific descriptor type. This will be used new pools a...
Divide::vector< DescriptorAllocator > _clearAllocators
VkDescriptorPool createPool(Divide::I32 count, VkDescriptorPoolCreateFlags flags)
void Flip()
Not thread safe! Switches default allocators to the next frame. When frames loop it will reset the de...
void ReturnAllocator(DescriptorAllocatorHandle &handle, bool bIsFull)
Divide::vector< std::unique_ptr< PoolStorage > > _descriptorPools
DescriptorAllocatorHandle GetAllocator()
std::mutex Mutex
Definition: SharedMutex.h:40
int32_t I32
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
DescriptorAllocatorHandle & operator=(const DescriptorAllocatorHandle &)=delete
bool Allocate(const VkDescriptorSetLayout &layout, VkDescriptorSet &builtSet, Divide::U8 retryCount=0u)
Allocate new descriptor. handle has to be valid returns true if allocation succeeded,...
void Return()
Return this handle to the pool. Will make this handle orphaned.
DescriptorAllocatorPool * ownerPool
Divide::F32 multiplier
VkDescriptorType type
Divide::vector< PoolSize > sizes
Divide::vector< DescriptorAllocator > _fullAllocators
Divide::vector< DescriptorAllocator > _usableAllocators