[Bug 27901] New: GLSL cos/sin functions broken on Mesa R600 driver

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Thu Apr 29 12:09:06 PDT 2010


           Summary: GLSL cos/sin functions broken on Mesa R600 driver
           Product: Mesa
           Version: git
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: medium
         Component: Drivers/DRI/R600
        AssignedTo: dri-devel at lists.freedesktop.org
        ReportedBy: alain.perrot at gmail.com

As I was playing with OpenGL examples from Joe Groff's blog at
I noticed that the cos and sin GLSL functions are broken on the Mesa R600
driver. Other trigonometric functions may be broken as well.

The blog entries provide two versions of a sample program that blend two images
together using GLSL. The blend factor is computed from a timestamp using the
sin function.

There's no problem with the example from chapter 2 where the blend factor is
computed on the CPU (source code at http://github.com/jckarter/hello-gl).

Mesa R600 driver fails to properly run the example from chapter 3 where the
blend factor is computed on the GPU using the GLSL sin function. Mesa software
renderer has no problem running this example (source code at

Looking at GLSL 1.10 spec, R600 ISA doc and R600 driver code (function
assemble_TRIG in r700_assembler.c), I guess there is two problems :

1. both the GLSL cos/sin functions and R600 hardware expects the angle to be
specified in radians, but the assemble_TRIG function divides the specified
angle by 2 * PI (the result is no more radians).

2. R600 hardware expects the angle to be in the range [-PI, PI] while GLSL does
not specify a range, and the assemble_TRIG function does not clip the angle in
the required range.

A quick and dirty hack to make the example from chapter 3 work with R600 driver
is to clip the timestamp to the [-PI, PI] range and then to multiply it by 2 *
PI :

--- hello-gl.c.old      2010-04-29 20:55:55.000000000 +0200
+++ hello-gl.c  2010-04-29 20:56:12.000000000 +0200
@@ -202,7 +202,10 @@
 static void update_timer(void)
     int milliseconds = glutGet(GLUT_ELAPSED_TIME);
-    g_resources.timer = (float)milliseconds * 0.001f;
+    g_resources.timer = fmodf((float)milliseconds * 0.001f, 2.0f *
+    if(g_resources.timer > 3.1415926535897f)
+        g_resources.timer -= 2.0f * 3.1415926535897f;
+    g_resources.timer *= 2.0f * 3.1415926535897f;

My config:
RV670 (Radeon HD 3870)
Kubuntu 10.04 "Lucid Lynx" 64-bit
Linux kernel 2.6.34-rc5 from Ubuntu Mainline Kernel PPA
libdrm, radeon, Mesa, Xorg from Xorg-edgers PPA

Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

More information about the dri-devel mailing list