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 "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 "GrVkCopyPipeline.h" |
12 #include "GrVkGLSLSampler.h" | 13 #include "GrVkGLSLSampler.h" |
13 #include "GrVkPipeline.h" | 14 #include "GrVkPipeline.h" |
14 #include "GrVkRenderTarget.h" | 15 #include "GrVkRenderTarget.h" |
15 #include "GrVkSampler.h" | 16 #include "GrVkSampler.h" |
16 #include "GrVkUniformBuffer.h" | 17 #include "GrVkUniformBuffer.h" |
17 #include "GrVkUtil.h" | 18 #include "GrVkUtil.h" |
18 | 19 |
19 #ifdef SK_TRACE_VK_RESOURCES | 20 #ifdef SK_TRACE_VK_RESOURCES |
20 GrVkResource::Trace GrVkResource::fTrace; | 21 GrVkResource::Trace GrVkResource::fTrace; |
21 uint32_t GrVkResource::fKeyCounter = 0; | 22 uint32_t GrVkResource::fKeyCounter = 0; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 VkPipelineShaderStageCreateIn
fo* shaderStageInfo, | 61 VkPipelineShaderStageCreateIn
fo* shaderStageInfo, |
61 int shaderStageCount, | 62 int shaderStageCount, |
62 GrPrimitiveType primitiveType
, | 63 GrPrimitiveType primitiveType
, |
63 const GrVkRenderPass& renderP
ass, | 64 const GrVkRenderPass& renderP
ass, |
64 VkPipelineLayout layout) { | 65 VkPipelineLayout layout) { |
65 | 66 |
66 return GrVkPipeline::Create(fGpu, pipeline, primProc, shaderStageInfo, shade
rStageCount, | 67 return GrVkPipeline::Create(fGpu, pipeline, primProc, shaderStageInfo, shade
rStageCount, |
67 primitiveType, renderPass, layout, fPipelineCach
e); | 68 primitiveType, renderPass, layout, fPipelineCach
e); |
68 } | 69 } |
69 | 70 |
| 71 GrVkCopyPipeline* GrVkResourceProvider::findOrCreateCopyPipeline( |
| 72 const GrVkRenderTarget* dst, |
| 73 VkPipelineShaderStageCreateInfo* shaderStageInfo, |
| 74 VkPipelineLayout pipelineLayout) { |
| 75 // Find or Create a compatible pipeline |
| 76 GrVkCopyPipeline* pipeline = nullptr; |
| 77 for (int i = 0; i < fCopyPipelines.count() && !pipeline; ++i) { |
| 78 if (fCopyPipelines[i]->isCompatible(*dst->simpleRenderPass())) { |
| 79 pipeline = fCopyPipelines[i]; |
| 80 } |
| 81 } |
| 82 if (!pipeline) { |
| 83 pipeline = GrVkCopyPipeline::Create(fGpu, shaderStageInfo, |
| 84 pipelineLayout, |
| 85 dst->numColorSamples(), |
| 86 *dst->simpleRenderPass(), |
| 87 fPipelineCache); |
| 88 fCopyPipelines.push_back(pipeline); |
| 89 } |
| 90 SkASSERT(pipeline); |
| 91 pipeline->ref(); |
| 92 return pipeline; |
| 93 } |
70 | 94 |
71 // To create framebuffers, we first need to create a simple RenderPass that is | 95 // To create framebuffers, we first need to create a simple RenderPass that is |
72 // only used for framebuffer creation. When we actually render we will create | 96 // only used for framebuffer creation. When we actually render we will create |
73 // RenderPasses as needed that are compatible with the framebuffer. | 97 // RenderPasses as needed that are compatible with the framebuffer. |
74 const GrVkRenderPass* | 98 const GrVkRenderPass* |
75 GrVkResourceProvider::findCompatibleRenderPass(const GrVkRenderTarget& target, | 99 GrVkResourceProvider::findCompatibleRenderPass(const GrVkRenderTarget& target, |
76 CompatibleRPHandle* compatibleHan
dle) { | 100 CompatibleRPHandle* compatibleHan
dle) { |
77 for (int i = 0; i < fRenderPassArray.count(); ++i) { | 101 for (int i = 0; i < fRenderPassArray.count(); ++i) { |
78 if (fRenderPassArray[i].isCompatible(target)) { | 102 if (fRenderPassArray[i].isCompatible(target)) { |
79 const GrVkRenderPass* renderPass = fRenderPassArray[i].getCompatible
RenderPass(); | 103 const GrVkRenderPass* renderPass = fRenderPassArray[i].getCompatible
RenderPass(); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 324 } |
301 fAvailableCommandBuffers.reset(); | 325 fAvailableCommandBuffers.reset(); |
302 | 326 |
303 // release our available secondary command buffers | 327 // release our available secondary command buffers |
304 for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) { | 328 for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) { |
305 SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique()); | 329 SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique()); |
306 fAvailableSecondaryCommandBuffers[i]->unref(fGpu); | 330 fAvailableSecondaryCommandBuffers[i]->unref(fGpu); |
307 } | 331 } |
308 fAvailableSecondaryCommandBuffers.reset(); | 332 fAvailableSecondaryCommandBuffers.reset(); |
309 | 333 |
| 334 // Release all copy pipelines |
| 335 for (int i = 0; i < fCopyPipelines.count(); ++i) { |
| 336 fCopyPipelines[i]->unref(fGpu); |
| 337 } |
| 338 |
310 // loop over all render pass sets to make sure we destroy all the internal V
kRenderPasses | 339 // loop over all render pass sets to make sure we destroy all the internal V
kRenderPasses |
311 for (int i = 0; i < fRenderPassArray.count(); ++i) { | 340 for (int i = 0; i < fRenderPassArray.count(); ++i) { |
312 fRenderPassArray[i].releaseResources(fGpu); | 341 fRenderPassArray[i].releaseResources(fGpu); |
313 } | 342 } |
314 fRenderPassArray.reset(); | 343 fRenderPassArray.reset(); |
315 | 344 |
316 // Iterate through all store GrVkSamplers and unref them before resetting th
e hash. | 345 // Iterate through all store GrVkSamplers and unref them before resetting th
e hash. |
317 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); | 346 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); |
318 for (; !iter.done(); ++iter) { | 347 for (; !iter.done(); ++iter) { |
319 (*iter).unref(fGpu); | 348 (*iter).unref(fGpu); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 385 } |
357 fAvailableCommandBuffers.reset(); | 386 fAvailableCommandBuffers.reset(); |
358 | 387 |
359 // release our available secondary command buffers | 388 // release our available secondary command buffers |
360 for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) { | 389 for (int i = 0; i < fAvailableSecondaryCommandBuffers.count(); ++i) { |
361 SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique()); | 390 SkASSERT(fAvailableSecondaryCommandBuffers[i]->unique()); |
362 fAvailableSecondaryCommandBuffers[i]->unrefAndAbandon(); | 391 fAvailableSecondaryCommandBuffers[i]->unrefAndAbandon(); |
363 } | 392 } |
364 fAvailableSecondaryCommandBuffers.reset(); | 393 fAvailableSecondaryCommandBuffers.reset(); |
365 | 394 |
| 395 // Abandon all copy pipelines |
| 396 for (int i = 0; i < fCopyPipelines.count(); ++i) { |
| 397 fCopyPipelines[i]->unrefAndAbandon(); |
| 398 } |
| 399 |
366 // loop over all render pass sets to make sure we destroy all the internal V
kRenderPasses | 400 // loop over all render pass sets to make sure we destroy all the internal V
kRenderPasses |
367 for (int i = 0; i < fRenderPassArray.count(); ++i) { | 401 for (int i = 0; i < fRenderPassArray.count(); ++i) { |
368 fRenderPassArray[i].abandonResources(); | 402 fRenderPassArray[i].abandonResources(); |
369 } | 403 } |
370 fRenderPassArray.reset(); | 404 fRenderPassArray.reset(); |
371 | 405 |
372 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re
setting the hash. | 406 // Iterate through all store GrVkSamplers and unrefAndAbandon them before re
setting the hash. |
373 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); | 407 SkTDynamicHash<GrVkSampler, uint16_t>::Iter iter(&fSamplers); |
374 for (; !iter.done(); ++iter) { | 408 for (; !iter.done(); ++iter) { |
375 (*iter).unrefAndAbandon(); | 409 (*iter).unrefAndAbandon(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 } | 474 } |
441 | 475 |
442 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { | 476 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { |
443 for (int i = 0; i < fRenderPasses.count(); ++i) { | 477 for (int i = 0; i < fRenderPasses.count(); ++i) { |
444 if (fRenderPasses[i]) { | 478 if (fRenderPasses[i]) { |
445 fRenderPasses[i]->unrefAndAbandon(); | 479 fRenderPasses[i]->unrefAndAbandon(); |
446 fRenderPasses[i] = nullptr; | 480 fRenderPasses[i] = nullptr; |
447 } | 481 } |
448 } | 482 } |
449 } | 483 } |
OLD | NEW |