Commit Graph

41 Commits

Author SHA1 Message Date
Kenneth Graunke
1e3bcbdf31 glsl: Add a new ir_txs (textureSize) opcode to ir_texture.
One unique aspect of TXS is that it doesn't have a coordinate.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
2011-08-23 11:16:30 -07:00
Paul Berry
f4830be938 glsl: Make ir_reader able to read plain (return) statements.
Previously ir_reader was only able to handle return of non-void.

This patch is necessary in order to allow optimization passes to be
tested in isolation.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2011-07-08 09:59:29 -07:00
Kenneth Graunke
233b88eab9 glsl: Explicitly specify a type when reading/printing ir_texture.
This is necessary for GLSL 1.30+ shadow sampling functions, which return
a single float rather than splatting the value to a vec4 based on
GL_DEPTH_TEXTURE_MODE.
2011-03-14 13:03:50 -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
c5a27b5939 glsl: Change texel offsets to a single vector rvalue.
Having these as actual integer values makes it difficult to implement
the texture*Offset built-in functions, since the offset is actually a
function parameter (which doesn't have a constant value).

The original rationale was that some hardware needs these offset baked
into the instruction opcode.  However, at least i965 should be able to
support non-constant offsets.  Others should be able to rely on inlining
and constant propagation.
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
Brian Paul
9f2bf3d65c glsl: silence uninitialized var warning in read_texture()
And generate an error if the texture pattern is not matched.
2011-01-25 13:11:47 -07:00
Kenneth Graunke
e256e4743c glsl, i965: Remove unnecessary talloc includes.
These are already picked up by ir.h or glsl_types.h.
2011-01-21 15:41:19 -08:00
Kenneth Graunke
bbafd2b849 ir_reader: Make assignment conditions optional.
You can now simply write (assign (xy) <lhs> <rhs>) instead of the
verbose (assign (constant bool (1)) (xy) <lhs> <rhs>).
2011-01-12 23:55:34 -08:00
Kenneth Graunke
b74ff382a4 ir_reader: Convert to a class.
This makes it unnecessary to pass _mesa_glsl_parse_state around
everywhere, making at least the prototypes a lot easier to read.

It's also more C++-ish than a pile of static C functions.
2011-01-12 23:55:34 -08:00
Kenneth Graunke
ec7e4f0ec5 ir_reader: Combine the three dereference reading functions into one.
These used to be more complicated, but now are so simple there's no real
point in keeping them separate.
2011-01-12 23:55:34 -08:00
Kenneth Graunke
e486fca2d3 ir_reader: Relax requirement that function arguments be s_lists.
All of these functions used to take s_list pointers so they wouldn't all
need SX_AS_LIST conversions and error checking.  However, the new
pattern matcher conveniently does this for us in one centralized place.

So there's no need to insist on s_list.  Switching to s_expression saves
a bit of code and is somewhat cleaner.
2011-01-12 23:55:33 -08:00
Kenneth Graunke
d798815272 ir_reader: Remove s_list::length() method.
Most code now relies on the pattern matcher rather than this function,
and for the only remaining case, not using this saves an iteration.
2011-01-12 23:55:33 -08:00
Kenneth Graunke
daeb0c646e ir_reader: Add a pattern matching system and use it everywhere.
Previously, the IR reader was riddled with code that:
1. Checked for the right number of list elements (via a linked list walk)
2. Retrieved references to each component (via ->next->next pointers)
3. Downcasted as necessary to make sure that each sub-component was the
   right type (i.e. symbol, int, list).
4. Checking that the tag (i.e. "declare") was correct.

This was all very ad-hoc and a bit ugly.  Error checking had to be done
at both steps 1, 3, and 4.  Most code didn't even check the tag, relying
on the caller to do so.  Not all callers did.

The new pattern matching module performs the whole process in a single
straightforward function call, resulting in shorter, more readable code.

Unfortunately, MSVC does not support C99-style anonymous arrays, so the
pattern must be declared outside of the match call.
2011-01-12 23:55:33 -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
Kenneth Graunke
c180e95d26 ir_reader: Fix some potential NULL pointer dereferences.
Found by inspection.
2010-11-03 13:39:42 -07:00
Kenneth Graunke
e751ce39bf ir_reader: Remove useless error check.
It's already been determined that length == 3, so clearly swiz->next is
a valid S-Expression.
2010-11-03 13:39:42 -07:00
Kenneth Graunke
0fd665ca63 ir_reader: Return a specific ir_dereference variant.
There's really no reason to return the base class when we have more
specific information about what type it is.
2010-11-03 13:39:42 -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
9a3df46fbc ir_reader: Only validate IR when a global 'debug' flag is set.
This extra validation is very useful when working on the built-ins, but
in general overkill - the results should stay the same unless the
built-ins or ir_validate have changed.

Also, validating all the built-in functions in every test case makes
piglit run unacceptably slow.
2010-09-05 01:57:37 -07:00
Kenneth Graunke
79088746a2 ir_reader: Run ir_validate on the generated IR.
It's just too easy to get something wrong in hand-written IR.
2010-09-04 02:19:38 -07:00
Kenneth Graunke
2809d70723 ir_reader: Emit global variables at the top of the instruction list.
Since functions are emitted when scanning for prototypes, functions
always come first, even if the original IR listed the variable
declarations first.

Fixes an ir_validate error (to be turned on in the next commit).
2010-09-04 02:19:38 -07:00
Kenneth Graunke
b758de16e3 ir_reader: Drop support for reading the old assignment format. 2010-09-04 02:19:38 -07:00
Kenneth Graunke
03a6276477 ir_reader: Read the new assignment format (with write mask).
This preserves the ability to read the old format, for momentary
compatibility with all the existing IR implementations of built-ins.
2010-09-04 02:19:37 -07:00
Kenneth Graunke
a71b46a8ad ir_reader: Track the current function and report it in error messages. 2010-09-04 02:19:37 -07:00
Vinson Lee
b43611b79c glsl: Initialize data in read_constant.
Completely initialize data that is passed into a ir_constant constructor.

Fixes piglit glsl-fs-mix valgrind uninitialized variable error on
softpipe and llvmpipe.
2010-08-29 11:48:02 -07:00
Kenneth Graunke
b6f15869b3 glsl: Move is_built_in flag from ir_function_signature to ir_function.
Also rename it to "is_builtin" for consistency.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
2010-08-26 09:19:48 -07:00
Kenneth Graunke
43ff8f1a4b glsl2: Rework builtin function generation.
Each language version/extension and target now has a "profile" containing
all of the available builtin function prototypes.  These are written in
GLSL, and come directly out of the GLSL spec (except for expanding genType).

A new builtins/ir/ folder contains the hand-written IR for each builtin,
regardless of what version includes it.  Only those definitions that have
prototypes in the profile will be included.

The autogenerated IR for texture builtins is no longer written to disk,
so there's no longer any confusion as to what's hand-written or
generated.

All scripts are now in python instead of perl.
2010-08-13 19:09:36 -07:00
Kenneth Graunke
d802ba110f ir_reader: Don't mark functions as defined if their body is empty. 2010-08-13 19:09:35 -07:00
Kenneth Graunke
3c033637de glsl2: Make ir_assignment derive from ir_instruction, not ir_rvalue.
Assignments can only exist at the top level instruction stream; the
residual value is handled by assigning the value to a temporary and
returning an ir_dereference_variable of that temporary.
2010-07-22 16:50:37 -07:00
Kenneth Graunke
ef2c38b245 ir_reader: Add support for reading constant arrays. 2010-07-21 16:38:33 -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
1f47245bdd glsl2: Remove the const disease from function signature's callee. 2010-07-18 18:13:06 -07:00
Ian Romanick
13f782c4ae linker: Implement first bits of intrastage linking
This currently involves an ugly hack so that every link doesn't result
in all the built-in functions showing up as multiply defined.  As soon
as the built-in functions are stored in a separate compilation unit,
ir_function_signature::is_built_in can be removed.
2010-07-12 18:51:55 -07:00
Kenneth Graunke
e024c5c690 ir_reader: Don't emit ir_function multiple times. 2010-07-07 16:37:48 -07:00
Kenneth Graunke
2070f9f5be glsl2: Fix for dead strings being stored in the symbol table. 2010-07-02 18:03:58 -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
Kenneth Graunke
78062273de ir_reader: Free memory for S-Expressions earlier.
There's no point in keeping it around once we've read the IR.

Also, remove an unnecessary talloc_parent call.
2010-06-25 17:07:42 -07:00
Eric Anholt
2928588267 glsl2: Move the compiler to the subdirectory it will live in in Mesa. 2010-06-24 15:36:00 -07:00