blob: ffb6626a24063ab36b4cb1f8c8222df0c50e0992 [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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
egdanielc2dc1b22016-03-18 13:18:23 -070014GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, VkDescriptorType type, uint32_t count)
Greg Daniel164a9f02016-02-22 09:56:40 -050015 : INHERITED()
halcanary9d524f22016-03-29 09:03:52 -070016 , fType (type)
egdanielc2dc1b22016-03-18 13:18:23 -070017 , fCount(count) {
18 VkDescriptorPoolSize poolSize;
19 memset(&poolSize, 0, sizeof(VkDescriptorPoolSize));
20 poolSize.descriptorCount = count;
21 poolSize.type = type;
Greg Daniel164a9f02016-02-22 09:56:40 -050022
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;
egdanielc2dc1b22016-03-18 13:18:23 -070028 // 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;
Greg Daniel164a9f02016-02-22 09:56:40 -050032
33 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateDescriptorPool(gpu->device(),
34 &createInfo,
35 nullptr,
36 &fDescPool));
37}
38
egdanielc2dc1b22016-03-18 13:18:23 -070039bool GrVkDescriptorPool::isCompatible(VkDescriptorType type, uint32_t count) const {
40 return fType == type && count <= fCount;
Greg Daniel164a9f02016-02-22 09:56:40 -050041}
42
43void GrVkDescriptorPool::reset(const GrVkGpu* gpu) {
44 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), ResetDescriptorPool(gpu->device(), fDescPool, 0));
45}
46
Ethan Nicholas8e265a72018-12-12 16:22:40 -050047void GrVkDescriptorPool::freeGPUData(GrVkGpu* gpu) const {
Greg Daniel164a9f02016-02-22 09:56:40 -050048 // 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}