xref: /aosp_15_r20/external/skia/src/gpu/graphite/vk/VulkanDescriptorPool.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2 * Copyright 2023 Google LLC
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 skgpu_graphite_VulkanDescriptorPool_DEFINED
9 #define skgpu_graphite_VulkanDescriptorPool_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 
13 #include "include/core/SkSpan.h"
14 #include "src/gpu/graphite/DescriptorData.h"
15 #include "src/gpu/graphite/vk/VulkanGraphiteUtilsPriv.h"
16 
17 namespace skgpu::graphite {
18 
19 class VulkanSharedContext;
20 
21 class VulkanDescriptorPool : public SkRefCnt {
22 public:
23     // Conservative upper bound of number of sets supported per pool.
24     static constexpr int kMaxNumSets = 512;
25     /**
26      * Given a span of descriptor types and counts, a descriptor pool will be created which houses
27      * enough of the descriptor types and quantities requested to allocate the maximum number of
28      * sets possible (kMaxNumSets). Counts must be > 0.
29     */
30     static sk_sp<VulkanDescriptorPool> Make(const VulkanSharedContext*,
31                                             SkSpan<DescriptorData>,
32                                             VkDescriptorSetLayout);
33 
descPool()34     VkDescriptorPool descPool() { return fDescPool; }
35 
descSetLayout()36     const VkDescriptorSetLayout* descSetLayout() {
37         SkASSERT(fDescSetLayout != VK_NULL_HANDLE);
38         return &fDescSetLayout;
39     }
40 
41 private:
42     // Conservative overestimation of a maximum number of descriptors of any given type that can be
43     // requested.
44     static constexpr int kMaxNumDescriptors = 1024;
45 
46     VulkanDescriptorPool(const VulkanSharedContext*,
47                          VkDescriptorPool,
48                          VkDescriptorSetLayout);
49     ~VulkanDescriptorPool() override;
50 
51     const VulkanSharedContext*       fSharedContext;
52     VkDescriptorPool                 fDescPool;
53     // The VulkanDescriptorPool has ownership of the VkDescSetLayout used to allocate sets from this
54     // pool.
55     VkDescriptorSetLayout            fDescSetLayout;
56 };
57 } // namespace skgpu::graphite
58 
59 #endif // skgpu_graphite_VulkanDescriptorPool_DEFINED
60