| OLD | NEW |
| (Empty) |
| 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 | |
| 14 GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, const DescriptorTypeC
ounts& typeCounts) | |
| 15 : INHERITED() | |
| 16 , fTypeCounts(typeCounts) { | |
| 17 uint32_t numPools = fTypeCounts.numPoolSizes(); | |
| 18 SkAutoTDeleteArray<VkDescriptorPoolSize> poolSizes(new VkDescriptorPoolSize[
numPools]); | |
| 19 int currentPool = 0; | |
| 20 for (int i = VK_DESCRIPTOR_TYPE_BEGIN_RANGE; i < VK_DESCRIPTOR_TYPE_END_RANG
E; ++i) { | |
| 21 if (fTypeCounts.fDescriptorTypeCount[i]) { | |
| 22 VkDescriptorPoolSize& poolSize = poolSizes.get()[currentPool++]; | |
| 23 poolSize.type = (VkDescriptorType)i; | |
| 24 poolSize.descriptorCount = fTypeCounts.fDescriptorTypeCount[i]; | |
| 25 } | |
| 26 } | |
| 27 SkASSERT(currentPool == numPools); | |
| 28 | |
| 29 VkDescriptorPoolCreateInfo createInfo; | |
| 30 memset(&createInfo, 0, sizeof(VkDescriptorPoolCreateInfo)); | |
| 31 createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; | |
| 32 createInfo.pNext = nullptr; | |
| 33 createInfo.flags = 0; | |
| 34 createInfo.maxSets = 2; // Currently we allow one set for samplers and one
set for uniforms | |
| 35 createInfo.poolSizeCount = numPools; | |
| 36 createInfo.pPoolSizes = poolSizes.get(); | |
| 37 | |
| 38 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateDescriptorPool(gpu->device(), | |
| 39 &createInfo, | |
| 40 nullptr, | |
| 41 &fDescPool)); | |
| 42 } | |
| 43 | |
| 44 bool GrVkDescriptorPool::isCompatible(const DescriptorTypeCounts& typeCounts) co
nst { | |
| 45 return fTypeCounts.isSuperSet(typeCounts); | |
| 46 } | |
| 47 | |
| 48 void GrVkDescriptorPool::reset(const GrVkGpu* gpu) { | |
| 49 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), ResetDescriptorPool(gpu->device(), f
DescPool, 0)); | |
| 50 } | |
| 51 | |
| 52 void GrVkDescriptorPool::freeGPUData(const GrVkGpu* gpu) const { | |
| 53 // Destroying the VkDescriptorPool will automatically free and delete any Vk
DescriptorSets | |
| 54 // allocated from the pool. | |
| 55 GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorPool(gpu->device(), fDescPoo
l, nullptr)); | |
| 56 } | |
| 57 | |
| 58 /////////////////////////////////////////////////////////////////////////////// | |
| 59 | |
| 60 uint32_t GrVkDescriptorPool::DescriptorTypeCounts::numPoolSizes() const { | |
| 61 uint32_t count = 0; | |
| 62 for (int i = VK_DESCRIPTOR_TYPE_BEGIN_RANGE; i < VK_DESCRIPTOR_TYPE_END_RANG
E; ++i) { | |
| 63 count += fDescriptorTypeCount[i] ? 1 : 0; | |
| 64 } | |
| 65 return count; | |
| 66 } | |
| 67 | |
| 68 bool GrVkDescriptorPool::DescriptorTypeCounts::isSuperSet(const DescriptorTypeCo
unts& that) const { | |
| 69 for (int i = VK_DESCRIPTOR_TYPE_BEGIN_RANGE; i < VK_DESCRIPTOR_TYPE_END_RANG
E; ++i) { | |
| 70 if (that.fDescriptorTypeCount[i] > fDescriptorTypeCount[i]) { | |
| 71 return false; | |
| 72 } | |
| 73 } | |
| 74 return true; | |
| 75 } | |
| 76 | |
| 77 void GrVkDescriptorPool::DescriptorTypeCounts::setTypeCount(VkDescriptorType typ
e, uint8_t count) { | |
| 78 fDescriptorTypeCount[type] = count; | |
| 79 } | |
| OLD | NEW |