[graphite] Add support for caching discardable msaa textures

Bug: skia:12754
Change-Id: I66f5f64dc6d27f3bd9bf936fd5989531e33ecdc7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/515856
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2022-03-04 10:14:40 -05:00 committed by SkCQ
parent a27ddd9167
commit 11206c3faf
2 changed files with 35 additions and 5 deletions

View File

@ -99,19 +99,41 @@ sk_sp<Texture> ResourceProvider::findOrCreateDepthStencilAttachment(SkISize dime
// stomping on each other's data.
fGpu->caps()->buildKeyForTexture(dimensions, info, kType, Shareable::kYes, &key);
return this->findOrCreateTextureWithKey(dimensions, info, key);
}
sk_sp<Texture> ResourceProvider::findOrCreateDiscardableMSAAAttachment(SkISize dimensions,
const TextureInfo& info) {
SkASSERT(info.isValid());
static const ResourceType kType = GraphiteResourceKey::GenerateResourceType();
GraphiteResourceKey key;
// We always make discardable msaa attachments shareable. Between any render pass we discard
// the values of the MSAA texture. Thus it is safe to be used by multiple different render
// passes without worry of stomping on each other's data. It is the callings code responsiblity
// to populate the discardable MSAA texture with data at the start of the render pass.
fGpu->caps()->buildKeyForTexture(dimensions, info, kType, Shareable::kYes, &key);
return this->findOrCreateTextureWithKey(dimensions, info, key);
}
sk_sp<Texture> ResourceProvider::findOrCreateTextureWithKey(SkISize dimensions,
const TextureInfo& info,
const GraphiteResourceKey& key) {
if (Resource* resource = fResourceCache->findAndRefResource(key)) {
return sk_sp<Texture>(static_cast<Texture*>(resource));
}
auto stencil = this->createTexture(dimensions, info);
if (!stencil) {
auto tex = this->createTexture(dimensions, info);
if (!tex) {
return nullptr;
}
stencil->setKey(key);
fResourceCache->insertResource(stencil.get());
tex->setKey(key);
fResourceCache->insertResource(tex.get());
return stencil;
return tex;
}
sk_sp<Sampler> ResourceProvider::findOrCreateCompatibleSampler(const SkSamplingOptions& smplOptions,

View File

@ -27,6 +27,7 @@ class Caps;
class GlobalCache;
class Gpu;
class GraphicsPipeline;
class GraphiteResourceKey;
class ResourceCache;
class Sampler;
class SingleOwner;
@ -48,6 +49,9 @@ public:
sk_sp<Texture> findOrCreateDepthStencilAttachment(SkISize dimensions,
const TextureInfo&);
sk_sp<Texture> findOrCreateDiscardableMSAAAttachment(SkISize dimensions,
const TextureInfo&);
sk_sp<Buffer> findOrCreateBuffer(size_t size, BufferType type, PrioritizeGpuReads);
sk_sp<Sampler> findOrCreateCompatibleSampler(const SkSamplingOptions&,
@ -71,6 +75,10 @@ private:
SkTileMode xTileMode,
SkTileMode yTileMode) = 0;
sk_sp<Texture> findOrCreateTextureWithKey(SkISize dimensions,
const TextureInfo& info,
const GraphiteResourceKey& key);
class GraphicsPipelineCache {
public:
GraphicsPipelineCache(ResourceProvider* resourceProvider);