diff options
author | Kenneth Graunke <[email protected]> | 2012-03-20 15:56:37 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2012-04-02 14:15:41 -0700 |
commit | d884f60861f270cdcf7d9d47765efcf1e1de30b6 (patch) | |
tree | 9041472738a13510a6cce1073cf64064eea294ec /src/glsl/builtins/ir | |
parent | 622eed075092a0325e0927bf2f9ef29f20bbf416 (diff) |
glsl: Convert ir_call to be a statement rather than a value.
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]>
Diffstat (limited to 'src/glsl/builtins/ir')
-rw-r--r-- | src/glsl/builtins/ir/acos.ir | 23 | ||||
-rw-r--r-- | src/glsl/builtins/ir/atan.ir | 80 |
2 files changed, 58 insertions, 45 deletions
diff --git a/src/glsl/builtins/ir/acos.ir b/src/glsl/builtins/ir/acos.ir index d1cfebeff8a..f0078f884e7 100644 --- a/src/glsl/builtins/ir/acos.ir +++ b/src/glsl/builtins/ir/acos.ir @@ -2,21 +2,28 @@ (signature float (parameters (declare (in) float x)) - ((return (expression float - (constant float (1.5707963)) - (call asin ((var_ref x))))))) + ((declare () float s) + (call asin (var_ref s) ((var_ref x))) + (return (expression float - (constant float (1.5707963)) (var_ref s))))) + (signature vec2 (parameters (declare (in) vec2 x)) - ((return (expression vec2 - (constant float (1.5707963)) - (call asin ((var_ref x))))))) + ((declare () vec2 s) + (call asin (var_ref s) ((var_ref x))) + (return (expression vec2 - (constant float (1.5707963)) (var_ref s))))) + (signature vec3 (parameters (declare (in) vec3 x)) - ((return (expression vec3 - (constant float (1.5707963)) - (call asin ((var_ref x))))))) + ((declare () vec3 s) + (call asin (var_ref s) ((var_ref x))) + (return (expression vec3 - (constant float (1.5707963)) (var_ref s))))) + (signature vec4 (parameters (declare (in) vec4 x)) - ((return (expression vec4 - (constant float (1.5707963)) - (call asin ((var_ref x))))))) + ((declare () vec4 s) + (call asin (var_ref s) ((var_ref x))) + (return (expression vec4 - (constant float (1.5707963)) (var_ref s))))) )) diff --git a/src/glsl/builtins/ir/atan.ir b/src/glsl/builtins/ir/atan.ir index 7b5ea13c6ba..a9dc08e9727 100644 --- a/src/glsl/builtins/ir/atan.ir +++ b/src/glsl/builtins/ir/atan.ir @@ -2,50 +2,62 @@ (signature float (parameters (declare (in) float y_over_x)) - ((return (call asin ((expression float * + ((declare () float s) + (call asin (var_ref s) + ((expression float * (var_ref y_over_x) (expression float rsq (expression float + (expression float * (var_ref y_over_x) (var_ref y_over_x)) - (constant float (1.0)))))))))) + (constant float (1.0))))))) + (return (var_ref s)))) (signature vec2 (parameters (declare (in) vec2 y_over_x)) - ((return (call asin ((expression vec2 * + ((declare () vec2 s) + (call asin (var_ref s) + ((expression vec2 * (var_ref y_over_x) (expression vec2 rsq (expression vec2 + (expression vec2 * (var_ref y_over_x) (var_ref y_over_x)) - (constant float (1.0)))))))))) + (constant float (1.0))))))) + (return (var_ref s)))) (signature vec3 (parameters (declare (in) vec3 y_over_x)) - ((return (call asin ((expression vec3 * + ((declare () vec3 s) + (call asin (var_ref s) + ((expression vec3 * (var_ref y_over_x) (expression vec3 rsq (expression vec3 + (expression vec3 * (var_ref y_over_x) (var_ref y_over_x)) - (constant float (1.0)))))))))) + (constant float (1.0))))))) + (return (var_ref s)))) (signature vec4 (parameters (declare (in) vec4 y_over_x)) - ((return (call asin ((expression vec4 * + ((declare () vec4 s) + (call asin (var_ref s) + ((expression vec4 * (var_ref y_over_x) (expression vec4 rsq (expression vec4 + (expression vec4 * (var_ref y_over_x) (var_ref y_over_x)) - (constant float (1.0)))))))))) + (constant float (1.0))))))) + (return (var_ref s)))) (signature float (parameters @@ -57,7 +69,7 @@ (if (expression bool > (expression float abs (var_ref x)) (expression float * (constant float (1.0e-8)) (expression float abs (var_ref y)))) ( - (assign (x) (var_ref r) (call atan ((expression float / (var_ref y) (var_ref x))))) + (call atan (var_ref r) ((expression float / (var_ref y) (var_ref x)))) (if (expression bool < (var_ref x) (constant float (0.000000)) ) ( (if (expression bool >= (var_ref y) (constant float (0.000000)) ) ((assign (x) (var_ref r) (expression float + (var_ref r) (constant float (3.141593))))) @@ -82,12 +94,11 @@ (declare (in) vec2 y) (declare (in) vec2 x)) ((declare () vec2 r) - (assign (x) (var_ref r) - (call atan ((swiz x (var_ref y)) - (swiz x (var_ref x))))) - (assign (y) (var_ref r) - (call atan ((swiz y (var_ref y)) - (swiz y (var_ref x))))) + (declare () float temp) + (call atan (var_ref temp) ((swiz x (var_ref y)) (swiz x (var_ref x)))) + (assign (x) (var_ref r) (var_ref temp)) + (call atan (var_ref temp) ((swiz y (var_ref y)) (swiz y (var_ref x)))) + (assign (y) (var_ref r) (var_ref temp)) (return (var_ref r)))) (signature vec3 @@ -95,15 +106,13 @@ (declare (in) vec3 y) (declare (in) vec3 x)) ((declare () vec3 r) - (assign (x) (var_ref r) - (call atan ((swiz x (var_ref y)) - (swiz x (var_ref x))))) - (assign (y) (var_ref r) - (call atan ((swiz y (var_ref y)) - (swiz y (var_ref x))))) - (assign (z) (var_ref r) - (call atan ((swiz z (var_ref y)) - (swiz z (var_ref x))))) + (declare () float temp) + (call atan (var_ref temp) ((swiz x (var_ref y)) (swiz x (var_ref x)))) + (assign (x) (var_ref r) (var_ref temp)) + (call atan (var_ref temp) ((swiz y (var_ref y)) (swiz y (var_ref x)))) + (assign (y) (var_ref r) (var_ref temp)) + (call atan (var_ref temp) ((swiz z (var_ref y)) (swiz z (var_ref x)))) + (assign (z) (var_ref r) (var_ref temp)) (return (var_ref r)))) (signature vec4 @@ -111,18 +120,15 @@ (declare (in) vec4 y) (declare (in) vec4 x)) ((declare () vec4 r) - (assign (x) (var_ref r) - (call atan ((swiz x (var_ref y)) - (swiz x (var_ref x))))) - (assign (y) (var_ref r) - (call atan ((swiz y (var_ref y)) - (swiz y (var_ref x))))) - (assign (z) (var_ref r) - (call atan ((swiz z (var_ref y)) - (swiz z (var_ref x))))) - (assign (w) (var_ref r) - (call atan ((swiz w (var_ref y)) - (swiz w (var_ref x))))) - (return (var_ref r))))) + (declare () float temp) + (call atan (var_ref temp) ((swiz x (var_ref y)) (swiz x (var_ref x)))) + (assign (x) (var_ref r) (var_ref temp)) + (call atan (var_ref temp) ((swiz y (var_ref y)) (swiz y (var_ref x)))) + (assign (y) (var_ref r) (var_ref temp)) + (call atan (var_ref temp) ((swiz z (var_ref y)) (swiz z (var_ref x)))) + (assign (z) (var_ref r) (var_ref temp)) + (call atan (var_ref temp) ((swiz w (var_ref y)) (swiz w (var_ref x)))) + (assign (w) (var_ref r) (var_ref temp)) + (return (var_ref r)))) )) |