summaryrefslogtreecommitdiffstats
path: root/src/glsl/ir.cpp
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Add a helper constructor for expressions that works out result type.Eric Anholt2010-11-301-0/+102
| | | | | | This doesn't cover all expressions or all operand types, but it will complain if you overreach and it allows for much greater slack on the programmer's part.
* glsl: Add a helper function for determining if an rvalue could be a saturate.Eric Anholt2010-11-191-0/+56
| | | | | | Hardware pretty commonly has saturate modifiers on instructions, and this can be used in codegen to produce those, without everyone else needing to understand clamping other than min and max.
* glsl: Add ir_quadop_vector expressionIan Romanick2010-11-191-2/+23
| | | | | | | | | | The vector operator collects 2, 3, or 4 scalar components into a vector. Doing this has several advantages. First, it will make ud-chain tracking for components of vectors much easier. Second, a later optimization pass could collect scalars into vectors to allow generation of SWZ instructions (or similar as operands to other instructions on R200 and i915). It also enables an easy way to generate IR for SWZ instructions in the ARB_vertex_program assembler.
* glsl: Add unary ir_expression constructorIan Romanick2010-11-191-0/+13
|
* glsl: Add ir_rvalue::is_negative_one predicateIan Romanick2010-11-191-0/+41
|
* glsl: Add ir_unop_sin_reduced and ir_unop_cos_reducedIan Romanick2010-11-191-0/+2
| | | | | | | | | | | | The operate just like ir_unop_sin and ir_unop_cos except that they expect their inputs to be limited to the range [-pi, pi]. Several GPUs require this limited range for their sine and cosine instructions, so having these as operations (along with a to-be-written lowering pass) helps this architectures. These new operations also matche the semantics of the GL_ARB_fragment_program SCS instruction. Having these as operations helps in generating GLSL IR directly from assembly fragment programs.
* glsl: Make is_zero and is_one virtual methods of ir_rvalueIan Romanick2010-11-181-0/+10
| | | | | This eliminates the need in some cames to validate that an rvalue is an ir_constant before checking to see if it's 0 or 1.
* glsl: Fix 'control reaches end of non-void function' warning.Vinson Lee2010-11-171-0/+3
| | | | | | | Fix this GCC warning. ir.cpp: In static member function 'static unsigned int ir_expression::get_num_operands(ir_expression_operation)': ir.cpp:199: warning: control reaches end of non-void function
* glsl: Refactor get_num_operands.Kenneth Graunke2010-11-171-70/+5
| | | | | | | | | | This adds sentinel values to the ir_expression_operation enum type: ir_last_unop, ir_last_binop, and ir_last_opcode. They are set to the previous one so they don't trigger "unhandled case in switch statement" warnings, but should never be handled directly. This allows us to remove the huge array of 1s and 2s in ir_expression::get_num_operands().
* glsl: Remove the ir_binop_cross opcode.Kenneth Graunke2010-11-171-2/+0
|
* glsl: Refactor is_vec_{zero,one} to be methods of ir_constantIan Romanick2010-11-161-0/+73
| | | | These predicates will be used in other places soon.
* glsl: Add a new ir_unop_round_even opcode for GLSL 1.30's roundEven.Kenneth Graunke2010-10-141-0/+2
| | | | Also, update ir_to_mesa's "1.30 is unsupported" case to "handle" it.
* glsl: Track explicit location in AST to IR translationIan Romanick2010-10-081-0/+1
|
* glsl: Rework assignments with write_masks to have LHS chan count match RHS.Eric Anholt2010-09-221-1/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Change from has_builtin_signature to has_user_signature.Kenneth Graunke2010-09-161-2/+2
| | | | | The print visitor needs this, and the only existing user can work with has_user_signature just as well.
* glsl: introduce ir_binop_all_equal and ir_binop_any_equal, allow vector cmpsLuca Barbieri2010-09-131-0/+5
| | | | | | | | | | | | | | | | | 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 <[email protected]>
* glsl2: Add ir_unop_noiseIan Romanick2010-09-091-0/+3
|
* glsl: Move is_builtin flag back to ir_function_signature.Kenneth Graunke2010-09-071-1/+13
| | | | | | | | | | | This effectively reverts b6f15869b324ae64a00d0fe46fa3c8c62c1edb6c. 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.
* ir_expression: Add static operator_string methodIan Romanick2010-09-031-3/+7
| | | | | I've used this in quite a few debug commits that never reached an up-stream tree.
* glsl2: Add cmp field to ir_loopIan Romanick2010-09-031-0/+12
| | | | | This reprents the type of comparison between the loop induction variable and the loop termination value.
* glsl: Add proper handling for constant matrix-from-matrix constructors.Kenneth Graunke2010-09-011-0/+25
| | | | | Fixes piglit test case constructor-21.vert and changes constructor-22.vert to give the correct output.
* glsl: Move generate_constructor_(matrix|vector) to ir_constant ctor.Kenneth Graunke2010-09-011-0/+35
|
* glsl2: Allow ir_constant::zero to create boolean constantsIan Romanick2010-09-011-1/+1
|
* glsl: Completely initialize value member in ir_constant constructor.Vinson Lee2010-08-291-0/+3
| | | | | | | | | The ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list) did not completely initialize the entire value member. Fixes piglit glsl-fs-sampler-numbering-2 valgrind uninitialized value error in softpipe and llvmpipe.
* glsl: Initialize the rest of values of ir_constant::value.Vinson Lee2010-08-281-0/+12
| | | | | Fixes valgrind uninitialized value errors in the piglit shader tests for softpipe and llvmpipe.
* glsl: Move is_built_in flag from ir_function_signature to ir_function.Kenneth Graunke2010-08-261-1/+1
| | | | | | Also rename it to "is_builtin" for consistency. Signed-off-by: Ian Romanick <[email protected]>
* glsl: Don't consider things with a type containing a sampler as an lvalue.Eric Anholt2010-08-251-0/+23
| | | | | | | | | | | | | | | We had ad-hoc handled some common cases by flagging sampler-typed variables as read_only, and rejected initializers of samplers. However, people could sneak them in in all sorts of surprising ways, like using whole-array or structure assignment. Fixes: glslparsertest/glsl2/sampler-01.frag glslparsertest/glsl2/sampler-03.frag glslparsertest/glsl2/sampler-04.frag glslparsertest/glsl2/sampler-06.frag Bug #27403.
* glsl: Include main/core.h.Chia-I Wu2010-08-241-2/+1
| | | | Make glsl include only main/core.h from core mesa.
* mesa: Add new ir_unop_any() expression operation.Eric Anholt2010-08-231-0/+2
| | | | | | | The previous any() implementation would generate arg0.x || arg0.y || arg0.z. Having an expression operation for this makes it easy for the backend to generate something easier (DPn + SNE for 915 FS, .any predication on 965 VS)
* ir_constant: Don't assert on out-of-bounds array accessesIan Romanick2010-08-171-1/+15
| | | | | | | | | Several optimization paths, including constant folding, can lead to accessing an ir_constant array with an out of bounds index. The GLSL spec lets us produce "undefined" results, but it does not let us crash. Fixes piglit test case glsl-array-bounds-01 and glsl-array-bounds-03.
* glsl2: Remove the shader_in/shader_out tracking separate from var->mode.Eric Anholt2010-08-041-4/+0
| | | | | | | | | | | | | | | 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.
* glsl2: Add ir_assignment::write_mask and associated methodsIan Romanick2010-08-041-2/+111
| | | | | | | | | | | | | | | | | | | | | | | 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.
* glsl2: Initialize the ARB_fcc fields of ir_variable.Eric Anholt2010-08-021-0/+2
| | | | Fixes intermittent failure in glsl-arb-fragment-coord-conventions.
* glsl2: Initialize ir_function_signature::is_built_in.Kenneth Graunke2010-07-301-0/+1
| | | | Fixes a valgrind error.
* glsl2: Fix spelling of "sentinel."Eric Anholt2010-07-291-4/+4
|
* glsl2: Add new ir_constant::zero static method.Kenneth Graunke2010-07-281-0/+12
| | | | This conveniently creates a zero value of whatever type you want.
* glsl2: When stealing var->constant_value, steal its children as well.Eric Anholt2010-07-271-1/+1
| | | | | Fixes: glsl1-GLSL 1.20 uniform array constructor
* glsl2: Also steal the constant components of aggregate-typed ir_constants.Eric Anholt2010-07-261-0/+18
|
* glsl2: Steal ir_variable's constant_value field.Kenneth Graunke2010-07-261-0/+3
| | | | Fixes a link-time crash in glsl-vs-cross-3.
* glsl2: Initialize ir_instruction::type and ir_rvalue::type.Kenneth Graunke2010-07-221-0/+5
| | | | | | | | | | | Top-level instructions now get NULL as their default type (since type is irrelevant for things like ir_function), while ir_rvalues get error_type by default. This should make it easier to tell if we've forgotten to set a type. It also fixes some "Conditional jump or move depends on uninitialized value" errors in valgrind caused by ir_validate examining the type of top level ir_instructions, which weren't set.
* ir_constant_expression: Add support for array == and !=.Kenneth Graunke2010-07-211-3/+8
| | | | | Piglit parser tests const-array-03.frag and const-array-04.frag now generate the correct code.
* glsl2: Extend ir_constant to store constant arrays, and generate them.Kenneth Graunke2010-07-211-2/+21
| | | | | | | | | 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.
* glsl2: Implement utility routine to talloc reparent an IR treeIan Romanick2010-07-201-0/+15
|
* glsl2: Add and use new variable mode ir_var_temporaryIan Romanick2010-07-201-2/+4
| | | | | | | | | | | | | | | | | 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'.
* glsl2: strdup the field names used in dereference_record.Eric Anholt2010-07-201-2/+2
| | | | | Otherwise, after linking and freeing the old data, the pointer would dangle. Partial fix for glsl1-struct*.
* glsl2: Give IR nodes a type field.Eric Anholt2010-07-191-2/+21
| | | | | | | This is a big deal for debugging if nothing else ("what class is this ir_instruction, really?"), but is also nice for avoiding building a whole visitor or an if (node->as_whatever() || node->as_other_thing()) chain.
* glsl2: Remove the const disease from function signature's callee.Eric Anholt2010-07-181-1/+1
|
* glsl2: Make cross() be an expression operation.Eric Anholt2010-07-181-0/+2
| | | | | | ARB_fp, ARB_vp, Mesa IR, and the 965 vertex shader all have instructions for cross. Shaves 12 Mesa instructions off of a 66-instruction shader I have.
* ir_function_signature: Add method to get the function owning a signatureIan Romanick2010-07-121-1/+1
| | | | | | | | | There is no setter function, the getter returns a constant pointer, and ir_function_signature::_function is private for a reason. The only way to make a connection between a function and function signature is via ir_function::add_signature. This helps ensure that certain invariants (i.e., a function signature is in the list of signatures for its _function) are met.
* ir_call: Add method to set the function signature being calledIan Romanick2010-07-121-0/+8
|