[Piglit] [PATCH] glsl-1.10 / glsl-1.20: Relax precision requirements of variable indexing tests

Ian Romanick idr at freedesktop.org
Wed Aug 21 20:44:49 PDT 2013


From: Ian Romanick <ian.d.romanick at intel.com>

Many of these tests fail on older GPU such as Intel i915 due to the
precision requirement.  This is because many GPUs in this class only use
24-bit floats.  Many also implement many instructions cheaply (with poor
precision).

Do a couple things to relax the precision requirement.  First, use the
distance squared instead of the distance.  This saves an
inverse-square-root and a multiple.  The inverse-square-root has
notoriously poor precision on old GPUs.  Second, pick a precision that
passes on at least one 24-bit float GPU.  I picked 4e-9 because that was
the smallest bound that would pass on i915.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
I suspect that r300 GPUs also fail these tests, but I don't have any of
that hardware around.  Could someone test before and after for me? :)

This is also not the full patch.  The full patch is ~300kb, so the list
server would have rejected it.  This is just a handful of representitive
tests and the generator script.

 .../fs-temp-array-mat2-col-row-wr.shader_test             |  4 +++-
 .../fs-temp-array-mat2-col-wr.shader_test                 |  4 +++-
 .../fs-temp-array-mat2-index-col-row-wr.shader_test       |  4 +++-
 .../fs-temp-array-mat2-index-col-wr.shader_test           |  4 +++-
 .../fs-temp-array-mat2-index-row-wr.shader_test           |  4 +++-
 .../fs-temp-array-mat2-index-wr.shader_test               |  4 +++-
 .../vs-temp-array-mat2-col-row-wr.shader_test             |  6 +++---
 .../vs-temp-array-mat2-col-wr.shader_test                 |  6 +++---
 .../vs-temp-array-mat2-index-col-row-wr.shader_test       |  6 +++---
 .../vs-temp-array-mat2-index-col-wr.shader_test           |  6 +++---
 .../vs-temp-array-mat2-index-row-wr.shader_test           |  6 +++---
 .../vs-temp-array-mat2-index-wr.shader_test               |  6 +++---
 tests/spec/glsl-1.10/variable-index-write.sh              | 15 +++++++++++++--
 13 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-col-row-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-col-row-wr.shader_test
index 647cc02..ee9e77f 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-col-row-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-col-row-wr.shader_test
@@ -16,6 +16,8 @@ uniform int row;
 uniform int col;
 uniform float value;
 
+float distanceSqr(vec a, vec b) { vec diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     mat2 dst_matrix[3];
@@ -34,7 +36,7 @@ void main()
      */
     dst_matrix[1] = src_matrix;
     dst_matrix[1][col][row] = value;
-    gl_FragColor = (distance(dst_matrix[1] * v, expect) < 1e-6)
+    gl_FragColor = (distanceSqr(dst_matrix[1] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-col-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-col-wr.shader_test
index 5dd759e..02d3ad1 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-col-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-col-wr.shader_test
@@ -15,6 +15,8 @@ uniform int index;
 uniform int col;
 uniform vec2 value;
 
+float distanceSqr(vec a, vec b) { vec diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     mat2 dst_matrix[3];
@@ -33,7 +35,7 @@ void main()
      */
     dst_matrix[1] = src_matrix;
     dst_matrix[1][col] = value;
-    gl_FragColor = (distance(dst_matrix[1] * v, expect) < 1e-6)
+    gl_FragColor = (distanceSqr(dst_matrix[1] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-col-row-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-col-row-wr.shader_test
index acc3b77..27bf7d6 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-col-row-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-col-row-wr.shader_test
@@ -16,6 +16,8 @@ uniform int row;
 uniform int col;
 uniform float value;
 
+float distanceSqr(vec a, vec b) { vec diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     mat2 dst_matrix[3];
@@ -34,7 +36,7 @@ void main()
      */
     dst_matrix[index] = src_matrix;
     dst_matrix[index][col][row] = value;
-    gl_FragColor = (distance(dst_matrix[index] * v, expect) < 1e-6)
+    gl_FragColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-col-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-col-wr.shader_test
index 4e82686..592ee5e 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-col-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-col-wr.shader_test
@@ -15,6 +15,8 @@ uniform int index;
 uniform int col;
 uniform vec2 value;
 
+float distanceSqr(vec a, vec b) { vec diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     mat2 dst_matrix[3];
@@ -33,7 +35,7 @@ void main()
      */
     dst_matrix[index] = src_matrix;
     dst_matrix[index][col] = value;
-    gl_FragColor = (distance(dst_matrix[index] * v, expect) < 1e-6)
+    gl_FragColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-row-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-row-wr.shader_test
index e4451a0..f1bd811 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-row-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-row-wr.shader_test
@@ -16,6 +16,8 @@ uniform int row;
 uniform int col;
 uniform float value;
 
+float distanceSqr(vec a, vec b) { vec diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     mat2 dst_matrix[3];
@@ -34,7 +36,7 @@ void main()
      */
     dst_matrix[index] = src_matrix;
     dst_matrix[index][1][row] = value;
-    gl_FragColor = (distance(dst_matrix[index] * v, expect) < 1e-6)
+    gl_FragColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-wr.shader_test
index 079fec3..83bcadd 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/fs-temp-array-mat2-index-wr.shader_test
@@ -15,6 +15,8 @@ uniform int index;
 uniform int col;
 uniform vec2 value;
 
+float distanceSqr(vec a, vec b) { vec diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     mat2 dst_matrix[3];
@@ -33,7 +35,7 @@ void main()
      */
     dst_matrix[index] = src_matrix;
     dst_matrix[index][1] = value;
-    gl_FragColor = (distance(dst_matrix[index] * v, expect) < 1e-6)
+    gl_FragColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-col-row-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-col-row-wr.shader_test
index 924807d..7b1dfed 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-col-row-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-col-row-wr.shader_test
@@ -5,7 +5,6 @@
 GLSL >= 1.10
 
 [vertex shader]
-#version 110
 uniform mat2 src_matrix;
 uniform vec2 v;
 uniform vec2 expect;
@@ -14,6 +13,8 @@ uniform int row;
 uniform int col;
 uniform float value;
 
+float distanceSqr(vec2 a, vec2 b) { vec2 diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
@@ -34,12 +35,11 @@ void main()
      */
     dst_matrix[1] = src_matrix;
     dst_matrix[1][col][row] = value;
-    gl_FrontColor = (distance(dst_matrix[1] * v, expect) < 1e-6)
+    gl_FrontColor = (distanceSqr(dst_matrix[1] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
 [fragment shader]
-#version 110
 void main() { gl_FragColor = gl_Color; }
 
 [test]
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-col-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-col-wr.shader_test
index 4bb04e8..ffc8c88 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-col-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-col-wr.shader_test
@@ -5,7 +5,6 @@
 GLSL >= 1.10
 
 [vertex shader]
-#version 110
 uniform mat2 src_matrix;
 uniform vec2 v;
 uniform vec2 expect;
@@ -13,6 +12,8 @@ uniform int index;
 uniform int col;
 uniform vec2 value;
 
+float distanceSqr(vec2 a, vec2 b) { vec2 diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
@@ -33,12 +34,11 @@ void main()
      */
     dst_matrix[1] = src_matrix;
     dst_matrix[1][col] = value;
-    gl_FrontColor = (distance(dst_matrix[1] * v, expect) < 1e-6)
+    gl_FrontColor = (distanceSqr(dst_matrix[1] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
 [fragment shader]
-#version 110
 void main() { gl_FragColor = gl_Color; }
 
 [test]
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-col-row-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-col-row-wr.shader_test
index adaf608..67579e6 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-col-row-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-col-row-wr.shader_test
@@ -5,7 +5,6 @@
 GLSL >= 1.10
 
 [vertex shader]
-#version 110
 uniform mat2 src_matrix;
 uniform vec2 v;
 uniform vec2 expect;
@@ -14,6 +13,8 @@ uniform int row;
 uniform int col;
 uniform float value;
 
+float distanceSqr(vec2 a, vec2 b) { vec2 diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
@@ -34,12 +35,11 @@ void main()
      */
     dst_matrix[index] = src_matrix;
     dst_matrix[index][col][row] = value;
-    gl_FrontColor = (distance(dst_matrix[index] * v, expect) < 1e-6)
+    gl_FrontColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
 [fragment shader]
-#version 110
 void main() { gl_FragColor = gl_Color; }
 
 [test]
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-col-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-col-wr.shader_test
index 39c6dff..216e66e 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-col-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-col-wr.shader_test
@@ -5,7 +5,6 @@
 GLSL >= 1.10
 
 [vertex shader]
-#version 110
 uniform mat2 src_matrix;
 uniform vec2 v;
 uniform vec2 expect;
@@ -13,6 +12,8 @@ uniform int index;
 uniform int col;
 uniform vec2 value;
 
+float distanceSqr(vec2 a, vec2 b) { vec2 diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
@@ -33,12 +34,11 @@ void main()
      */
     dst_matrix[index] = src_matrix;
     dst_matrix[index][col] = value;
-    gl_FrontColor = (distance(dst_matrix[index] * v, expect) < 1e-6)
+    gl_FrontColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
 [fragment shader]
-#version 110
 void main() { gl_FragColor = gl_Color; }
 
 [test]
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-row-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-row-wr.shader_test
index e5a5c08..947b8de 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-row-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-row-wr.shader_test
@@ -5,7 +5,6 @@
 GLSL >= 1.10
 
 [vertex shader]
-#version 110
 uniform mat2 src_matrix;
 uniform vec2 v;
 uniform vec2 expect;
@@ -14,6 +13,8 @@ uniform int row;
 uniform int col;
 uniform float value;
 
+float distanceSqr(vec2 a, vec2 b) { vec2 diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
@@ -34,12 +35,11 @@ void main()
      */
     dst_matrix[index] = src_matrix;
     dst_matrix[index][1][row] = value;
-    gl_FrontColor = (distance(dst_matrix[index] * v, expect) < 1e-6)
+    gl_FrontColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
 [fragment shader]
-#version 110
 void main() { gl_FragColor = gl_Color; }
 
 [test]
diff --git a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-wr.shader_test b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-wr.shader_test
index 2ade3d1..78ba7a2 100644
--- a/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-wr.shader_test
+++ b/tests/spec/glsl-1.10/execution/variable-indexing/vs-temp-array-mat2-index-wr.shader_test
@@ -5,7 +5,6 @@
 GLSL >= 1.10
 
 [vertex shader]
-#version 110
 uniform mat2 src_matrix;
 uniform vec2 v;
 uniform vec2 expect;
@@ -13,6 +12,8 @@ uniform int index;
 uniform int col;
 uniform vec2 value;
 
+float distanceSqr(vec2 a, vec2 b) { vec2 diff = a - b; return abs(dot(diff, diff)); }
+
 void main()
 {
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
@@ -33,12 +34,11 @@ void main()
      */
     dst_matrix[index] = src_matrix;
     dst_matrix[index][1] = value;
-    gl_FrontColor = (distance(dst_matrix[index] * v, expect) < 1e-6)
+    gl_FrontColor = (distanceSqr(dst_matrix[index] * v, expect) < 4e-9)
         ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
 }
 
 [fragment shader]
-#version 110
 void main() { gl_FragColor = gl_Color; }
 
 [test]
diff --git a/tests/spec/glsl-1.10/variable-index-write.sh b/tests/spec/glsl-1.10/variable-index-write.sh
index 96a4791..eb8f0b6 100755
--- a/tests/spec/glsl-1.10/variable-index-write.sh
+++ b/tests/spec/glsl-1.10/variable-index-write.sh
@@ -50,6 +50,13 @@ function emit_globals
 }
 
 
+function emit_distanceSqr_function
+{
+    dim=$1
+    echo "float distanceSqr(vec${dim} a, vec${dim} b) { vec${dim} diff = a - b; return abs(dot(diff, diff)); }"
+    echo
+}
+
 function emit_set_matrix
 {
     matrix_dim=$1
@@ -179,6 +186,7 @@ function emit_fs
     echo "[fragment shader]"
 
     emit_globals $*
+    emit_distanceSqr_function
 
     echo "void main()"
     echo "{"
@@ -192,7 +200,7 @@ function emit_fs
 	emit_transform $*
     fi
 
-    echo "    gl_FragColor = (distance(dst_matrix${idx} * v, expect) < 1e-6)"
+    echo "    gl_FragColor = (distanceSqr(dst_matrix${idx} * v, expect) < 4e-9)"
     echo "        ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);"
     echo "}"
     echo
@@ -352,6 +360,9 @@ function emit_vs_wr_test
 
     echo "[vertex shader]"
     emit_globals $*
+    if [ "x$mode" != "xvarying" ] ; then
+        emit_distanceSqr_function $matrix_dim
+    fi
 
     echo "void main()"
     echo "{"
@@ -362,7 +373,7 @@ function emit_vs_wr_test
     emit_transform $*
 
     if [ "x$mode" != "xvarying" ] ; then
-	echo "    gl_FrontColor = (distance(dst_matrix${idx} * v, expect) < 1e-6)"
+	echo "    gl_FrontColor = (distanceSqr(dst_matrix${idx} * v, expect) < 4e-9)"
 	echo "        ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);"
     fi
 
-- 
1.8.1.4



More information about the Piglit mailing list