mesa: fix get_texbuffer_format().

It has wrongly assigned the mesa formats for GL_LUMINANCE_ALPHA16I_EXT
and GL_LUMINANCE_ALPHA32I_EXT internal formats.

Signed-off-by: Samuel Iglesias Gonsalvez <correo@samuelig.es>
mesa: Autogenerate most of format_pack.c

We were auto-generating it before.  The problem was that the autogeneration
tool we were using was called "copy, paste, and edit".  Let's use a more
sensible solution.

Signed-off-by: Jason Ekstrand <jason.ekstrand@intel.com>

v2 by Samuel Iglesias <siglesias@igalia.com>
- Remove format_pack.c as it is now autogenerated
- Add usage of INDENT_FLAGS in Makefile.am
- Remove whitespace

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa: Autogenerate format_unpack.c

Signed-off-by: Jason Ekstrand <jason.ekstrand@intel.com>

v2 by Samuel Iglesias <siglesias@igalia.com>:
- Add usage of INDENT_FLAGS in Makefile.am

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa: Add _mesa_pack_uint_rgba_row() format conversion function

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa: Add support for non-normalized formats in format_pack.c.mako

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa/format_pack: Fix _FLOAT formats for pack_ubyte_*() and pack_uint_*()

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa/format_pack: Add _mesa_pack_int_rgba_row()

This will be used to unify code in pack.c.

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa: Add support for normalized formats in integer unpack functions

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa/formats: add new mesa formats and their pack/unpack functions.

This  will be used to refactor code in pack.c and support conversion
to/from these types in a master convert function that will be added
later.

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa: use format conversion functions in swrast

This commit adds a macro to facilitate the task of using
format conversions functions but keeps the same API.

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
mesa: Add an implementation of a master convert function.

v2 by Iago Toral <itoral@igalia.com>:

- 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 was 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 RGBA8888_* to other files. These will come in handy when in need to
  test if a given array format is RGBA or defining dst RGBA formats.

v3 by Samuel Iglesias <siglesias@igalia.com>:

- Add an RGBA8888_INT definition.
mesa: Set normalized=true for float array formats.

In order to check if a format is normalized Mesa does something like this:
normalized = !_mesa_is_enum_format_integer(srcFormat);

So all float types will set normalized to true. Since our mesa_array_format
includes a normalized flag for each type we want to make it consistent with
this.
mesa: Do not assert on integer<->non-integer direct pack/unpack fast paths

We can have conversions from non-integer types to integer types, so remove
the assertions for these in the pack/unpack fast paths. It could be that
we do not have all the necessary pack/unpack functions in these cases though,
so protect these paths with conditionals and let _mesa_format_convert use
other paths to resolve these kind of conversions if necessary.
mesa: Expose compute_component_mapping as _mesa_compute_component_mapping

This is necessary to handle conversions between array types where
the driver does not support the dst format requested by the client and
chooses a different format instead.

We will need this in _mesa_format_convert, so move it to format_utils.c,
prefix it with '_mesa_' and make it available to other files.
mesa: Consider internal base format in _mesa_format_convert (swizzle path).

Add a dst_internal_format parameter to _mesa_format_convert, that represents
the base internal format for texture/pixel uploads, so we can do the right
thing when the driver has selected a different internal format for the target
dst format.
mesa: Consider internal base format in _mesa_format_convert (float path).

For some conversions in the float path doing src->rgba->dst is not enough and
we need to consider thedst  base internal format. In these cases a swizzle
operation is required to match the semantics of the base internal format
requested, so we need to do src->rgba->swizzle->rgba->dst. This is the same
logic that exists right now in the float path of texstore_rgba (texstore.c)
that handles texture uploads.
mesa: Avoid pack/unpack fast paths if base internal format != base format

In general, if the dst base internal format and the selected dst format are
different we can't be sure that directly packing or unpacking to the destination
format will produce correct results. In these cases we probably want to fall
back to other paths (like mesa_swizzle_and_convert) that can handle these
situations better.

An example of this includes a luminance internal format for which the driver
decided to use something like BGRA. In these case, unpacking to BGRA won't
match the requirements of the luminance internal format.

In the future we may want to allow these fast paths for specific cases
where we know the direct pack/unpack functions will do the right thing.
mesa: Add helper to convert a GL format and type to a mesa (array) format.
mesa: Add _mesa_swap2_copy and _mesa_swap4_copy

We have _mesa_swap{2,4} but these do in-place byte-swapping only. The new
functions receive an extra parameter so we can swap bytes on a source
input array and store the results in a (possibly different) destination
array.

This is useful to implement byte-swapping in pixel uploads, since in this
case we need to swap bytes on the src data which is owned by the
application so we can't do an in-place byte swap.
mesa: Add RGBA to Luminance conversion helpers

For glReadPixels Luminance values are computed from RGBA as L=R+G+B.
This, however, requires ad-hoc implementation, since pack/unpack functions
or _mesa_swizzle_and_convert won't do this (and thus, neither will
_mesa_format_convert). This patch adds helpers to do this computation so
they can be used to support conversion to these formats.

The current implementation of glReadPixels does this computation as part
of the span functions in pack.c (see _mesa_pack_rgba_span_float), that do
this together with other things like type conversion, etc. We do not want
to use these functions, we want to use _mesa_format_convert instead, so we
need to extract this functionality as helper functions.