Mesa (master): mesa: Implement GL_EXT_texture_sRGB_RG8 for softpipe and llvmpipe

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 4 21:37:45 UTC 2021


Module: Mesa
Branch: master
Commit: dd05cbf5e07736f7597722a935cf6127ea2fa628
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=dd05cbf5e07736f7597722a935cf6127ea2fa628

Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 15 13:49:37 2020 -0500

mesa: Implement GL_EXT_texture_sRGB_RG8 for softpipe and llvmpipe

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 at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8060>

---

 src/mesa/main/extensions_table.h       |  1 +
 src/mesa/main/fbobject.c               |  1 +
 src/mesa/main/formats.c                |  1 +
 src/mesa/main/formats.csv              |  1 +
 src/mesa/main/formats.h                |  1 +
 src/mesa/main/glformats.c              | 21 ++++++++++++++++-----
 src/mesa/main/glheader.h               |  4 ++++
 src/mesa/main/mtypes.h                 |  1 +
 src/mesa/main/texformat.c              |  3 +++
 src/mesa/main/textureview.c            |  1 +
 src/mesa/state_tracker/st_extensions.c |  3 +++
 src/mesa/state_tracker/st_format.c     |  4 ++++
 src/util/format/u_format_tests.c       |  4 ++++
 13 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h
index 550d5c6c358..896f2ff63e0 100644
--- a/src/mesa/main/extensions_table.h
+++ b/src/mesa/main/extensions_table.h
@@ -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)
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index 66ac9fd1267..fb3ecace034 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -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;
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 0bca52fde50..ffb04084d98 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -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;
diff --git a/src/mesa/main/formats.csv b/src/mesa/main/formats.csv
index 6fc787cdf57..e2b54e935bb 100644
--- a/src/mesa/main/formats.csv
+++ b/src/mesa/main/formats.csv
@@ -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
 
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index f0e58b327e6..29c1308c383 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -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
diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
index 897d0ff5ca3..34f930751bf 100644
--- a/src/mesa/main/glformats.c
+++ b/src/mesa/main/glformats.c
@@ -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 &&
diff --git a/src/mesa/main/glheader.h b/src/mesa/main/glheader.h
index a7818d6a5b1..12c9b949433 100644
--- a/src/mesa/main/glheader.h
+++ b/src/mesa/main/glheader.h
@@ -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
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index d847e27c0c1..70e7b218197 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -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;
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 1c9122370b4..bf46b6658d9 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -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);
diff --git a/src/mesa/main/textureview.c b/src/mesa/main/textureview.c
index 5d9bc81c2d7..2986afb7c11 100644
--- a/src/mesa/main/textureview.c
+++ b/src/mesa/main/textureview.c
@@ -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},
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index e60f7c55318..0557201c8ce 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -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 },
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 1c927316e47..cc5621072bb 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -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 */
    {
diff --git a/src/util/format/u_format_tests.c b/src/util/format/u_format_tests.c
index 0cc4de86d88..487b4b89881 100644
--- a/src/util/format/u_format_tests.c
+++ b/src/util/format/u_format_tests.c
@@ -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)},



More information about the mesa-commit mailing list