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 #include "GrVkDescriptorPool.h"
9 
10 #include "GrVkGpu.h"
11 #include "SkTemplates.h"
12 
13 
14 GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, VkDescriptorType type, uint32_t count)
15     : INHERITED()
16     , fType (type)
17     , fCount(count) {
18     VkDescriptorPoolSize poolSize;
19     memset(&poolSize, 0, sizeof(VkDescriptorPoolSize));
20     poolSize.descriptorCount = count;
21     poolSize.type = type;
22 
23     VkDescriptorPoolCreateInfo createInfo;
24     memset(&createInfo, 0, sizeof(VkDescriptorPoolCreateInfo));
25     createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
26     createInfo.pNext = nullptr;
27     createInfo.flags = 0;
28     // This is an over/conservative estimate since each set may contain more than count descriptors.
29     createInfo.maxSets = count;
30     createInfo.poolSizeCount = 1;
31     createInfo.pPoolSizes = &poolSize;
32 
33     GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateDescriptorPool(gpu->device(),
34                                                                  &createInfo,
35                                                                  nullptr,
36                                                                  &fDescPool));
37 }
38 
39 bool GrVkDescriptorPool::isCompatible(VkDescriptorType type, uint32_t count) const {
40     return fType == type && count <= fCount;
41 }
42 
43 void GrVkDescriptorPool::reset(const GrVkGpu* gpu) {
44     GR_VK_CALL_ERRCHECK(gpu->vkInterface(), ResetDescriptorPool(gpu->device(), fDescPool, 0));
45 }
46 
47 void GrVkDescriptorPool::freeGPUData(const GrVkGpu* gpu) const {
48     // Destroying the VkDescriptorPool will automatically free and delete any VkDescriptorSets
49     // allocated from the pool.
50     GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorPool(gpu->device(), fDescPool, nullptr));
51 }
52