Commit ffd80394 by Alexey Knyazev Committed by Commit Bot

Metal: Enable iOS pixel formats on macOS 11

Bug: angleproject:2634, angleproject:5672 Change-Id: Idd1cc325067e73b02f4f82b2d78d20420e50645b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2739729 Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 6073af53
......@@ -4,9 +4,9 @@
"src/libANGLE/renderer/angle_format_map.json":
"ae32dfce450f7b7ffc62d746d6fddf83",
"src/libANGLE/renderer/metal/gen_mtl_format_table.py":
"5e3a7d6e95784fa0276e4b689c01cdec",
"ee0b5db245a6672b86b122426a16d395",
"src/libANGLE/renderer/metal/mtl_format_map.json":
"07db91c8be19afe687f77eb42998f3c9",
"848c1e2f6d76115e3d0499346b5684d5",
"src/libANGLE/renderer/metal/mtl_format_table_autogen.mm":
"76ef6391067b5e5ac6be19a11db21e49"
"7765df9be304bf08d1c1c510c7b171ac"
}
\ No newline at end of file
......@@ -712,6 +712,18 @@ void DisplayMtl::initializeTextureCaps() const
// Re-verify texture extensions.
mNativeExtensions.setTextureExtensionSupport(mNativeTextureCaps);
// Enable ANGLE-specific ETC2/EAC extension that is not set by the call above.
if (supportsAppleGPUFamily(1) && gl::DetermineCompressedTextureETCSupport(mNativeTextureCaps))
{
mNativeExtensions.compressedTextureETC = true;
}
// Enable ASTC sliced 3D, requires MTLGPUFamilyApple3
if (supportsAppleGPUFamily(3) && mNativeExtensions.textureCompressionASTCLDRKHR)
{
mNativeExtensions.textureCompressionSliced3dASTCKHR = true;
}
// Disable all depth buffer and stencil buffer readback extensions until we need them
mNativeExtensions.readDepthNV = false;
mNativeExtensions.readStencilNV = false;
......
......@@ -94,8 +94,7 @@ image_format_assign_template1 = """
"""
image_format_assign_template2 = """
if (metalDevice.depth24Stencil8PixelFormatSupported &&
!display->getFeatures().forceD24S8AsUnsupported.enabled)
if ({fallback_condition})
{{
this->metalFormat = {mtl_format};
this->actualFormatId = angle::FormatID::{actual_angle_format};
......@@ -287,7 +286,9 @@ def gen_image_map_switch_mac_case(angle_format, actual_angle_format_info, angle_
actual_angle_format_fallback=actual_angle_format_fallback,
mtl_format_fallback=angle_to_mtl_map[actual_angle_format_fallback],
init_function_fallback=angle_format_utils.get_internal_format_initializer(
gl_format, actual_angle_format_fallback))
gl_format, actual_angle_format_fallback),
fallback_condition="metalDevice.depth24Stencil8PixelFormatSupported && \
!display->getFeatures().forceD24S8AsUnsupported.enabled")
else:
# return ordinary block:
return image_format_assign_template1.format(
......@@ -300,9 +301,32 @@ def gen_image_map_switch_mac_case(angle_format, actual_angle_format_info, angle_
gen_format_assign_code)
# Generate format conversion switch case (non-desktop ES 3.0 case)
def gen_image_map_switch_es3_case(angle_format, actual_angle_format_info, angle_to_gl,
angle_to_mtl_map, mac_fallbacks):
gl_format = angle_to_gl[angle_format]
def gen_format_assign_code(actual_angle_format, angle_to_mtl_map):
actual_angle_format_fallback = mac_fallbacks[actual_angle_format]
return image_format_assign_template2.format(
actual_angle_format=actual_angle_format,
mtl_format=angle_to_mtl_map[actual_angle_format],
init_function=angle_format_utils.get_internal_format_initializer(
gl_format, actual_angle_format),
actual_angle_format_fallback=actual_angle_format_fallback,
mtl_format_fallback=angle_to_mtl_map[actual_angle_format_fallback],
init_function_fallback=angle_format_utils.get_internal_format_initializer(
gl_format, actual_angle_format_fallback),
fallback_condition="display->supportsAppleGPUFamily(1)")
return gen_image_map_switch_case(angle_format, actual_angle_format_info, angle_to_mtl_map,
gen_format_assign_code)
def gen_image_map_switch_string(image_table, angle_to_gl):
angle_override = image_table["override"]
mac_override = image_table["override_mac"]
mac_override_es3 = image_table["override_mac_es3"]
mac_override_bc1 = image_table["override_mac_bc1"]
ios_override = image_table["override_ios"]
mac_fallbacks = image_table["d24s8_fallbacks_mac"]
angle_to_mtl = image_table["map"]
......@@ -319,45 +343,56 @@ def gen_image_map_switch_string(image_table, angle_to_gl):
switch_data = ''
def gen_image_map_switch_common_case(angle_format, actual_angle_format):
mac_case = gen_image_map_switch_mac_case(angle_format, actual_angle_format, angle_to_gl,
mac_angle_to_mtl, mac_fallbacks)
non_mac_case = gen_image_map_switch_simple_case(angle_format, actual_angle_format,
angle_to_gl, angle_to_mtl)
if mac_case == non_mac_case:
return mac_case
re = ''
re += "#if TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
re += mac_case
re += "#else // TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
re += non_mac_case
re += "#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
return re
# Common case
return gen_image_map_switch_simple_case(angle_format, actual_angle_format, angle_to_gl,
angle_to_mtl)
# Common case: universally-supported formats + universal overrides
for angle_format in sorted(angle_to_mtl.keys()):
switch_data += gen_image_map_switch_common_case(angle_format, angle_format)
for angle_format in sorted(angle_override.keys()):
switch_data += gen_image_map_switch_common_case(angle_format, angle_override[angle_format])
# Mac specific
# Mac GPU case: macOS + Catalyst targets
switch_data += "#if TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
for angle_format in sorted(mac_specific_map.keys()):
switch_data += gen_image_map_switch_mac_case(angle_format, angle_format, angle_to_gl,
mac_angle_to_mtl, mac_fallbacks)
for angle_format in sorted(mac_override.keys()):
switch_data += gen_image_map_switch_mac_case(angle_format, mac_override[angle_format],
for angle_format in sorted(mac_override_bc1.keys()):
switch_data += gen_image_map_switch_mac_case(angle_format, mac_override_bc1[angle_format],
angle_to_gl, mac_angle_to_mtl, mac_fallbacks)
switch_data += "#endif\n"
# Override missing ES 3.0 formats for older macOS SDK or Catalyst
switch_data += "#if (TARGET_OS_OSX && (__MAC_OS_X_VERSION_MAX_ALLOWED < 101600)) || \\\n"
switch_data += "TARGET_OS_MACCATALYST\n"
for angle_format in sorted(mac_override_es3.keys()):
switch_data += gen_image_map_switch_mac_case(angle_format, mac_override_es3[angle_format],
angle_to_gl, mac_angle_to_mtl, mac_fallbacks)
switch_data += "#endif\n"
# iOS specific
switch_data += "#elif TARGET_OS_IOS || TARGET_OS_TV // TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
switch_data += "#if TARGET_OS_IOS || TARGET_OS_TV\n"
for angle_format in sorted(ios_specific_map.keys()):
switch_data += gen_image_map_switch_simple_case(angle_format, angle_format, angle_to_gl,
ios_specific_map)
for angle_format in sorted(ios_override.keys()):
switch_data += gen_image_map_switch_simple_case(angle_format, ios_override[angle_format],
angle_to_gl, ios_angle_to_mtl)
switch_data += "#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
switch_data += "#endif\n"
# Try to support all iOS formats on newer macOS with Apple GPU.
switch_data += "#if (TARGET_OS_OSX && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600))\n"
for angle_format in sorted(ios_specific_map.keys()):
if (angle_format in mac_override_es3.keys()):
# ETC/EAC or packed 16-bit
switch_data += gen_image_map_switch_es3_case(angle_format, angle_format, angle_to_gl,
ios_angle_to_mtl, mac_override_es3)
else:
# ASTC or PVRTC1
switch_data += gen_image_map_switch_simple_case(angle_format, angle_format,
angle_to_gl, ios_specific_map)
switch_data += "#endif\n"
switch_data += " default:\n"
switch_data += " this->metalFormat = MTLPixelFormatInvalid;\n"
switch_data += " this->actualFormatId = angle::FormatID::NONE;"
......@@ -454,11 +489,14 @@ def gen_mtl_format_caps_init_string(map_image):
caps_init_str += "#if TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
caps_init_str += caps_to_cpp(mac_caps)
caps_init_str += "#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
caps_init_str += "#if (TARGET_OS_IOS && !TARGET_OS_MACCATALYST) || TARGET_OS_TV || \\\n"
caps_init_str += " (TARGET_OS_OSX && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600))\n"
caps_init_str += "#elif TARGET_OS_IOS || TARGET_OS_TV // TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
caps_init_str += caps_to_cpp(ios_caps)
caps_init_str += "#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST\n"
caps_init_str += "#endif\n"
return caps_init_str
......@@ -471,9 +509,9 @@ def main():
outputs = ['mtl_format_table_autogen.mm']
if sys.argv[1] == 'inputs':
print ','.join(inputs)
print(','.join(inputs))
elif sys.argv[1] == 'outputs':
print ','.join(outputs)
print(','.join(outputs))
else:
print('Invalid script parameters')
return 1
......
......@@ -172,7 +172,7 @@ constexpr size_t kOcclusionQueryResultSize = sizeof(uint64_t);
constexpr gl::Version kMaxSupportedGLVersion = gl::Version(3, 0);
// Work-around the enum is not available on macOS
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#if (TARGET_OS_OSX && (__MAC_OS_X_VERSION_MAX_ALLOWED < 101600)) || TARGET_OS_MACCATALYST
constexpr MTLBlitOption kBlitOptionRowLinearPVRTC = MTLBlitOptionNone;
#else
constexpr MTLBlitOption kBlitOptionRowLinearPVRTC = MTLBlitOptionRowLinearPVRTC;
......
......@@ -92,6 +92,7 @@
"PVRTC1_RGB_4BPP_UNORM_SRGB_BLOCK": "MTLPixelFormatPVRTC_RGB_4BPP_sRGB",
"PVRTC1_RGBA_2BPP_UNORM_SRGB_BLOCK": "MTLPixelFormatPVRTC_RGBA_2BPP_sRGB",
"PVRTC1_RGBA_4BPP_UNORM_SRGB_BLOCK": "MTLPixelFormatPVRTC_RGBA_4BPP_sRGB",
"ETC1_R8G8B8_UNORM_BLOCK": "MTLPixelFormatETC2_RGB8",
"ETC2_R8G8B8_UNORM_BLOCK": "MTLPixelFormatETC2_RGB8",
"ETC2_R8G8B8_SRGB_BLOCK": "MTLPixelFormatETC2_RGB8_sRGB",
"ETC2_R8G8B8A1_UNORM_BLOCK": "MTLPixelFormatETC2_RGB8A1",
......@@ -176,13 +177,9 @@
},
"override_ios": {
"D24_UNORM_S8_UINT": "D32_FLOAT_S8X24_UINT",
"D16_UNORM": "D32_FLOAT",
"ETC1_R8G8B8_UNORM_BLOCK": "ETC2_R8G8B8_UNORM_BLOCK"
"D16_UNORM": "D32_FLOAT"
},
"override_mac": {
"R5G6B5_UNORM": "R8G8B8A8_UNORM",
"R5G5B5A1_UNORM": "R8G8B8A8_UNORM",
"R4G4B4A4_UNORM": "R8G8B8A8_UNORM",
"override_mac_bc1": {
"BC1_RGB_UNORM_BLOCK": {
"default": "BC1_RGBA_UNORM_BLOCK",
"swizzle": ["RGB1", "BC1_RGBA_UNORM_BLOCK"]
......@@ -190,7 +187,12 @@
"BC1_RGB_UNORM_SRGB_BLOCK": {
"default": "BC1_RGBA_UNORM_SRGB_BLOCK",
"swizzle": ["RGB1", "BC1_RGBA_UNORM_SRGB_BLOCK"]
},
}
},
"override_mac_es3": {
"R5G6B5_UNORM": "R8G8B8A8_UNORM",
"R5G5B5A1_UNORM": "R8G8B8A8_UNORM",
"R4G4B4A4_UNORM": "R8G8B8A8_UNORM",
"ETC1_R8G8B8_UNORM_BLOCK": "R8G8B8A8_UNORM",
"ETC2_R8G8B8_UNORM_BLOCK": "R8G8B8A8_UNORM",
"ETC2_R8G8B8_SRGB_BLOCK": "R8G8B8A8_UNORM_SRGB",
......@@ -659,90 +661,90 @@
},
"caps_ios": {
"MTLPixelFormatB5G6R5Unorm":{
"filterable": "true",
"filterable": "display->supportsAppleGPUFamily(1)",
"writable": "false",
"blendable": "true",
"multisample": "true",
"resolve": "true",
"colorRenderable": "true"
"blendable": "display->supportsAppleGPUFamily(1)",
"multisample": "display->supportsAppleGPUFamily(1)",
"resolve": "display->supportsAppleGPUFamily(1)",
"colorRenderable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatABGR4Unorm":{
"filterable": "true",
"filterable": "display->supportsAppleGPUFamily(1)",
"writable": "false",
"blendable": "true",
"multisample": "true",
"resolve": "true",
"colorRenderable": "true"
"blendable": "display->supportsAppleGPUFamily(1)",
"multisample": "display->supportsAppleGPUFamily(1)",
"resolve": "display->supportsAppleGPUFamily(1)",
"colorRenderable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatBGR5A1Unorm":{
"filterable": "true",
"filterable": "display->supportsAppleGPUFamily(1)",
"writable": "false",
"blendable": "true",
"multisample": "true",
"resolve": "true",
"colorRenderable": "true"
"blendable": "display->supportsAppleGPUFamily(1)",
"multisample": "display->supportsAppleGPUFamily(1)",
"resolve": "display->supportsAppleGPUFamily(1)",
"colorRenderable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatA1BGR5Unorm":{
"filterable": "true",
"filterable": "display->supportsAppleGPUFamily(1)",
"writable": "false",
"blendable": "true",
"multisample": "true",
"resolve": "true",
"colorRenderable": "true"
"blendable": "display->supportsAppleGPUFamily(1)",
"multisample": "display->supportsAppleGPUFamily(1)",
"resolve": "display->supportsAppleGPUFamily(1)",
"colorRenderable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatPVRTC_RGB_4BPP":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatPVRTC_RGB_2BPP":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatPVRTC_RGBA_4BPP":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatPVRTC_RGBA_2BPP":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatPVRTC_RGB_2BPP_sRGB":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatPVRTC_RGB_4BPP_sRGB":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatPVRTC_RGBA_2BPP_sRGB":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatPVRTC_RGBA_4BPP_sRGB":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatETC2_RGB8":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatETC2_RGB8_sRGB":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatETC2_RGB8A1":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatETC2_RGB8A1_sRGB":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatEAC_RGBA8":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatEAC_RGBA8_sRGB":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatEAC_R11Unorm":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatEAC_R11Snorm":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatEAC_RG11Unorm":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatEAC_RG11Snorm":{
"filterable": "true"
"filterable": "display->supportsAppleGPUFamily(1)"
},
"MTLPixelFormatASTC_4x4_LDR":{
"filterable": "display->supportsAppleGPUFamily(2)"
......
......@@ -161,7 +161,8 @@ bool Format::isPVRTC() const
{
switch (metalFormat)
{
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
#if (TARGET_OS_IOS && !TARGET_OS_MACCATALYST) || \
(TARGET_OS_OSX && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600))
case MTLPixelFormatPVRTC_RGB_2BPP:
case MTLPixelFormatPVRTC_RGB_2BPP_sRGB:
case MTLPixelFormatPVRTC_RGB_4BPP:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment