Commit Graph

54 Commits

Author SHA1 Message Date
Ian Romanick 0f0179b8c2 glsl: Remove extra newline from error message 2011-05-03 14:51:02 -07:00
Ian Romanick edf2e4f79d glsl: 80-column wrapping and whitespace fixes 2011-04-18 17:06:08 -07:00
Ian Romanick 8842158944 glsl: Finish out the reduce/reduce error fixes
Track variables, functions, and types during parsing.  Use this
information in the lexer to return the currect "type" for identifiers.

Change the handling of structure constructors.  They will now show up
in the AST as constructors (instead of plain function calls).

Fixes piglit tests constructor-18.vert, constructor-19.vert, and
constructor-20.vert.  Also fixes bugzilla #29926.

NOTE: This is a candidate for the 7.9 and 7.10 branches.
2011-02-11 14:12:43 -08:00
Kenneth Graunke cfd8d45ccd glsl: Fix invalid use of ralloc_asprintf in prototype_string.
This was my mistake when converting from talloc to ralloc.  I was
confused because the other calls in the function are to asprintf_append
and the original code used str as the context rather than NULL.

Fixes bug #33823.
2011-02-01 23:31:35 -08:00
Brian Paul 59c957b688 glsl: add cast to silence signed/unsigned comparison warning 2011-01-31 14:09:24 -07:00
Kenneth Graunke 819d57fce9 glsl: Introduce a new "const_in" variable mode.
This annotation is for an "in" function parameter for which it is only legal
to pass constant expressions.  The only known example of this, currently,
is the textureOffset functions.

This should never be used for globals.
2011-01-31 11:10:59 -08:00
Kenneth Graunke d3073f58c1 Convert everything from the talloc API to the ralloc API. 2011-01-31 10:17:09 -08:00
Chad Versace b66be7518a glsl: Improve error message when read-only vars are written
Improves the cases when:
* an explicit assignment references the read-only variable
* an 'out' or 'inout' function parameter references the read-only variable
2011-01-21 14:06:28 -08:00
Kenneth Graunke c17c790387 glsl: Properly add functions during lazy built-in prototype importing.
The original lazy built-in importing patch did not add the newly created
function to the symbol table, nor actually emit it into the IR stream.

Adding it to the symbol table is non-trivial since importing occurs when
generating some ir_call in a nested scope.  A new add_global_function
method, backed by new symbol_table code in the previous patch, handles
this.

Fixes bug #32030.
2010-12-06 13:43:22 -08:00
Kenneth Graunke f5692f452f glsl: Lazily import built-in function prototypes.
This makes a very simple 1.30 shader go from 196k of memory to 9k.

NOTE: This -may- be a candidate for the 7.9 branch, as the benefit is
substantial.  However, it's not a simple change, so it may be wiser to
wait for 7.10.
2010-11-30 13:48:28 -08:00
Ian Romanick bb756bb0a6 glsl: Fix matrix constructors with vector parameters
When the semantics of write masks in assignments were changed, this
code was not correctly updated.

Fixes piglit test glsl-mat-from-vec-ctor-01.
2010-11-19 17:17:25 -08:00
Ian Romanick 2d2d6a80c1 glsl: Simplify generation of swizzle for vector constructors 2010-11-16 12:11:02 -08:00
Kenneth Graunke afb6fb9a92 glsl: Remove unnecessary "unused variable" warning suppression.
The "instructions" variable -is- used, so the cast to void can go away.
2010-11-09 15:55:40 -08:00
Kenneth Graunke ba2382f50d glsl: Fix constant component count in vector constructor emitting.
Fixes freedesktop.org bug #31101 as well as piglit test cases
assignment-type-mismatch.vert and constructor-28.vert.
2010-10-25 12:56:47 -07:00
Eric Anholt b39e6f33b6 glsl: Rework assignments with write_masks to have LHS chan count match RHS.
It turns out that most people new to this IR are surprised when an
assignment to (say) 3 components on the LHS takes 4 components on the
RHS.  It also makes for quite strange IR output:

(assign (constant bool (1)) (x) (var_ref color) (swiz x (var_ref v) ))
(assign (constant bool (1)) (y) (var_ref color) (swiz yy (var_ref v) ))
(assign (constant bool (1)) (z) (var_ref color) (swiz zzz (var_ref v) ))

But even worse, even we get it wrong, as shown by this line of our
current step(float, vec4):

(assign (constant bool (1)) (w)
	(var_ref t)
	(expression float b2f (expression bool >=
		    (swiz w (var_ref x))(var_ref edge))))

where we try to assign a float to the writemasked-out x channel and
don't supply anything for the actual w channel we're writing.  Drivers
right now just get lucky since ir_to_mesa spams the float value across
all the source channels of a vec4.

Instead, the RHS will now have a number of components equal to the
number of components actually being written.  Hopefully this confuses
everyone less, and it also makes codegen for a scalar target simpler.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2010-09-22 13:09:51 -07:00
Kenneth Graunke b4ec3f268c ast_to_hir: Allow matrix-from-matrix constructors in GLSL ES.
Everything but 1.10 supports this, so just change the check to ==.
2010-09-07 17:30:38 -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
Kenneth Graunke 43a6200f3c glsl: Convert constant record constructor parameters to ir_constants.
I'm not sure if this is strictly necessary, but it seems wise.
2010-09-01 20:39:09 -07:00
Kenneth Graunke cfe0dd5622 glsl: Reject structure constructors that have too many arguments.
Fixes piglit test constructor-27.vert.
2010-09-01 20:39:09 -07:00
Ian Romanick 37200d83d3 glsl2: Emit structure constructors inline
Fixes piglit test cases glsl-[fv]s-all-0[12].
2010-09-01 20:39:09 -07:00
Kenneth Graunke 3960558795 glsl: Fix write mask in matrix-from-matrix constructors.
If the matrix being constructed was larger than the source matrix, it
would overwrite the lower-right part of the matrix with the wrong
values, rather than leaving it as the identity matrix.

For example, constructing a mat4 from a mat2 should only use a writemask
of "xy" when copying from the source, but was using "xyzw".

Fixes the code generated by piglit test constructor-23.vert.
2010-09-01 18:57:51 -07:00
Kenneth Graunke 1f7c7df40f glsl: Move generate_constructor_(matrix|vector) to ir_constant ctor. 2010-09-01 18:57:50 -07:00
Kenneth Graunke 550237eedd ast_function: Fix check for "too few components".
This was triggering even for matrix-from-matrix constructors.  It is
perfectly legal to construct a mat3 from a mat2 - the rest will be
filled in by the identity matrix.

Changes piglit test constructor-23.vert from FAIL to PASS, but the
generated code is incorrect.
2010-09-01 18:57:50 -07:00
Kenneth Graunke ee88c46640 ast_function: Remove bogus cases from generate_constructor_matrix.
There are no integer matrix types, so switching on them is silly.
2010-09-01 18:57:50 -07:00
Ian Romanick a6c3cd5ca6 glsl2: Write vector constructor constants in a single assignment
Make two passes over the constructor parameters.  Write all of the
constants in a single write, then write the non-constants one at a
time.  This causes the fragment shader

varying float g;
void main()
{
	gl_FragColor = vec4(0.0, g, 0.0, 1.0);
}

to generate

(function main
  (signature void (parameters )
    (
      (declare (temporary ) vec4 vec_ctor@0x8580058)
      (assign (constant bool (1)) (xzw) (var_ref vec_ctor@0x8580058)  (constant vec4 (0.000000 0.000000 0.000000 1.000000)) )
      (assign (constant bool (1)) (y) (var_ref vec_ctor@0x8580058)  (swiz xxxx (var_ref g@0x8580218) ))
      (assign (constant bool (1)) (xyzw) (var_ref gl_FragColor@0x84d32a0)  (var_ref vec_ctor@0x8580058) )
    ))
)

instead of

(function main
  (signature void (parameters )
    (
      (declare (temporary ) vec4 vec_ctor@0x8580058)
      (assign (constant bool (1)) (x) (var_ref vec_ctor@0x8580058)  (constant vec4 (0.000000 0.000000 0.000000 1.000000)) )
      (assign (constant bool (1)) (y) (var_ref vec_ctor@0x8580058)  (swiz xxxx (var_ref g@0x8580218) ))
      (assign (constant bool (1)) (z) (var_ref vec_ctor@0x8580058)  (constant vec4 (0.000000 0.000000 0.000000 1.000000)) )
      (assign (constant bool (1)) (w) (var_ref vec_ctor@0x8580058)  (constant vec4 (0.000000 0.000000 0.000000 1.000000)) )
      (assign (constant bool (1)) (xyzw) (var_ref gl_FragColor@0x84d32a0)  (var_ref vec_ctor@0x8580058) )
    ))
)

A similar optimization could be done for matrix constructors, but it
is a little more complicate there.
2010-08-31 14:44:13 -07:00
Vinson Lee 0c93e69b25 glsl: Initialize data in ast_function_expression::hir.
Completely initialize data that is passed to ir_constant constructor.

Fixes piglit glsl-orangebook-ch06-bump valgrind uninitialized variable
error on softpipe and llvmpipe.
2010-08-29 14:05:07 -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
Ian Romanick bdc0e5285a glsl2: Fix transpose of rows and cols
This error led to an assertion failure for some constructors of
non-square matrices.  It only occured in matrices where the number of
columns was greater than the number of rows.  It didn't even always
occur on those.

Fixes piglit glslparsertest case constructor-16.vert.
2010-08-17 16:06:30 -07:00
Ian Romanick 0dc39f481a glsl2: Use MIN2 from macros.h instead of open coding it 2010-08-12 18:01:14 -07:00
Ian Romanick 1e0f0459e0 glsl2: Log a better error message when a matching function cannot be found 2010-08-05 17:21:39 -07:00
Ian Romanick 3d58be6135 glsl2: Generate masked assignments in vector and matrix constructors
Previously the in-line matrix and vector constructors would generate
swizzles in the LHS.  The code is actually more clear if it just
generates the masked assignments instead of relying on the
ir_assignment constructor to convert the swizzles to write masks.
2010-08-04 16:47:28 -07:00
Kenneth Graunke ad98aa9d93 glsl2: Remove uses of deprecated TALLOC_CTX type. 2010-08-04 15:57:19 -07:00
Eric Anholt 900ab2f564 glsl2: No need to strdup the name passed in to ir_variable constructor.
ir_variable always strdups the incoming name so that it matches the
lifetime of the ir_variable.
2010-08-03 11:40:26 -07:00
Eric Anholt 62c4763b70 glsl2: Fix spelling of "sentinel." 2010-07-29 14:02:19 -07:00
Kenneth Graunke 46d91615a2 ast_function: Set constant_value on return value temporaries in 1.20+. 2010-07-28 15:46:26 -07:00
Kenneth Graunke 74e1802f5d glsl2: Extend ir_constant to store constant arrays, and generate them.
Since GLSL permits arrays of structures, we need to store each element
as an ir_constant*, not just ir_constant_data.

Fixes parser tests const-array-01.frag, const-array-03.frag,
const-array-04.frag, const-array-05.frag, though 03 and 04 generate the
wrong code.
2010-07-21 16:38:33 -07:00
Kenneth Graunke 13a19745d4 glsl2: Emit array constructors inline. 2010-07-21 16:38:32 -07:00
Kenneth Graunke 0048c7aef8 glsl2: Add some comments. 2010-07-21 16:37:57 -07:00
Kenneth Graunke c7a18da690 glsl2: Replace insert_before/remove pairs with exec_node::replace_with. 2010-07-21 16:37:57 -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 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 1f47245bdd glsl2: Remove the const disease from function signature's callee. 2010-07-18 18:13:06 -07:00
Kenneth Graunke 17a307d154 ast_function: Actually do type conversion on function arguments. 2010-07-14 16:49:24 -07:00
Kenneth Graunke 284d821206 ast_function: Fix non-float constructors with matrix arguments.
Previously, code like ivec4(mat2(...)) would fail because the compiler
would naively try to convert a mat2 to an imat2...which doesn't exist.
Now, a separate pass breaks such matrices down to their columns, which
can be converted from vec2 to ivec2.

Fixes piglit tests constructor-11.vert, constructor-14.vert,
constructor-15.vert, and CorrectConstFolding2.frag.
2010-07-09 09:46:29 -07:00
Kenneth Graunke f58bbd134e ast_function: Move error return earlier and don't indent the world.
This has no functional changes.
2010-07-09 09:46:29 -07:00
Kenneth Graunke 59df3385e1 ast_function: Remove unnecessary check for empty constructors.
This case is already caught by a later check that ensures sufficient
components were provided, based on the type.
2010-07-09 09:46:29 -07:00
Kenneth Graunke 953ff1283d glsl2: Use _mesa_glsl_parse_state as the talloc parent, not glsl_shader.
_mesa_glsl_parse_state should be the parent for all temporary allocation
done while compiling a shader.  glsl_shader should only be used as the
parent for the shader's final IR---the _result_ of compilation.

Since many IR instructions may be added or discarded during optimization
passes, IR should not ever be allocated to glsl_shader directly.

Done via sed -i s/talloc_parent(state)/state/g and s/talloc_parent(st)/st/g.

This also removes a ton of talloc_parent calls, which may help performance.
2010-06-30 13:52:24 -07:00
Ian Romanick 4b6feb0398 glsl2: Use talloc_strdup when generating constructor temporary names 2010-06-29 11:15:26 -07:00
Ian Romanick 699b247661 glsl2: Don't flatten constructor parameters to scalars
Now that all scalar, vector, and matrix constructors are emitted
in-line, the parameters to these constructors should not be flattened
to a pile of scalars.  Instead, the functions that emit the in-line
constructor bodies can directly write the parameters to the correct
locations in the objects being constructed.
2010-06-29 11:15:26 -07:00