Chromium Code Reviews| 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 "GrVkDescriptorSetManager.h" | |
| 9 | |
| 10 #include "GrVkDescriptorPool.h" | |
| 11 #include "GrVkDescriptorSet.h" | |
| 12 #include "GrVkGpu.h" | |
| 13 | |
| 14 GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu, | |
| 15 VkDescriptorSetLayout layout, | |
| 16 VkDescriptorType type, | |
| 17 uint32_t samplerCount) | |
| 18 : fPoolManager(layout, type, samplerCount, gpu) | |
| 19 , fNumSamplerBindings(samplerCount) { | |
| 20 } | |
| 21 | |
| 22 const GrVkDescriptorSet* GrVkDescriptorSetManager::refDescriptorSet(GrVkGpu* gpu , | |
|
jvanverth1
2016/07/21 15:30:06
It's not clear why this is called refDescriptorSet
egdaniel
2016/07/21 17:27:11
Ah when I originally wrote this I was storing all
| |
| 23 const Handle & handle) { | |
| 24 const GrVkDescriptorSet* ds = nullptr; | |
| 25 int count = fFreeSets.count(); | |
| 26 if (count > 0) { | |
| 27 ds = fFreeSets[count - 1]; | |
| 28 fFreeSets.removeShuffle(count - 1); | |
|
jvanverth1
2016/07/21 15:30:06
I don't think it has to happen in this change, but
egdaniel
2016/07/21 17:27:11
Yeah I think it does actaully have a pop_back() me
| |
| 29 } else { | |
| 30 VkDescriptorSet vkDS; | |
| 31 fPoolManager.getNewDescriptorSet(gpu, &vkDS); | |
| 32 | |
| 33 ds = new GrVkDescriptorSet(vkDS, fPoolManager.fPool, handle); | |
| 34 } | |
| 35 SkASSERT(ds); | |
| 36 return ds; | |
| 37 } | |
| 38 | |
| 39 void GrVkDescriptorSetManager::recycleDescriptorSet(const GrVkDescriptorSet* des cSet) { | |
| 40 SkASSERT(descSet); | |
| 41 descSet->ref(); | |
|
jvanverth1
2016/07/21 15:30:06
I wonder if it makes sense to remove this, and the
egdaniel
2016/07/21 17:27:11
Done.
| |
| 42 fFreeSets.push_back(descSet); | |
| 43 } | |
| 44 | |
| 45 void GrVkDescriptorSetManager::release(const GrVkGpu* gpu) { | |
| 46 fPoolManager.freeGPUResources(gpu); | |
| 47 | |
| 48 for (int i = 0; i < fFreeSets.count(); ++i) { | |
| 49 fFreeSets[i]->unref(gpu); | |
| 50 } | |
| 51 fFreeSets.reset(); | |
| 52 } | |
| 53 | |
| 54 void GrVkDescriptorSetManager::abandon() { | |
| 55 fPoolManager.abandonGPUResources(); | |
| 56 | |
| 57 for (int i = 0; i < fFreeSets.count(); ++i) { | |
| 58 fFreeSets[i]->unrefAndAbandon(); | |
| 59 } | |
| 60 fFreeSets.reset(); | |
| 61 } | |
| 62 | |
| 63 //////////////////////////////////////////////////////////////////////////////// | |
| 64 | |
| 65 void GrVkDescriptorSetManager::DescriptorPoolManager::getNewPool(GrVkGpu* gpu) { | |
| 66 if (fPool) { | |
| 67 fPool->unref(gpu); | |
| 68 uint32_t newPoolSize = fMaxDescriptors + ((fMaxDescriptors + 1) >> 1); | |
| 69 if (newPoolSize < kMaxDescriptors) { | |
| 70 fMaxDescriptors = newPoolSize; | |
| 71 } else { | |
| 72 fMaxDescriptors = kMaxDescriptors; | |
| 73 } | |
| 74 | |
| 75 } | |
| 76 fPool = gpu->resourceProvider().findOrCreateCompatibleDescriptorPool(fDescTy pe, | |
| 77 fMaxDes criptors); | |
| 78 SkASSERT(fPool); | |
| 79 } | |
| 80 | |
| 81 void GrVkDescriptorSetManager::DescriptorPoolManager::getNewDescriptorSet(GrVkGp u* gpu, | |
| 82 VkDesc riptorSet* ds) { | |
| 83 if (!fMaxDescriptors) { | |
| 84 return; | |
| 85 } | |
| 86 fCurrentDescriptorCount += fDescCountPerSet; | |
| 87 if (fCurrentDescriptorCount > fMaxDescriptors) { | |
| 88 this->getNewPool(gpu); | |
| 89 fCurrentDescriptorCount = fDescCountPerSet; | |
| 90 } | |
| 91 | |
| 92 VkDescriptorSetAllocateInfo dsAllocateInfo; | |
| 93 memset(&dsAllocateInfo, 0, sizeof(VkDescriptorSetAllocateInfo)); | |
| 94 dsAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; | |
| 95 dsAllocateInfo.pNext = nullptr; | |
| 96 dsAllocateInfo.descriptorPool = fPool->descPool(); | |
| 97 dsAllocateInfo.descriptorSetCount = 1; | |
| 98 dsAllocateInfo.pSetLayouts = &fDescLayout; | |
| 99 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), AllocateDescriptorSets(gpu->device() , | |
| 100 &dsAllocateIn fo, | |
| 101 ds)); | |
| 102 } | |
| 103 | |
| 104 void GrVkDescriptorSetManager::DescriptorPoolManager::freeGPUResources(const GrV kGpu* gpu) { | |
| 105 // The layout should be owned by the class which owns the DescriptorSetManag er so it will | |
| 106 // take care of destroying it. | |
| 107 fDescLayout = VK_NULL_HANDLE; | |
| 108 | |
| 109 if (fPool) { | |
| 110 fPool->unref(gpu); | |
| 111 fPool = nullptr; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 void GrVkDescriptorSetManager::DescriptorPoolManager::abandonGPUResources() { | |
| 116 fDescLayout = VK_NULL_HANDLE; | |
| 117 if (fPool) { | |
| 118 fPool->unrefAndAbandon(); | |
| 119 fPool = nullptr; | |
| 120 } | |
| 121 } | |
| OLD | NEW |