| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrVkDescriptorSetManager_DEFINED | 8 #ifndef GrVkDescriptorSetManager_DEFINED |
| 9 #define GrVkDescriptorSetManager_DEFINED | 9 #define GrVkDescriptorSetManager_DEFINED |
| 10 | 10 |
| 11 #include "GrResourceHandle.h" | 11 #include "GrResourceHandle.h" |
| 12 #include "GrVkDescriptorPool.h" | 12 #include "GrVkDescriptorPool.h" |
| 13 #include "SkRefCnt.h" | 13 #include "SkRefCnt.h" |
| 14 #include "SkTArray.h" | 14 #include "SkTArray.h" |
| 15 #include "vk/GrVkDefines.h" | 15 #include "vk/GrVkDefines.h" |
| 16 | 16 |
| 17 class GrVkDescriptorSet; | 17 class GrVkDescriptorSet; |
| 18 class GrVkGpu; | 18 class GrVkGpu; |
| 19 class GrVkUniformHandler; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * This class handles the allocation of descriptor sets for a given VkDescriptor
SetLayout. It will | 22 * This class handles the allocation of descriptor sets for a given VkDescriptor
SetLayout. It will |
| 22 * try to reuse previously allocated descriptor sets if they are no longer in us
e by other objects. | 23 * try to reuse previously allocated descriptor sets if they are no longer in us
e by other objects. |
| 23 */ | 24 */ |
| 24 class GrVkDescriptorSetManager { | 25 class GrVkDescriptorSetManager { |
| 25 public: | 26 public: |
| 26 GR_DEFINE_RESOURCE_HANDLE_CLASS(Handle); | 27 GR_DEFINE_RESOURCE_HANDLE_CLASS(Handle); |
| 27 | 28 |
| 28 GrVkDescriptorSetManager(GrVkGpu* gpu, | 29 GrVkDescriptorSetManager(GrVkGpu* gpu, |
| 29 VkDescriptorSetLayout layout, | |
| 30 VkDescriptorType, | 30 VkDescriptorType, |
| 31 uint32_t samplerCount); | 31 const GrVkUniformHandler* handler = nullptr); |
| 32 ~GrVkDescriptorSetManager() {} | 32 ~GrVkDescriptorSetManager() {} |
| 33 | 33 |
| 34 void abandon(); | 34 void abandon(); |
| 35 void release(const GrVkGpu* gpu); | 35 void release(const GrVkGpu* gpu); |
| 36 | 36 |
| 37 VkDescriptorSetLayout layout() const { return fPoolManager.fDescLayout; } |
| 38 |
| 37 const GrVkDescriptorSet* getDescriptorSet(GrVkGpu* gpu, const Handle& handle
); | 39 const GrVkDescriptorSet* getDescriptorSet(GrVkGpu* gpu, const Handle& handle
); |
| 38 | 40 |
| 39 void recycleDescriptorSet(const GrVkDescriptorSet*); | 41 void recycleDescriptorSet(const GrVkDescriptorSet*); |
| 40 | 42 |
| 41 int isCompatible(uint32_t numSamplers) const { return numSamplers == fNumSam
plerBindings; } | 43 bool isCompatible(VkDescriptorType type, const GrVkUniformHandler*) const; |
| 42 | 44 |
| 43 private: | 45 private: |
| 44 struct DescriptorPoolManager { | 46 struct DescriptorPoolManager { |
| 45 DescriptorPoolManager(VkDescriptorSetLayout layout, VkDescriptorType typ
e, | 47 DescriptorPoolManager(VkDescriptorType type, GrVkGpu* gpu, |
| 46 uint32_t samplerCount, GrVkGpu* gpu) | 48 const GrVkUniformHandler* handler = nullptr); |
| 47 : fDescLayout(layout) | |
| 48 , fDescType(type) | |
| 49 , fCurrentDescriptorCount(0) | |
| 50 , fPool(nullptr) { | |
| 51 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER == type) { | |
| 52 fDescCountPerSet = kNumUniformDescPerSet; | |
| 53 } else { | |
| 54 SkASSERT(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); | |
| 55 fDescCountPerSet = samplerCount; | |
| 56 } | |
| 57 | |
| 58 SkASSERT(fDescCountPerSet < kStartNumDescriptors); | |
| 59 fMaxDescriptors = kStartNumDescriptors; | |
| 60 SkASSERT(fMaxDescriptors > 0); | |
| 61 this->getNewPool(gpu); | |
| 62 } | |
| 63 | 49 |
| 64 ~DescriptorPoolManager() { | 50 ~DescriptorPoolManager() { |
| 65 SkASSERT(!fDescLayout); | 51 SkASSERT(!fDescLayout); |
| 66 SkASSERT(!fPool); | 52 SkASSERT(!fPool); |
| 67 } | 53 } |
| 68 | 54 |
| 69 void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds); | 55 void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds); |
| 70 | 56 |
| 71 void freeGPUResources(const GrVkGpu* gpu); | 57 void freeGPUResources(const GrVkGpu* gpu); |
| 72 void abandonGPUResources(); | 58 void abandonGPUResources(); |
| 73 | 59 |
| 74 VkDescriptorSetLayout fDescLayout; // Not owned by this class | 60 VkDescriptorSetLayout fDescLayout; |
| 75 VkDescriptorType fDescType; | 61 VkDescriptorType fDescType; |
| 76 uint32_t fDescCountPerSet; | 62 uint32_t fDescCountPerSet; |
| 77 uint32_t fMaxDescriptors; | 63 uint32_t fMaxDescriptors; |
| 78 uint32_t fCurrentDescriptorCount; | 64 uint32_t fCurrentDescriptorCount; |
| 79 GrVkDescriptorPool* fPool; | 65 GrVkDescriptorPool* fPool; |
| 80 | 66 |
| 81 private: | 67 private: |
| 82 enum { | 68 enum { |
| 83 kNumUniformDescPerSet = 2, | 69 kUniformDescPerSet = 2, |
| 84 kMaxDescriptors = 1024, | 70 kMaxDescriptors = 1024, |
| 85 kStartNumDescriptors = 16, // must be less than kMaxUniformDescripto
rs | 71 kStartNumDescriptors = 16, // must be less than kMaxUniformDescripto
rs |
| 86 }; | 72 }; |
| 87 | 73 |
| 88 void getNewPool(GrVkGpu* gpu); | 74 void getNewPool(GrVkGpu* gpu); |
| 89 }; | 75 }; |
| 90 | 76 |
| 91 DescriptorPoolManager fPoolManager; | 77 DescriptorPoolManager fPoolManager; |
| 92 SkTArray<const GrVkDescriptorSet*> fFreeSets; | 78 SkTArray<const GrVkDescriptorSet*, true> fFreeSets; |
| 93 // If the number of bindings is 0 we assume this is for uniform buffers | 79 SkSTArray<4, uint32_t> fBindingVisibilities; |
| 94 uint32_t fNumSamplerBindings; | |
| 95 }; | 80 }; |
| 96 | 81 |
| 97 #endif | 82 #endif |
| OLD | NEW |