1 /* 2 * Copyright 2021 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef skgpu_graphite_MtlGraphiteTypesPriv_DEFINED 9 #define skgpu_graphite_MtlGraphiteTypesPriv_DEFINED 10 11 #include "include/core/SkString.h" 12 #include "include/gpu/graphite/GraphiteTypes.h" 13 #include "include/gpu/graphite/TextureInfo.h" 14 #include "include/gpu/graphite/mtl/MtlGraphiteTypes.h" 15 16 /////////////////////////////////////////////////////////////////////////////// 17 18 #include <TargetConditionals.h> 19 20 // We're using the MSL version as shorthand for the Metal SDK version here 21 #if defined(SK_BUILD_FOR_MAC) 22 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130000 23 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 300 24 #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 120000 25 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 240 26 #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 110000 27 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 230 28 #else 29 #error Must use at least 11.00 SDK to build Metal backend for MacOS 30 #endif 31 #else 32 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160000 || __TV_OS_VERSION_MAX_ALLOWED >= 160000 33 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 300 34 #elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 || __TV_OS_VERSION_MAX_ALLOWED >= 150000 35 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 240 36 #elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 || __TV_OS_VERSION_MAX_ALLOWED >= 140000 37 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 230 38 #else 39 #error Must use at least 14.00 SDK to build Metal backend for iOS 40 #endif 41 #endif 42 43 #import <Metal/Metal.h> 44 45 namespace skgpu::graphite { 46 47 struct MtlTextureSpec { MtlTextureSpecMtlTextureSpec48 MtlTextureSpec() 49 : fFormat(MTLPixelFormatInvalid) 50 , fUsage(MTLTextureUsageUnknown) 51 , fStorageMode(MTLStorageModeShared) 52 , fFramebufferOnly(false) {} MtlTextureSpecMtlTextureSpec53 MtlTextureSpec(const MtlTextureInfo& info) 54 : fFormat(info.fFormat) 55 , fUsage(info.fUsage) 56 , fStorageMode(info.fStorageMode) 57 , fFramebufferOnly(info.fFramebufferOnly) {} 58 59 bool operator==(const MtlTextureSpec& that) const { 60 return fFormat == that.fFormat && fUsage == that.fUsage && 61 fStorageMode == that.fStorageMode && fFramebufferOnly == that.fFramebufferOnly; 62 } 63 isCompatibleMtlTextureSpec64 bool isCompatible(const MtlTextureSpec& that) const { 65 // The usages may match or the usage passed in may be a superset of the usage stored within. 66 return fFormat == that.fFormat && fStorageMode == that.fStorageMode && 67 fFramebufferOnly == that.fFramebufferOnly && (fUsage & that.fUsage) == fUsage; 68 } 69 toStringMtlTextureSpec70 SkString toString() const { 71 return SkStringPrintf("format=%u,usage=0x%04X,storageMode=%u,framebufferOnly=%d", 72 (uint32_t)fFormat, 73 (uint32_t)fUsage, 74 (uint32_t)fStorageMode, 75 fFramebufferOnly); 76 } 77 78 MTLPixelFormat fFormat; 79 MTLTextureUsage fUsage; 80 MTLStorageMode fStorageMode; 81 bool fFramebufferOnly; 82 }; 83 84 MtlTextureInfo MtlTextureSpecToTextureInfo(const MtlTextureSpec& mtlSpec, 85 uint32_t sampleCount, 86 Mipmapped mipmapped); 87 88 namespace TextureInfos { 89 MtlTextureSpec GetMtlTextureSpec(const TextureInfo&); 90 MTLPixelFormat GetMTLPixelFormat(const TextureInfo&); 91 MTLTextureUsage GetMTLTextureUsage(const TextureInfo&); 92 bool GetMtlFramebufferOnly(const TextureInfo&); 93 } // namespace TextureInfos 94 95 } // namespace skgpu::graphite 96 97 #endif // skgpu_graphite_MtlGraphiteTypesPriv_DEFINED 98