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 #include "GrVkDescriptorSetManager.h" | 8 #include "GrVkDescriptorSetManager.h" |
9 | 9 |
10 #include "GrVkDescriptorPool.h" | 10 #include "GrVkDescriptorPool.h" |
11 #include "GrVkDescriptorSet.h" | 11 #include "GrVkDescriptorSet.h" |
12 #include "GrVkGpu.h" | 12 #include "GrVkGpu.h" |
13 #include "GrVkUniformHandler.h" | |
14 #include "glsl/GrGLSLSampler.h" | |
13 | 15 |
14 GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu, | 16 GrVkDescriptorSetManager::GrVkDescriptorSetManager(GrVkGpu* gpu, |
15 VkDescriptorSetLayout layout, | 17 VkDescriptorSetLayout layout, |
16 VkDescriptorType type, | 18 VkDescriptorType type, |
17 uint32_t samplerCount) | 19 uint32_t descCountPerSet, |
18 : fPoolManager(layout, type, samplerCount, gpu) | 20 const GrVkUniformHandler* uni formHandler) |
19 , fNumSamplerBindings(samplerCount) { | 21 : fPoolManager(layout, type, descCountPerSet, gpu) { |
22 if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) { | |
23 SkASSERT(uniformHandler); | |
24 SkASSERT((int)descCountPerSet == uniformHandler->numSamplers()); | |
25 for (int i = 0; i < uniformHandler->numSamplers(); ++i) { | |
26 fBindingVisibilities.push_back(uniformHandler->getSampler(i).visibil ity()); | |
27 } | |
28 } else { | |
29 SkASSERT(type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); | |
30 SkASSERT(2 == descCountPerSet); | |
31 // We set the visibility of the first binding to the vertex shader and t he second to the | |
32 // fragment shader. | |
33 fBindingVisibilities.push_back(kVertex_GrShaderFlag); | |
34 fBindingVisibilities.push_back(kFragment_GrShaderFlag); | |
35 } | |
20 } | 36 } |
21 | 37 |
22 const GrVkDescriptorSet* GrVkDescriptorSetManager::getDescriptorSet(GrVkGpu* gpu , | 38 const GrVkDescriptorSet* GrVkDescriptorSetManager::getDescriptorSet(GrVkGpu* gpu , |
23 const Handle & handle) { | 39 const Handle & handle) { |
24 const GrVkDescriptorSet* ds = nullptr; | 40 const GrVkDescriptorSet* ds = nullptr; |
25 int count = fFreeSets.count(); | 41 int count = fFreeSets.count(); |
26 if (count > 0) { | 42 if (count > 0) { |
27 ds = fFreeSets[count - 1]; | 43 ds = fFreeSets[count - 1]; |
28 fFreeSets.removeShuffle(count - 1); | 44 fFreeSets.removeShuffle(count - 1); |
29 } else { | 45 } else { |
(...skipping 22 matching lines...) Expand all Loading... | |
52 | 68 |
53 void GrVkDescriptorSetManager::abandon() { | 69 void GrVkDescriptorSetManager::abandon() { |
54 fPoolManager.abandonGPUResources(); | 70 fPoolManager.abandonGPUResources(); |
55 | 71 |
56 for (int i = 0; i < fFreeSets.count(); ++i) { | 72 for (int i = 0; i < fFreeSets.count(); ++i) { |
57 fFreeSets[i]->unrefAndAbandon(); | 73 fFreeSets[i]->unrefAndAbandon(); |
58 } | 74 } |
59 fFreeSets.reset(); | 75 fFreeSets.reset(); |
60 } | 76 } |
61 | 77 |
78 VkDescriptorSetLayout GrVkDescriptorSetManager::layout() const { return fPoolMan ager.fDescLayout; } | |
jvanverth1
2016/07/25 19:12:56
Put in .h file?
egdaniel
2016/07/26 13:33:19
Done.
| |
79 | |
80 bool GrVkDescriptorSetManager::isCompatible(VkDescriptorType type, | |
81 const GrVkUniformHandler* uniHandler ) const { | |
82 SkASSERT(uniHandler); | |
83 if (type != fPoolManager.fDescType) { | |
84 return false; | |
85 } | |
86 | |
87 if (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) { | |
88 if (fBindingVisibilities.count() != uniHandler->numSamplers()) { | |
89 return false; | |
90 } | |
91 for (int i = 0; i < uniHandler->numSamplers(); ++i) { | |
92 if (uniHandler->getSampler(i).visibility() != fBindingVisibilities[i ]) { | |
93 return false; | |
94 } | |
95 } | |
96 } | |
97 return true; | |
98 } | |
99 | |
62 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
63 | 101 |
64 void GrVkDescriptorSetManager::DescriptorPoolManager::getNewPool(GrVkGpu* gpu) { | 102 void GrVkDescriptorSetManager::DescriptorPoolManager::getNewPool(GrVkGpu* gpu) { |
65 if (fPool) { | 103 if (fPool) { |
66 fPool->unref(gpu); | 104 fPool->unref(gpu); |
67 uint32_t newPoolSize = fMaxDescriptors + ((fMaxDescriptors + 1) >> 1); | 105 uint32_t newPoolSize = fMaxDescriptors + ((fMaxDescriptors + 1) >> 1); |
68 if (newPoolSize < kMaxDescriptors) { | 106 if (newPoolSize < kMaxDescriptors) { |
69 fMaxDescriptors = newPoolSize; | 107 fMaxDescriptors = newPoolSize; |
70 } else { | 108 } else { |
71 fMaxDescriptors = kMaxDescriptors; | 109 fMaxDescriptors = kMaxDescriptors; |
(...skipping 22 matching lines...) Expand all Loading... | |
94 dsAllocateInfo.pNext = nullptr; | 132 dsAllocateInfo.pNext = nullptr; |
95 dsAllocateInfo.descriptorPool = fPool->descPool(); | 133 dsAllocateInfo.descriptorPool = fPool->descPool(); |
96 dsAllocateInfo.descriptorSetCount = 1; | 134 dsAllocateInfo.descriptorSetCount = 1; |
97 dsAllocateInfo.pSetLayouts = &fDescLayout; | 135 dsAllocateInfo.pSetLayouts = &fDescLayout; |
98 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), AllocateDescriptorSets(gpu->device() , | 136 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), AllocateDescriptorSets(gpu->device() , |
99 &dsAllocateIn fo, | 137 &dsAllocateIn fo, |
100 ds)); | 138 ds)); |
101 } | 139 } |
102 | 140 |
103 void GrVkDescriptorSetManager::DescriptorPoolManager::freeGPUResources(const GrV kGpu* gpu) { | 141 void GrVkDescriptorSetManager::DescriptorPoolManager::freeGPUResources(const GrV kGpu* gpu) { |
104 // The layout should be owned by the class which owns the DescriptorSetManag er so it will | 142 if (fDescLayout) { |
105 // take care of destroying it. | 143 GR_VK_CALL(gpu->vkInterface(), DestroyDescriptorSetLayout(gpu->device(), fDescLayout, |
jvanverth1
2016/07/25 19:12:56
Is there any way to create this in the DescriptorP
egdaniel
2016/07/26 13:33:19
Done.
| |
106 fDescLayout = VK_NULL_HANDLE; | 144 nullptr)); |
145 fDescLayout = VK_NULL_HANDLE; | |
146 } | |
107 | 147 |
108 if (fPool) { | 148 if (fPool) { |
109 fPool->unref(gpu); | 149 fPool->unref(gpu); |
110 fPool = nullptr; | 150 fPool = nullptr; |
111 } | 151 } |
112 } | 152 } |
113 | 153 |
114 void GrVkDescriptorSetManager::DescriptorPoolManager::abandonGPUResources() { | 154 void GrVkDescriptorSetManager::DescriptorPoolManager::abandonGPUResources() { |
115 fDescLayout = VK_NULL_HANDLE; | 155 fDescLayout = VK_NULL_HANDLE; |
116 if (fPool) { | 156 if (fPool) { |
117 fPool->unrefAndAbandon(); | 157 fPool->unrefAndAbandon(); |
118 fPool = nullptr; | 158 fPool = nullptr; |
119 } | 159 } |
120 } | 160 } |
OLD | NEW |