[Piglit] [PATCH 4/4] vs|fs-sqrt-zero: test sqrt(x) with uniform x=0

Brian Paul brianp at vmware.com
Fri Jul 20 11:33:43 PDT 2012


Since sqrt(x) is typically implemented with a reciprocal square root, zero
is a special case.  Mesa's GLSL->TGSI translator uses a CND instruction to
return 0 if x<=0.
---
 .../glsl-1.00/execution/fs-sqrt-zero.shader_test   |   26 ++++++++++++++++
 .../glsl-1.00/execution/vs-sqrt-zero.shader_test   |   32 ++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/glsl-1.00/execution/fs-sqrt-zero.shader_test
 create mode 100644 tests/spec/glsl-1.00/execution/vs-sqrt-zero.shader_test

diff --git a/tests/spec/glsl-1.00/execution/fs-sqrt-zero.shader_test b/tests/spec/glsl-1.00/execution/fs-sqrt-zero.shader_test
new file mode 100644
index 0000000..c8e451a
--- /dev/null
+++ b/tests/spec/glsl-1.00/execution/fs-sqrt-zero.shader_test
@@ -0,0 +1,26 @@
+[require]
+GLSL >= 1.00
+
+[vertex shader]
+void main()
+{
+  gl_Position = gl_Vertex;
+}
+
+[fragment shader]
+uniform vec2 arg0;
+void main()
+{
+  float x = sqrt(arg0.x);  // should be 0
+  float y = sqrt(arg0.y);  // should be 1
+
+  x = 0.5 + x;  // should be 0.5
+  y = y * 0.5;  // should be 0.5
+
+  gl_FragColor = vec4(x, y, 0.0, 1.0);
+}
+
+[test]
+uniform vec2 arg0 0.0 1.0
+draw rect -1 -1 2 2
+probe rgba 0 0 0.5 0.5 0.0 1.0
diff --git a/tests/spec/glsl-1.00/execution/vs-sqrt-zero.shader_test b/tests/spec/glsl-1.00/execution/vs-sqrt-zero.shader_test
new file mode 100644
index 0000000..c2a01b0
--- /dev/null
+++ b/tests/spec/glsl-1.00/execution/vs-sqrt-zero.shader_test
@@ -0,0 +1,32 @@
+[require]
+GLSL >= 1.00
+
+[vertex shader]
+uniform vec2 arg0;
+varying vec4 color;
+
+void main()
+{
+  gl_Position = gl_Vertex;
+
+  float x = sqrt(arg0.x);  // should be 0
+  float y = sqrt(arg0.y);  // should be 1
+
+  x = 0.5 + x;  // should be 0.5
+  y = y * 0.5;  // should be 0.5
+
+  color = vec4(x, y, 0.0, 1.0);
+}
+
+[fragment shader]
+varying vec4 color;
+
+void main()
+{
+  gl_FragColor = color;
+}
+
+[test]
+uniform vec2 arg0 0.0 1.0
+draw rect -1 -1 2 2
+probe rgba 0 0 0.5 0.5 0.0 1.0
-- 
1.7.3.4



More information about the Piglit mailing list