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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 cmdBuffer = GrVkSecondaryCommandBuffer::Create(fGpu, fGpu->cmdPool()); | 261 cmdBuffer = GrVkSecondaryCommandBuffer::Create(fGpu, fGpu->cmdPool()); |
261 } | 262 } |
262 return cmdBuffer; | 263 return cmdBuffer; |
263 } | 264 } |
264 | 265 |
265 void GrVkResourceProvider::recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuf
fer* cb) { | 266 void GrVkResourceProvider::recycleSecondaryCommandBuffer(GrVkSecondaryCommandBuf
fer* cb) { |
266 cb->reset(fGpu); | 267 cb->reset(fGpu); |
267 fAvailableSecondaryCommandBuffers.push_back(cb); | 268 fAvailableSecondaryCommandBuffers.push_back(cb); |
268 } | 269 } |
269 | 270 |
| 271 const GrVkResource* GrVkResourceProvider::findOrCreateStandardUniformBufferResou
rce() { |
| 272 const GrVkResource* resource = nullptr; |
| 273 int count = fAvailableUniformBufferResources.count(); |
| 274 if (count > 0) { |
| 275 resource = fAvailableUniformBufferResources[count - 1]; |
| 276 fAvailableUniformBufferResources.removeShuffle(count - 1); |
| 277 } else { |
| 278 resource = GrVkUniformBuffer::CreateResource(fGpu, GrVkUniformBuffer::kS
tandardSize); |
| 279 } |
| 280 return resource; |
| 281 } |
| 282 |
| 283 void GrVkResourceProvider::recycleStandardUniformBufferResource(const GrVkResour
ce* resource) { |
| 284 fAvailableUniformBufferResources.push_back(resource); |
| 285 } |
| 286 |
270 void GrVkResourceProvider::destroyResources() { | 287 void GrVkResourceProvider::destroyResources() { |
271 // release our active command buffers | 288 // release our active command buffers |
272 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { | 289 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { |
273 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); | 290 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); |
274 SkASSERT(fActiveCommandBuffers[i]->unique()); | 291 SkASSERT(fActiveCommandBuffers[i]->unique()); |
275 fActiveCommandBuffers[i]->reset(fGpu); | 292 fActiveCommandBuffers[i]->reset(fGpu); |
276 fActiveCommandBuffers[i]->unref(fGpu); | 293 fActiveCommandBuffers[i]->unref(fGpu); |
277 } | 294 } |
278 fActiveCommandBuffers.reset(); | 295 fActiveCommandBuffers.reset(); |
279 // release our available command buffers | 296 // release our available command buffers |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 nullptr)); | 332 nullptr)); |
316 fUniformDescLayout = VK_NULL_HANDLE; | 333 fUniformDescLayout = VK_NULL_HANDLE; |
317 } | 334 } |
318 | 335 |
319 // We must release/destroy all command buffers and pipeline states before re
leasing the | 336 // We must release/destroy all command buffers and pipeline states before re
leasing the |
320 // GrVkDescriptorSetManagers | 337 // GrVkDescriptorSetManagers |
321 for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { | 338 for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { |
322 fDescriptorSetManagers[i].release(fGpu); | 339 fDescriptorSetManagers[i].release(fGpu); |
323 } | 340 } |
324 fDescriptorSetManagers.reset(); | 341 fDescriptorSetManagers.reset(); |
| 342 |
| 343 // release our uniform buffers |
| 344 for (int i = 0; i < fAvailableUniformBufferResources.count(); ++i) { |
| 345 SkASSERT(fAvailableUniformBufferResources[i]->unique()); |
| 346 fAvailableUniformBufferResources[i]->unref(fGpu); |
| 347 } |
| 348 fAvailableUniformBufferResources.reset(); |
325 } | 349 } |
326 | 350 |
327 void GrVkResourceProvider::abandonResources() { | 351 void GrVkResourceProvider::abandonResources() { |
328 // release our active command buffers | 352 // release our active command buffers |
329 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { | 353 for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { |
330 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); | 354 SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); |
331 SkASSERT(fActiveCommandBuffers[i]->unique()); | 355 SkASSERT(fActiveCommandBuffers[i]->unique()); |
332 fActiveCommandBuffers[i]->unrefAndAbandon(); | 356 fActiveCommandBuffers[i]->unrefAndAbandon(); |
333 } | 357 } |
334 fActiveCommandBuffers.reset(); | 358 fActiveCommandBuffers.reset(); |
(...skipping 29 matching lines...) Expand all Loading... |
364 | 388 |
365 fPipelineCache = VK_NULL_HANDLE; | 389 fPipelineCache = VK_NULL_HANDLE; |
366 | 390 |
367 // We must abandon all command buffers and pipeline states before abandoning
the | 391 // We must abandon all command buffers and pipeline states before abandoning
the |
368 // GrVkDescriptorSetManagers | 392 // GrVkDescriptorSetManagers |
369 for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { | 393 for (int i = 0; i < fDescriptorSetManagers.count(); ++i) { |
370 fDescriptorSetManagers[i].abandon(); | 394 fDescriptorSetManagers[i].abandon(); |
371 } | 395 } |
372 fDescriptorSetManagers.reset(); | 396 fDescriptorSetManagers.reset(); |
373 | 397 |
| 398 // release our uniform buffers |
| 399 for (int i = 0; i < fAvailableUniformBufferResources.count(); ++i) { |
| 400 SkASSERT(fAvailableUniformBufferResources[i]->unique()); |
| 401 fAvailableUniformBufferResources[i]->unrefAndAbandon(); |
| 402 } |
| 403 fAvailableUniformBufferResources.reset(); |
374 } | 404 } |
375 | 405 |
376 //////////////////////////////////////////////////////////////////////////////// | 406 //////////////////////////////////////////////////////////////////////////////// |
377 | 407 |
378 GrVkResourceProvider::CompatibleRenderPassSet::CompatibleRenderPassSet( | 408 GrVkResourceProvider::CompatibleRenderPassSet::CompatibleRenderPassSet( |
379 const GrVkG
pu* gpu, | 409 const GrVkG
pu* gpu, |
380 const GrVkR
enderTarget& target) | 410 const GrVkR
enderTarget& target) |
381 : fLastReturnedIndex(0) { | 411 : fLastReturnedIndex(0) { |
382 fRenderPasses.emplace_back(new GrVkRenderPass()); | 412 fRenderPasses.emplace_back(new GrVkRenderPass()); |
383 fRenderPasses[0]->initSimple(gpu, target); | 413 fRenderPasses[0]->initSimple(gpu, target); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 } | 449 } |
420 | 450 |
421 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { | 451 void GrVkResourceProvider::CompatibleRenderPassSet::abandonResources() { |
422 for (int i = 0; i < fRenderPasses.count(); ++i) { | 452 for (int i = 0; i < fRenderPasses.count(); ++i) { |
423 if (fRenderPasses[i]) { | 453 if (fRenderPasses[i]) { |
424 fRenderPasses[i]->unrefAndAbandon(); | 454 fRenderPasses[i]->unrefAndAbandon(); |
425 fRenderPasses[i] = nullptr; | 455 fRenderPasses[i] = nullptr; |
426 } | 456 } |
427 } | 457 } |
428 } | 458 } |
OLD | NEW |