mesa: Implement GL_EXT_texture_sRGB_RG8 for softpipe and llvmpipe
authorAdam Jackson <ajax@redhat.com>
Tue, 15 Dec 2020 18:49:37 +0000 (13:49 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 4 Jan 2021 21:19:35 +0000 (21:19 +0000)
sRGB_RG8 is not registered for big-GL yet, see this Khronos issue
for updates on that:

https://github.com/KhronosGroup/OpenGL-Registry/issues/450

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8060>

13 files changed:
src/mesa/main/extensions_table.h
src/mesa/main/fbobject.c
src/mesa/main/formats.c
src/mesa/main/formats.csv
src/mesa/main/formats.h
src/mesa/main/glformats.c
src/mesa/main/glheader.h
src/mesa/main/mtypes.h
src/mesa/main/texformat.c
src/mesa/main/textureview.c
src/mesa/state_tracker/st_extensions.c
src/mesa/state_tracker/st_format.c
src/util/format/u_format_tests.c

index 550d5c6..896f2ff 100644 (file)
@@ -323,6 +323,7 @@ EXT(EXT_texture_rectangle                   , NV_texture_rectangle
 EXT(EXT_texture_rg                          , ARB_texture_rg                         ,  x ,  x ,  x , ES2, 2011)
 EXT(EXT_texture_sRGB                        , EXT_texture_sRGB                       , GLL, GLC,  x ,  x , 2004)
 EXT(EXT_texture_sRGB_R8                     , EXT_texture_sRGB_R8                    , GLL ,GLC,  x ,  30, 2015)
+EXT(EXT_texture_sRGB_RG8                    , EXT_texture_sRGB_RG8                   ,  x ,  x ,  x ,  30, 2015)
 EXT(EXT_texture_sRGB_decode                 , EXT_texture_sRGB_decode                , GLL, GLC,  x ,  30, 2006)
 EXT(EXT_texture_shadow_lod                  , EXT_texture_shadow_lod                 , GLL, GLC,  x ,  30, 2018)
 EXT(EXT_texture_shared_exponent             , EXT_texture_shared_exponent            , GLL, GLC,  x ,  x , 2004)
index 66ac9fd..fb3ecac 100644 (file)
@@ -814,6 +814,7 @@ is_format_color_renderable(const struct gl_context *ctx, mesa_format format,
    case GL_RGB10:
    case GL_RGB9_E5:
    case GL_SR8_EXT:
+   case GL_SRG8_EXT:
       return GL_FALSE;
    default:
       break;
index 0bca52f..ffb0408 100644 (file)
@@ -1129,6 +1129,7 @@ _mesa_uncompressed_format_to_type_and_comps(mesa_format format,
       *comps = 1;
       return;
    case MESA_FORMAT_LA_SRGB8:
+   case MESA_FORMAT_RG_SRGB8:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 2;
       return;
index 6fc787c..e2b54e9 100644 (file)
@@ -151,6 +151,7 @@ MESA_FORMAT_X8B8G8R8_SRGB                 , packed, 1, 1, 1, x8  , un8 , un8 , u
 # Array sRGB formats
 MESA_FORMAT_R_SRGB8                       , array , 1, 1, 1, un8 ,     ,     ,     , x001, srgb
 MESA_FORMAT_L_SRGB8                       , array , 1, 1, 1, un8 ,     ,     ,     , xxx1, srgb
+MESA_FORMAT_RG_SRGB8                      , array , 1, 1, 1, un8 , un8 ,     ,     , xy01, srgb
 MESA_FORMAT_LA_SRGB8                      , array , 1, 1, 1, un8 , un8 ,     ,     , xxxy, srgb
 MESA_FORMAT_BGR_SRGB8                     , array , 1, 1, 1, un8 , un8 , un8 ,     , zyx1, srgb
 
index f0e58b3..29c1308 100644 (file)
@@ -432,6 +432,7 @@ typedef enum pipe_format mesa_format;
 #define MESA_FORMAT_R8G8B8X8_SRGB                PIPE_FORMAT_RGBX8888_SRGB
 #define MESA_FORMAT_X8B8G8R8_SRGB                PIPE_FORMAT_XBGR8888_SRGB
 #define MESA_FORMAT_R_SRGB8                      PIPE_FORMAT_R8_SRGB
+#define MESA_FORMAT_RG_SRGB8                     PIPE_FORMAT_R8G8_SRGB
 #define MESA_FORMAT_L_SRGB8                      PIPE_FORMAT_L8_SRGB
 #define MESA_FORMAT_LA_SRGB8                     PIPE_FORMAT_L8A8_SRGB
 #define MESA_FORMAT_BGR_SRGB8                    PIPE_FORMAT_R8G8B8_SRGB
index 897d0ff..34f9307 100644 (file)
@@ -2511,6 +2511,15 @@ _mesa_base_tex_format(const struct gl_context *ctx, GLint internalFormat)
       }
    }
 
+   if (_mesa_has_EXT_texture_sRGB_RG8(ctx)) {
+      switch (internalFormat) {
+      case GL_SRG8_EXT:
+         return GL_RG;
+      default:
+         ; /* fallthrough */
+      }
+   }
+
    if (_mesa_has_integer_textures(ctx)) {
       switch (internalFormat) {
       case GL_RGBA8UI_EXT:
@@ -3157,11 +3166,13 @@ _mesa_gles_error_check_format_and_type(const struct gl_context *ctx,
          return GL_INVALID_OPERATION;
       switch (type) {
       case GL_UNSIGNED_BYTE:
-         if (internalFormat != GL_RG8 &&
-             (!_mesa_has_EXT_texture_compression_rgtc(ctx) ||
-              internalFormat != GL_COMPRESSED_RED_GREEN_RGTC2_EXT))
-            return GL_INVALID_OPERATION;
-         break;
+         if (internalFormat == GL_RG8 ||
+             (_mesa_has_EXT_texture_compression_rgtc(ctx) &&
+              internalFormat == GL_COMPRESSED_RED_GREEN_RGTC2_EXT) ||
+             (_mesa_has_EXT_texture_sRGB_RG8(ctx) &&
+              internalFormat == GL_SRG8_EXT))
+            break;
+         return GL_INVALID_OPERATION;
 
       case GL_BYTE:
          if (internalFormat != GL_RG8_SNORM &&
index a7818d6..12c9b94 100644 (file)
@@ -138,6 +138,10 @@ typedef int GLclampx;
 #define GL_SR8_EXT                                              0x8FBD
 #endif
 
+#ifndef GL_EXT_texture_sRGB_RG8
+#define GL_SRG8_EXT                                             0x8FBE
+#endif
+
 #ifndef GL_AMD_compressed_ATC_texture
 #define GL_ATC_RGB_AMD                                          0x8C92
 #define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD                          0x8C93
index d847e27..70e7b21 100644 (file)
@@ -4437,6 +4437,7 @@ struct gl_extensions
    GLboolean EXT_texture_snorm;
    GLboolean EXT_texture_sRGB;
    GLboolean EXT_texture_sRGB_R8;
+   GLboolean EXT_texture_sRGB_RG8;
    GLboolean EXT_texture_sRGB_decode;
    GLboolean EXT_texture_swizzle;
    GLboolean EXT_texture_type_2_10_10_10_REV;
index 1c91223..bf46b66 100644 (file)
@@ -479,6 +479,9 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
    case GL_SR8_EXT:
       RETURN_IF_SUPPORTED(MESA_FORMAT_R_SRGB8);
       break;
+   case GL_SRG8_EXT:
+      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SRGB8);
+      break;
    case GL_SLUMINANCE_EXT:
    case GL_SLUMINANCE8_EXT:
       RETURN_IF_SUPPORTED(MESA_FORMAT_L_SRGB8);
index 5d9bc81..2986afb 100644 (file)
@@ -169,6 +169,7 @@ static const struct internal_format_class_info compatible_internal_formats[] = {
    {GL_VIEW_CLASS_16_BITS, GL_RG8},
    {GL_VIEW_CLASS_16_BITS, GL_R16},
    {GL_VIEW_CLASS_16_BITS, GL_RG8_SNORM},
+   {GL_VIEW_CLASS_16_BITS, GL_SRG8_EXT},
    {GL_VIEW_CLASS_16_BITS, GL_R16_SNORM},
    {GL_VIEW_CLASS_8_BITS, GL_R8UI},
    {GL_VIEW_CLASS_8_BITS, GL_R8I},
index e60f7c5..0557201 100644 (file)
@@ -982,6 +982,9 @@ void st_init_extensions(struct pipe_screen *screen,
       { { o(EXT_texture_sRGB_R8) },
         { PIPE_FORMAT_R8_SRGB }, },
 
+      { { o(EXT_texture_sRGB_RG8) },
+        { PIPE_FORMAT_R8G8_SRGB }, },
+
       { { o(EXT_texture_type_2_10_10_10_REV) },
         { PIPE_FORMAT_R10G10B10A2_UNORM,
           PIPE_FORMAT_B10G10R10A2_UNORM },
index 1c92731..cc56210 100644 (file)
@@ -427,6 +427,10 @@ static const struct format_mapping format_map[] = {
       { GL_SR8_EXT, 0 },
       { PIPE_FORMAT_R8_SRGB, 0 }
    },
+   {
+      { GL_SRG8_EXT, 0 },
+      { PIPE_FORMAT_R8G8_SRGB, 0 }
+   },
 
    /* 16-bit float formats */
    {
index 0cc4de8..487b4b8 100644 (file)
@@ -240,6 +240,10 @@ util_format_test_cases[] =
    {PIPE_FORMAT_R8_SRGB, PACKED_1x8(0xff), PACKED_1x8(0xbc), UNPACKED_1x1(0.502886458033, 0.0, 0.0, 1.0)},
    {PIPE_FORMAT_R8_SRGB, PACKED_1x8(0xff), PACKED_1x8(0xff), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)},
 
+   {PIPE_FORMAT_R8G8_SRGB, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)},
+   {PIPE_FORMAT_R8G8_SRGB, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xbc, 0xbc), UNPACKED_1x1(0.502886458033, 0.502886458033, 0.0, 1.0)},
+   {PIPE_FORMAT_R8G8_SRGB, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), UNPACKED_1x1(1.0, 1.0, 0.0, 1.0)},
+
    {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)},
    {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0x00bc), UNPACKED_1x1(0.502886458033, 0.502886458033, 0.502886458033, 0.0)},
    {PIPE_FORMAT_L8A8_SRGB, PACKED_1x16(0xffff), PACKED_1x16(0x00ff), UNPACKED_1x1(1.0, 1.0, 1.0, 0.0)},