gallivm: ignore rho approximation for cube maps

There's two reasons for this:
1) even when ignoring rho approximation for cube maps, the result is still
not correct, but it's better as the max error at edges is now sqrt(2) instead
of 2 (which was a full mip level), same as it is for ordinary 2d maps when
doing rho approximations (so the error actually goes from factor 2 at edges and
sqrt(2) completely inside a face to sqrt(2) at edges and 0 inside a face).
2) I want to repurpose rho_no_approx for cubemaps for fully correct cubemap
derivatives (so don't need yet another debug var).

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
gallivm: handle explicit derivatives for cubemaps

They need some special handling. Quite complicated.
Additionally, use the same code for implicit derivatives too if no_rho_approx
and no_quad_lod is set, because it seems while generally it should be ok
to use per quad lod for implicit derivatives there's at least some test which
insists that in case of cubemaps the shared lod value MUST come from a pixel
inside the primitive (due to the derivatives becoming different if a different
larger major axis is chosen).

v2: based on Brian's feedback, clean up code a bit.
And use sign bit of major axis instead of pre-select s/t/r sign for coord
mirroring (which should be the same in the end, saves 2 ands).
Also fix two bugs with select/mirror of derivatives, the minor axes need to
use major axis sign as well (instead of major derivative axis sign), and
don't mistakenly use absolute values of major derivative and inverse major
values.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
gallivm: kill old per-quad face selection code

Not used since ages, and it wouldn't work at all with explicit derivatives now
(not that it did before as it ignored them but now the code would just use
the derivs pre-projected which would be quite random numbers).

v2: also get rid of 3 helper functions no longer used.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
llvmpipe: We don't use the draw pipeline for offset_point/line.

Unless the polygon fill mode is different from PIPE_POLYGON_MODE_FILL,
so checking the the polygon mode is sufficient.

Testing done: no regression in polygon-mode-offset
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
util: Fix MinGW build.

_GNU_SOURCE appears to not be used reliably.  Use _MSC_VER instead so
that MSVC alone is affected.
radeon/winsys: fix handling in radeon_drm_cs_flush v2

Calling radeon_drm_cs_flush from multiple threads might cause deadlocks,
fix this by immediately signaling the semaphore after waiting for it.

This is a candidate for the stable branch(es).

Partially fixes: https://bugs.freedesktop.org/show_bug.cgi?id=70123

v2: some fixes on commit message

Signed-off-by: Christian König <christian.koenig@amd.com>
glsl: Construct gl_in with a location of -1.

We use a location of -1 for variables which don't have their own
assigned locations--this includes ir_variables which represent named
interface blocks.  Technically the location assigned to gl_in doesn't
matter, since gl_in is only accessed via its members (which have their
own locations).  But it's nice to be consistent.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Fix block name of built-in gl_PerVertex interface block.

Previously, we erroneously used the name "gl_in" for both the block
name and the instance name.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Refactor code for creating gl_PerVertex interface block.

Currently, we create just a single gl_PerVertex interface block for
geometry shader inputs.  In later patches, we'll also need to create
an interface block for geometry and vertex shader outputs.  Moving the
code into its own class will make reuse easier.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Construct gl_PerVertex interfaces for GS and VS outputs.

Although these interfaces can't be accessed directly by GLSL (since
they don't have an instance name), they will be necessary in order to
allow redeclarations of gl_PerVertex.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Account for location field when comparing interface blocks.

In commit e2660770731b018411fbe1620cacddaf8dff5287 (glsl: Keep track
of location for interface block fields), I neglected to update
glsl_type::record_key_compare to account for the fact that interface
types now contain location information.  As a result, interface types
that differ only by their location information would not be properly
distinguished.

At the moment this is not a problem, because the only interface block
in which location information != -1 is gl_PerVertex, and gl_PerVertex
is always created in the same way.  However, in the patches that
follow, we'll be adding new ways to create gl_PerVertex (by
redeclaring it), so we'll need location information to be handled
properly.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Refactor code to check that identifier names are valid.

GLSL reserves identifiers beginning with "gl_" or containing "__", but
we haven't been consistent about enforcing this rule.  This patch
makes a new function to check whether identifier names are valid.  In
the process it closes a loophole where we would previously allow
function argument names to contain "__".

v2: Rename check_valid_identifier() -> validate_identifier().  Add
curly braces in validate_identifier().

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Don't allow unnamed interface blocks to redeclare variables.

Note: some limited amount of redeclaration is actually allowed,
provided the shader is redeclaring the built-in gl_PerVertex interface
block.  Support for this will be added in future patches.

Fixes piglit tests
spec/glsl-1.50/compiler/unnamed-interface-block-elem-conflicts-with-prev-{block-elem,global}.vert.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Don't allow invalid identifiers as interface block names.

Note: we need to make an exception for the gl_PerVertex interface
block, since this is allowed to be redeclared.  Future patches will
make redeclaration of gl_PerVertex work properly.

Fixes piglit test
spec/glsl-1.50/compiler/interface-block-name-uses-gl-prefix.vert.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Don't allow invalid identifier names in struct/interface fields.

Note: we need to make an exception for the gl_PerVertex interface
block, since built-in variables are allowed to be redeclared inside
it.  Future patches will make redeclaration of gl_PerVertex work
properly.

Fixes piglit tests:
- spec/glsl-1.50/compiler/interface-block-array-elem-uses-gl-prefix.vert
- spec/glsl-1.50/compiler/named-interface-block-elem-uses-gl-prefix.vert
- spec/glsl-1.50/compiler/unnamed-interface-block-elem-uses-gl-prefix.vert

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Don't allow invalid identifiers as interface block instance names.

Note: we need to make an exception for the gl_PerVertex interface
block, since in geometry shaders it is allowed to be redeclared with
the instance name gl_in.  Future patches will make redeclaration of
gl_PerVertex work properly.

Fixes piglit test
spec/glsl-1.50/compiler/interface-block-instance-name-uses-gl-prefix.vert.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Don't allow invalid identifiers as struct names.

Fixes piglit test
spec/glsl-1.10/compiler/struct/struct-name-uses-gl-prefix.vert.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Generalize processing of variable redeclarations.

This patch modifies the get_variable_being_redeclared() function so
that it no longer relies on the ast_declaration for the variable being
redeclared.  In future patches, this will allow
get_variable_being_redeclared() to be used for processing
redeclarations of the built-in gl_PerVertex interface block.

v2: Also make get_variable_being_redeclared() static.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Add an ir_variable::reinit_interface_type() function.

This will be used by future patches to change an ir_variable's
interface type when the gl_PerVertex built-in interface block is
redeclared.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glsl: Make it possible to disable a variable in the symbol table.

In later patches, we'll use this in order to implement the required
behaviour that after the gl_PerVertex interface block has been
redeclared, only members of the redeclared interface block may be
used.

v2: Update the function name and comment to clarify that we aren't
actually removing the variable from the symbol table, just disabling
it.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>