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

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

Issue 2115993002: Add resource tracking output and command buffer recycling (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments Created 4 years, 5 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/GrVkCommandBuffer.h ('k') | src/gpu/vk/GrVkDescriptorPool.h » ('j') | 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 2015 Google Inc. 2 * Copyright 2015 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 "GrVkCommandBuffer.h" 8 #include "GrVkCommandBuffer.h"
9 9
10 #include "GrVkFramebuffer.h" 10 #include "GrVkFramebuffer.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 this->onFreeGPUData(gpu); 46 this->onFreeGPUData(gpu);
47 } 47 }
48 48
49 void GrVkCommandBuffer::abandonSubResources() const { 49 void GrVkCommandBuffer::abandonSubResources() const {
50 for (int i = 0; i < fTrackedResources.count(); ++i) { 50 for (int i = 0; i < fTrackedResources.count(); ++i) {
51 fTrackedResources[i]->unrefAndAbandon(); 51 fTrackedResources[i]->unrefAndAbandon();
52 } 52 }
53 } 53 }
54 54
55 void GrVkCommandBuffer::reset(GrVkGpu* gpu) {
56 SkASSERT(!fIsActive);
57 for (int i = 0; i < fTrackedResources.count(); ++i) {
58 fTrackedResources[i]->unref(gpu);
59 }
60 fTrackedResources.reset();
61
62 this->invalidateState();
63
64 // we will retain resources for later use
65 VkCommandBufferResetFlags flags = 0;
66 GR_VK_CALL(gpu->vkInterface(), ResetCommandBuffer(fCmdBuffer, flags));
67
68 this->onReset(gpu);
69 }
70
55 //////////////////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////////////
56 // CommandBuffer commands 72 // CommandBuffer commands
57 //////////////////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////////////////
58 74
59 void GrVkCommandBuffer::pipelineBarrier(const GrVkGpu* gpu, 75 void GrVkCommandBuffer::pipelineBarrier(const GrVkGpu* gpu,
60 VkPipelineStageFlags srcStageMask, 76 VkPipelineStageFlags srcStageMask,
61 VkPipelineStageFlags dstStageMask, 77 VkPipelineStageFlags dstStageMask,
62 bool byRegion, 78 bool byRegion,
63 BarrierType barrierType, 79 BarrierType barrierType,
64 void* barrier) const { 80 void* barrier) const {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 329 }
314 330
315 void GrVkPrimaryCommandBuffer::endRenderPass(const GrVkGpu* gpu) { 331 void GrVkPrimaryCommandBuffer::endRenderPass(const GrVkGpu* gpu) {
316 SkASSERT(fIsActive); 332 SkASSERT(fIsActive);
317 SkASSERT(fActiveRenderPass); 333 SkASSERT(fActiveRenderPass);
318 GR_VK_CALL(gpu->vkInterface(), CmdEndRenderPass(fCmdBuffer)); 334 GR_VK_CALL(gpu->vkInterface(), CmdEndRenderPass(fCmdBuffer));
319 fActiveRenderPass = nullptr; 335 fActiveRenderPass = nullptr;
320 } 336 }
321 337
322 void GrVkPrimaryCommandBuffer::executeCommands(const GrVkGpu* gpu, 338 void GrVkPrimaryCommandBuffer::executeCommands(const GrVkGpu* gpu,
323 const GrVkSecondaryCommandBuffer* buffer) { 339 GrVkSecondaryCommandBuffer* buffe r) {
324 SkASSERT(fIsActive); 340 SkASSERT(fIsActive);
325 SkASSERT(fActiveRenderPass); 341 SkASSERT(fActiveRenderPass);
326 SkASSERT(fActiveRenderPass->isCompatible(*buffer->fActiveRenderPass)); 342 SkASSERT(fActiveRenderPass->isCompatible(*buffer->fActiveRenderPass));
327 343
328 GR_VK_CALL(gpu->vkInterface(), CmdExecuteCommands(fCmdBuffer, 1, &buffer->fC mdBuffer)); 344 GR_VK_CALL(gpu->vkInterface(), CmdExecuteCommands(fCmdBuffer, 1, &buffer->fC mdBuffer));
329 this->addResource(buffer); 345 buffer->ref();
346 fSecondaryCommandBuffers.push_back(buffer);
330 // When executing a secondary command buffer all state (besides render pass state) becomes 347 // When executing a secondary command buffer all state (besides render pass state) becomes
331 // invalidated and must be reset. This includes bound buffers, pipelines, dy namic state, etc. 348 // invalidated and must be reset. This includes bound buffers, pipelines, dy namic state, etc.
332 this->invalidateState(); 349 this->invalidateState();
333 } 350 }
334 351
335 void GrVkPrimaryCommandBuffer::submitToQueue(const GrVkGpu* gpu, 352 void GrVkPrimaryCommandBuffer::submitToQueue(const GrVkGpu* gpu,
336 VkQueue queue, 353 VkQueue queue,
337 GrVkGpu::SyncQueue sync) { 354 GrVkGpu::SyncQueue sync) {
338 SkASSERT(!fIsActive); 355 SkASSERT(!fIsActive);
339 356
340 VkResult err; 357 VkResult err;
341 VkFenceCreateInfo fenceInfo; 358 if (VK_NULL_HANDLE == fSubmitFence) {
342 memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo)); 359 VkFenceCreateInfo fenceInfo;
343 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; 360 memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo));
344 err = GR_VK_CALL(gpu->vkInterface(), CreateFence(gpu->device(), &fenceInfo, nullptr, 361 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
345 &fSubmitFence)); 362 err = GR_VK_CALL(gpu->vkInterface(), CreateFence(gpu->device(), &fenceIn fo, nullptr,
346 SkASSERT(!err); 363 &fSubmitFence));
364 SkASSERT(!err);
365 } else {
366 GR_VK_CALL(gpu->vkInterface(), ResetFences(gpu->device(), 1, &fSubmitFen ce));
367 }
347 368
348 VkSubmitInfo submitInfo; 369 VkSubmitInfo submitInfo;
349 memset(&submitInfo, 0, sizeof(VkSubmitInfo)); 370 memset(&submitInfo, 0, sizeof(VkSubmitInfo));
350 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; 371 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
351 submitInfo.pNext = nullptr; 372 submitInfo.pNext = nullptr;
352 submitInfo.waitSemaphoreCount = 0; 373 submitInfo.waitSemaphoreCount = 0;
353 submitInfo.pWaitSemaphores = nullptr; 374 submitInfo.pWaitSemaphores = nullptr;
354 submitInfo.pWaitDstStageMask = 0; 375 submitInfo.pWaitDstStageMask = 0;
355 submitInfo.commandBufferCount = 1; 376 submitInfo.commandBufferCount = 1;
356 submitInfo.pCommandBuffers = &fCmdBuffer; 377 submitInfo.pCommandBuffers = &fCmdBuffer;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 409
389 default: 410 default:
390 SkDebugf("Error getting fence status: %d\n", err); 411 SkDebugf("Error getting fence status: %d\n", err);
391 SkFAIL("failing"); 412 SkFAIL("failing");
392 break; 413 break;
393 } 414 }
394 415
395 return false; 416 return false;
396 } 417 }
397 418
419 void GrVkPrimaryCommandBuffer::onReset(GrVkGpu* gpu) {
420 for (int i = 0; i < fSecondaryCommandBuffers.count(); ++i) {
421 gpu->resourceProvider().recycleSecondaryCommandBuffer(fSecondaryCommandB uffers[i]);
422 }
423 fSecondaryCommandBuffers.reset();
424 }
425
398 void GrVkPrimaryCommandBuffer::copyImage(const GrVkGpu* gpu, 426 void GrVkPrimaryCommandBuffer::copyImage(const GrVkGpu* gpu,
399 GrVkImage* srcImage, 427 GrVkImage* srcImage,
400 VkImageLayout srcLayout, 428 VkImageLayout srcLayout,
401 GrVkImage* dstImage, 429 GrVkImage* dstImage,
402 VkImageLayout dstLayout, 430 VkImageLayout dstLayout,
403 uint32_t copyRegionCount, 431 uint32_t copyRegionCount,
404 const VkImageCopy* copyRegions) { 432 const VkImageCopy* copyRegions) {
405 SkASSERT(fIsActive); 433 SkASSERT(fIsActive);
406 SkASSERT(!fActiveRenderPass); 434 SkASSERT(!fActiveRenderPass);
407 this->addResource(srcImage->resource()); 435 this->addResource(srcImage->resource());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 // Destroy the fence, if any 559 // Destroy the fence, if any
532 if (VK_NULL_HANDLE != fSubmitFence) { 560 if (VK_NULL_HANDLE != fSubmitFence) {
533 GR_VK_CALL(gpu->vkInterface(), DestroyFence(gpu->device(), fSubmitFence, nullptr)); 561 GR_VK_CALL(gpu->vkInterface(), DestroyFence(gpu->device(), fSubmitFence, nullptr));
534 } 562 }
535 } 563 }
536 564
537 /////////////////////////////////////////////////////////////////////////////// 565 ///////////////////////////////////////////////////////////////////////////////
538 // SecondaryCommandBuffer 566 // SecondaryCommandBuffer
539 //////////////////////////////////////////////////////////////////////////////// 567 ////////////////////////////////////////////////////////////////////////////////
540 568
541 GrVkSecondaryCommandBuffer* GrVkSecondaryCommandBuffer::Create( 569 GrVkSecondaryCommandBuffer* GrVkSecondaryCommandBuffer::Create(const GrVkGpu* gp u,
542 const GrVkGpu* gpu, 570 VkCommandPool cmd Pool) {
543 VkCommandPool cmdPool,
544 const GrVkRenderPass* com patibleRenderPass) {
545 const VkCommandBufferAllocateInfo cmdInfo = { 571 const VkCommandBufferAllocateInfo cmdInfo = {
546 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType 572 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
547 NULL, // pNext 573 NULL, // pNext
548 cmdPool, // commandPool 574 cmdPool, // commandPool
549 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level 575 VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level
550 1 // bufferCount 576 1 // bufferCount
551 }; 577 };
552 578
553 VkCommandBuffer cmdBuffer; 579 VkCommandBuffer cmdBuffer;
554 VkResult err = GR_VK_CALL(gpu->vkInterface(), AllocateCommandBuffers(gpu->de vice(), 580 VkResult err = GR_VK_CALL(gpu->vkInterface(), AllocateCommandBuffers(gpu->de vice(),
555 &cmdInf o, 581 &cmdInf o,
556 &cmdBuf fer)); 582 &cmdBuf fer));
557 if (err) { 583 if (err) {
558 return nullptr; 584 return nullptr;
559 } 585 }
560 return new GrVkSecondaryCommandBuffer(cmdBuffer, compatibleRenderPass); 586 return new GrVkSecondaryCommandBuffer(cmdBuffer);
561 } 587 }
562 588
563 589
564 void GrVkSecondaryCommandBuffer::begin(const GrVkGpu* gpu, const GrVkFramebuffer * framebuffer) { 590 void GrVkSecondaryCommandBuffer::begin(const GrVkGpu* gpu, const GrVkFramebuffer * framebuffer,
591 const GrVkRenderPass* compatibleRenderPas s) {
565 SkASSERT(!fIsActive); 592 SkASSERT(!fIsActive);
566 SkASSERT(fActiveRenderPass); 593 SkASSERT(compatibleRenderPass);
594 fActiveRenderPass = compatibleRenderPass;
567 595
568 VkCommandBufferInheritanceInfo inheritanceInfo; 596 VkCommandBufferInheritanceInfo inheritanceInfo;
569 memset(&inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo)); 597 memset(&inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
570 inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO; 598 inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
571 inheritanceInfo.pNext = nullptr; 599 inheritanceInfo.pNext = nullptr;
572 inheritanceInfo.renderPass = fActiveRenderPass->vkRenderPass(); 600 inheritanceInfo.renderPass = fActiveRenderPass->vkRenderPass();
573 inheritanceInfo.subpass = 0; // Currently only using 1 subpass for each rend er pass 601 inheritanceInfo.subpass = 0; // Currently only using 1 subpass for each rend er pass
574 inheritanceInfo.framebuffer = framebuffer ? framebuffer->framebuffer() : VK_ NULL_HANDLE; 602 inheritanceInfo.framebuffer = framebuffer ? framebuffer->framebuffer() : VK_ NULL_HANDLE;
575 inheritanceInfo.occlusionQueryEnable = false; 603 inheritanceInfo.occlusionQueryEnable = false;
576 inheritanceInfo.queryFlags = 0; 604 inheritanceInfo.queryFlags = 0;
(...skipping 12 matching lines...) Expand all
589 fIsActive = true; 617 fIsActive = true;
590 } 618 }
591 619
592 void GrVkSecondaryCommandBuffer::end(const GrVkGpu* gpu) { 620 void GrVkSecondaryCommandBuffer::end(const GrVkGpu* gpu) {
593 SkASSERT(fIsActive); 621 SkASSERT(fIsActive);
594 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), EndCommandBuffer(fCmdBuffer)); 622 GR_VK_CALL_ERRCHECK(gpu->vkInterface(), EndCommandBuffer(fCmdBuffer));
595 this->invalidateState(); 623 this->invalidateState();
596 fIsActive = false; 624 fIsActive = false;
597 } 625 }
598 626
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkCommandBuffer.h ('k') | src/gpu/vk/GrVkDescriptorPool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698