[Piglit] [PATCH] glsl-fs-clamp-[234]: New tests for a bug Chad noticed in saturate handling.

Eric Anholt eric at anholt.net
Mon Apr 11 16:24:44 PDT 2011


The point here is to try to catch the cases where the compiler turns a
min/max of a variable float with constant vectors into a saturate of a
float.

We never actually failed, becase we aren't writemasking in ir_to_mesa
(so the full temporary vector would be filled anyway), and because in
brw_fs.cpp we had split up the expression to scalars already.
---
 tests/shaders/glsl-fs-clamp-2.shader_test |   29 +++++++++++++++++++++++++++++
 tests/shaders/glsl-fs-clamp-3.shader_test |   29 +++++++++++++++++++++++++++++
 tests/shaders/glsl-fs-clamp-4.shader_test |   29 +++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 tests/shaders/glsl-fs-clamp-2.shader_test
 create mode 100644 tests/shaders/glsl-fs-clamp-3.shader_test
 create mode 100644 tests/shaders/glsl-fs-clamp-4.shader_test

diff --git a/tests/shaders/glsl-fs-clamp-2.shader_test b/tests/shaders/glsl-fs-clamp-2.shader_test
new file mode 100644
index 0000000..5d856ca
--- /dev/null
+++ b/tests/shaders/glsl-fs-clamp-2.shader_test
@@ -0,0 +1,29 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+varying vec4 color;
+
+void main()
+{
+	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+	/* Renormalize to [-1, 2] */
+	color = (gl_Vertex + 1.0) * 3.0 / 2.0 - 1.0;
+}
+
+[fragment shader]
+varying vec4 color;
+
+void main()
+{
+	float x = min(1.0, max(0.0, color.x)) * 0.5 + 0.25;
+	float y = min(1.0, max(0.0, color.y)) * 0.5 + 0.25;
+	gl_FragColor = vec4(x, y, 0.0, 0.0);
+}
+
+[test]
+draw rect -1 -1 2 2
+relative probe rgba (0.0, 0.0) (0.25, 0.25, 0.0, 0.0)
+relative probe rgba (1.0, 0.0) (0.75, 0.25, 0.0, 0.0)
+relative probe rgba (0.0, 1.0) (0.25, 0.75, 0.0, 0.0)
+relative probe rgba (1.0, 1.0) (0.75, 0.75, 0.0, 0.0)
diff --git a/tests/shaders/glsl-fs-clamp-3.shader_test b/tests/shaders/glsl-fs-clamp-3.shader_test
new file mode 100644
index 0000000..ec61790
--- /dev/null
+++ b/tests/shaders/glsl-fs-clamp-3.shader_test
@@ -0,0 +1,29 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+varying vec4 color;
+
+void main()
+{
+	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+	/* Renormalize to [-1, 2] */
+	color = (gl_Vertex + 1.0) * 3.0 / 2.0 - 1.0;
+}
+
+[fragment shader]
+varying vec4 color;
+
+void main()
+{
+	vec2 x = min(vec2(1.0), max(0.0, color.x)) * 0.5 + 0.25;
+	vec2 y = min(vec2(1.0), max(0.0, color.y)) * 0.5 + 0.25;
+	gl_FragColor = vec4(x.y, y.y, 0.0, 0.0);
+}
+
+[test]
+draw rect -1 -1 2 2
+relative probe rgba (0.0, 0.0) (0.25, 0.25, 0.0, 0.0)
+relative probe rgba (1.0, 0.0) (0.75, 0.25, 0.0, 0.0)
+relative probe rgba (0.0, 1.0) (0.25, 0.75, 0.0, 0.0)
+relative probe rgba (1.0, 1.0) (0.75, 0.75, 0.0, 0.0)
diff --git a/tests/shaders/glsl-fs-clamp-4.shader_test b/tests/shaders/glsl-fs-clamp-4.shader_test
new file mode 100644
index 0000000..829ac28
--- /dev/null
+++ b/tests/shaders/glsl-fs-clamp-4.shader_test
@@ -0,0 +1,29 @@
+[require]
+GLSL >= 1.10
+
+[vertex shader]
+varying vec4 color;
+
+void main()
+{
+	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
+	/* Renormalize to [-1, 2] */
+	color = (gl_Vertex + 1.0) * 3.0 / 2.0 - 1.0;
+}
+
+[fragment shader]
+varying vec4 color;
+
+void main()
+{
+	vec2 x = min(max(vec2(0.0), color.x), 1.0) * 0.5 + 0.25;
+	vec2 y = min(max(vec2(0.0), color.y), 1.0) * 0.5 + 0.25;
+	gl_FragColor = vec4(x.y, y.y, 0.0, 0.0);
+}
+
+[test]
+draw rect -1 -1 2 2
+relative probe rgba (0.0, 0.0) (0.25, 0.25, 0.0, 0.0)
+relative probe rgba (1.0, 0.0) (0.75, 0.25, 0.0, 0.0)
+relative probe rgba (0.0, 1.0) (0.25, 0.75, 0.0, 0.0)
+relative probe rgba (1.0, 1.0) (0.75, 0.75, 0.0, 0.0)
-- 
1.7.4.1



More information about the Piglit mailing list