Add Texture usage to GrAttachment.
This is not used anywhere yet, just starting to get the framework all
set up.
Bug: skia:10727
Change-Id: Ie321bb850e4c0eecd5e557b8a7828ee941ba7d2c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/378377
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrAttachment.cpp b/src/gpu/GrAttachment.cpp
index f465153..6db517d 100644
--- a/src/gpu/GrAttachment.cpp
+++ b/src/gpu/GrAttachment.cpp
@@ -29,6 +29,7 @@
SkISize dimensions,
GrAttachment::UsageFlags requiredUsage,
int sampleCnt,
+ GrMipmapped mipmapped,
GrProtected isProtected) {
SkASSERT(!dimensions.isEmpty());
@@ -51,12 +52,13 @@
SkISize dimensions,
UsageFlags requiredUsage,
int sampleCnt,
+ GrMipmapped mipmapped,
GrProtected isProtected,
GrUniqueKey* key) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kDomain, 5);
- build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, isProtected);
+ build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected);
}
void GrAttachment::ComputeScratchKey(const GrCaps& caps,
@@ -64,20 +66,20 @@
SkISize dimensions,
UsageFlags requiredUsage,
int sampleCnt,
+ GrMipmapped mipmapped,
GrProtected isProtected,
GrScratchKey* key) {
static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
- SkASSERT(sampleCnt > 1);
-
GrScratchKey::Builder builder(key, kType, 5);
- build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, isProtected);
+ build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected);
}
void GrAttachment::computeScratchKey(GrScratchKey* key) const {
- if (fSupportedUsages & UsageFlags::kColorAttachment) {
+ if (!SkToBool(fSupportedUsages & UsageFlags::kStencilAttachment)) {
auto isProtected = this->isProtected() ? GrProtected::kYes : GrProtected::kNo;
ComputeScratchKey(*this->getGpu()->caps(), this->backendFormat(), this->dimensions(),
- fSupportedUsages, this->numSamples(), isProtected, key);
+ fSupportedUsages, this->numSamples(), this->mipmapped(), isProtected,
+ key);
}
}
diff --git a/src/gpu/GrAttachment.h b/src/gpu/GrAttachment.h
index 0cd26ee..d1b81e0 100644
--- a/src/gpu/GrAttachment.h
+++ b/src/gpu/GrAttachment.h
@@ -27,6 +27,7 @@
enum class UsageFlags : uint8_t {
kStencilAttachment = 0x1,
kColorAttachment = 0x2,
+ kTexture = 0x4,
};
GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(UsageFlags);
@@ -36,6 +37,8 @@
int numSamples() const { return fSampleCnt; }
+ GrMipmapped mipmapped() const { return fMipmapped; }
+
bool hasPerformedInitialClear() const { return fHasPerformedInitialClear; }
void markHasPerformedInitialClear() { fHasPerformedInitialClear = true; }
@@ -49,6 +52,7 @@
SkISize dimensions,
UsageFlags requiredUsage,
int sampleCnt,
+ GrMipmapped mipmapped,
GrProtected isProtected,
GrUniqueKey* key);
@@ -59,15 +63,17 @@
SkISize dimensions,
UsageFlags requiredUsage,
int sampleCnt,
+ GrMipmapped mipmapped,
GrProtected,
GrScratchKey* key);
protected:
GrAttachment(GrGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, int sampleCnt,
- GrProtected isProtected)
+ GrMipmapped mipmapped, GrProtected isProtected)
: INHERITED(gpu, dimensions, isProtected)
, fSupportedUsages(supportedUsages)
- , fSampleCnt(sampleCnt) {}
+ , fSampleCnt(sampleCnt)
+ , fMipmapped(mipmapped) {}
private:
size_t onGpuMemorySize() const final;
@@ -75,19 +81,17 @@
void computeScratchKey(GrScratchKey*) const final;
const char* getResourceType() const override {
- // TODO: Once attachments can have multiple usages this needs to be updated
- switch (fSupportedUsages) {
- case (UsageFlags::kColorAttachment):
- return "ColorAttachment";
- case (UsageFlags::kStencilAttachment):
- return "StencilAttachment";
- default:
- SkUNREACHABLE;
+ if (fSupportedUsages == UsageFlags::kStencilAttachment) {
+ return "StencilAttachment";
}
+
+ // This is a general grouping of all textures and color attachments.
+ return "Surface";
}
UsageFlags fSupportedUsages;
int fSampleCnt;
+ GrMipmapped fMipmapped;
bool fHasPerformedInitialClear = false;
using INHERITED = GrSurface;
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 5e2798a..eef4721 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -48,7 +48,7 @@
GrRenderable renderable,
int renderTargetSampleCnt,
SkBudgeted budgeted,
- GrMipMapped mipMapped,
+ GrMipmapped mipmapped,
GrProtected isProtected,
const GrMipLevel texels[]) {
ASSERT_SINGLE_OWNER
@@ -58,18 +58,18 @@
}
int numMipLevels = 1;
- if (mipMapped == GrMipMapped::kYes) {
+ if (mipmapped == GrMipmapped::kYes) {
numMipLevels = SkMipmap::ComputeLevelCount(dimensions.fWidth, dimensions.fHeight) + 1;
}
if (!fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt,
- mipMapped)) {
+ mipmapped)) {
return nullptr;
}
// Current rule is that you can provide no level data, just the base, or all the levels.
bool hasPixels = texels[0].fPixels;
auto scratch = this->getExactScratch(dimensions, format, renderable, renderTargetSampleCnt,
- budgeted, mipMapped, isProtected);
+ budgeted, mipmapped, isProtected);
if (scratch) {
if (!hasPixels) {
return scratch;
@@ -96,10 +96,10 @@
GrRenderable renderable,
int renderTargetSampleCnt,
SkBudgeted budgeted,
- GrMipmapped mipMapped,
+ GrMipmapped mipmapped,
GrProtected isProtected) {
sk_sp<GrTexture> tex(this->refScratchTexture(dimensions, format, renderable,
- renderTargetSampleCnt, mipMapped, isProtected));
+ renderTargetSampleCnt, mipmapped, isProtected));
if (tex && SkBudgeted::kNo == budgeted) {
tex->resourcePriv().makeUnbudgeted();
}
@@ -139,21 +139,21 @@
return this->writePixels(std::move(tex), colorType, dimensions, &mipLevel, 1);
} else {
return this->createTexture(dimensions, format, colorType, renderable, renderTargetSampleCnt,
- budgeted, GrMipMapped::kNo, isProtected, &mipLevel);
+ budgeted, GrMipmapped::kNo, isProtected, &mipLevel);
}
}
sk_sp<GrTexture> GrResourceProvider::createCompressedTexture(SkISize dimensions,
const GrBackendFormat& format,
SkBudgeted budgeted,
- GrMipmapped mipMapped,
+ GrMipmapped mipmapped,
GrProtected isProtected,
SkData* data) {
ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
return nullptr;
}
- return fGpu->createCompressedTexture(dimensions, format, budgeted, mipMapped,
+ return fGpu->createCompressedTexture(dimensions, format, budgeted, mipmapped,
isProtected, data->data(), data->size());
}
@@ -161,7 +161,7 @@
const GrBackendFormat& format,
GrRenderable renderable,
int renderTargetSampleCnt,
- GrMipmapped mipMapped,
+ GrMipmapped mipmapped,
SkBudgeted budgeted,
GrProtected isProtected) {
ASSERT_SINGLE_OWNER
@@ -170,7 +170,7 @@
}
if (!fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt,
- mipMapped)) {
+ mipmapped)) {
return nullptr;
}
@@ -181,12 +181,12 @@
// TODO: Support GrMipmapped::kYes in scratch texture lookup here.
sk_sp<GrTexture> tex =
this->getExactScratch(dimensions, format, renderable, renderTargetSampleCnt, budgeted,
- mipMapped, isProtected);
+ mipmapped, isProtected);
if (tex) {
return tex;
}
- return fGpu->createTexture(dimensions, format, renderable, renderTargetSampleCnt, mipMapped,
+ return fGpu->createTexture(dimensions, format, renderable, renderTargetSampleCnt, mipmapped,
budgeted, isProtected);
}
@@ -254,7 +254,7 @@
const GrBackendFormat& format,
GrRenderable renderable,
int renderTargetSampleCnt,
- GrMipmapped mipMapped,
+ GrMipmapped mipmapped,
GrProtected isProtected) {
ASSERT_SINGLE_OWNER
SkASSERT(!this->isAbandoned());
@@ -267,7 +267,7 @@
if (fGpu->caps()->reuseScratchTextures() || renderable == GrRenderable::kYes) {
GrScratchKey key;
GrTexture::ComputeScratchKey(*this->caps(), format, dimensions, renderable,
- renderTargetSampleCnt, mipMapped, isProtected, &key);
+ renderTargetSampleCnt, mipmapped, isProtected, &key);
GrGpuResource* resource = fCache->findAndRefScratchResource(key);
if (resource) {
fGpu->stats()->incNumScratchTexturesReused();
@@ -518,8 +518,8 @@
GrProtected isProtected = rt->isProtected() ? GrProtected::kYes : GrProtected::kNo;
GrAttachment::ComputeSharedAttachmentUniqueKey(
*this->caps(), stencilFormat, rt->dimensions(),
- GrAttachment::UsageFlags::kStencilAttachment, numStencilSamples, isProtected,
- &sbKey);
+ GrAttachment::UsageFlags::kStencilAttachment, numStencilSamples, GrMipmapped::kNo,
+ isProtected, &sbKey);
auto stencil = this->findByUniqueKey<GrAttachment>(sbKey);
if (!stencil) {
// Need to try and create a new stencil
@@ -552,7 +552,7 @@
}
if (!fCaps->validateSurfaceParams(dimensions, format, GrRenderable::kYes, sampleCnt,
- GrMipMapped::kNo)) {
+ GrMipmapped::kNo)) {
return nullptr;
}
@@ -577,7 +577,7 @@
GrScratchKey key;
GrAttachment::ComputeScratchKey(*this->caps(), format, dimensions,
GrAttachment::UsageFlags::kColorAttachment, sampleCnt,
- isProtected, &key);
+ GrMipmapped::kNo, isProtected, &key);
GrGpuResource* resource = fCache->findAndRefScratchResource(key);
if (resource) {
fGpu->stats()->incNumScratchMSAAAttachmentsReused();
diff --git a/src/gpu/d3d/GrD3DAttachment.cpp b/src/gpu/d3d/GrD3DAttachment.cpp
index 13d9da4..ad514bb 100644
--- a/src/gpu/d3d/GrD3DAttachment.cpp
+++ b/src/gpu/d3d/GrD3DAttachment.cpp
@@ -17,7 +17,8 @@
const GrD3DTextureResourceInfo& info,
sk_sp<GrD3DResourceState> state,
const GrD3DDescriptorHeap::CPUHandle& view)
- : GrAttachment(gpu, dimensions, supportedUsages, desc.SampleDesc.Count, GrProtected::kNo)
+ : GrAttachment(gpu, dimensions, supportedUsages, desc.SampleDesc.Count, GrMipmapped::kNo,
+ GrProtected::kNo)
, GrD3DTextureResource(info, state)
, fView(view)
, fFormat(format) {
diff --git a/src/gpu/dawn/GrDawnAttachment.cpp b/src/gpu/dawn/GrDawnAttachment.cpp
index d88d7d4..8fd7a35 100644
--- a/src/gpu/dawn/GrDawnAttachment.cpp
+++ b/src/gpu/dawn/GrDawnAttachment.cpp
@@ -18,7 +18,7 @@
int samples,
wgpu::Texture texture,
wgpu::TextureView view)
- : INHERITED(gpu, dimensions, supportedUsages, samples, GrProtected::kNo)
+ : INHERITED(gpu, dimensions, supportedUsages, samples, GrMipmapped::kNo, GrProtected::kNo)
, fTexture(texture)
, fView(view) {
this->registerWithCache(SkBudgeted::kYes);
diff --git a/src/gpu/gl/GrGLAttachment.h b/src/gpu/gl/GrGLAttachment.h
index ba5a1d40..d7d95f6 100644
--- a/src/gpu/gl/GrGLAttachment.h
+++ b/src/gpu/gl/GrGLAttachment.h
@@ -21,7 +21,8 @@
GrGLAttachment(
GrGpu* gpu, const IDDesc& idDesc, SkISize dimensions, UsageFlags supportedUsages,
int sampleCnt, GrGLFormat format)
- : GrAttachment(gpu, dimensions, supportedUsages, sampleCnt, GrProtected::kNo)
+ : GrAttachment(gpu, dimensions, supportedUsages, sampleCnt, GrMipmapped::kNo,
+ GrProtected::kNo)
, fFormat(format)
, fRenderbufferID(idDesc.fRenderbufferID) {
SkASSERT(supportedUsages == UsageFlags::kStencilAttachment);
diff --git a/src/gpu/mock/GrMockAttachment.h b/src/gpu/mock/GrMockAttachment.h
index 062ae4d..f2bb366 100644
--- a/src/gpu/mock/GrMockAttachment.h
+++ b/src/gpu/mock/GrMockAttachment.h
@@ -15,7 +15,8 @@
class GrMockAttachment : public GrAttachment {
public:
GrMockAttachment(GrMockGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, int sampleCnt)
- : INHERITED(gpu, dimensions, supportedUsages, sampleCnt, GrProtected::kNo) {
+ : INHERITED(gpu, dimensions, supportedUsages, sampleCnt, GrMipmapped::kNo,
+ GrProtected::kNo) {
SkASSERT(supportedUsages == UsageFlags::kStencilAttachment);
this->registerWithCache(SkBudgeted::kYes);
}
diff --git a/src/gpu/mtl/GrMtlAttachment.mm b/src/gpu/mtl/GrMtlAttachment.mm
index ad2824e..968b8b3 100644
--- a/src/gpu/mtl/GrMtlAttachment.mm
+++ b/src/gpu/mtl/GrMtlAttachment.mm
@@ -18,7 +18,8 @@
SkISize dimensions,
UsageFlags supportedUsages,
const id<MTLTexture> view)
- : GrAttachment(gpu, dimensions, supportedUsages, view.sampleCount, GrProtected::kNo)
+ : GrAttachment(gpu, dimensions, supportedUsages, view.sampleCount, GrMipmapped::kNo,
+ GrProtected::kNo)
, fView(view) {
this->registerWithCache(SkBudgeted::kYes);
}
diff --git a/src/gpu/vk/GrVkAttachment.cpp b/src/gpu/vk/GrVkAttachment.cpp
index 919ca6d..6a91924 100644
--- a/src/gpu/vk/GrVkAttachment.cpp
+++ b/src/gpu/vk/GrVkAttachment.cpp
@@ -21,7 +21,8 @@
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
sk_sp<const GrVkImageView> view,
SkBudgeted budgeted)
- : GrAttachment(gpu, dimensions, supportedUsages, info.fSampleCount, info.fProtected)
+ : GrAttachment(gpu, dimensions, supportedUsages, info.fSampleCount, GrMipmapped::kNo,
+ info.fProtected)
, GrVkImage(gpu, info, std::move(mutableState), GrBackendObjectOwnership::kOwned)
, fView(std::move(view)) {
this->registerWithCache(budgeted);
@@ -35,7 +36,8 @@
sk_sp<const GrVkImageView> view,
GrBackendObjectOwnership ownership,
GrWrapCacheable cacheable)
- : GrAttachment(gpu, dimensions, supportedUsages, info.fSampleCount, info.fProtected)
+ : GrAttachment(gpu, dimensions, supportedUsages, info.fSampleCount, GrMipmapped::kNo,
+ info.fProtected)
, GrVkImage(gpu, info, std::move(mutableState), ownership)
, fView(std::move(view)) {
this->registerWithCacheWrapped(cacheable);