From 43ff8f1a4b90554eae489cebb7e05f983dd9ad66 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 11 Aug 2010 16:53:52 -0700 Subject: glsl2: Rework builtin function generation. Each language version/extension and target now has a "profile" containing all of the available builtin function prototypes. These are written in GLSL, and come directly out of the GLSL spec (except for expanding genType). A new builtins/ir/ folder contains the hand-written IR for each builtin, regardless of what version includes it. Only those definitions that have prototypes in the profile will be included. The autogenerated IR for texture builtins is no longer written to disk, so there's no longer any confusion as to what's hand-written or generated. All scripts are now in python instead of perl. --- src/glsl/builtins/ir/atan | 154 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 src/glsl/builtins/ir/atan (limited to 'src/glsl/builtins/ir/atan') diff --git a/src/glsl/builtins/ir/atan b/src/glsl/builtins/ir/atan new file mode 100644 index 0000000000..8404829387 --- /dev/null +++ b/src/glsl/builtins/ir/atan @@ -0,0 +1,154 @@ +((function atan + (signature float + (parameters + (declare (in) float x)) + ((return (call asin ((expression float * + (var_ref x) + (expression float rsq + (expression float + + (expression float * + (var_ref x) + (var_ref x)) + (constant float (1.0)))))))))) + + (signature vec2 + (parameters + (declare (in) vec2 y_over_x)) + ((return (call asin ((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)))))))))) + + (signature vec3 + (parameters + (declare (in) vec3 y_over_x)) + ((return (call asin ((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)))))))))) + + (signature vec4 + (parameters + (declare (in) vec4 y_over_x)) + ((return (call asin ((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)))))))))) + + (signature float + (parameters + (declare (in ) float y) + (declare (in ) float x) + ) + ( + (declare () float r) + (declare ( ) float abs_retval) + (assign (constant bool (1)) (var_ref abs_retval) (call abs ((var_ref x) )) +) + (if (expression bool > (var_ref abs_retval) (constant float (0.000100)) ) ( + (declare ( ) float atan_retval) + (assign (constant bool (1)) (var_ref atan_retval) (call atan ((expression float / (var_ref y) (var_ref x) ) )) +) + (assign (constant bool (1)) (var_ref r) (var_ref atan_retval) ) + (if (expression bool < (var_ref x) (constant float (0.000000)) ) ( + (if (expression bool >= (var_ref y) (constant float (0.000000)) ) ( + (declare ( ) float assignment_tmp) + (assign (constant bool (1)) (var_ref assignment_tmp) (expression float + (var_ref r) (constant float (3.141593)) ) ) + (assign (constant bool (1)) (var_ref r) (var_ref assignment_tmp) ) + ) + ( + (declare ( ) float assignment_tmp) + (assign (constant bool (1)) (var_ref assignment_tmp) (expression float - (var_ref r) (constant float (3.141593)) ) ) + (assign (constant bool (1)) (var_ref r) (var_ref assignment_tmp) ) + )) + + ) + ( + )) + + ) + ( + (if (expression bool >= (var_ref y) (constant float (0.000000)) ) ( + (assign (constant bool (1)) (var_ref r) (constant float (1.570796)) ) + ) + ( + (assign (constant bool (1)) (var_ref r) (constant float (-1.570796)) ) + )) + + )) + + (return (var_ref r) ) + )) + + + + (signature vec2 + (parameters + (declare (in) vec2 y) + (declare (in) vec2 x)) + ((declare () vec2 r) + (assign (constant bool (1)) + (swiz x (var_ref r)) + (call atan ((swiz x (var_ref y)) + (swiz x (var_ref x))))) + (assign (constant bool (1)) + (swiz y (var_ref r)) + (call atan ((swiz y (var_ref y)) + (swiz y (var_ref x))))) + (return (var_ref r)))) + + (signature vec3 + (parameters + (declare (in) vec3 y) + (declare (in) vec3 x)) + ((declare () vec3 r) + (assign (constant bool (1)) + (swiz x (var_ref r)) + (call atan ((swiz x (var_ref y)) + (swiz x (var_ref x))))) + (assign (constant bool (1)) + (swiz y (var_ref r)) + (call atan ((swiz y (var_ref y)) + (swiz y (var_ref x))))) + (assign (constant bool (1)) + (swiz z (var_ref r)) + (call atan ((swiz z (var_ref y)) + (swiz z (var_ref x))))) + (return (var_ref r)))) + + (signature vec4 + (parameters + (declare (in) vec4 y) + (declare (in) vec4 x)) + ((declare () vec4 r) + (assign (constant bool (1)) + (swiz x (var_ref r)) + (call atan ((swiz x (var_ref y)) + (swiz x (var_ref x))))) + (assign (constant bool (1)) + (swiz y (var_ref r)) + (call atan ((swiz y (var_ref y)) + (swiz y (var_ref x))))) + (assign (constant bool (1)) + (swiz z (var_ref r)) + (call atan ((swiz z (var_ref y)) + (swiz z (var_ref x))))) + (assign (constant bool (1)) + (swiz w (var_ref r)) + (call atan ((swiz w (var_ref y)) + (swiz w (var_ref x))))) + (return (var_ref r))))) + +)) -- cgit v1.2.3 From 16c733495d74d8c2443aa915a55df97c02b415c7 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 31 Aug 2010 19:13:09 -0600 Subject: glsl2: fix bug in atan(y, x) function When x==0, the result was wrong. Fixes piglit glsl-fs-atan-1.shader_test --- src/glsl/builtin_function.cpp | 12 ++++++------ src/glsl/builtins/ir/atan | 10 +++------- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'src/glsl/builtins/ir/atan') diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp index d3484cbcd3..e6feb55759 100644 --- a/src/glsl/builtin_function.cpp +++ b/src/glsl/builtin_function.cpp @@ -324,6 +324,8 @@ static const char *builtin_atan = ") \n" " (assign (constant bool (1)) (var_ref r) (var_ref atan_retval) ) \n" " (if (expression bool < (var_ref x) (constant float (0.000000)) ) (\n" + "\n" + "\n" " (if (expression bool >= (var_ref y) (constant float (0.000000)) ) (\n" " (declare ( ) float assignment_tmp)\n" " (assign (constant bool (1)) (var_ref assignment_tmp) (expression float + (var_ref r) (constant float (3.141593)) ) ) \n" @@ -341,12 +343,10 @@ static const char *builtin_atan = "\n" " )\n" " (\n" - " (if (expression bool >= (var_ref y) (constant float (0.000000)) ) (\n" - " (assign (constant bool (1)) (var_ref r) (constant float (1.570796)) ) \n" - " )\n" - " (\n" - " (assign (constant bool (1)) (var_ref r) (constant float (-1.570796)) ) \n" - " ))\n" + "\n" + " (declare () float sgn)\n" + " (assign (constant bool (1)) (var_ref sgn) (expression float sign (var_ref y)))\n" + " (assign (constant bool (1)) (var_ref r) (expression float * (var_ref sgn) (constant float (1.5707965))))\n" "\n" " ))\n" "\n" diff --git a/src/glsl/builtins/ir/atan b/src/glsl/builtins/ir/atan index 8404829387..04e1898f9f 100644 --- a/src/glsl/builtins/ir/atan +++ b/src/glsl/builtins/ir/atan @@ -80,13 +80,9 @@ ) ( - (if (expression bool >= (var_ref y) (constant float (0.000000)) ) ( - (assign (constant bool (1)) (var_ref r) (constant float (1.570796)) ) - ) - ( - (assign (constant bool (1)) (var_ref r) (constant float (-1.570796)) ) - )) - + (declare () float sgn) + (assign (constant bool (1)) (var_ref sgn) (expression float sign (var_ref y))) + (assign (constant bool (1)) (var_ref r) (expression float * (var_ref sgn) (constant float (1.5707965)))) )) (return (var_ref r) ) -- cgit v1.2.3