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

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

Issue 1862043002: Refactor to separate backend object lifecycle and GpuResource budget decision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix unrelated GrBuffer::onGpuMemorySize() lack of override keyword compile error Created 4 years, 8 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/GrVkGpu.h ('k') | src/gpu/vk/GrVkIndexBuffer.cpp » ('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 "GrVkGpu.h" 8 #include "GrVkGpu.h"
9 9
10 #include "GrContextOptions.h" 10 #include "GrContextOptions.h"
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // Submit the current command buffer to the Queue 431 // Submit the current command buffer to the Queue
432 this->submitCommandBuffer(kSkip_SyncQueue); 432 this->submitCommandBuffer(kSkip_SyncQueue);
433 433
434 transferBuffer->unref(); 434 transferBuffer->unref();
435 } 435 }
436 436
437 return true; 437 return true;
438 } 438 }
439 439
440 //////////////////////////////////////////////////////////////////////////////// 440 ////////////////////////////////////////////////////////////////////////////////
441 GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::Li feCycle lifeCycle, 441 GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budget ed,
442 const SkTArray<GrMipLevel>& texels) { 442 const SkTArray<GrMipLevel>& texels) {
443 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); 443 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
444 444
445 VkFormat pixelFormat; 445 VkFormat pixelFormat;
446 if (!GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)) { 446 if (!GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)) {
447 return nullptr; 447 return nullptr;
448 } 448 }
449 449
450 if (!fVkCaps->isConfigTexturable(desc.fConfig)) { 450 if (!fVkCaps->isConfigTexturable(desc.fConfig)) {
451 return nullptr; 451 return nullptr;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 imageDesc.fWidth = desc.fWidth; 486 imageDesc.fWidth = desc.fWidth;
487 imageDesc.fHeight = desc.fHeight; 487 imageDesc.fHeight = desc.fHeight;
488 imageDesc.fLevels = 1; 488 imageDesc.fLevels = 1;
489 imageDesc.fSamples = 1; 489 imageDesc.fSamples = 1;
490 imageDesc.fImageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TI LING_OPTIMAL; 490 imageDesc.fImageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TI LING_OPTIMAL;
491 imageDesc.fUsageFlags = usageFlags; 491 imageDesc.fUsageFlags = usageFlags;
492 imageDesc.fMemProps = memProps; 492 imageDesc.fMemProps = memProps;
493 493
494 GrVkTexture* tex; 494 GrVkTexture* tex;
495 if (renderTarget) { 495 if (renderTarget) {
496 tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, desc, lifeCycle, 496 tex = GrVkTextureRenderTarget::CreateNewTextureRenderTarget(this, budget ed, desc,
497 imageDesc); 497 imageDesc);
498 } else { 498 } else {
499 tex = GrVkTexture::CreateNewTexture(this, desc, lifeCycle, imageDesc); 499 tex = GrVkTexture::CreateNewTexture(this, budgeted, desc, imageDesc);
500 } 500 }
501 501
502 if (!tex) { 502 if (!tex) {
503 return nullptr; 503 return nullptr;
504 } 504 }
505 505
506 // TODO: We're ignoring MIP levels here. 506 // TODO: We're ignoring MIP levels here.
507 if (!texels.empty()) { 507 if (!texels.empty()) {
508 SkASSERT(texels.begin()->fPixels); 508 SkASSERT(texels.begin()->fPixels);
509 if (!this->uploadTexData(tex, 0, 0, desc.fWidth, desc.fHeight, desc.fCon fig, 509 if (!this->uploadTexData(tex, 0, 0, desc.fWidth, desc.fHeight, desc.fCon fig,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 int maxSize = this->caps()->maxTextureSize(); 541 int maxSize = this->caps()->maxTextureSize();
542 if (desc.fWidth > maxSize || desc.fHeight > maxSize) { 542 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
543 return nullptr; 543 return nullptr;
544 } 544 }
545 545
546 const GrVkTextureInfo* info = reinterpret_cast<const GrVkTextureInfo*>(desc. fTextureHandle); 546 const GrVkTextureInfo* info = reinterpret_cast<const GrVkTextureInfo*>(desc. fTextureHandle);
547 if (VK_NULL_HANDLE == info->fImage || VK_NULL_HANDLE == info->fAlloc) { 547 if (VK_NULL_HANDLE == info->fImage || VK_NULL_HANDLE == info->fAlloc) {
548 return nullptr; 548 return nullptr;
549 } 549 }
550 550
551 GrGpuResource::LifeCycle lifeCycle = (kAdopt_GrWrapOwnership == ownership)
552 ? GrGpuResource::kAdopted_LifeCycle
553 : GrGpuResource::kBorrowed_LifeCycle;
554
555 GrSurfaceDesc surfDesc; 551 GrSurfaceDesc surfDesc;
556 // next line relies on GrBackendTextureDesc's flags matching GrTexture's 552 // next line relies on GrBackendTextureDesc's flags matching GrTexture's
557 surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags; 553 surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags;
558 surfDesc.fWidth = desc.fWidth; 554 surfDesc.fWidth = desc.fWidth;
559 surfDesc.fHeight = desc.fHeight; 555 surfDesc.fHeight = desc.fHeight;
560 surfDesc.fConfig = desc.fConfig; 556 surfDesc.fConfig = desc.fConfig;
561 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() ); 557 surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount() );
562 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla g); 558 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFla g);
563 // In GL, Chrome assumes all textures are BottomLeft 559 // In GL, Chrome assumes all textures are BottomLeft
564 // In VK, we don't have this restriction 560 // In VK, we don't have this restriction
565 surfDesc.fOrigin = resolve_origin(desc.fOrigin); 561 surfDesc.fOrigin = resolve_origin(desc.fOrigin);
566 562
567 GrVkTexture* texture = nullptr; 563 GrVkTexture* texture = nullptr;
568 if (renderTarget) { 564 if (renderTarget) {
569 texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this , surfDesc, 565 texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this , surfDesc,
570 life Cycle, format, 566 owne rship, format,
571 info ); 567 info );
572 } else { 568 } else {
573 texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, lifeCycle, f ormat, 569 texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, ownership, f ormat, info);
574 info);
575 } 570 }
576 if (!texture) { 571 if (!texture) {
577 return nullptr; 572 return nullptr;
578 } 573 }
579 574
580 return texture; 575 return texture;
581 } 576 }
582 577
583 GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& wrapDesc, 578 GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDe sc& wrapDesc,
584 GrWrapOwnership ownership) { 579 GrWrapOwnership ownership) {
585 580
586 const GrVkTextureInfo* info = 581 const GrVkTextureInfo* info =
587 reinterpret_cast<const GrVkTextureInfo*>(wrapDesc.fRenderTargetHandle); 582 reinterpret_cast<const GrVkTextureInfo*>(wrapDesc.fRenderTargetHandle);
588 if (VK_NULL_HANDLE == info->fImage || 583 if (VK_NULL_HANDLE == info->fImage ||
589 (VK_NULL_HANDLE == info->fAlloc && kAdopt_GrWrapOwnership == ownership)) { 584 (VK_NULL_HANDLE == info->fAlloc && kAdopt_GrWrapOwnership == ownership)) {
590 return nullptr; 585 return nullptr;
591 } 586 }
592 587
593 GrGpuResource::LifeCycle lifeCycle = (kAdopt_GrWrapOwnership == ownership)
594 ? GrGpuResource::kAdopted_LifeCycle
595 : GrGpuResource::kBorrowed_LifeCycle;
596
597 GrSurfaceDesc desc; 588 GrSurfaceDesc desc;
598 desc.fConfig = wrapDesc.fConfig; 589 desc.fConfig = wrapDesc.fConfig;
599 desc.fFlags = kCheckAllocation_GrSurfaceFlag; 590 desc.fFlags = kCheckAllocation_GrSurfaceFlag;
600 desc.fWidth = wrapDesc.fWidth; 591 desc.fWidth = wrapDesc.fWidth;
601 desc.fHeight = wrapDesc.fHeight; 592 desc.fHeight = wrapDesc.fHeight;
602 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount() ); 593 desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount() );
603 594
604 desc.fOrigin = resolve_origin(wrapDesc.fOrigin); 595 desc.fOrigin = resolve_origin(wrapDesc.fOrigin);
605 596
606 GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, de sc, 597 GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, de sc,
607 lifeCycl e, 598 ownershi p,
608 info); 599 info);
609 if (tgt && wrapDesc.fStencilBits) { 600 if (tgt && wrapDesc.fStencilBits) {
610 if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeig ht)) { 601 if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeig ht)) {
611 tgt->unref(); 602 tgt->unref();
612 return nullptr; 603 return nullptr;
613 } 604 }
614 } 605 }
615 return tgt; 606 return tgt;
616 } 607 }
617 608
(...skipping 27 matching lines...) Expand all
645 int width, 636 int width,
646 int height) { 637 int height) {
647 SkASSERT(width >= rt->width()); 638 SkASSERT(width >= rt->width());
648 SkASSERT(height >= rt->height()); 639 SkASSERT(height >= rt->height());
649 640
650 int samples = rt->numStencilSamples(); 641 int samples = rt->numStencilSamples();
651 642
652 const GrVkCaps::StencilFormat& sFmt = this->vkCaps().preferedStencilFormat() ; 643 const GrVkCaps::StencilFormat& sFmt = this->vkCaps().preferedStencilFormat() ;
653 644
654 GrVkStencilAttachment* stencil(GrVkStencilAttachment::Create(this, 645 GrVkStencilAttachment* stencil(GrVkStencilAttachment::Create(this,
655 GrGpuResource:: kCached_LifeCycle,
656 width, 646 width,
657 height, 647 height,
658 samples, 648 samples,
659 sFmt)); 649 sFmt));
660 fStats.incStencilAttachmentCreates(); 650 fStats.incStencilAttachmentCreates();
661 return stencil; 651 return stencil;
662 } 652 }
663 653
664 //////////////////////////////////////////////////////////////////////////////// 654 ////////////////////////////////////////////////////////////////////////////////
665 655
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 aglSwapBuffers(aglGetCurrentContext()); 1601 aglSwapBuffers(aglGetCurrentContext());
1612 int set_a_break_pt_here = 9; 1602 int set_a_break_pt_here = 9;
1613 aglSwapBuffers(aglGetCurrentContext()); 1603 aglSwapBuffers(aglGetCurrentContext());
1614 #elif defined(SK_BUILD_FOR_WIN32) 1604 #elif defined(SK_BUILD_FOR_WIN32)
1615 SwapBuf(); 1605 SwapBuf();
1616 int set_a_break_pt_here = 9; 1606 int set_a_break_pt_here = 9;
1617 SwapBuf(); 1607 SwapBuf();
1618 #endif 1608 #endif
1619 #endif 1609 #endif
1620 } 1610 }
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkGpu.h ('k') | src/gpu/vk/GrVkIndexBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698