swrast: Fix vertex color in _swsetup_Translate()

Straightforward fix to properly load dest->color with color data, as
opposed to position data as previously implemented.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27499
Cc: "10.1" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit 15c92464df07c5c0bb23a007358c560faeab76a8)
swrast: allocate swrast_texture_image::ImageSlices array if needed

Fixes a segmentation fault in conform divzero.c test.
This happens when glTexImage(level, width=0, height=0) is called.  We
don't allocate texture memory in that case so the ImageSlices array
was never allocated.

Cc: "10.1" <mesa-stable@lists.freedesktop.org>

Reviewed-by: José Fonseca <jfonseca@vmware.com>
(cherry picked from commit 7cc2e2e99d857617178ce01f52ae2a9b04da3275)
r300g: don't crash when getting NULL colorbuffers

Cc: mesa-stable@lists.freedesktop.org
(cherry picked from commit e522c455e40b06a89885d413d564df40015259b3)
st/mesa: remove trailing NULL colorbuffers

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit 8a1dfba73e5b675635108e7d8309444704b8fef4)
r600g: fix edge flags and layered rendering on R600-R700

We forgot to set these bits.

Cc: 10.1 mesa-stable@lists.freedesktop.org
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit e5741f1e91429366699cb0a57c40968f0f9fd8cb)

Conflicts:
	src/gallium/drivers/r600/r600_state.c
r600g: disable async DMA on R700

Cc: 10.0 10.1 mesa-stable@lists.freedesktop.org
(cherry picked from commit 6dd045ef4074d23ac659eadb2388b12542e3aab8)
r600g: fix MSAA resolve on R6xx when the destination is 1D-tiled

Cc: 10.0 10.1 mesa-stable@lists.freedesktop.org
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 20a9b784da3c286bdba5fbfb4e6592e16560895c)
r600g: fix flushing on RV670, RS780, RS880 again

Cc: 10.0 10.1 mesa-stable@lists.freedesktop.org
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 042e40f67b4cec0bc1d5d783bc3207a191bf433b)
r600g: fix buffer copying on R600-R700

This fixes broken rendering in DOTA 2.

Cc: 10.0 10.1 mesa-stable@lists.freedesktop.org
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 0967970768c517c8c2f1a969e0a043982b4b1bf7)
r600g: fix for broken CULL_FRONT behavior on R6xx

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit ecc8a37ec5be7fca79205f08666fb76474ab5c0d)

Conflicts:
	src/gallium/drivers/r600/r600_pipe.h
r600g: fix for an MSAA hang on RV770

Cc: 10.0 10.1 mesa-stable@lists.freedesktop.org
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 3d0c4f3b01569f43318e648786ae79f7b6b4948e)
r600g: fix hang on RV740 by using DX_RASTERIZATION_KILL instead of SX_MISC

Changing SX_MISC hangs RV740. When we're at it, let's use DX_RASTERIZATION_KILL
on all R700 and later chipsets.

Cc: 10.0 10.1 mesa-stable@lists.freedesktop.org
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 3a3b1bf60e0ef233a8610684a7472e3600d0e65e)
gbm/dri: Fix out-of-memory error path in dri_device_create()

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
(cherry picked from commit aa91fe1c09e066751c5419adb7810745336bd051)
wayland: Fix the logic in disabling the prime capability

It looks like this bit of code is trying to disable the prime capability if
the driver doesn't support createImageFromFds. However the logic looks a bit
broken and what it would actually do is disable all other capabilities apart
from prime. This patch fixes it to actually disable prime.

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
(cherry picked from commit 63d4661ab28c036ab000f94812a91d93d538a72a)
egl: Protect use of gbm_dri with ifdef HAVE_DRM_PLATFORM

Otherwise it fails to compile if the drm egl platform is disabled.

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
(cherry picked from commit 17860309f17de78e729f77e86101004f61f6bcf3)
st/mesa: Fix NULL pointer dereference for incomplete framebuffers

This can happen with glamor, which uses EGL_KHR_surfaceless_context and
only explicitly binds GL_READ_FRAMEBUFFER for glReadPixels.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit 136c437cea3ebc9541735bb40951128e1210f06b)
cherry-ignore: Ignore a patch causing a regression

This may be just a bogus test. I'm waiting to see what the bugzilla decides:

https://bugs.freedesktop.org/show_bug.cgi?id=77702
i965: Fix render-to-texture in non-FinishRenderTexture cases.

We've had several problems now with FinishRenderTexture not getting called
enough, and we're ready to just give up on it ever doing what we need.  In
particular, an upcoming Steam title had rendering bugs that could be fixed
by always_flush_cache=true.

Instead of hoping Mesa core can figure out when we need to flush our
caches, just track what BOs we've rendered to in a set, and when we render
from a BO in that set, emit a flush and clear the set.

There's some overhead to keeping this set, but most of that is just
hashing the pointer -- it turns out our set never even gets very large,
because cache flushes are so common (even on cairo-gl).

No statistically significant performance difference in cairo-gl (n=100),
despite spending ~.5% CPU in these set operations.

v1: (Original patch by Eric Anholt.)
v2: (Changes by Ken Graunke.)
  - Rebase forward from May 7th 2013 -> March 4th 2014.
  - Drop the FinishRenderTexture hook entirely; after rebasing the
    patch, the hook was just an empty function.
  - Move the brw_render_cache_set_clear() call from
    intel_batchbuffer_emit_flush() to brw_emit_pipe_control_flush().
    In theory, this could catch more cases where we've flushed.
  - Consider stencil as a possible texturing source.
v3: (changes by anholt):
  - Move set_clear() back to emit_mi_flush() -- it means we can drop
    more forced flushes from the code.  In the previous location, it
    wouldn't have been called when we wanted pre-gen6.
  - Move the set clear from batch init to reset -- it should be empty at
    the start of every batch, since the kernel handled any inter-batch
    flush for us.
v4: Drop the debug code in set.c that I accidentally committed.
v5: Back port to 10.1 stable branch (remove reference to stencil texture.)

Signed-off-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Tested-by: Dylan Baker <baker.dylan.c@gmail.com> [v2]

Conflicts:
	src/mesa/drivers/dri/i965/brw_draw.c
	src/mesa/drivers/dri/i965/intel_fbo.h
i965: Don't enable reset notification support on Gen4-5.

arekm reported that using Chrome with GPU acceleration enabled on GM45
triggered the hw_ctx != NULL assertion in brw_get_graphics_reset_status.

We definitely do not want to advertise reset notification support on
Gen4-5 systems, since it needs hardware contexts, and we never even
request a hardware context on those systems.

Cc: "10.1" <mesa-stable@lists.freedesktop.org>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=75723
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
(cherry picked from commit 0380ec467d78f40b5c8134158ca48b4c5378b282)
i965: Actually emit PIPELINE_SELECT and 3DSTATE_VF_STATISTICS.

For platforms using hardware contexts (currently Gen6+), we failed to
emit PIPELINE_SELECT and 3DSTATE_VF_STATISTICS, instead emitting MI_NOOP
for both.

During one of the context initialization reordering patches, we
accidentally moved brw_init_state before we set brw->CMD_PIPELINE_SELECT
and brw->CMD_VF_STATISTICS.  So, when brw_init_state uploaded initial
GPU state (brw_init_state -> brw_upload_initial_gpu_state ->
brw_upload_invariant_state), these would be 0 (MI_NOOP).

Storing the commands in the context is not worthwhile.  We have many
generation checks in our state upload code, and for platforms with
hardware contexts, this only gets called once per GL context anyway.
The cost is negligable, and it's easy to botch context creation
ordering.

This may fix hangs on Gen6+ when using the media pipeline.

Cc: "10.0 10.1" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ben Widawsky <ben@bwidawsk.net>
(cherry picked from commit ac30e1adb49ec6947f740b47d90f8403fe416314)

Conflicts:
	src/mesa/drivers/dri/i965/brw_context.h