blob: 6c9a6f805561eb0c4c270fcd9547a3e4b6cb6457 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/vk/GrVkDescriptorPool.h"
Greg Daniel164a9f02016-02-22 09:56:40 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/private/SkTemplates.h"
11#include "src/gpu/vk/GrVkGpu.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050012
13
Greg Daniele643da62019-11-05 12:36:42 -050014GrVkDescriptorPool::GrVkDescriptorPool(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
Greg Daniele643da62019-11-05 12:36:42 -050033 GR_VK_CALL_ERRCHECK(gpu, CreateDescriptorPool(gpu->device(), &createInfo, nullptr, &fDescPool));
Greg Daniel164a9f02016-02-22 09:56:40 -050034}
35
egdanielc2dc1b22016-03-18 13:18:23 -070036bool GrVkDescriptorPool::isCompatible(VkDescriptorType type, uint32_t count) const {
37 return fType == type && count <= fCount;
Greg Daniel164a9f02016-02-22 09:56:40 -050038}
39
Greg Daniele643da62019-11-05 12:36:42 -050040void GrVkDescriptorPool::reset(GrVkGpu* gpu) {
41 GR_VK_CALL_ERRCHECK(gpu, ResetDescriptorPool(gpu->device(), fDescPool, 0));
Greg Daniel164a9f02016-02-22 09:56:40 -050042}
43
Ethan Nicholas8e265a72018-12-12 16:22:40 -050044void GrVkDescriptorPool::freeGPUData(GrVkGpu* gpu) const {
Greg Daniel164a9f02016-02-22 09:56:40 -050045 // Destroying the VkDescriptorPool will automatically free and delete any VkDescriptorSets
46 // allocated from the pool.
47 GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorPool(gpu->device(), fDescPool, nullptr));
48}