c11/threads: Fix nano to milisecond conversion.

Per https://gist.github.com/yohhoy/2223710/#comment-710118

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Michel Dänzer <michel@daenzer.net>
(cherry picked from commit f34d75d6f69f4c0bf391e0adf1fd469601b01b04)
mapi/u_thread: Use GetCurrentThreadId

u_thread_self() expects thrd_current() to return a unique numeric ID
for the current thread, but this is not feasible on Windows.

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit e8d85034dad37177fce780ee3e09501e60be6e81)
c11/threads: Don't implement thrd_current on Windows.

GetCurrentThread() returns a pseudo-handle (a constant which only makes
sense when used within the calling thread) and not a real handle.

DuplicateHandle() will return a real handle, but it will create a new
handle every time we call.  Calling DuplicateHandle() here means we will
leak handles, which can cause serious problems.

In short, the Windows implementation of thrd_t needs a thorough make
over, and it won't be pretty.  It looks like C11 committee
over-simplified things: it would be much better to have seperate objects
for threads and thread IDs like C++11 does.

For now, just comment out the thrd_current() implementation, so we get
build errors if anybody tries to use it.

Thanks to Brian Paul for spotting and diagnosing this problem.

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit a61d859519d520b849c11ad5c1c1972870abd956)
st/osmesa: check buffer size when searching for buffers

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=75543
Cc: "10.1" <mesa-stable@lists.freedesktop.org>
(cherry picked from commit cbacee207faf866b0444beb583d3d6f341a8ee78)
mesa: Set initial internal format of a texture to GL_RGBA

From OpenGL 4.0 spec, page 398:
   "The initial internal format of a texel array is RGBA
    instead of 1. TEXTURE_COMPONENTS is deprecated; always
    use TEXTURE_INTERNAL_FORMAT."

Fixes Khronos OpenGL CTS test failure: proxy_textures_invalid_size

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit 063980151e801fca6c314e14c82e9a7b8c04a4d2)
mesa: Allow GL_DEPTH_COMPONENT and GL_DEPTH_STENCIL combinations in glTexImage{123}D()

From OpenGL 3.3 spec, page 141:
   "Textures with a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL
    require either depth component data or depth/stencil component data.
    Textures with other base internal formats require RGBA component data.
    The error INVALID_OPERATION is generated if one of the base internal
    format and format is DEPTH_COMPONENT or DEPTH_STENCIL, and the other
    is neither of these values."

Fixes Khronos OpenGL CTS test failure: proxy_textures_invalid_size

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit 079bff5a99fa19029fc0caba92fe57046ee29b23)
gallium/util: Fix memory leak

Fix a leaked vertex shader in u_blitter.c

Signed-off-by: Aaron Watry <awatry@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>

CC: "10.1" <mesa-stable@lists.freedesktop.org>
(cherry picked from commit fb781526787463cb4a1c596b6f8ed867d24b87a2)
mesa: fix copy & paste bugs in pack_ubyte_SARGB8()

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
(cherry picked from commit 9493fc729e35e36c1840957b4af40338e69236a5)
mesa: fix copy & paste bugs in pack_ubyte_SRGB8()

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
(cherry picked from commit 1e25aa4cdb3bb1f190ea3905eb1d169e0c5a1ef0)
mesa: Wrap SSE4.1 code in #ifdef __SSE4_1__.

Because people insist on doing things like explicitly disabling SSE 4.1.

Cc: "10.0 10.1" <mesa-stable@lists.freedesktop.org>
Tested-by: David Heidelberger <david.heidelberger@ixit.cz>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=71547
(cherry picked from commit 8d3f739383fbdf671752fdec707f1c2b9b2aa6a3)
r600g: fix texelFetchOffset GLSL functions

Cc: mesa-stable@lists.freedesktop.org
(cherry picked from commit 8a08051e2a7227061300e344a4e41a1cdf2d6145)
r600g: fix blitting the last 2 mipmap levels for Evergreen

This fixes a lot of compressedteximage piglit tests.

R600-R700 don't have this issue.

Cc: mesa-stable@lists.freedesktop.org
(cherry picked from commit fcdf6fa86cb4dc530b8ab6881faa1da1aafa2b81)
mesa: fix the format of glEdgeFlagPointer

Softpipe expects a float in the vertex shader, which is what glEdgeFlag
generates.

This fixes piglit/gl-2.0-edgeflag.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
(cherry picked from commit 780ce576bb1781f027797039693b98253ee4813e)
nouveau: fix fence waiting logic in screen destroy

nouveau_fence_wait has the expectation that an external entity is
holding onto the fence being waited on, not that it is merely held onto
by the current pointer. Fixes a use-after-free in nouveau_fence_wait
when used on the screen's current fence.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=75279
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Christoph Bumiller <e0425955@student.tuwien.ac.at>
Cc: "9.2 10.0 10.1" <mesa-stable@lists.freedesktop.org>
(cherry picked from commit 507f0230d4ca2238c818006499e21abb4c133203)

Conflicts:
	src/gallium/drivers/nouveau/nv30/nv30_screen.c
nv50: adjust blit_3d handling of ms output textures

This fixes some unwanted scaling when the output is multisampled.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Christoph Bumiller <e0425955@student.tuwien.ac.at>
Cc: "10.0 10.1" <mesa-stable@lists.freedesktop.org>
(cherry picked from commit 253314d4872ab4c4f01c0f1cd31ce4b71877ec30)

And squashed with:

Revert nvc0 part of "nv50: adjust blit_3d handling of ms output textures"

The nvc0 bits don't appear to work, and I thought I had removed them
from the commit. Oops.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: "10.0 10.1" <mesa-stable@lists.freedesktop.org>
(cherry picked from commit 897f40f25d21af678b1b67c1a68c4a6722d19983)
gallium: add endian detection for OpenBSD

Cc: "10.0" "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit 40214267aba2f357eb3334eb8235504ccb93035a)
r600g,radeonsi: fix MAX_TEXTURE_3D_LEVELS and MAX_TEXTURE_ARRAY_LAYERS limits

CB_COLORi_VIEW.SLICE_MAX can be at most 2047.

This fixes the maxlayers piglit test.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
(cherry picked from commit 4f1f32306a5238507af44dde0e3a53820b896930)

Conflicts:
	src/gallium/drivers/r600/r600_pipe.c
	src/gallium/drivers/radeonsi/si_pipe.c
nv50: add missing brackets when handling the samplers array

Commit 3805a864b1d(nv50: assert before trying to out-of-bounds access
samplers) introduced a series of asserts as a precausion of a previous
illegal memory access.

Although it failed to encapsulate loop within nv50_sampler_state_delete
effectively failing to clear the sampler state, apart from exadurating
the illegal memory access issue.

Fixes gcc warning "array subscript is above array bounds" and
"Nesting level does not match indentation" and "Out-of-bounds read"
defects reported by Coverity.

Cc: "10.1" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
(cherry picked from commit c26b488088a459be26cfdb0b134fb058aa4c0411)
mesa: return v.value_int64 when the requested type is TYPE_INT64

Fixes "Operands don't affect result" defect reported by Coverity.

Cc: "9.2 10.0 10.1"  <mesa-stable@lists.freedesktop.org>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
(cherry picked from commit a9cf3aa2087f807b15e0e59ad00dd5bacf362c18)
i965/fs: Fix register comparisons in saturate propagation.

opt_saturate_propagation_local compares scan_inst->dst.reg/reg_offset
with inst->src[0].reg/reg_offset, and ensures that scan_inst->dst.file
is GRF.  But nothing ensured that inst->src[0].file was GRF.

In the following program, this resulted in u1:F matching vgrf1:UW,
and a saturate being incorrectly propagated from instruction 8 to
instruction 1.

{  1}    0: add vgrf0:UW, hw_reg1+8:UW, hw_reg0:V
{  1}    1: add vgrf1:UW, hw_reg1+10:UW, hw_reg0:V
{  1}    2: linterp vgrf6:F, hw_reg2:F, hw_reg3:F, hw_reg0:F
{  2}    3: linterp vgrf27:F, hw_reg2:F, hw_reg3:F, hw_reg0+16:F
{  4}    4: mov vgrf10+0.0:F, vgrf6:F
{  3}    5: mov vgrf10+1.0:F, vgrf27:F
{  6}    6: tex vgrf8+0.0:F, vgrf10+0.0:F
{  5}    7: mov vgrf32:F, u1:F
{  5}    8: mov.sat vgrf12:F, u1:F

From shader-db:
   total instructions in shared programs: 1841932 -> 1841957 (0.00%)
   instructions in affected programs:     5823 -> 5848 (0.43%)
I inspected two of the 25 hurt shaders, and concluded that they were
both hitting this bug, and not legitimately optimized.

This fixes bugs in Left 4 Dead 2 and Team Fortress 2, possibly among
others.  The optimization pass didn't exist in 10.0, so this is only
a candidate for 10.1.

Cc: "10.1" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
(cherry picked from commit 4d2e79269a97c403a6384e0f5164b9f54b6a5f61)