| 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 "src/gpu/ganesh/vk/GrVkDescriptorPool.h" |
| 9 |
|
| 10 |
#include "src/gpu/ganesh/vk/GrVkGpu.h" |
| 11 |
#include "src/gpu/ganesh/vk/GrVkUtil.h" |
| 12 |
|
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
GrVkDescriptorPool* GrVkDescriptorPool::Create(GrVkGpu* gpu, VkDescriptorType type, |
| 16 |
uint32_t count) { |
| 17 |
VkDescriptorPoolSize poolSize; |
| 18 |
memset(&poolSize, 0, sizeof(VkDescriptorPoolSize)); |
| 19 |
poolSize.descriptorCount = count; |
| 20 |
poolSize.type = type; |
| 21 |
|
| 22 |
VkDescriptorPoolCreateInfo createInfo; |
| 23 |
memset(&createInfo, 0, sizeof(VkDescriptorPoolCreateInfo)); |
| 24 |
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 25 |
createInfo.pNext = nullptr; |
| 26 |
createInfo.flags = 0; |
| 27 |
// This is an over/conservative estimate since each set may contain more than count descriptors. |
| 28 |
createInfo.maxSets = count; |
| 29 |
createInfo.poolSizeCount = 1; |
| 30 |
createInfo.pPoolSizes = &poolSize; |
| 31 |
|
| 32 |
VkDescriptorPool pool; |
| 33 |
VkResult result; |
| 34 |
GR_VK_CALL_RESULT(gpu, result, CreateDescriptorPool(gpu->device(), &createInfo, nullptr, |
| 35 |
&pool)); |
| 36 |
if (result != VK_SUCCESS) { |
| 37 |
return nullptr; |
| 38 |
} |
| 39 |
return new GrVkDescriptorPool(gpu, pool, type, count); |
| 40 |
} |
| 41 |
|
| 42 |
GrVkDescriptorPool::GrVkDescriptorPool(const GrVkGpu* gpu, VkDescriptorPool pool, |
| 43 |
VkDescriptorType type, uint32_t count) |
| 44 |
: INHERITED(gpu), fType(type), fCount(count), fDescPool(pool) {} |
| 45 |
|
| 46 |
bool GrVkDescriptorPool::isCompatible(VkDescriptorType type, uint32_t count) const { |
| 47 |
return fType == type && count <= fCount; |
| 48 |
} |
| 49 |
|
| 50 |
void GrVkDescriptorPool::freeGPUData() const { |
| 51 |
// Destroying the VkDescriptorPool will automatically free and delete any VkDescriptorSets |
| 52 |
// allocated from the pool. |
| 53 |
GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorPool(fGpu->device(), fDescPool, nullptr)); |
| 54 |
} |