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>
This commit is contained in:
parent
0421083a44
commit
58f153db31
@ -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) {
|
||||
|
@ -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>);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user