[Piglit] [PATCH] glsl-1.30: Verify proper conversion of large floats to uints.

Paul Berry stereotype441 at gmail.com
Wed Jun 13 16:59:56 PDT 2012


This patch adds two new tests that exercise a bug in Mesa/i965:
conversion from float to uint was being done in a two step process:
convert first to int and then to uint.  Since i965 uses saturating
arithmetic in float->int conversion, this caused conversion to give
the wrong result for values greater than 0x7fffffff.

I'll be submitting a Mesa fix shortly.
---
 .../execution/fs-float-uint-conversion.shader_test |   37 +++++++++++++++++++
 .../execution/vs-float-uint-conversion.shader_test |   38 ++++++++++++++++++++
 2 files changed, 75 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/glsl-1.30/execution/fs-float-uint-conversion.shader_test
 create mode 100644 tests/spec/glsl-1.30/execution/vs-float-uint-conversion.shader_test

diff --git a/tests/spec/glsl-1.30/execution/fs-float-uint-conversion.shader_test b/tests/spec/glsl-1.30/execution/fs-float-uint-conversion.shader_test
new file mode 100644
index 0000000..5c346a6
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/fs-float-uint-conversion.shader_test
@@ -0,0 +1,37 @@
+# Check that a very large floating point value can be converted to a
+# uint, even though it falls outside the valid range of ints.
+#
+# The very large floating point value we test with is 0xff000000 ==
+# 4278190080, which can be represented exactly using a 32-bit float,
+# so we don't need to worry about rounding error.
+
+[require]
+GLSL >= 1.30
+
+[vertex shader]
+#version 130
+void main()
+{
+	gl_Position = gl_Vertex;
+}
+
+[fragment shader]
+#version 130
+uniform float float_value;
+uniform uint uint_value;
+
+#define RED vec4(1.0, 0.0, 0.0, 1.0)
+#define GREEN vec4(0.0, 1.0, 0.0, 1.0)
+
+void main()
+{
+	uint converted = uint(float_value);
+	bool match = converted == uint_value;
+	gl_FragColor = match ? GREEN : RED;
+}
+
+[test]
+uniform float float_value 4278190080
+uniform uint uint_value 4278190080
+draw rect -1 -1 2 2
+probe all rgba 0.0 1.0 0.0 1.0
diff --git a/tests/spec/glsl-1.30/execution/vs-float-uint-conversion.shader_test b/tests/spec/glsl-1.30/execution/vs-float-uint-conversion.shader_test
new file mode 100644
index 0000000..03b8c60
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/vs-float-uint-conversion.shader_test
@@ -0,0 +1,38 @@
+# Check that a very large floating point value can be converted to a
+# uint, even though it falls outside the valid range of ints.
+#
+# The very large floating point value we test with is 0xff000000 ==
+# 4278190080, which can be represented exactly using a 32-bit float,
+# so we don't need to worry about rounding error.
+
+[require]
+GLSL >= 1.30
+
+[vertex shader]
+#version 130
+uniform float float_value;
+uniform uint uint_value;
+
+#define RED vec4(1.0, 0.0, 0.0, 1.0)
+#define GREEN vec4(0.0, 1.0, 0.0, 1.0)
+
+void main()
+{
+	gl_Position = gl_Vertex;
+	uint converted = uint(float_value);
+	bool match = converted == uint_value;
+	gl_FrontColor = match ? GREEN : RED;
+}
+
+[fragment shader]
+#version 130
+void main()
+{
+	gl_FragColor = gl_Color;
+}
+
+[test]
+uniform float float_value 4278190080
+uniform uint uint_value 4278190080
+draw rect -1 -1 2 2
+probe all rgba 0.0 1.0 0.0 1.0
-- 
1.7.7.6



More information about the Piglit mailing list