aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl/ir_constant_expression.cpp
Commit message (Collapse)AuthorAgeFilesLines
* mesa: Use _mesa_lroundevenf() in some more places.Matt Turner2015-08-041-10/+4
|
* glsl: Avoid double promotion.Matt Turner2015-07-291-2/+2
|
* glsl: Remove MSVC implementations of copysign and isnormal.Matt Turner2015-07-291-13/+1
| | | | Non-Gallium parts of Mesa require MSVC 2013 which provides these.
* glsl: Remove never used sin_reduced/cos_reduced.Matt Turner2015-04-061-2/+0
| | | | | | | | These were added in commit f2616e56, presumably in preparation for translating ARB vp/fp into GLSL IR. That never happened, and neither did a lowering pass that actually generated these instructions. Reviewed-by: Jason Ekstrand <[email protected]>
* mesa: Replace _mesa_round_to_even() with _mesa_roundeven().Matt Turner2015-03-181-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Eric's initial patch adding constant expression evaluation for ir_unop_round_even used nearbyint. The open-coded _mesa_round_to_even implementation came about without much explanation after a reviewer asked whether nearbyint depended on the application not modifying the rounding mode. Of course (as Eric commented) we rely on the application not changing the rounding mode from its default (round-to-nearest) in many other places, including the IROUND function used by _mesa_round_to_even! Worse, IROUND() is implemented using the trunc(x + 0.5) trick which fails for x = nextafterf(0.5, 0.0). Still worse, _mesa_round_to_even unexpectedly returns an int. I suspect that could cause problems when rounding large integral values not representable as an int in ir_constant_expression.cpp's ir_unop_round_even evaluation. Its use of _mesa_round_to_even is clearly broken for doubles (as noted during review). The constant expression evaluation code for the packing built-in functions also mistakenly assumed that _mesa_round_to_even returned a float, as can be seen by the cast through a signed integer type to an unsigned (since negative float -> unsigned conversions are undefined). rint() and nearbyint() implement the round-half-to-even behavior we want when the rounding mode is set to the default round-to-nearest. The only difference between them is that nearbyint() raises the inexact exception. This patch implements _mesa_roundeven{f,}, a function similar to the roundeven function added by a yet unimplemented technical specification (ISO/IEC TS 18661-1:2014), with a small difference in behavior -- we don't bother raising the inexact exception, which I don't think we care about anyway. At least recent Intel CPUs can quickly change a subset of the bits in the x87 floating-point control register, but the exception mask bits are not included. rint() does not need to change these bits, but nearbyint() does (twice: save old, set new, and restore old) in order to raise the inexact exception, which would incur some penalty. Reviewed-by: Carl Worth <[email protected]>
* glsl: replace Elements() with ARRAY_SIZE()Brian Paul2015-03-021-1/+1
| | | | Acked-by: Ilia Mirkin <[email protected]>
* glsl/ir: Add builtin constant function support for doublesDave Airlie2015-02-191-32/+215
| | | | | Signed-off-by: Dave Airlie <[email protected]> Reviewed-by: Ilia Mirkin <[email protected]>
* Avoid fighting with Solaris headers over isnormal()Alan Coopersmith2015-02-171-1/+1
| | | | | | | | | | | When compiling in C99 or C++11 modes, Solaris defines isnormal() as a macro via <math.h>, which causes the function definition to become too mangled to compile. Signed-off-by: Alan Coopersmith <[email protected]> Cc: "10.5" <[email protected]> Reviewed-by: Emil Velikov <[email protected]> Reviewed-by: Brian Paul <[email protected]>
* glsl: Add constant evaluation of ir_unop_saturateAbdiel Janulgue2014-08-311-0/+6
| | | | | | | | v2: Use CLAMP macro (Ian Romanick) Signed-off-by: Abdiel Janulgue <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: add ARB_derivative control supportIlia Mirkin2014-08-141-0/+4
| | | | | | | Signed-off-by: Ilia Mirkin <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Chris Forbes <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: add new expression types for interpolateAt*Chris Forbes2014-07-121-0/+2
| | | | | | | Will be used to implement interpolateAt*() from ARB_gpu_shader5 Signed-off-by: Chris Forbes <[email protected]> Reviewed-by: Ilia Mirkin <[email protected]>
* glsl: Use typed foreach_in_list instead of foreach_list.Matt Turner2014-07-011-4/+3
| | | | Reviewed-by: Ian Romanick <[email protected]>
* glsl: Remove unused include from ir_constant_expression.cppThomas Helland2014-06-101-1/+0
| | | | | | | | Found with IWYU. Compile-tested on my Ivy-bridge system. Reviewed-by: Tom Stellard <[email protected]> Reviewed-by: Matt Turner <[email protected]> Signed-off-by: Thomas Helland <[email protected]>
* glsl: Clean up "unused parameter" warningsIan Romanick2014-03-251-5/+5
| | | | | | | | | | | ../../src/glsl/ir_constant_expression.cpp:486:1: warning: unused parameter 'variable_context' [-Wunused-parameter] ../../src/glsl/ir_constant_expression.cpp:1633:1: warning: unused parameter 'variable_context' [-Wunused-parameter] ../../src/glsl/ir_constant_expression.cpp:1752:1: warning: unused parameter 'variable_context' [-Wunused-parameter] ../../src/glsl/ir_constant_expression.cpp:1761:1: warning: unused parameter 'variable_context' [-Wunused-parameter] ../../src/glsl/ir_constant_expression.cpp:1769:1: warning: unused parameter 'variable_context' [-Wunused-parameter] Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
* glsl: Minor clean ups in constant_referencedIan Romanick2014-03-251-11/+6
| | | | | | | These could probably be squashed into one of the previous commits. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
* glsl: Remove ir_dereference::constant_referencedIan Romanick2014-03-251-25/+0
| | | | | | | | All of the functionality is implemented in a private function in the one file where it is used. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
* glsl: Fold implementation of ir_dereference_array::constant_referenced into ↵Ian Romanick2014-03-251-46/+43
| | | | | | | wrapper Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
* glsl: Fold implementation of ir_dereference_record::constant_referenced into ↵Ian Romanick2014-03-251-17/+21
| | | | | | | wrapper Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
* glsl: Fold implementation of ir_dereference_variable::constant_referenced ↵Ian Romanick2014-03-251-12/+13
| | | | | | | into wrapper Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
* glsl: Add wrapper function that calls ir_dereference::constant_referencedIan Romanick2014-03-251-16/+36
| | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
* glsl: Group all of the constant_referenced functions togetherIan Romanick2014-03-251-92/+103
| | | | | Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Topi Pohjolainen <[email protected]>
* glsl: Add constant evaluation of ir_binop_bfm.Matt Turner2014-01-271-0/+17
| | | | Reviewed-by: Ian Romanick <[email protected]>
* mesa: Fix compile error with MSVC 2013Thomas Sondergaard2014-01-081-1/+1
| | | | | | | | | This fixes the following compile error: src\glsl\ir_constant_expression.cpp(1405) : error C2666: 'copysign' : 3 overloads have similar conversions Cc: "10.0" <[email protected]> Reviewed-by: Brian Paul <[email protected]>
* glsl: move variables in to ir_variable::data, part ITapani Pälli2013-12-121-1/+1
| | | | | | | | | | This patch moves following bitfields in to the data structure: used, assigned, how_declared, mode, interpolation, origin_upper_left, pixel_center_integer Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Define isnormal for Oracle Solaris Studio.Vinson Lee2013-10-041-0/+6
| | | | | | | | This patch fixes this Oracle Solaris Studio build error. "../../src/glsl/ir_constant_expression.cpp", line 1398: Error: The function "isnormal" must have a prototype. Signed-off-by: Vinson Lee <[email protected]>
* glsl: Define isnormal and copysign for MSVC to fix build.Vinson Lee2013-09-221-0/+14
| | | | | | | | | | | | | This patch fixes these MSVC build errors. ir_constant_expression.cpp src\glsl\ir_constant_expression.cpp(564) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data src\glsl\ir_constant_expression.cpp(1384) : error C3861: 'isnormal': identifier not found src\glsl\ir_constant_expression.cpp(1385) : error C3861: 'copysign': identifier not found Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=69541 Signed-off-by: Vinson Lee <[email protected]> Acked-by: Matt Turner <[email protected]>
* glsl: Add support for ldexp.Matt Turner2013-09-171-0/+10
| | | | | v2: Drop frexp. Rebase on builtins rewrite. Reviewed-by: Paul Berry <[email protected]>
* glsl: Add conditional-select IR.Matt Turner2013-09-091-0/+8
| | | | | | | | | | | It's a ?: that operates per-component on vectors. Will be used in upcoming lowering pass for ldexp and the implementation of frexp. csel(selector, a, b): per-component result = selector ? a : b Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Convert ir_function_signature::is_builtin to a method.Kenneth Graunke2013-09-091-1/+1
| | | | | | | | | | | A signature is a built-in if and only if builtin_info != NULL, so we don't actually need a separate flag bit. Making a boolean-valued method allows existing code to ask the same question while not worrying about the internal representation. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Paul Berry <[email protected]>
* glsl: Add support for new fma built-in in ARB_gpu_shader5.Matt Turner2013-08-271-0/+11
| | | | | | v2: Add constant folding support. Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Ian Romanick <[email protected]>
* glsl: Add ir_triop_vector_insertIan Romanick2013-05-131-0/+25
| | | | | | | | | | | | | | | The new opcode is used to generate a new vector with a single field from the source vector replaced. This will eventually replace ir_dereference_array of vectors in the LHS of assignments. v2: Convert tabs to spaces. Suggested by Eric. v3: Add constant expression handling for ir_triop_vector_insert. This prevents the constant matrix inversion tests from regressing. Duh. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add ir_binop_vector_extractIan Romanick2013-05-131-4/+34
| | | | | | | | | | | | | | | | | | | | The new opcode is used to get a single field from a vector. The field index may not be constant. This will eventually replace ir_dereference_array of vectors. This is similar to the extractelement instruction in LLVM IR. http://llvm.org/docs/LangRef.html#extractelement-instruction v2: Convert tabs to spaces. Suggested by Eric. v3: Add array index range checking to ir_binop_vector_extract constant expression handling. Suggested by Ken. v4: Use CLAMP instead of MIN2(MAX2()). Suggested by Ken. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* glsl: Add constant evaluation of bit built-ins.Matt Turner2013-05-061-1/+125
| | | | | | | | v2: Order bits from LSB end (31 - count) for ir_unop_find_msb. v3: Add ir_triop_bitfield_extract as an exception to the op[0]->type == op[1]->type assertion in ir_constant_expression.cpp. Reviewed-by: Chris Forbes <[email protected]> [v2]
* glsl: Fix array indexing when constant folding built-in functions.Paul Berry2013-04-021-1/+1
| | | | | | | | | | | | | | | | | | | Mesa constant-folds built-in functions by using a miniature GLSL interpreter (see ir_function_signature::constant_expression_evaluate_expression_list()). This interpreter had a bug in its handling of array indexing, which caused expressions like "m[i][j]" (where m is a matrix) to be handled incorrectly. Specifically, it incorrectly treated j as indexing into the whole matrix (rather than indexing just into the vector m[i]); as a result the offset computed for m[i] was lost and m[i][j] was treated as m[j][0]. Fixes piglit tests inverse-mat[234].{vert,frag}. NOTE: This is a candidate for the 9.1 and 9.0 branches. Reviewed-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=57436
* glsl: Convert mix() to use a new ir_triop_lrp opcode.Kenneth Graunke2013-02-281-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | Many GPUs have an instruction to do linear interpolation which is more efficient than simply performing the algebra necessary (two multiplies, an add, and a subtract). Pattern matching or peepholing this is more desirable, but can be tricky. By using an opcode, we can at least make shaders which use the mix() built-in get the more efficient behavior. Currently, all consumers lower ir_triop_lrp. Subsequent patches will actually generate different code. v2 [mattst88]: - Add LRP_TO_ARITH flag to ir_to_mesa.cpp. Will be removed in a subsequent patch and ir_triop_lrp translated directly. v3 [mattst88]: - Move changes from the next patch to opt_algebraic.cpp to accept 3-src operations. Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
* 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.