Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/vk/GrVkDescriptorPool.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/private/SkTemplates.h" |
| 11 | #include "src/gpu/vk/GrVkGpu.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 12 | |
| 13 | |
Greg Daniel | 9b63dc8 | 2019-11-06 09:21:55 -0500 | [diff] [blame] | 14 | GrVkDescriptorPool* GrVkDescriptorPool::Create(GrVkGpu* gpu, VkDescriptorType type, |
| 15 | uint32_t count) { |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 16 | VkDescriptorPoolSize poolSize; |
| 17 | memset(&poolSize, 0, sizeof(VkDescriptorPoolSize)); |
| 18 | poolSize.descriptorCount = count; |
| 19 | poolSize.type = type; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 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; |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 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; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 30 | |
Greg Daniel | 9b63dc8 | 2019-11-06 09:21:55 -0500 | [diff] [blame] | 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 | } |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 38 | return new GrVkDescriptorPool(gpu, pool, type, count); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 39 | } |
| 40 | |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 41 | GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, VkDescriptorPool pool, |
| 42 | VkDescriptorType type, uint32_t count) |
| 43 | : INHERITED(gpu), fType(type), fCount(count), fDescPool(pool) {} |
Greg Daniel | 9b63dc8 | 2019-11-06 09:21:55 -0500 | [diff] [blame] | 44 | |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 45 | bool GrVkDescriptorPool::isCompatible(VkDescriptorType type, uint32_t count) const { |
| 46 | return fType == type && count <= fCount; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 47 | } |
| 48 | |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 49 | void GrVkDescriptorPool::freeGPUData() const { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 50 | // Destroying the VkDescriptorPool will automatically free and delete any VkDescriptorSets |
| 51 | // allocated from the pool. |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 52 | GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorPool(fGpu->device(), fDescPool, nullptr)); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 53 | } |