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 <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2022-03-29 07:58:23 +00:00 committed by Dawn LUCI CQ
parent fc1a2ae904
commit 46d5480d20
2 changed files with 213 additions and 2 deletions

View File

@ -316,11 +316,33 @@ namespace dawn::native::metal {
} }
MaybeError InitializeSupportedFeaturesImpl() override { MaybeError InitializeSupportedFeaturesImpl() override {
// Check compressed texture format with deprecated MTLFeatureSet way.
#if defined(DAWN_PLATFORM_MACOS) #if defined(DAWN_PLATFORM_MACOS)
if ([*mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) { if ([*mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) {
mSupportedFeatures.EnableFeature(Feature::TextureCompressionBC); mSupportedFeatures.EnableFeature(Feature::TextureCompressionBC);
} }
#endif #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 (@available(macOS 10.15, iOS 14.0, *)) {
if (IsGPUCounterSupported( if (IsGPUCounterSupported(

View File

@ -356,48 +356,237 @@ namespace dawn::native::metal {
case wgpu::TextureFormat::BC7RGBAUnormSrgb: case wgpu::TextureFormat::BC7RGBAUnormSrgb:
#endif #endif
case wgpu::TextureFormat::R8BG8Biplanar420Unorm:
case wgpu::TextureFormat::ETC2RGB8Unorm: case wgpu::TextureFormat::ETC2RGB8Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatETC2_RGB8;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ETC2RGB8UnormSrgb: case wgpu::TextureFormat::ETC2RGB8UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatETC2_RGB8_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ETC2RGB8A1Unorm: case wgpu::TextureFormat::ETC2RGB8A1Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatETC2_RGB8A1;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb: case wgpu::TextureFormat::ETC2RGB8A1UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatETC2_RGB8A1_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ETC2RGBA8Unorm: case wgpu::TextureFormat::ETC2RGBA8Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatEAC_RGBA8;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ETC2RGBA8UnormSrgb: case wgpu::TextureFormat::ETC2RGBA8UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatEAC_RGBA8_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::EACR11Unorm: case wgpu::TextureFormat::EACR11Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatEAC_R11Unorm;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::EACR11Snorm: case wgpu::TextureFormat::EACR11Snorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatEAC_R11Snorm;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::EACRG11Unorm: case wgpu::TextureFormat::EACRG11Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatEAC_RG11Unorm;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::EACRG11Snorm: case wgpu::TextureFormat::EACRG11Snorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatEAC_RG11Snorm;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC4x4Unorm: case wgpu::TextureFormat::ASTC4x4Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_4x4_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC4x4UnormSrgb: case wgpu::TextureFormat::ASTC4x4UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_4x4_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC5x4Unorm: case wgpu::TextureFormat::ASTC5x4Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_5x4_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC5x4UnormSrgb: case wgpu::TextureFormat::ASTC5x4UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_5x4_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC5x5Unorm: case wgpu::TextureFormat::ASTC5x5Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_5x5_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC5x5UnormSrgb: case wgpu::TextureFormat::ASTC5x5UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_5x5_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC6x5Unorm: case wgpu::TextureFormat::ASTC6x5Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_6x5_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC6x5UnormSrgb: case wgpu::TextureFormat::ASTC6x5UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_6x5_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC6x6Unorm: case wgpu::TextureFormat::ASTC6x6Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_6x6_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC6x6UnormSrgb: case wgpu::TextureFormat::ASTC6x6UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_6x6_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC8x5Unorm: case wgpu::TextureFormat::ASTC8x5Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_8x5_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC8x5UnormSrgb: case wgpu::TextureFormat::ASTC8x5UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_8x5_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC8x6Unorm: case wgpu::TextureFormat::ASTC8x6Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_8x6_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC8x6UnormSrgb: case wgpu::TextureFormat::ASTC8x6UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_8x6_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC8x8Unorm: case wgpu::TextureFormat::ASTC8x8Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_8x8_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC8x8UnormSrgb: case wgpu::TextureFormat::ASTC8x8UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_8x8_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC10x5Unorm: case wgpu::TextureFormat::ASTC10x5Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_10x5_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC10x5UnormSrgb: case wgpu::TextureFormat::ASTC10x5UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_10x5_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC10x6Unorm: case wgpu::TextureFormat::ASTC10x6Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_10x6_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC10x6UnormSrgb: case wgpu::TextureFormat::ASTC10x6UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_10x6_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC10x8Unorm: case wgpu::TextureFormat::ASTC10x8Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_10x8_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC10x8UnormSrgb: case wgpu::TextureFormat::ASTC10x8UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_10x8_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC10x10Unorm: case wgpu::TextureFormat::ASTC10x10Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_10x10_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC10x10UnormSrgb: case wgpu::TextureFormat::ASTC10x10UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_10x10_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC12x10Unorm: case wgpu::TextureFormat::ASTC12x10Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_12x10_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC12x10UnormSrgb: case wgpu::TextureFormat::ASTC12x10UnormSrgb:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_12x10_sRGB;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC12x12Unorm: case wgpu::TextureFormat::ASTC12x12Unorm:
if (@available(macOS 11.0, iOS 8.0, *)) {
return MTLPixelFormatASTC_12x12_LDR;
} else {
UNREACHABLE();
}
case wgpu::TextureFormat::ASTC12x12UnormSrgb: 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: case wgpu::TextureFormat::Undefined:
UNREACHABLE(); UNREACHABLE();
} }