blob: cac3d4306a0b48a6cbffcd7bd7c204bc3b8fef7c [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 Daniel9b63dc82019-11-06 09:21:55 -050014GrVkDescriptorPool* GrVkDescriptorPool::Create(GrVkGpu* gpu, VkDescriptorType type,
15 uint32_t count) {
egdanielc2dc1b22016-03-18 13:18:23 -070016 VkDescriptorPoolSize poolSize;
17 memset(&poolSize, 0, sizeof(VkDescriptorPoolSize));
18 poolSize.descriptorCount = count;
19 poolSize.type = type;
Greg Daniel164a9f02016-02-22 09:56:40 -050020
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;
egdanielc2dc1b22016-03-18 13:18:23 -070026 // 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;
Greg Daniel164a9f02016-02-22 09:56:40 -050030
Greg Daniel9b63dc82019-11-06 09:21:55 -050031 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 }
Jim Van Verth5082df12020-03-11 16:14:51 -040038 return new GrVkDescriptorPool(gpu, pool, type, count);
Greg Daniel164a9f02016-02-22 09:56:40 -050039}
40
Jim Van Verth5082df12020-03-11 16:14:51 -040041GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, VkDescriptorPool pool,
42 VkDescriptorType type, uint32_t count)
43 : INHERITED(gpu), fType(type), fCount(count), fDescPool(pool) {}
Greg Daniel9b63dc82019-11-06 09:21:55 -050044
egdanielc2dc1b22016-03-18 13:18:23 -070045bool GrVkDescriptorPool::isCompatible(VkDescriptorType type, uint32_t count) const {
46 return fType == type && count <= fCount;
Greg Daniel164a9f02016-02-22 09:56:40 -050047}
48
Jim Van Verth5082df12020-03-11 16:14:51 -040049void GrVkDescriptorPool::freeGPUData() const {
Greg Daniel164a9f02016-02-22 09:56:40 -050050 // Destroying the VkDescriptorPool will automatically free and delete any VkDescriptorSets
51 // allocated from the pool.
Jim Van Verth5082df12020-03-11 16:14:51 -040052 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorPool(fGpu->device(), fDescPool, nullptr));
Greg Daniel164a9f02016-02-22 09:56:40 -050053}