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 | |
| 8 | #include "GrVkDescriptorPool.h" |
| 9 | |
| 10 | #include "GrVkGpu.h" |
| 11 | #include "SkTemplates.h" |
| 12 | |
| 13 | |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 14 | GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, VkDescriptorType type, uint32_t count) |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 15 | : INHERITED() |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 16 | , fType (type) |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 17 | , fCount(count) { |
| 18 | VkDescriptorPoolSize poolSize; |
| 19 | memset(&poolSize, 0, sizeof(VkDescriptorPoolSize)); |
| 20 | poolSize.descriptorCount = count; |
| 21 | poolSize.type = type; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 22 | |
| 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; |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 28 | // 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 Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 32 | |
| 33 | GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateDescriptorPool(gpu->device(), |
| 34 | &createInfo, |
| 35 | nullptr, |
| 36 | &fDescPool)); |
| 37 | } |
| 38 | |
egdaniel | c2dc1b2 | 2016-03-18 13:18:23 -0700 | [diff] [blame] | 39 | bool GrVkDescriptorPool::isCompatible(VkDescriptorType type, uint32_t count) const { |
| 40 | return fType == type && count <= fCount; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void GrVkDescriptorPool::reset(const GrVkGpu* gpu) { |
| 44 | GR_VK_CALL_ERRCHECK(gpu->vkInterface(), ResetDescriptorPool(gpu->device(), fDescPool, 0)); |
| 45 | } |
| 46 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame^] | 47 | void GrVkDescriptorPool::freeGPUData(GrVkGpu* gpu) const { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 48 | // 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 | } |