[Piglit] [PATCH v2] Make ARB_shader_precision tests ignore 0.0 vs -0.0.

Kenneth Graunke kenneth at whitecape.org
Mon May 16 23:56:14 UTC 2016


The multiplication precision tests were attempting to multiply
0.0 * -0.1 and expecting to get +0.0 (0x00000000), and failing
if they received -0.0 (0x80000000).  This seems fairly bogus.

According to the ARB_shader_precision specification:
"In general, correct signedness of 0 is not required."

To avoid this problem, remove the sign bit from both the results
and expected values when the value is equal to (+/-) 0.0.

v2: Use xs.dtype.type(0.0) (suggested by Dylan Baker).

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 generated_tests/gen_shader_precision_tests.py                | 8 +++++++-
 generated_tests/templates/gen_shader_precision_tests/fs.mako | 4 ++--
 generated_tests/templates/gen_shader_precision_tests/gs.mako | 4 ++--
 generated_tests/templates/gen_shader_precision_tests/vs.mako | 4 ++--
 4 files changed, 13 insertions(+), 7 deletions(-)

I don't think it matters, but I'd actually thought about doing that
just to be safe anyway...

diff --git a/generated_tests/gen_shader_precision_tests.py b/generated_tests/gen_shader_precision_tests.py
index 43b6a25..6ab83e0 100644
--- a/generated_tests/gen_shader_precision_tests.py
+++ b/generated_tests/gen_shader_precision_tests.py
@@ -206,6 +206,11 @@ def shader_runner_format(values):
 
     return retval
 
+def drop_signbit(xs):
+    if (np.isscalar(xs)):
+        return xs.dtype.type(0.0) if xs == 0.0 else xs
+    return np.array([xs.dtype.type(0.0) if x == 0.0 else x for x in xs],
+                    xs.dtype)
 
 def main():
     """ Main function """
@@ -225,7 +230,8 @@ def main():
             complex_tol_type = signature.rettype
             for test_vector in test_vectors:
                 tolerance = _gen_tolerance(signature.name, signature.rettype, test_vector.arguments)
-                refined_test_vectors.append(TestVector(test_vector.arguments, test_vector.result, tolerance))
+                result = drop_signbit(test_vector.result)
+                refined_test_vectors.append(TestVector(test_vector.arguments, result, tolerance))
             # Then generate the shader_test scripts
             for shader_stage in ('vs', 'fs', 'gs'):
                 template = template_file('gen_shader_precision_tests', '{0}.mako'.format(shader_stage))
diff --git a/generated_tests/templates/gen_shader_precision_tests/fs.mako b/generated_tests/templates/gen_shader_precision_tests/fs.mako
index 0a66efa..a556bad 100644
--- a/generated_tests/templates/gen_shader_precision_tests/fs.mako
+++ b/generated_tests/templates/gen_shader_precision_tests/fs.mako
@@ -32,7 +32,7 @@ void main()
     ## build an array of bit-level representations of the floating point results calculated above
     ##
   int resultbits[${num_elements}] = int[${num_elements}](\
-${', '.join('floatBitsToInt(result{0})'.format(i) for i in indexers)}\
+${', '.join('result{0} == 0.0 ? 0x0 : floatBitsToInt(result{0})'.format(i) for i in indexers)}\
 );
     ##
     ## build an array of bit-level representations of the passed-in floating point expected results
@@ -84,7 +84,7 @@ max(ulps${indexers[len(indexers)-2]}, ulps${indexers[len(indexers)-1]})\
     ##
     ## if there is only a single result value generated, compare it directly
     ##
-  int resultbits = floatBitsToInt(result);
+  int resultbits = result == 0.0 ? 0x0 : floatBitsToInt(result);
   int expectedbits = floatBitsToInt(expected);
   bool signerr = resultbits>>31 != expectedbits>>31;
   float ulps = abs(resultbits - expectedbits);
diff --git a/generated_tests/templates/gen_shader_precision_tests/gs.mako b/generated_tests/templates/gen_shader_precision_tests/gs.mako
index a480594..d37a42b 100644
--- a/generated_tests/templates/gen_shader_precision_tests/gs.mako
+++ b/generated_tests/templates/gen_shader_precision_tests/gs.mako
@@ -43,7 +43,7 @@ void main()
     ## build an array of bit-level representations of the floating point results calculated above
     ##
   int resultbits[${num_elements}] = int[${num_elements}](\
-${', '.join('floatBitsToInt(result{0})'.format(i) for i in indexers)}\
+${', '.join('result{0} == 0.0 ? 0x0 : floatBitsToInt(result{0})'.format(i) for i in indexers)}\
 );
     ##
     ## build an array of bit-level representations of the passed-in floating point expected results
@@ -95,7 +95,7 @@ max(ulps${indexers[len(indexers)-2]}, ulps${indexers[len(indexers)-1]})\
     ##
     ## if there is only a single result value generated, compare it directly
     ##
-  int resultbits = floatBitsToInt(result);
+  int resultbits = result == 0.0 ? 0x0 : floatBitsToInt(result);
   int expectedbits = floatBitsToInt(expected);
   bool signerr = resultbits>>31 != expectedbits>>31;
   float ulps = abs(resultbits - expectedbits);
diff --git a/generated_tests/templates/gen_shader_precision_tests/vs.mako b/generated_tests/templates/gen_shader_precision_tests/vs.mako
index e7282f5..7ccdadc 100644
--- a/generated_tests/templates/gen_shader_precision_tests/vs.mako
+++ b/generated_tests/templates/gen_shader_precision_tests/vs.mako
@@ -33,7 +33,7 @@ void main()
     ## build an array of bit-level representations of the floating point results calculated above
     ##
   int resultbits[${num_elements}] = int[${num_elements}](\
-${', '.join('floatBitsToInt(result{0})'.format(i) for i in indexers)}\
+${', '.join('result{0} == 0.0 ? 0x0 : floatBitsToInt(result{0})'.format(i) for i in indexers)}\
 );
     ##
     ## build an array of bit-level representations of the passed-in floating point expected results
@@ -85,7 +85,7 @@ max(ulps${indexers[len(indexers)-2]}, ulps${indexers[len(indexers)-1]})\
     ##
     ## if there is only a single result value generated, compare it directly
     ##
-  int resultbits = floatBitsToInt(result);
+  int resultbits = result == 0.0 ? 0x0 : floatBitsToInt(result);
   int expectedbits = floatBitsToInt(expected);
   bool signerr = resultbits>>31 != expectedbits>>31;
   float ulps = abs(resultbits - expectedbits);
-- 
2.8.2



More information about the Piglit mailing list