Commit 4d667d40 authored by Kenneth Graunke's avatar Kenneth Graunke

Make ARB_shader_precision tests ignore 0.0 vs -0.0.

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's avatarKenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Dylan Baker's avatarDylan Baker <dylan@pnwbakers.com>
Acked-by: Matt Turner's avatarMatt Turner <mattst88@gmail.com>
parent 1cc4003d
......@@ -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))
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment