[Piglit] [PATCH] Add tests for abs(-x) with intermediate.

Paul Berry stereotype441 at gmail.com
Fri Oct 7 12:24:14 PDT 2011


These tests exercise a bug I found in the Mesa i965 fragment shader:
when computing abs(-x), if the intermediate value (-x) was used
elsewhere in the shader, then abs(-x) was incorrectly computed as
-abs(x).  The failure did not occur if the intermediate value was not
used, so this bug was not caught by the
glsl-{fs,vs}-abs-neg.shader_test.
---
 .../glsl-fs-abs-neg-with-intermediate.shader_test  |   34 ++++++++++++++++++
 .../glsl-vs-abs-neg-with-intermediate.shader_test  |   36 ++++++++++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)
 create mode 100644 tests/shaders/glsl-fs-abs-neg-with-intermediate.shader_test
 create mode 100644 tests/shaders/glsl-vs-abs-neg-with-intermediate.shader_test

diff --git a/tests/shaders/glsl-fs-abs-neg-with-intermediate.shader_test b/tests/shaders/glsl-fs-abs-neg-with-intermediate.shader_test
new file mode 100644
index 0000000..6e4e4e0
--- /dev/null
+++ b/tests/shaders/glsl-fs-abs-neg-with-intermediate.shader_test
@@ -0,0 +1,34 @@
+# [description]
+# This test exercises a bug found in Mesa: taking the absolute value
+# of -x should yield abs(x), not -abs(x).
+#
+# In this test, the intermediate value, -x, is also used in the
+# shader.
+
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+#version 110
+
+void main()
+{
+	gl_Position = gl_Vertex;
+}
+
+[fragment shader]
+#version 110
+
+uniform float x;
+
+void main(void)
+{
+	float y = -x;
+	float z = abs(y);
+	gl_FragColor = vec4(0.5 + x, 0.5 + y, 0.5 + z, 1.0);
+}
+
+[test]
+uniform float x 0.25
+draw rect -1 -1 2 2
+probe all rgba 0.75 0.25 0.75 1.0
diff --git a/tests/shaders/glsl-vs-abs-neg-with-intermediate.shader_test b/tests/shaders/glsl-vs-abs-neg-with-intermediate.shader_test
new file mode 100644
index 0000000..b06d2f6
--- /dev/null
+++ b/tests/shaders/glsl-vs-abs-neg-with-intermediate.shader_test
@@ -0,0 +1,36 @@
+# [description]
+# This test exercises a bug found in Mesa: taking the absolute value
+# of -x should yield abs(x), not -abs(x).
+#
+# In this test, the intermediate value, -x, is also used in the
+# shader.
+
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+#version 110
+
+uniform float x;
+
+void main()
+{
+	gl_Position = gl_Vertex;
+
+	float y = -x;
+	float z = abs(y);
+	gl_FrontColor = vec4(0.5 + x, 0.5 + y, 0.5 + z, 1.0);
+}
+
+[fragment shader]
+#version 110
+
+void main(void)
+{
+	gl_FragColor = gl_Color;
+}
+
+[test]
+uniform float x 0.25
+draw rect -1 -1 2 2
+probe all rgba 0.75 0.25 0.75 1.0
-- 
1.7.6.4



More information about the Piglit mailing list