Chromium Code Reviews| 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 "GrVkPipeline.h" | 12 #include "GrVkPipeline.h" |
| 13 #include "GrVkRenderTarget.h" | 13 #include "GrVkRenderTarget.h" |
| 14 #include "GrVkSampler.h" | 14 #include "GrVkSampler.h" |
| 15 #include "GrVkUniformBuffer.h" | |
| 15 #include "GrVkUtil.h" | 16 #include "GrVkUtil.h" |
| 16 | 17 |
| 17 #ifdef SK_TRACE_VK_RESOURCES | 18 #ifdef SK_TRACE_VK_RESOURCES |
| 18 GrVkResource::Trace GrVkResource::fTrace; | 19 GrVkResource::Trace GrVkResource::fTrace; |
| 19 uint32_t GrVkResource::fKeyCounter = 0; | 20 uint32_t GrVkResource::fKeyCounter = 0; |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) | 23 GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) |
| 23 : fGpu(gpu) | 24 : fGpu(gpu) |
| 24 , fPipelineCache(VK_NULL_HANDLE) | 25 , fPipelineCache(VK_NULL_HANDLE) |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 cmdBuffer = GrVkSecondaryCommandBuffer::Create(fGpu, fGpu->cmdPool()); | 259 cmdBuffer = GrVkSecondaryCommandBuffer::Create(fGpu, fGpu->cmdPool()); |
| 259 } | 260 } |
| 260 return cmdBuffer; | 261 return cmdBuffer; |
| 261 } | 262 } |
| 262 | 263 |
| 263 void GrVkResourceProvider::recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuf fer* cb) { | 264 void GrVkResourceProvider::recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuf fer* cb) { |
| 264 cb->reset(fGpu); | 265 cb->reset(fGpu); |
| 265 fAvailableSecondaryCommandBuffers.push_back(cb); | 266 fAvailableSecondaryCommandBuffers.push_back(cb); |
| 266 } | 267 } |
| 267 | 268 |
| 269 const GrVkResource* GrVkResourceProvider::findOrCreateStandardUniformBufferResou rce() { | |
| 270 const GrVkResource* resource = nullptr; | |
| 271 int count = fAvailableUniformBufferResources.count(); | |
| 272 if (count > 0) { | |
| 273 resource = fAvailableUniformBufferResources[count - 1]; | |
| 274 fAvailableUniformBufferResources.removeShuffle(count - 1); | |
| 275 } else { | |
| 276 resource = GrVkUniformBuffer::CreateResource(fGpu, GrVkUniformBuffer::kS tandardSize); | |
| 277 } | |
| 278 return resource; | |
| 279 } | |
| 280 | |
| 281 void GrVkResourceProvider::recycleStandardUniformBufferResource(const GrVkResour ce* resource) { | |
| 282 resource->ref(); | |
| 283 fAvailableUniformBufferResources.push_back(resource); | |
| 284 } | |
| 285 | |
| 268 void GrVkResourceProvider::destroyResources() { | 286 void GrVkResourceProvider::destroyResources() { |
| 269 // release our active command buffers | 287 // release our active command buffers |
| 270 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { | 288 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { |
| 271 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); | 289 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); |
| 272 SkASSERT(fActiveCommandBuffers[i]->unique()); | 290 SkASSERT(fActiveCommandBuffers[i]->unique()); |
| 273 fActiveCommandBuffers[i]->reset(fGpu); | 291 fActiveCommandBuffers[i]->reset(fGpu); |
| 274 fActiveCommandBuffers[i]->unref(fGpu); | 292 fActiveCommandBuffers[i]->unref(fGpu); |
| 275 } | 293 } |
| 276 fActiveCommandBuffers.reset(); | 294 fActiveCommandBuffers.reset(); |
| 277 // release our available command buffers | 295 // release our available command buffers |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 307 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipeli neCache, nullptr)); | 325 GR_VK_CALL(fGpu->vkInterface(), DestroyPipelineCache(fGpu->device(), fPipeli neCache, nullptr)); |
| 308 fPipelineCache = VK_NULL_HANDLE; | 326 fPipelineCache = VK_NULL_HANDLE; |
| 309 | 327 |
| 310 if (fUniformDescLayout) { | 328 if (fUniformDescLayout) { |
| 311 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ), | 329 GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device( ), |
| 312 fUniformDescL ayout, | 330 fUniformDescL ayout, |
| 313 nullptr)); | 331 nullptr)); |
| 314 fUniformDescLayout = VK_NULL_HANDLE; | 332 fUniformDescLayout = VK_NULL_HANDLE; |
| 315 } | 333 } |
| 316 fUniformDescPool->unref(fGpu); | 334 fUniformDescPool->unref(fGpu); |
| 335 | |
| 336 // release our uniform buffers | |
|
egdaniel
2016/07/19 20:48:37
do you need an abandon form of this?
| |
| 337 for (int i = 0; i < fAvailableUniformBufferResources.count(); ++i) { | |
| 338 SkASSERT(fAvailableUniformBufferResources[i]->unique()); | |
| 339 fAvailableUniformBufferResources[i]->unref(fGpu); | |
| 340 } | |
| 341 fAvailableUniformBufferResources.reset(); | |
| 317 } | 342 } |
| 318 | 343 |
| 319 void GrVkResourceProvider::abandonResources() { | 344 void GrVkResourceProvider::abandonResources() { |
| 320 // release our active command buffers | 345 // release our active command buffers |
| 321 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { | 346 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { |
| 322 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); | 347 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); |
| 323 SkASSERT(fActiveCommandBuffers[i]->unique()); | 348 SkASSERT(fActiveCommandBuffers[i]->unique()); |
| 324 fActiveCommandBuffers[i]->unrefAndAbandon(); | 349 fActiveCommandBuffers[i]->unrefAndAbandon(); |
| 325 } | 350 } |
| 326 fActiveCommandBuffers.reset(); | 351 fActiveCommandBuffers.reset(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 } | 431 } |
| 407 | 432 |
| 408 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { | 433 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { |
| 409 for (int i = 0; i < fRenderPasses.count(); ++i) { | 434 for (int i = 0; i < fRenderPasses.count(); ++i) { |
| 410 if (fRenderPasses[i]) { | 435 if (fRenderPasses[i]) { |
| 411 fRenderPasses[i]->unrefAndAbandon(); | 436 fRenderPasses[i]->unrefAndAbandon(); |
| 412 fRenderPasses[i] = nullptr; | 437 fRenderPasses[i] = nullptr; |
| 413 } | 438 } |
| 414 } | 439 } |
| 415 } | 440 } |
| OLD | NEW |