Commit graph

90 commits

Author SHA1 Message Date
Eric Anholt
ff79633d9f glsl: Fix structure and array comparisions.
We were trying to emit a single ir_expression to compare the whole
thing.  The backends (ir_to_mesa.cpp and brw_fs.cpp so far) expected
ir_binop_any_nequal or ir_binop_all_equal to apply to at most a vector
(with matrices broken down by the lowering pass).  Break them down to
a bunch of ORed or ANDed any_nequals/all_equals.

Fixes:
glsl-array-compare
glsl-array-compare-02
glsl-fs-struct-equal
glsl-fs-struct-notequal
Bug #31909
2010-11-30 11:42:42 -08:00
Eric Anholt
001eee52d4 glsl: Make the symbol table's add_variable just use the variable's name. 2010-11-29 17:08:27 -08:00
Eric Anholt
e8f5ebf313 glsl: Make the symbol table's add_function just use the function's name. 2010-11-29 17:08:27 -08:00
Chad Versace
b4cdba687c glsl: Fix erroneous cast in ast_jump_statement::hir()
Return values were erroneously cast from (ir_rvalue*) to (ir_expression*).

NOTE: This is a candidate for the 7.9 branch.
2010-11-17 11:59:32 -08:00
Chad Versace
6e00627384 glsl: Fix ast-to-hir for ARB_fragment_coord_conventions
Function ast_declarator_list::hir(), when processing keywords added by
extension ARB_fragment_coord_conventions, made the mistake of checking only if
the extension was __supported by the driver__. The correct behavior is to check
if the extensi0n is __enabled in the parse state__.

NOTE: this is a candidate for the 7.9 branch.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2010-10-25 10:10:58 -07:00
Kenneth Graunke
a75da2c0e8 glsl: Remove useless ir_shader enumeration value. 2010-10-20 15:07:47 -07:00
Vinson Lee
460da0db4a glsl: Add assert for unhandled ir_shader case.
Silences this GCC warning.
ast_to_hir.cpp: In function 'void apply_type_qualifier_to_variable(const
ast_type_qualifier*, ir_variable*, _mesa_glsl_parse_state*, YYLTYPE*)'
ast_to_hir.cpp:1768: warning: enumeration value 'ir_shader' not handled
in switch
2010-10-20 14:10:26 -07:00
Chad Versace
d03ac0f8d8 glsl: Implement ast-to-hir for bit-logic ops
Implement by adding to ast_expression::hir() the following cases:
    - ast_and_assign
    - ast_or_assign
    - ast_xor_assign
2010-10-19 13:17:33 -07:00
Chad Versace
cfdbf8bc84 glsl: Define bit_logic_result_type() in ast_to_hir.cpp
This function type checks the operands of and returns the result type of
bit-logic operations.  It replaces the type checking performed in the
following cases of ast_expression::hir() :
    - ast_bit_and
    - ast_bit_or
    - ast_bit_xor
2010-10-19 13:17:33 -07:00
Chad Versace
338ed6ec29 glsl: Implement ast-to-hir for bit-shift-assignment
Implement by adding to ast_expression::hir() these cases:
    - ast_ls_assign
    - ast_rs_assign
2010-10-19 13:17:33 -07:00
Chad Versace
c0197ab0af glsl: Define shift_result_type() in ast_to_hir.cpp
This function type checks the operands of and returns the result type of
bit-shift operations. It replaces the type checking performed in the following
cases of ast_expression::hir() :
    - ast_lshift
    - ast_rshift
2010-10-19 13:17:33 -07:00
Kenneth Graunke
b8276e46f5 glsl: Don't return NULL IR for erroneous bit-shift operators.
Existing code relies on IR being generated (possibly with error type)
rather than returning NULL.  So, don't break - go ahead and generate the
operation.  As long as an error is flagged, things will work out.

Fixes fd.o bug #30914.
2010-10-18 00:26:14 -07:00
Chad Versace
5c4c36f7f3 glsl: Implement ast-to-hir for binary shifts in GLSL 1.30
Implement by adding the following cases to ast_expression::hir():
    - ast_lshift
    - ast_rshift
Also, implement ir validation for the new operators by adding the following
cases to ir_validate::visit_leave():
    - ir_binop_lshift
    - ir_binop_rshift
2010-10-15 00:20:18 -07:00
Ian Romanick
68a4fc9d5a glsl: Add linker support for explicit attribute locations 2010-10-08 14:21:23 -07:00
Ian Romanick
eee68d3631 glsl: Track explicit location in AST to IR translation 2010-10-08 14:21:23 -07:00
Ian Romanick
e24d35a5b5 glsl: Wrap ast_type_qualifier contents in a struct in a union
This will ease adding non-bit fields in the near future.
2010-10-08 14:21:22 -07:00
Kenneth Graunke
ca92ae2699 glsl: Properly handle nested structure types.
Fixes piglit test CorrectFull.frag.
2010-09-18 11:21:34 +02:00
Kenneth Graunke
81f0339398 glsl: Change from has_builtin_signature to has_user_signature.
The print visitor needs this, and the only existing user can work with
has_user_signature just as well.
2010-09-16 02:52:25 -07:00
Luca Barbieri
4dfb89904c glsl: introduce ir_binop_all_equal and ir_binop_any_equal, allow vector cmps
Currently GLSL IR forbids any vector comparisons, and defines "ir_binop_equal"
and "ir_binop_nequal" to compare all elements and give a single bool.

This is highly unintuitive and prevents generation of optimal Mesa IR.

Hence, first rename "ir_binop_equal" to "ir_binop_all_equal" and
"ir_binop_nequal" to "ir_binop_any_nequal".

Second, readd "ir_binop_equal" and "ir_binop_nequal" with the same semantics
as less, lequal, etc.

Third, allow all comparisons to acts on vectors.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
2010-09-13 17:53:04 -07:00
Kenneth Graunke
10eaa8bcbc ast_to_hir: Mark arrays as lvalues in GLSL ES, but prohibit assignment.
This allows them to be passed as out/inout parameters, but still
prevents them from being used as the target of an assignment.  This is
per section 5.8 of the GLSL ES 1.00 specification.
2010-09-07 17:30:39 -07:00
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