22 {
26 return nullptr;
27 }
28
29 const MtlTextureSpec& mtlSpec =
info.mtlTextureSpec();
31
32 if (mtlSpec.fUsage & MTLTextureUsageShaderRead && !caps->isTexturable(
info)) {
33 return nullptr;
34 }
35
36 if (mtlSpec.fUsage & MTLTextureUsageRenderTarget &&
38 return nullptr;
39 }
40
41 if (mtlSpec.fUsage & MTLTextureUsageShaderWrite && !caps->isStorage(
info)) {
42 return nullptr;
43 }
44
45 int numMipLevels = 1;
46 if (
info.mipmapped() == Mipmapped::kYes) {
48 }
49
50 sk_cfp<MTLTextureDescriptor*>
desc([[MTLTextureDescriptor alloc] init]);
51 (*desc).textureType = (
info.numSamples() > 1) ? MTLTextureType2DMultisample : MTLTextureType2D;
52 (*desc).pixelFormat = (MTLPixelFormat)mtlSpec.fFormat;
55 (*desc).depth = 1;
56 (*desc).mipmapLevelCount = numMipLevels;
57 (*desc).sampleCount =
info.numSamples();
58 (*desc).arrayLength = 1;
59 (*desc).usage = mtlSpec.fUsage;
60 (*desc).storageMode = (MTLStorageMode)mtlSpec.fStorageMode;
61
63#ifdef SK_ENABLE_MTL_DEBUG_INFO
64 if (mtlSpec.fUsage & MTLTextureUsageRenderTarget) {
66 (*texture).label = @"DepthStencil";
67 } else {
68 if (
info.numSamples() > 1) {
69 if (mtlSpec.fUsage & MTLTextureUsageShaderRead) {
70 (*texture).label = @"MSAA SampledTexture-ColorAttachment";
71 } else {
72 (*texture).label = @"MSAA ColorAttachment";
73 }
74 } else {
75 if (mtlSpec.fUsage & MTLTextureUsageShaderRead) {
76 (*texture).label = @"SampledTexture-ColorAttachment";
77 } else {
78 (*texture).label = @"ColorAttachment";
79 }
80 }
81 }
82 } else if (mtlSpec.fUsage & MTLTextureUsageShaderWrite) {
83 SkASSERT(mtlSpec.fUsage & MTLTextureUsageShaderRead);
84 (*texture).label = @"StorageTexture";
85 } else {
86 SkASSERT(mtlSpec.fUsage & MTLTextureUsageShaderRead);
87 (*texture).label = @"SampledTexture";
88 }
89#endif
90
92}
static int ComputeLevelCount(int baseWidth, int baseHeight)
const Caps * caps() const
const myers::Point & get(const myers::Segment &)
bool MtlFormatIsDepthOrStencil(MTLPixelFormat format)
constexpr int32_t width() const
constexpr int32_t height() const