[Mesa-dev] [PATCH 09/10] mesa: Add support to unpack depth-stencil texture in to FLOAT_32_UNSIGNED_INT_24_8_REV

Anuj Phogat anuj.phogat at gmail.com
Fri Mar 21 15:01:41 PDT 2014


Cc: <mesa-stable at lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 src/mesa/main/format_unpack.c | 79 ++++++++++++++++++++++++++++++++++++++++++-
 src/mesa/main/format_unpack.h |  5 +++
 2 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
index 7abbe46..1725f10 100644
--- a/src/mesa/main/format_unpack.c
+++ b/src/mesa/main/format_unpack.c
@@ -4264,6 +4264,79 @@ _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
    }
 }
 
+static void
+unpack_float_32_uint_24_8_depth_stencil_S8_Z24(const GLuint *src,
+                                               GLuint *dst, GLuint n)
+{
+   GLuint i;
+
+   for (i = 0; i < n; i++) {
+      GLuint val = src[i];
+      GLuint z24 = val & 0xffffff;
+      GLfloat zf = z24 * (1.0F / 0xffffff);
+      GLuint s = val & 0xff000000;
+      ((GLfloat *) dst)[i * 2 + 0] = zf;
+      dst[i * 2 + 1] = s;
+   }
+}
+
+static void
+unpack_float_32_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
+                                                  GLuint *dst, GLuint n)
+{
+   GLuint i;
+
+   for (i = 0; i < n; i++) {
+      /* 8 bytes per pixel (float + uint32) */
+      GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
+      GLuint s = src[i * 2 + 1] & 0xff;
+      ((GLfloat *) dst)[i * 2 + 0] = zf;
+      dst[i * 2 + 1] = s;
+   }
+}
+
+static void
+unpack_float_32_uint_24_8_depth_stencil_Z24_S8(const GLuint *src,
+                                               GLuint *dst, GLuint n)
+{
+   GLuint i;
+
+   for (i = 0; i < n; i++) {
+      GLuint val = src[i];
+      GLuint z24 = (val >> 8);
+      GLfloat zf = z24 * (1.0F / 0xffffff);
+      GLuint s = val & 0xff;
+      ((GLfloat *) dst)[i * 2 + 0] = zf;
+      dst[i * 2 + 1] = s << 24;
+   }
+}
+
+/**
+ * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
+ * \param format  the source data format
+ */
+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_depth_stencil_Z24_S8(src, dst, n);
+      break;
+   case MESA_FORMAT_Z24_UNORM_S8_UINT:
+      unpack_float_32_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
+      break;
+   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
+      unpack_float_32_uint_24_8_depth_stencil_Z32_S8X24(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
@@ -4274,12 +4347,16 @@ _mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
 	                       const void *src, GLenum type,
                                GLuint *dst)
 {
-   assert(type == GL_UNSIGNED_INT_24_8);
+   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",
diff --git a/src/mesa/main/format_unpack.h b/src/mesa/main/format_unpack.h
index 5904a28..51f97df 100644
--- a/src/mesa/main/format_unpack.h
+++ b/src/mesa/main/format_unpack.h
@@ -64,6 +64,11 @@ _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
 					 const void *src, GLuint *dst);
 
 void
+_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format,
+                                                  GLuint n,
+                                                  const void *src,
+                                                  GLuint *dst);
+void
 _mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
                               const void *src, GLenum type,
                               GLuint *dst);
-- 
1.8.3.1



More information about the mesa-dev mailing list