Mesa (master): mesa: implement new texture format ARGB2101010

Marek Olšák mareko at kemper.freedesktop.org
Thu Dec 23 15:58:45 UTC 2010


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

Author: Marek Olšák <maraeo at gmail.com>
Date:   Tue Dec 21 18:54:50 2010 +0100

mesa: implement new texture format ARGB2101010

Radeon GPUs do support GL_RGB10_A2.

---

 src/mesa/main/colormac.h     |    4 ++
 src/mesa/main/formats.c      |   14 ++++++++
 src/mesa/main/formats.h      |    1 +
 src/mesa/main/texfetch.c     |    7 ++++
 src/mesa/main/texfetch_tmp.h |   25 ++++++++++++++
 src/mesa/main/texformat.c    |    2 +
 src/mesa/main/texstore.c     |   75 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 128 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h
index 245fb65..f00faa5 100644
--- a/src/mesa/main/colormac.h
+++ b/src/mesa/main/colormac.h
@@ -198,6 +198,10 @@ do {						\
    ((((B) & 0xf8) >> 1) | (((G) & 0xc0) >> 6) | (((G) & 0x38) << 10) | (((R) & 0xf8) << 5) |	\
     ((A) ? 0x80 : 0))
 
+#define PACK_COLOR_2101010( A, B, G, R )					\
+   (((B) << 22) | ((G) << 12) | ((R) << 2) |	\
+    (((A) & 0xc0) << 24))
+
 #define PACK_COLOR_4444( R, G, B, A )					\
    ((((R) & 0xf0) << 8) | (((G) & 0xf0) << 4) | ((B) & 0xf0) | ((A) >> 4))
 
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 42f70ca..0975407 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -375,6 +375,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       1, 1, 4
    },
    {
+      MESA_FORMAT_ARGB2101010,
+      "MESA_FORMAT_ARGB2101010",
+      GL_RGBA,
+      GL_UNSIGNED_NORMALIZED,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
+   {
       MESA_FORMAT_Z24_S8,          /* Name */
       "MESA_FORMAT_Z24_S8",        /* StrName */
       GL_DEPTH_STENCIL,            /* BaseFormat */
@@ -1251,6 +1260,11 @@ _mesa_format_to_type_and_comps(gl_format format,
       *comps = 4;
       return;
 
+   case MESA_FORMAT_ARGB2101010:
+      *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
+      *comps = 4;
+      return;
+
    case MESA_FORMAT_RGBA5551:
       *datatype = GL_UNSIGNED_SHORT_5_5_5_1;
       *comps = 4;
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 997229b..c147376 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -82,6 +82,7 @@ typedef enum
    MESA_FORMAT_R16,		/*                     RRRR RRRR RRRR RRRR */
    MESA_FORMAT_RG1616,		/* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
    MESA_FORMAT_RG1616_REV,	/* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
+   MESA_FORMAT_ARGB2101010,     /* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
    MESA_FORMAT_Z24_S8,          /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
    MESA_FORMAT_S8_Z24,          /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
    MESA_FORMAT_Z16,             /*                     ZZZZ ZZZZ ZZZZ ZZZZ */
diff --git a/src/mesa/main/texfetch.c b/src/mesa/main/texfetch.c
index 372ef26..dff5963 100644
--- a/src/mesa/main/texfetch.c
+++ b/src/mesa/main/texfetch.c
@@ -356,6 +356,13 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       store_texel_rg1616_rev,
    },
    {
+      MESA_FORMAT_ARGB2101010,
+      fetch_texel_1d_f_argb2101010,
+      fetch_texel_2d_f_argb2101010,
+      fetch_texel_3d_f_argb2101010,
+      store_texel_argb2101010
+   },
+   {
       MESA_FORMAT_Z24_S8,
       fetch_texel_1d_f_z24_s8,
       fetch_texel_2d_f_z24_s8,
diff --git a/src/mesa/main/texfetch_tmp.h b/src/mesa/main/texfetch_tmp.h
index 2f583ed..c985de9 100644
--- a/src/mesa/main/texfetch_tmp.h
+++ b/src/mesa/main/texfetch_tmp.h
@@ -810,6 +810,31 @@ static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
 #endif
 
 
+/* MESA_FORMAT_ARGB2101010 ***************************************************/
+
+/* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
+static void FETCH(f_argb2101010)( const struct gl_texture_image *texImage,
+                                  GLint i, GLint j, GLint k, GLfloat *texel )
+{
+   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+   const GLuint s = *src;
+   texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
+   texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
+   texel[BCOMP] = ((s >>  0) & 0x3ff) * (1.0F / 1023.0F);
+   texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
+}
+
+#if DIM == 3
+static void store_texel_argb2101010(struct gl_texture_image *texImage,
+                                    GLint i, GLint j, GLint k, const void *texel)
+{
+   const GLubyte *rgba = (const GLubyte *) texel;
+   GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
+   *dst = PACK_COLOR_2101010(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
+}
+#endif
+
+
 /* MESA_FORMAT_RG88 **********************************************************/
 
 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
index 894c013..9d30a7e 100644
--- a/src/mesa/main/texformat.c
+++ b/src/mesa/main/texformat.c
@@ -75,6 +75,8 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
 
       /* deep RGBA formats */
       case GL_RGB10_A2:
+         return MESA_FORMAT_ARGB2101010;
+
       case GL_RGBA12:
       case GL_RGBA16:
          return MESA_FORMAT_RGBA_16;
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 89677c5..b14ffe8 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -2038,6 +2038,80 @@ _mesa_texstore_argb1555(TEXSTORE_PARAMS)
 }
 
 
+static GLboolean
+_mesa_texstore_argb2101010(TEXSTORE_PARAMS)
+{
+   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_ARGB2101010);
+   ASSERT(texelBytes == 4);
+
+   if (!ctx->_ImageTransferState &&
+       !srcPacking->SwapBytes &&
+       dstFormat == MESA_FORMAT_ARGB2101010 &&
+       srcFormat == GL_BGRA &&
+       srcType == GL_UNSIGNED_INT_2_10_10_10_REV &&
+       baseInternalFormat == GL_RGBA) {
+      /* simple memcpy path */
+      memcpy_texture(ctx, dims,
+                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
+                     dstRowStride,
+                     dstImageOffsets,
+                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+                     srcAddr, srcPacking);
+   }
+   else {
+      /* general path */
+      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
+                                                 baseInternalFormat,
+                                                 baseFormat,
+                                                 srcWidth, srcHeight, srcDepth,
+                                                 srcFormat, srcType, srcAddr,
+                                                 srcPacking);
+      const GLchan *src = tempImage;
+      GLint img, row, col;
+      if (!tempImage)
+         return GL_FALSE;
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = (GLubyte *) dstAddr
+            + dstImageOffsets[dstZoffset + img] * texelBytes
+            + dstYoffset * dstRowStride
+            + dstXoffset * texelBytes;
+         if (baseInternalFormat == GL_RGBA) {
+            for (row = 0; row < srcHeight; row++) {
+               GLuint *dstUS = (GLuint *) dstRow;
+               for (col = 0; col < srcWidth; col++) {
+                  dstUS[col] = PACK_COLOR_2101010( CHAN_TO_UBYTE(src[ACOMP]),
+                                                   CHAN_TO_UBYTE(src[RCOMP]),
+                                                   CHAN_TO_UBYTE(src[GCOMP]),
+                                                   CHAN_TO_UBYTE(src[BCOMP]) );
+                  src += 4;
+               }
+               dstRow += dstRowStride;
+            }
+         } else if (baseInternalFormat == GL_RGB) {
+            for (row = 0; row < srcHeight; row++) {
+               GLuint *dstUS = (GLuint *) dstRow;
+               for (col = 0; col < srcWidth; col++) {
+                  dstUS[col] = PACK_COLOR_2101010( 0xff,
+                                                   CHAN_TO_UBYTE(src[RCOMP]),
+                                                   CHAN_TO_UBYTE(src[GCOMP]),
+                                                   CHAN_TO_UBYTE(src[BCOMP]) );
+                  src += 4;
+               }
+               dstRow += dstRowStride;
+            }
+         } else {
+            ASSERT(0);
+         }
+      }
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
+
 /**
  * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
  */
@@ -3938,6 +4012,7 @@ texstore_funcs[MESA_FORMAT_COUNT] =
    { MESA_FORMAT_R16, _mesa_texstore_r16 },
    { MESA_FORMAT_RG1616, _mesa_texstore_unorm1616 },
    { MESA_FORMAT_RG1616_REV, _mesa_texstore_unorm1616 },
+   { MESA_FORMAT_ARGB2101010, _mesa_texstore_argb2101010 },
    { MESA_FORMAT_Z24_S8, _mesa_texstore_z24_s8 },
    { MESA_FORMAT_S8_Z24, _mesa_texstore_s8_z24 },
    { MESA_FORMAT_Z16, _mesa_texstore_z16 },




More information about the mesa-commit mailing list