Re: [Mesa-dev] [PATCH 01/29] mesa: Add an implementation of a master convert function.

2014-11-21 Thread Iago Toral
On Fri, 2014-11-21 at 17:40 +0900, Michel Dänzer wrote:
> On 21.11.2014 17:07, Iago Toral wrote:
> > On Thu, 2014-11-20 at 11:10 -0800, Jason Ekstrand wrote:
> >> On Thu, Nov 20, 2014 at 1:48 AM, Iago Toral  wrote:
> >>  Just out of curiosity: is there any gain in avoiding the GL
> >>  types in the
> >>  conversion code?
> >>
> >>
> >> As I said in my reply to Jose on the 00/20 patch, we would like to
> >> eventually move the format conversion stuff to a common helper library
> >> that can be shared by mesa main and the gallium code.  If we are going
> >> to do that, then we don't want any GL dependencies.
> >
> > Yes, I know, I was just wondering why Mesa and Gallium would need/want
> > to avoid the GL dependencies in that helper library, since clients of
> > that library would usually be things like glTexImage or glReadPixels and
> > these deal with GL types.
> 
> Since OpenGL is only one out of many APIs provided by state trackers on 
> top of Gallium (some of which have nothing to do with OpenGL), code 
> below the Gallium interface using GL types directly is a layering violation.

Aha, I see now. That makes sense.
Thanks for the explanation!

Iago


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


Re: [Mesa-dev] [PATCH 01/29] mesa: Add an implementation of a master convert function.

2014-11-21 Thread Michel Dänzer

On 21.11.2014 17:07, Iago Toral wrote:

On Thu, 2014-11-20 at 11:10 -0800, Jason Ekstrand wrote:

On Thu, Nov 20, 2014 at 1:48 AM, Iago Toral  wrote:
 Just out of curiosity: is there any gain in avoiding the GL
 types in the
 conversion code?


As I said in my reply to Jose on the 00/20 patch, we would like to
eventually move the format conversion stuff to a common helper library
that can be shared by mesa main and the gallium code.  If we are going
to do that, then we don't want any GL dependencies.


Yes, I know, I was just wondering why Mesa and Gallium would need/want
to avoid the GL dependencies in that helper library, since clients of
that library would usually be things like glTexImage or glReadPixels and
these deal with GL types.


Since OpenGL is only one out of many APIs provided by state trackers on 
top of Gallium (some of which have nothing to do with OpenGL), code 
below the Gallium interface using GL types directly is a layering violation.



--
Earthling Michel Dänzer   |   http://www.amd.com
Libre software enthusiast | Mesa and X developer
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 01/29] mesa: Add an implementation of a master convert function.

2014-11-21 Thread Iago Toral
On Thu, 2014-11-20 at 11:10 -0800, Jason Ekstrand wrote:
> 
> 
> On Thu, Nov 20, 2014 at 1:48 AM, Iago Toral  wrote:
> On Wed, 2014-11-19 at 11:28 -0800, Jason Ekstrand wrote:
> > By and large, this looks good to me.  Most of my comments
> are cosmetic
> > or suggestions for added documentation.  There is one issue
> that I
> > think is subtly wrong with integer format conversion but
> that should
> > be easy to fix.
> >
> > --Jason
> >
> > On Tue, Nov 18, 2014 at 1:23 AM, Iago Toral Quiroga
> >  wrote:
> > From: Jason Ekstrand 
> >
> > v2 by Iago Toral :
> >
> > - When testing if we can directly pack we should use
> the src
> > format to check
> >   if we are packing from an RGBA format. The
> original code
> > used the dst format
> >   for the ubyte case by mistake.
> > - Fixed incorrect number of bits for dst, it was
> computed
> > using the src format
> >   instead of the dst format.
> > - If the dst format is an array format, check if it
> is signed.
> > We were only
> >   checking this for the case where it was not an
> array format,
> > but we need
> >   to know this in both scenarios.
> > - Fixed incorrect swizzle transform for the cases
> where we
> > convert between
> >   array formats.
> > - Compute is_signed and bits only once and for the
> dst format.
> > We were
> >   computing these for the src format too but they
> were
> > overwritten by the
> >   dst values immediately after.
> > - Be more careful when selecting the integer path.
> > Specifically, check that
> >   both src and dst are integer types. Checking only
> one of
> > them should suffice
> >   since OpenGL does not allow conversions between
> normalized
> > and integer types,
> >   but putting extra care here makes sense and also
> makes the
> > actual requirements
> >   for this path more clear.
> > - The format argument for pack functions is the
> destination
> > format we are
> >   packing to, not the source format (which has to be
> RGBA).
> > - Expose RGBA_* to other files. These will come
> in handy
> > when in need to
> >   test if a given array format is RGBA or in need to
> pass RGBA
> > formats to
> >   mesa_format_convert.
> >
> > v3 by Samuel Iglesias :
> >
> > - Add an RGBA_INT definition.
> > ---
> >  src/mesa/main/format_utils.c | 378
> > +++
> >  src/mesa/main/format_utils.h |  10 ++
> >  src/mesa/main/formats.h  |  15 +-
> >  3 files changed, 399 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/mesa/main/format_utils.c
> > b/src/mesa/main/format_utils.c
> > index fcbbba4..c3815cb 100644
> > --- a/src/mesa/main/format_utils.c
> > +++ b/src/mesa/main/format_utils.c
> > @@ -25,6 +25,384 @@
> >  #include "format_utils.h"
> >  #include "glformats.h"
> >  #include "macros.h"
> > +#include "format_pack.h"
> > +#include "format_unpack.h"
> > +
> > +mesa_array_format RGBA_FLOAT = {{
> > +   MESA_ARRAY_FORMAT_TYPE_FLOAT,
> > +   0,
> > +   4,
> > +   0, 1, 2, 3,
> > +   0, 1
> > +}};
> > +
> > +mesa_array_format RGBA_UBYTE = {{
> > +   MESA_ARRAY_FORMAT_TYPE_UBYTE,
> > +   1,
> > +   4,
> > +   0, 1, 2, 3,
> > +   0, 1
> > +}};
> > +
> > +mesa_array_format RGBA_UINT = {{
> > +   MESA_ARRAY_FORMAT_TYPE_UINT,
> > +   0,
> > +   4,
> > +   0, 1, 2, 3,
> > +   0, 1
> > +}};
> > +
> > +mesa_array_format RGBA_INT = {{
> > +   MESA_ARRAY_FORMAT_TYPE_

Re: [Mesa-dev] [PATCH 01/29] mesa: Add an implementation of a master convert function.

2014-11-20 Thread Jason Ekstrand
On Thu, Nov 20, 2014 at 1:48 AM, Iago Toral  wrote:

> On Wed, 2014-11-19 at 11:28 -0800, Jason Ekstrand wrote:
> > By and large, this looks good to me.  Most of my comments are cosmetic
> > or suggestions for added documentation.  There is one issue that I
> > think is subtly wrong with integer format conversion but that should
> > be easy to fix.
> >
> > --Jason
> >
> > On Tue, Nov 18, 2014 at 1:23 AM, Iago Toral Quiroga
> >  wrote:
> > From: Jason Ekstrand 
> >
> > v2 by Iago Toral :
> >
> > - When testing if we can directly pack we should use the src
> > format to check
> >   if we are packing from an RGBA format. The original code
> > used the dst format
> >   for the ubyte case by mistake.
> > - Fixed incorrect number of bits for dst, it was computed
> > using the src format
> >   instead of the dst format.
> > - If the dst format is an array format, check if it is signed.
> > We were only
> >   checking this for the case where it was not an array format,
> > but we need
> >   to know this in both scenarios.
> > - Fixed incorrect swizzle transform for the cases where we
> > convert between
> >   array formats.
> > - Compute is_signed and bits only once and for the dst format.
> > We were
> >   computing these for the src format too but they were
> > overwritten by the
> >   dst values immediately after.
> > - Be more careful when selecting the integer path.
> > Specifically, check that
> >   both src and dst are integer types. Checking only one of
> > them should suffice
> >   since OpenGL does not allow conversions between normalized
> > and integer types,
> >   but putting extra care here makes sense and also makes the
> > actual requirements
> >   for this path more clear.
> > - The format argument for pack functions is the destination
> > format we are
> >   packing to, not the source format (which has to be RGBA).
> > - Expose RGBA_* to other files. These will come in handy
> > when in need to
> >   test if a given array format is RGBA or in need to pass RGBA
> > formats to
> >   mesa_format_convert.
> >
> > v3 by Samuel Iglesias :
> >
> > - Add an RGBA_INT definition.
> > ---
> >  src/mesa/main/format_utils.c | 378
> > +++
> >  src/mesa/main/format_utils.h |  10 ++
> >  src/mesa/main/formats.h  |  15 +-
> >  3 files changed, 399 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/mesa/main/format_utils.c
> > b/src/mesa/main/format_utils.c
> > index fcbbba4..c3815cb 100644
> > --- a/src/mesa/main/format_utils.c
> > +++ b/src/mesa/main/format_utils.c
> > @@ -25,6 +25,384 @@
> >  #include "format_utils.h"
> >  #include "glformats.h"
> >  #include "macros.h"
> > +#include "format_pack.h"
> > +#include "format_unpack.h"
> > +
> > +mesa_array_format RGBA_FLOAT = {{
> > +   MESA_ARRAY_FORMAT_TYPE_FLOAT,
> > +   0,
> > +   4,
> > +   0, 1, 2, 3,
> > +   0, 1
> > +}};
> > +
> > +mesa_array_format RGBA_UBYTE = {{
> > +   MESA_ARRAY_FORMAT_TYPE_UBYTE,
> > +   1,
> > +   4,
> > +   0, 1, 2, 3,
> > +   0, 1
> > +}};
> > +
> > +mesa_array_format RGBA_UINT = {{
> > +   MESA_ARRAY_FORMAT_TYPE_UINT,
> > +   0,
> > +   4,
> > +   0, 1, 2, 3,
> > +   0, 1
> > +}};
> > +
> > +mesa_array_format RGBA_INT = {{
> > +   MESA_ARRAY_FORMAT_TYPE_INT,
> > +   0,
> > +   4,
> > +   0, 1, 2, 3,
> > +   0, 1
> > +}};
> > +
> > +static void
> > +invert_swizzle(uint8_t dst[4], const uint8_t src[4])
> > +{
> > +   int i, j;
> > +
> > +   dst[0] = MESA_FORMAT_SWIZZLE_NONE;
> > +   dst[1] = MESA_FORMAT_SWIZZLE_NONE;
> > +   dst[2] = MESA_FORMAT_SWIZZLE_NONE;
> > +   dst[3] = MESA_FORMAT_SWIZZLE_NONE;
> > +
> > +   for (i = 0; i < 4; ++i)
> > +  for (j = 0; j < 4; ++j)
> > + if (src[j] == i && dst[i] ==
> > MESA_FORMAT_SWIZZLE_NONE)
> > +dst[i] = j;
> > +}
> > +
> > +static GLenum
> > +gl_type_for_array_format_datatype(enum
> > mesa_array_format_datatype type)
> > +{
> > +   switch (type) {
> > +   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
> > +  return GL_UNSIGNED_BYTE;
> > +   case MESA_ARRAY_FORMAT_TYPE_USHORT:
> >  

Re: [Mesa-dev] [PATCH 01/29] mesa: Add an implementation of a master convert function.

2014-11-20 Thread Iago Toral
On Wed, 2014-11-19 at 11:28 -0800, Jason Ekstrand wrote:
> By and large, this looks good to me.  Most of my comments are cosmetic
> or suggestions for added documentation.  There is one issue that I
> think is subtly wrong with integer format conversion but that should
> be easy to fix.
> 
> --Jason
> 
> On Tue, Nov 18, 2014 at 1:23 AM, Iago Toral Quiroga
>  wrote:
> From: Jason Ekstrand 
> 
> v2 by Iago Toral :
> 
> - When testing if we can directly pack we should use the src
> format to check
>   if we are packing from an RGBA format. The original code
> used the dst format
>   for the ubyte case by mistake.
> - Fixed incorrect number of bits for dst, it was computed
> using the src format
>   instead of the dst format.
> - If the dst format is an array format, check if it is signed.
> We were only
>   checking this for the case where it was not an array format,
> but we need
>   to know this in both scenarios.
> - Fixed incorrect swizzle transform for the cases where we
> convert between
>   array formats.
> - Compute is_signed and bits only once and for the dst format.
> We were
>   computing these for the src format too but they were
> overwritten by the
>   dst values immediately after.
> - Be more careful when selecting the integer path.
> Specifically, check that
>   both src and dst are integer types. Checking only one of
> them should suffice
>   since OpenGL does not allow conversions between normalized
> and integer types,
>   but putting extra care here makes sense and also makes the
> actual requirements
>   for this path more clear.
> - The format argument for pack functions is the destination
> format we are
>   packing to, not the source format (which has to be RGBA).
> - Expose RGBA_* to other files. These will come in handy
> when in need to
>   test if a given array format is RGBA or in need to pass RGBA
> formats to
>   mesa_format_convert.
> 
> v3 by Samuel Iglesias :
> 
> - Add an RGBA_INT definition.
> ---
>  src/mesa/main/format_utils.c | 378
> +++
>  src/mesa/main/format_utils.h |  10 ++
>  src/mesa/main/formats.h  |  15 +-
>  3 files changed, 399 insertions(+), 4 deletions(-)
> 
> diff --git a/src/mesa/main/format_utils.c
> b/src/mesa/main/format_utils.c
> index fcbbba4..c3815cb 100644
> --- a/src/mesa/main/format_utils.c
> +++ b/src/mesa/main/format_utils.c
> @@ -25,6 +25,384 @@
>  #include "format_utils.h"
>  #include "glformats.h"
>  #include "macros.h"
> +#include "format_pack.h"
> +#include "format_unpack.h"
> +
> +mesa_array_format RGBA_FLOAT = {{
> +   MESA_ARRAY_FORMAT_TYPE_FLOAT,
> +   0,
> +   4,
> +   0, 1, 2, 3,
> +   0, 1
> +}};
> +
> +mesa_array_format RGBA_UBYTE = {{
> +   MESA_ARRAY_FORMAT_TYPE_UBYTE,
> +   1,
> +   4,
> +   0, 1, 2, 3,
> +   0, 1
> +}};
> +
> +mesa_array_format RGBA_UINT = {{
> +   MESA_ARRAY_FORMAT_TYPE_UINT,
> +   0,
> +   4,
> +   0, 1, 2, 3,
> +   0, 1
> +}};
> +
> +mesa_array_format RGBA_INT = {{
> +   MESA_ARRAY_FORMAT_TYPE_INT,
> +   0,
> +   4,
> +   0, 1, 2, 3,
> +   0, 1
> +}};
> +
> +static void
> +invert_swizzle(uint8_t dst[4], const uint8_t src[4])
> +{
> +   int i, j;
> +
> +   dst[0] = MESA_FORMAT_SWIZZLE_NONE;
> +   dst[1] = MESA_FORMAT_SWIZZLE_NONE;
> +   dst[2] = MESA_FORMAT_SWIZZLE_NONE;
> +   dst[3] = MESA_FORMAT_SWIZZLE_NONE;
> +
> +   for (i = 0; i < 4; ++i)
> +  for (j = 0; j < 4; ++j)
> + if (src[j] == i && dst[i] ==
> MESA_FORMAT_SWIZZLE_NONE)
> +dst[i] = j;
> +}
> +
> +static GLenum
> +gl_type_for_array_format_datatype(enum
> mesa_array_format_datatype type)
> +{
> +   switch (type) {
> +   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
> +  return GL_UNSIGNED_BYTE;
> +   case MESA_ARRAY_FORMAT_TYPE_USHORT:
> +  return GL_UNSIGNED_SHORT;
> +   case MESA_ARRAY_FORMAT_TYPE_UINT:
> +  return GL_UNSIGNED_INT;
> +   case MESA_ARRAY_FORMAT_TYPE_BYTE:
> +  return GL_BYTE;
> +   case MESA_ARRAY_FORMAT_TYPE_SHORT:
> +  

Re: [Mesa-dev] [PATCH 01/29] mesa: Add an implementation of a master convert function.

2014-11-19 Thread Jason Ekstrand
By and large, this looks good to me.  Most of my comments are cosmetic or
suggestions for added documentation.  There is one issue that I think is
subtly wrong with integer format conversion but that should be easy to fix.
--Jason

On Tue, Nov 18, 2014 at 1:23 AM, Iago Toral Quiroga 
wrote:

> From: Jason Ekstrand 
>
> v2 by Iago Toral :
>
> - When testing if we can directly pack we should use the src format to
> check
>   if we are packing from an RGBA format. The original code used the dst
> format
>   for the ubyte case by mistake.
> - Fixed incorrect number of bits for dst, it was computed using the src
> format
>   instead of the dst format.
> - If the dst format is an array format, check if it is signed. We were only
>   checking this for the case where it was not an array format, but we need
>   to know this in both scenarios.
> - Fixed incorrect swizzle transform for the cases where we convert between
>   array formats.
> - Compute is_signed and bits only once and for the dst format. We were
>   computing these for the src format too but they were overwritten by the
>   dst values immediately after.
> - Be more careful when selecting the integer path. Specifically, check that
>   both src and dst are integer types. Checking only one of them should
> suffice
>   since OpenGL does not allow conversions between normalized and integer
> types,
>   but putting extra care here makes sense and also makes the actual
> requirements
>   for this path more clear.
> - The format argument for pack functions is the destination format we are
>   packing to, not the source format (which has to be RGBA).
> - Expose RGBA_* to other files. These will come in handy when in need
> to
>   test if a given array format is RGBA or in need to pass RGBA formats to
>   mesa_format_convert.
>
> v3 by Samuel Iglesias :
>
> - Add an RGBA_INT definition.
> ---
>  src/mesa/main/format_utils.c | 378
> +++
>  src/mesa/main/format_utils.h |  10 ++
>  src/mesa/main/formats.h  |  15 +-
>  3 files changed, 399 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
> index fcbbba4..c3815cb 100644
> --- a/src/mesa/main/format_utils.c
> +++ b/src/mesa/main/format_utils.c
> @@ -25,6 +25,384 @@
>  #include "format_utils.h"
>  #include "glformats.h"
>  #include "macros.h"
> +#include "format_pack.h"
> +#include "format_unpack.h"
> +
> +mesa_array_format RGBA_FLOAT = {{
> +   MESA_ARRAY_FORMAT_TYPE_FLOAT,
> +   0,
> +   4,
> +   0, 1, 2, 3,
> +   0, 1
> +}};
> +
> +mesa_array_format RGBA_UBYTE = {{
> +   MESA_ARRAY_FORMAT_TYPE_UBYTE,
> +   1,
> +   4,
> +   0, 1, 2, 3,
> +   0, 1
> +}};
> +
> +mesa_array_format RGBA_UINT = {{
> +   MESA_ARRAY_FORMAT_TYPE_UINT,
> +   0,
> +   4,
> +   0, 1, 2, 3,
> +   0, 1
> +}};
> +
> +mesa_array_format RGBA_INT = {{
> +   MESA_ARRAY_FORMAT_TYPE_INT,
> +   0,
> +   4,
> +   0, 1, 2, 3,
> +   0, 1
> +}};
> +
> +static void
> +invert_swizzle(uint8_t dst[4], const uint8_t src[4])
> +{
> +   int i, j;
> +
> +   dst[0] = MESA_FORMAT_SWIZZLE_NONE;
> +   dst[1] = MESA_FORMAT_SWIZZLE_NONE;
> +   dst[2] = MESA_FORMAT_SWIZZLE_NONE;
> +   dst[3] = MESA_FORMAT_SWIZZLE_NONE;
> +
> +   for (i = 0; i < 4; ++i)
> +  for (j = 0; j < 4; ++j)
> + if (src[j] == i && dst[i] == MESA_FORMAT_SWIZZLE_NONE)
> +dst[i] = j;
> +}
> +
> +static GLenum
> +gl_type_for_array_format_datatype(enum mesa_array_format_datatype type)
> +{
> +   switch (type) {
> +   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
> +  return GL_UNSIGNED_BYTE;
> +   case MESA_ARRAY_FORMAT_TYPE_USHORT:
> +  return GL_UNSIGNED_SHORT;
> +   case MESA_ARRAY_FORMAT_TYPE_UINT:
> +  return GL_UNSIGNED_INT;
> +   case MESA_ARRAY_FORMAT_TYPE_BYTE:
> +  return GL_BYTE;
> +   case MESA_ARRAY_FORMAT_TYPE_SHORT:
> +  return GL_SHORT;
> +   case MESA_ARRAY_FORMAT_TYPE_INT:
> +  return GL_INT;
> +   case MESA_ARRAY_FORMAT_TYPE_HALF:
> +  return GL_HALF_FLOAT;
> +   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
> +  return GL_FLOAT;
> +   default:
> +  assert(!"Invalid datatype");
> +  return GL_NONE;
> +   }
> +}
>

We should probably just make _mesa_swizzle_and_convert take these instead
of the GL types.  That way we can completely remove GL from the format
conversion code.  I'm fine if that's a separate patch on top.

Also, it would be good to have a nice descriptive docstring on the function
below.

+
> +void
> +_mesa_format_convert(void *void_dst, uint32_t dst_format, size_t
> dst_stride,
> + void *void_src, uint32_t src_format, size_t
> src_stride,
> + size_t width, size_t height)
> +{
> +   uint8_t *dst = (uint8_t *)void_dst;
> +   uint8_t *src = (uint8_t *)void_src;
> +   mesa_array_format src_array_format, dst_array_format;
> +   uint8_t src2dst[4], src2rgba[4], rgba2dst[4], dst2rgba[4];
> +   GLenum src_gl_type, dst_gl_type, common_gl_type;
> +   bool normalized, dst_integer

[Mesa-dev] [PATCH 01/29] mesa: Add an implementation of a master convert function.

2014-11-18 Thread Iago Toral Quiroga
From: Jason Ekstrand 

v2 by Iago Toral :

- When testing if we can directly pack we should use the src format to check
  if we are packing from an RGBA format. The original code used the dst format
  for the ubyte case by mistake.
- Fixed incorrect number of bits for dst, it was computed using the src format
  instead of the dst format.
- If the dst format is an array format, check if it is signed. We were only
  checking this for the case where it was not an array format, but we need
  to know this in both scenarios.
- Fixed incorrect swizzle transform for the cases where we convert between
  array formats.
- Compute is_signed and bits only once and for the dst format. We were
  computing these for the src format too but they were overwritten by the
  dst values immediately after.
- Be more careful when selecting the integer path. Specifically, check that
  both src and dst are integer types. Checking only one of them should suffice
  since OpenGL does not allow conversions between normalized and integer types,
  but putting extra care here makes sense and also makes the actual requirements
  for this path more clear.
- The format argument for pack functions is the destination format we are
  packing to, not the source format (which has to be RGBA).
- Expose RGBA_* to other files. These will come in handy when in need to
  test if a given array format is RGBA or in need to pass RGBA formats to
  mesa_format_convert.

v3 by Samuel Iglesias :

- Add an RGBA_INT definition.
---
 src/mesa/main/format_utils.c | 378 +++
 src/mesa/main/format_utils.h |  10 ++
 src/mesa/main/formats.h  |  15 +-
 3 files changed, 399 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index fcbbba4..c3815cb 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -25,6 +25,384 @@
 #include "format_utils.h"
 #include "glformats.h"
 #include "macros.h"
+#include "format_pack.h"
+#include "format_unpack.h"
+
+mesa_array_format RGBA_FLOAT = {{
+   MESA_ARRAY_FORMAT_TYPE_FLOAT,
+   0,
+   4,
+   0, 1, 2, 3,
+   0, 1
+}};
+
+mesa_array_format RGBA_UBYTE = {{
+   MESA_ARRAY_FORMAT_TYPE_UBYTE,
+   1,
+   4,
+   0, 1, 2, 3,
+   0, 1
+}};
+
+mesa_array_format RGBA_UINT = {{
+   MESA_ARRAY_FORMAT_TYPE_UINT,
+   0,
+   4,
+   0, 1, 2, 3,
+   0, 1
+}};
+
+mesa_array_format RGBA_INT = {{
+   MESA_ARRAY_FORMAT_TYPE_INT,
+   0,
+   4,
+   0, 1, 2, 3,
+   0, 1
+}};
+
+static void
+invert_swizzle(uint8_t dst[4], const uint8_t src[4])
+{
+   int i, j;
+
+   dst[0] = MESA_FORMAT_SWIZZLE_NONE;
+   dst[1] = MESA_FORMAT_SWIZZLE_NONE;
+   dst[2] = MESA_FORMAT_SWIZZLE_NONE;
+   dst[3] = MESA_FORMAT_SWIZZLE_NONE;
+
+   for (i = 0; i < 4; ++i)
+  for (j = 0; j < 4; ++j)
+ if (src[j] == i && dst[i] == MESA_FORMAT_SWIZZLE_NONE)
+dst[i] = j;
+}
+
+static GLenum
+gl_type_for_array_format_datatype(enum mesa_array_format_datatype type)
+{
+   switch (type) {
+   case MESA_ARRAY_FORMAT_TYPE_UBYTE:
+  return GL_UNSIGNED_BYTE;
+   case MESA_ARRAY_FORMAT_TYPE_USHORT:
+  return GL_UNSIGNED_SHORT;
+   case MESA_ARRAY_FORMAT_TYPE_UINT:
+  return GL_UNSIGNED_INT;
+   case MESA_ARRAY_FORMAT_TYPE_BYTE:
+  return GL_BYTE;
+   case MESA_ARRAY_FORMAT_TYPE_SHORT:
+  return GL_SHORT;
+   case MESA_ARRAY_FORMAT_TYPE_INT:
+  return GL_INT;
+   case MESA_ARRAY_FORMAT_TYPE_HALF:
+  return GL_HALF_FLOAT;
+   case MESA_ARRAY_FORMAT_TYPE_FLOAT:
+  return GL_FLOAT;
+   default:
+  assert(!"Invalid datatype");
+  return GL_NONE;
+   }
+}
+
+void
+_mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
+ void *void_src, uint32_t src_format, size_t src_stride,
+ size_t width, size_t height)
+{
+   uint8_t *dst = (uint8_t *)void_dst;
+   uint8_t *src = (uint8_t *)void_src;
+   mesa_array_format src_array_format, dst_array_format;
+   uint8_t src2dst[4], src2rgba[4], rgba2dst[4], dst2rgba[4];
+   GLenum src_gl_type, dst_gl_type, common_gl_type;
+   bool normalized, dst_integer, src_integer, is_signed;
+   uint8_t (*tmp_ubyte)[4];
+   float (*tmp_float)[4];
+   uint32_t (*tmp_uint)[4];
+   int i, bits;
+   size_t row;
+
+   if (src_format & MESA_ARRAY_FORMAT_BIT) {
+  src_array_format.as_uint = src_format;
+   } else {
+  assert(_mesa_is_format_color_format(src_format));
+  src_array_format.as_uint = _mesa_format_to_array_format(src_format);
+   }
+
+   if (dst_format & MESA_ARRAY_FORMAT_BIT) {
+  dst_array_format.as_uint = dst_format;
+   } else {
+  assert(_mesa_is_format_color_format(dst_format));
+  dst_array_format.as_uint = _mesa_format_to_array_format(dst_format);
+   }
+
+   /* Handle the cases where we can directly unpack */
+   if (!(src_format & MESA_ARRAY_FORMAT_BIT)) {
+  if (dst_array_format.as_uint == RGBA_FLOAT.as_uint) {
+ for (row = 0; row < height; ++row) {
+