Add memoryless parameter for MSAA attachment creation

Bug: skia:12086
Change-Id: I9ad293852850253a8c3b1ca6bac4cf86900daec5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/449842
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2021-09-20 11:48:21 -04:00 committed by SkCQ
parent 2816dcfc67
commit 8d59fe04b8
16 changed files with 56 additions and 17 deletions

View File

@ -152,6 +152,20 @@ enum class GrScissorTest : bool {
kEnabled = true
};
/*
* Used to say whether texture is backed by memory.
*/
enum class GrMemoryless : bool {
/**
* The texture will be allocated normally and will affect memory budgets.
*/
kNo = false,
/**
* The texture will be not use GPU memory and will not affect memory budgets.
*/
kYes = true
};
struct GrMipLevel {
const void* fPixels = nullptr;
size_t fRowBytes = 0;

View File

@ -629,7 +629,8 @@ public:
virtual sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected isProtected) = 0;
GrProtected isProtected,
GrMemoryless isMemoryless) = 0;
void handleDirtyContext() {
if (fResetBits) {

View File

@ -672,7 +672,8 @@ sk_sp<GrAttachment> GrResourceProvider::getDiscardableMSAAAttachment(SkISize dim
if (msaaAttachment) {
return msaaAttachment;
}
msaaAttachment = this->makeMSAAAttachment(dimensions, format, sampleCnt, isProtected);
msaaAttachment = this->makeMSAAAttachment(dimensions, format, sampleCnt, isProtected,
GrMemoryless::kNo);
if (msaaAttachment) {
this->assignUniqueKeyToResource(key, msaaAttachment.get());
}
@ -682,7 +683,8 @@ sk_sp<GrAttachment> GrResourceProvider::getDiscardableMSAAAttachment(SkISize dim
sk_sp<GrAttachment> GrResourceProvider::makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int sampleCnt,
GrProtected isProtected) {
GrProtected isProtected,
GrMemoryless isMemoryless) {
ASSERT_SINGLE_OWNER
SkASSERT(sampleCnt > 1);
@ -705,7 +707,7 @@ sk_sp<GrAttachment> GrResourceProvider::makeMSAAAttachment(SkISize dimensions,
return scratch;
}
return fGpu->makeMSAAAttachment(dimensions, format, sampleCnt, isProtected);
return fGpu->makeMSAAAttachment(dimensions, format, sampleCnt, isProtected, isMemoryless);
}
sk_sp<GrAttachment> GrResourceProvider::refScratchMSAAAttachment(SkISize dimensions,

View File

@ -295,7 +295,8 @@ public:
sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int sampleCnt,
GrProtected isProtected);
GrProtected isProtected,
GrMemoryless isMemoryless);
/**
* Gets a GrAttachment that can be used for MSAA rendering. This attachment may be shared by

View File

@ -86,7 +86,8 @@ public:
sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected isProtected) override {
GrProtected isProtected,
GrMemoryless isMemoryless) override {
return nullptr;
}

View File

@ -69,7 +69,8 @@ public:
sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected isProtected) override {
GrProtected isProtected,
GrMemoryless isMemoryless) override {
return nullptr;
}

View File

@ -1721,7 +1721,9 @@ sk_sp<GrAttachment> GrGLGpu::makeStencilAttachment(const GrBackendFormat& colorF
}
sk_sp<GrAttachment> GrGLGpu::makeMSAAAttachment(SkISize dimensions, const GrBackendFormat& format,
int numSamples, GrProtected isProtected) {
int numSamples, GrProtected isProtected,
GrMemoryless isMemoryless) {
SkASSERT(isMemoryless == GrMemoryless::kNo);
return GrGLAttachment::MakeMSAA(this, dimensions, numSamples, format.asGLFormat());
}

View File

@ -155,7 +155,8 @@ public:
sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected isProtected) override;
GrProtected isProtected,
GrMemoryless) override;
void deleteBackendTexture(const GrBackendTexture&) override;

View File

@ -167,7 +167,8 @@ private:
sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected isProtected) override {
GrProtected isProtected,
GrMemoryless isMemoryless) override {
return nullptr;
}

View File

@ -275,7 +275,8 @@ private:
sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected isProtected) override;
GrProtected isProtected,
GrMemoryless isMemoryless) override;
bool createMtlTextureForBackendSurface(MTLPixelFormat,
SkISize dimensions,

View File

@ -529,7 +529,13 @@ sk_sp<GrAttachment> GrMtlGpu::makeStencilAttachment(const GrBackendFormat& /*col
sk_sp<GrAttachment> GrMtlGpu::makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected /*isProtected*/) {
GrProtected isProtected,
GrMemoryless isMemoryless) {
// Metal doesn't support protected textures
SkASSERT(isProtected == GrProtected::kNo);
// TODO: add memoryless support
SkASSERT(isMemoryless == GrMemoryless::kNo);
MTLPixelFormat pixelFormat = (MTLPixelFormat) format.asMtlFormat();
SkASSERT(pixelFormat != MTLPixelFormatInvalid);
SkASSERT(!GrMtlFormatIsCompressed(pixelFormat));

View File

@ -67,7 +67,8 @@ sk_sp<GrMtlRenderTarget> GrMtlRenderTarget::MakeWrappedRenderTarget(GrMtlGpu* gp
}
auto rp = gpu->getContext()->priv().resourceProvider();
sk_sp<GrAttachment> msaaAttachment = rp->makeMSAAAttachment(
dimensions, GrBackendFormat::MakeMtl(format), sampleCnt, GrProtected::kNo);
dimensions, GrBackendFormat::MakeMtl(format), sampleCnt, GrProtected::kNo,
GrMemoryless::kNo);
if (!msaaAttachment) {
return nullptr;
}

View File

@ -51,7 +51,8 @@ bool create_rt_attachments(GrMtlGpu* gpu, SkISize dimensions, MTLPixelFormat for
if (sampleCnt > 1) {
auto rp = gpu->getContext()->priv().resourceProvider();
sk_sp<GrAttachment> msaaAttachment = rp->makeMSAAAttachment(
dimensions, GrBackendFormat::MakeMtl(format), sampleCnt, GrProtected::kNo);
dimensions, GrBackendFormat::MakeMtl(format), sampleCnt, GrProtected::kNo,
GrMemoryless::kNo);
if (!msaaAttachment) {
return false;
}

View File

@ -1486,7 +1486,11 @@ sk_sp<GrAttachment> GrVkGpu::makeStencilAttachment(const GrBackendFormat& /*colo
sk_sp<GrAttachment> GrVkGpu::makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected isProtected) {
GrProtected isProtected,
GrMemoryless isMemoryless) {
// TODO: add memoryless support
SkASSERT(isMemoryless == GrMemoryless::kNo);
VkFormat pixelFormat;
SkAssertResult(format.asVkFormat(&pixelFormat));
SkASSERT(!GrVkFormatIsCompressed(pixelFormat));

View File

@ -118,7 +118,8 @@ public:
sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions,
const GrBackendFormat& format,
int numSamples,
GrProtected isProtected) override;
GrProtected isProtected,
GrMemoryless isMemoryless) override;
void addBufferMemoryBarrier(const GrManagedResource*,
VkPipelineStageFlags srcStageMask,

View File

@ -59,7 +59,8 @@ bool create_rt_attachments(GrVkGpu* gpu, SkISize dimensions, VkFormat format, in
if (sampleCnt > 1) {
auto rp = gpu->getContext()->priv().resourceProvider();
sk_sp<GrAttachment> msaaAttachment = rp->makeMSAAAttachment(
dimensions, GrBackendFormat::MakeVk(format), sampleCnt, isProtected);
dimensions, GrBackendFormat::MakeVk(format), sampleCnt, isProtected,
GrMemoryless::kNo);
if (!msaaAttachment) {
return false;
}