glsl: Fix the foreach_in_list_reverse macro.

We clearly don't want to start at the head and walk backwards; we want
to start at the last real element before the tail sentinel.  If the list
is empty, tail_pred will be the head sentinel, and we'll stop.

Nothing uses this function, so I guess nobody noticed it was broken.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
i965/disasm: Fix disassembly of the any16h/all16h predicates.

BRW_PREDICATE_ALIGN1_ANY16H was incorrectly being disassembled as
"all16h", and ALL16H would probably print as "(null)".

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
nv50/ir: use unordered_set instead of list to keep track of var uses

The set of variable uses does not need to be ordered in any way, and
removing/adding elements is a fairly common operation in various
optimization passes.

This shortens runtime of piglit test fp-long-alu to ~22s from ~4h

Signed-off-by: Tobias Klausmann <tobias.johannes.klausmann@mni.thm.de>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
nvc0: allocate more space before a counter is configured

On nvc0, a counter can have up to 6 sources instead of only one
for nve4+. This fixes a crash when a counter uses more than
one source.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
mesa: use float to silence MSVC warning in _mesa_GetMultisamplefv()
st/mesa: minor fix-up in st_GetSamplePosition()

If the driver doesn't implement get_sample_position(), let's return
some non-garbage values.
st/mesa: minor simplification of some state atom assignments
mesa: fix geometry shader memory leaks

Spotted by Charmaine Lee.
Cc: "10.2" <mesa-stable@lists.freedesktop.org>

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
st/mesa: fix geometry shader memory leak

Spotted by Charmaine Lee.
Cc: "10.2" <mesa-stable@lists.freedesktop.org>

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Charmaine Lee <charmainel@vmware.com>
radeonsi: fix order of r600_need_dma_space and r600_context_bo_reloc

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
tgsi: properly parse indirect dimension references (e.g. for UBOs)

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Brian Paul <brianp@vmware.com>
gallium/u_blitter: fix some shader memory leaks

The _msaa shaders weren't getting freed.
Cc: "10.2" <mesa-stable@lists.freedesktop.org>

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
glsl/glcpp: Do not allow undefining the built-in macros

Fixes piglit tests in spec/glsl-es-3.00/compile:
undef-__FILE__.vert
undef-GL_ES.vert
undef-__LINE__.vert
undef-__VERSION__.vert

Also, fixes Khronos GLES3 CTS tests:
undefine_invalid_object_1_vertex
undefine_invalid_object_1_fragment
undefine_invalid_object_2_vertex
undefine_invalid_object_2_fragment

Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
glsl/glcpp: Add test to ensure compiler won't allow #undef for some builtins

Currently verifying that an #undef of __FILE__, __LINE__, or __VERSION__ will
generate an error.

Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
glsl/glcpp: Fix preprocessor error condition for macro redefinition

This patch specifically fixes redefinition condition for white space
changes. #define and #undef functionality in GLSL follows the standard
for C++ preprocessors for macro definitions.

From https://gcc.gnu.org/onlinedocs/cpp/Undefining-and-Redefining-Macros.html:

These definitions are effectively the same:

     #define FOUR (2 + 2)
     #define FOUR         (2    +    2)
     #define FOUR (2 /* two */ + 2)

but these are not:

     #define FOUR (2 + 2)
     #define FOUR ( 2+2 )
     #define FOUR (2 * 2)
     #define FOUR(score,and,seven,years,ago) (2 + 2)

Fixes Khronos GLES3 CTS tests;
invalid_object_whitespace_vertex
invalid_object_whitespace_fragment

Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
glsl/glcpp: Fixup glcpp tests for redefining a macro with whitespace changes.

Previously, the test suite was expecting the compiler to allow a redefintion
of a macro with whitespace added, but gcc is more strict and allows only for
changes in the amounts of whitespace, (but insists that whitespace exist or
not in exactly the same places).

See: https://gcc.gnu.org/onlinedocs/cpp/Undefining-and-Redefining-Macros.html:

 These definitions are effectively the same:

      #define FOUR (2 + 2)
      #define FOUR         (2    +    2)
      #define FOUR (2 /* two */ + 2)

 but these are not:

      #define FOUR (2 + 2)
      #define FOUR ( 2+2 )
      #define FOUR (2 * 2)
      #define FOUR(score,and,seven,years,ago) (2 + 2)

This change adjusts the existing "redefine-macro-legitimate" test to work with
the more strict understanding, and adds a new "redefine-whitespace" test to
verify that changes in the position of whitespace are flagged as errors.

Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
glsl/glcpp: Fix glcpp to catch garbage after #if 1 ... #else

Previously, a line such as:

	#else garbage

would flag an error if it followed "#if 0", but not if it followed "#if 1".

We fix this by setting a new bit of state (lexing_else) that allows the lexer
to defer switching to the <SKIP> start state until after the NEWLINE following
the #else directive.

A new test case is added for:

	#if 1
	#else garbage
	#endif

which was untested before, (and did not generate the desired error).

This fixes the following Khronos GLES3 CTS tests:

	tokens_after_else_vertex
        tokens_after_else_fragment

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
glsl/glcpp: Fix glcpp to properly lex entire "preprocessing numbers"

The preprocessor defines a notions of a "preprocessing number" that
starts with either a digit or a decimal point, and continues with zero
or more of digits, decimal points, identifier characters, or the sign
symbols, ('-' and '+').

Prior to this change, preprocessing numbers were lexed as some
combination of OTHER and IDENTIFIER tokens. This had the problem of
causing undesired macro expansion in some cases.

We add tests to ensure that the undesired macro expansion does not
happen in cases such as:

	#define e +1
	#define xyz -2

	int n = 1e;
	int p = 1xyz;

In either case these macro definitions have no effect after this
change, so that the numeric literals, (whether valid or not), will be
passed on as-is from the preprocessor to the compiler proper.

This fixes the following Khronos GLES3 CTS tests:

	preprocessor.basic.correct_phases_vertex
	preprocessor.basic.correct_phases_fragment

v2. Thanks to Anuj Phogat for improving the original regular expression,
(which accepted a '+' or '-', where these are only allowed after one of
[eEpP]. I also expanded the test to exercise this.

v3. Also fixed regular expression to require at least one digit at the
beginning (after an optional period). Otherwise, a string such as ".xyz" was
getting sucked up as a preprocessing number, (where obviously this should be a
field access). Again, I expanded the test to exercise this.

Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
glsl/glcpp: Add short-circuiting for || and && in #if/#elif for OpenGL ES.

The GLSL ES Specification 3.00.4 says:

	#if, #ifdef, #ifndef, #else, #elif, and #endif are defined to operate
        as for C++ except for the following:
	...
	• Undefined identifiers not consumed by the defined operator do not
	  default to '0'. Use of such identifiers causes an error.

	[Page 11 (page 127 of the PDF file)]

as well as:

	The semantics of applying operators in the preprocessor match those
	standard in the C++ preprocessor with the following exceptions:

	• The 2nd operand in a logical and ('&&') operation is evaluated if
	  and only if the 1st operand evaluates to non-zero.

	• The 2nd operand in a logical or ('||') operation is evaluated if
	  and only if the 1st operand evaluates to zero.

	If an operand is not evaluated, the presence of undefined identifiers
	in the operand will not cause an error.

(Note that neither of these deviations from C++ preprocessor behavior apply to
non-ES GLSL, at least as of specfication version 4.30.6).

The first portion of this, (generating an error for an undefined macro in an
(short-circuiting to squelch errors), was not implemented previously, but is
implemented in this commit.

A test is added for "make check" to ensure this behavior.

Note: The change as implemented does make the error message a bit less
precise, (it just states that an undefined macro was encountered, but not the
name of the macro).

This commit fixes the following Khronos GLES3 conformance test:

	undefined_identifiers.valid_undefined_identifier_1_vertex
	undefined_identifiers.valid_undefined_identifier_1_fragment
	undefined_identifiers.valid_undefined_identifier_2_vertex
	undefined_identifiers.valid_undefined_identifier_2_fragment

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
glsl/glcpp: Once again report undefined macro name in error message.

While writing the previous commit message, I just felt bad documenting the
shortcoming of the change, (that undefined macro names would not be reported
in error messages).

Fix this by preserving the first-encounterd undefined macro name and reporting
that in any resulting error message.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>