Commit Graph

36351 Commits

Author SHA1 Message Date
Eric Anholt
fade78edcb glsl2: strdup the field names used in dereference_record.
Otherwise, after linking and freeing the old data, the pointer would
dangle.  Partial fix for glsl1-struct*.
2010-07-20 17:30:10 -07:00
Eric Anholt
21b0dbd799 glsl2: talloc the glsl_struct_field[] we use to look up structure types.
Since the types are singletons across the lifetime of the compiler,
repeatedly compiling a program with the same structure type defined
would drop a copy of the array on the floor per compile.

This is a bit tricky because the static GLSL types are not called with
the talloc-based new, so we have to use the global type context, which
may not be initialized yet.
2010-07-20 17:30:10 -07:00
Eric Anholt
b6e92ad7da glsl2: Don't claim a match on structure types with different field names.
We regularly do lookups on the field names of the structure to find
the types within the struct, so returning a structure type with bad
names will lead to lots of error types being found.
2010-07-20 17:30:10 -07:00
Kenneth Graunke
094cf8c199 glsl2: Add support for the .length() method on arrays.
Fixes piglit test glsl-array-length, and provides proper error messages
for negative piglit tests array-length-110.frag, array-length-unsized.frag,
and array-length-args.frag.
2010-07-20 17:13:17 -07:00
Kenneth Graunke
1036a7ebae glsl2: Remove incorrect assertion in the parser.
This assertion is triggered by method calls (i.e. array.length()), where
subexpressions[1] is an ast_function_call expression.  Since the
assertion itself had a comment saying it could be removed eventually,
simply do so.

Causes negative glslparser tests array-length-110.frag,
array-length-args.frag, and array-length-unsized.frag to pass, but only
because the length() method is not supported yet.
2010-07-20 17:13:17 -07:00
Kenneth Graunke
2b7c42b40a glsl2: Disallow non-constant array indexing for unsized arrays.
Fixes piglit test unsized-array-non-const-index.vert.
2010-07-20 17:13:17 -07:00
Kenneth Graunke
e4768eecd5 ir_constant_expression: Remove pointless use of variable_referenced.
ir_dereference_variable always references an ir_variable, so there's no
point in calling a function and NULL-checking the result.
2010-07-20 17:10:05 -07:00
Kenneth Graunke
98f32a13be ir_constant_expression: Use "this" pointer directly.
In ir_expression's signature, I replaced ir->operands[i] with op[i] as
it is more concise; an assertion already ensures these are equal.
2010-07-20 17:10:05 -07:00
Kenneth Graunke
fb2ffd2846 ir_constant_expression: Convert from a visitor to a virtual function.
The constant_expression_wrapper was already the only external API, and
much of the internal code used it anyway.  Also, it wouldn't ever visit
non-rvalue ir_instructions, so using a visitor seemed a bit unnecessary.

This uses "ir_foo *ir = this;" lines to avoid code churn.  These should
be removed.
2010-07-20 17:10:05 -07:00
Kenneth Graunke
e340854115 glsl2: Move constant_expression_value method to ir_rvalue.
This prevents top-level callers from asking for the value of something
that is guaranteed not to have one.
2010-07-20 17:10:05 -07:00
Carl Worth
e1acbfca32 glcpp: Avoid accidental token pasting in preprocessed result.
Consider this test case:

	#define EMPTY
	int foo = 1+EMPTY+4;

The expression should compile as the sequence of tokens 1, PLUS,
UNARY_POSITIVE, 4. But glcpp has been failing for this case since it
results in the string "1++4" which a compiler correctly sees as a
syntax error, (1, POST_INCREMENT, 4).

We fix this by changing any macro with an empty definition to result
in a single SPACE token rather than nothing. This then gives "1+ +4"
which compiles correctly.

This commit does touch up the two existing test cases which already
have empty macros, (to add the space to the expected result).

It also adds a new test case to exercise the above scenario.
2010-07-20 17:01:12 -07:00
Carl Worth
942ccc5170 glcpp: Add missing include in xtalloc.c
Without this, the compiler was legitimately complaining about missing
declarations for all of the functions being defined here.
2010-07-20 17:01:12 -07:00
Carl Worth
d80dcaf427 glcpp: Add static keyword to several functions in the parser.
This quiets warnings about missing declarations otherwise.
2010-07-20 17:01:11 -07:00
Carl Worth
fb90560744 glcpp: Avoid warnings in generated flex code.
We define the YY_NO_INPUT macro to avoid one needless function being
generated.

for the other needless functions, (yyunput and yy_top_state), we add a
new UNREACHABLE start condition and call these functions from an
action there. This doesn't change functionality at all, (since we
never enter the UNREACHABLE start condition), but makes the compiler
stop complaining about these two functions being defined but not used.
2010-07-20 17:01:11 -07:00
Carl Worth
a9bb4bcde3 glcpp-lex: Declare some generated functions to eliminate compiler warnings.
It's really a bug in flex that these functions are generated with neither
a declaration nor the 'static' keyword, but we can at least avoid the
warnings this way.
2010-07-20 17:01:11 -07:00
Carl Worth
1d7e03e48e glcpp: Fix support for nested #ifdef and nested #ifndef
Previously, if the outer #ifdef/#ifndef evaluated to false, the inner
directive would not be parsed correctly, (the identifier as the subject
of the #ifdef/#ifndef would inadvertently be skipped along with the other
content correctly being skipped).

We fix this by setting the lexing_if state in each case here.

We also add a new test to the test suite to ensure that this case is tested.
2010-07-20 17:01:11 -07:00
Carl Worth
17f9beb6c3 glcpp: Support #if(expression) with no intervening space.
And add a test case to ensure that this works.
2010-07-20 17:01:11 -07:00
Carl Worth
61ebc01dfe glcpp: Fix use-after-free error from #undef directive.
By taking advantage of the recently-added hash_table_remove function.

With this change, all existing tests are now valgrind-clean.
2010-07-20 17:01:11 -07:00
Carl Worth
d4f239de6e hash_table: Add new hash_table_remove function.
To allow for the removal of a single element from a hash table.
2010-07-20 17:01:11 -07:00
Carl Worth
d1500f8a19 glcpp: Make test suite test for valgrind cleanliness.
As it turns out, 4 of our current tests are not valgrind clean,
(use after free errors or so), so this will be helpful for
investigating and fixing those.
2010-07-20 17:01:11 -07:00
Carl Worth
3a530b8ef6 glcpp: Make test suite report final count of passed/total tests.
And report PASS or FAIL for each test along the way as well.
2010-07-20 17:01:11 -07:00
Carl Worth
41d525f2df Build a standalone glcpp binary.
This is convenient for testing the preprocessor independent of the rest of
mesa, (just run glcpp-test in the src/glsl/glcpp/tests).
2010-07-20 17:01:11 -07:00
Carl Worth
f15e27ec1d glcpp: Delete copies of hash_table.c, hash_table.h, and other headers.
These were only ever intended to exist in the original, standalone
implementation of glcpp, (with the idea of dropping them as soon as
the code moved into mesa). The current build system wasn't compiling
this C file, but the presence of the header files could cause problems
if the two copies diverge in the future.

We head those problems off by deleting al of these redundant files.
2010-07-20 17:01:11 -07:00
Eric Anholt
325a49701f glsl2: Fix handling of out values in function inlining.
The parameters[i] is our inlined variables representing the
parameters, so they are always ir_var_auto.  Walk the signature params
in handling "out" values like we do for "in" values to find the mode.

Fixes (with the previous 2 commits):
glsl1-function call with in, out params
glsl1-function call with inout params
2010-07-20 16:21:07 -07:00
Eric Anholt
2927c81ed1 glsl2: Don't mark a variable as constant if it was used as an out param. 2010-07-20 15:59:04 -07:00
Eric Anholt
02d3711a21 glsl2: Always insert function calls into the instruction stream.
If they have a return value, this means putting it into a temporary
and making a deref of the temp be the rvalue, since we don't know if
the rvalue will be used or not.
2010-07-20 15:59:04 -07:00
Eric Anholt
f8946699ec glsl2: Add definitions of the builtin constants present in GLSL 1.10.
Fixes:
glsl1-built-in constants
2010-07-20 14:03:35 -07:00
Eric Anholt
1245babe0c glsl2: Fix asin() implementation.
I'd flipped around the order of two operations in paren-balancing
adventures, and left out the multiply by sign(x) required for negative x.

Fixes:
glsl1-acos(vec4) function
glsl1-asin(vec4) function
glsl1-atan(vec4) function
2010-07-20 12:24:01 -07:00
Eric Anholt
117d154b4d glsl2: notEqual() produces a boolean value, not the base type of the args.
Fixes:
glsl1-vector relational (bvec2 ==,!=)
glsl1-vector relational (vec4 !=)
2010-07-20 12:01:40 -07:00
Eric Anholt
14f8e16132 glsl2: Constant-fold assignment conditions. 2010-07-20 12:01:40 -07:00
Ian Romanick
5a2e0b8ce5 glsl2: Don't validate IR if there were compilation errors 2010-07-20 11:38:54 -07:00
Eric Anholt
18ab797d3a ir_to_mesa: Fix swizzled writemasks with swapped component ordering.
I hadn't noticed you could do this, but glsl1 tests caught it.  Fixes:
glsl1-Swizzled writemask
glsl1-Swizzled writemask (2)
glsl1-Swizzled writemask (rgba)
glsl1-Swizzled writemask (stpq)
2010-07-20 11:28:33 -07:00
Ian Romanick
cd6764ed6e linker: Remove the FINISHME comment for intrastage linking 2010-07-19 14:50:43 -07:00
Ian Romanick
1a03a644d2 linker: Remove redundant check for 'main' in shaders
This is now handled in link_intrastage_shaders.
2010-07-19 14:50:43 -07:00
Ian Romanick
25f51d3b9b linker: Track and validate GLSL versions used in shaders 2010-07-19 14:50:43 -07:00
Ian Romanick
b64e979971 glsl2: Use Elements macro 2010-07-19 14:50:43 -07:00
Ian Romanick
fc9ae101b4 linker: Recursively resolve function calls in imported functions 2010-07-19 14:50:43 -07:00
Ian Romanick
532c2d3085 linker: look up function signatures during linking instead of using callee
Instead of using ir_call::callee, search for the signature in the
linked shader.  This will allow resolving calls from functions
imported from other shaders.  The ir_call::callee pointer in the
imported function will still reference a signature in the original shader.
2010-07-19 14:50:43 -07:00
Ian Romanick
5adbf0bff1 linker: Pull find_matching_signature out of call_link_visitor
The list of shaders to search needs to be provided as an explicit
parameter to support coming changes.  At that point there is no reason
for it to be in the class.  Also, fix some of the 'const' decorators.
2010-07-19 14:50:43 -07:00
Ian Romanick
b95897b89d glsl2: Explicitly walk lists in ir_function::parameter_lists_match
Give ir_function::parameter_lists_match_exist similar treatment.  Make
the parameters const, and propogate the constness as far as it will
trivially go.
2010-07-19 14:50:43 -07:00
Ian Romanick
de415b7f4b linker: Add comment about bug in initializer handling 2010-07-19 14:50:43 -07:00
Ian Romanick
8fe8a814b0 linker: First bits of intrastage, intershader function linking
This handles the easy case of linking a function in a different
compilation unit that doesn't call any functions or reference any
global variables.
2010-07-19 14:50:43 -07:00
Ian Romanick
a48a2b66e8 ir_function_signature: Make actual_parameters public 2010-07-19 14:50:43 -07:00
Ian Romanick
3880d07f4b linker: Remove some unnecessary includes 2010-07-19 14:50:43 -07:00
Kenneth Graunke
61a44ccaef exec_list: Fix foreach_list_safe.
It now works correctly when nodes are removed, as it was originally
intended to do; it no longer processes nodes added to the list before
the current node, nor those added immediately after the current node.

This matches the behavior of Linux's list_for_each_safe.
2010-07-19 14:49:34 -07:00
Ian Romanick
303c99f12f linker: Use foreach_list_safe in move_non_declarations
The node being processed may be removed from the list and put in a
different list.  Not using the safe version caused list processing to
change streams after moving a node.
2010-07-19 12:36:32 -07:00
Ian Romanick
9303e358cb linker: Move global instructions from the linked shader first
For the shader containing 'main', use the linked shader (i.e., the
clone of the original shader that contained main) as the source for
global instructions to move into main.
2010-07-19 12:36:32 -07:00
Eric Anholt
5304493c40 glsl2: Fix lexing of octal values, including "0".
When faced with a constructor like 'ivec4(0, 2, 0, 0)', we would
manage to get a value of 2 instead of 0 for the first "0".  Usually 2
characters past "0" would point at some junk and lex as 0 anyway.

Fixes glsl-octal and glsl-unused-varyings.
2010-07-19 11:58:03 -07:00
Eric Anholt
82d4b9593b glsl2: Fix the expression type for atan's pi * sign(y).
Fixes CorrectFunction.vert.
2010-07-19 10:47:12 -07:00
Eric Anholt
95c08920ea i915: Ask the compiler to flatten out all the if statements that it can. 2010-07-19 10:47:08 -07:00