summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2021-01-27 20:27:46 -0800
committerIan Romanick <ian.d.romanick@intel.com>2021-03-26 17:02:14 -0700
commit89548e829765faae84faab6d637610a9d9a1ac2b (patch)
tree7ebd9327d02636b48802ab032a9fdd69e8792391
parent6a4be9e9946df310d9402f995f371c7deb8c27ba (diff)
glsl-1.30: Test range analysis of min and max in the presence of NaN
Mesa currently fails both of these tests. The range analysis of min(-abs(x), abs(y)) says that -abs(x) must be the result. However, if one parameter is NaN, min (and max) will always choose the parameter that is a number. Therefore, if x is NaN, the result will be abs(y). Some optimizations use this knowledge to eliminate comparisons. Some examples: (('fge', 'a(is_lt_zero)', 'b(is_not_negative)'), False), (('flt', 'a(is_not_negative)', 'b(is_not_positive)'), False), These reductions are "exact" if either "a" or "b" is NaN, but they are not exact if range analysis provides incorrect range information. Part-of: <https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/463>
-rw-r--r--tests/spec/glsl-1.30/execution/range_analysis_fmax_of_nan.shader_test30
-rw-r--r--tests/spec/glsl-1.30/execution/range_analysis_fmin_of_nan.shader_test30
2 files changed, 60 insertions, 0 deletions
diff --git a/tests/spec/glsl-1.30/execution/range_analysis_fmax_of_nan.shader_test b/tests/spec/glsl-1.30/execution/range_analysis_fmax_of_nan.shader_test
new file mode 100644
index 000000000..8783823ea
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/range_analysis_fmax_of_nan.shader_test
@@ -0,0 +1,30 @@
+[require]
+GLSL >= 1.30
+
+[vertex shader passthrough]
+
+[fragment shader]
+#version 130
+uniform float zero = 0.0;
+uniform float also_zero = 0.0;
+uniform float a_number = 42.0;
+
+out vec4 piglit_fragcolor;
+
+void main()
+{
+ float not_a_number = zero / also_zero;
+
+ /* Result of the max() should be -42, but range analysis might incorrectly
+ * think that it's some value >= 0.
+ */
+ if (-32.0 >= max(abs(not_a_number), -abs(a_number))) {
+ piglit_fragcolor = vec4(0.0, 1.0, 0.0, 1.0);
+ } else {
+ piglit_fragcolor = vec4(1.0, 0.0, 0.0, 1.0);
+ }
+}
+
+[test]
+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/range_analysis_fmin_of_nan.shader_test b/tests/spec/glsl-1.30/execution/range_analysis_fmin_of_nan.shader_test
new file mode 100644
index 000000000..6ea87592e
--- /dev/null
+++ b/tests/spec/glsl-1.30/execution/range_analysis_fmin_of_nan.shader_test
@@ -0,0 +1,30 @@
+[require]
+GLSL >= 1.30
+
+[vertex shader passthrough]
+
+[fragment shader]
+#version 130
+uniform float zero = 0.0;
+uniform float also_zero = 0.0;
+uniform float a_number = 42.0;
+
+out vec4 piglit_fragcolor;
+
+void main()
+{
+ float not_a_number = zero / also_zero;
+
+ /* Result of the min() should be 42, but range analysis might incorrectly
+ * think that it's some value <= 0.
+ */
+ if (32.0 < min(-abs(not_a_number), abs(a_number))) {
+ piglit_fragcolor = vec4(0.0, 1.0, 0.0, 1.0);
+ } else {
+ piglit_fragcolor = vec4(1.0, 0.0, 0.0, 1.0);
+ }
+}
+
+[test]
+draw rect -1 -1 2 2
+probe all rgba 0.0 1.0 0.0 1.0