[Mesa-dev] [PATCH 4/5] Add MESA_FORMAT_A8L8_{SNORM,SRGB}
Richard Sandiford
rsandifo at linux.vnet.ibm.com
Mon Jul 21 08:43:20 PDT 2014
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.
---
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 | 28 +++++++++++++++++++
src/mesa/main/formats.h | 2 ++
src/mesa/main/texformat.c | 3 ++
src/mesa/main/texstore.c | 10 +++++--
src/mesa/swrast/s_texfetch.c | 2 ++
src/mesa/swrast/s_texfetch_tmp.h | 24 ++++++++++++++++
9 files changed, 135 insertions(+), 2 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c b/src/mesa/drivers/dri/i965/brw_surface_formats.c
index 41f4221..596609e 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,
@@ -490,6 +491,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 c97c052..41253e7 100644
--- a/src/mesa/main/format_pack.c
+++ b/src/mesa/main/format_pack.c
@@ -1161,6 +1161,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 = linear_ubyte_to_srgb_ubyte(src[RCOMP]);
+ *d = PACK_COLOR_88(l, src[ACOMP]);
+}
+
static void
pack_float_L8A8_SRGB(const GLfloat src[4], void *dst)
{
@@ -1170,6 +1180,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 = linear_float_to_srgb_ubyte(src[RCOMP]);
+ CLAMPED_FLOAT_TO_UBYTE(a, src[ACOMP]);
+ *d = PACK_COLOR_88(l, a);
+}
+
/* MESA_FORMAT_RGBA_FLOAT32 */
@@ -1595,6 +1614,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
*/
@@ -1968,6 +2001,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; */
@@ -2021,6 +2055,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;
@@ -2131,6 +2166,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;
@@ -2185,6 +2221,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 ad5ea4c..7854985 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -836,6 +836,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] = _mesa_nonlinear_to_linear(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)
{
}
@@ -1992,6 +2005,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)
{
@@ -2391,6 +2418,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;
@@ -2510,6 +2538,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 1f20a9a..e33b1b7 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -632,6 +632,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
8, 0, 0, 0, 0,
1, 1, 2
},
+ {
+ MESA_FORMAT_A8L8_SNORM,
+ "MESA_FORMAT_A8L8_SNORM",
+ GL_LUMINANCE_ALPHA,
+ GL_SIGNED_NORMALIZED,
+ 0, 0, 0, 8,
+ 8, 0, 0, 0, 0,
+ 1, 1, 2
+ },
/* Array signed/normalized formats */
{
@@ -798,6 +807,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
8, 0, 0, 0, 0,
1, 1, 2
},
+ {
+ MESA_FORMAT_A8L8_SRGB,
+ "MESA_FORMAT_A8L8_SRGB",
+ GL_LUMINANCE_ALPHA,
+ GL_UNSIGNED_NORMALIZED,
+ 0, 0, 0, 8,
+ 8, 0, 0, 0, 0,
+ 1, 1, 2
+ },
/* Array sRGB formats */
{
@@ -2051,6 +2069,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:
@@ -2093,6 +2112,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;
@@ -2576,6 +2598,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;
@@ -2627,6 +2650,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;
@@ -3128,6 +3152,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:
@@ -3444,6 +3469,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.h b/src/mesa/main/formats.h
index dc50bc8..17cbe86 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -241,6 +241,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 */
@@ -263,6 +264,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 c61a748..99a1ff3 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -477,6 +477,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;
@@ -547,6 +548,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:
@@ -555,6 +557,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/main/texstore.c b/src/mesa/main/texstore.c
index d363f9f..ae52bd3 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -2114,6 +2114,7 @@ _mesa_texstore_snorm88(TEXSTORE_PARAMS)
const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
ASSERT(dstFormat == MESA_FORMAT_L8A8_SNORM ||
+ dstFormat == MESA_FORMAT_A8L8_SNORM ||
dstFormat == MESA_FORMAT_G8R8_SNORM ||
dstFormat == MESA_FORMAT_R8G8_SNORM);
ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
@@ -3244,10 +3245,13 @@ _mesa_texstore_sla8(TEXSTORE_PARAMS)
mesa_format newDstFormat;
GLboolean k;
- ASSERT(dstFormat == MESA_FORMAT_L8A8_SRGB);
+ ASSERT(dstFormat == MESA_FORMAT_L8A8_SRGB ||
+ dstFormat == MESA_FORMAT_A8L8_SRGB);
/* reuse normal luminance/alpha texstore code */
- newDstFormat = MESA_FORMAT_L8A8_UNORM;
+ newDstFormat = (dstFormat == MESA_FORMAT_L8A8_SRGB ?
+ MESA_FORMAT_L8A8_UNORM :
+ MESA_FORMAT_A8L8_UNORM);
k = _mesa_texstore_unorm88(ctx, dims, baseInternalFormat,
newDstFormat,
@@ -3620,6 +3624,7 @@ _mesa_get_texstore_func(mesa_format format)
table[MESA_FORMAT_B8G8R8A8_SRGB] = _mesa_texstore_sargb8;
table[MESA_FORMAT_L_SRGB8] = _mesa_texstore_sl8;
table[MESA_FORMAT_L8A8_SRGB] = _mesa_texstore_sla8;
+ table[MESA_FORMAT_A8L8_SRGB] = _mesa_texstore_sla8;
table[MESA_FORMAT_SRGB_DXT1] = _mesa_texstore_rgb_dxt1;
table[MESA_FORMAT_SRGBA_DXT1] = _mesa_texstore_rgba_dxt1;
table[MESA_FORMAT_SRGBA_DXT3] = _mesa_texstore_rgba_dxt3;
@@ -3680,6 +3685,7 @@ _mesa_get_texstore_func(mesa_format format)
table[MESA_FORMAT_A_SNORM8] = _mesa_texstore_snorm8;
table[MESA_FORMAT_L_SNORM8] = _mesa_texstore_snorm8;
table[MESA_FORMAT_L8A8_SNORM] = _mesa_texstore_snorm88;
+ table[MESA_FORMAT_A8L8_SNORM] = _mesa_texstore_snorm88;
table[MESA_FORMAT_I_SNORM8] = _mesa_texstore_snorm8;
table[MESA_FORMAT_A_SNORM16] = _mesa_texstore_snorm16;
table[MESA_FORMAT_L_SNORM16] = _mesa_texstore_snorm16;
diff --git a/src/mesa/swrast/s_texfetch.c b/src/mesa/swrast/s_texfetch.c
index e508368..72930bb 100644
--- a/src/mesa/swrast/s_texfetch.c
+++ b/src/mesa/swrast/s_texfetch.c
@@ -238,6 +238,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),
@@ -260,6 +261,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 0fce355..9effe5f 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.8.3.1
More information about the mesa-dev
mailing list