mesa: Add MESA_FORMAT_{A8R8G8B8, X8R8G8B8, X8B8G8R8}_SRGB (v2)
[mesa.git] / src / mesa / main / format_unpack.c
index ea1ac38afa3f3551d084ae2dee14f86dc8822a39..d5628a9e7cba235b173b21a134e988bc2f474929 100644 (file)
@@ -28,6 +28,7 @@
 #include "macros.h"
 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
+#include "util/format_srgb.h"
 
 
 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
@@ -53,34 +54,6 @@ struct z32f_x24s8
 #define EXPAND_6_8(X)  ( ((X) << 2) | ((X) >> 4) )
 
 
-/**
- * Convert an 8-bit sRGB value from non-linear space to a
- * linear RGB value in [0, 1].
- * Implemented with a 256-entry lookup table.
- */
-GLfloat
-_mesa_nonlinear_to_linear(GLubyte cs8)
-{
-   static GLfloat table[256];
-   static GLboolean tableReady = GL_FALSE;
-   if (!tableReady) {
-      /* compute lookup table now */
-      GLuint i;
-      for (i = 0; i < 256; i++) {
-         const GLfloat cs = UBYTE_TO_FLOAT(i);
-         if (cs <= 0.04045) {
-            table[i] = cs / 12.92f;
-         }
-         else {
-            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
-         }
-      }
-      tableReady = GL_TRUE;
-   }
-   return table[cs8];
-}
-
-
 /**********************************************************************/
 /*  Unpack, returning GLfloat colors                                  */
 /**********************************************************************/
@@ -645,7 +618,7 @@ unpack_R10G10B10A2_UINT(const void *src, GLfloat dst[][4], GLuint n)
 
 
 static void
-unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
+unpack_S8_UINT_Z24_UNORM(const void *src, GLfloat dst[][4], GLuint n)
 {
    /* only return Z, not stencil data */
    const GLuint *s = ((const GLuint *) src);
@@ -662,7 +635,7 @@ unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
 }
 
 static void
-unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
+unpack_Z24_UNORM_S8_UINT(const void *src, GLfloat dst[][4], GLuint n)
 {
    /* only return Z, not stencil data */
    const GLuint *s = ((const GLuint *) src);
@@ -679,7 +652,7 @@ unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
 }
 
 static void
-unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
+unpack_Z_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
 {
    const GLushort *s = ((const GLushort *) src);
    GLuint i;
@@ -692,19 +665,19 @@ unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
 }
 
 static void
-unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
+unpack_Z24_UNORM_X8_UINT(const void *src, GLfloat dst[][4], GLuint n)
 {
-   unpack_S8_Z24(src, dst, n);
+   unpack_Z24_UNORM_S8_UINT(src, dst, n);
 }
 
 static void
-unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
+unpack_X8_UINT_Z24_UNORM(const void *src, GLfloat dst[][4], GLuint n)
 {
-   unpack_Z24_S8(src, dst, n);
+   unpack_S8_UINT_Z24_UNORM(src, dst, n);
 }
 
 static void
-unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
+unpack_Z_UNORM32(const void *src, GLfloat dst[][4], GLuint n)
 {
    const GLuint *s = ((const GLuint *) src);
    GLuint i;
@@ -717,20 +690,20 @@ unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
 }
 
 static void
-unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
+unpack_Z32_FLOAT_S8X24_UINT(const void *src, GLfloat dst[][4], GLuint n)
 {
-   const GLfloat *s = ((const GLfloat *) src);
+   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
    GLuint i;
    for (i = 0; i < n; i++) {
       dst[i][0] =
       dst[i][1] =
-      dst[i][2] = s[i * 2];
+      dst[i][2] = s[i].z;
       dst[i][3] = 1.0F;
    }
 }
 
 static void
-unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
+unpack_Z_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
 {
    const GLfloat *s = ((const GLfloat *) src);
    GLuint i;
@@ -763,9 +736,9 @@ unpack_BGR_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
    const GLubyte *s = (const GLubyte *) src;
    GLuint i;
    for (i = 0; i < n; i++) {
-      dst[i][RCOMP] = _mesa_nonlinear_to_linear(s[i*3+2]);
-      dst[i][GCOMP] = _mesa_nonlinear_to_linear(s[i*3+1]);
-      dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i*3+0]);
+      dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+2]);
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+1]);
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i*3+0]);
       dst[i][ACOMP] = 1.0F;
    }
 }
@@ -776,9 +749,9 @@ unpack_A8B8G8R8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i] >> 24) );
-      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
-      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
+      dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 24) );
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >>  8) & 0xff );
       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
    }
 }
@@ -789,22 +762,35 @@ unpack_B8G8R8A8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
-      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
-      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
+      dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >>  8) & 0xff );
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i]      ) & 0xff );
       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
    }
 }
 
+static void
+unpack_A8R8G8B8_SRGB(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] = util_format_srgb_8unorm_to_linear_float( (s[i] >>  8) & 0xff );
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 24) );
+      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
+   }
+}
+
 static void
 unpack_R8G8B8A8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
-      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
-      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
+      dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i]      ) & 0xff );
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >>  8) & 0xff );
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
    }
 }
@@ -817,7 +803,7 @@ unpack_L_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
    for (i = 0; i < n; i++) {
       dst[i][RCOMP] = 
       dst[i][GCOMP] = 
-      dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]);
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i]);
       dst[i][ACOMP] = 1.0F;
    }
 }
@@ -830,11 +816,24 @@ unpack_L8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
    for (i = 0; i < n; i++) {
       dst[i][RCOMP] =
       dst[i][GCOMP] =
-      dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff);
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float(s[i] & 0xff);
       dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
    }
 }
 
+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)
 {
@@ -1707,19 +1706,6 @@ unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
    }
 }
 
-static void
-unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
-{
-   const GLbyte *s = (const GLbyte *) src;
-   GLuint i;
-   for (i = 0; i < n; i++) {
-      dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
-      dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
-      dst[i][BCOMP] = 0;
-      dst[i][ACOMP] = 0;
-   }
-}
-
 static void
 unpack_R_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
 {
@@ -2005,6 +1991,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)
 {
@@ -2119,7 +2119,7 @@ unpack_XRGB1555_UNORM(const void *src, GLfloat dst[][4], GLuint n)
 }
 
 static void
-unpack_XBGR8888_SNORM(const void *src, GLfloat dst[][4], GLuint n)
+unpack_R8G8B8X8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
 {
    const GLuint *s = ((const GLuint *) src);
    GLuint i;
@@ -2137,10 +2137,23 @@ unpack_R8G8B8X8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
-      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
-      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
-      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
+      dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i]      ) & 0xff );
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >>  8) & 0xff );
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+      dst[i][ACOMP] = 1.0f;
+   }
+}
+
+static void
+unpack_X8B8G8R8_SRGB(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] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 24) );
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >>  8) & 0xff );
+      dst[i][ACOMP] = 1.0f;
    }
 }
 
@@ -2332,9 +2345,22 @@ unpack_B8G8R8X8_SRGB(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] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
-      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
-      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
+      dst[i][RCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >>  8) & 0xff );
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i]      ) & 0xff );
+      dst[i][ACOMP] = 1.0F;
+   }
+}
+
+static void
+unpack_X8R8G8B8_SRGB(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] = util_format_srgb_8unorm_to_linear_float( (s[i] >>  8) & 0xff );
+      dst[i][GCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 16) & 0xff );
+      dst[i][BCOMP] = util_format_srgb_8unorm_to_linear_float( (s[i] >> 24) );
       dst[i][ACOMP] = 1.0F;
    }
 }
@@ -2391,19 +2417,21 @@ get_unpack_rgba_function(mesa_format format)
       table[MESA_FORMAT_B10G10R10A2_UNORM] = unpack_B10G10R10A2_UNORM;
       table[MESA_FORMAT_B10G10R10A2_UINT] = unpack_B10G10R10A2_UINT;
       table[MESA_FORMAT_R10G10B10A2_UINT] = unpack_R10G10B10A2_UINT;
-      table[MESA_FORMAT_S8_UINT_Z24_UNORM] = unpack_Z24_S8;
-      table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_S8_Z24;
-      table[MESA_FORMAT_Z_UNORM16] = unpack_Z16;
-      table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_X8_Z24;
-      table[MESA_FORMAT_X8_UINT_Z24_UNORM] = unpack_Z24_X8;
-      table[MESA_FORMAT_Z_UNORM32] = unpack_Z32;
+      table[MESA_FORMAT_S8_UINT_Z24_UNORM] = unpack_S8_UINT_Z24_UNORM;
+      table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_Z24_UNORM_S8_UINT;
+      table[MESA_FORMAT_Z_UNORM16] = unpack_Z_UNORM16;
+      table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_Z24_UNORM_X8_UINT;
+      table[MESA_FORMAT_X8_UINT_Z24_UNORM] = unpack_X8_UINT_Z24_UNORM;
+      table[MESA_FORMAT_Z_UNORM32] = unpack_Z_UNORM32;
       table[MESA_FORMAT_S_UINT8] = unpack_S8;
       table[MESA_FORMAT_BGR_SRGB8] = unpack_BGR_SRGB8;
       table[MESA_FORMAT_A8B8G8R8_SRGB] = unpack_A8B8G8R8_SRGB;
       table[MESA_FORMAT_B8G8R8A8_SRGB] = unpack_B8G8R8A8_SRGB;
+      table[MESA_FORMAT_A8R8G8B8_SRGB] = unpack_A8R8G8B8_SRGB;
       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;
@@ -2486,7 +2514,6 @@ get_unpack_rgba_function(mesa_format format)
       table[MESA_FORMAT_RGB_UINT32] = unpack_RGB_UINT32;
       table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
 
-      table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
       table[MESA_FORMAT_R_SNORM8] = unpack_R_SNORM8;
       table[MESA_FORMAT_R8G8_SNORM] = unpack_R8G8_SNORM;
       table[MESA_FORMAT_X8B8G8R8_SNORM] = unpack_X8B8G8R8_SNORM;
@@ -2524,6 +2551,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;
@@ -2533,13 +2561,14 @@ get_unpack_rgba_function(mesa_format format)
       table[MESA_FORMAT_R9G9B9E5_FLOAT] = unpack_R9G9B9E5_FLOAT;
       table[MESA_FORMAT_R11G11B10_FLOAT] = unpack_R11G11B10_FLOAT;
 
-      table[MESA_FORMAT_Z_FLOAT32] = unpack_Z32_FLOAT;
-      table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = unpack_Z32_FLOAT_X24S8;
+      table[MESA_FORMAT_Z_FLOAT32] = unpack_Z_FLOAT32;
+      table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = unpack_Z32_FLOAT_S8X24_UINT;
 
       table[MESA_FORMAT_B4G4R4X4_UNORM] = unpack_XRGB4444_UNORM;
       table[MESA_FORMAT_B5G5R5X1_UNORM] = unpack_XRGB1555_UNORM;
-      table[MESA_FORMAT_R8G8B8X8_SNORM] = unpack_XBGR8888_SNORM;
+      table[MESA_FORMAT_R8G8B8X8_SNORM] = unpack_R8G8B8X8_SNORM;
       table[MESA_FORMAT_R8G8B8X8_SRGB] = unpack_R8G8B8X8_SRGB;
+      table[MESA_FORMAT_X8B8G8R8_SRGB] = unpack_X8B8G8R8_SRGB;
       table[MESA_FORMAT_RGBX_UINT8] = unpack_XBGR8888_UINT;
       table[MESA_FORMAT_RGBX_SINT8] = unpack_XBGR8888_SINT;
       table[MESA_FORMAT_B10G10R10X2_UNORM] = unpack_B10G10R10X2_UNORM;
@@ -2558,6 +2587,7 @@ get_unpack_rgba_function(mesa_format format)
       table[MESA_FORMAT_G16R16_SNORM] = unpack_G16R16_SNORM;
 
       table[MESA_FORMAT_B8G8R8X8_SRGB] = unpack_B8G8R8X8_SRGB;
+      table[MESA_FORMAT_X8R8G8B8_SRGB] = unpack_X8R8G8B8_SRGB;
 
       initialized = GL_TRUE;
    }
@@ -3935,7 +3965,7 @@ _mesa_unpack_rgba_block(mesa_format format,
 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
 
 static void
-unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
+unpack_float_z_X8_UINT_Z24_UNORM(GLuint n, const void *src, GLfloat *dst)
 {
    /* only return Z, not stencil data */
    const GLuint *s = ((const GLuint *) src);
@@ -3949,7 +3979,7 @@ unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
 }
 
 static void
-unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
+unpack_float_z_Z24_UNORM_X8_UINT(GLuint n, const void *src, GLfloat *dst)
 {
    /* only return Z, not stencil data */
    const GLuint *s = ((const GLuint *) src);
@@ -3983,7 +4013,7 @@ unpack_float_Z_UNORM32(GLuint n, const void *src, GLfloat *dst)
 }
 
 static void
-unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
+unpack_float_Z_FLOAT32(GLuint n, const void *src, GLfloat *dst)
 {
    memcpy(dst, src, n * sizeof(float));
 }
@@ -4013,11 +4043,11 @@ _mesa_unpack_float_z_row(mesa_format format, GLuint n,
    switch (format) {
    case MESA_FORMAT_S8_UINT_Z24_UNORM:
    case MESA_FORMAT_X8_UINT_Z24_UNORM:
-      unpack = unpack_float_z_Z24_X8;
+      unpack = unpack_float_z_X8_UINT_Z24_UNORM;
       break;
    case MESA_FORMAT_Z24_UNORM_S8_UINT:
    case MESA_FORMAT_Z24_UNORM_X8_UINT:
-      unpack = unpack_float_z_X8_Z24;
+      unpack = unpack_float_z_Z24_UNORM_X8_UINT;
       break;
    case MESA_FORMAT_Z_UNORM16:
       unpack = unpack_float_Z_UNORM16;
@@ -4026,7 +4056,7 @@ _mesa_unpack_float_z_row(mesa_format format, GLuint n,
       unpack = unpack_float_Z_UNORM32;
       break;
    case MESA_FORMAT_Z_FLOAT32:
-      unpack = unpack_float_z_Z32F;
+      unpack = unpack_float_Z_FLOAT32;
       break;
    case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
       unpack = unpack_float_z_Z32X24S8;
@@ -4045,7 +4075,7 @@ _mesa_unpack_float_z_row(mesa_format format, GLuint n,
 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
 
 static void
-unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
+unpack_uint_z_X8_UINT_Z24_UNORM(const void *src, GLuint *dst, GLuint n)
 {
    /* only return Z, not stencil data */
    const GLuint *s = ((const GLuint *) src);
@@ -4056,7 +4086,7 @@ unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
 }
 
 static void
-unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
+unpack_uint_z_Z24_UNORM_X8_UINT(const void *src, GLuint *dst, GLuint n)
 {
    /* only return Z, not stencil data */
    const GLuint *s = ((const GLuint *) src);
@@ -4118,11 +4148,11 @@ _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
    switch (format) {
    case MESA_FORMAT_S8_UINT_Z24_UNORM:
    case MESA_FORMAT_X8_UINT_Z24_UNORM:
-      unpack = unpack_uint_z_Z24_X8;
+      unpack = unpack_uint_z_X8_UINT_Z24_UNORM;
       break;
    case MESA_FORMAT_Z24_UNORM_S8_UINT:
    case MESA_FORMAT_Z24_UNORM_X8_UINT:
-      unpack = unpack_uint_z_X8_Z24;
+      unpack = unpack_uint_z_Z24_UNORM_X8_UINT;
       break;
    case MESA_FORMAT_Z_UNORM16:
       unpack = unpack_uint_Z_UNORM16;
@@ -4147,13 +4177,13 @@ _mesa_unpack_uint_z_row(mesa_format format, GLuint n,
 
 
 static void
-unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
+unpack_ubyte_s_S_UINT8(const void *src, GLubyte *dst, GLuint n)
 {
    memcpy(dst, src, n);
 }
 
 static void
-unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
+unpack_ubyte_s_S8_UINT_Z24_UNORM(const void *src, GLubyte *dst, GLuint n)
 {
    GLuint i;
    const GLuint *src32 = src;
@@ -4163,7 +4193,7 @@ unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
 }
 
 static void
-unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
+unpack_ubyte_s_Z24_UNORM_S8_UINT(const void *src, GLubyte *dst, GLuint n)
 {
    GLuint i;
    const GLuint *src32 = src;
@@ -4173,7 +4203,7 @@ unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
 }
 
 static void
-unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
+unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, GLubyte *dst, GLuint n)
 {
    GLuint i;
    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
@@ -4188,16 +4218,16 @@ _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
 {
    switch (format) {
    case MESA_FORMAT_S_UINT8:
-      unpack_ubyte_s_S8(src, dst, n);
+      unpack_ubyte_s_S_UINT8(src, dst, n);
       break;
    case MESA_FORMAT_S8_UINT_Z24_UNORM:
-      unpack_ubyte_s_Z24_S8(src, dst, n);
+      unpack_ubyte_s_S8_UINT_Z24_UNORM(src, dst, n);
       break;
    case MESA_FORMAT_Z24_UNORM_S8_UINT:
-      unpack_ubyte_s_S8_Z24(src, dst, n);
+      unpack_ubyte_s_Z24_UNORM_S8_UINT(src, dst, n);
       break;
    case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
-      unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
+      unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(src, dst, n);
       break;
    default:
       _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
@@ -4207,7 +4237,7 @@ _mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
 }
 
 static void
-unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
+unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const GLuint *src, GLuint *dst, GLuint n)
 {
    GLuint i;
 
@@ -4233,7 +4263,7 @@ unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
 }
 
 static void
-unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
+unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const GLuint *src, GLuint *dst, GLuint n)
 {
    memcpy(dst, src, n * 4);
 }
@@ -4248,10 +4278,10 @@ _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
 {
    switch (format) {
    case MESA_FORMAT_S8_UINT_Z24_UNORM:
-      unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
+      unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(src, dst, n);
       break;
    case MESA_FORMAT_Z24_UNORM_S8_UINT:
-      unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
+      unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(src, dst, n);
       break;
    case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
       unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
@@ -4263,3 +4293,108 @@ _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
       return;
    }
 }
+
+static void
+unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const GLuint *src,
+                                            GLuint *dst, GLuint n)
+{
+   GLuint i;
+   struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
+   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
+
+   for (i = 0; i < n; i++) {
+      const GLuint z24 = src[i] & 0xffffff;
+      d[i].z = z24 * scale;
+      d[i].x24s8 = src[i] >> 24;
+      assert(d[i].z >= 0.0f);
+      assert(d[i].z <= 1.0f);
+   }
+}
+
+static void
+unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const GLuint *src,
+                                               GLuint *dst, GLuint n)
+{
+   memcpy(dst, src, n * sizeof(struct z32f_x24s8));
+}
+
+static void
+unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const GLuint *src,
+                                            GLuint *dst, GLuint n)
+{
+   GLuint i;
+   struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
+   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
+
+   for (i = 0; i < n; i++) {
+      const GLuint z24 = src[i] >> 8;
+      d[i].z = z24 * scale;
+      d[i].x24s8 = src[i] & 0xff;
+      assert(d[i].z >= 0.0f);
+      assert(d[i].z <= 1.0f);
+   }
+}
+
+/**
+ * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
+ * \param format  the source data format
+ *
+ * In GL_FLOAT_32_UNSIGNED_INT_24_8_REV lower 4 bytes contain float
+ * component and higher 4 bytes contain packed 24-bit and 8-bit
+ * components.
+ *
+ *    31 30 29 28 ... 4 3 2 1 0    31 30 29 ... 9 8 7 6 5 ... 2 1 0
+ *    +-------------------------+  +--------------------------------+
+ *    |    Float Component      |  | Unused         | 8 bit stencil |
+ *    +-------------------------+  +--------------------------------+
+ *          lower 4 bytes                  higher 4 bytes
+ */
+void
+_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
+                                                 const void *src, GLuint *dst)
+{
+   switch (format) {
+   case MESA_FORMAT_S8_UINT_Z24_UNORM:
+      unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(src, dst, n);
+      break;
+   case MESA_FORMAT_Z24_UNORM_S8_UINT:
+      unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(src, dst, n);
+      break;
+   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
+      unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(src, dst, n);
+      break;
+   default:
+      _mesa_problem(NULL,
+                    "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
+                    _mesa_get_format_name(format));
+      return;
+   }
+}
+
+/**
+ * Unpack depth/stencil
+ * \param format  the source data format
+ * \param type the destination data type
+ */
+void
+_mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
+                              const void *src, GLenum type,
+                               GLuint *dst)
+{
+   assert(type == GL_UNSIGNED_INT_24_8 ||
+          type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
+
+   switch (type) {
+   case GL_UNSIGNED_INT_24_8:
+      _mesa_unpack_uint_24_8_depth_stencil_row(format, n, src, dst);
+      break;
+   case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
+      _mesa_unpack_float_32_uint_24_8_depth_stencil_row(format, n, src, dst);
+      break;
+   default:
+      _mesa_problem(NULL,
+                    "bad type 0x%x in _mesa_unpack_depth_stencil_row",
+                    type);
+      return;
+   }
+}