summaryrefslogtreecommitdiffstats
path: root/src/glsl/ir_constant_expression.cpp
Commit message (Collapse)AuthorAgeFilesLines
* glsl: Evaluate constant pack/unpack 4x8 expressionsMatt Turner2013-01-251-0/+166
| | | | | | | | | That is, evaluate constant expressions for the following functions: packSnorm4x8, unpackSnorm4x8 packUnorm4x8, unpackUnorm4x8 Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Evaluate constant GLSL ES 3.00 pack/unpack expressions (v3)Chad Versace2013-01-241-0/+189
| | | | | | | | | | | | | | | | | | That is, evaluate constant expressions of the following functions: packSnorm2x16 unpackSnorm2x16 packUnorm2x16 unpackUnorm2x16 packHalf2x16 unpackHalf2x16 v2: Reuse _mesa_pack_float_to_half and its inverse to evaluate pack/unpackHalf2x16. [for idr] v3: Whitespace fixes. [for mattst88] Don't cast neg floats directly to uint16; use an intermediate cast to int16. [for paul] Reviewed-by: Ian Romanick <[email protected]> (v2) Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Matt Tuner <[email protected]> Signed-off-by: Chad Versace <[email protected]>
* mesa,glsl: Move round_to_even() from glsl to mesa/main (v2)Chad Versace2013-01-241-20/+1
| | | | | | | | | | | | | Move round_to_even's definition to mesa/main so that _mesa_float_to_half() can use it in order to eliminate rounding bias. In additon to moving the fuction definition, prefix its name with "_mesa", just as all other functions in mesa/main are prefixed. v2: Fix Android build. Reviewed-by: Ian Romanick <[email protected]> Signed-off-by: Chad Versace <[email protected]>
* glsl: Add support for ir_unop_f2u to constant folding.Paul Berry2012-06-151-0/+6
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: fix deref_hash memory leak in constant_expression_valueMarcin Slusarz2012-06-081-2/+5
| | | | Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Bitwise conversion operator support in ir_constant_expression.Olivier Galibert2012-06-071-0/+47
| | | | | | | | | A "test_out = floatBitsToUint(-1.0);" fired through the GLSL compiler gives a correct "(assign (x) (var_ref test_out) (constant uint (3212836864)))" Signed-off-by: Olivier Galibert <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Change built-in constant expression evaluation to run the IR.Olivier Galibert2012-05-081-380/+141
| | | | | | | | This removes code duplication with ir_expression::constant_expression_value and builtins/ir/*. Signed-off-by: Olivier Galibert <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add a constant_referenced method to ir_dereference*Olivier Galibert2012-05-081-0/+92
| | | | | | | | | | The method is used to get a reference to an ir_constant * within the context of evaluating an assignment when calculating a constant_expression_value. Signed-off-by: Olivier Galibert <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> [v1]
* glsl: Add a variable context to constant_expression_value().Olivier Galibert2012-05-081-17/+25
| | | | | | Signed-off-by: Olivier Galibert <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Eric Anholt <[email protected]> [v1]
* glsl: Fix broken constant expression handling for <, <=, >, and >=.Kenneth Graunke2012-05-081-9/+9
| | | | | | | | | | | | | We were looping over all the vector components, but only dealing with the first one. This was masked by the fact that constant expression handling on built-ins went through custom code for the lessThan() /function/ rather than the ir_binop_less expression operator. NOTE: This is a candidate for all release branches. Reviewed-by: Ian Romanick <[email protected]> Signed-off-by: Olivier Galibert <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* glsl: Convert ir_call to be a statement rather than a value.Kenneth Graunke2012-04-021-3/+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: Move constant expression handling from calls to signatures.Kenneth Graunke2012-04-021-8/+19
| | | | | | | | | | | | | | | When translating a call from AST to HIR, we need to decide whether it can be evaluated to a constant before emitting any code (namely, the temporary declaration, assignment, and call.) Soon, ir_call will become a statement taking a dereference of where to store the return value, rather than an rvalue to be used on the RHS of an assignment. It will be more convenient to try evaluation before creating a call. ir_function_signature seems like a reasonable place. 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-0/+7
| | | | | | | | | | | | | | | | | | | | | | 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: Handle constant expressions involving ir_binop_equal/nequal.Kenneth Graunke2011-11-101-0/+6
| | | | | | | | | | | Constant expressions which called GLSL's equal() and notEqual() built-ins on bvecs would hit an assertion failure; we simply forgot to implement them for booleans. NOTE: This is a candidate for stable release branches. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Chad Versace <[email protected]>
* glsl: Fix copy-paste error in constant_expression_value(ir_binop_nequal)Paul Berry2011-10-311-1/+1
| | | | | | | | | | | The implementation of ir_binop_nequal in constant_expression_value() appears to have been copy-and-pasted from the implementation of ir_binop_equal, but with all instances of '==' changed to '!='. This is correct except for one minor flaw: one of those '==' operators was in an assertion checking that the types of the two arguments were equal. That one needs to stay an '=='. Fixes piglit tests {fs,vs}-inline-notequal.
* glsl: Add support for constant expression evaluation on round(), roundEven().Eric Anholt2011-10-231-0/+29
| | | | | | | | | | | | v2: Avoid the C99 rounding functions, because I don't trust get/setting the C99 rounding mode from inside our library not having other side effects. Instead, open-code roundEven() behavior around Mesa's IROUND, which we're already testing for C99 rounding mode safety. Fixes glsl-1.30/compiler/built-in-functions/round* Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add support for constant expression evaluation on trunc().Eric Anholt2011-09-281-0/+2
| | | | | | | Fixes the glsl-1.30/compiler/built-in-functions/trunc-* tests under 1.30. Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Fix assertion checking types of constant bitshift expressions.Eric Anholt2011-09-281-1/+3
| | | | | | | | Bitshifts are one of the rare places that GLSL allows mixed base types without an implicit conversion occurring. Reviewed-by: Chad Versace <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add ir_unop_i2u and ir_unop_u2i operations.Bryan Cain2011-06-291-1/+12
| | | | | | | | | | | | | | | | | 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: Reinstate constant-folding for division by zeroChad Versace2011-02-151-21/+21
| | | | | | | | | | | | | | | Fixes regression: https://bugs.freedesktop.org/show_bug.cgi?id=34160 Commit e7c1f058d18f62aa4871aec623f994d7b68cb8c1 disabled constant-folding when division-by-zero occured. This was a mistake, because the spec does allow division by zero. (From section 5.9 of the GLSL 1.20 spec: Dividing by zero does not cause an exception but does result in an unspecified value.) For floating-point division, the original pre-e7c1f05 behavior is reinstated. For integer division, constant-fold 1/0 to 0.
* Revert "glsl: Fix constant-folding for reciprocal expressions"Chad Versace2011-02-151-10/+6
| | | | | | | | | | | | This reverts commit b3cf92aa916ee0537ee37723c23a9897ac9cd3e0. The reverted commit prevented constant-folding of reciprocal expressions when the reciprocated expression was 0. However, since the spec allows division by zero, constant-folding *is* permissible in this case. From Section 5.9 of the GLSL 1.20 spec: Dividing by zero does not cause an exception but does result in an unspecified value.
* glsl: Avoid division-by-zero during constant-foldingChad Versace2011-02-021-1/+19
| | | | | | | | | | | | | | | | | | | | | Avoid division-by-zero when constant-folding the following expression types: ir_unop_rsq ir_binop_div ir_binop_mod Fixes bugs: https://bugs.freedesktop.org//show_bug.cgi?id=33306 https://bugs.freedesktop.org//show_bug.cgi?id=33508 Fixes Piglit tests: glslparsertest/glsl2/div-by-zero-01.frag glslparsertest/glsl2/div-by-zero-02.frag glslparsertest/glsl2/div-by-zero-03.frag glslparsertest/glsl2/modulus-zero-01.frag glslparsertest/glsl2/modulus-zero-02.frag NOTE: This is a candidate for the 7.9 and 7.10 branches.
* glsl: Fix constant-folding for reciprocal expressionsChad Versace2011-02-021-6/+10
| | | | | | | | | | | | | | | Do not constant-fold a reciprocal if any component of the reciprocated expression is 0. For example, do not constant-fold `1 / vec4(0, 1, 2, 3)`. Incorrect, previous behavior ---------------------------- Reciprocals were constant-folded even when some component of the reciprocated expression was 0. The incorrectly applied arithmetic was: 1 / 0 := 0 For example, 1 / vec4(0, 1, 2, 3) = vec4(0, 1, 1/2, 1/3) NOTE: This is a candidate for the 7.9 and 7.10 branches.
* Convert everything from the talloc API to the ralloc API.Kenneth Graunke2011-01-311-5/+5
|
* glsl: Add ir_quadop_vector expressionIan Romanick2010-11-191-0/+18
| | | | | | | | | | 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: Eliminate assumptions about size of ir_expression::operandsIan Romanick2010-11-191-1/+1
| | | | This may grow in the near future.
* 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: Remove the ir_binop_cross opcode.Kenneth Graunke2010-11-171-12/+8
|
* glsl: Fix constant expression handling for <, >, <=, >= on vectors.Kenneth Graunke2010-11-171-48/+60
| | | | | | | | | | | | | | | | | ir_binop_less, ir_binop_greater, ir_binop_lequal, and ir_binop_gequal are defined to work on vectors as well as scalars, as long as the two operands have the same type. This is evident from both ir_validate.cpp and our use of these opcodes in the GLSL lessThan, greaterThan, lessThanEqual, greaterThanEqual built-in functions. Found by code inspection. Not known to fix any bugs. Presumably, our tests for the built-in comparison functions must pass because C.E. handling is done on the ir_call of "greaterThan" rather than the inlined opcode. The C.E. handling of the built-in function calls is correct. NOTE: This is a candidate for the 7.9 branch.
* glsl: fix assorted MSVC warningsBrian Paul2010-11-151-13/+13
|
* glsl: Add constant expression handling for asinh, acosh, and atanh.Kenneth Graunke2010-11-151-0/+12
|
* glsl: Fix ir_expression::constant_expression_value()Chad Versace2010-11-091-0/+3
| | | | | When the type of the ir_expression is error_type, return NULL. This fixes bug 31371.
* glsl: Implement constant expr evaluation for bitwise logic opsChad Versace2010-10-151-0/+54
| | | | | | | | Implement by adding the following cases to ir_exporession::constant_expression_value(): - ir_binop_bit_and - ir_binop_bit_or - ir_binop_bit_xor
* glsl: Implement constant expr evaluation for bit-shift opsChad Versace2010-10-151-0/+48
| | | | | | | Implement by adding the following cases to ir_expression::constant_expression_value(): - ir_binop_lshfit - ir_binop_rshfit
* glsl: Implement constant expr evaluation for bitwise-notChad Versace2010-10-151-0/+15
| | | | | Implement by adding a case to ir_expression::constant_expression_value() for ir_unop_bit_not.
* glsl: Initialize variable in ir_derefence_array::constant_expression_valueVinson Lee2010-10-131-1/+1
| | | | | | | Completely initialize data passed to ir_constant constructor. Fixes piglit glsl-mat-from-int-ctor-03 valgrind uninitialized value error on softpipe.
* glsl: Fix broken handling of ir_binop_equal and ir_binop_nequal.Kenneth Graunke2010-09-201-25/+30
| | | | | | | | When ir_binop_all_equal and ir_binop_any_nequal were introduced, the meaning of these two opcodes changed to return vectors rather than a single scalar, but the constant expression handling code was incorrectly written and only worked for scalars. As a result, only the first component of the returned vector would be properly initialized.
* glsl: introduce ir_binop_all_equal and ir_binop_any_equal, allow vector cmpsLuca Barbieri2010-09-131-4/+34
| | | | | | | | | | | | | | | | | 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]>
* glsl: Move is_builtin flag back to ir_function_signature.Kenneth Graunke2010-09-071-1/+1
| | | | | | | | | | | 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.
* glsl: Initialize variable in ir_swizzle::constant_expression_value.Vinson Lee2010-08-291-1/+1
| | | | | | | Complete initialize data passed to ir_constant constructor. Fixes piglit glsl-mat-from-int-ctor-02 valgrind unintialized variable error with 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: Include main/core.h.Chia-I Wu2010-08-241-1/+1
| | | | Make glsl include only main/core.h from core mesa.
* mesa: Add new ir_unop_any() expression operation.Eric Anholt2010-08-231-0/+9
| | | | | | | 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_expression: Implement equal/notEqual for booleans.Kenneth Graunke2010-08-181-0/+6
| | | | | | Calls to equal(bvec, bvec) or notEqual(bvec, bvec) previously caused an assertion. Fixes piglit tests glsl-const-builtin-equal-bool and glsl-const-builtin-notEqual-bool.
* glsl2: Skip talloc_parent in constant_expression of non-constant arrays.Eric Anholt2010-08-041-1/+1
|
* glsl2: Make the clone() method take a talloc context.Eric Anholt2010-08-041-2/+5
| | | | | | | 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.
* glsl2: Fix typo in clamp() constant builtin using uint instead of int.Eric Anholt2010-08-021-1/+1
| | | | | I take back the bad things I've said about the signed/unsigned comparison warning now.
* glsl2: Don't consider uniform initializers as constant expressions.Eric Anholt2010-08-021-0/+6
| | | | | We were happily optimizing away the body of glsl-uniform-initializer-* to never use the uniforms.
* ir_constant_expression: Add support for the "outerProduct" builtin.Kenneth Graunke2010-07-281-1/+8
|
* ir_constant_expression: Add support for the "mix" builtin.Kenneth Graunke2010-07-281-1/+13
| | | | Both 1.10 and 1.30 variants.