[Mesa-dev] [PATCH v4 16/22] mesa: Add _mesa_pack_uint_rgba_row() format conversion function

Samuel Iglesias Gonsálvez siglesias at igalia.com
Fri Jan 9 02:39:57 PST 2015


On Thursday, January 08, 2015 08:20:55 AM Iago Toral Quiroga wrote:
> From: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
> 
> We will use this later on to handle uint conversion scenarios in a master
> convert function.
> 
> v2:
> - Modify pack_uint_*() function generation to use c.datatype() and
>   f.datatype().
> - Remove UINT_TO_FLOAT() macro usage from pack_uint*()
> - Remove "if not f.is_normalized()" conditional as pack_uint*()
>   functions are only autogenerated for non normalized formats.
> 
> v3:
> - Add clamping for non-normalized integer formats in pack_uint*()
> 
> Signed-off-by: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
> Reviewed-by: Jason Ekstrand <jason.ekstrand at intel.com>
> ---
>  src/mesa/main/format_pack.h  |  3 ++
>  src/mesa/main/format_pack.py | 84
> ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87
> insertions(+)
> 
> diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h
> index 2577def..1582ad1 100644
> --- a/src/mesa/main/format_pack.h
> +++ b/src/mesa/main/format_pack.h
> @@ -77,6 +77,9 @@ extern void
>  _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
>                            const GLubyte src[][4], void *dst);
> 
> +extern void
> +_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
> +                         const GLuint src[][4], void *dst);
> 
>  extern void
>  _mesa_pack_ubyte_rgba_rect(mesa_format format, GLuint width, GLuint height,
> diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py
> index cb347ab..3240d24 100644
> --- a/src/mesa/main/format_pack.py
> +++ b/src/mesa/main/format_pack.py
> @@ -160,6 +160,58 @@ pack_ubyte_r11g11b10_float(const GLubyte src[4], void
> *dst) *d = float3_to_r11g11b10f(rgb);
>  }
> 
> +/* uint packing functions */
> +
> +%for f in rgb_formats:
> +   %if not f.is_int():
> +      <% continue %>
> +   %elif f.is_normalized():
> +      <% continue %>
> +   %elif f.is_compressed():
> +      <% continue %>
> +   %endif
> +
> +static inline void
> +pack_uint_${f.short_name()}(const GLuint src[4], void *dst)
> +{
> +   %for (i, c) in enumerate(f.channels):
> +      <% i = f.swizzle.inverse()[i] %>
> +      %if c.type == 'x':
> +         <% continue %>
> +      %endif
> +
> +      ${c.datatype()} ${c.name} =
> +      %if c.type == parser.SIGNED:
> +         _mesa_signed_to_signed(src[${i}], ${c.size});

When fixing "mesa/format_pack: Add _mesa_pack_int_rgba_row()" patch I found an 
error here, it should be:

         _mesa_unsigned_to_signed(src[${i}], ${c.size});

I tested it with piglit and it gives no regressions.

Jason, if you agree with it, we will integrate this change before pushing the 
patch to master.

Sam 

> +      %elif c.type == parser.UNSIGNED:
> +         _mesa_unsigned_to_unsigned(src[${i}], ${c.size});
> +      %else:
> +         assert(!"Invalid type: only integer types are allowed");
> +      %endif
> +   %endfor
> +
> +   %if f.layout == parser.ARRAY:
> +      ${f.datatype()} *d = (${f.datatype()} *)dst;
> +      %for (i, c) in enumerate(f.channels):
> +         %if c.type == 'x':
> +            <% continue %>
> +         %endif
> +         d[${i}] = ${c.name};
> +      %endfor
> +   %elif f.layout == parser.PACKED:
> +      ${f.datatype()} d = 0;
> +      %for (i, c) in enumerate(f.channels):
> +         %if c.type == 'x':
> +            <% continue %>
> +         %endif
> +         d |= PACK(${c.name}, ${c.shift}, ${c.size});
> +      %endfor
> +      (*(${f.datatype()} *)dst) = d;
> +   %else:
> +      <% assert False %>
> +   %endif
> +}
> +%endfor
> 
>  /* float packing functions */
> 
> @@ -312,6 +364,38 @@ _mesa_pack_ubyte_rgba_row(mesa_format format, GLuint n,
> }
> 
>  /**
> + * Pack a row of GLuint rgba[4] values to the destination.
> + */
> +void
> +_mesa_pack_uint_rgba_row(mesa_format format, GLuint n,
> +                          const GLuint src[][4], void *dst)
> +{
> +   GLuint i;
> +   GLubyte *d = dst;
> +
> +   switch (format) {
> +%for f in rgb_formats:
> +   %if not f.is_int():
> +      <% continue %>
> +   %elif f.is_normalized():
> +      <% continue %>
> +   %elif f.is_compressed():
> +      <% continue %>
> +   %endif
> +
> +   case ${f.name}:
> +      for (i = 0; i < n; ++i) {
> +         pack_uint_${f.short_name()}(src[i], d);
> +         d += ${f.block_size() / 8};
> +      }
> +      break;
> +%endfor
> +   default:
> +      assert(!"Invalid format");
> +   }
> +}
> +
> +/**
>   * Pack a row of GLfloat rgba[4] values to the destination.
>   */
>  void
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150109/e07e6f45/attachment.sig>


More information about the mesa-dev mailing list