[Mac] Move MetalPixelFormat() to UtilsMetal
Will facilitate extracting creation of TextureMtl objects from
TextureMTL.mm to UtilsMetal, which itself is necessary to allow
SharedTextureMemoryMTL to create and cache TextureMtl objects.
Change-Id: I382392d2e532aadcd42db8ffe93259e8286db342
Bug: dawn:2152, 1493854
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/168647
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/metal/TextureMTL.mm b/src/dawn/native/metal/TextureMTL.mm
index 6fc1eb1..7dc082c 100644
--- a/src/dawn/native/metal/TextureMTL.mm
+++ b/src/dawn/native/metal/TextureMTL.mm
@@ -230,401 +230,6 @@
#endif
} // namespace
-MTLPixelFormat MetalPixelFormat(const DeviceBase* device, wgpu::TextureFormat format) {
- switch (format) {
- case wgpu::TextureFormat::R8Unorm:
- return MTLPixelFormatR8Unorm;
- case wgpu::TextureFormat::R8Snorm:
- return MTLPixelFormatR8Snorm;
- case wgpu::TextureFormat::R8Uint:
- return MTLPixelFormatR8Uint;
- case wgpu::TextureFormat::R8Sint:
- return MTLPixelFormatR8Sint;
-
- case wgpu::TextureFormat::R16Unorm:
- return MTLPixelFormatR16Unorm;
- case wgpu::TextureFormat::R16Snorm:
- return MTLPixelFormatR16Snorm;
- case wgpu::TextureFormat::R16Uint:
- return MTLPixelFormatR16Uint;
- case wgpu::TextureFormat::R16Sint:
- return MTLPixelFormatR16Sint;
- case wgpu::TextureFormat::R16Float:
- return MTLPixelFormatR16Float;
- case wgpu::TextureFormat::RG8Unorm:
- return MTLPixelFormatRG8Unorm;
- case wgpu::TextureFormat::RG8Snorm:
- return MTLPixelFormatRG8Snorm;
- case wgpu::TextureFormat::RG8Uint:
- return MTLPixelFormatRG8Uint;
- case wgpu::TextureFormat::RG8Sint:
- return MTLPixelFormatRG8Sint;
-
- case wgpu::TextureFormat::R32Uint:
- return MTLPixelFormatR32Uint;
- case wgpu::TextureFormat::R32Sint:
- return MTLPixelFormatR32Sint;
- case wgpu::TextureFormat::R32Float:
- return MTLPixelFormatR32Float;
- case wgpu::TextureFormat::RG16Unorm:
- return MTLPixelFormatRG16Unorm;
- case wgpu::TextureFormat::RG16Snorm:
- return MTLPixelFormatRG16Snorm;
- case wgpu::TextureFormat::RG16Uint:
- return MTLPixelFormatRG16Uint;
- case wgpu::TextureFormat::RG16Sint:
- return MTLPixelFormatRG16Sint;
- case wgpu::TextureFormat::RG16Float:
- return MTLPixelFormatRG16Float;
- case wgpu::TextureFormat::RGBA8Unorm:
- return MTLPixelFormatRGBA8Unorm;
- case wgpu::TextureFormat::RGBA8UnormSrgb:
- return MTLPixelFormatRGBA8Unorm_sRGB;
- case wgpu::TextureFormat::RGBA8Snorm:
- return MTLPixelFormatRGBA8Snorm;
- case wgpu::TextureFormat::RGBA8Uint:
- return MTLPixelFormatRGBA8Uint;
- case wgpu::TextureFormat::RGBA8Sint:
- return MTLPixelFormatRGBA8Sint;
- case wgpu::TextureFormat::BGRA8Unorm:
- return MTLPixelFormatBGRA8Unorm;
- case wgpu::TextureFormat::BGRA8UnormSrgb:
- return MTLPixelFormatBGRA8Unorm_sRGB;
- case wgpu::TextureFormat::RGB10A2Uint:
- return MTLPixelFormatRGB10A2Uint;
- case wgpu::TextureFormat::RGB10A2Unorm:
- return MTLPixelFormatRGB10A2Unorm;
- case wgpu::TextureFormat::RG11B10Ufloat:
- return MTLPixelFormatRG11B10Float;
- case wgpu::TextureFormat::RGB9E5Ufloat:
- return MTLPixelFormatRGB9E5Float;
-
- case wgpu::TextureFormat::RG32Uint:
- return MTLPixelFormatRG32Uint;
- case wgpu::TextureFormat::RG32Sint:
- return MTLPixelFormatRG32Sint;
- case wgpu::TextureFormat::RG32Float:
- return MTLPixelFormatRG32Float;
- case wgpu::TextureFormat::RGBA16Unorm:
- return MTLPixelFormatRGBA16Unorm;
- case wgpu::TextureFormat::RGBA16Snorm:
- return MTLPixelFormatRGBA16Snorm;
- case wgpu::TextureFormat::RGBA16Uint:
- return MTLPixelFormatRGBA16Uint;
- case wgpu::TextureFormat::RGBA16Sint:
- return MTLPixelFormatRGBA16Sint;
- case wgpu::TextureFormat::RGBA16Float:
- return MTLPixelFormatRGBA16Float;
-
- case wgpu::TextureFormat::RGBA32Uint:
- return MTLPixelFormatRGBA32Uint;
- case wgpu::TextureFormat::RGBA32Sint:
- return MTLPixelFormatRGBA32Sint;
- case wgpu::TextureFormat::RGBA32Float:
- return MTLPixelFormatRGBA32Float;
-
- case wgpu::TextureFormat::Depth32Float:
- return MTLPixelFormatDepth32Float;
- case wgpu::TextureFormat::Depth24Plus:
- return MTLPixelFormatDepth32Float;
- case wgpu::TextureFormat::Depth24PlusStencil8:
- case wgpu::TextureFormat::Depth32FloatStencil8:
- return MTLPixelFormatDepth32Float_Stencil8;
- case wgpu::TextureFormat::Depth16Unorm:
- if (@available(macOS 10.12, iOS 13.0, *)) {
- return MTLPixelFormatDepth16Unorm;
- }
- DAWN_UNREACHABLE();
- case wgpu::TextureFormat::Stencil8:
- if (device->IsToggleEnabled(Toggle::MetalUseCombinedDepthStencilFormatForStencil8)) {
- return MTLPixelFormatDepth32Float_Stencil8;
- }
- return MTLPixelFormatStencil8;
-
-#if DAWN_PLATFORM_IS(MACOS)
- case wgpu::TextureFormat::BC1RGBAUnorm:
- return MTLPixelFormatBC1_RGBA;
- case wgpu::TextureFormat::BC1RGBAUnormSrgb:
- return MTLPixelFormatBC1_RGBA_sRGB;
- case wgpu::TextureFormat::BC2RGBAUnorm:
- return MTLPixelFormatBC2_RGBA;
- case wgpu::TextureFormat::BC2RGBAUnormSrgb:
- return MTLPixelFormatBC2_RGBA_sRGB;
- case wgpu::TextureFormat::BC3RGBAUnorm:
- return MTLPixelFormatBC3_RGBA;
- case wgpu::TextureFormat::BC3RGBAUnormSrgb:
- return MTLPixelFormatBC3_RGBA_sRGB;
- case wgpu::TextureFormat::BC4RSnorm:
- return MTLPixelFormatBC4_RSnorm;
- case wgpu::TextureFormat::BC4RUnorm:
- return MTLPixelFormatBC4_RUnorm;
- case wgpu::TextureFormat::BC5RGSnorm:
- return MTLPixelFormatBC5_RGSnorm;
- case wgpu::TextureFormat::BC5RGUnorm:
- return MTLPixelFormatBC5_RGUnorm;
- case wgpu::TextureFormat::BC6HRGBFloat:
- return MTLPixelFormatBC6H_RGBFloat;
- case wgpu::TextureFormat::BC6HRGBUfloat:
- return MTLPixelFormatBC6H_RGBUfloat;
- case wgpu::TextureFormat::BC7RGBAUnorm:
- return MTLPixelFormatBC7_RGBAUnorm;
- case wgpu::TextureFormat::BC7RGBAUnormSrgb:
- return MTLPixelFormatBC7_RGBAUnorm_sRGB;
-#else
- case wgpu::TextureFormat::BC1RGBAUnorm:
- case wgpu::TextureFormat::BC1RGBAUnormSrgb:
- case wgpu::TextureFormat::BC2RGBAUnorm:
- case wgpu::TextureFormat::BC2RGBAUnormSrgb:
- case wgpu::TextureFormat::BC3RGBAUnorm:
- case wgpu::TextureFormat::BC3RGBAUnormSrgb:
- case wgpu::TextureFormat::BC4RSnorm:
- case wgpu::TextureFormat::BC4RUnorm:
- case wgpu::TextureFormat::BC5RGSnorm:
- case wgpu::TextureFormat::BC5RGUnorm:
- case wgpu::TextureFormat::BC6HRGBFloat:
- case wgpu::TextureFormat::BC6HRGBUfloat:
- case wgpu::TextureFormat::BC7RGBAUnorm:
- case wgpu::TextureFormat::BC7RGBAUnormSrgb:
-#endif
-
- case wgpu::TextureFormat::ETC2RGB8Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatETC2_RGB8;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ETC2RGB8UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatETC2_RGB8_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ETC2RGB8A1Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatETC2_RGB8A1;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatETC2_RGB8A1_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ETC2RGBA8Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatEAC_RGBA8;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ETC2RGBA8UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatEAC_RGBA8_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::EACR11Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatEAC_R11Unorm;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::EACR11Snorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatEAC_R11Snorm;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::EACRG11Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatEAC_RG11Unorm;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::EACRG11Snorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatEAC_RG11Snorm;
- } else {
- DAWN_UNREACHABLE();
- }
-
- case wgpu::TextureFormat::ASTC4x4Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_4x4_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC4x4UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_4x4_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC5x4Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_5x4_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC5x4UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_5x4_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC5x5Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_5x5_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC5x5UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_5x5_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC6x5Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_6x5_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC6x5UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_6x5_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC6x6Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_6x6_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC6x6UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_6x6_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC8x5Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_8x5_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC8x5UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_8x5_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC8x6Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_8x6_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC8x6UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_8x6_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC8x8Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_8x8_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC8x8UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_8x8_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC10x5Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_10x5_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC10x5UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_10x5_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC10x6Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_10x6_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC10x6UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_10x6_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC10x8Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_10x8_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC10x8UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_10x8_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC10x10Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_10x10_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC10x10UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_10x10_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC12x10Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_12x10_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC12x10UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_12x10_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC12x12Unorm:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_12x12_LDR;
- } else {
- DAWN_UNREACHABLE();
- }
- case wgpu::TextureFormat::ASTC12x12UnormSrgb:
- if (@available(macOS 11.0, iOS 8.0, *)) {
- return MTLPixelFormatASTC_12x12_sRGB;
- } else {
- DAWN_UNREACHABLE();
- }
-
- case wgpu::TextureFormat::R8BG8Biplanar420Unorm:
- case wgpu::TextureFormat::R10X6BG10X6Biplanar420Unorm:
- case wgpu::TextureFormat::R8BG8A8Triplanar420Unorm:
- case wgpu::TextureFormat::Undefined:
- DAWN_UNREACHABLE();
- }
-}
-
NSRef<MTLTextureDescriptor> Texture::CreateMetalTextureDescriptor() const {
NSRef<MTLTextureDescriptor> mtlDescRef = AcquireNSRef([MTLTextureDescriptor new]);
MTLTextureDescriptor* mtlDesc = mtlDescRef.Get();
diff --git a/src/dawn/native/metal/UtilsMetal.h b/src/dawn/native/metal/UtilsMetal.h
index 688b2c3..441d0ae 100644
--- a/src/dawn/native/metal/UtilsMetal.h
+++ b/src/dawn/native/metal/UtilsMetal.h
@@ -48,6 +48,8 @@
namespace dawn::native::metal {
+MTLPixelFormat MetalPixelFormat(const DeviceBase* device, wgpu::TextureFormat format);
+
NSRef<NSString> MakeDebugName(DeviceBase* device, const char* prefix, std::string label = "");
// Templating for setting the label on MTL objects because not all MTL objects are of the same base
diff --git a/src/dawn/native/metal/UtilsMetal.mm b/src/dawn/native/metal/UtilsMetal.mm
index 538c22f..69e5523 100644
--- a/src/dawn/native/metal/UtilsMetal.mm
+++ b/src/dawn/native/metal/UtilsMetal.mm
@@ -156,6 +156,401 @@
} // anonymous namespace
+MTLPixelFormat MetalPixelFormat(const DeviceBase* device, wgpu::TextureFormat format) {
+ switch (format) {
+ case wgpu::TextureFormat::R8Unorm:
+ return MTLPixelFormatR8Unorm;
+ case wgpu::TextureFormat::R8Snorm:
+ return MTLPixelFormatR8Snorm;
+ case wgpu::TextureFormat::R8Uint:
+ return MTLPixelFormatR8Uint;
+ case wgpu::TextureFormat::R8Sint:
+ return MTLPixelFormatR8Sint;
+
+ case wgpu::TextureFormat::R16Unorm:
+ return MTLPixelFormatR16Unorm;
+ case wgpu::TextureFormat::R16Snorm:
+ return MTLPixelFormatR16Snorm;
+ case wgpu::TextureFormat::R16Uint:
+ return MTLPixelFormatR16Uint;
+ case wgpu::TextureFormat::R16Sint:
+ return MTLPixelFormatR16Sint;
+ case wgpu::TextureFormat::R16Float:
+ return MTLPixelFormatR16Float;
+ case wgpu::TextureFormat::RG8Unorm:
+ return MTLPixelFormatRG8Unorm;
+ case wgpu::TextureFormat::RG8Snorm:
+ return MTLPixelFormatRG8Snorm;
+ case wgpu::TextureFormat::RG8Uint:
+ return MTLPixelFormatRG8Uint;
+ case wgpu::TextureFormat::RG8Sint:
+ return MTLPixelFormatRG8Sint;
+
+ case wgpu::TextureFormat::R32Uint:
+ return MTLPixelFormatR32Uint;
+ case wgpu::TextureFormat::R32Sint:
+ return MTLPixelFormatR32Sint;
+ case wgpu::TextureFormat::R32Float:
+ return MTLPixelFormatR32Float;
+ case wgpu::TextureFormat::RG16Unorm:
+ return MTLPixelFormatRG16Unorm;
+ case wgpu::TextureFormat::RG16Snorm:
+ return MTLPixelFormatRG16Snorm;
+ case wgpu::TextureFormat::RG16Uint:
+ return MTLPixelFormatRG16Uint;
+ case wgpu::TextureFormat::RG16Sint:
+ return MTLPixelFormatRG16Sint;
+ case wgpu::TextureFormat::RG16Float:
+ return MTLPixelFormatRG16Float;
+ case wgpu::TextureFormat::RGBA8Unorm:
+ return MTLPixelFormatRGBA8Unorm;
+ case wgpu::TextureFormat::RGBA8UnormSrgb:
+ return MTLPixelFormatRGBA8Unorm_sRGB;
+ case wgpu::TextureFormat::RGBA8Snorm:
+ return MTLPixelFormatRGBA8Snorm;
+ case wgpu::TextureFormat::RGBA8Uint:
+ return MTLPixelFormatRGBA8Uint;
+ case wgpu::TextureFormat::RGBA8Sint:
+ return MTLPixelFormatRGBA8Sint;
+ case wgpu::TextureFormat::BGRA8Unorm:
+ return MTLPixelFormatBGRA8Unorm;
+ case wgpu::TextureFormat::BGRA8UnormSrgb:
+ return MTLPixelFormatBGRA8Unorm_sRGB;
+ case wgpu::TextureFormat::RGB10A2Uint:
+ return MTLPixelFormatRGB10A2Uint;
+ case wgpu::TextureFormat::RGB10A2Unorm:
+ return MTLPixelFormatRGB10A2Unorm;
+ case wgpu::TextureFormat::RG11B10Ufloat:
+ return MTLPixelFormatRG11B10Float;
+ case wgpu::TextureFormat::RGB9E5Ufloat:
+ return MTLPixelFormatRGB9E5Float;
+
+ case wgpu::TextureFormat::RG32Uint:
+ return MTLPixelFormatRG32Uint;
+ case wgpu::TextureFormat::RG32Sint:
+ return MTLPixelFormatRG32Sint;
+ case wgpu::TextureFormat::RG32Float:
+ return MTLPixelFormatRG32Float;
+ case wgpu::TextureFormat::RGBA16Unorm:
+ return MTLPixelFormatRGBA16Unorm;
+ case wgpu::TextureFormat::RGBA16Snorm:
+ return MTLPixelFormatRGBA16Snorm;
+ case wgpu::TextureFormat::RGBA16Uint:
+ return MTLPixelFormatRGBA16Uint;
+ case wgpu::TextureFormat::RGBA16Sint:
+ return MTLPixelFormatRGBA16Sint;
+ case wgpu::TextureFormat::RGBA16Float:
+ return MTLPixelFormatRGBA16Float;
+
+ case wgpu::TextureFormat::RGBA32Uint:
+ return MTLPixelFormatRGBA32Uint;
+ case wgpu::TextureFormat::RGBA32Sint:
+ return MTLPixelFormatRGBA32Sint;
+ case wgpu::TextureFormat::RGBA32Float:
+ return MTLPixelFormatRGBA32Float;
+
+ case wgpu::TextureFormat::Depth32Float:
+ return MTLPixelFormatDepth32Float;
+ case wgpu::TextureFormat::Depth24Plus:
+ return MTLPixelFormatDepth32Float;
+ case wgpu::TextureFormat::Depth24PlusStencil8:
+ case wgpu::TextureFormat::Depth32FloatStencil8:
+ return MTLPixelFormatDepth32Float_Stencil8;
+ case wgpu::TextureFormat::Depth16Unorm:
+ if (@available(macOS 10.12, iOS 13.0, *)) {
+ return MTLPixelFormatDepth16Unorm;
+ }
+ DAWN_UNREACHABLE();
+ case wgpu::TextureFormat::Stencil8:
+ if (device->IsToggleEnabled(Toggle::MetalUseCombinedDepthStencilFormatForStencil8)) {
+ return MTLPixelFormatDepth32Float_Stencil8;
+ }
+ return MTLPixelFormatStencil8;
+
+#if DAWN_PLATFORM_IS(MACOS)
+ case wgpu::TextureFormat::BC1RGBAUnorm:
+ return MTLPixelFormatBC1_RGBA;
+ case wgpu::TextureFormat::BC1RGBAUnormSrgb:
+ return MTLPixelFormatBC1_RGBA_sRGB;
+ case wgpu::TextureFormat::BC2RGBAUnorm:
+ return MTLPixelFormatBC2_RGBA;
+ case wgpu::TextureFormat::BC2RGBAUnormSrgb:
+ return MTLPixelFormatBC2_RGBA_sRGB;
+ case wgpu::TextureFormat::BC3RGBAUnorm:
+ return MTLPixelFormatBC3_RGBA;
+ case wgpu::TextureFormat::BC3RGBAUnormSrgb:
+ return MTLPixelFormatBC3_RGBA_sRGB;
+ case wgpu::TextureFormat::BC4RSnorm:
+ return MTLPixelFormatBC4_RSnorm;
+ case wgpu::TextureFormat::BC4RUnorm:
+ return MTLPixelFormatBC4_RUnorm;
+ case wgpu::TextureFormat::BC5RGSnorm:
+ return MTLPixelFormatBC5_RGSnorm;
+ case wgpu::TextureFormat::BC5RGUnorm:
+ return MTLPixelFormatBC5_RGUnorm;
+ case wgpu::TextureFormat::BC6HRGBFloat:
+ return MTLPixelFormatBC6H_RGBFloat;
+ case wgpu::TextureFormat::BC6HRGBUfloat:
+ return MTLPixelFormatBC6H_RGBUfloat;
+ case wgpu::TextureFormat::BC7RGBAUnorm:
+ return MTLPixelFormatBC7_RGBAUnorm;
+ case wgpu::TextureFormat::BC7RGBAUnormSrgb:
+ return MTLPixelFormatBC7_RGBAUnorm_sRGB;
+#else
+ case wgpu::TextureFormat::BC1RGBAUnorm:
+ case wgpu::TextureFormat::BC1RGBAUnormSrgb:
+ case wgpu::TextureFormat::BC2RGBAUnorm:
+ case wgpu::TextureFormat::BC2RGBAUnormSrgb:
+ case wgpu::TextureFormat::BC3RGBAUnorm:
+ case wgpu::TextureFormat::BC3RGBAUnormSrgb:
+ case wgpu::TextureFormat::BC4RSnorm:
+ case wgpu::TextureFormat::BC4RUnorm:
+ case wgpu::TextureFormat::BC5RGSnorm:
+ case wgpu::TextureFormat::BC5RGUnorm:
+ case wgpu::TextureFormat::BC6HRGBFloat:
+ case wgpu::TextureFormat::BC6HRGBUfloat:
+ case wgpu::TextureFormat::BC7RGBAUnorm:
+ case wgpu::TextureFormat::BC7RGBAUnormSrgb:
+#endif
+
+ case wgpu::TextureFormat::ETC2RGB8Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatETC2_RGB8;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ETC2RGB8UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatETC2_RGB8_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ETC2RGB8A1Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatETC2_RGB8A1;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatETC2_RGB8A1_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ETC2RGBA8Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatEAC_RGBA8;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ETC2RGBA8UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatEAC_RGBA8_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::EACR11Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatEAC_R11Unorm;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::EACR11Snorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatEAC_R11Snorm;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::EACRG11Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatEAC_RG11Unorm;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::EACRG11Snorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatEAC_RG11Snorm;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+
+ case wgpu::TextureFormat::ASTC4x4Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_4x4_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC4x4UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_4x4_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC5x4Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_5x4_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC5x4UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_5x4_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC5x5Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_5x5_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC5x5UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_5x5_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC6x5Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_6x5_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC6x5UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_6x5_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC6x6Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_6x6_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC6x6UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_6x6_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC8x5Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_8x5_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC8x5UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_8x5_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC8x6Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_8x6_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC8x6UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_8x6_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC8x8Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_8x8_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC8x8UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_8x8_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC10x5Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_10x5_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC10x5UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_10x5_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC10x6Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_10x6_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC10x6UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_10x6_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC10x8Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_10x8_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC10x8UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_10x8_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC10x10Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_10x10_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC10x10UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_10x10_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC12x10Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_12x10_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC12x10UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_12x10_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC12x12Unorm:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_12x12_LDR;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+ case wgpu::TextureFormat::ASTC12x12UnormSrgb:
+ if (@available(macOS 11.0, iOS 8.0, *)) {
+ return MTLPixelFormatASTC_12x12_sRGB;
+ } else {
+ DAWN_UNREACHABLE();
+ }
+
+ case wgpu::TextureFormat::R8BG8Biplanar420Unorm:
+ case wgpu::TextureFormat::R10X6BG10X6Biplanar420Unorm:
+ case wgpu::TextureFormat::R8BG8A8Triplanar420Unorm:
+ case wgpu::TextureFormat::Undefined:
+ DAWN_UNREACHABLE();
+ }
+}
+
NSRef<NSString> MakeDebugName(DeviceBase* device, const char* prefix, std::string label) {
std::ostringstream objectNameStream;
objectNameStream << prefix;