[Piglit] [PATCH 04/12] gen_builtin_uniform_tests.py: Add tessellation control shader tests.

Ilia Mirkin imirkin at alum.mit.edu
Wed Sep 17 22:12:42 PDT 2014


On Wed, Sep 17, 2014 at 3:42 AM, Chris Forbes <chrisf at ijw.co.nz> wrote:
> From: Fabian Bieler <fabianbieler at fastmail.fm>
>
> ---
>  generated_tests/gen_builtin_uniform_tests.py | 129 ++++++++++++++++++++++++++-
>  1 file changed, 125 insertions(+), 4 deletions(-)
>
> diff --git a/generated_tests/gen_builtin_uniform_tests.py b/generated_tests/gen_builtin_uniform_tests.py
> index 7edd5cc..b8eceed 100644
> --- a/generated_tests/gen_builtin_uniform_tests.py
> +++ b/generated_tests/gen_builtin_uniform_tests.py
> @@ -357,6 +357,12 @@ class ShaderTest(object):
>      def glsl_version(self):
>          return self._signature.version_introduced
>
> +    def extensions(self):
> +        ext = []
> +        if self._signature.extension:
> +            ext.append(self._signature.extension)
> +        return ext
> +
>      def draw_command(self):
>          if self.glsl_version() >= 140:
>              return 'draw arrays GL_TRIANGLE_FAN 0 4\n'
> @@ -380,6 +386,22 @@ class ShaderTest(object):
>      def make_vertex_shader(self):
>          """Return the vertex shader for this test."""
>
> +    def make_tess_ctrl_shader(self):
> +        """Return the tessellation control shader for this test
> +        (or None if this test doesn't require a geometry shader).
> +        No need to reimplement this function in classes that don't
> +        use geometry shaders.
> +        """
> +        return None
> +
> +    def make_tess_eval_shader(self):
> +        """Return the tessellation evaluation shader for this test
> +        (or None if this test doesn't require a geometry shader).
> +        No need to reimplement this function in classes that don't
> +        use geometry shaders.
> +        """
> +        return None
> +
>      def make_geometry_shader(self):
>          """Return the geometry shader for this test (or None if this
>          test doesn't require a geometry shader).  No need to
> @@ -415,8 +437,8 @@ class ShaderTest(object):
>          shader, after the built-in function is called.
>          """
>          shader = ''
> -        if self._signature.extension:
> -            shader += '#extension GL_{0} : require\n'.format(self._signature.extension)
> +        for ext in self.extensions():
> +            shader += '#extension GL_{0} : require\n'.format(ext)
>          shader += additional_declarations
>          for i in xrange(len(self._signature.argtypes)):
>              shader += 'uniform {0} arg{1};\n'.format(
> @@ -469,8 +491,8 @@ 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.lower()
> +        if self.extensions():
> +            subdir = self.extensions()[0].lower()
>          else:
>              subdir = 'glsl-{0:1.2f}'.format(float(self.glsl_version()) / 100)
>          return os.path.join(
> @@ -489,6 +511,16 @@ class ShaderTest(object):
>          shader_test += '[vertex shader]\n'
>          shader_test += self.make_vertex_shader()
>          shader_test += '\n'
> +        tcs = self.make_tess_ctrl_shader()
> +        if tcs:
> +            shader_test += '[tessellation control shader]\n'
> +            shader_test += tcs
> +            shader_test += '\n'
> +        tes = self.make_tess_eval_shader()
> +        if tes:
> +            shader_test += '[tessellation evaluation shader]\n'
> +            shader_test += tes
> +            shader_test += '\n'
>          gs = self.make_geometry_shader()
>          if gs:
>              shader_test += '[geometry shader]\n'
> @@ -544,6 +576,94 @@ void main()
>          return shader
>
>
> +class TessellationShaderTest(ShaderTest):
> +    """Abstract class for tests that exercise the built-in in
> +    tessellation shaders.
> +    """
> +
> +    def glsl_version(self):
> +        return max(150, ShaderTest.glsl_version(self))
> +
> +    def extensions(self):
> +        ext = []
> +        if self._signature.extension:
> +            ext.append(self._signature.extension)
> +        ext.append("ARB_tessellation_shader")
> +        return ext
> +
> +    def draw_command(self):
> +        return 'draw arrays GL_PATCHES 0 3\n'

Should this be 3 or 6? I assumed you'd want 2 triangles to cover the
whole screen? (And I think the vertex data is laid out as a triangle
fan, which is no good for these purposes...)

> +
> +    def make_vertex_shader(self):
> +        shader = \
> +"""in vec4 vertex;
> +out vec4 vertex_to_tcs;
> +
> +void main()
> +{
> +     vertex_to_tcs = vertex;
> +}
> +"""
> +        return shader
> +
> +    def make_fragment_shader(self):
> +        shader = \
> +"""in vec4 color_to_fs;
> +
> +void main()
> +{
> +  gl_FragColor = color_to_fs;
> +}
> +"""
> +        return shader
> +
> +
> +class TessCtrlShaderTest(TessellationShaderTest):
> +    """Derived class for tests that exercise the built-in in a
> +    tessellation control shader.
> +    """
> +
> +    def test_prefix(self):
> +        return 'tcs'
> +
> +    def make_tess_ctrl_shader(self):
> +        additional_declarations = \
> +"""layout(vertices = 3) out;
> +in vec4 vertex_to_tcs[];
> +out vec4 vertex_to_tes[3];
> +patch out vec4 color_to_tes;
> +"""
> +        body = \
> +"""  vertex_to_tes[gl_InvocationID] = vertex_to_tcs[gl_InvocationID];
> +  color_to_tes = tmp_color;
> +  gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);
> +  gl_TessLevelInner = float[2](1.0, 1.0);
> +"""
> +        shader = self.make_test_shader(
> +            additional_declarations,
> +            '  vec4 tmp_color;\n',
> +            'tmp_color',
> +            body)
> +        return shader
> +
> +    def make_tess_eval_shader(self):
> +        shader = \
> +"""#extension GL_ARB_tessellation_shader : require
> +layout(quads) in;
> +
> +in vec4 vertex_to_tes[];
> +patch in vec4 color_to_tes;
> +out vec4 color_to_fs;
> +void main() {
> +  gl_Position = vertex_to_tes[1]
> +              + (vertex_to_tes[0] - vertex_to_tes[1]) * gl_TessCoord[0]
> +              + (vertex_to_tes[2] - vertex_to_tes[1]) * gl_TessCoord[1];
> +  color_to_fs = color_to_tes;
> +}
> +"""
> +        return shader
> +
> +
>  class GeometryShaderTest(ShaderTest):
>      """Derived class for tests that exercise the built-in in a
>      geometry shader.
> @@ -626,6 +746,7 @@ def all_tests():
>              if use_if and signature.rettype != glsl_bool:
>                  continue
>              yield VertexShaderTest(signature, test_vectors, use_if)
> +            yield TessCtrlShaderTest(signature, test_vectors, use_if)
>              yield GeometryShaderTest(signature, test_vectors, use_if)
>              yield FragmentShaderTest(signature, test_vectors, use_if)
>
> --
> 2.1.0
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list