Use mipmapping/protected to lookup scratch textures.

Include protected in scratch key.

Change-Id: I0dfc58c9f54e8279a39adf4bad808b7e0e72cba2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/241397
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-09-16 13:14:47 -04:00 committed by Skia Commit-Bot
parent e3671013e5
commit 14cb4139eb
7 changed files with 51 additions and 41 deletions

View File

@ -84,9 +84,9 @@ protected:
// We're about to be idle in the resource cache. Do our part to trigger the idle callbacks.
fIdleProcs.reset();
}
void computeScratchKey(GrScratchKey*) const override;
private:
void computeScratchKey(GrScratchKey*) const override;
size_t onGpuMemorySize() const override;
void markMipMapsDirty();
void markMipMapsClean();

View File

@ -124,9 +124,10 @@ sk_sp<GrTexture> GrResourceProvider::getExactScratch(const GrSurfaceDesc& desc,
GrRenderable renderable,
int renderTargetSampleCnt,
SkBudgeted budgeted,
GrMipMapped mipMapped,
GrProtected isProtected) {
sk_sp<GrTexture> tex(this->refScratchTexture(desc, format, renderable, renderTargetSampleCnt,
isProtected));
mipMapped, isProtected));
if (tex && SkBudgeted::kNo == budgeted) {
tex->resourcePriv().makeUnbudgeted();
}
@ -223,9 +224,9 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc,
// Compressed textures are read-only so they don't support re-use for scratch.
// TODO: Support GrMipMapped::kYes in scratch texture lookup here.
if (!GrPixelConfigIsCompressed(desc.fConfig) && mipMapped == GrMipMapped::kNo) {
if (!GrPixelConfigIsCompressed(desc.fConfig)) {
sk_sp<GrTexture> tex = this->getExactScratch(
desc, format, renderable, renderTargetSampleCnt, budgeted, isProtected);
desc, format, renderable, renderTargetSampleCnt, budgeted, mipMapped, isProtected);
if (tex) {
return tex;
}
@ -288,7 +289,7 @@ sk_sp<GrTexture> GrResourceProvider::createApproxTexture(const GrSurfaceDesc& de
copyDesc.fHeight = MakeApprox(desc.fHeight);
if (auto tex = this->refScratchTexture(copyDesc, format, renderable, renderTargetSampleCnt,
isProtected)) {
GrMipMapped::kNo, isProtected)) {
return tex;
}
@ -300,6 +301,7 @@ sk_sp<GrTexture> GrResourceProvider::refScratchTexture(const GrSurfaceDesc& desc
const GrBackendFormat& format,
GrRenderable renderable,
int renderTargetSampleCnt,
GrMipMapped mipMapped,
GrProtected isProtected) {
ASSERT_SINGLE_OWNER
SkASSERT(!this->isAbandoned());
@ -311,7 +313,8 @@ sk_sp<GrTexture> GrResourceProvider::refScratchTexture(const GrSurfaceDesc& desc
// to fall back to making a new texture.
if (fGpu->caps()->reuseScratchTextures() || renderable == GrRenderable::kYes) {
GrScratchKey key;
GrTexturePriv::ComputeScratchKey(desc, renderable, renderTargetSampleCnt, &key);
GrTexturePriv::ComputeScratchKey(desc.fConfig, desc.fWidth, desc.fHeight, renderable,
renderTargetSampleCnt, mipMapped, isProtected, &key);
GrGpuResource* resource = fCache->findAndRefScratchResource(key);
if (resource) {
fGpu->stats()->incNumScratchTexturesReused();

View File

@ -284,22 +284,24 @@ private:
// Attempts to find a resource in the cache that exactly matches the GrSurfaceDesc. Failing that
// it returns null. If non-null, the resulting texture is always budgeted.
sk_sp<GrTexture> refScratchTexture(const GrSurfaceDesc& desc,
const GrBackendFormat& format,
GrRenderable renderable,
sk_sp<GrTexture> refScratchTexture(const GrSurfaceDesc&,
const GrBackendFormat&,
GrRenderable,
int renderTargetSampleCnt,
GrProtected isProtected);
GrMipMapped,
GrProtected);
/*
* Try to find an existing scratch texture that exactly matches 'desc'. If successful
* update the budgeting accordingly.
*/
sk_sp<GrTexture> getExactScratch(const GrSurfaceDesc& desc,
const GrBackendFormat& format,
GrRenderable renderable,
sk_sp<GrTexture> getExactScratch(const GrSurfaceDesc&,
const GrBackendFormat&,
GrRenderable,
int renderTargetSampleCnt,
SkBudgeted budgeted,
GrProtected isProtected);
SkBudgeted,
GrMipMapped,
GrProtected);
GrResourceCache* cache() { return fCache; }
const GrResourceCache* cache() const { return fCache; }

View File

@ -281,7 +281,7 @@ void GrSurfaceProxy::computeScratchKey(GrScratchKey* key) const {
int height = this->worstCaseHeight();
GrTexturePriv::ComputeScratchKey(this->config(), width, height, renderable, sampleCount,
mipMapped, key);
mipMapped, fIsProtected, key);
}
void GrSurfaceProxy::setLastRenderTask(GrRenderTask* renderTask) {

View File

@ -86,13 +86,20 @@ void GrTexture::computeScratchKey(GrScratchKey* key) const {
sampleCount = rt->numSamples();
renderable = GrRenderable::kYes;
}
auto isProtected = this->isProtected() ? GrProtected::kYes : GrProtected::kNo;
GrTexturePriv::ComputeScratchKey(this->config(), this->width(), this->height(), renderable,
sampleCount, this->texturePriv().mipMapped(), key);
sampleCount, this->texturePriv().mipMapped(), isProtected,
key);
}
}
void GrTexturePriv::ComputeScratchKey(GrPixelConfig config, int width, int height,
GrRenderable renderable, int sampleCnt, GrMipMapped mipMapped,
void GrTexturePriv::ComputeScratchKey(GrPixelConfig config,
int width,
int height,
GrRenderable renderable,
int sampleCnt,
GrMipMapped mipMapped,
GrProtected isProtected,
GrScratchKey* key) {
static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
SkASSERT(width > 0);
@ -102,22 +109,18 @@ void GrTexturePriv::ComputeScratchKey(GrPixelConfig config, int width, int heigh
// make sure desc.fConfig fits in 5 bits
SkASSERT(sk_float_log2(kLast_GrPixelConfig) <= 5);
SkASSERT(static_cast<int>(config) < (1 << 5));
SkASSERT(sampleCnt < (1 << 8));
SkASSERT(static_cast<int>(mipMapped) <= 1);
SkASSERT(static_cast<uint32_t>(config) < (1 << 5));
SkASSERT(static_cast<uint32_t>(mipMapped) <= 1);
SkASSERT(static_cast<uint32_t>(isProtected) <= 1);
SkASSERT(static_cast<uint32_t>(renderable) <= 1);
SkASSERT(static_cast<uint32_t>(sampleCnt) < (1 << (32 - 8)));
GrScratchKey::Builder builder(key, kType, 3);
builder[0] = width;
builder[1] = height;
builder[2] = config
| (static_cast<uint32_t>(mipMapped) << 5)
| (sampleCnt << 6)
| (static_cast<uint32_t>(renderable) << 14);
}
void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrRenderable renderable,
int sampleCnt, GrScratchKey* key) {
// Note: the fOrigin field is not used in the scratch key
return ComputeScratchKey(desc.fConfig, desc.fWidth, desc.fHeight, renderable, sampleCnt,
GrMipMapped::kNo, key);
builder[2] = (static_cast<uint32_t>(config) << 0)
| (static_cast<uint32_t>(mipMapped) << 5)
| (static_cast<uint32_t>(isProtected) << 6)
| (static_cast<uint32_t>(renderable) << 7)
| (static_cast<uint32_t>(sampleCnt) << 8);
}

View File

@ -53,9 +53,14 @@ public:
: GrSamplerState::Filter::kMipMap;
}
static void ComputeScratchKey(const GrSurfaceDesc&, GrRenderable, int sampleCnt, GrScratchKey*);
static void ComputeScratchKey(GrPixelConfig config, int width, int height, GrRenderable,
int sampleCnt, GrMipMapped, GrScratchKey* key);
static void ComputeScratchKey(GrPixelConfig config,
int width,
int height,
GrRenderable,
int sampleCnt,
GrMipMapped,
GrProtected,
GrScratchKey* key);
private:
GrTexturePriv(GrTexture* texture) : fTexture(texture) { }

View File

@ -195,11 +195,8 @@ private:
this->texturePriv().mipMapped());
}
void computeScratchKey(GrScratchKey* key) const override {
GrTexturePriv::ComputeScratchKey(this->config(), this->width(), this->height(),
GrRenderable::kYes, this->numSamples(),
this->texturePriv().mipMapped(), key);
}
// This avoids an inherits via dominance warning on MSVC.
void computeScratchKey(GrScratchKey* key) const override { GrTexture::computeScratchKey(key); }
};
#endif