[Mesa-dev] [PATCH] mesa: fix software mipmap generation code for packed Z/stencil formats

2011-10-07 Thread Brian Paul
From: Brian Paul bri...@vmware.com

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=32458
---
 src/mesa/main/formats.c |8 
 src/mesa/main/mipmap.c  |   38 +-
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 02b2028..6307f8e 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -2075,13 +2075,13 @@ _mesa_format_to_type_and_comps(gl_format format,
   return;
 
case MESA_FORMAT_Z24_S8:
-  *datatype = GL_UNSIGNED_INT;
-  *comps = 1; /* XXX OK? */
+  *datatype = GL_UNSIGNED_INT_24_8_MESA;
+  *comps = 2;
   return;
 
case MESA_FORMAT_S8_Z24:
-  *datatype = GL_UNSIGNED_INT;
-  *comps = 1; /* XXX OK? */
+  *datatype = GL_UNSIGNED_INT_8_24_REV_MESA;
+  *comps = 2;
   return;
 
case MESA_FORMAT_Z16:
diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c
index f04a98b..46d71bb 100644
--- a/src/mesa/main/mipmap.c
+++ b/src/mesa/main/mipmap.c
@@ -43,7 +43,13 @@
 static GLint
 bytes_per_pixel(GLenum datatype, GLuint comps)
 {
-   GLint b = _mesa_sizeof_packed_type(datatype);
+   GLint b;
+
+   if (datatype == GL_UNSIGNED_INT_8_24_REV_MESA ||
+   datatype == GL_UNSIGNED_INT_24_8_MESA)
+  return 4;
+
+   b = _mesa_sizeof_packed_type(datatype);
assert(b = 0);
 
if (_mesa_type_is_packed(datatype))
@@ -717,6 +723,36 @@ do_row(GLenum datatype, GLuint comps, GLint srcWidth,
   }
}
 
+   else if (datatype == GL_UNSIGNED_INT_24_8_MESA  comps == 2) {
+  GLuint i, j, k;
+  const GLuint *rowA = (const GLuint *) srcRowA;
+  const GLuint *rowB = (const GLuint *) srcRowB;
+  GLuint *dst = (GLuint *) dstRow;
+  /* note: averaging stencil values seems weird, but what else? */
+  for (i = j = 0, k = k0; i  (GLuint) dstWidth;
+   i++, j += colStride, k += colStride) {
+ GLuint z = (((rowA[j]  8) + (rowA[k]  8) +
+  (rowB[j]  8) + (rowB[k]  8)) / 4)  8;
+ GLuint s = ((rowA[j]  0xff) + (rowA[k]  0xff) +
+ (rowB[j]  0xff) + (rowB[k]  0xff)) / 4;
+ dst[i] = z | s;
+  }
+   }
+   else if (datatype == GL_UNSIGNED_INT_8_24_REV_MESA  comps == 2) {
+  GLuint i, j, k;
+  const GLuint *rowA = (const GLuint *) srcRowA;
+  const GLuint *rowB = (const GLuint *) srcRowB;
+  GLuint *dst = (GLuint *) dstRow;
+  for (i = j = 0, k = k0; i  (GLuint) dstWidth;
+   i++, j += colStride, k += colStride) {
+ GLuint z = ((rowA[j]  0xff) + (rowA[k]  0xff) +
+ (rowB[j]  0xff) + (rowB[k]  0xff)) / 4;
+ GLuint s = (((rowA[j]  24) + (rowA[k]  24) +
+  (rowB[j]  24) + (rowB[k]  24)) / 4)  24;
+ dst[i] = z | s;
+  }
+   }
+
else {
   _mesa_problem(NULL, bad format in do_row());
}
-- 
1.7.3.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH] mesa: fix software mipmap generation code for packed Z/stencil formats

2011-10-07 Thread Chad Versace
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 10/07/2011 07:21 AM, Brian Paul wrote:
 From: Brian Paul bri...@vmware.com
 
 Fixes https://bugs.freedesktop.org/show_bug.cgi?id=32458
 ---
  src/mesa/main/formats.c |8 
  src/mesa/main/mipmap.c  |   38 +-
  2 files changed, 41 insertions(+), 5 deletions(-)

The arithmetic looks good to me.
Reviewed-by: Chad Versace c...@chad-versace.us

- -- 
Chad Versace
c...@chad-versace.us
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOjx8PAAoJEAIvNt057x8iWKYQAIoEkWtDRR3Jo6ncQndSwFYZ
L2jTqSFViCh1jmRZjdnX9F0S1TYNMdqPo8lxL0JkUcbzHPzIBnrKqlOfJ+qg3pJx
qTJkQhrcN3aHErMNyuNgI1Zq7Ue2iDzWYwitj7lLl9fJDf04qFLm1m0nsR6PW2V7
IH5wWm9o0F1jJ8SBixiR9i5yeXJZgj+dORCIcfKrl7E4tGI1KGLlzwIrUrUaJeGz
hZwOLRBIqI4iLXrOzS0up8dEiotEZK4nx3cifTQAKkL+EEYmKPiq4uQzkAFOr1Ad
VEQBM+F9TbaFT0hcUjHPMbjHqIvsp9meT/m86CDxH5H4AfSvDVPA6rixA21G1aA4
c1YmISqZ+moSmNCxNvhDZGbDeztfsyPikPYV2km8w1IbUlFBg5HABADmJPGj49+D
GMAqpsmIGVNuetR3pKaWcC3lfiOEFlGfhWMk1I54Xa55i570hjIzLz1aeA9eiX+w
1CnFsZctp4ZMgrpoW3073QgIpx2IE+EfacBNq6r6P8FXSQg2H+7hHmDaRgB9iEGx
9beSgyxTjcDqW5xyWT4NGsSqhM4PJqn/fUnbV24uPiR8tAfNTVmY+ce10OG3+74w
Qo2ba5wUMigK+EtyNmhN2zirTfry5ROd/zoOJmpZQomDpuj/Id+QKHyVVsejlQiw
upjpLt21JBboDi0Uqcw6
=sWqy
-END PGP SIGNATURE-
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev