gallivm: Fix build with LLVM >= r180063
(cherry picked from commit ead4db420e9e5408f41c70768a290592a384aedb)
gallivm: Fix build with LLVM 3.3

Reviewed-by: Tom Stellard <thomas.stellard@amd.com>
(cherry picked from commit 4742f9b00b804dd01eb9955dd386a2373cd8eb36)
st/mesa: initialize all program constants and UBO limits

Also simplify UBO support checking.

NOTE: This is a candidate for the 9.1 branch.

Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit 614ee25077b7ffafeb87b22563d01856824fb4bc)
st/mesa: initialize Const.MaxColorAttachments

NOTE: This is a candidate for the stable branches.

Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit 6a2ad679e6f11f51e01001943f7d18329f077620)
st/mesa: fix a couple of issues in st_bind_ubos

- don't reference a buffer for a local variable
  (that's never useful unless it can be the only reference to the buffer)
- check if the buffer is not NULL
- set buffer_size as specified with BindBufferRange

NOTE: This is a candidate for the 9.1 branch.

Reviewed-by: Fredrik Höglund <fredrik@kde.org>
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit a17e87d4ebd84c1a01c3821c04ed9d8d7c763983)
mesa: Use accessor for stencil reference values in glGet

NOTE: This is a candidate for stable branches.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
(cherry picked from commit 96a1bf1ba3b3e556abe2e7303b8b785e93e68985)
st/glx/xlib: check for null ctx pointer in glXIsDirect()

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64745
Note: This is a candidate for the stable branches.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
(cherry picked from commit 1e9875acbe0a1204e144b12b66b5b0ec55664e2c)
xlib: check for null ctx pointer in glXIsDirect()

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64745
Note: This is a candidate for the stable branches.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
(cherry picked from commit 9772284df2cba1dd30ec401fd19c5a212197b411)
st/glx: add null ctx check in glXDestroyContext()

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64934
NOTE: This is a candidate for the stable branches.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
(cherry picked from commit fd29e4acdae3a667e5b2519aa87ad457decb50c6)
xlib: add null ctx check in glXDestroyContext()

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64934
NOTE: This is a candidate for the stable branches.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
(cherry picked from commit fd9fe4470be0437c18cbd6d2bc8e568378f88200)
mesa: declare UniformBufferBindings as an array with a static size

Some Gallium drivers were crashing, because the array was not large enough.

v2: clamp the per-shader maximum in st/mesa, then sum them all up

NOTE: This is a candidate for the stable branches.
(cherry picked from commit 15a4b6db2192b0adc05c3dc07cf043316c556f2e)
xmlpool/build: Make sure to set mo properly

Some shells does not set variables sequentially in a statement i.e. "a=X
b=${a}" won't set "b" to "X" but empty value.

This patch introduce ";" to make sure "mo" is set properly before "lang"
assignment.

Bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=471302
(cherry picked from commit 95e145aaee1c535aa4d55b1765c717968efdf18c)
nvc0: set rsvd_kick correctly

This prevents trampling beyond the end of the command stream during flushes.

NOTE: This is a candidate for the stable branches.

Reported-by: Christoph Bumiller <christoph.bumiller@speed.at>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
(cherry picked from commit e72cc26518d8a60093ac497bf680c1f4ba614fa9)
intel: Fix MRT handling of glBitmap().

We'd only hit color buffer 0 even if multiple draw buffers were bound.

NOTE: This is a candidate for the stable branches.

Reviewed-and-tested-by: Ian Romanick <ian.d.romanick@intel.com>
Acked-by: Paul Berry <stereotype441@gmail.com>
(cherry picked from commit 1cb8de6fff24743e479e17f023bd3a7b455b756f)
intel: Fix format handling of blit glBitmap()

Any 32-bit format got ARGB8888 handling (including, say, GL_RG1616), and
anything else got 16-bit (including, say, GL_R8), which could potentially
hang the GPU by writing out of bounds.

NOTE: This is a candidate for the stable branches.

Reviewed-and-tested-by: Ian Romanick <ian.d.romanick@intel.com>
Acked-by: Paul Berry <stereotype441@gmail.com>
(cherry picked from commit 0a39cb88deee338de3c82db2e70594f11ee1cc8d)
gallivm: fix out-of-bounds access with mirror_clamp_to_edge address mode

Surprising this bug survived so long, we were missing a clamp (in the
linear filtering version).
(Valgrind complained a lot about invalid reads with piglit texwrap,
I've also seen spurios failures in this test which might have
happened due to this. Valgrind probably didn't complain before the
alignment reduction in llvmpipe to 4x4 since the test is using tiny
textures so the reads were still always well within allocated area.)
While here, also do an effective clamp (after half subtraction)
of [0,length-0.5] instead of [0, length-1] which saves an instruction
(the filtering weight could be different due to this, but only if
both texels point to the same max texel so it doesn't matter).
(Both changes are borrowed from PIPE_TEX_CLAMP_TO_EDGE case.)

Note: This is a candidate for the stable branches.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
(cherry picked from commit 458a9a0f85b93e3520c33dd3b502e26a31f08e4b)
meta: move vertex array enables for mipmap generation

Before, on the second call to GenerateMipmap we were enabling two
vertex arrays for the current vertex array object, rather than
the private generate-mipmap vertex array object.  This caused
things to blow up elsewhere.

This patch moves the array enables into the block where the
generate-mipmap vertex array object is created, as we do in
the setup_ff_generate_mipmap() function.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=60518
NOTE: This is a candidate for the stable branches.

Tested-by: core13@gmx.net
Reviewed-by: José Fonseca <jfonseca@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
(cherry picked from commit dcc5b6bfb79261779d85325239d75a2e1f3bec37)
mesa: handle missing read buffer in _mesa_get_color_read_format/type()

We were crashing when GL_READ_BUFFER == GL_NONE.  Check for NULL
pointers and reorganize the code.  The spec doesn't say which error
to generate in this situation, but NVIDIA raises GL_INVALID_OPERATION.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=65173
NOTE: This is a candidate for the stable branches.

Tested-by: Vedran Rodic <vrodic@gmail.com>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
(cherry picked from commit e20a2df4017ab10dd7199936948c6ac809bfacb6)
i965: Fix glColorPointer(GL_FIXED)

When a gl_client_array is created with glColorPointer,
gl_client_array::Normalized is true. This caused the translation from the
gl_client_array's type to a BRW_SURFACEFORMAT to assertion fail.

Fixes the spinning cube's color in Android 4.2's ApiDemos.apk,
"Graphics > OpenGL ES".

Fixes assertion failure in mesa-demos/src/egl/opengles1/tri_x11 on Haswell
and Ivybridge:
  brw_draw_upload.c:287: get_surface_type: Assertion `0' failed.

No Piglit regressions on Haswell.

Note: This is a candidate for the 9.1 branch.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42182
Issue: AXIA-2954
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
(cherry picked from commit 7a9f4d3e7114ca709658a620644ad897bdda41e7)
i965: fix problem with constant out of bounds access (v3)

Okay I now understand why Frank would want to run away, this is
my attempt at fixing the CVE out of bounds access to constants
outside the range. This attempt converts any illegal constants
to constant 0 as per the GL spec, and is undefined behaviour.

A future patch should add some debug for users to find this out,
but this needs to be backported to stable branches.

CVE-2013-1872

v2: drop the last hunk which was a separate fix (now in master).
hopefully fix the indentations.

v3: don't fail piglit, the whole 8/16 dispatch stuff was over
my head, and I spent a while figuring it out, but this one is
definitely safe, one piglit pass extra on my Ironlake.

NOTE: This is a candidate for stable branches.

Signed-off-by: Dave Airlie <airlied@redhat.com>
(cherry picked from commit 0677ea063cd96adefe87c1fb01ef7c66d905535b)