[Piglit] [PATCH 1/2] Add built-in function test generator support for extensions.

Kenneth Graunke kenneth at whitecape.org
Fri Jan 24 13:59:40 PST 2014


GL extensions often add new built-in functions.  We'd like to be able to
generate tests for them.  This means emitting the #extension line, and
placing them in generated_tests/spec/<extension name> rather than the
GLSL version number.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 generated_tests/builtin_function.py          | 31 +++++++++++++++-------------
 generated_tests/gen_builtin_uniform_tests.py | 12 ++++++++---
 2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/generated_tests/builtin_function.py b/generated_tests/builtin_function.py
index e1f43a4..d2fdf41 100644
--- a/generated_tests/builtin_function.py
+++ b/generated_tests/builtin_function.py
@@ -187,7 +187,7 @@ glsl_mat4x4 = glsl_mat4
 #           argtypes=('float', 'vec3'))
 Signature = collections.namedtuple(
     'Signature',
-    ('name', 'template', 'version_introduced', 'rettype', 'argtypes'))
+    ('name', 'template', 'version_introduced', 'extension', 'rettype', 'argtypes'))
 
 
 # Named tuple representing a single piece of test data for testing a
@@ -674,7 +674,7 @@ def _vectorize_test_vectors(test_vectors, scalar_arg_indices, vector_length):
     return vectorized_test_vectors
 
 
-def _store_test_vector(test_suite_dict, name, glsl_version, test_vector,
+def _store_test_vector(test_suite_dict, name, glsl_version, extension, test_vector,
                        template=None):
     """Store a test vector in the appropriate place in
     test_suite_dict.  The dictionary key (which is a Signature tuple)
@@ -697,14 +697,14 @@ def _store_test_vector(test_suite_dict, name, glsl_version, test_vector,
         glsl_version, rettype.version_introduced,
         *[t.version_introduced for t in argtypes])
     signature = Signature(
-        name, template, adjusted_glsl_version, rettype, argtypes)
+        name, template, adjusted_glsl_version, extension, rettype, argtypes)
     if signature not in test_suite_dict:
         test_suite_dict[signature] = []
     test_suite_dict[signature].append(test_vector)
 
 
-def _store_test_vectors(test_suite_dict, name, glsl_version, test_vectors,
-                        template=None):
+def _store_test_vectors(test_suite_dict, name, glsl_version, extension,
+                        test_vectors, template=None):
     """Store multiple test vectors in the appropriate places in
     test_suite_dict.
 
@@ -712,8 +712,8 @@ def _store_test_vectors(test_suite_dict, name, glsl_version, test_vectors,
     Signature objects generated.
     """
     for test_vector in test_vectors:
-        _store_test_vector(test_suite_dict, name, glsl_version, test_vector,
-                           template=template)
+        _store_test_vector(test_suite_dict, name, glsl_version, extension,
+                           test_vector, template=template)
 
 
 def make_arguments(input_generators):
@@ -756,7 +756,8 @@ def _make_componentwise_test_vectors(test_suite_dict):
 
     def f(name, arity, glsl_version, python_equivalent,
           alternate_scalar_arg_indices, test_inputs,
-          tolerance_function=_strict_tolerance):
+          tolerance_function=_strict_tolerance,
+          extension=None):
         """Create test vectors for the function with the given name
         and arity, which was introduced in the given glsl_version.
 
@@ -781,7 +782,7 @@ def _make_componentwise_test_vectors(test_suite_dict):
         scalar_test_vectors = _simulate_function(
             make_arguments(test_inputs), python_equivalent, tolerance_function)
         _store_test_vectors(
-            test_suite_dict, name, glsl_version, scalar_test_vectors)
+            test_suite_dict, name, glsl_version, extension, scalar_test_vectors)
         if alternate_scalar_arg_indices is None:
             scalar_arg_indices_list = [()]
         else:
@@ -789,7 +790,7 @@ def _make_componentwise_test_vectors(test_suite_dict):
         for scalar_arg_indices in scalar_arg_indices_list:
             for vector_length in (2, 3, 4):
                 _store_test_vectors(
-                    test_suite_dict, name, glsl_version,
+                    test_suite_dict, name, glsl_version, extension,
                     _vectorize_test_vectors(
                         scalar_test_vectors, scalar_arg_indices,
                         vector_length))
@@ -890,7 +891,8 @@ def _make_vector_relational_test_vectors(test_suite_dict):
         }
 
     def f(name, arity, glsl_version, python_equivalent, arg_types,
-          tolerance_function=_strict_tolerance):
+          tolerance_function=_strict_tolerance,
+          extension=None):
         """Make test vectors for the function with the given name and
         arity, which was introduced in the given glsl_version.
 
@@ -913,7 +915,7 @@ def _make_vector_relational_test_vectors(test_suite_dict):
                 tolerance_function)
             for vector_length in (2, 3, 4):
                 _store_test_vectors(
-                    test_suite_dict, name, glsl_version,
+                    test_suite_dict, name, glsl_version, extension,
                     _vectorize_test_vectors(
                         scalar_test_vectors, (), vector_length))
 
@@ -1141,7 +1143,8 @@ def _make_vector_or_matrix_test_vectors(test_suite_dict):
 
     def f(name, arity, glsl_version, python_equivalent,
           filter, test_inputs, tolerance_function=_strict_tolerance,
-          template=None):
+          template=None,
+          extension=None):
         """Make test vectors for the function with the given name and
         arity, which was introduced in the given glsl_version.
 
@@ -1170,7 +1173,7 @@ def _make_vector_or_matrix_test_vectors(test_suite_dict):
             test_inputs = \
                 [arguments for arguments in test_inputs if filter(*arguments)]
         _store_test_vectors(
-            test_suite_dict, name, glsl_version,
+            test_suite_dict, name, glsl_version, extension,
             _simulate_function(
                 test_inputs, python_equivalent, tolerance_function),
             template=template)
diff --git a/generated_tests/gen_builtin_uniform_tests.py b/generated_tests/gen_builtin_uniform_tests.py
index 340a9b9..5ecfc87 100644
--- a/generated_tests/gen_builtin_uniform_tests.py
+++ b/generated_tests/gen_builtin_uniform_tests.py
@@ -414,7 +414,10 @@ class ShaderTest(object):
         statements that need to be inside the main() funciton of the
         shader, after the built-in function is called.
         """
-        shader = additional_declarations
+        shader = ''
+        if self._signature.extension:
+            shader += '#extension GL_{0} : require\n'.format(self._signature.extension)
+        shader += additional_declarations
         for i in xrange(len(self._signature.argtypes)):
             shader += 'uniform {0} arg{1};\n'.format(
                 self._signature.argtypes[i], i)
@@ -466,9 +469,12 @@ class ShaderTest(object):
     def filename(self):
         argtype_names = '-'.join(
             str(argtype) for argtype in self._signature.argtypes)
+        if self._signature.extension:
+            subdir = self._signature.extension
+        else:
+            subdir = 'glsl-{0:1.2f}'.format(float(self.glsl_version()) / 100)
         return os.path.join(
-            'spec', 'glsl-{0:1.2f}'.format(float(self.glsl_version()) / 100),
-            'execution', 'built-in-functions',
+            'spec', subdir, 'execution', 'built-in-functions',
             '{0}-{1}-{2}{3}.shader_test'.format(
                 self.test_prefix(), self._signature.name, argtype_names,
                 self._comparator.testname_suffix()))
-- 
1.8.5.2



More information about the Piglit mailing list