summaryrefslogtreecommitdiffstats
path: root/src/glsl/ir.cpp
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Remove ir_call::get_callee() and set_callee().Kenneth Graunke2012-04-021-5/+0
| | | | | | | | | | | | | Previously, set_callee() performed some assertions about the type of the ir_call; protecting the bare pointer ensured these checks would be run. However, ir_call no longer has a type, so the getter and setter methods don't actually do anything useful. Remove them in favor of accessing callee directly, as is done with most other fields in our IR. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Convert ir_call to be a statement rather than a value.Kenneth Graunke2012-04-021-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Aside from ir_call, our IR is cleanly split into two classes: - Statements (typeless; used for side effects, control flow) - Values (deeply nestable, pure, typed expression trees) Unfortunately, ir_call confused all this: - For void functions, we placed ir_call directly in the instruction stream, treating it as an untyped statement. Yet, it was a subclass of ir_rvalue, and no other ir_rvalue could be used in this way. - For functions with a return value, ir_call could be placed in arbitrary expression trees. While this fit naturally with the source language, it meant that expressions might not be pure, making it difficult to transform and optimize them. To combat this, we always emitted ir_call directly in the RHS of an ir_assignment, only using a temporary variable in expression trees. Many passes relied on this assumption; the acos and atan built-ins violated it. This patch makes ir_call a statement (ir_instruction) rather than a value (ir_rvalue). Non-void calls now take a ir_dereference of a variable, and store the return value there---effectively a call and assignment rolled into one. They cannot be embedded in expressions. All expression trees are now pure, without exception. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Use ir_rvalue to represent generic error_type values.Kenneth Graunke2012-04-021-5/+5
| | | | | | | | | | | | | | | | | | | | | | Currently, ir_call can be used as either a statement (for void functions) or a value (for non-void functions). This is rather awkward, as it's the only class that can be used in both forms. A number of places use ir_call::get_error_instruction() to construct a generic value of error_type. If ir_call is to become a statement, it can no longer serve this purpose. Unfortunately, none of our classes are particularly well suited for this, and creating a new one would be rather aggrandizing. So, this patch introduces ir_rvalue::error_value(), a static method that creates an instance of the base class, ir_rvalue. This has the nice property that you can't accidentally try and access uninitialized fields (as it doesn't have any). The downside is that the base class is no longer abstract. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Make ir_dereference_variable ctor assert the variable exists.Kenneth Graunke2012-03-261-1/+3
| | | | | | | | | | | | | | This also seems like a bad idea. There were too many instances for me to thoroughly scan the code as I did with the last two patches, but a quick scan indicated that most callers newly allocate a variable, dereference it, or NULL-check. In some cases, it wasn't clear that the value would be non-NULL, but they didn't check for error_type either. At any rate, not checking for this is a bug, and assertions will trigger it earlier and more reliably than returning error_type. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Make ir_dereference_record constructor assert the variable exists.Kenneth Graunke2012-03-261-4/+4
| | | | | | | | | | | | | | | | | | Providing a NULL pointer to the ir_dereference_record() constructor seems like a bad idea. Currently, if provided NULL, it returns a partially constructed value of error type. However, none of the callers are prepared to handle that scenario. Code inspection shows that all callers do one of the following: - Already NULL-check the argument prior to creating the dereference - Already deference the argument (and thus would crash if it were NULL) - Newly allocate the argument. Thus, it should be safe to simply assert the value passed is not NULL. This should also catch issues right away, rather than dying later. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Make ir_dereference_array constructor assert the variable exists.Kenneth Graunke2012-03-261-10/+9
| | | | | | | | | | | | | | | | | | Providing a NULL pointer to the ir_dereference_array() constructor seems like a bad idea. Currently, if provided NULL, it returns a partially constructed value of error type. However, none of the callers are prepared to handle that scenario. Code inspection shows that all callers do one of the following: - Already NULL-check the argument prior to creating the dereference - Already deference the argument (and thus would crash if it were NULL) - Newly allocate the argument. Thus, it should be safe to simply assert the value passed is not NULL. This should also catch issues right away, rather than dying later. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* linker: Check that initializers for global variables matchIan Romanick2011-11-031-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This requires tracking a couple extra fields in ir_variable: * A flag to indicate that a variable had an initializer. * For non-const variables, a field to track the constant value of the variable's initializer. For variables non-constant initalizers, ir_variable::has_initializer will be true, but ir_variable::constant_initializer will be NULL. The linker can use the values of these fields to check adherence to the GLSL 4.20 rules for shared global variables: "If a shared global has multiple initializers, the initializers must all be constant expressions, and they must all have the same value. Otherwise, a link error will result. (A shared global having only one initializer does not require that initializer to be a constant expression.)" Previous to 4.20 the GLSL spec simply said that initializers must have the same value. In this case of non-constant initializers, this was impossible to determine. As a result, no vendor actually implemented that behavior. The 4.20 behavior matches the behavior of NVIDIA's shipping implementations. NOTE: This is candidate for the 7.11 branch. This patch also needs the preceding patch "glsl: Refactor generate_ARB_draw_buffers_variables to use add_builtin_constant" Signed-off-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=34687 Reviewed-by: Kenneth Graunke <[email protected]> Acked-by: Paul Berry <[email protected]>
* glsl: add ir_variable::determine_interpolation_mode() function.Paul Berry2011-10-271-0/+15
| | | | | | | | This function determines how a variable should be interpolated based both on interpolation qualifiers and the current shade model. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Distinguish between no interpolation qualifier and 'smooth'Paul Berry2011-10-271-1/+2
| | | | | | | | | | | | | | | Previously, we treated the 'smooth' qualifier as equivalent to no qualifier at all. However, this is incorrect for the built-in color variables (gl_FrontColor, gl_BackColor, gl_FrontSecondaryColor, and gl_BackSecondaryColor). For those variables, if there is no qualifier at all, interpolation should be flat if the shade model is GL_FLAT, and smooth if the shade model is GL_SMOOTH. To make this possible, I added a new value to the glsl_interp_qualifier enum, INTERP_QUALIFIER_NONE. Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* mesa: Expose GLSL interpolation qualifiers in gl_fragment_program.Paul Berry2011-10-271-4/+4
| | | | | | | | | | | | | | | | | This patch makes GLSL interpolation qualifiers visible to drivers via the array InterpQualifier[] in gl_fragment_program, so that they can easily be used by driver back-ends to select the correct interpolation mode. Previous to this patch, the GLSL compiler was using the enum ir_variable_interpolation to represent interpolation types. Rather than make a duplicate enum in core mesa to represent the same thing, I moved the enum into mtypes.h and renamed it to be more consistent with the other enums defined there. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: Remove unused method ir_variable::component_slotsIan Romanick2011-10-071-8/+0
| | | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Remove field array_lvalue from ir_variable.Paul Berry2011-09-141-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The array_lvalue field was attempting to enforce the restriction that whole arrays can't be used on the left-hand side of an assignment in GLSL 1.10 or GLSL ES, and can't be used as out or inout parameters in GLSL 1.10. However, it was buggy (it didn't work properly for built-in arrays), and it was clumsy (it unnecessarily kept track on a variable-by-variable basis, and it didn't cover the GLSL ES case). This patch removes the array_lvalue field completely in favor of explicit checks in ast_parameter_declarator::hir() (this check is added) and in do_assignment (this check was already present). This causes a benign behavioral change: when the user attempts to pass an array as an out or inout parameter of a function in GLSL 1.10, the error is now flagged at the time the function definition is encountered, rather than at the time of invocation. Previously we allowed such functions to be defined, and only flagged the error if they were invoked. Fixes Piglit tests spec/glsl-1.10/compiler/qualifiers/fn-{out,inout}-array-prohibited* and spec/glsl-1.20/compiler/assignment-operators/assign-builtin-array-allowed.vert. Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add a new ir_txs (textureSize) opcode to ir_texture.Kenneth Graunke2011-08-231-6/+10
| | | | | | | | One unique aspect of TXS is that it doesn't have a coordinate. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Dave Airlie <[email protected]>
* glsl: Make is_lvalue() and variable_referenced() const.Paul Berry2011-08-151-2/+2
| | | | | | | | | | These functions don't modify the target instruction, so it makes sense to make them const. This allows these functions to be called from ir validation code (which uses const to ensure that it doesn't accidentally modify the IR being validated). Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Move type_contains_sampler() into glsl_type for later reuse.Paul Berry2011-07-181-16/+1
| | | | | | | The new location, as a member function of glsl_type, is more consistent with queries like is_sampler(), is_boolean(), is_float(), etc. Placing the function inside glsl_type also makes it available to any code that uses glsl_types.
* glsl: Add ir_unop_i2u and ir_unop_u2i operations.Bryan Cain2011-06-291-0/+8
| | | | | | | | | | | | | | | | | These are necessary to handle int/uint constructor conversions. For example, the following code currently results in a type mismatch: int x = 7; uint y = uint(x); In particular, uint(x) still has type int. This commit simply adds the new operations; it does not generate them, nor does it add backend support for them. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
* glsl: add cast to silence signed/unsigned comparison warningBrian Paul2011-03-151-1/+1
|
* glsl: Explicitly specify a type when reading/printing ir_texture.Kenneth Graunke2011-03-141-12/+8
| | | | | | 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.
* glsl: Introduce a new "const_in" variable mode.Kenneth Graunke2011-01-311-1/+16
| | | | | | | | 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.
* Convert everything from the talloc API to the ralloc API.Kenneth Graunke2011-01-311-9/+9
|
* glsl: Propagate depth layout qualifier from AST to IRChad Versace2011-01-261-0/+1
|
* glsl: Define enum ir_depth_layoutChad Versace2011-01-261-0/+16
|
* glsl: Track variable usage, use that to enforce semanticsIan Romanick2011-01-121-0/+1
| | | | | | | | | In particular, variables cannot be redeclared invariant after being used. Fixes piglit test invariant-05.vert and bugzilla #29164. NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Add type inference support for remaining expression opcodes.Kenneth Graunke2011-01-111-0/+48
|
* glsl: Fix flipped return of has_value() for array constants.Eric Anholt2010-12-021-1/+1
| | | | Fixes glsl-array-uniform.
* 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.