From 9e774041f84302523b43d5ab3ce6bd929d2bd722 Mon Sep 17 00:00:00 2001 From: Alexey Knyazev Date: Fri, 31 Jan 2020 15:09:01 +0400 Subject: [PATCH] Update S3TC GL extension strings Added avoid_dxt1_srgb_texture_format workaround Bug: angleproject:4266 Change-Id: I286a9c66f6ea1d2c9d3587f6ca85608336eb44a6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2033065 Reviewed-by: Jamie Madill Reviewed-by: Jonah Ryan-Davis Commit-Queue: Jamie Madill --- include/platform/FeaturesGL.h | 8 ++++++ src/libANGLE/renderer/gl/formatutilsgl.cpp | 26 +++++++++++++++---- src/libANGLE/renderer/gl/renderergl_utils.cpp | 3 +++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/platform/FeaturesGL.h b/include/platform/FeaturesGL.h index e7403722c..b1e214635 100644 --- a/include/platform/FeaturesGL.h +++ b/include/platform/FeaturesGL.h @@ -411,6 +411,14 @@ struct FeaturesGL : FeatureSetBase "rewrite_row_major_matrices", FeatureCategory::OpenGLWorkarounds, "Rewrite row major matrices in shaders as column major as a driver bug workaround", &members, "http://anglebug.com/2273"}; + + // Bugs exist in various OpenGL Intel drivers on Windows that produce incorrect + // values for GL_COMPRESSED_SRGB_S3TC_DXT1_EXT format. Replace it with + // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT as it's the closest option allowed by + // the WebGL extension spec. + Feature avoidDXT1sRGBTextureFormat = { + "avoid_dxt1_srgb_texture_format", FeatureCategory::OpenGLWorkarounds, + "Replaces DXT1 sRGB with DXT1 sRGB Alpha as a driver bug workaround.", &members}; }; inline FeaturesGL::FeaturesGL() = default; diff --git a/src/libANGLE/renderer/gl/formatutilsgl.cpp b/src/libANGLE/renderer/gl/formatutilsgl.cpp index d43522836..85bfafa6d 100644 --- a/src/libANGLE/renderer/gl/formatutilsgl.cpp +++ b/src/libANGLE/renderer/gl/formatutilsgl.cpp @@ -307,15 +307,22 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap() InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_ETC2_sRGB8_alpha8_texture"), AlwaysSupported(), NeverSupported(), NeverSupported() ); // From GL_EXT_texture_compression_dxt1 - // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support | - InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_dxt1"), AlwaysSupported(), NeverSupported(), NeverSupported() ); - InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_dxt1"), AlwaysSupported(), NeverSupported(), NeverSupported() ); + // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support | + InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_dxt1", "GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), NeverSupported() ); + InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_dxt1", "GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), NeverSupported() ); // From GL_ANGLE_texture_compression_dxt3 - InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, ExtsOnly("GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_ANGLE_texture_compression_dxt3"), AlwaysSupported(), NeverSupported(), NeverSupported() ); + InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, ExtsOnly("GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_ANGLE_texture_compression_dxt3", "GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), NeverSupported() ); // From GL_ANGLE_texture_compression_dxt5 - InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, ExtsOnly("GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_ANGLE_texture_compression_dxt5"), AlwaysSupported(), NeverSupported(), NeverSupported() ); + InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, ExtsOnly("GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_ANGLE_texture_compression_dxt5", "GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(), NeverSupported() ); + + // From GL_EXT_texture_compression_s3tc_srgb + // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support | + InsertFormatMapping(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc GL_EXT_texture_sRGB"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_s3tc GL_NV_sRGB_formats"), AlwaysSupported(), NeverSupported(), NeverSupported() ); + InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc GL_EXT_texture_sRGB"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_s3tc GL_NV_sRGB_formats"), AlwaysSupported(), NeverSupported(), NeverSupported() ); + InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc GL_EXT_texture_sRGB"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_s3tc GL_NV_sRGB_formats"), AlwaysSupported(), NeverSupported(), NeverSupported() ); + InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc GL_EXT_texture_sRGB"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_s3tc GL_NV_sRGB_formats"), AlwaysSupported(), NeverSupported(), NeverSupported() ); // From GL_OES_compressed_ETC1_RGB8_texture InsertFormatMapping(&map, GL_ETC1_RGB8_OES, VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "GL_OES_compressed_ETC1_RGB8_texture"), AlwaysSupported(), NeverSupported(), NeverSupported() ); @@ -583,6 +590,15 @@ static GLenum GetNativeCompressedFormat(const FunctionsGL *functions, } } + if (features.avoidDXT1sRGBTextureFormat.enabled) + { + if (format == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT) + { + // Pass GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT instead to workaround driver bug. + result = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; + } + } + return result; } diff --git a/src/libANGLE/renderer/gl/renderergl_utils.cpp b/src/libANGLE/renderer/gl/renderergl_utils.cpp index 57c7ddfcc..d2f223cfc 100644 --- a/src/libANGLE/renderer/gl/renderergl_utils.cpp +++ b/src/libANGLE/renderer/gl/renderergl_utils.cpp @@ -1649,6 +1649,9 @@ void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *feature // IsApple() && functions->standard == STANDARD_GL_DESKTOP); // TODO(anglebug.com/2273): diagnose crashes with this workaround. false); + + // Workaround for incorrect sampling from DXT1 sRGB textures in Intel OpenGL on Windows. + ANGLE_FEATURE_CONDITION(features, avoidDXT1sRGBTextureFormat, IsWindows() && isIntel); } void InitializeFrontendFeatures(const FunctionsGL *functions, angle::FrontendFeatures *features)