[Mesa-dev] [PATCH 04/11] mesa: Add MESA_FORMAT_A8L8_{SNORM,SRGB}

Dave Airlie airlied at gmail.com
Mon Sep 15 23:28:00 PDT 2014


From: Richard Sandiford <rsandifo at linux.vnet.ibm.com>

The associated UNORM format already existed.

This means that each LnAn format has a reversed counterpart,
which is necessary for handling big-endian mesa<->gallium mappings.

[airlied: rebased onto current master]

Signed-off-by: Richard Sandiford <rsandifo at linux.vnet.ibm.com>
Reviewed-by: Brian Paul <brianp at vmware.com>
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/mesa/drivers/dri/i965/brw_surface_formats.c |  2 ++
 src/mesa/main/format_pack.c                     | 37 +++++++++++++++++++++++++
 src/mesa/main/format_unpack.c                   | 29 +++++++++++++++++++
 src/mesa/main/formats.c                         | 10 +++++++
 src/mesa/main/formats.csv                       |  2 ++
 src/mesa/main/formats.h                         |  2 ++
 src/mesa/main/texformat.c                       |  3 ++
 src/mesa/swrast/s_texfetch.c                    |  2 ++
 src/mesa/swrast/s_texfetch_tmp.h                | 24 ++++++++++++++++
 9 files changed, 111 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c b/src/mesa/drivers/dri/i965/brw_surface_formats.c
index 974f2df..b726c27 100644
--- a/src/mesa/drivers/dri/i965/brw_surface_formats.c
+++ b/src/mesa/drivers/dri/i965/brw_surface_formats.c
@@ -371,6 +371,7 @@ brw_format_for_mesa_format(mesa_format mesa_format)
       [MESA_FORMAT_R8G8B8A8_SRGB] = BRW_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB,
       [MESA_FORMAT_L_SRGB8] = BRW_SURFACEFORMAT_L8_UNORM_SRGB,
       [MESA_FORMAT_L8A8_SRGB] = BRW_SURFACEFORMAT_L8A8_UNORM_SRGB,
+      [MESA_FORMAT_A8L8_SRGB] = 0,
       [MESA_FORMAT_SRGB_DXT1] = BRW_SURFACEFORMAT_DXT1_RGB_SRGB,
       [MESA_FORMAT_SRGBA_DXT1] = BRW_SURFACEFORMAT_BC1_UNORM_SRGB,
       [MESA_FORMAT_SRGBA_DXT3] = BRW_SURFACEFORMAT_BC2_UNORM_SRGB,
@@ -495,6 +496,7 @@ brw_format_for_mesa_format(mesa_format mesa_format)
       [MESA_FORMAT_A_SNORM8] = 0,
       [MESA_FORMAT_L_SNORM8] = 0,
       [MESA_FORMAT_L8A8_SNORM] = 0,
+      [MESA_FORMAT_A8L8_SNORM] = 0,
       [MESA_FORMAT_I_SNORM8] = 0,
       [MESA_FORMAT_A_SNORM16] = 0,
       [MESA_FORMAT_L_SNORM16] = 0,
diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c
index 6cbf859..231fd6c 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -1129,6 +1129,16 @@ pack_ubyte_L8A8_SRGB(const GLubyte src[4], void *dst)
    *d = PACK_COLOR_88(src[ACOMP], l);
 }
 
+/* MESA_FORMAT_A8L8_SRGB */
+
+static void
+pack_ubyte_A8L8_SRGB(const GLubyte src[4], void *dst)
+{
+   GLushort *d = ((GLushort *) dst);
+   GLubyte l = util_format_linear_to_srgb_8unorm(src[RCOMP]);
+   *d = PACK_COLOR_88(l, src[ACOMP]);
+}
+
 static void
 pack_float_L8A8_SRGB(const GLfloat src[4], void *dst)
 {
@@ -1138,6 +1148,15 @@ pack_float_L8A8_SRGB(const GLfloat src[4], void *dst)
    *d = PACK_COLOR_88(a, l);
 }
 
+static void
+pack_float_A8L8_SRGB(const GLfloat src[4], void *dst)
+{
+   GLushort *d = ((GLushort *) dst);
+   GLubyte a, l = util_format_linear_float_to_srgb_8unorm(src[RCOMP]);
+   CLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
+   *d = PACK_COLOR_88(l, a);
+}
+
 
 /* MESA_FORMAT_RGBA_FLOAT32 */
 
@@ -1563,6 +1582,20 @@ pack_float_L8A8_SNORM(const GLfloat src[4], void *dst)
 
 
 /*
+ * MESA_FORMAT_A8L8_SNORM
+ */
+
+static void
+pack_float_A8L8_SNORM(const GLfloat src[4], void *dst)
+{
+   GLushort *d = (GLushort *) dst;
+   GLbyte l = FLOAT_TO_BYTE(CLAMP(src[RCOMP], -1.0f, 1.0f));
+   GLbyte a = FLOAT_TO_BYTE(CLAMP(src[ACOMP], -1.0f, 1.0f));
+   *d = (l << 8) | a;
+}
+
+
+/*
  * MESA_FORMAT_A_SNORM16
  */
 
@@ -1936,6 +1969,7 @@ _mesa_get_pack_ubyte_rgba_function(mesa_format format)
       table[MESA_FORMAT_R8G8B8A8_SRGB] = pack_ubyte_R8G8B8A8_SRGB;
       table[MESA_FORMAT_L_SRGB8] = pack_ubyte_L_SRGB8;
       table[MESA_FORMAT_L8A8_SRGB] = pack_ubyte_L8A8_SRGB;
+      table[MESA_FORMAT_A8L8_SRGB] = pack_ubyte_A8L8_SRGB;
       /* n/a */
       table[MESA_FORMAT_SRGB_DXT1] = NULL; /* pack_ubyte_SRGB_DXT1; */
       table[MESA_FORMAT_SRGBA_DXT1] = NULL; /* pack_ubyte_SRGBA_DXT1; */
@@ -1989,6 +2023,7 @@ _mesa_get_pack_ubyte_rgba_function(mesa_format format)
       table[MESA_FORMAT_A_SNORM8] = NULL;
       table[MESA_FORMAT_L_SNORM8] = NULL;
       table[MESA_FORMAT_L8A8_SNORM] = NULL;
+      table[MESA_FORMAT_A8L8_SNORM] = NULL;
       table[MESA_FORMAT_I_SNORM8] = NULL;
       table[MESA_FORMAT_A_SNORM16] = NULL;
       table[MESA_FORMAT_L_SNORM16] = NULL;
@@ -2099,6 +2134,7 @@ _mesa_get_pack_float_rgba_function(mesa_format format)
       table[MESA_FORMAT_R8G8B8A8_SRGB] = pack_float_R8G8B8A8_SRGB;
       table[MESA_FORMAT_L_SRGB8] = pack_float_L_SRGB8;
       table[MESA_FORMAT_L8A8_SRGB] = pack_float_L8A8_SRGB;
+      table[MESA_FORMAT_A8L8_SRGB] = pack_float_A8L8_SRGB;
 
       /* n/a */
       table[MESA_FORMAT_SRGB_DXT1] = NULL;
@@ -2153,6 +2189,7 @@ _mesa_get_pack_float_rgba_function(mesa_format format)
       table[MESA_FORMAT_A_SNORM8] = pack_float_A_SNORM8;
       table[MESA_FORMAT_L_SNORM8] = pack_float_L_SNORM8;
       table[MESA_FORMAT_L8A8_SNORM] = pack_float_L8A8_SNORM;
+      table[MESA_FORMAT_A8L8_SNORM] = pack_float_A8L8_SNORM;
       table[MESA_FORMAT_I_SNORM8] = pack_float_L_SNORM8; /* reused */
       table[MESA_FORMAT_A_SNORM16] = pack_float_A_SNORM16;
       table[MESA_FORMAT_L_SNORM16] = pack_float_L_SNORM16;
diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index b84ed02..eed92d8 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -809,6 +809,19 @@ unpack_L8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
 }
 
 static void
+unpack_A8L8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
+{
+   const GLushort *s = (const GLushort *) src;
+   GLuint i;
+   for (i = 0; i < n; i++) {
+      dst[i][RCOMP] =
+      dst[i][GCOMP] =
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i] >> 8);
+      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] & 0xff); /* linear! */
+   }
+}
+
+static void
 unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
 {
 }
@@ -1965,6 +1978,20 @@ unpack_L8A8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
    }
 }
 
+
+static void
+unpack_A8L8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
+{
+   const GLshort *s = ((const GLshort *) src);
+   GLuint i;
+   for (i = 0; i < n; i++) {
+      dst[i][RCOMP] =
+      dst[i][GCOMP] =
+      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
+      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
+   }
+}
+
 static void
 unpack_I_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
 {
@@ -2364,6 +2391,7 @@ get_unpack_rgba_function(mesa_format format)
       table[MESA_FORMAT_R8G8B8A8_SRGB] = unpack_R8G8B8A8_SRGB;
       table[MESA_FORMAT_L_SRGB8] = unpack_L_SRGB8;
       table[MESA_FORMAT_L8A8_SRGB] = unpack_L8A8_SRGB;
+      table[MESA_FORMAT_A8L8_SRGB] = unpack_A8L8_SRGB;
       table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
       table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
       table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
@@ -2483,6 +2511,7 @@ get_unpack_rgba_function(mesa_format format)
       table[MESA_FORMAT_A_SNORM8] = unpack_A_SNORM8;
       table[MESA_FORMAT_L_SNORM8] = unpack_L_SNORM8;
       table[MESA_FORMAT_L8A8_SNORM] = unpack_L8A8_SNORM;
+      table[MESA_FORMAT_A8L8_SNORM] = unpack_A8L8_SNORM;
       table[MESA_FORMAT_I_SNORM8] = unpack_I_SNORM8;
       table[MESA_FORMAT_A_SNORM16] = unpack_A_SNORM16;
       table[MESA_FORMAT_L_SNORM16] = unpack_L_SNORM16;
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index db22a45..8fd36a0 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -360,6 +360,7 @@ _mesa_get_format_color_encoding(mesa_format format)
    case MESA_FORMAT_R8G8B8A8_SRGB:
    case MESA_FORMAT_L_SRGB8:
    case MESA_FORMAT_L8A8_SRGB:
+   case MESA_FORMAT_A8L8_SRGB:
    case MESA_FORMAT_SRGB_DXT1:
    case MESA_FORMAT_SRGBA_DXT1:
    case MESA_FORMAT_SRGBA_DXT3:
@@ -428,6 +429,9 @@ _mesa_get_srgb_format_linear(mesa_format format)
    case MESA_FORMAT_L8A8_SRGB:
       format = MESA_FORMAT_L8A8_UNORM;
       break;
+   case MESA_FORMAT_A8L8_SRGB:
+      format = MESA_FORMAT_A8L8_UNORM;
+      break;
    case MESA_FORMAT_SRGB_DXT1:
       format = MESA_FORMAT_RGB_DXT1;
       break;
@@ -919,6 +923,7 @@ _mesa_format_to_type_and_comps(mesa_format format,
       return;
    case MESA_FORMAT_R8G8_SNORM:
    case MESA_FORMAT_L8A8_SNORM:
+   case MESA_FORMAT_A8L8_SNORM:
       *datatype = GL_BYTE;
       *comps = 2;
       return;
@@ -970,6 +975,7 @@ _mesa_format_to_type_and_comps(mesa_format format,
       *comps = 1;
       return;
    case MESA_FORMAT_L8A8_SRGB:
+   case MESA_FORMAT_A8L8_SRGB:
       *datatype = GL_UNSIGNED_BYTE;
       *comps = 2;
       return;
@@ -1475,6 +1481,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
    case MESA_FORMAT_L8A8_SRGB:
       return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE && littleEndian;
    case MESA_FORMAT_A8L8_UNORM:
+   case MESA_FORMAT_A8L8_SRGB:
       return GL_FALSE;
 
    case MESA_FORMAT_L16A16_UNORM:
@@ -1797,6 +1804,9 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
    case MESA_FORMAT_L8A8_SNORM:
       return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
              littleEndian && !swapBytes;
+   case MESA_FORMAT_A8L8_SNORM:
+      return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
+             !littleEndian && !swapBytes;
    case MESA_FORMAT_I_SNORM8:
       return format == GL_RED && type == GL_BYTE;
    case MESA_FORMAT_A_SNORM16:
diff --git a/src/mesa/main/formats.csv b/src/mesa/main/formats.csv
index 4d542b7..b4d16de 100644
--- a/src/mesa/main/formats.csv
+++ b/src/mesa/main/formats.csv
@@ -119,6 +119,7 @@ MESA_FORMAT_G16R16_SNORM                  , packed, 1, 1, sn16, sn16,     ,
 MESA_FORMAT_R8G8_SNORM                    , packed, 1, 1, sn8 , sn8 ,     ,     , xy01, rgb
 MESA_FORMAT_G8R8_SNORM                    , packed, 1, 1, sn8 , sn8 ,     ,     , yx01, rgb
 MESA_FORMAT_L8A8_SNORM                    , packed, 1, 1, sn8 , sn8 ,     ,     , xxxy, rgb
+MESA_FORMAT_A8L8_SNORM                    , packed, 1, 1, sn8 , sn8 ,     ,     , yyyx, rgb
 
 # Array signed/normalized formats
 MESA_FORMAT_A_SNORM8                      , array , 1, 1, sn8 ,     ,     ,     , 000x, rgb
@@ -141,6 +142,7 @@ MESA_FORMAT_B8G8R8X8_SRGB                 , packed, 1, 1, un8 , un8 , un8 , x8
 MESA_FORMAT_R8G8B8A8_SRGB                 , packed, 1, 1, un8 , un8 , un8 , un8 , xyzw, srgb
 MESA_FORMAT_R8G8B8X8_SRGB                 , packed, 1, 1, un8 , un8 , un8 , x8  , xyz1, srgb
 MESA_FORMAT_L8A8_SRGB                     , packed, 1, 1, un8 , un8 ,     ,     , xxxy, srgb
+MESA_FORMAT_A8L8_SRGB                     , packed, 1, 1, un8 , un8 ,     ,     , yyyx, srgb
 
 # Array sRGB formats
 MESA_FORMAT_L_SRGB8                       , array , 1, 1, un8 ,     ,     ,     , xxx1, srgb
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index d6253bf..8671738 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -265,6 +265,7 @@ typedef enum
    MESA_FORMAT_R8G8_SNORM,       /*                     GGGG GGGG RRRR RRRR */
    MESA_FORMAT_G8R8_SNORM,       /*                     RRRR RRRR GGGG GGGG */
    MESA_FORMAT_L8A8_SNORM,       /*                     AAAA AAAA LLLL LLLL */
+   MESA_FORMAT_A8L8_SNORM,       /*                     LLLL LLLL AAAA AAAA */
 
    /* Array signed/normalized formats */
    MESA_FORMAT_A_SNORM8,      /* byte[i] = A */
@@ -287,6 +288,7 @@ typedef enum
    MESA_FORMAT_R8G8B8A8_SRGB,    /* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
    MESA_FORMAT_R8G8B8X8_SRGB,    /* xxxx xxxx BBBB BBBB GGGG GGGG RRRR RRRR */
    MESA_FORMAT_L8A8_SRGB,                            /* AAAA AAAA LLLL LLLL */
+   MESA_FORMAT_A8L8_SRGB,                            /* LLLL LLLL AAAA AAAA */
 
    /* Array sRGB formats */
    MESA_FORMAT_L_SRGB8,       /* ubyte[i] = L */
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 6d3b805..09e307c 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -485,6 +485,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
    case GL_LUMINANCE_ALPHA_SNORM:
    case GL_LUMINANCE8_ALPHA8_SNORM:
       RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_SNORM);
+      RETURN_IF_SUPPORTED(MESA_FORMAT_A8L8_SNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
       RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
       break;
@@ -555,6 +556,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
    case GL_SLUMINANCE_ALPHA_EXT:
    case GL_SLUMINANCE8_ALPHA8_EXT:
       RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_SRGB);
+      RETURN_IF_SUPPORTED(MESA_FORMAT_A8L8_SRGB);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
       break;
    case GL_COMPRESSED_SLUMINANCE_EXT:
@@ -563,6 +565,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
       break;
    case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
       RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_SRGB);
+      RETURN_IF_SUPPORTED(MESA_FORMAT_A8L8_SRGB);
       RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
       break;
    case GL_COMPRESSED_SRGB_EXT:
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
index 38d71ca..dfba190 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -210,6 +210,7 @@ texfetch_funcs[] =
    FETCH_FUNCS(R8G8_SNORM),
    FETCH_NULL(G8R8_SNORM),
    FETCH_FUNCS(L8A8_SNORM),
+   FETCH_FUNCS(A8L8_SNORM),
 
    /* Array signed/normalized formats */
    FETCH_FUNCS(A_SNORM8),
@@ -232,6 +233,7 @@ texfetch_funcs[] =
    FETCH_FUNCS(R8G8B8A8_SRGB),
    FETCH_FUNCS(R8G8B8X8_SRGB),
    FETCH_FUNCS(L8A8_SRGB),
+   FETCH_FUNCS(A8L8_SRGB),
 
    /* Array sRGB formats */
    FETCH_FUNCS(L_SRGB8),
diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index 3923e2b..81ae045 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -817,6 +817,18 @@ FETCH(L8A8_SRGB)(const struct swrast_texture_image *texImage,
 
 
 static void
+FETCH(A8L8_SRGB)(const struct swrast_texture_image *texImage,
+                 GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 2);
+   texel[RCOMP] =
+   texel[GCOMP] =
+   texel[BCOMP] = nonlinear_to_linear(s >> 8);
+   texel[ACOMP] = UBYTE_TO_FLOAT(s & 0xff); /* linear */
+}
+
+
+static void
 FETCH(RGBA_SINT8)(const struct swrast_texture_image *texImage,
                   GLint i, GLint j, GLint k, GLfloat *texel)
 {
@@ -961,6 +973,18 @@ FETCH(L8A8_SNORM)(const struct swrast_texture_image *texImage,
 
 
 static void
+FETCH(A8L8_SNORM)(const struct swrast_texture_image *texImage,
+                  GLint i, GLint j, GLint k, GLfloat *texel)
+{
+   const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
+   texel[RCOMP] =
+   texel[GCOMP] =
+   texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
+   texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
+}
+
+
+static void
 FETCH(X8B8G8R8_SNORM)(const struct swrast_texture_image *texImage,
                       GLint i, GLint j, GLint k, GLfloat *texel)
 {
-- 
1.9.3



More information about the mesa-dev mailing list