gallivm: fix up out-of-bounds level when using conformant out-of-bound behavior

When using (d3d10) conformant out-of-bound behavior for texel fetching
(currently always enabled) the level still needs to be set to a safe value
even though the offset in the end won't get used because the level is used
to look up the mip offset itself and the actual strides, which might otherwise
crash.
For simplicity, we'll use level 0 in this case (this ought to be safe, llvmpipe
does not actually fill in level 0 information if first_level is larger, but
some random strides / offsets shouldn't hurt as ultimately we always use
offset 0 in this case).
Fixes a crash in some in-house test where random huge levels appear in
lp_build_fetch_texel() (the test actually uses level 0 always but if the
fetching happens in a block with a execution mask random values may appear).

CC: <mesa-stable@lists.freedesktop.org>

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
(cherry picked from commit 5a12155503c9cd0cc77b0a0e52bc563c39631275)
i965/miptree: Layout 1D Array as 2D Array with height of 1

1D array miptrees were being laid out as a 2D texture with 1 slice.
This happened due to the mesa core storing the 1D array slice count in
the height field. On Intel hardware, we want to create a 2D array with
a height of 1 for the 1D array case.

Fixes assertion failure in piglit (gen6, gen8):
spec/glsl-1.30/execution/tex-miplevel-selection textureOffset 1DArrayShadow

In release builds of Mesa, this test was observed to cause a GPU hang
on gen8.

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Cc: "10.2" <mesa-stable@lists.freedesktop.org>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=81450
Tested-by: Ben Widawsky <ben@bwidawsk.net>
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
(cherry picked from commit c860a379d2fa09da1711591b6aef4a885d224ea0)
mesa/st: only convert AND(a, NOT(b)) into MAD when not using native integers

Native integers imply a somewhat different handling of booleans. Instead
of being 1.0/0.0 floats, they are 0 (true) / -1 (false) integers. As such
the original optimization no longer applies.

Reported-by: Glenn Kennard <glenn.kennard@gmail.com>
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Cc: "10.2" <mesa-stable@lists.freedesktop.org>
(cherry picked from commit 7b3d0a9a1eb11bf70390ad116ed662a47f06183e)
mesa: Fix error condition for valid texture targets in glTexStorage* functions

Fixes gles3 Khronos CTS test: texture_storage_texture_targets

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
(cherry picked from commit a94d78438d35cfde851596dff8461f1e739a0ddc)
mesa: Turn target_can_be_compressed() in to a utility function

V2:  Declare the function in teximage.h

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit ac2adf66c1ce009fed9175c891f4d90c6d79b7ab)
mesa: Add error condition for using compressed internalformat in glTexStorage3D()

Fixes gles3 Khronos CTS test: texture_storage_texture_internal_formats

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit e27c9f3a02509fe59db7ec409a339cc5ea809600)
mesa: Fix condition for using compressed internalformat in glCompressedTexImage3D()

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit 3c7a0c690a1a0d72ad2b911e4a209447ce3edc1f)
mesa: Add utility function _mesa_is_enum_format_snorm()

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit 845b5ec89fb5543a3d38a31e1e8bc5f84449ea6c)
mesa: Don't allow snorm internal formats in glCopyTexImage*() in GLES3

Fixes few failures in gles3 Khronos CTS test: packed_pixels

Cc: "10.2" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit 2d362a6aee0a1acab08590f2ba0ce50743546209)
mesa: Add a helper function _mesa_is_enum_format_unsized()

Function is utilized by next patch in the series.

V2: Add missing formats.

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit e0fe00eeac75d8fdd378a1f7633d2efd1db0a7b0)
mesa: Add a gles3 error condition for sized internalformat in glCopyTexImage*()

Fixes many failures in gles3 Khronos CTS test: packed_pixels

V2: Add the check for alpha bits to avoid confusion.

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit 5c0d2a12f30d75df10ede6ab98434f55abae3fef)
mesa: Add gles3 error condition for GL_RGBA10_A2 buffer format in glCopyTexImage*()

Fixes many failures in gles3 Khronos CTS test: packed_pixels

Khronos bug# 9807
Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>

(cherry picked from commit 6df48ff27ad14c341a7ba4f1f833c8dbfbd056c1)
mesa: Add utility function _mesa_is_enum_format_unorm()

V2: Add missing formats.

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit 938b3d003401538ceadac28ec5fe0e6ca583d2a6)
mesa: Add gles3 condition for normalized internal formats in glCopyTexImage*()

Fixes many failures in gles3 Khronos CTS test: packed_pixels

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
(cherry picked from commit 2fc420546199b5834ea3a0741d718333596ee235)
mesa: Allow GL_TEXTURE_CUBE_MAP target with compressed internal formats

GL_TEXTURE_CUBE_MAP is an allowed texture target in glTexStorage2D()
and is allowed to be used (like GL_TEXTURE_2D) with compressed internal
formats.

Cc: <mesa-stable@lists.freedesktop.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
(cherry picked from commit c7def2257aae3b73ba37609dfbc0a0f35fa99c81)
meta: Use _mesa_get_format_bits() to get the GL_RED_BITS

We currently get red bits from ctx->DrawBuffer->Visual.redBits
by making a false assumption that the texture we're writing to
(in glCopyTexImage2D()) is used as a DrawBuffer.

Fixes many failures in gles3 Khronos CTS test:
copy_tex_image_conversions_required

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
(cherry picked from commit 7de90890c64d019c56e5a06e427b207220729997)

Conflicts:
	src/mesa/drivers/common/meta.c
egl: Fix OpenGL ES version checks in _eglParseContextAttribList()

We would generate EGL_BAD_CONFIG because _eglGetContextAPIBit
returns zero for the combination of EGL_OPENGL_ES_API and a major
version > 3.  By just returning zero, the caller can't tell the
difference between a bad version (which should generate
EGL_BAD_MATCH) and a bad API (which should generate
EGL_BAD_CONFIG).  This patch causes us to filter out major
versions > 3 at a point where we can generate the correct error.

Fixes gles3 Khronos CTS test:
egl_create_context.egl_create_context

V2: Fix commit message as suggested by Ian.

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
(cherry picked from commit d308f57fe796a39d7d3f547aad62540cfd520675)
meta: Fix datatype computation in get_temp_image_type()

Changes in the patch will cause datatype to be computed
correctly for 8 and 16 bit integer formats. For example:
GL_RG8I, GL_RG16I etc.

Fixes many failures in gles3 Khronos CTS test:
copy_tex_image_conversions_required
copy_tex_image_conversions_forbidden

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
(cherry picked from commit 338fef61f86bb121e47b096428dce2a9109d3a3e)

Conflicts:
	src/mesa/drivers/common/meta.c
configure: check for dladdr via AC_CHECK_FUNC/AC_CHECK_LIB

Use both macros as in some cases using AC_CHECK_FUNCS alone may fail.
Thus HAVE_DLADDR will not be defined, and as a result most of the code
in megadriver_stub.c will not be compiled. Breaking the backwards
compatibility between older libGL/xserver(s) and DRI megadrivers.

Cc: Jon TURNEY <jon.turney@dronecode.org.uk>
Cc: "10.2" <mesa-stable@lists.freedesktop.org>
[Emil Velikov] Commit message.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>

(cherry picked from commit 39a4cc45a417bea3bb1cfbe20ea5045200f76c25)

Also squashed together with:

configure.ac: Use LIBS rather than LDFLAGS to add -ldl to dladdr check

ec8ebff "Check for dladdr()" erroneously uses LDFLAGS rather than LIBS to add
-ldl to the dladdr check.

Replace the workaround in 39a4cc4 of explicitly checking in libdl, with a more
correct approach of using LIBS.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Tested-by: Pali Rohár <pali.rohar@gmail.com>
Cc: "10.2" <mesa-stable@lists.freedesktop.org>
(cherry picked from commit a2e1dc0cce3f5c4b94123a5fd4de42ecc988ab14)
st/mesa: fix blit-based partial TexSubImage for 1D arrays

This fixes piglit spec/EXT_texture_array/render-1darray.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
(cherry picked from commit 0b5d88a518da7e4c8a084b7881580846c5d6d11f)