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