Commit graph

170 commits

Author SHA1 Message Date
Kenneth Graunke
a98d5a5ac8 glsl: Allow overloading of built-ins without hiding in GLSL ES.
The rules are explicitly different from desktop GLSL.
2010-09-07 17:30:39 -07:00
Kenneth Graunke
f412fac5b4 glsl: Move is_builtin flag back to ir_function_signature.
This effectively reverts b6f15869b3.

In desktop GLSL, defining a function with the same name as a built-in
hides that built-in function completely, so there would never be
built-in and user function signatures in the same ir_function.

However, in GLSL ES, overloading built-ins is allowed, and does not
hide the built-in signatures - so we're back to needing this.
2010-09-07 17:30:38 -07:00
Kenneth Graunke
c98deb18d5 ast_to_hir: Reject embedded structure definitions in GLSL ES 1.00. 2010-09-07 17:30:38 -07:00
Kenneth Graunke
d8e34e29eb ast_to_hir: Reject unsized array declarations in GLSL ES 1.00. 2010-09-07 17:30:38 -07:00
Kenneth Graunke
814c89abdb glsl: Set default language version in mesa_glsl_parse_state constructor.
This should make it easier to change the default version based on the
API (say, version 1.00 for OpenGL ES).

Also, synchronize the symbol table's version with the parse state's
version just before doing AST-to-HIR.  This way, it will be set when
it matters, but the main initialization code doesn't have to care about
the symbol table.
2010-09-07 17:30:37 -07:00
Ian Romanick
f09fabc448 glsl2: Forbid array-types in ?: operator in GLSL 1.10
Fixes bugzilla #30039.
2010-09-07 14:33:29 -07:00
Kenneth Graunke
f32d3df8ab glsl: Apply implicit conversions to structure constructor parameters.
The code for handling implicit conversions should probably get
refactored, but for now, this is easy.

Fixes piglit test constructor-26.vert.
2010-09-01 20:39:09 -07:00
Ian Romanick
e466b182bb glsl2: Remove unnecessary glsl_symbol_table::get_function parameter return_constructors
Now that constructors are not generated as functions or stored in the
symbol table, there is no need to flag whether or not constructors
should be returned.
2010-09-01 20:39:09 -07:00
Ian Romanick
a789ca649c glsl2: Don't generate constructor functions for structures 2010-09-01 20:39:09 -07:00
Ian Romanick
63b80f8cc1 glsl2: Disallow function declarations within function definitions in GLSL 1.20
The GLSL 1.20 spec specifically disallows this, but it was allowed in
GLSL 1.10.

Fixes piglit test cases local-function-0[13].frag and bugzilla #29921.
2010-09-01 07:08:34 -07:00
Kenneth Graunke
1eea96326f ast_to_hir: Add support for bit-wise operators (but not shifts).
Previously, using bit-wise operators in some larger expression would
crash on a NULL pointer dereference.  This code at least doesn't crash.

Fixes piglit test bitwise-01.frag.
2010-08-31 11:00:34 -07:00
Ian Romanick
de3b40d8cd glsl2: Remove a couple FINISHME comments that have already been resolved 2010-08-26 09:24:58 -07:00
Kenneth Graunke
a044285e25 glsl: Move built-ins to live beyond the global scope.
Per the GLSL 1.20 specification (presumably a clarification of 1.10).

Also, when creating user functions, make a new ir_function that shadows the
built-in ir_function, rather than adding new signatures.  User functions
are supposed to hide built-ins, not overload them.

Fixes piglit tests redeclaration-{04, 12, 14}.vert.
2010-08-26 09:19:48 -07:00
Kenneth Graunke
5d25746640 glsl: Refactor variable declaration handling.
Moving the check for an earlier variable declaration helps cleanly
separate out the re-declaration vs. new declaration code a bit.  With
that in place, conflicts between variable names and structure types or
function names aren't caught by the earlier "redeclaration" error
message, so check the return type on glsl_symbol_table::add_variable
and issue an error there.  If one occurs, don't emit the initializer.

Fixes redeclaration-01.vert and redeclaration-09.vert.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
2010-08-26 09:19:48 -07:00
Kenneth Graunke
ac2376e6f5 glsl: Don't add overloads to existing structure constructors.
Instead, make a new ir_function and try to add it to the symbol table.

Fixes piglit test redeclaration-08.vert.
2010-08-26 09:19:48 -07:00
Kenneth Graunke
e09591317b glsl: Remove name_declared_this_scope check when adding functions.
Instead, rely on the symbol table's rules.

Fixes redeclaration-02.vert.
2010-08-26 09:19:48 -07:00
Kenneth Graunke
e9c7ceed27 glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.

However, in 1.10, variables and functions can share the same name in the
same scope.  Structure types, however, conflict with/hide both.

Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-26 09:19:48 -07:00
Aras Pranckevicius
5226f8c7b0 glsl: fix crash with variable indexing into array in a struct
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
2010-08-25 16:22:44 -07:00
Chia-I Wu
bfd7c9ac22 glsl: Include main/core.h.
Make glsl include only main/core.h from core mesa.
2010-08-24 11:27:29 +08:00
Eric Anholt
e11757bb89 glsl: When unable to assign the initializer for a const variable, set it to 0.
This prevents assertion failures or cascading errors after we've
logged the fact that we were unable to handle the initializer.

Fixes unsized-array-non-const-index-2.vert
2010-08-23 14:58:38 -07:00
Eric Anholt
76e96d74f4 glsl: Cleanly fail when a function has an unknown return type.
Bug #29608.
2010-08-23 13:27:36 -07:00
Eric Anholt
a721abfbd1 glsl: Trim the size of uniform arrays to the maximum element used.
Fixes glsl-getactiveuniform-array-size.
2010-08-23 10:34:31 -07:00
Vinson Lee
13b3d4c23d glsl: Silence unused variable warning.
The variable is actually used but only in the body of an assert.
2010-08-21 16:22:18 -07:00
Kenneth Graunke
e511a35fc5 glsl: Handle array declarations in function parameters.
The 'vec4[12] foo' style already worked, but the 'vec4 foo[12]' style
did not.  Also, 'vec4[] foo' was wrongly accepted.

Fixes piglit test cases array-19.vert and array-21.vert.

May fix fd.o bug #29684 (or at least part of it).
2010-08-21 15:42:27 -07:00
Kenneth Graunke
edd180f032 ast_to_hir: Reject function names that start with "gl_".
Fixes piglit test redeclaration-03.vert.
2010-08-20 02:46:05 -07:00
Kenneth Graunke
826a39cb14 ast_to_hir: Fix crash when a function shadows a variable.
The code would attempt to add a new signature to the ir_function, which
didn't exist.  Simply bailing out/returning early seems reasonable.

Fixes piglit test redeclaration-02.vert, and fixes a crash in
redeclaration-03.vert (the test still fails).
2010-08-20 02:46:05 -07:00
Kenneth Graunke
665d75cc5a glsl: Fix scoping bug in if statements.
Fixes glslparsertest/glsl2/scoping-01.frag (successfully compiled but
should've failed) and scoping-02.frag (assertion triggered).
2010-08-18 14:03:25 -07:00
Ian Romanick
768b55a526 glsl2: Remove unnecessary use of 'struct' before type names
In C++ you don't have to say 'struct' or 'class' if the declaration of
the type has been seen.  Some compilers will complain if you use
'struct' when 'class' should have been used and vice versa.

Fixes bugzilla #29539.
2010-08-13 16:46:43 -07:00
Ian Romanick
202604e816 glsl2: Don't declare a variable called sig that shadows the other one
Accidentally having a variable called 'sig' within an if-statement
cause the higher scope 'sig' to always be NULL.  As a result a new
function signature was created for a function definition even when one
already existed from a prototype declaration.

Fixes piglit test case glsl-function-prototype (bugzilla #29520).
2010-08-11 16:58:25 -07:00
Eric Anholt
8048226b7b glsl2: Insert global declarations at the top of the instruction stream.
Fixes use-before-decl in glslparsertest shaders.

Fixes:
CorrectFull.frag
CorrectModule.frag
2010-08-05 14:41:09 -07:00
Eric Anholt
046bef2357 glsl2: Remove the shader_in/shader_out tracking separate from var->mode.
I introduced this for ir_dead_code to distinguish function parameter
outvals from varying outputs.  Only, since ast_to_hir's
current_function is unset when setting up function parameters (they're
needed for making the function signature in the first place), all
function parameter outvals were marked as shader outputs anyway.  This
meant that an inlined function's cloned outval was marked as a shader
output and couldn't be dead-code eliminated.  Instead, since
ir_dead_code doesn't even look at function parameters, just use
var->mode.

The longest Mesa IR coming out of ir_to_mesa for Yo Frankie drops from
725 instructions to 636.
2010-08-04 20:52:33 -07:00
Ian Romanick
8e9ce2eb56 glsl2: Don't try to construct an ir_assignment with an invalid LHS 2010-08-04 16:47:27 -07:00
Eric Anholt
8273bd4687 glsl2: Make the clone() method take a talloc context.
In most cases, we needed to be reparenting the cloned IR to a
different context (for example, to the linked shader instead of the
unlinked shader), or optimization before the reparent would cause
memory usage of the original object to grow and grow.
2010-08-04 12:42:47 -07:00
Aras Pranckevicius
1c325af4d6 glsl2: Fix stack smash when ternary selection is used. 2010-07-31 12:00:01 -07:00
Eric Anholt
fa33d0b854 glsl2: Fix spelling of "initializer." 2010-07-29 14:02:19 -07:00
Eric Anholt
4a962170d7 glsl2: Add support for redeclaring layout of gl_FragCoord for ARB_fcc.
Fixes:
glsl-arb-fragment-coord-conventions
2010-07-28 15:00:09 -07:00
Ian Romanick
8d8469eb2a glsl2: Perform some semantic checking of ARB_fcc layout qualifiers
The rest cannot be handled until built-in variables (i.e.,
gl_FragCoord) can be redeclared to add qualifiers.
2010-07-28 14:16:12 -07:00
Eric Anholt
a0879b9dd4 glsl2: Put side effects of the RHS of logic_or in the right branch.
Kind of missing the point to only do the side effects if the LHS
evaluates as true.

Fixes:
glsl1-|| operator, short-circuit
2010-07-22 16:34:36 -07:00
Eric Anholt
9703ed05e6 glsl2: When setting the size of an unsized array, set its deref's size too. 2010-07-22 15:56:07 -07:00
Carl Worth
47c90b1447 glsl2: Fix expected type for multiplying vector with non-square matrix.
Previously, the compiler expected the result of the multiplication to
be of the same type as the vector. This is correct for square
matrices, but wrong for all others.

We fix this by instead expecting a vector with the same number of rows
as the matrix (for the case of M*v with a column vector) or the same
number of columns as the matrix (for v*M with a row vector).

This fix causes the following four glean tests to now pass:

	glsl1-mat4x2 * vec4
  	glsl1-vec2 * mat4x2 multiply
  	glsl1-vec3 * mat4x3 multiply
  	glsl1-vec4 * mat3x4 multiply
2010-07-22 14:59:06 -07:00
Eric Anholt
2d1ed7b1b1 glsl2: When a "continue" happens in a "for" loop, run the loop expression.
Fixes:
glsl1-for-loop with continue

Bug #29097
2010-07-22 13:02:40 -07:00
Kenneth Graunke
e1d71850fa ast_to_hir: Fix bug in constant initializers.
Implicit conversions were not being performed, nor was there any
type checking - it was possible to have, say, var->type == float
and var->constant_value->type == int.  Later use of the constant
expression would trigger an assertion.

Fixes piglit test const-implicit-conversion.frag.
2010-07-21 16:38:32 -07:00
Carl Worth
c24bcad9f8 glsl: Correctly handle unary plus operator.
Previously, any occurence of the unary plus operator would trigger a
bogus type mismatch error. Fix this by making the ast_plus case look
more like the ast_neg case as far as type-checking is concerned.

With this change the shaders/CorrectPreprocess8.frag test in piglit
now passes.
2010-07-21 11:42:27 -07:00
Ian Romanick
f38d15b80d glsl2: glsl_type has its own talloc context, don't pass one in 2010-07-20 17:48:25 -07:00
Ian Romanick
7e2aa91507 glsl2: Add and use new variable mode ir_var_temporary
This is quite a large patch because breaking it into smaller pieces
would result in the tree being intermitently broken.  The big changes
are:

    * Add the ir_var_temporary variable mode

    * Change the ir_variable constructor to take the mode as a
      parameter and correctly specify the mode for all ir_varables.

    * Change the linker to not cross validate ir_var_temporary
      variables.

    * Change the linker to pull all ir_var_temporary variables from
      global scope into 'main'.
2010-07-20 17:48:24 -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
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
Ian Romanick
81d664f099 glsl2: Move temp declaration to correct side of if-statement in IR 2010-07-12 15:19:29 -07:00
Ian Romanick
0b9ae3befb glsl2: Add declarations for temporaries to instruction stream
Temporary variables added for &&, ||, and ?: were not being added to
the instruction stream.  This resulted in either test failures or
Valgrind being angry after the original IR tree was destroyed by
talloc_free.  The talloc_free caused the ir_variables to be destroyed
even though they were still referenced.
2010-07-12 14:56:21 -07:00
Kenneth Graunke
dfd30ca6a9 glsl2: Remove generate_temporary and global temporary counter.
Most places in the code simply use a static name, which works because
names are never used to look up an ir_variable.  generate_temporary is
simply unnecessary (and looks like it would leak memory, and isn't
thread safe...)
2010-07-08 15:44:19 -07:00