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 #ifndef GrVkDescriptorSetManager_DEFINED | |
| 9 #define GrVkDescriptorSetManager_DEFINED | |
| 10 | |
| 11 #include "GrResourceHandle.h" | |
| 12 #include "GrVkDescriptorPool.h" | |
| 13 #include "SkRefCnt.h" | |
| 14 #include "SkTArray.h" | |
| 15 #include "vk/GrVkDefines.h" | |
| 16 | |
| 17 class GrVkDescriptorSet; | |
| 18 class GrVkGpu; | |
| 19 | |
| 20 /** | |
| 21 * 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 */ | |
| 24 class GrVkDescriptorSetManager { | |
| 25 public: | |
| 26 GR_DEFINE_RESOURCE_HANDLE_CLASS(Handle); | |
| 27 | |
| 28 GrVkDescriptorSetManager(GrVkGpu* gpu, | |
| 29 VkDescriptorSetLayout layout, | |
| 30 VkDescriptorType, | |
| 31 uint32_t samplerCount); | |
| 32 ~GrVkDescriptorSetManager() {} | |
| 33 | |
| 34 void abandon(); | |
| 35 void release(const GrVkGpu* gpu); | |
| 36 | |
| 37 const GrVkDescriptorSet* refDescriptorSet(GrVkGpu* gpu, const Handle& handle ); | |
|
jvanverth1
2016/07/21 15:30:06
why this?
egdaniel
2016/07/21 17:27:11
changed to get.
| |
| 38 | |
| 39 void recycleDescriptorSet(const GrVkDescriptorSet*); | |
| 40 | |
| 41 int isCompatible(uint32_t numSamplers) const { return numSamplers == fNumSam plerBindings; } | |
| 42 | |
| 43 private: | |
| 44 struct DescriptorPoolManager { | |
| 45 DescriptorPoolManager(VkDescriptorSetLayout layout, VkDescriptorType typ e, | |
| 46 uint32_t samplerCount, GrVkGpu* gpu) | |
| 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 | |
| 64 ~DescriptorPoolManager() { | |
| 65 SkASSERT(!fDescLayout); | |
| 66 SkASSERT(!fPool); | |
| 67 } | |
| 68 | |
| 69 void getNewDescriptorSet(GrVkGpu* gpu, VkDescriptorSet* ds); | |
| 70 | |
| 71 void freeGPUResources(const GrVkGpu* gpu); | |
| 72 void abandonGPUResources(); | |
| 73 | |
| 74 VkDescriptorSetLayout fDescLayout; // Not owned by this class | |
| 75 VkDescriptorType fDescType; | |
| 76 uint32_t fDescCountPerSet; | |
| 77 uint32_t fMaxDescriptors; | |
| 78 uint32_t fCurrentDescriptorCount; | |
| 79 GrVkDescriptorPool* fPool; | |
| 80 | |
| 81 private: | |
|
jvanverth1
2016/07/21 15:30:06
Indented one space too far?
egdaniel
2016/07/21 17:27:11
Done.
| |
| 82 enum { | |
| 83 kNumUniformDescPerSet = 2, | |
| 84 kMaxDescriptors = 1024, | |
| 85 kStartNumDescriptors = 16, // must be less than kMaxUniformDescripto rs | |
| 86 }; | |
| 87 | |
| 88 void getNewPool(GrVkGpu* gpu); | |
| 89 }; | |
| 90 | |
| 91 DescriptorPoolManager fPoolManager; | |
| 92 SkTArray<const GrVkDescriptorSet*> fFreeSets; | |
| 93 // If the number of bindings in 0 we assume this is for uniform buffers | |
|
jvanverth1
2016/07/21 15:30:06
sp: is 0
egdaniel
2016/07/21 17:27:11
Done.
| |
| 94 uint32_t fNumSamplerBindings; | |
| 95 }; | |
| 96 | |
| 97 #endif | |
| OLD | NEW |