[Piglit] [PATCH 4/4] Test accuracy of dFdx and dFdy functions.

Paul Berry stereotype441 at gmail.com
Tue Oct 1 12:32:42 PDT 2013


Mesa/i965 currently (as of commit 1cc3b90) has an inaccurate
implementation of dFdy() which produces the same results for every
pixel in an aligned 2x2 block.  This piglit test exposes the
inaccuracy.

v2: Use an error threshold of 1.0e-3 for both tests.  Set hint
GL_FRAGMENT_SHADER_DERIVATIVE_HINT to GL_NICEST, since some
implementations may use a less accurate derivative formula by default
in order to speed up textureGrad operations.
---
 .../execution/fs-dfdx-accuracy.shader_test         | 36 ++++++++++++++++++++++
 .../execution/fs-dfdy-accuracy.shader_test         | 36 ++++++++++++++++++++++
 2 files changed, 72 insertions(+)
 create mode 100644 tests/spec/glsl-1.10/execution/fs-dfdx-accuracy.shader_test
 create mode 100644 tests/spec/glsl-1.10/execution/fs-dfdy-accuracy.shader_test

diff --git a/tests/spec/glsl-1.10/execution/fs-dfdx-accuracy.shader_test b/tests/spec/glsl-1.10/execution/fs-dfdx-accuracy.shader_test
new file mode 100644
index 0000000..e301243
--- /dev/null
+++ b/tests/spec/glsl-1.10/execution/fs-dfdx-accuracy.shader_test
@@ -0,0 +1,36 @@
+# The spec allows considerable leeway in how dFdx() is calculated,
+# however the expected implementation is via forward or backward
+# differencing.  (Implementations are permitted, for instance, to use
+# forward differencing for some pixels and backward differencing for
+# other pixels).
+#
+# This test computes dFdx(x*y), which should exactly equal y at every
+# pixel, regardless of whether forward or backward differencing is
+# used.
+
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main()
+{
+	gl_Position = gl_Vertex;
+}
+
+[fragment shader]
+void main()
+{
+	float x = gl_FragCoord.x;
+	float y = gl_FragCoord.y;
+	float xy = x * y;
+	float dxydx = dFdx(xy);
+	if (distance(dxydx, y) > 1.0e-3)
+		gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+	else
+		gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[test]
+hint GL_FRAGMENT_SHADER_DERIVATIVE_HINT GL_NICEST
+draw rect -1 -1 2 2
+probe all rgba 0.0 1.0 0.0 1.0
diff --git a/tests/spec/glsl-1.10/execution/fs-dfdy-accuracy.shader_test b/tests/spec/glsl-1.10/execution/fs-dfdy-accuracy.shader_test
new file mode 100644
index 0000000..9f11c06
--- /dev/null
+++ b/tests/spec/glsl-1.10/execution/fs-dfdy-accuracy.shader_test
@@ -0,0 +1,36 @@
+# The spec allows considerable leeway in how dFdy() is calculated,
+# however the expected implementation is via forward or backward
+# differencing.  (Implementations are permitted, for instance, to use
+# forward differencing for some pixels and backward differencing for
+# other pixels).
+#
+# This test computes dFdy(x*y), which should exactly equal x at every
+# pixel, regardless of whether forward or backward differencing is
+# used.
+
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+void main()
+{
+	gl_Position = gl_Vertex;
+}
+
+[fragment shader]
+void main()
+{
+	float x = gl_FragCoord.x;
+	float y = gl_FragCoord.y;
+	float xy = x * y;
+	float dxydy = dFdy(xy);
+	if (distance(dxydy, x) > 1.0e-3)
+		gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+	else
+		gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+}
+
+[test]
+hint GL_FRAGMENT_SHADER_DERIVATIVE_HINT GL_NICEST
+draw rect -1 -1 2 2
+probe all rgba 0.0 1.0 0.0 1.0
-- 
1.8.4



More information about the Piglit mailing list