Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp
index 4d84455..8ad3968 100644
--- a/src/gpu/vk/GrVkRenderTarget.cpp
+++ b/src/gpu/vk/GrVkRenderTarget.cpp
@@ -22,16 +22,16 @@
// We're virtually derived from GrSurface (via GrRenderTarget) so its
// constructor must be explicitly called.
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
+ SkBudgeted budgeted,
const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
const GrVkImage::Resource* imageResource,
const GrVkImage::Resource* msaaResource,
const GrVkImageView* colorAttachmentView,
const GrVkImageView* resolveAttachmentView)
- : GrSurface(gpu, lifeCycle, desc)
+ : GrSurface(gpu, desc)
, GrVkImage(imageResource)
// for the moment we only support 1:1 color to stencil
- , GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig)
+ , GrRenderTarget(gpu, desc, kUnified_SampleConfig)
, fFramebuffer(nullptr)
, fColorAttachmentView(colorAttachmentView)
, fMSAAImageResource(msaaResource)
@@ -41,7 +41,7 @@
// The plus 1 is to account for the resolve texture.
fColorValuesPerPixel = desc.fSampleCnt + 1; // TODO: this still correct?
this->createFramebuffer(gpu);
- this->registerWithCache();
+ this->registerWithCache(budgeted);
msaaResource->ref();
}
@@ -49,16 +49,14 @@
// constructor must be explicitly called.
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
const GrVkImage::Resource* imageResource,
const GrVkImage::Resource* msaaResource,
const GrVkImageView* colorAttachmentView,
- const GrVkImageView* resolveAttachmentView,
- Derived)
- : GrSurface(gpu, lifeCycle, desc)
+ const GrVkImageView* resolveAttachmentView)
+ : GrSurface(gpu, desc)
, GrVkImage(imageResource)
// for the moment we only support 1:1 color to stencil
- , GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig)
+ , GrRenderTarget(gpu, desc, kUnified_SampleConfig)
, fFramebuffer(nullptr)
, fColorAttachmentView(colorAttachmentView)
, fMSAAImageResource(msaaResource)
@@ -74,13 +72,13 @@
// We're virtually derived from GrSurface (via GrRenderTarget) so its
// constructor must be explicitly called.
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
+ SkBudgeted budgeted,
const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
const GrVkImage::Resource* imageResource,
const GrVkImageView* colorAttachmentView)
- : GrSurface(gpu, lifeCycle, desc)
+ : GrSurface(gpu, desc)
, GrVkImage(imageResource)
- , GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig)
+ , GrRenderTarget(gpu, desc, kUnified_SampleConfig)
, fFramebuffer(nullptr)
, fColorAttachmentView(colorAttachmentView)
, fMSAAImageResource(nullptr)
@@ -89,20 +87,18 @@
SkASSERT(!desc.fSampleCnt);
fColorValuesPerPixel = 1;
this->createFramebuffer(gpu);
- this->registerWithCache();
+ this->registerWithCache(budgeted);
}
// We're virtually derived from GrSurface (via GrRenderTarget) so its
// constructor must be explicitly called.
GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu,
const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
const GrVkImage::Resource* imageResource,
- const GrVkImageView* colorAttachmentView,
- Derived)
- : GrSurface(gpu, lifeCycle, desc)
+ const GrVkImageView* colorAttachmentView)
+ : GrSurface(gpu, desc)
, GrVkImage(imageResource)
- , GrRenderTarget(gpu, lifeCycle, desc, kUnified_SampleConfig)
+ , GrRenderTarget(gpu, desc, kUnified_SampleConfig)
, fFramebuffer(nullptr)
, fColorAttachmentView(colorAttachmentView)
, fMSAAImageResource(nullptr)
@@ -115,8 +111,8 @@
GrVkRenderTarget*
GrVkRenderTarget::Create(GrVkGpu* gpu,
+ SkBudgeted budgeted,
const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
const GrVkImage::Resource* imageResource) {
VkFormat pixelFormat;
GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat);
@@ -172,11 +168,11 @@
GrVkRenderTarget* texRT;
if (msaaResource) {
- texRT = new GrVkRenderTarget(gpu, desc, lifeCycle, imageResource, msaaResource,
+ texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource, msaaResource,
colorAttachmentView, resolveAttachmentView);
msaaResource->unref(gpu);
} else {
- texRT = new GrVkRenderTarget(gpu, desc, lifeCycle, imageResource,
+ texRT = new GrVkRenderTarget(gpu, budgeted, desc, imageResource,
colorAttachmentView);
}
@@ -185,8 +181,8 @@
GrVkRenderTarget*
GrVkRenderTarget::CreateNewRenderTarget(GrVkGpu* gpu,
+ SkBudgeted budgeted,
const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
const GrVkImage::ImageDesc& imageDesc) {
SkASSERT(imageDesc.fUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
@@ -195,7 +191,7 @@
return nullptr;
}
- GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageResource);
+ GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, budgeted, desc, imageResource);
// Create() will increment the refCount of the image resource if it succeeds
imageResource->unref(gpu);
return rt;
@@ -204,18 +200,18 @@
GrVkRenderTarget*
GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu,
const GrSurfaceDesc& desc,
- GrGpuResource::LifeCycle lifeCycle,
+ GrWrapOwnership ownership,
const GrVkTextureInfo* info) {
SkASSERT(info);
// We can wrap a rendertarget without its allocation, as long as we don't take ownership
SkASSERT(VK_NULL_HANDLE != info->fImage);
- SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopted_LifeCycle != lifeCycle);
+ SkASSERT(VK_NULL_HANDLE != info->fAlloc || kAdopt_GrWrapOwnership != ownership);
GrVkImage::Resource::Flags flags = (VK_IMAGE_TILING_LINEAR == info->fImageTiling)
? Resource::kLinearTiling_Flag : Resource::kNo_Flags;
const GrVkImage::Resource* imageResource;
- if (kBorrowed_LifeCycle == lifeCycle) {
+ if (kBorrow_GrWrapOwnership == ownership) {
imageResource = new GrVkImage::BorrowedResource(info->fImage,
info->fAlloc,
flags,
@@ -227,7 +223,7 @@
return nullptr;
}
- GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, desc, lifeCycle, imageResource);
+ GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc, imageResource);
if (rt) {
rt->fCurrentLayout = info->fImageLayout;
}
@@ -367,12 +363,7 @@
void GrVkRenderTarget::onRelease() {
this->releaseInternalObjects();
- if (this->shouldFreeResources()) {
- this->releaseImage(this->getVkGpu());
- } else {
- this->abandonImage();
- }
-
+ this->releaseImage(this->getVkGpu());
GrRenderTarget::onRelease();
}