mesa formats: add MESA_FORMAT_ABGR2101010_UINT
authorJordan Justen <jordan.l.justen@intel.com>
Sat, 9 Jun 2012 19:14:26 +0000 (12:14 -0700)
committerJordan Justen <jordan.l.justen@intel.com>
Sat, 21 Jul 2012 23:49:42 +0000 (16:49 -0700)
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/main/format_pack.c
src/mesa/main/format_unpack.c
src/mesa/main/formats.c
src/mesa/main/formats.h
src/mesa/main/texformat.c
src/mesa/main/texstore.c
src/mesa/swrast/s_texfetch.c

index 7f0bda1278daf17ede6e31b34852f47ac9cabbb5..be6c026e8c2f4cb90ddb7c3e6251eef2b3a4540a 100644 (file)
@@ -1005,6 +1005,32 @@ pack_float_ARGB2101010(const GLfloat src[4], void *dst)
 }
 
 
+/* MESA_FORMAT_ABGR2101010_UINT */
+
+static void
+pack_ubyte_ABGR2101010_UINT(const GLubyte src[4], void *dst)
+{
+   GLuint *d = ((GLuint *) dst);
+   GLushort r = UBYTE_TO_USHORT(src[RCOMP]);
+   GLushort g = UBYTE_TO_USHORT(src[GCOMP]);
+   GLushort b = UBYTE_TO_USHORT(src[BCOMP]);
+   GLushort a = UBYTE_TO_USHORT(src[ACOMP]);
+   *d = PACK_COLOR_2101010_US(a, b, g, r);
+}
+
+static void
+pack_float_ABGR2101010_UINT(const GLfloat src[4], void *dst)
+{
+   GLuint *d = ((GLuint *) dst);
+   GLushort r, g, b, a;
+   UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
+   UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
+   UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
+   UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
+   *d = PACK_COLOR_2101010_US(a, b, g, r);
+}
+
+
 /* MESA_FORMAT_SRGB8 */
 
 static void
@@ -1696,6 +1722,7 @@ _mesa_get_pack_ubyte_rgba_function(gl_format format)
       table[MESA_FORMAT_RG1616] = pack_ubyte_RG1616;
       table[MESA_FORMAT_RG1616_REV] = pack_ubyte_RG1616_REV;
       table[MESA_FORMAT_ARGB2101010] = pack_ubyte_ARGB2101010;
+      table[MESA_FORMAT_ABGR2101010_UINT] = pack_ubyte_ABGR2101010_UINT;
 
       /* should never convert RGBA to these formats */
       table[MESA_FORMAT_Z24_S8] = NULL;
@@ -1841,6 +1868,7 @@ _mesa_get_pack_float_rgba_function(gl_format format)
       table[MESA_FORMAT_RG1616] = pack_float_RG1616;
       table[MESA_FORMAT_RG1616_REV] = pack_float_RG1616_REV;
       table[MESA_FORMAT_ARGB2101010] = pack_float_ARGB2101010;
+      table[MESA_FORMAT_ABGR2101010_UINT] = pack_float_ABGR2101010_UINT;
 
       /* should never convert RGBA to these formats */
       table[MESA_FORMAT_Z24_S8] = NULL;
index d1daae59ce1530605cf37b33c6e229a909756bd3..529c416a8cc6999731d3daed2b7ac9d8e41680ff 100644 (file)
@@ -609,6 +609,20 @@ unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
 }
 
 
+static void
+unpack_ABGR2101010_UINT(const void *src, GLfloat dst[][4], GLuint n)
+{
+   const GLuint *s = ((const GLuint *) src);
+   GLuint i;
+   for (i = 0; i < n; i++) {
+      dst[i][RCOMP] = (GLfloat)((s[i] >>  0) & 0x3ff);
+      dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
+      dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
+      dst[i][ACOMP] = (GLfloat)((s[i] >> 30) &  0x03);
+   }
+}
+
+
 static void
 unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
 {
@@ -1499,6 +1513,7 @@ get_unpack_rgba_function(gl_format format)
       table[MESA_FORMAT_RG1616] = unpack_RG1616;
       table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
       table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
+      table[MESA_FORMAT_ABGR2101010_UINT] = unpack_ABGR2101010_UINT;
       table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
       table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
       table[MESA_FORMAT_Z16] = unpack_Z16;
@@ -2589,6 +2604,20 @@ unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
    }
 }
 
+static void
+unpack_int_rgba_ABGR2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
+{
+   unsigned int i;
+
+   for (i = 0; i < n; i++) {
+      GLuint tmp = src[i];
+      dst[i][0] = (tmp >> 0) & 0x3ff;
+      dst[i][1] = (tmp >> 10) & 0x3ff;
+      dst[i][2] = (tmp >> 20) & 0x3ff;
+      dst[i][3] = (tmp >> 30) & 0x3;
+   }
+}
+
 void
 _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
                            const void *src, GLuint dst[][4])
@@ -2759,6 +2788,11 @@ _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
    case MESA_FORMAT_ARGB2101010_UINT:
       unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
       break;
+
+   case MESA_FORMAT_ABGR2101010_UINT:
+      unpack_int_rgba_ABGR2101010_UINT(src, dst, n);
+      break;
+
    default:
       _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
                     _mesa_get_format_name(format));
index 5dd9f085a85790d65373a8a3f06195e04dffdc2b..1fa641c92ee7854e9e0bfee47ed67eb8aa97acd6 100644 (file)
@@ -1520,6 +1520,15 @@ static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
       0, 0, 0, 0, 0,
       1, 1, 4
    },
+   {
+      MESA_FORMAT_ABGR2101010_UINT,
+      "MESA_FORMAT_ABGR2101010_UINT",
+      GL_RGBA,
+      GL_UNSIGNED_INT,
+      10, 10, 10, 2,
+      0, 0, 0, 0, 0,
+      1, 1, 4
+   },
 };
 
 
@@ -2503,6 +2512,7 @@ _mesa_format_to_type_and_comps(gl_format format,
       return;
 
    case MESA_FORMAT_ARGB2101010_UINT:
+   case MESA_FORMAT_ABGR2101010_UINT:
       *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
       *comps = 4;
       return;
@@ -2928,6 +2938,11 @@ _mesa_format_matches_format_and_type(gl_format gl_format,
               type == GL_UNSIGNED_INT_2_10_10_10_REV &&
               !swapBytes);
 
+   case MESA_FORMAT_ABGR2101010_UINT:
+      return (format == GL_RGBA_INTEGER_EXT &&
+              type == GL_UNSIGNED_INT_2_10_10_10_REV &&
+              !swapBytes);
+
    case MESA_FORMAT_RGB9_E5_FLOAT:
       return format == GL_RGB && type == GL_UNSIGNED_INT_5_9_9_9_REV &&
          !swapBytes;
index 176e0fd18f6e0c1fabed819ca84da3f729b63288..1843eb6fc2cf3d96097a0270270938a89e1a876c 100644 (file)
@@ -276,6 +276,7 @@ typedef enum
    MESA_FORMAT_Z32_FLOAT_X24S8,
 
    MESA_FORMAT_ARGB2101010_UINT,
+   MESA_FORMAT_ABGR2101010_UINT,
 
    MESA_FORMAT_COUNT
 } gl_format;
index 26bcbc10a665508ff7dbc2da360c50e8a8b27f78..91897176ef4de7964db49bb602b363fc60bc6bc8 100644 (file)
@@ -887,6 +887,7 @@ _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
       switch (internalFormat) {
       case GL_RGB10_A2UI:
          RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010_UINT);
+         RETURN_IF_SUPPORTED(MESA_FORMAT_ABGR2101010_UINT);
          break;
       default:
          break;
index 6721be9e85ec4341f35f90f396b3570a1539dc8f..ab9fdf26d3e7098f4dcce86e291f6dfb9817cecd 100644 (file)
@@ -71,6 +71,7 @@
 #include "teximage.h"
 #include "texstore.h"
 #include "enums.h"
+#include "glformats.h"
 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
 
@@ -3890,6 +3891,72 @@ _mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS)
    return GL_TRUE;
 }
 
+static GLboolean
+_mesa_texstore_abgr2101010_uint(TEXSTORE_PARAMS)
+{
+   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
+
+   ASSERT(dstFormat == MESA_FORMAT_ABGR2101010_UINT);
+   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
+
+   if (baseInternalFormat == GL_RGBA &&
+       _mesa_format_matches_format_and_type(dstFormat, srcFormat, srcType,
+                                            srcPacking->SwapBytes)) {
+      /* simple memcpy path */
+      memcpy_texture(ctx, dims,
+                     dstFormat,
+                     dstRowStride, dstSlices,
+                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
+                     srcAddr, srcPacking);
+   }
+   else {
+      /* general path */
+      const GLuint *tempImage = make_temp_uint_image(ctx, dims,
+                                                     baseInternalFormat,
+                                                     baseFormat,
+                                                     srcWidth, srcHeight,
+                                                     srcDepth, srcFormat,
+                                                     srcType, srcAddr,
+                                                     srcPacking);
+      const GLuint *src = tempImage;
+      GLint img, row, col;
+      GLboolean is_unsigned = _mesa_is_type_unsigned(srcType);
+      if (!tempImage)
+         return GL_FALSE;
+      for (img = 0; img < srcDepth; img++) {
+         GLubyte *dstRow = dstSlices[img];
+
+         for (row = 0; row < srcHeight; row++) {
+            GLuint *dstUI = (GLuint *) dstRow;
+            if (is_unsigned) {
+               for (col = 0; col < srcWidth; col++) {
+                  GLushort a,r,g,b;
+                  r = MIN2(src[RCOMP], 0x3ff);
+                  g = MIN2(src[GCOMP], 0x3ff);
+                  b = MIN2(src[BCOMP], 0x3ff);
+                  a = MIN2(src[ACOMP], 0x003);
+                  dstUI[col] = (a << 30) | (b << 20) | (g << 10) | (r);
+                  src += 4;
+               }
+            } else {
+               for (col = 0; col < srcWidth; col++) {
+                  GLushort a,r,g,b;
+                  r = CLAMP((GLint) src[RCOMP], 0, 0x3ff);
+                  g = CLAMP((GLint) src[GCOMP], 0, 0x3ff);
+                  b = CLAMP((GLint) src[BCOMP], 0, 0x3ff);
+                  a = CLAMP((GLint) src[ACOMP], 0, 0x003);
+                  dstUI[col] = (a << 30) | (b << 20) | (g << 10) | (r);
+                  src += 4;
+               }
+            }
+            dstRow += dstRowStride;
+         }
+      }
+      free((void *) tempImage);
+   }
+   return GL_TRUE;
+}
+
 static GLboolean
 _mesa_texstore_null(TEXSTORE_PARAMS)
 {
@@ -4084,6 +4151,7 @@ _mesa_get_texstore_func(gl_format format)
       table[MESA_FORMAT_RGBA_UINT32] = _mesa_texstore_rgba_uint32;
 
       table[MESA_FORMAT_ARGB2101010_UINT] = _mesa_texstore_argb2101010_uint;
+      table[MESA_FORMAT_ABGR2101010_UINT] = _mesa_texstore_abgr2101010_uint;
       initialized = GL_TRUE;
    }
 
index 8529ff08db3d257fa49c7a93a50fef0c1a564fa3..12ee47963d74f30927fc9ec09d1c8492eb670f40 100644 (file)
@@ -1104,7 +1104,13 @@ texfetch_funcs[MESA_FORMAT_COUNT] =
       NULL,
       NULL,
       NULL
-   }
+   },
+   {
+      MESA_FORMAT_ABGR2101010_UINT,
+      NULL,
+      NULL,
+      NULL
+   },
 };