Commit graph

37181 commits

Author SHA1 Message Date
Ian Romanick
6235c6a838 glsl2: Additional validation of write masks 2010-08-04 16:47:28 -07:00
Ian Romanick
5a7758efbe glsl2: Add ir_assignment::write_mask and associated methods
Replace swizzles on the LHS with additional swizzles on the RHS and a
write mask in the assignment instruction.  As part of this add
ir_assignment::set_lhs.  Ideally we'd make ir_assignment::lhs private
to prevent erroneous writes, but that would require a lot of code
butchery at this point.

Add ir_assignment constructor that takes an explicit write mask.  This
is required for ir_assignment::clone, but it can also be used in other
places.  Without this, ir_assignment clones lose their write masks,
and incorrect IR is generated in optimization passes.

Add ir_assignment::whole_variable_written method.  This method gets
the variable on the LHS if the whole variable is written or NULL
otherwise.  This is different from
ir->lhs->whole_variable_referenced() because the latter has no
knowledge of the write mask stored in the ir_assignment.

Gut all code from ir_to_mesa that handled swizzles on the LHS of
assignments.  There is probably some other refactoring that could be
done here, but that can be left for another day.
2010-08-04 16:47:27 -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
8dbdcb0b43 glsl2: Constant fold the children of many more ir_instruction types. 2010-08-04 16:25:56 -07:00
Eric Anholt
6ecf62f673 glsl2: Return a real progress value from constant folding. 2010-08-04 16:25:56 -07:00
Eric Anholt
3d23f0a90c glsl2: Refactor constant folding of rvalues to a function. 2010-08-04 16:25:56 -07:00
Kenneth Graunke
0ef79a5f11 glcpp: Refresh autogenerated lexer and parser. 2010-08-04 15:57:20 -07:00
Kenneth Graunke
1ffc1cd861 glcpp: Remove xtalloc wrappers in favor of plain talloc.
Calling exit() on a memory failure probably made sense for the
standalone preprocessor, but doesn't seem too appealing as part of
the GL library.  Also, we don't use it in the main compiler.
2010-08-04 15:57:20 -07:00
Kenneth Graunke
ad98aa9d93 glsl2: Remove uses of deprecated TALLOC_CTX type. 2010-08-04 15:57:19 -07:00
Aras Pranckevicius
ea3a9eb53a glsl2: add gl_LightModel built-in uniform. 2010-08-04 14:41:01 -07:00
Eric Anholt
b6ceddc371 glsl2: Don't try to assign locations for samplers during linking.
Mesa will do the mapping at _mesa_add_sampler() time.  Fixes assertion
failures in debug builds, which might have caught real problems with
multiple samplers linked in a row.
2010-08-04 14:28:57 -07:00
Eric Anholt
fe1918c71c ir_to_mesa: Clean up the mapping of samplers to Mesa's sampler uniforms.
Instead of using a linker-assigned location (since samplers don't
actually take up uniform space, being a link-time choice), use the
sampler's varaible pointer as a hash key.
2010-08-04 14:21:01 -07:00
Eric Anholt
8e181b629f mesa: Don't null deref looking for Mesa IR code at compile time.
The new compiler doesn't generate Mesa IR at compile time, and that
compile time code previously wouldn't have reflected the link time
code that actually got used.  But do dump the info log of the compile
regardless.
2010-08-04 14:13:08 -07:00
Eric Anholt
952d0f88e1 glsl2: Skip talloc_parent in constant_expression of non-constant arrays. 2010-08-04 12:57:58 -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
84ee01f40a glsl2: Set ir_discard::ir_type when cloning it
Fixes unset ir_type after inlining.
2010-08-04 08:57:02 -07:00
Eric Anholt
c22dee7216 glsl2: Fix ir_validate validating null variable names.
An unnamed variable in a prototype will have a NULL ->name, so don't
worry about storage then.

Fixes:
CorrectFunction1.vert
CorrectParse1.frag
2010-08-03 11:47:02 -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
c8babd5d9b glsl2: Fix typo in clamp() constant builtin using uint instead of int.
I take back the bad things I've said about the signed/unsigned
comparison warning now.
2010-08-02 17:50:20 -07:00
Eric Anholt
47f305a4fc ir_to_mesa: Add support for 1.20 uniform initializers.
Fixes:
glsl-uniform-initializer-1
glsl-uniform-initializer-2
glsl-uniform-initializer-3
glsl-uniform-initializer-4
glsl1-GLSL 1.20 uniform array constructor
2010-08-02 17:47:35 -07:00
Eric Anholt
5704ed27dd glsl2: Don't consider uniform initializers as constant expressions.
We were happily optimizing away the body of
glsl-uniform-initializer-* to never use the uniforms.
2010-08-02 17:47:35 -07:00
Eric Anholt
b10bb527ea Initialize a couple of HasIndex2 fields on Mesa IR src regs. 2010-08-02 17:47:35 -07:00
Eric Anholt
26675e37bc ir_to_mesa: Support for struct uniforms.
Fixes glsl-uniform-struct.
2010-08-02 17:47:35 -07:00
Eric Anholt
9c02412cdc ir_to_mesa: Add a constructor for ir_to_mesa_src_reg.
This helps makes sure we don't miss any new fields, and makes totally
uninitialized src_regs be PROGRAM_UNDEFINED.
2010-08-02 17:47:35 -07:00
Carl Worth
1575070bfe glsl2: Use talloc_zero_size instead of talloc_size to allocate ast_node objects.
This is a zero-ing function, (like calloc), to avoid bugs due to
accessing uninitialized values. Thanks to valgrind for noticing the
use of uninitialized values.
2010-08-02 17:27:56 -07:00
Ian Romanick
42f3e7b6d7 glsl_type: Use string key for array type hash 2010-08-02 13:53:33 -07:00
Ian Romanick
955ceef47f Keep a local copy of the symbol name in the symbol table
The symbol_header structure that tracks symbols with a particular name
may have a different (longer) life time than the symbols it tracks.
Not keeping a local copy of the name can lead to use-after-free
errors.  For example, the following sequence would trigger such an
error:

    char *copy = strdup(name);

    _mesa_symbol_table_push_scope(st);
    _mesa_symbol_table_add_symbol(st, 0, name, NULL);
    _mesa_symbol_table_pop_scope(st);
    free(name);
    _mesa_symbol_table_find_symbol(st, 0, copy);

With this change, the symbol table keeps a local copy of the name that
has the same life time as the symbol_header for that name.  This
resolves some use-after-free errors with built-in functions in the
GLSL compiler.
2010-08-02 13:53:32 -07:00
Ian Romanick
7ffe40532f glsl2: Clean-up two 'unused variable' warnings 2010-08-02 13:53:32 -07:00
Ian Romanick
cf41c8a0d8 glsl2: Make glsl_types::ctx private again 2010-08-02 13:53:32 -07:00
Eric Anholt
eb7e120f0f glsl2: Fix expression type in builtin tan().
Fixes glsl-fs-tan-1.
2010-08-02 12:33:18 -07:00
Eric Anholt
ee7666b5ac glsl2: Add validation that talloc ownership of ir_* names is right. 2010-08-02 12:08:52 -07:00
Eric Anholt
e75dbf66d0 glsl2: Fix validation for ir_unop_not.
We use vector ir_unop_not to implement builtin not(), and that seems fine.
2010-08-02 12:06:34 -07:00
Eric Anholt
47f3f22311 glsl2: Add support for floating constants like "1f".
Fixes glsl-floating-constant-120.
2010-08-02 11:26:43 -07:00
Eric Anholt
960ba0014a glsl2: Initialize the ARB_fcc fields of ir_variable.
Fixes intermittent failure in glsl-arb-fragment-coord-conventions.
2010-08-02 11:20:32 -07:00
Eric Anholt
b8db38e1c4 glsl2: Also initialize the identifier field of parameter_declarator.
The non-named parameter grammar understandably doesn't set the
identifier field.  Fixes intermittent failures about void main(void)
{} having a named void parameter.
2010-08-02 11:04:54 -07:00
Eric Anholt
004e924014 glsl2: Fix spelling of "precision" in error output. 2010-08-02 10:59:46 -07:00
Eric Anholt
f311d8e9e9 glsl2: Don't add mesa/program/ as an include dir. Let includes say program/. 2010-08-02 10:59:46 -07:00
Aras Pranckevicius
31747155ea glsl2: Give the path within src/mesa/ for headers instead of relying on -I. 2010-08-02 10:59:46 -07:00
Aras Pranckevicius
b35703df10 glsl2: initialize is_array and array_size of ast_parameter_declarator
The non-array path of glsl_parser.ypp wasn't setting is_array to false.
2010-08-02 10:59:42 -07:00
Eric Anholt
6a41626e90 glsl2: Make non-square matrix keywords not keywords pre-120.
Fixes glsl-mat-110.
2010-08-01 19:11:10 -07:00
Eric Anholt
b42519108d ir_to_mesa: Add support for MESA_GLSL=log.
This is the option that dumps shader source to files in the current
directory.
2010-08-01 11:41:02 -07:00
Eric Anholt
93b10bd353 glcpp: Add a testcase for the failure in compiling xonotic's shader.
gcc and mesa master agree that this is OK.
2010-08-01 11:40:07 -07:00
Eric Anholt
f6b03f3235 glsl2: Do algebraic optimizations after linking as well.
Linking brings in inlining of builtins, so we weren't catching the
(rcp(/sqrt(x)) -> rsq(x)) without it.
2010-07-31 15:52:24 -07:00
Eric Anholt
784695442c glsl2: Add new tree grafting optimization pass. 2010-07-31 15:52:21 -07:00
Eric Anholt
d72edc4ddd glsl2: Factor out the variable refcounting part of ir_dead_code.cpp. 2010-07-31 15:52:21 -07:00
Aras Pranckevicius
1c325af4d6 glsl2: Fix stack smash when ternary selection is used. 2010-07-31 12:00:01 -07:00
Eric Anholt
3fa1b85196 glsl2: Fix the implementation of atan(y, x).
So many problems here.  One is that we can't do the quadrant handling
for all the channels at the same time, so we call the float(y, x)
version multiple times.  I'd also left out the x == 0 handling.  Also,
the quadrant handling was broken for y == 0, so there was a funny
discontinuity on the +x side if you plugged in obvious values to test.

I generated the atan(float y, float x) code from a short segment of
GLSL and pasted it in by hand.  It would be nice to automate that
somehow.

Fixes:
glsl-fs-atan-1
glsl-fs-atan-2
2010-07-30 15:19:00 -07:00
Carl Worth
ec9675ec53 ast: Initialize location data in constructor of all ast_node objects.
This prevents using uninitialized data in _msea_glsl_error in some
cases, (including at least 6 piglit tests). Thanks to valgrind for
pointing out the problem!
2010-07-30 15:03:37 -07:00
Eric Anholt
40f57c2bec ir_to_mesa: Add the function name as a comment to BGNSUB and ENDSUB. 2010-07-30 14:57:44 -07:00
Eric Anholt
5e5583ee06 glsl2: Update the callee pointer of calls to newly-linked-in functions.
Otherwise, ir_function_inlining will see the body of the function from
the unlinked version of the shader, which won't have had the lowering
passes done on it or linking's variable remapping.
2010-07-30 14:57:22 -07:00