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 "GrVkPipelineState.h" | 8 #include "GrVkPipelineState.h" |
9 | 9 |
10 #include "GrPipeline.h" | 10 #include "GrPipeline.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "GrVkUniformBuffer.h" | 21 #include "GrVkUniformBuffer.h" |
22 #include "glsl/GrGLSLFragmentProcessor.h" | 22 #include "glsl/GrGLSLFragmentProcessor.h" |
23 #include "glsl/GrGLSLGeometryProcessor.h" | 23 #include "glsl/GrGLSLGeometryProcessor.h" |
24 #include "glsl/GrGLSLXferProcessor.h" | 24 #include "glsl/GrGLSLXferProcessor.h" |
25 #include "SkMipmap.h" | 25 #include "SkMipmap.h" |
26 | 26 |
27 GrVkPipelineState::GrVkPipelineState(GrVkGpu* gpu, | 27 GrVkPipelineState::GrVkPipelineState(GrVkGpu* gpu, |
28 const GrVkPipelineState::Desc& desc, | 28 const GrVkPipelineState::Desc& desc, |
29 GrVkPipeline* pipeline, | 29 GrVkPipeline* pipeline, |
30 VkPipelineLayout layout, | 30 VkPipelineLayout layout, |
31 VkDescriptorSetLayout dsLayout[2], | 31 VkDescriptorSetLayout dsSamplerLayout, |
32 const BuiltinUniformHandles& builtinUniform
Handles, | 32 const BuiltinUniformHandles& builtinUniform
Handles, |
33 const UniformInfoArray& uniforms, | 33 const UniformInfoArray& uniforms, |
34 uint32_t vertexUniformSize, | 34 uint32_t vertexUniformSize, |
35 uint32_t fragmentUniformSize, | 35 uint32_t fragmentUniformSize, |
36 uint32_t numSamplers, | 36 uint32_t numSamplers, |
37 GrGLSLPrimitiveProcessor* geometryProcessor
, | 37 GrGLSLPrimitiveProcessor* geometryProcessor
, |
38 GrGLSLXferProcessor* xferProcessor, | 38 GrGLSLXferProcessor* xferProcessor, |
39 const GrGLSLFragProcs& fragmentProcessors) | 39 const GrGLSLFragProcs& fragmentProcessors) |
40 : fPipeline(pipeline) | 40 : fPipeline(pipeline) |
41 , fPipelineLayout(layout) | 41 , fPipelineLayout(layout) |
42 , fStartDS(SK_MaxS32) | 42 , fStartDS(SK_MaxS32) |
43 , fDSCount(0) | 43 , fDSCount(0) |
44 , fBuiltinUniformHandles(builtinUniformHandles) | 44 , fBuiltinUniformHandles(builtinUniformHandles) |
45 , fGeometryProcessor(geometryProcessor) | 45 , fGeometryProcessor(geometryProcessor) |
46 , fXferProcessor(xferProcessor) | 46 , fXferProcessor(xferProcessor) |
47 , fFragmentProcessors(fragmentProcessors) | 47 , fFragmentProcessors(fragmentProcessors) |
48 , fDesc(desc) | 48 , fDesc(desc) |
49 , fDataManager(uniforms, vertexUniformSize, fragmentUniformSize) | 49 , fDataManager(uniforms, vertexUniformSize, fragmentUniformSize) |
50 , fSamplerPoolManager(dsLayout[GrVkUniformHandler::kSamplerDescSet], | 50 , fSamplerPoolManager(dsSamplerLayout, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAM
PLER, |
51 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, numSamplers
, gpu) | 51 numSamplers, gpu) |
52 , fUniformPoolManager(dsLayout[GrVkUniformHandler::kUniformBufferDescSet], | 52 , fCurrentUniformDescPool(nullptr) { |
53 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, | |
54 (vertexUniformSize || fragmentUniformSize) ? 2 : 0, gp
u) { | |
55 fSamplers.setReserve(numSamplers); | 53 fSamplers.setReserve(numSamplers); |
56 fTextureViews.setReserve(numSamplers); | 54 fTextureViews.setReserve(numSamplers); |
57 fTextures.setReserve(numSamplers); | 55 fTextures.setReserve(numSamplers); |
58 | 56 |
59 fDescriptorSets[0] = VK_NULL_HANDLE; | 57 fDescriptorSets[0] = VK_NULL_HANDLE; |
60 fDescriptorSets[1] = VK_NULL_HANDLE; | 58 fDescriptorSets[1] = VK_NULL_HANDLE; |
61 | 59 |
62 // Currently we are always binding a descriptor set for uniform buffers. | 60 // Currently we are always binding a descriptor set for uniform buffers. |
63 if (vertexUniformSize || fragmentUniformSize) { | 61 if (vertexUniformSize || fragmentUniformSize) { |
64 fDSCount++; | 62 fDSCount++; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 117 |
120 if (fVertexUniformBuffer) { | 118 if (fVertexUniformBuffer) { |
121 fVertexUniformBuffer->release(gpu); | 119 fVertexUniformBuffer->release(gpu); |
122 } | 120 } |
123 | 121 |
124 if (fFragmentUniformBuffer) { | 122 if (fFragmentUniformBuffer) { |
125 fFragmentUniformBuffer->release(gpu); | 123 fFragmentUniformBuffer->release(gpu); |
126 } | 124 } |
127 | 125 |
128 fSamplerPoolManager.freeGPUResources(gpu); | 126 fSamplerPoolManager.freeGPUResources(gpu); |
129 fUniformPoolManager.freeGPUResources(gpu); | 127 if (fCurrentUniformDescPool) { |
| 128 fCurrentUniformDescPool->unref(gpu); |
| 129 fCurrentUniformDescPool = nullptr; |
| 130 } |
130 | 131 |
131 this->freeTempResources(gpu); | 132 this->freeTempResources(gpu); |
132 } | 133 } |
133 | 134 |
134 void GrVkPipelineState::abandonGPUResources() { | 135 void GrVkPipelineState::abandonGPUResources() { |
135 fPipeline->unrefAndAbandon(); | 136 fPipeline->unrefAndAbandon(); |
136 fPipeline = nullptr; | 137 fPipeline = nullptr; |
137 | 138 |
138 fPipelineLayout = VK_NULL_HANDLE; | 139 fPipelineLayout = VK_NULL_HANDLE; |
139 | 140 |
140 fVertexUniformBuffer->abandon(); | 141 fVertexUniformBuffer->abandon(); |
141 fFragmentUniformBuffer->abandon(); | 142 fFragmentUniformBuffer->abandon(); |
142 | 143 |
143 for (int i = 0; i < fSamplers.count(); ++i) { | 144 for (int i = 0; i < fSamplers.count(); ++i) { |
144 fSamplers[i]->unrefAndAbandon(); | 145 fSamplers[i]->unrefAndAbandon(); |
145 } | 146 } |
146 fSamplers.rewind(); | 147 fSamplers.rewind(); |
147 | 148 |
148 for (int i = 0; i < fTextureViews.count(); ++i) { | 149 for (int i = 0; i < fTextureViews.count(); ++i) { |
149 fTextureViews[i]->unrefAndAbandon(); | 150 fTextureViews[i]->unrefAndAbandon(); |
150 } | 151 } |
151 fTextureViews.rewind(); | 152 fTextureViews.rewind(); |
152 | 153 |
153 for (int i = 0; i < fTextures.count(); ++i) { | 154 for (int i = 0; i < fTextures.count(); ++i) { |
154 fTextures[i]->unrefAndAbandon(); | 155 fTextures[i]->unrefAndAbandon(); |
155 } | 156 } |
156 fTextures.rewind(); | 157 fTextures.rewind(); |
157 | 158 |
158 fSamplerPoolManager.abandonGPUResources(); | 159 fSamplerPoolManager.abandonGPUResources(); |
159 fUniformPoolManager.abandonGPUResources(); | 160 if (fCurrentUniformDescPool) { |
| 161 fCurrentUniformDescPool->unrefAndAbandon(); |
| 162 fCurrentUniformDescPool = nullptr; |
| 163 } |
160 } | 164 } |
161 | 165 |
162 static void append_texture_bindings(const GrProcessor& processor, | 166 static void append_texture_bindings(const GrProcessor& processor, |
163 SkTArray<const GrTextureAccess*>* textureBin
dings) { | 167 SkTArray<const GrTextureAccess*>* textureBin
dings) { |
164 if (int numTextures = processor.numTextures()) { | 168 if (int numTextures = processor.numTextures()) { |
165 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu
res); | 169 const GrTextureAccess** bindings = textureBindings->push_back_n(numTextu
res); |
166 int i = 0; | 170 int i = 0; |
167 do { | 171 do { |
168 bindings[i] = &processor.textureAccess(i); | 172 bindings[i] = &processor.textureAccess(i); |
169 } while (++i < numTextures); | 173 } while (++i < numTextures); |
(...skipping 28 matching lines...) Expand all Loading... |
198 // Get new descriptor sets | 202 // Get new descriptor sets |
199 if (fNumSamplers) { | 203 if (fNumSamplers) { |
200 fSamplerPoolManager.getNewDescriptorSet(gpu, | 204 fSamplerPoolManager.getNewDescriptorSet(gpu, |
201 &fDescriptorSets[GrVkUniformHandler
::kSamplerDescSet]); | 205 &fDescriptorSets[GrVkUniformHandler
::kSamplerDescSet]); |
202 this->writeSamplers(gpu, textureBindings); | 206 this->writeSamplers(gpu, textureBindings); |
203 } | 207 } |
204 | 208 |
205 if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) { | 209 if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) { |
206 if (fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragme
ntUniformBuffer) || | 210 if (fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragme
ntUniformBuffer) || |
207 VK_NULL_HANDLE == fDescriptorSets[GrVkUniformHandler::kUniformBuffer
DescSet]) { | 211 VK_NULL_HANDLE == fDescriptorSets[GrVkUniformHandler::kUniformBuffer
DescSet]) { |
208 fUniformPoolManager.getNewDescriptorSet(gpu, | 212 const GrVkDescriptorPool* pool; |
209 &fDescriptorSets[GrVkUniformHandler::kUni
formBufferDescSet]); | 213 int uniformDSIdx = GrVkUniformHandler::kUniformBufferDescSet; |
| 214 gpu->resourceProvider().getUniformDescriptorSet(&fDescriptorSets[uni
formDSIdx], |
| 215 &pool); |
| 216 if (pool != fCurrentUniformDescPool) { |
| 217 if (fCurrentUniformDescPool) { |
| 218 fCurrentUniformDescPool->unref(gpu); |
| 219 } |
| 220 fCurrentUniformDescPool = pool; |
| 221 fCurrentUniformDescPool->ref(); |
| 222 } |
210 this->writeUniformBuffers(gpu); | 223 this->writeUniformBuffers(gpu); |
211 } | 224 } |
212 } | 225 } |
213 } | 226 } |
214 | 227 |
215 void GrVkPipelineState::writeUniformBuffers(const GrVkGpu* gpu) { | 228 void GrVkPipelineState::writeUniformBuffers(const GrVkGpu* gpu) { |
216 VkWriteDescriptorSet descriptorWrites[2]; | 229 VkWriteDescriptorSet descriptorWrites[2]; |
217 memset(descriptorWrites, 0, 2 * sizeof(VkWriteDescriptorSet)); | 230 memset(descriptorWrites, 0, 2 * sizeof(VkWriteDescriptorSet)); |
218 | 231 |
219 uint32_t firstUniformWrite = 0; | 232 uint32_t firstUniformWrite = 0; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 if (fDSCount) { | 382 if (fDSCount) { |
370 commandBuffer->bindDescriptorSets(gpu, this, fPipelineLayout, fStartDS,
fDSCount, | 383 commandBuffer->bindDescriptorSets(gpu, this, fPipelineLayout, fStartDS,
fDSCount, |
371 &fDescriptorSets[fStartDS], 0, nullptr
); | 384 &fDescriptorSets[fStartDS], 0, nullptr
); |
372 } | 385 } |
373 } | 386 } |
374 | 387 |
375 void GrVkPipelineState::addUniformResources(GrVkCommandBuffer& commandBuffer) { | 388 void GrVkPipelineState::addUniformResources(GrVkCommandBuffer& commandBuffer) { |
376 if (fSamplerPoolManager.fPool) { | 389 if (fSamplerPoolManager.fPool) { |
377 commandBuffer.addResource(fSamplerPoolManager.fPool); | 390 commandBuffer.addResource(fSamplerPoolManager.fPool); |
378 } | 391 } |
379 if (fUniformPoolManager.fPool) { | 392 if (fCurrentUniformDescPool) { |
380 commandBuffer.addResource(fUniformPoolManager.fPool); | 393 commandBuffer.addResource(fCurrentUniformDescPool); |
381 } | 394 } |
382 | 395 |
383 if (fVertexUniformBuffer.get()) { | 396 if (fVertexUniformBuffer.get()) { |
384 commandBuffer.addResource(fVertexUniformBuffer->resource()); | 397 commandBuffer.addResource(fVertexUniformBuffer->resource()); |
385 } | 398 } |
386 if (fFragmentUniformBuffer.get()) { | 399 if (fFragmentUniformBuffer.get()) { |
387 commandBuffer.addResource(fFragmentUniformBuffer->resource()); | 400 commandBuffer.addResource(fFragmentUniformBuffer->resource()); |
388 } | 401 } |
389 for (int i = 0; i < fSamplers.count(); ++i) { | 402 for (int i = 0; i < fSamplers.count(); ++i) { |
390 commandBuffer.addResource(fSamplers[i]); | 403 commandBuffer.addResource(fSamplers[i]); |
(...skipping 20 matching lines...) Expand all Loading... |
411 } | 424 } |
412 | 425 |
413 } | 426 } |
414 if (fMaxDescriptors) { | 427 if (fMaxDescriptors) { |
415 fPool = gpu->resourceProvider().findOrCreateCompatibleDescriptorPool(fDe
scType, | 428 fPool = gpu->resourceProvider().findOrCreateCompatibleDescriptorPool(fDe
scType, |
416 fMa
xDescriptors); | 429 fMa
xDescriptors); |
417 } | 430 } |
418 SkASSERT(fPool || !fMaxDescriptors); | 431 SkASSERT(fPool || !fMaxDescriptors); |
419 } | 432 } |
420 | 433 |
421 void GrVkPipelineState::DescriptorPoolManager::getNewDescriptorSet(GrVkGpu* gpu,
VkDescriptorSet* ds) { | 434 void GrVkPipelineState::DescriptorPoolManager::getNewDescriptorSet(GrVkGpu* gpu, |
| 435 VkDescriptorS
et* ds) { |
422 if (!fMaxDescriptors) { | 436 if (!fMaxDescriptors) { |
423 return; | 437 return; |
424 } | 438 } |
425 fCurrentDescriptorCount += fDescCountPerSet; | 439 fCurrentDescriptorCount += fDescCountPerSet; |
426 if (fCurrentDescriptorCount > fMaxDescriptors) { | 440 if (fCurrentDescriptorCount > fMaxDescriptors) { |
427 this->getNewPool(gpu); | 441 this->getNewPool(gpu); |
428 fCurrentDescriptorCount = fDescCountPerSet; | 442 fCurrentDescriptorCount = fDescCountPerSet; |
429 } | 443 } |
430 | 444 |
431 VkDescriptorSetAllocateInfo dsAllocateInfo; | 445 VkDescriptorSetAllocateInfo dsAllocateInfo; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 510 |
497 b.add32(get_blend_info_key(pipeline)); | 511 b.add32(get_blend_info_key(pipeline)); |
498 | 512 |
499 b.add32(primitiveType); | 513 b.add32(primitiveType); |
500 | 514 |
501 // Set key length | 515 // Set key length |
502 int keyLength = key->count(); | 516 int keyLength = key->count(); |
503 SkASSERT(0 == (keyLength % 4)); | 517 SkASSERT(0 == (keyLength % 4)); |
504 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength); | 518 *reinterpret_cast<uint32_t*>(key->begin()) = SkToU32(keyLength); |
505 } | 519 } |
OLD | NEW |