[Piglit] [PATCH 7/8] gen_builtin_uniform_tests.py: Draw small rectangles per test, and probe them.

Eric Anholt eric at anholt.net
Fri Aug 29 14:41:18 PDT 2014


Before, we were drawing the whole window every time, while we only
probed a single pixel.  Instead, draw 4x4 rectangles across the
window, and probe the whole rectangle.  4x4 is chosen to at least get
several subspans rendering at the same time, in case drivers have bugs
in that area.

For what the effect looks like on generated shader_test code, before
we had generated tests that looked like:

    [...]
    draw rect -1 -1 2 2
    probe rgb 2 0 0.0 1.0 0.0 1.0
    [...]
    draw rect -1 -1 2 2
    probe rgb 3 0 0.0 1.0 0.0 1.0

and now we have:

    [...]
    draw rect ortho 8 0 4 4
    [...]
    draw rect ortho 12 0 4 4
    probe rect rgba (8, 0, 4, 4) (0.0, 1.0, 0.0, 1.0)
    probe rect rgba (12, 0, 4, 4) (1.0, 1.0, 1.0, 1.0)

or

    [...]
    draw rect ortho 8 0 4 4
    [...]
    draw rect ortho 12 0 4 4
    probe all rgba 0.0 1.0 0.0 1.0

Piglit (-t glsl-1.10/execution/built-in-functions/fs-op) runtime effects:
i965: -4.09672% +/- 1.54184% (n=24/26)
simulated VC4: -52.0335% +/- 1.83986% (n=3).
---
 generated_tests/gen_builtin_uniform_tests.py | 77 +++++++++++++++++++++++-----
 1 file changed, 63 insertions(+), 14 deletions(-)

diff --git a/generated_tests/gen_builtin_uniform_tests.py b/generated_tests/gen_builtin_uniform_tests.py
index 7dea38c..dc01607 100644
--- a/generated_tests/gen_builtin_uniform_tests.py
+++ b/generated_tests/gen_builtin_uniform_tests.py
@@ -134,6 +134,11 @@ class Comparator(object):
     def result_vector(self, test_vector):
         """Return the expected result color as a list of floats."""
 
+    @abc.abstractmethod
+    def has_invariant_result_vector(self):
+        """Returns whether the expected color is the same for all tests.
+        """
+
     def testname_suffix(self):
         """Return a string to be used as a suffix on the test name to
         distinguish it from tests using other comparators."""
@@ -176,6 +181,9 @@ class BoolComparator(Comparator):
     def result_vector(self, test_vector):
         return self.convert_to_float(test_vector.result)
 
+    def has_invariant_result_vector(self):
+        return False
+
 
 class BoolIfComparator(Comparator):
     """Comparator that tests functions returning bools by evaluating
@@ -216,6 +224,9 @@ class BoolIfComparator(Comparator):
     def result_vector(self, test_vector):
         return self.convert_to_float(test_vector.result)
 
+    def has_invariant_result_vector(self):
+        return False
+
     def testname_suffix(self):
         return '-using-if'
 
@@ -255,6 +266,9 @@ class IntComparator(Comparator):
     def result_vector(self, test_vector):
         return [0.0, 1.0, 0.0, 1.0]
 
+    def has_invariant_result_vector(self):
+        return True
+
 
 class FloatComparator(Comparator):
     """Comparator that tests functions returning floats or vecs using a
@@ -326,6 +340,9 @@ class FloatComparator(Comparator):
     def result_vector(self, test_vector):
         return [0.0, 1.0, 0.0, 1.0]
 
+    def has_invariant_result_vector(self):
+        return True
+
 
 class ShaderTest(object):
     """Class used to build a test of a single built-in.  This is an
@@ -349,6 +366,18 @@ class ShaderTest(object):
         """
         self._signature = signature
         self._test_vectors = test_vectors
+
+        num_tests = len(self._test_vectors)
+
+        # Size of the rectangles drawn by the test.
+        self.rect_width = 4
+        self.rect_height = 4
+        # Window size for our SIZE directive to shader_runner.
+        self.win_width = min(num_tests * self.rect_width, 512)
+        self.win_height = self.rect_height * ((num_tests * self.rect_width +
+                                               self.win_width - 1) /
+                                              self.win_width)
+
         if use_if:
             self._comparator = BoolIfComparator(signature)
         elif signature.rettype.base_type == glsl_bool:
@@ -363,17 +392,31 @@ class ShaderTest(object):
     def glsl_version(self):
         return self._signature.version_introduced
 
-    def draw_command(self):
-        return 'draw rect -1 -1 2 2\n'
+    def draw_command(self, test_num):
+        x = test_num * self.rect_width % self.win_width
+        y = test_num * self.rect_width / self.win_width * self.rect_height
+        # Make sure that the whole window gets initialized, by
+        # extending the last rectangle of the last row, if necessary.
+        if test_num == len(self._test_vectors) - 1:
+            w = self.win_width - x
+        else:
+            w = self.rect_width
+        h = self.rect_height
+        return 'draw rect ortho {0} {1} {2} {3}\n'.format(x, y, w, h)
 
     def probe_command(self, test_num, probe_vector):
-        # Note: shader_runner uses a 250x250 window so we must
-        # ensure that test_num <= 250.
-        return 'probe rgb {0} 0 {1} {2} {3} {4}\n'.format(test_num % 250,
-                                                          probe_vector[0],
-                                                          probe_vector[1],
-                                                          probe_vector[2],
-                                                          probe_vector[3])
+        return 'probe rect rgba ({0}, {1}, {2}, {3}) ({4}, {5}, {6}, {7})\n'.format(
+            test_num * self.rect_width % self.win_width,
+            test_num * self.rect_width / self.win_width * self.rect_height,
+            self.rect_width,
+            self.rect_height,
+            probe_vector[0], probe_vector[1], probe_vector[2], probe_vector[3])
+
+    def probe_all_command(self, probe_vector):
+        return 'probe all rgba {0} {1} {2} {3}\n'.format(probe_vector[0],
+                                                         probe_vector[1],
+                                                         probe_vector[2],
+                                                         probe_vector[3])
 
     def make_additional_requirements(self):
         """Return a string that should be included in the test's
@@ -458,9 +501,15 @@ class ShaderTest(object):
                     i, shader_runner_format(
                         column_major_values(test_vector.arguments[i])))
             test += self._comparator.draw_test(test_vector,
-                                               self.draw_command())
-            test += self.probe_command(test_num,
-                                       self._comparator.result_vector(test_vector))
+                                               self.draw_command(test_num))
+            result_color = self._comparator.result_vector(test_vector)
+
+        if self._comparator.has_invariant_result_vector():
+            test += self.probe_all_command(self._comparator.result_vector(None))
+        else:
+            for test_num, test_vector in enumerate(self._test_vectors):
+                result_color = self._comparator.result_vector(test_vector)
+                test += self.probe_command(test_num, result_color)
         return test
 
     def filename(self):
@@ -481,8 +530,8 @@ class ShaderTest(object):
         shader_test = '[require]\n'
         shader_test += 'GLSL >= {0:1.2f}\n'.format(
             float(self.glsl_version()) / 100)
-        shader_test += 'SIZE {0} 1'.format(
-            min(len(self._test_vectors), 250))
+        shader_test += 'SIZE {0} {1}'.format(self.win_width,
+                                             self.win_height)
         shader_test += self.make_additional_requirements()
         shader_test += '\n'
         shader_test += '[vertex shader]\n'
-- 
2.1.0



More information about the Piglit mailing list