Mesa (master): glsl2: fix bug in atan(y, x) function

Brian Paul brianp at kemper.freedesktop.org
Tue Aug 31 18:17:09 PDT 2010


Module: Mesa
Branch: master
Commit: 16c733495d74d8c2443aa915a55df97c02b415c7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=16c733495d74d8c2443aa915a55df97c02b415c7

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Aug 31 19:13:09 2010 -0600

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(-)

diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp
index d3484cb..e6feb55 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 8404829..04e1898 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) )



More information about the mesa-commit mailing list