Debian Codegraph @

src/gpu/ganesh/vk/GrVkDescriptorSetManager.h

raw
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrVkDescriptorSetManager_DEFINED
9 #define GrVkDescriptorSetManager_DEFINED
10
11 #include "include/private/base/SkAssert.h"
12 #include "include/private/base/SkTArray.h"
13 #include "include/private/gpu/vk/SkiaVulkan.h"
14 #include "src/gpu/ganesh/GrResourceHandle.h"
15
16 #include <cstddef>
17 #include <cstdint>
18
19 class GrVkDescriptorPool;
20 class GrVkDescriptorSet;
21 class GrVkGpu;
22 class GrVkSampler;
23 class GrVkUniformHandler;
24 /**
25 * This class handles the allocation of descriptor sets for a given VkDescriptorSetLayout. It will
26 * try to reuse previously allocated descriptor sets if they are no longer in use by other objects.
27 */
28 class GrVkDescriptorSetManager {
29 public:
30 GR_DEFINE_RESOURCE_HANDLE_CLASS(Handle)
31
32 static GrVkDescriptorSetManager* CreateUniformManager(GrVkGpu* gpu);
33 static GrVkDescriptorSetManager* CreateSamplerManager(GrVkGpu* gpu, VkDescriptorType type,
34 const GrVkUniformHandler&);
35 // See GrVkResourceProvider::getZeroSamplerDescriptorSetHandle() for more info on what the zero
36 // sampler is for.
37 static GrVkDescriptorSetManager* CreateZeroSamplerManager(GrVkGpu* gpu);
38 static GrVkDescriptorSetManager* CreateInputManager(GrVkGpu* gpu);
39
40 ~GrVkDescriptorSetManager() {}
41
42 void release(GrVkGpu* gpu);
43
44 VkDescriptorSetLayout layout() const { return fPoolManager.fDescLayout; }
45
46 const GrVkDescriptorSet* getDescriptorSet(GrVkGpu* gpu, const Handle& handle);
47
48 void recycleDescriptorSet(const GrVkDescriptorSet*);
49
50 bool isCompatible(VkDescriptorType type, const GrVkUniformHandler*) const;
51
52 bool isZeroSampler() const;
53
54 private:
55 struct DescriptorPoolManager {
56 DescriptorPoolManager(VkDescriptorSetLayout, VkDescriptorType type,
57 uint32_t descCountPerSet);
58
59 ~DescriptorPoolManager() {
60 SkASSERT(!fDescLayout);
61 SkASSERT(!fPool);
62 }
63
64 bool getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds);
65
66 void freeGPUResources(GrVkGpu* gpu);
67
68 VkDescriptorSetLayout fDescLayout;
69 VkDescriptorType fDescType;
70 uint32_t fDescCountPerSet;
71 uint32_t fMaxDescriptors;
72 uint32_t fCurrentDescriptorCount;
73 GrVkDescriptorPool* fPool;
74
75 private:
76 static constexpr size_t kMaxDescriptors = 1024;
77 static constexpr size_t kStartNumDescriptors = 16;
78 // kStartNumDescriptors must be less than kMaxUniformDescriptors
79 static_assert(kStartNumDescriptors < kMaxDescriptors);
80
81 bool getNewPool(GrVkGpu* gpu);
82 };
83
84 static GrVkDescriptorSetManager* Create(GrVkGpu* gpu,
85 VkDescriptorType,
86 const skia_private::TArray<uint32_t>& visibilities,
87 const skia_private::TArray<const GrVkSampler*>& immutableSamplers);
88
89 GrVkDescriptorSetManager(GrVkGpu* gpu,
90 VkDescriptorType, VkDescriptorSetLayout, uint32_t descCountPerSet,
91 const skia_private::TArray<uint32_t>& visibilities,
92 const skia_private::TArray<const GrVkSampler*>& immutableSamplers);
93
94
95 DescriptorPoolManager fPoolManager;
96 skia_private::TArray<const GrVkDescriptorSet*, true> fFreeSets;
97 skia_private::STArray<4, uint32_t> fBindingVisibilities;
98 skia_private::STArray<4, const GrVkSampler*> fImmutableSamplers;
99 };
100
101 #endif