diff options
author | Paul Berry <stereotype441@gmail.com> | 2011-08-10 16:03:43 -0700 |
---|---|---|
committer | Paul Berry <stereotype441@gmail.com> | 2011-08-15 11:18:46 -0700 |
commit | 62f30256a3970b847ef228dabc4a4c07f0b19b84 (patch) | |
tree | a895a562ea5f760126b16c53f834d377d924e64c /generated_tests/gen_builtin_uniform_tests.py | |
parent | 70bff3c40bba136c29e04fddfbc42f81a9a500cd (diff) |
Add operator tests to auto-generated built-in function tests.
This patch adds tests for the following built-in GLSL operators:
- op-add, op-sub, op-mult, op-div: binary arithemetic operators on
floats, vecs, mats, ints, and ivecs.
- op-uplus, op-neg: unary arithmetic operators on floats, vecs, mats,
ints, and ivecs.
- op-gt, op-lt, op-ge, op-le: comparison operators on ints and floats.
- op-eq, op-ne: equality and inequality comparison on any GLSL 1.20 type.
- op-and, op-or, op-xor: logical operations on bools.
- op-not: unary logical not on bools.
- op-selection: trinary selection operator (x?y:z), where the first
argument is a bool and the second and third arguments are any GLSL
1.20 type.
Note that implicit type conversions are not tested. So, for instance,
int * ivec is tested, but float * ivec is not. This was in an effort
to avoid generating an outrageous number of tests.
Note also that the "shortcut" behavior of logical and/or and trinary
selection is not tested.
These tests leverage the same test generation framework used to test
built-in functions, so the tests exercise vertex shaders, fragment
shaders, and constant folding.
All in all 1332 tests are added, in the subtrees
spec/glsl-1.{10,20}/{compiler,execution}/built-in-functions.
Reviewed-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'generated_tests/gen_builtin_uniform_tests.py')
-rw-r--r-- | generated_tests/gen_builtin_uniform_tests.py | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/generated_tests/gen_builtin_uniform_tests.py b/generated_tests/gen_builtin_uniform_tests.py index 64cb9272d..752cfb72d 100644 --- a/generated_tests/gen_builtin_uniform_tests.py +++ b/generated_tests/gen_builtin_uniform_tests.py @@ -158,6 +158,29 @@ class BoolComparator(Comparator): +class IntComparator(Comparator): + def __init__(self, signature): + self.__signature = signature + + def make_additional_declarations(self): + return 'uniform {0} expected;\n'.format(self.__signature.rettype) + + def make_result_handler(self, output_var): + return ' {v} = {cond} ? {green} : {red};\n'.format( + v=output_var, cond='result == expected', + green='vec4(0.0, 1.0, 0.0, 1.0)', + red='vec4(1.0, 0.0, 0.0, 1.0)') + + def make_result_test(self, test_num, test_vector): + test = 'uniform {0} expected {1}\n'.format( + shader_runner_type(self.__signature.rettype), + shader_runner_format(column_major_values(test_vector.result))) + test += 'draw rect -1 -1 2 2\n' + test += 'probe rgba {0} 0 0.0 1.0 0.0 1.0\n'.format(test_num) + return test + + + class FloatComparator(Comparator): def __init__(self, signature): self.__signature = signature @@ -239,6 +262,8 @@ class ShaderTest(object): self._comparator = BoolComparator(signature) elif signature.rettype.base_type == glsl_float: self._comparator = FloatComparator(signature) + elif signature.rettype.base_type == glsl_int: + self._comparator = IntComparator(signature) else: raise Exception('Unexpected rettype {0}'.format(signature.rettype)) @@ -288,10 +313,11 @@ class ShaderTest(object): shader += 'void main()\n' shader += '{\n' shader += additional_statements - args = ', '.join( - 'arg{0}'.format(i) for i in xrange(len(self._signature.argtypes))) - shader += ' {0} result = {1}({2});\n'.format( - self._signature.rettype, self._signature.name, args) + invocation = self._signature.template.format( + *['arg{0}'.format(i) + for i in xrange(len(self._signature.argtypes))]) + shader += ' {0} result = {1};\n'.format( + self._signature.rettype, invocation) shader += self._comparator.make_result_handler(output_var) shader += '}\n' return shader @@ -307,7 +333,10 @@ class ShaderTest(object): shader_runner_type(self._signature.argtypes[i]), i, shader_runner_format( column_major_values(test_vector.arguments[i]))) - test += self._comparator.make_result_test(test_num, test_vector) + # Note: shader_runner uses a 250x250 window so we must + # ensure that test_num <= 250. + test += self._comparator.make_result_test( + test_num % 250, test_vector) return test def filename(self): |