egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [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/GrVkDescriptorSetManager.h" |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/vk/GrVkDescriptorPool.h" |
| 11 | #include "src/gpu/vk/GrVkDescriptorSet.h" |
| 12 | #include "src/gpu/vk/GrVkGpu.h" |
| 13 | #include "src/gpu/vk/GrVkUniformHandler.h" |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 14 | |
Ben Wagner | 6c30e74 | 2019-02-06 10:46:14 -0500 | [diff] [blame] | 15 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 16 | #include <sanitizer/lsan_interface.h> |
| 17 | #endif |
| 18 | |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 19 | GrVkDescriptorSetManager* GrVkDescriptorSetManager::CreateUniformManager(GrVkGpu* gpu) { |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame^] | 20 | SkSTArray<1, uint32_t> visibilities; |
| 21 | uint32_t stages = kVertex_GrShaderFlag | kFragment_GrShaderFlag; |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 22 | if (gpu->vkCaps().shaderCaps()->geometryShaderSupport()) { |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame^] | 23 | stages |= kGeometry_GrShaderFlag; |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 24 | } |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame^] | 25 | visibilities.push_back(stages); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 26 | |
| 27 | SkTArray<const GrVkSampler*> samplers; |
| 28 | return new GrVkDescriptorSetManager(gpu, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, visibilities, |
| 29 | samplers); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | GrVkDescriptorSetManager* GrVkDescriptorSetManager::CreateSamplerManager( |
| 33 | GrVkGpu* gpu, VkDescriptorType type, const GrVkUniformHandler& uniformHandler) { |
| 34 | SkSTArray<4, uint32_t> visibilities; |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 35 | SkSTArray<4, const GrVkSampler*> immutableSamplers; |
Brian Salomon | 662ea4b | 2018-07-12 14:53:49 -0400 | [diff] [blame] | 36 | SkASSERT(type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 37 | for (int i = 0 ; i < uniformHandler.numSamplers(); ++i) { |
| 38 | visibilities.push_back(uniformHandler.samplerVisibility(i)); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 39 | immutableSamplers.push_back(uniformHandler.immutableSampler(i)); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 40 | } |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 41 | return new GrVkDescriptorSetManager(gpu, type, visibilities, immutableSamplers); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | GrVkDescriptorSetManager* GrVkDescriptorSetManager::CreateSamplerManager( |
| 45 | GrVkGpu* gpu, VkDescriptorType type, const SkTArray<uint32_t>& visibilities) { |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 46 | SkSTArray<4, const GrVkSampler*> immutableSamplers; |
| 47 | SkASSERT(type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 48 | for (int i = 0 ; i < visibilities.count(); ++i) { |
| 49 | immutableSamplers.push_back(nullptr); |
| 50 | } |
| 51 | return new GrVkDescriptorSetManager(gpu, type, visibilities, immutableSamplers); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 54 | GrVkDescriptorSetManager::GrVkDescriptorSetManager( |
| 55 | GrVkGpu* gpu, VkDescriptorType type, |
| 56 | const SkTArray<uint32_t>& visibilities, |
| 57 | const SkTArray<const GrVkSampler*>& immutableSamplers) |
| 58 | : fPoolManager(type, gpu, visibilities, immutableSamplers) { |
| 59 | #ifdef SK_DEBUG |
| 60 | if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) { |
| 61 | SkASSERT(visibilities.count() == immutableSamplers.count()); |
| 62 | } else { |
| 63 | SkASSERT(immutableSamplers.count() == 0); |
| 64 | } |
| 65 | #endif |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 66 | for (int i = 0; i < visibilities.count(); ++i) { |
| 67 | fBindingVisibilities.push_back(visibilities[i]); |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 68 | } |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 69 | for (int i = 0; i < immutableSamplers.count(); ++i) { |
| 70 | const GrVkSampler* sampler = immutableSamplers[i]; |
| 71 | if (sampler) { |
| 72 | sampler->ref(); |
| 73 | } |
| 74 | fImmutableSamplers.push_back(sampler); |
| 75 | } |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 76 | } |
| 77 | |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 78 | const GrVkDescriptorSet* GrVkDescriptorSetManager::getDescriptorSet(GrVkGpu* gpu, |
| 79 | const Handle& handle) { |
| 80 | const GrVkDescriptorSet* ds = nullptr; |
| 81 | int count = fFreeSets.count(); |
| 82 | if (count > 0) { |
| 83 | ds = fFreeSets[count - 1]; |
| 84 | fFreeSets.removeShuffle(count - 1); |
| 85 | } else { |
| 86 | VkDescriptorSet vkDS; |
| 87 | fPoolManager.getNewDescriptorSet(gpu, &vkDS); |
| 88 | |
| 89 | ds = new GrVkDescriptorSet(vkDS, fPoolManager.fPool, handle); |
| 90 | } |
| 91 | SkASSERT(ds); |
| 92 | return ds; |
| 93 | } |
| 94 | |
| 95 | void GrVkDescriptorSetManager::recycleDescriptorSet(const GrVkDescriptorSet* descSet) { |
| 96 | SkASSERT(descSet); |
| 97 | fFreeSets.push_back(descSet); |
| 98 | } |
| 99 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 100 | void GrVkDescriptorSetManager::release(GrVkGpu* gpu) { |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 101 | fPoolManager.freeGPUResources(gpu); |
| 102 | |
| 103 | for (int i = 0; i < fFreeSets.count(); ++i) { |
| 104 | fFreeSets[i]->unref(gpu); |
| 105 | } |
| 106 | fFreeSets.reset(); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 107 | |
| 108 | for (int i = 0; i < fImmutableSamplers.count(); ++i) { |
| 109 | if (fImmutableSamplers[i]) { |
| 110 | fImmutableSamplers[i]->unref(gpu); |
| 111 | } |
| 112 | } |
| 113 | fImmutableSamplers.reset(); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void GrVkDescriptorSetManager::abandon() { |
| 117 | fPoolManager.abandonGPUResources(); |
| 118 | |
| 119 | for (int i = 0; i < fFreeSets.count(); ++i) { |
| 120 | fFreeSets[i]->unrefAndAbandon(); |
| 121 | } |
| 122 | fFreeSets.reset(); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 123 | |
| 124 | for (int i = 0; i < fImmutableSamplers.count(); ++i) { |
| 125 | if (fImmutableSamplers[i]) { |
| 126 | fImmutableSamplers[i]->unrefAndAbandon(); |
| 127 | } |
| 128 | } |
| 129 | fImmutableSamplers.reset(); |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 130 | } |
| 131 | |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 132 | bool GrVkDescriptorSetManager::isCompatible(VkDescriptorType type, |
| 133 | const GrVkUniformHandler* uniHandler) const { |
| 134 | SkASSERT(uniHandler); |
| 135 | if (type != fPoolManager.fDescType) { |
| 136 | return false; |
| 137 | } |
| 138 | |
Brian Salomon | 662ea4b | 2018-07-12 14:53:49 -0400 | [diff] [blame] | 139 | SkASSERT(type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 140 | if (fBindingVisibilities.count() != uniHandler->numSamplers()) { |
| 141 | return false; |
| 142 | } |
| 143 | for (int i = 0; i < uniHandler->numSamplers(); ++i) { |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 144 | if (uniHandler->samplerVisibility(i) != fBindingVisibilities[i] || |
| 145 | uniHandler->immutableSampler(i) != fImmutableSamplers[i]) { |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 146 | return false; |
| 147 | } |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 148 | } |
| 149 | return true; |
| 150 | } |
| 151 | |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 152 | bool GrVkDescriptorSetManager::isCompatible(VkDescriptorType type, |
| 153 | const SkTArray<uint32_t>& visibilities) const { |
| 154 | if (type != fPoolManager.fDescType) { |
| 155 | return false; |
| 156 | } |
| 157 | |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 158 | if (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER == type || |
| 159 | VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER == type) { |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 160 | if (fBindingVisibilities.count() != visibilities.count()) { |
| 161 | return false; |
| 162 | } |
| 163 | for (int i = 0; i < visibilities.count(); ++i) { |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 164 | if (visibilities[i] != fBindingVisibilities[i] || fImmutableSamplers[i] != nullptr) { |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 165 | return false; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | return true; |
| 170 | } |
| 171 | |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 172 | //////////////////////////////////////////////////////////////////////////////// |
| 173 | |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 174 | VkShaderStageFlags visibility_to_vk_stage_flags(uint32_t visibility) { |
| 175 | VkShaderStageFlags flags = 0; |
| 176 | |
| 177 | if (visibility & kVertex_GrShaderFlag) { |
| 178 | flags |= VK_SHADER_STAGE_VERTEX_BIT; |
| 179 | } |
| 180 | if (visibility & kGeometry_GrShaderFlag) { |
| 181 | flags |= VK_SHADER_STAGE_GEOMETRY_BIT; |
| 182 | } |
| 183 | if (visibility & kFragment_GrShaderFlag) { |
| 184 | flags |= VK_SHADER_STAGE_FRAGMENT_BIT; |
| 185 | } |
| 186 | return flags; |
| 187 | } |
| 188 | |
| 189 | GrVkDescriptorSetManager::DescriptorPoolManager::DescriptorPoolManager( |
| 190 | VkDescriptorType type, |
| 191 | GrVkGpu* gpu, |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 192 | const SkTArray<uint32_t>& visibilities, |
| 193 | const SkTArray<const GrVkSampler*>& immutableSamplers) |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 194 | : fDescType(type) |
| 195 | , fCurrentDescriptorCount(0) |
| 196 | , fPool(nullptr) { |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 197 | |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 198 | |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 199 | if (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER == type || |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 200 | VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER == type) { |
| 201 | uint32_t numBindings = visibilities.count(); |
| 202 | std::unique_ptr<VkDescriptorSetLayoutBinding[]> dsSamplerBindings( |
| 203 | new VkDescriptorSetLayoutBinding[numBindings]); |
| 204 | for (uint32_t i = 0; i < numBindings; ++i) { |
| 205 | uint32_t visibility = visibilities[i]; |
| 206 | dsSamplerBindings[i].binding = i; |
| 207 | dsSamplerBindings[i].descriptorType = type; |
| 208 | dsSamplerBindings[i].descriptorCount = 1; |
| 209 | dsSamplerBindings[i].stageFlags = visibility_to_vk_stage_flags(visibility); |
Greg Daniel | 7a82edf | 2018-12-04 10:54:34 -0500 | [diff] [blame] | 210 | if (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER == type) { |
| 211 | if (immutableSamplers[i]) { |
| 212 | dsSamplerBindings[i].pImmutableSamplers = immutableSamplers[i]->samplerPtr(); |
| 213 | } else { |
| 214 | dsSamplerBindings[i].pImmutableSamplers = nullptr; |
| 215 | } |
| 216 | } |
egdaniel | 4d866df | 2016-08-25 13:52:00 -0700 | [diff] [blame] | 217 | } |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 218 | |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 219 | VkDescriptorSetLayoutCreateInfo dsSamplerLayoutCreateInfo; |
| 220 | memset(&dsSamplerLayoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo)); |
| 221 | dsSamplerLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 222 | dsSamplerLayoutCreateInfo.pNext = nullptr; |
| 223 | dsSamplerLayoutCreateInfo.flags = 0; |
| 224 | dsSamplerLayoutCreateInfo.bindingCount = numBindings; |
| 225 | // Setting to nullptr fixes an error in the param checker validation layer. Even though |
| 226 | // bindingCount is 0 (which is valid), it still tries to validate pBindings unless it is |
| 227 | // null. |
| 228 | dsSamplerLayoutCreateInfo.pBindings = numBindings ? dsSamplerBindings.get() : nullptr; |
| 229 | |
Ben Wagner | 6c30e74 | 2019-02-06 10:46:14 -0500 | [diff] [blame] | 230 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 231 | // skia:8713 |
| 232 | __lsan::ScopedDisabler lsanDisabler; |
| 233 | #endif |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 234 | GR_VK_CALL_ERRCHECK(gpu->vkInterface(), |
| 235 | CreateDescriptorSetLayout(gpu->device(), |
| 236 | &dsSamplerLayoutCreateInfo, |
| 237 | nullptr, |
| 238 | &fDescLayout)); |
| 239 | fDescCountPerSet = visibilities.count(); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 240 | } else { |
Greg Daniel | a754378 | 2017-05-02 14:01:43 -0400 | [diff] [blame] | 241 | SkASSERT(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER == type); |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame^] | 242 | GR_STATIC_ASSERT(1 == kUniformDescPerSet); |
Greg Daniel | 18f9602 | 2017-05-04 15:09:03 -0400 | [diff] [blame] | 243 | SkASSERT(kUniformDescPerSet == visibilities.count()); |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 244 | // Create Uniform Buffer Descriptor |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame^] | 245 | VkDescriptorSetLayoutBinding dsUniBinding; |
| 246 | memset(&dsUniBinding, 0, sizeof(dsUniBinding)); |
| 247 | dsUniBinding.binding = GrVkUniformHandler::kUniformBinding; |
| 248 | dsUniBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 249 | dsUniBinding.descriptorCount = 1; |
| 250 | dsUniBinding.stageFlags = visibility_to_vk_stage_flags(visibilities[0]); |
| 251 | dsUniBinding.pImmutableSamplers = nullptr; |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 252 | |
| 253 | VkDescriptorSetLayoutCreateInfo uniformLayoutCreateInfo; |
| 254 | memset(&uniformLayoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo)); |
| 255 | uniformLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 256 | uniformLayoutCreateInfo.pNext = nullptr; |
| 257 | uniformLayoutCreateInfo.flags = 0; |
Ethan Nicholas | 0be3480 | 2019-08-15 12:36:58 -0400 | [diff] [blame^] | 258 | uniformLayoutCreateInfo.bindingCount = 1; |
| 259 | uniformLayoutCreateInfo.pBindings = &dsUniBinding; |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 260 | |
Ben Wagner | 6c30e74 | 2019-02-06 10:46:14 -0500 | [diff] [blame] | 261 | #if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS) |
| 262 | // skia:8713 |
| 263 | __lsan::ScopedDisabler lsanDisabler; |
| 264 | #endif |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 265 | GR_VK_CALL_ERRCHECK(gpu->vkInterface(), CreateDescriptorSetLayout(gpu->device(), |
| 266 | &uniformLayoutCreateInfo, |
| 267 | nullptr, |
| 268 | &fDescLayout)); |
| 269 | fDescCountPerSet = kUniformDescPerSet; |
| 270 | } |
| 271 | |
| 272 | SkASSERT(fDescCountPerSet < kStartNumDescriptors); |
| 273 | fMaxDescriptors = kStartNumDescriptors; |
| 274 | SkASSERT(fMaxDescriptors > 0); |
| 275 | this->getNewPool(gpu); |
| 276 | } |
| 277 | |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 278 | void GrVkDescriptorSetManager::DescriptorPoolManager::getNewPool(GrVkGpu* gpu) { |
| 279 | if (fPool) { |
| 280 | fPool->unref(gpu); |
| 281 | uint32_t newPoolSize = fMaxDescriptors + ((fMaxDescriptors + 1) >> 1); |
| 282 | if (newPoolSize < kMaxDescriptors) { |
| 283 | fMaxDescriptors = newPoolSize; |
| 284 | } else { |
| 285 | fMaxDescriptors = kMaxDescriptors; |
| 286 | } |
| 287 | |
| 288 | } |
| 289 | fPool = gpu->resourceProvider().findOrCreateCompatibleDescriptorPool(fDescType, |
| 290 | fMaxDescriptors); |
| 291 | SkASSERT(fPool); |
| 292 | } |
| 293 | |
| 294 | void GrVkDescriptorSetManager::DescriptorPoolManager::getNewDescriptorSet(GrVkGpu* gpu, |
| 295 | VkDescriptorSet* ds) { |
| 296 | if (!fMaxDescriptors) { |
| 297 | return; |
| 298 | } |
| 299 | fCurrentDescriptorCount += fDescCountPerSet; |
| 300 | if (fCurrentDescriptorCount > fMaxDescriptors) { |
| 301 | this->getNewPool(gpu); |
| 302 | fCurrentDescriptorCount = fDescCountPerSet; |
| 303 | } |
| 304 | |
| 305 | VkDescriptorSetAllocateInfo dsAllocateInfo; |
| 306 | memset(&dsAllocateInfo, 0, sizeof(VkDescriptorSetAllocateInfo)); |
| 307 | dsAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 308 | dsAllocateInfo.pNext = nullptr; |
| 309 | dsAllocateInfo.descriptorPool = fPool->descPool(); |
| 310 | dsAllocateInfo.descriptorSetCount = 1; |
| 311 | dsAllocateInfo.pSetLayouts = &fDescLayout; |
| 312 | GR_VK_CALL_ERRCHECK(gpu->vkInterface(), AllocateDescriptorSets(gpu->device(), |
| 313 | &dsAllocateInfo, |
| 314 | ds)); |
| 315 | } |
| 316 | |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 317 | void GrVkDescriptorSetManager::DescriptorPoolManager::freeGPUResources(GrVkGpu* gpu) { |
egdaniel | 707bbd6 | 2016-07-26 07:19:47 -0700 | [diff] [blame] | 318 | if (fDescLayout) { |
| 319 | GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorSetLayout(gpu->device(), fDescLayout, |
| 320 | nullptr)); |
| 321 | fDescLayout = VK_NULL_HANDLE; |
| 322 | } |
egdaniel | a95220d | 2016-07-21 11:50:37 -0700 | [diff] [blame] | 323 | |
| 324 | if (fPool) { |
| 325 | fPool->unref(gpu); |
| 326 | fPool = nullptr; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | void GrVkDescriptorSetManager::DescriptorPoolManager::abandonGPUResources() { |
| 331 | fDescLayout = VK_NULL_HANDLE; |
| 332 | if (fPool) { |
| 333 | fPool->unrefAndAbandon(); |
| 334 | fPool = nullptr; |
| 335 | } |
| 336 | } |