[Mesa-stable] [PATCH V3 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
Wed Mar 26 10:48:49 PDT 2014


On Wed, Mar 26, 2014 at 7:13 AM, Brian Paul <brianp at vmware.com> wrote:
> On 03/25/2014 06:01 PM, Anuj Phogat wrote:
>>
>> V2: Follow the new naming convention for unpack functions.
>>      Use double precision for converting Z24 to a float.
>>
>> V3: Unpack stencil value to most significant byte.
>>      Use 'struct z32f_x24s8' type.
>>
>> Cc: <mesa-stable at lists.freedesktop.org>
>> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
>> ---
>>   src/mesa/main/format_unpack.c | 80
>> ++++++++++++++++++++++++++++++++++++++++++-
>>   src/mesa/main/format_unpack.h |  5 +++
>>   2 files changed, 84 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c
>> index 7abbe46..6e6bed8 100644
>> --- a/src/mesa/main/format_unpack.c
>> +++ b/src/mesa/main/format_unpack.c
>> @@ -4264,6 +4264,80 @@
>> _mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
>>      }
>>   }
>>
>> +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] & 0xff000000;
>> +      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)
>> +{
>> +   GLuint i;
>> +   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
>> +   struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
>> +
>> +   for (i = 0; i < n; i++) {
>> +      d[i].z = s[i].z;
>> +      d[i].x24s8 = (s[i].x24s8 & 0xff) << 24;
>> +   }
>> +}
>> +
>> +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) << 24;
>> +      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
>> + */
>> +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
>> @@ -4274,12 +4348,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);
>>
>
> One last question.  My reading of GL_NV_depth_buffer_float is that the
> stencil byte goes in the least significant position of the uint, not the
> most significant position.  Is MSB the Intel/gen convention?
>
You're right again. I'm fooled by an application data to think otherwise.
And I'm unable to reproduce it now :(. I will post a new patch with this
issue fixed.

> Maybe we should have a comment on
> _mesa_unpack_float_32_uint_24_8_depth_stencil_row() just to make it clear
> where the stencil byte winds up.
I'll also add a comment to avoid any confusion in future.
>
> Thanks.
>
> -Brian
>
>
> _______________________________________________
> mesa-stable mailing list
> mesa-stable at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-stable


More information about the mesa-stable mailing list