Mesa (master): GLSL: The LOG2 macro doesn't have enough precision

Ian Romanick idr at kemper.freedesktop.org
Fri Dec 19 21:08:10 UTC 2008


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Dec 18 14:11:06 2008 -0800

GLSL: The LOG2 macro doesn't have enough precision

It looks like the LOG2 macro only has 8 or 9 bits of precission, but
the ARB_vertex_program spec says "accurate to at least 10 bits".

---

 src/mesa/shader/prog_execute.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
index 8163ae6..a93733c 100644
--- a/src/mesa/shader/prog_execute.c
+++ b/src/mesa/shader/prog_execute.c
@@ -963,7 +963,10 @@ _mesa_execute_program(GLcontext * ctx,
          {
             GLfloat a[4], result[4];
             fetch_vector1(&inst->SrcReg[0], machine, a);
-            result[0] = result[1] = result[2] = result[3] = LOG2(a[0]);
+	    /* The fast LOG2 macro doesn't meet the precision requirements.
+	     */
+            result[0] = result[1] = result[2] = result[3] =
+		(log(a[0]) * 1.442695F);
             store_vector4(inst, machine, result);
          }
          break;
@@ -1022,7 +1025,11 @@ _mesa_execute_program(GLcontext * ctx,
                   GLfloat mantissa = FREXPF(t[0], &exponent);
                   q[0] = (GLfloat) (exponent - 1);
                   q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */
-                  q[2] = (GLfloat) (q[0] + LOG2(q[1]));
+
+		  /* The fast LOG2 macro doesn't meet the precision
+		   * requirements.
+		   */
+                  q[2] = (log(t[0]) * 1.442695F);
                }
             }
             else {




More information about the mesa-commit mailing list