Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/gpu/vk/GrVkResourceProvider.cpp

Issue 1927943002: Unify DescriptorPools for vulkan uniform descriptor sets (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use enum Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkResourceProvider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrVkResourceProvider.h" 8 #include "GrVkResourceProvider.h"
9 9
10 #include "GrTextureParams.h" 10 #include "GrTextureParams.h"
11 #include "GrVkCommandBuffer.h" 11 #include "GrVkCommandBuffer.h"
12 #include "GrVkPipeline.h" 12 #include "GrVkPipeline.h"
13 #include "GrVkRenderPass.h" 13 #include "GrVkRenderPass.h"
14 #include "GrVkSampler.h" 14 #include "GrVkSampler.h"
15 #include "GrVkUtil.h" 15 #include "GrVkUtil.h"
16 16
17 #ifdef SK_TRACE_VK_RESOURCES 17 #ifdef SK_TRACE_VK_RESOURCES
18 SkTDynamicHash<GrVkResource, uint32_t> GrVkResource::fTrace; 18 SkTDynamicHash<GrVkResource, uint32_t> GrVkResource::fTrace;
19 SkRandom GrVkResource::fRandom; 19 SkRandom GrVkResource::fRandom;
20 #endif 20 #endif
21 21
22 GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) : fGpu(gpu) 22 GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu)
23 , fPipelineCache(VK_NUL L_HANDLE) { 23 : fGpu(gpu)
24 , fPipelineCache(VK_NULL_HANDLE)
25 , fUniformDescPool(nullptr)
26 , fCurrentUniformDescCount(0) {
24 fPipelineStateCache = new PipelineStateCache(gpu); 27 fPipelineStateCache = new PipelineStateCache(gpu);
25 } 28 }
26 29
27 GrVkResourceProvider::~GrVkResourceProvider() { 30 GrVkResourceProvider::~GrVkResourceProvider() {
28 SkASSERT(0 == fSimpleRenderPasses.count()); 31 SkASSERT(0 == fSimpleRenderPasses.count());
29 SkASSERT(VK_NULL_HANDLE == fPipelineCache); 32 SkASSERT(VK_NULL_HANDLE == fPipelineCache);
30 delete fPipelineStateCache; 33 delete fPipelineStateCache;
31 } 34 }
32 35
36 void GrVkResourceProvider::initUniformDescObjects() {
37 // Create Uniform Buffer Descriptor
38 // The vertex uniform buffer will have binding 0 and the fragment binding 1.
39 VkDescriptorSetLayoutBinding dsUniBindings[2];
40 memset(&dsUniBindings, 0, 2 * sizeof(VkDescriptorSetLayoutBinding));
41 dsUniBindings[0].binding = GrVkUniformHandler::kVertexBinding;
42 dsUniBindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
43 dsUniBindings[0].descriptorCount = 1;
44 dsUniBindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
45 dsUniBindings[0].pImmutableSamplers = nullptr;
46 dsUniBindings[1].binding = GrVkUniformHandler::kFragBinding;
47 dsUniBindings[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
48 dsUniBindings[1].descriptorCount = 1;
49 dsUniBindings[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
50 dsUniBindings[1].pImmutableSamplers = nullptr;
51
52 VkDescriptorSetLayoutCreateInfo dsUniformLayoutCreateInfo;
53 memset(&dsUniformLayoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo ));
54 dsUniformLayoutCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CR EATE_INFO;
55 dsUniformLayoutCreateInfo.pNext = nullptr;
56 dsUniformLayoutCreateInfo.flags = 0;
57 dsUniformLayoutCreateInfo.bindingCount = 2;
58 dsUniformLayoutCreateInfo.pBindings = dsUniBindings;
59
60 GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), CreateDescriptorSetLayout(fGpu->dev ice(),
61 &dsUnifor mLayoutCreateInfo,
62 nullptr,
63 &fUniform DescLayout));
64 fCurrMaxUniDescriptors = kStartNumUniformDescriptors;
65 fUniformDescPool = this->findOrCreateCompatibleDescriptorPool(VK_DESCRIPTOR_ TYPE_UNIFORM_BUFFER,
66 fCurrMaxUniDes criptors);
67 }
68
33 void GrVkResourceProvider::init() { 69 void GrVkResourceProvider::init() {
34 VkPipelineCacheCreateInfo createInfo; 70 VkPipelineCacheCreateInfo createInfo;
35 memset(&createInfo, 0, sizeof(VkPipelineCacheCreateInfo)); 71 memset(&createInfo, 0, sizeof(VkPipelineCacheCreateInfo));
36 createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; 72 createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
37 createInfo.pNext = nullptr; 73 createInfo.pNext = nullptr;
38 createInfo.flags = 0; 74 createInfo.flags = 0;
39 createInfo.initialDataSize = 0; 75 createInfo.initialDataSize = 0;
40 createInfo.pInitialData = nullptr; 76 createInfo.pInitialData = nullptr;
41 VkResult result = GR_VK_CALL(fGpu->vkInterface(), 77 VkResult result = GR_VK_CALL(fGpu->vkInterface(),
42 CreatePipelineCache(fGpu->device(), &createInfo , nullptr, 78 CreatePipelineCache(fGpu->device(), &createInfo , nullptr,
43 &fPipelineCache)); 79 &fPipelineCache));
44 SkASSERT(VK_SUCCESS == result); 80 SkASSERT(VK_SUCCESS == result);
45 if (VK_SUCCESS != result) { 81 if (VK_SUCCESS != result) {
46 fPipelineCache = VK_NULL_HANDLE; 82 fPipelineCache = VK_NULL_HANDLE;
47 } 83 }
84
85 this->initUniformDescObjects();
48 } 86 }
49 87
50 GrVkPipeline* GrVkResourceProvider::createPipeline(const GrPipeline& pipeline, 88 GrVkPipeline* GrVkResourceProvider::createPipeline(const GrPipeline& pipeline,
51 const GrPrimitiveProcessor& p rimProc, 89 const GrPrimitiveProcessor& p rimProc,
52 VkPipelineShaderStageCreateIn fo* shaderStageInfo, 90 VkPipelineShaderStageCreateIn fo* shaderStageInfo,
53 int shaderStageCount, 91 int shaderStageCount,
54 GrPrimitiveType primitiveType , 92 GrPrimitiveType primitiveType ,
55 const GrVkRenderPass& renderP ass, 93 const GrVkRenderPass& renderP ass,
56 VkPipelineLayout layout) { 94 VkPipelineLayout layout) {
57 95
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 136 }
99 137
100 sk_sp<GrVkPipelineState> GrVkResourceProvider::findOrCreateCompatiblePipelineSta te( 138 sk_sp<GrVkPipelineState> GrVkResourceProvider::findOrCreateCompatiblePipelineSta te(
101 const GrPipelin e& pipeline, 139 const GrPipelin e& pipeline,
102 const GrPrimiti veProcessor& proc, 140 const GrPrimiti veProcessor& proc,
103 GrPrimitiveType primitiveType, 141 GrPrimitiveType primitiveType,
104 const GrVkRende rPass& renderPass) { 142 const GrVkRende rPass& renderPass) {
105 return fPipelineStateCache->refPipelineState(pipeline, proc, primitiveType, renderPass); 143 return fPipelineStateCache->refPipelineState(pipeline, proc, primitiveType, renderPass);
106 } 144 }
107 145
146 void GrVkResourceProvider::getUniformDescriptorSet(VkDescriptorSet* ds,
147 const GrVkDescriptorPool** ou tPool) {
148 fCurrentUniformDescCount += kNumUniformDescPerSet;
149 if (fCurrentUniformDescCount > fCurrMaxUniDescriptors) {
150 fUniformDescPool->unref(fGpu);
151 if (fCurrMaxUniDescriptors < kMaxUniformDescriptors >> 1) {
152 fCurrMaxUniDescriptors = fCurrMaxUniDescriptors << 1;
153 } else {
154 fCurrMaxUniDescriptors = kMaxUniformDescriptors;
155 }
156 fUniformDescPool =
157 this->findOrCreateCompatibleDescriptorPool(VK_DESCRIPTOR_TYPE_UNIFOR M_BUFFER,
158 fCurrMaxUniDescriptors);
159 fCurrentUniformDescCount = kNumUniformDescPerSet;
160 }
161 SkASSERT(fUniformDescPool);
162
163 VkDescriptorSetAllocateInfo dsAllocateInfo;
164 memset(&dsAllocateInfo, 0, sizeof(VkDescriptorSetAllocateInfo));
165 dsAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
166 dsAllocateInfo.pNext = nullptr;
167 dsAllocateInfo.descriptorPool = fUniformDescPool->descPool();
168 dsAllocateInfo.descriptorSetCount = 1;
169 dsAllocateInfo.pSetLayouts = &fUniformDescLayout;
170 GR_VK_CALL_ERRCHECK(fGpu->vkInterface(), AllocateDescriptorSets(fGpu->device (),
171 &dsAllocateI nfo,
172 ds));
173 *outPool = fUniformDescPool;
174 }
175
108 GrVkCommandBuffer* GrVkResourceProvider::createCommandBuffer() { 176 GrVkCommandBuffer* GrVkResourceProvider::createCommandBuffer() {
109 GrVkCommandBuffer* cmdBuffer = GrVkCommandBuffer::Create(fGpu, fGpu->cmdPool ()); 177 GrVkCommandBuffer* cmdBuffer = GrVkCommandBuffer::Create(fGpu, fGpu->cmdPool ());
110 fActiveCommandBuffers.push_back(cmdBuffer); 178 fActiveCommandBuffers.push_back(cmdBuffer);
111 cmdBuffer->ref(); 179 cmdBuffer->ref();
112 return cmdBuffer; 180 return cmdBuffer;
113 } 181 }
114 182
115 void GrVkResourceProvider::checkCommandBuffers() { 183 void GrVkResourceProvider::checkCommandBuffers() {
116 for (int i = fActiveCommandBuffers.count()-1; i >= 0; --i) { 184 for (int i = fActiveCommandBuffers.count()-1; i >= 0; --i) {
117 if (fActiveCommandBuffers[i]->finished(fGpu)) { 185 if (fActiveCommandBuffers[i]->finished(fGpu)) {
(...skipping 26 matching lines...) Expand all
144 fSamplers.reset(); 212 fSamplers.reset();
145 213
146 fPipelineStateCache->release(); 214 fPipelineStateCache->release();
147 215
148 #ifdef SK_TRACE_VK_RESOURCES 216 #ifdef SK_TRACE_VK_RESOURCES
149 SkASSERT(0 == GrVkResource::fTrace.count()); 217 SkASSERT(0 == GrVkResource::fTrace.count());
150 #endif 218 #endif
151 219
152 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipeli neCache, nullptr)); 220 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipeli neCache, nullptr));
153 fPipelineCache = VK_NULL_HANDLE; 221 fPipelineCache = VK_NULL_HANDLE;
222
223 if (fUniformDescLayout) {
224 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ),
225 fUniformDescL ayout,
226 nullptr));
227 fUniformDescLayout = VK_NULL_HANDLE;
228 }
229 fUniformDescPool->unref(fGpu);
154 } 230 }
155 231
156 void GrVkResourceProvider::abandonResources() { 232 void GrVkResourceProvider::abandonResources() {
157 // release our current command buffers 233 // release our current command buffers
158 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { 234 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) {
159 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); 235 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu));
160 fActiveCommandBuffers[i]->unrefAndAbandon(); 236 fActiveCommandBuffers[i]->unrefAndAbandon();
161 } 237 }
162 fActiveCommandBuffers.reset(); 238 fActiveCommandBuffers.reset();
163 239
164 for (int i = 0; i < fSimpleRenderPasses.count(); ++i) { 240 for (int i = 0; i < fSimpleRenderPasses.count(); ++i) {
165 fSimpleRenderPasses[i]->unrefAndAbandon(); 241 fSimpleRenderPasses[i]->unrefAndAbandon();
166 } 242 }
167 fSimpleRenderPasses.reset(); 243 fSimpleRenderPasses.reset();
168 244
169 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re setting the hash. 245 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re setting the hash.
170 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); 246 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers);
171 for (; !iter.done(); ++iter) { 247 for (; !iter.done(); ++iter) {
172 (*iter).unrefAndAbandon(); 248 (*iter).unrefAndAbandon();
173 } 249 }
174 fSamplers.reset(); 250 fSamplers.reset();
175 251
176 fPipelineStateCache->abandon(); 252 fPipelineStateCache->abandon();
177 253
178 #ifdef SK_TRACE_VK_RESOURCES 254 #ifdef SK_TRACE_VK_RESOURCES
179 SkASSERT(0 == GrVkResource::fTrace.count()); 255 SkASSERT(0 == GrVkResource::fTrace.count());
180 #endif 256 #endif
181 fPipelineCache = VK_NULL_HANDLE; 257 fPipelineCache = VK_NULL_HANDLE;
258
259 fUniformDescLayout = VK_NULL_HANDLE;
260 fUniformDescPool->unrefAndAbandon();
182 } 261 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkResourceProvider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698