[Mesa-dev] [PATCH v2 10/23] mesa: Add a concept of an array format

Iago Toral itoral at igalia.com
Thu Dec 4 00:17:54 PST 2014


On Wed, 2014-12-03 at 14:58 -0800, Jason Ekstrand wrote:
> 
> 
> On Wed, Dec 3, 2014 at 2:52 PM, Ian Romanick <idr at freedesktop.org>
> wrote:
>         On 12/01/2014 03:04 AM, Iago Toral Quiroga wrote:
>         > From: Jason Ekstrand <jason.ekstrand at intel.com>
(...)
>         
>         >
>         > +enum mesa_array_format_datatype {
>         > +   MESA_ARRAY_FORMAT_TYPE_UBYTE = 0x0,
>         > +   MESA_ARRAY_FORMAT_TYPE_USHORT = 0x1,
>         > +   MESA_ARRAY_FORMAT_TYPE_UINT = 0x2,
>         > +   MESA_ARRAY_FORMAT_TYPE_BYTE = 0x4,
>         > +   MESA_ARRAY_FORMAT_TYPE_SHORT = 0x5,
>         > +   MESA_ARRAY_FORMAT_TYPE_INT = 0x6,
>         > +   MESA_ARRAY_FORMAT_TYPE_HALF = 0xd,
>         > +   MESA_ARRAY_FORMAT_TYPE_FLOAT = 0xe,
>         > +};
>         > +
>         > +#define MESA_ARRAY_FORMAT_TYPE_IS_SIGNED 0x4
>         > +#define MESA_ARRAY_FORMAT_TYPE_IS_FLOAT 0x8
>         > +#define MESA_ARRAY_FORMAT_BIT 0x80000000
>         
>         This...
>         
>         > +
>         > +typedef union {
>         > +   struct {
>         > +      enum mesa_array_format_datatype type:4;
>         > +      bool normalized:1;
>         > +      unsigned num_channels:3;
>         > +      unsigned swizzle_x:3;
>         > +      unsigned swizzle_y:3;
>         > +      unsigned swizzle_z:3;
>         > +      unsigned swizzle_w:3;
>         > +      unsigned pad:11;
>         > +      unsigned array_format_bit:1; /* Must always be 1 */
>         
>         ...and this are not correct on big-endian.
> 
> 
> Bah!  I originally did this as a bitfield in a uint32_t and then
> decided that the union was easier.  Probably best to go back to the
> bitfield...

Wouldn't it be enough to rewrite the 3 definitions like this?:

#define MESA_ARRAY_FORMAT_BIT (_mesa_little_endian() ?  0x80000000 :
0x00000080)

We can also go back to making mesa_array_format a plain uint32_t
bitflied, but that change would also require to rework
_mesa_format_convert and the GL -> mesa_(array)_format helper at least.
Not that it can't be done of course, but I wonder if it is necessary.

Iago

>  
>         
>         > +   };
>         > +   uint32_t as_uint;
>         > +} mesa_array_format;
>         > +
>         > +static const mesa_array_format _mesa_array_format_none = {{
>         > +   MESA_ARRAY_FORMAT_TYPE_UBYTE,
>         > +   0, 0, 0, 0, 0, 0, 0, 0
>         > +}};
>         > +
>         > +static inline unsigned
>         > +_mesa_ilog2(unsigned x)
>         > +{
>         > +   uint8_t i;
>         
>         I'd either make this unsigned or uint_fast8_t... I'd bet that
>         it doesn't
>         make any difference.
>         
>         > +   for (i = 1; i < 32; ++i)
>         > +      if (x <= (1u << i))
>         > +         return i;
>         > +   return 32;
>         > +}
>         > +
>         > +#define MESA_ARRAY_FORMAT_TYPE(SIZE, SIGNED, IS_FLOAT,
>         NORM) (     \
>         > +   ((_mesa_ilog2(SIZE)) & MESA_ARRAY_FORMAT_TYPE_SIZE_MASK)
>         |      \
>         > +   (((SIGNED)    << 2 ) & MESA_ARRAY_FORMAT_TYPE_IS_SIGNED)
>         |      \
>         > +   (((IS_FLOAT)  << 3 ) & MESA_ARRAY_FORMAT_TYPE_IS_FLOAT)
>         > +
>         > +static inline int
>         > +_mesa_array_format_datatype_size(enum
>         mesa_array_format_datatype type)
>         > +{
>         > +   return 1 << (type & 0x3);
>         > +}
>         >  /**
>         >   * Mesa texture/renderbuffer image formats.
>         >   */
>         > @@ -469,6 +525,12 @@ _mesa_get_format_block_size(mesa_format
>         format, GLuint *bw, GLuint *bh);
>         >  extern void
>         >  _mesa_get_format_swizzle(mesa_format format, uint8_t
>         swizzle_out[4]);
>         >
>         > +extern uint32_t
>         > +_mesa_format_to_array_format(mesa_format format);
>         > +
>         > +extern mesa_format
>         > +_mesa_format_from_array_format(uint32_t array_format);
>         > +
>         >  extern GLboolean
>         >  _mesa_is_format_compressed(mesa_format format);
>         >
>         >
>         
>         
>         _______________________________________________
>         mesa-dev mailing list
>         mesa-dev at lists.freedesktop.org
>         http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>         
> 
> 




More information about the mesa-dev mailing list