[Piglit] [PATCH 3/4] generators: Add a minimum version helper.

Dylan Baker baker.dylan.c at gmail.com
Tue Apr 12 07:49:51 UTC 2016


This adds another GLSL related helper, a factory for getting minimum
versions based on stages. This is able to sort all of the stages for
both OpenGL and OpenGL ES.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/modules/glsl.py   | 48 ++++++++++++++++++++++++
 unittests/generators/test_glsl.py | 78 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+)

diff --git a/generated_tests/modules/glsl.py b/generated_tests/modules/glsl.py
index 251537a..458dc47 100644
--- a/generated_tests/modules/glsl.py
+++ b/generated_tests/modules/glsl.py
@@ -209,3 +209,51 @@ class GLSLESVersion(object):
             return '{:.2f}'.format(float(self))
         else:
             return '{:.2f} es'.format(float(self))
+
+
+class _MinVersion(object):
+    """A factory class for sorting GLSL and GLSLES versions.
+
+    This stores the minimum version required for various operations (currently
+    only for_stage), and will take the version, and the any additional features,
+    and return the minimum supported version. It returns a GLSLVersion or a
+    GLSLESVersion.
+
+    This class is not meant to be reinitialized, instead use the provided
+    MinVersion constant.
+
+    """
+    __gl_stage_min = {
+        'frag': Version('110'),
+        'vert': Version('110'),
+        'geom': Version('150'),
+        'tesc': Version('140'),
+        'tese': Version('140'),
+        'comp': Version('140'),
+    }
+    __gles_stage_min = {
+        'frag': Version('100'),
+        'vert': Version('100'),
+        'comp': Version('310 es'),
+        'geom': Version('320 es'),
+        'tesc': Version('320 es'),
+        'tese': Version('320 es'),
+    }
+
+    def for_stage(self, stage, version):
+        """Return max(stage minimum version, requested version).
+
+        When provided a stage and version provides the minimum version
+        supported for that stage.
+
+        """
+        assert isinstance(version, (GLSLVersion, GLSLESVersion))
+        if isinstance(version, GLSLVersion):
+            _stage = self.__gl_stage_min[stage]
+        elif isinstance(version, GLSLESVersion):
+            _stage = self.__gles_stage_min[stage]
+
+        return _stage if _stage > version else version
+
+
+MinVersion = _MinVersion()  # pylint: disable=invalid-name
diff --git a/unittests/generators/test_glsl.py b/unittests/generators/test_glsl.py
index eabb600..0072db5 100644
--- a/unittests/generators/test_glsl.py
+++ b/unittests/generators/test_glsl.py
@@ -297,3 +297,81 @@ def test_GLSLESVersion_print_float():
 def test_GLSLESVersion_print_float_es():
     """generated_tests.modules.glsl.GLSLESVersion: print_float() (es version)"""
     nt.eq_(glsl.Version('300 es').print_float(), '3.00 es')
+
+
+class TestMinVersion_for_stage(object):
+    """Tests for generated_tests.modules.glsl.MinVersion.for_stage.
+
+    Each test covers the requested < required and requested == required. If
+    it's possible it also covers requested > required.
+
+    """
+    def _test(self, stage, version, expected):
+        nt.eq_(glsl.MinVersion.for_stage(stage, version), expected,
+               msg='(actual) {} != (expected) {}'.format(
+                   str(version), str(expected)))
+
+    def test_opengl_frag(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: FS (OpenGL)"""
+        self._test('frag', glsl.Version('150'), glsl.Version('150'))
+        self._test('frag', glsl.Version('110'), glsl.Version('110'))
+
+    def test_opengl_vert(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: VS (OpenGL)"""
+        self._test('vert', glsl.Version('150'), glsl.Version('150'))
+        self._test('vert', glsl.Version('110'), glsl.Version('110'))
+
+    def test_opengl_geom(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: GS (OpenGL)"""
+        self._test('geom', glsl.Version('330'), glsl.Version('330'))
+        self._test('geom', glsl.Version('110'), glsl.Version('150'))
+        self._test('geom', glsl.Version('150'), glsl.Version('150'))
+
+    def test_opengl_tesc(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: TCS (OpenGL)"""
+        self._test('tesc', glsl.Version('330'), glsl.Version('330'))
+        self._test('tesc', glsl.Version('110'), glsl.Version('140'))
+        self._test('tesc', glsl.Version('140'), glsl.Version('140'))
+
+    def test_opengl_tese(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: TES (OpenGL)"""
+        self._test('tese', glsl.Version('330'), glsl.Version('330'))
+        self._test('tese', glsl.Version('110'), glsl.Version('140'))
+        self._test('tese', glsl.Version('140'), glsl.Version('140'))
+
+    def test_opengl_comp(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: TES (OpenGL)"""
+        self._test('comp', glsl.Version('330'), glsl.Version('330'))
+        self._test('comp', glsl.Version('110'), glsl.Version('140'))
+        self._test('comp', glsl.Version('140'), glsl.Version('140'))
+
+    def test_opengles_frag(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: FS (OpenGL ES)"""
+        self._test('frag', glsl.Version('300 es'), glsl.Version('300 es'))
+        self._test('frag', glsl.Version('100'), glsl.Version('100'))
+
+    def test_opengles_vert(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: VS (OpenGL ES)"""
+        self._test('vert', glsl.Version('320 es'), glsl.Version('320 es'))
+        self._test('vert', glsl.Version('100'), glsl.Version('100'))
+
+    def test_opengles_geom(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: GS (OpenGL ES)"""
+        self._test('geom', glsl.Version('100'), glsl.Version('320 es'))
+        self._test('geom', glsl.Version('320 es'), glsl.Version('320 es'))
+
+    def test_opengles_tesc(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: TCS (OpenGL ES)"""
+        self._test('tesc', glsl.Version('320 es'), glsl.Version('320 es'))
+        self._test('tesc', glsl.Version('100'), glsl.Version('320 es'))
+
+    def test_opengles_tese(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: TES (OpenGL ES)"""
+        self._test('tese', glsl.Version('320 es'), glsl.Version('320 es'))
+        self._test('tese', glsl.Version('100'), glsl.Version('320 es'))
+
+    def test_opengles_comp(self):
+        """generated_tests.modules.glsl.MinVersion.for_stage: TES (OpenGL ES)"""
+        self._test('comp', glsl.Version('320 es'), glsl.Version('320 es'))
+        self._test('comp', glsl.Version('100'), glsl.Version('310 es'))
+        self._test('comp', glsl.Version('310 es'), glsl.Version('310 es'))
-- 
2.8.0



More information about the Piglit mailing list