Flutter Engine
The Flutter Engine
VulkanDescriptorPool.cpp
Go to the documentation of this file.
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
9
12
13namespace skgpu::graphite {
14
16 SkSpan<DescriptorData> requestedDescCounts,
17 VkDescriptorSetLayout layout) {
18
19 if (requestedDescCounts.empty()) {
20 return nullptr;
21 }
22
23 // For each requested descriptor type and count, create a VkDescriptorPoolSize struct which
24 // specifies the descriptor type and quantity for pool creation. Multiple pool size structures
25 // may contain the same descriptor type - the pool will be created with enough storage for the
26 // total number of descriptors of each type. Source:
27 // https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VkDescriptorPoolSize
28 // Note: The kMaxNumDescriptors limit could be evaded since we do not currently track and check
29 // the cumulative quantities of each type of descriptor, but this is an internal call and it is
30 // highly unexpected for us to exceed this limit in practice.
32 for (size_t i = 0; i < requestedDescCounts.size(); i++) {
33 SkASSERT(requestedDescCounts[i].fCount > 0);
34 if (requestedDescCounts[i].fCount > kMaxNumDescriptors) {
35 SkDebugf("The number of descriptors requested, %u, exceeds the maximum allowed (%d).\n",
36 requestedDescCounts[i].fCount,
37 kMaxNumDescriptors);
38 return nullptr;
39 }
40 VkDescriptorPoolSize& poolSize = poolSizes.push_back();
41 memset(&poolSize, 0, sizeof(VkDescriptorPoolSize));
42 // Map each DescriptorSetType to the appropriate backend VkDescriptorType
43 poolSize.type = DsTypeEnumToVkDs(requestedDescCounts[i].fType);
44 // Create a pool large enough to accommodate the maximum possible number of descriptor sets
45 poolSize.descriptorCount = requestedDescCounts[i].fCount * kMaxNumSets;
46 }
47
49 memset(&createInfo, 0, sizeof(VkDescriptorPoolCreateInfo));
51 createInfo.pNext = nullptr;
52 createInfo.flags = 0;
53 createInfo.maxSets = kMaxNumSets;
54 createInfo.poolSizeCount = requestedDescCounts.size();
55 createInfo.pPoolSizes = &poolSizes.front();
56
57 VkDescriptorPool pool;
59 VULKAN_CALL_RESULT(context,
60 result,
61 CreateDescriptorPool(context->device(),
62 &createInfo,
63 /*const VkAllocationCallbacks*=*/nullptr,
64 &pool));
65 if (result != VK_SUCCESS) {
66 VULKAN_CALL(context->interface(),
67 DestroyDescriptorSetLayout(context->device(), layout, nullptr));
68 return nullptr;
69 }
70 return sk_sp<VulkanDescriptorPool>(new VulkanDescriptorPool(context, pool, layout));
71}
72
73VulkanDescriptorPool::VulkanDescriptorPool(const VulkanSharedContext* context,
74 VkDescriptorPool pool,
75 VkDescriptorSetLayout layout)
76 : fSharedContext(context)
77 , fDescPool(pool)
78 , fDescSetLayout(layout) {}
79
80VulkanDescriptorPool::~VulkanDescriptorPool() {
81 // Destroying the VkDescriptorPool will automatically free and delete any VkDescriptorSets
82 // allocated from the pool.
83 VULKAN_CALL(fSharedContext->interface(),
84 DestroyDescriptorPool(fSharedContext->device(), fDescPool, nullptr));
85 if (fDescSetLayout != VK_NULL_HANDLE) {
86 VULKAN_CALL(fSharedContext->interface(),
87 DestroyDescriptorSetLayout(fSharedContext->device(), fDescSetLayout, nullptr));
88 fDescSetLayout = VK_NULL_HANDLE;
89 }
90}
91
92} // namespace skgpu::graphite
AutoreleasePool pool
#define SkASSERT(cond)
Definition: SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define VULKAN_CALL(IFACE, X)
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
constexpr bool empty() const
Definition: SkSpan_impl.h:96
constexpr size_t size() const
Definition: SkSpan_impl.h:95
static sk_sp< VulkanDescriptorPool > Make(const VulkanSharedContext *, SkSpan< DescriptorData >, VkDescriptorSetLayout)
const skgpu::VulkanInterface * interface() const
GAsyncResult * result
VkDescriptorType DsTypeEnumToVkDs(DescriptorType type)
const VkDescriptorPoolSize * pPoolSizes
Definition: vulkan_core.h:3760
VkDescriptorPoolCreateFlags flags
Definition: vulkan_core.h:3757
VkDescriptorType type
Definition: vulkan_core.h:3750
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
@ VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO
Definition: vulkan_core.h:235