aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Timothy Liang <timliang@google.com>2018-07-02 17:36:20 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-11 16:27:28 +0000
commit58f153db313033289ce4a0a7f68bdf6c66238460 (patch)
tree8c3a4cbde7d6d38680756ff2144fc3b88aaab3c7
parent0421083a447a8ab105d20c786f7d8377f30a6d5d (diff)
refactored where texture descriptors are made for metal gpu backend
Bug: skia: Change-Id: Ic90660b5ad5c1e795cd768bb7471e9ac80a59f47 Reviewed-on: https://skia-review.googlesource.com/138999 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Timothy Liang <timliang@google.com>
-rw-r--r--src/gpu/mtl/GrMtlGpu.mm37
-rw-r--r--src/gpu/mtl/GrMtlTexture.h4
-rw-r--r--src/gpu/mtl/GrMtlTexture.mm37
-rw-r--r--src/gpu/mtl/GrMtlTextureRenderTarget.h5
-rw-r--r--src/gpu/mtl/GrMtlTextureRenderTarget.mm39
5 files changed, 60 insertions, 62 deletions
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index d9dd3160ab..8c5f9ddf67 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -127,15 +127,48 @@ sk_sp<GrTexture> GrMtlGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted
if (!fMtlCaps->isConfigTexturable(desc.fConfig)) {
return nullptr;
}
+ MTLPixelFormat format;
+ if (!GrPixelConfigToMTLFormat(desc.fConfig, &format)) {
+ return nullptr;
+ }
bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
+ // This TexDesc refers to the texture that will be read by the client. Thus even if msaa is
+ // requested, this TexDesc describes the resolved texture. Therefore we always have samples set
+ // to 1.
+ MTLTextureDescriptor* texDesc = [[MTLTextureDescriptor alloc] init];
+ texDesc.textureType = MTLTextureType2D;
+ texDesc.pixelFormat = format;
+ texDesc.width = desc.fWidth;
+ texDesc.height = desc.fHeight;
+ texDesc.depth = 1;
+ texDesc.mipmapLevelCount = mipLevels;
+ texDesc.sampleCount = 1;
+ texDesc.arrayLength = 1;
+ texDesc.cpuCacheMode = MTLCPUCacheModeWriteCombined;
+ // Make all textures have private gpu only access. We can use transfer buffers or textures
+ // to copy to them.
+ texDesc.storageMode = MTLStorageModePrivate;
+ texDesc.usage = MTLTextureUsageShaderRead | renderTarget ? MTLTextureUsageRenderTarget : 0;
+
+ GrMipMapsStatus mipMapsStatus = GrMipMapsStatus::kNotAllocated;
+ if (mipLevels > 1) {
+ mipMapsStatus = GrMipMapsStatus::kValid;
+ for (int i = 0; i < mipLevels; ++i) {
+ if (!texels[i].fPixels) {
+ mipMapsStatus = GrMipMapsStatus::kDirty;
+ break;
+ }
+ }
+ }
+
sk_sp<GrMtlTexture> tex;
if (renderTarget) {
tex = GrMtlTextureRenderTarget::CreateNewTextureRenderTarget(this, budgeted,
- desc, mipLevels);
+ desc, texDesc, mipMapsStatus);
} else {
- tex = GrMtlTexture::CreateNewTexture(this, budgeted, desc, mipLevels);
+ tex = GrMtlTexture::CreateNewTexture(this, budgeted, desc, texDesc, mipMapsStatus);
}
if (!tex) {
diff --git a/src/gpu/mtl/GrMtlTexture.h b/src/gpu/mtl/GrMtlTexture.h
index 99fb27d6a5..2265b72a94 100644
--- a/src/gpu/mtl/GrMtlTexture.h
+++ b/src/gpu/mtl/GrMtlTexture.h
@@ -17,7 +17,9 @@ class GrMtlGpu;
class GrMtlTexture : public GrTexture {
public:
static sk_sp<GrMtlTexture> CreateNewTexture(GrMtlGpu*, SkBudgeted budgeted,
- const GrSurfaceDesc&, int mipLevels);
+ const GrSurfaceDesc&,
+ MTLTextureDescriptor*,
+ GrMipMapsStatus);
static sk_sp<GrMtlTexture> MakeWrappedTexture(GrMtlGpu*, const GrSurfaceDesc&,
id<MTLTexture>);
diff --git a/src/gpu/mtl/GrMtlTexture.mm b/src/gpu/mtl/GrMtlTexture.mm
index 87ee28b206..0511df29a8 100644
--- a/src/gpu/mtl/GrMtlTexture.mm
+++ b/src/gpu/mtl/GrMtlTexture.mm
@@ -54,43 +54,26 @@ GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu,
}
sk_sp<GrMtlTexture> GrMtlTexture::CreateNewTexture(GrMtlGpu* gpu, SkBudgeted budgeted,
- const GrSurfaceDesc& desc, int mipLevels) {
- MTLPixelFormat format;
- if (!GrPixelConfigToMTLFormat(desc.fConfig, &format)) {
- return nullptr;
- }
-
+ const GrSurfaceDesc& desc,
+ MTLTextureDescriptor* texDesc,
+ GrMipMapsStatus mipMapsStatus) {
if (desc.fSampleCnt > 1) {
SkASSERT(false); // Currently we don't support msaa
return nullptr;
}
-
- MTLTextureDescriptor* descriptor = [[MTLTextureDescriptor alloc] init];
- descriptor.textureType = MTLTextureType2D;
- descriptor.pixelFormat = format;
- descriptor.width = desc.fWidth;
- descriptor.height = desc.fHeight;
- descriptor.depth = 1;
- descriptor.mipmapLevelCount = mipLevels;
- descriptor.sampleCount = 1;
- descriptor.arrayLength = 1;
- // descriptor.resourceOptions This looks to be set by setting cpuCacheMode and storageModes
- descriptor.cpuCacheMode = MTLCPUCacheModeWriteCombined;
- // Make all textures have private gpu only access. We can use transfer buffers to copy to them.
- descriptor.storageMode = MTLStorageModePrivate;
- descriptor.usage = MTLTextureUsageShaderRead;
-
- id<MTLTexture> texture = [gpu->device() newTextureWithDescriptor:descriptor];
-
- GrMipMapsStatus mipMapsStatus = mipLevels > 1 ? GrMipMapsStatus::kValid
- : GrMipMapsStatus::kNotAllocated;
-
+ id<MTLTexture> texture = [gpu->device() newTextureWithDescriptor:texDesc];
+ SkASSERT(nil != texture);
+ SkASSERT(MTLTextureUsageShaderRead & texture.usage);
return sk_sp<GrMtlTexture>(new GrMtlTexture(gpu, budgeted, desc, texture, mipMapsStatus));
}
sk_sp<GrMtlTexture> GrMtlTexture::MakeWrappedTexture(GrMtlGpu* gpu,
const GrSurfaceDesc& desc,
id<MTLTexture> texture) {
+ if (desc.fSampleCnt > 1) {
+ SkASSERT(false); // Currently we don't support msaa
+ return nullptr;
+ }
SkASSERT(nil != texture);
SkASSERT(MTLTextureUsageShaderRead & texture.usage);
GrMipMapsStatus mipMapsStatus = texture.mipmapLevelCount > 1 ? GrMipMapsStatus::kValid
diff --git a/src/gpu/mtl/GrMtlTextureRenderTarget.h b/src/gpu/mtl/GrMtlTextureRenderTarget.h
index 74b682a9ec..dae3cbc2b6 100644
--- a/src/gpu/mtl/GrMtlTextureRenderTarget.h
+++ b/src/gpu/mtl/GrMtlTextureRenderTarget.h
@@ -16,7 +16,8 @@ public:
static sk_sp<GrMtlTextureRenderTarget> CreateNewTextureRenderTarget(GrMtlGpu*,
SkBudgeted,
const GrSurfaceDesc&,
- int mipLevels);
+ MTLTextureDescriptor*,
+ GrMipMapsStatus);
static sk_sp<GrMtlTextureRenderTarget> MakeWrappedTextureRenderTarget(GrMtlGpu*,
const GrSurfaceDesc&,
@@ -61,7 +62,7 @@ private:
static sk_sp<GrMtlTextureRenderTarget> Make(GrMtlGpu*,
const GrSurfaceDesc&,
id<MTLTexture> resolveTexture,
- int mipLevels,
+ GrMipMapsStatus,
SkBudgeted budgeted,
bool isWrapped);
diff --git a/src/gpu/mtl/GrMtlTextureRenderTarget.mm b/src/gpu/mtl/GrMtlTextureRenderTarget.mm
index c1b36dea83..5c3375af93 100644
--- a/src/gpu/mtl/GrMtlTextureRenderTarget.mm
+++ b/src/gpu/mtl/GrMtlTextureRenderTarget.mm
@@ -34,7 +34,7 @@ sk_sp<GrMtlTextureRenderTarget>
GrMtlTextureRenderTarget::Make(GrMtlGpu* gpu,
const GrSurfaceDesc& desc,
id<MTLTexture> renderTexture,
- int mipLevels,
+ GrMipMapsStatus mipMapsStatus,
SkBudgeted budgeted,
bool isWrapped) {
SkASSERT(nil != renderTexture);
@@ -42,8 +42,7 @@ GrMtlTextureRenderTarget::Make(GrMtlGpu* gpu,
SkASSERT(false); // Currently don't support MSAA
return nullptr;
}
- GrMipMapsStatus mipMapsStatus = mipLevels > 1 ? GrMipMapsStatus::kValid
- : GrMipMapsStatus::kNotAllocated;
+ SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage);
if (!isWrapped) {
return sk_sp<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(gpu,
budgeted,
@@ -63,31 +62,10 @@ sk_sp<GrMtlTextureRenderTarget>
GrMtlTextureRenderTarget::CreateNewTextureRenderTarget(GrMtlGpu* gpu,
SkBudgeted budgeted,
const GrSurfaceDesc& desc,
- int mipLevels) {
- MTLPixelFormat format;
- if (!GrPixelConfigToMTLFormat(desc.fConfig, &format)) {
- return nullptr;
- }
-
- MTLTextureDescriptor* descriptor = [[MTLTextureDescriptor alloc] init];
- descriptor.textureType = MTLTextureType2D;
- descriptor.pixelFormat = format;
- descriptor.width = desc.fWidth;
- descriptor.height = desc.fHeight;
- descriptor.depth = 1;
- descriptor.mipmapLevelCount = mipLevels;
- descriptor.sampleCount = 1;
- descriptor.arrayLength = 1;
- // descriptor.resourceOptions This looks to be set by setting cpuCacheMode and storageModes
- descriptor.cpuCacheMode = MTLCPUCacheModeWriteCombined;
- // RenderTargets never need to be mapped so their storage mode is set to private
- descriptor.storageMode = MTLStorageModePrivate;
-
- descriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
-
- id<MTLTexture> texture = [gpu->device() newTextureWithDescriptor:descriptor];
-
- return Make(gpu, desc, texture, mipLevels, budgeted, false);
+ MTLTextureDescriptor* texDesc,
+ GrMipMapsStatus mipMapsStatus) {
+ id<MTLTexture> texture = [gpu->device() newTextureWithDescriptor:texDesc];
+ return Make(gpu, desc, texture, mipMapsStatus, budgeted, false);
}
sk_sp<GrMtlTextureRenderTarget>
@@ -96,7 +74,8 @@ GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(GrMtlGpu* gpu,
id<MTLTexture> texture) {
SkASSERT(nil != texture);
- SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & texture.usage);
- return Make(gpu, desc, texture, texture.mipmapLevelCount, SkBudgeted::kNo, true);
+ GrMipMapsStatus mipMapsStatus = texture.mipmapLevelCount > 1 ? GrMipMapsStatus::kDirty
+ : GrMipMapsStatus::kNotAllocated;
+ return Make(gpu, desc, texture, mipMapsStatus, SkBudgeted::kNo, true);
}