[Mesa-dev] [PATCH v3 18/24] mesa/format_pack: Add _mesa_pack_int_rgba_row()

Samuel Iglesias Gonsálvez siglesias at igalia.com
Mon Dec 15 03:31:55 PST 2014


On Thursday, December 11, 2014 11:43:26 AM Jason Ekstrand wrote:
> On Tue, Dec 9, 2014 at 4:07 AM, Iago Toral Quiroga <itoral at igalia.com>
> 
> wrote:
> > From: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
> > 
> > This will be used to unify code in pack.c.
> > 
> > v2:
> > - Modify pack_int_*() function generator to use c.datatype() and
> > 
> >   f.datatype()
> > 
> > Signed-off-by: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
> > ---
> > 
> >  src/mesa/main/format_pack.h  |   3 ++
> >  src/mesa/main/format_pack.py | 121
> > 
> > +++++++++++++++++++++++++++++++++++++++++++
> > 
> >  2 files changed, 124 insertions(+)
> > 
> > diff --git a/src/mesa/main/format_pack.h b/src/mesa/main/format_pack.h
> > index 1582ad1..6087fc3 100644
> > --- a/src/mesa/main/format_pack.h
> > +++ b/src/mesa/main/format_pack.h
> > @@ -68,6 +68,9 @@ extern gl_pack_ubyte_stencil_func
> > 
> >  _mesa_get_pack_ubyte_stencil_func(mesa_format format);
> > 
> > +extern void
> > +_mesa_pack_int_rgba_row(mesa_format format, GLuint n,
> > +                          const GLint src[][4], void *dst);
> > 
> >  extern void
> >  _mesa_pack_float_rgba_row(mesa_format format, GLuint n,
> > 
> > diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py
> > index afb5011..487dc39 100644
> > --- a/src/mesa/main/format_pack.py
> > +++ b/src/mesa/main/format_pack.py
> > @@ -213,6 +213,99 @@ pack_uint_${f.short_name()}(const GLuint src[4], void
> > *dst)
> > 
> >  }
> >  %endfor
> > 
> > +/* int packing functions */
> > +
> > +%for f in rgb_formats:
> > +   %if f.name in ('MESA_FORMAT_R9G9B9E5_FLOAT',
> > 'MESA_FORMAT_R11G11B10_FLOAT'):
> > +      <% continue %>
> > +   %elif f.is_compressed():
> > +      <% continue %>
> > +   %endif
> > +
> > +static inline void
> > +pack_int_${f.short_name()}(const GLint 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 not f.is_normalized():
> > +         %if c.type == parser.FLOAT and c.size == 32:
> > +            INT_TO_FLOAT(src[${i}]);
> > +         %elif c.type == parser.FLOAT and c.size == 16:
> > +            _mesa_float_to_half(INT_TO_FLOAT(src[${i}]));
> > +         %else:
> > +            (${c.datatype()}) src[${i}];
> > +         %endif
> 
> > +      %elif c.type == parser.UNSIGNED:
> Any particular reason we're even allowing normalized formats here?  We
> don't in the unpack version.
> 

No reason. I will update the patch.

Thanks,

Sam

> > +         %if f.colorspace == 'srgb' and c.name in 'rgb':
> > +            util_format_linear_to_srgb_8unorm(src[${i}]);
> > +         %else:
> > +            CLAMP(src[${i}], 0, MAX_UINT(${c.size}));
> > +         %endif
> > +      %elif c.type == parser.SIGNED:
> > +         CLAMP(src[${i}], 0,  MAX_UINT(${c.size}));
> > +      %elif c.type == parser.FLOAT:
> > +         %if c.size == 32:
> > +            _mesa_snorm_to_float(src[${i}], 8);
> > +         %elif c.size == 16:
> > +            _mesa_snorm_to_half(src[${i}], 8);
> > +         %else:
> > +            <% assert False %>
> > +         %endif
> > +      %else:
> > +         <% assert False %>
> > +      %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
> > +
> > +static inline void
> > +pack_int_r9g9b9e5_float(const GLint src[4], void *dst)
> > +{
> > +   GLuint *d = (GLuint *) dst;
> > +   GLfloat rgb[3];
> > +   rgb[0] = _mesa_snorm_to_float(src[RCOMP], 8);
> > +   rgb[1] = _mesa_snorm_to_float(src[GCOMP], 8);
> > +   rgb[2] = _mesa_snorm_to_float(src[BCOMP], 8);
> > +   *d = float3_to_rgb9e5(rgb);
> > +}
> > +
> > +static inline void
> > +pack_int_r11g11b10_float(const GLint src[4], void *dst)
> > +{
> > +   GLuint *d = (GLuint *) dst;
> > +   GLfloat rgb[3];
> > +   rgb[0] = _mesa_snorm_to_float(src[RCOMP], 8);
> > +   rgb[1] = _mesa_snorm_to_float(src[GCOMP], 8);
> > +   rgb[2] = _mesa_snorm_to_float(src[BCOMP], 8);
> > +   *d = float3_to_r11g11b10f(rgb);
> > +}
> > +
> > 
> >  /* float packing functions */
> > 
> >  %for f in rgb_formats:
> > @@ -392,6 +485,34 @@ _mesa_pack_uint_rgba_row(mesa_format format, GLuint
> > n,
> > 
> >  }
> >  
> >  /**
> > 
> > + * Pack a row of GLint rgba[4] values to the destination.
> > + */
> > +void
> > +_mesa_pack_int_rgba_row(mesa_format format, GLuint n,
> > +                          const GLint src[][4], void *dst)
> > +{
> > +   GLuint i;
> > +   GLubyte *d = dst;
> > +
> > +   switch (format) {
> > +%for f in rgb_formats:
> > +   %if f.is_compressed():
> > +      <% continue %>
> > +   %endif
> > +
> > +   case ${f.name}:
> > +      for (i = 0; i < n; ++i) {
> > +         pack_int_${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
> > 
> > --
> > 1.9.1
> > 
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- 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/20141215/cf0df481/attachment.sig>


More information about the mesa-dev mailing list