From 46d5480d20b08e6f3b70174ec0344443123c14a5 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Tue, 29 Mar 2022 07:58:23 +0000 Subject: [PATCH] Metal: Add ASTC and ETC2 texture compression support. Fixed: dawn:1176 Change-Id: I7655ef98151a1bb78d23be0357a68cdd90e5078a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/84481 Auto-Submit: Corentin Wallez Reviewed-by: Austin Eng Reviewed-by: Loko Kung Commit-Queue: Corentin Wallez --- src/dawn/native/metal/BackendMTL.mm | 22 ++++ src/dawn/native/metal/TextureMTL.mm | 193 +++++++++++++++++++++++++++- 2 files changed, 213 insertions(+), 2 deletions(-) diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm index 1f75adb6f0..6f4751f08c 100644 --- a/src/dawn/native/metal/BackendMTL.mm +++ b/src/dawn/native/metal/BackendMTL.mm @@ -316,11 +316,33 @@ namespace dawn::native::metal { } MaybeError InitializeSupportedFeaturesImpl() override { + // Check compressed texture format with deprecated MTLFeatureSet way. #if defined(DAWN_PLATFORM_MACOS) if ([*mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) { mSupportedFeatures.EnableFeature(Feature::TextureCompressionBC); } #endif +#if defined(DAWN_PLATFORM_IOS) + if ([*mDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v1]) { + mSupportedFeatures.EnableFeature(Feature::TextureCompressionETC2); + } + if ([*mDevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v1]) { + mSupportedFeatures.EnableFeature(Feature::TextureCompressionASTC); + } +#endif + + // Check compressed texture format with MTLGPUFamily + if (@available(macOS 10.15, iOS 13.0, *)) { + if ([*mDevice supportsFamily:MTLGPUFamilyMac1]) { + mSupportedFeatures.EnableFeature(Feature::TextureCompressionBC); + } + if ([*mDevice supportsFamily:MTLGPUFamilyApple2]) { + mSupportedFeatures.EnableFeature(Feature::TextureCompressionETC2); + } + if ([*mDevice supportsFamily:MTLGPUFamilyApple3]) { + mSupportedFeatures.EnableFeature(Feature::TextureCompressionASTC); + } + } if (@available(macOS 10.15, iOS 14.0, *)) { if (IsGPUCounterSupported( diff --git a/src/dawn/native/metal/TextureMTL.mm b/src/dawn/native/metal/TextureMTL.mm index da5755a691..d75510a892 100644 --- a/src/dawn/native/metal/TextureMTL.mm +++ b/src/dawn/native/metal/TextureMTL.mm @@ -356,48 +356,237 @@ namespace dawn::native::metal { case wgpu::TextureFormat::BC7RGBAUnormSrgb: #endif - case wgpu::TextureFormat::R8BG8Biplanar420Unorm: - case wgpu::TextureFormat::ETC2RGB8Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatETC2_RGB8; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ETC2RGB8UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatETC2_RGB8_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ETC2RGB8A1Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatETC2_RGB8A1; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatETC2_RGB8A1_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ETC2RGBA8Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatEAC_RGBA8; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ETC2RGBA8UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatEAC_RGBA8_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::EACR11Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatEAC_R11Unorm; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::EACR11Snorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatEAC_R11Snorm; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::EACRG11Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatEAC_RG11Unorm; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::EACRG11Snorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatEAC_RG11Snorm; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC4x4Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_4x4_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC4x4UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_4x4_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC5x4Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_5x4_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC5x4UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_5x4_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC5x5Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_5x5_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC5x5UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_5x5_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC6x5Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_6x5_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC6x5UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_6x5_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC6x6Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_6x6_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC6x6UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_6x6_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC8x5Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_8x5_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC8x5UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_8x5_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC8x6Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_8x6_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC8x6UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_8x6_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC8x8Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_8x8_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC8x8UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_8x8_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC10x5Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_10x5_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC10x5UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_10x5_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC10x6Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_10x6_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC10x6UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_10x6_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC10x8Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_10x8_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC10x8UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_10x8_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC10x10Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_10x10_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC10x10UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_10x10_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC12x10Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_12x10_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC12x10UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_12x10_sRGB; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC12x12Unorm: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_12x12_LDR; + } else { + UNREACHABLE(); + } case wgpu::TextureFormat::ASTC12x12UnormSrgb: + if (@available(macOS 11.0, iOS 8.0, *)) { + return MTLPixelFormatASTC_12x12_sRGB; + } else { + UNREACHABLE(); + } + case wgpu::TextureFormat::R8BG8Biplanar420Unorm: case wgpu::TextureFormat::Undefined: UNREACHABLE(); }