[Piglit] [PATCH 24/45] gen_texture_lod_tests.py: Split templates

Dylan Baker baker.dylan.c at gmail.com
Wed Nov 12 15:46:06 PST 2014


Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/CMakeLists.txt                     |   6 +-
 generated_tests/gen_texture_lod_tests.py           | 146 +++++----------------
 .../frag_lod.glsl_parser_test.mako                 |  16 +++
 .../gen_texture_lod_tests/tex_grad.frag.mako       |  17 +++
 .../gen_texture_lod_tests/tex_grad.vert.mako       |  20 +++
 5 files changed, 94 insertions(+), 111 deletions(-)
 create mode 100644 generated_tests/templates/gen_texture_lod_tests/frag_lod.glsl_parser_test.mako
 create mode 100644 generated_tests/templates/gen_texture_lod_tests/tex_grad.frag.mako
 create mode 100644 generated_tests/templates/gen_texture_lod_tests/tex_grad.vert.mako

diff --git a/generated_tests/CMakeLists.txt b/generated_tests/CMakeLists.txt
index cbd065d..016c402 100644
--- a/generated_tests/CMakeLists.txt
+++ b/generated_tests/CMakeLists.txt
@@ -85,7 +85,11 @@ piglit_make_generated_tests(
 	)
 piglit_make_generated_tests(
 	texture_lod_tests.list
-	gen_texture_lod_tests.py)
+	gen_texture_lod_tests.py
+	templates/gen_texture_lod_tests/tex_grad.vert.mako
+	templates/gen_texture_lod_tests/tex_grad.frag.mako
+	templates/gen_texture_lod_tests/frag_lod.glsl_parser_test.mako
+	)
 piglit_make_generated_tests(
 	outerproduct_invalid_params.list
 	gen_outerproduct_invalid_params.py)
diff --git a/generated_tests/gen_texture_lod_tests.py b/generated_tests/gen_texture_lod_tests.py
index 6101341..ebedc61 100644
--- a/generated_tests/gen_texture_lod_tests.py
+++ b/generated_tests/gen_texture_lod_tests.py
@@ -22,9 +22,11 @@
 
 from __future__ import print_function
 import os
-import textwrap
 import collections
-import mako.template
+
+from templates import template_dir
+
+TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
 
 Parameters = collections.namedtuple(
     'Parameters', ['coord', 'grad', 'dimensions', 'mode'])
@@ -55,131 +57,55 @@ GRAD_TESTS = LOD_TESTS + [
 
 
 def get_extensions(mode):
-    """ If this test uses GL_ARB_texture_rectangle add it"""
+    """ If this test uses GL_ARB_texture_rectangle add it
+
+    GL_ARB_texture_rectangle is an odd extension, it is on by default, so don't
+    generate a #extension in the shader, just in the config block.
+
+    """
     if 'Rect' in mode:
         return 'GL_ARB_shader_texture_lod GL_ARB_texture_rectangle'
     return 'GL_ARB_shader_texture_lod'
 
 
-def gen_frag_lod_test(parameter, filename):
-    """ Generate fragment shader LOD tests """
-    template = mako.template.Template(textwrap.dedent("""
-    /* [config]
-     * expect_result: pass
-     * glsl_version: 1.10
-     * require_extensions: GL_ARB_shader_texture_lod
-     * [end config]
-     */
-    #extension GL_ARB_shader_texture_lod: require
-
-    uniform sampler${param.dimensions} s;
-    varying ${param.coord} coord;
-    varying float lod;
-
-    void main()
-    {
-      gl_FragColor = ${param.mode}Lod(s, coord, lod);
-    }
-    """))
-    with open(filename, 'w+') as f:
-        f.write(template.render_unicode(param=parameter))
-
-
-def gen_frag_grad_test(parameter, filename):
-    """ Generate fragment shader gradient tests """
-    template = mako.template.Template(textwrap.dedent("""
-    /* [config]
-     * expect_result: pass
-     * glsl_version: 1.10
-     * require_extensions: ${extensions}
-     * [end config]
-     */
-    #extension GL_ARB_shader_texture_lod: require
-
-    uniform sampler${param.dimensions} s;
-    varying ${param.coord} coord;
-    varying ${param.grad} dPdx;
-    varying ${param.grad} dPdy;
-
-    void main()
-    {
-      gl_FragColor = ${param.mode}GradARB(s, coord, dPdx, dPdy);
-    }
-    """))
-    with open(filename, 'w+') as f:
-        f.write(template.render_unicode(
-            param=parameter,
-            extensions=get_extensions(parameter.mode)))
-
-
-def gen_vert_grad_test(parameter, filename):
-    """ Generate vertex shader gradient tests """
-    template = mako.template.Template(textwrap.dedent("""
-    /* [config]
-     * expect_result: pass
-     * glsl_version: 1.10
-     * require_extensions: ${extensions}
-     * [end config]
-     */
-    #extension GL_ARB_shader_texture_lod: require
-
-    uniform sampler${param.dimensions} s;
-    attribute vec4 pos;
-    attribute ${param.coord} coord;
-    attribute ${param.grad} dPdx;
-    attribute ${param.grad} dPdy;
-    varying vec4 color;
-
-    void main()
-    {
-      gl_Position = pos;
-      color = ${param.mode}GradARB(s, coord, dPdx, dPdy);
-    }
-    """))
-    with open(filename, 'w+') as f:
-        f.write(template.render_unicode(
-            param=parameter,
-            extensions=get_extensions(parameter.mode)))
-
-
 def main():
     """ Main function
 
     Writes tests to generated_tests/spec/arb_shader_texture_lod/ directory
 
     """
-    try:
-        os.makedirs('spec/arb_shader_texture_lod/compiler')
-    except OSError:
-        pass
+    dirname = 'spec/arb_shader_texture_lod/compiler'
+    if not os.path.exists(dirname):
+        os.makedirs(dirname)
 
     for params in LOD_TESTS:
-        name = ("spec/arb_shader_texture_lod/compiler/"
-                "tex_lod-{mode}-{dimensions}-{coord}.frag".format(
-                    mode=params.mode,
-                    dimensions=params.dimensions,
-                    coord=params.coord))
+        name = os.path.join(
+            dirname,
+            "tex_lod-{mode}-{dimensions}-{coord}.frag".format(
+                mode=params.mode,
+                dimensions=params.dimensions,
+                coord=params.coord))
         print(name)
-        gen_frag_lod_test(params, name)
+        with open(name, 'w+') as f:
+            f.write(TEMPLATES.get_template(
+                'frag_lod.glsl_parser_test.mako').render_unicode(param=params))
 
     for params in GRAD_TESTS:
         # Generate fragment shader test
-        name = ("spec/arb_shader_texture_lod/compiler/"
-                "tex_grad-{mode}-{dimensions}-{coord}.frag".format(
-                    mode=params.mode,
-                    dimensions=params.dimensions,
-                    coord=params.coord))
-        print(name)
-        gen_frag_grad_test(params, name)
-
-        # Generate vertex shader test
-        name = ("spec/arb_shader_texture_lod/compiler/"
-                "tex_grad-{mode}-{dimensions}-{coord}.vert".format(
-                    mode=params.mode,
-                    dimensions=params.dimensions,
-                    coord=params.coord))
-        print(name)
-        gen_vert_grad_test(params, name)
+        name = os.path.join(
+            dirname,
+            "tex_grad-{mode}-{dimensions}-{coord}".format(
+                mode=params.mode,
+                dimensions=params.dimensions,
+                coord=params.coord))
+
+        for stage in ['frag', 'vert']:
+            print('{}.{}'.format(name, stage))
+            with open('{}.{}'.format(name, stage), 'w+') as f:
+                f.write(TEMPLATES.get_template(
+                    'tex_grad.{}.mako'.format(stage)).render_unicode(
+                        param=params,
+                        extensions=get_extensions(params.mode)))
 
 
 if __name__ == '__main__':
diff --git a/generated_tests/templates/gen_texture_lod_tests/frag_lod.glsl_parser_test.mako b/generated_tests/templates/gen_texture_lod_tests/frag_lod.glsl_parser_test.mako
new file mode 100644
index 0000000..3c3df9c
--- /dev/null
+++ b/generated_tests/templates/gen_texture_lod_tests/frag_lod.glsl_parser_test.mako
@@ -0,0 +1,16 @@
+/* [config]
+ * expect_result: pass
+ * glsl_version: 1.10
+ * require_extensions: GL_ARB_shader_texture_lod
+ * [end config]
+ */
+#extension GL_ARB_shader_texture_lod : require
+
+uniform sampler${param.dimensions} s;
+varying ${param.coord} coord;
+varying float lod;
+
+void main()
+{
+  gl_FragColor = ${param.mode}Lod(s, coord, lod);
+}
diff --git a/generated_tests/templates/gen_texture_lod_tests/tex_grad.frag.mako b/generated_tests/templates/gen_texture_lod_tests/tex_grad.frag.mako
new file mode 100644
index 0000000..d807c83
--- /dev/null
+++ b/generated_tests/templates/gen_texture_lod_tests/tex_grad.frag.mako
@@ -0,0 +1,17 @@
+/* [config]
+ * expect_result: pass
+ * glsl_version: 1.10
+ * require_extensions: ${extensions}
+ * [end config]
+ */
+#extension GL_ARB_shader_texture_lod : require
+
+uniform sampler${param.dimensions} s;
+varying ${param.coord} coord;
+varying ${param.grad} dPdx;
+varying ${param.grad} dPdy;
+
+void main()
+{
+  gl_FragColor = ${param.mode}GradARB(s, coord, dPdx, dPdy);
+}
diff --git a/generated_tests/templates/gen_texture_lod_tests/tex_grad.vert.mako b/generated_tests/templates/gen_texture_lod_tests/tex_grad.vert.mako
new file mode 100644
index 0000000..7d7aef3
--- /dev/null
+++ b/generated_tests/templates/gen_texture_lod_tests/tex_grad.vert.mako
@@ -0,0 +1,20 @@
+/* [config]
+ * expect_result: pass
+ * glsl_version: 1.10
+ * require_extensions: ${extensions}
+ * [end config]
+ */
+#extension GL_ARB_shader_texture_lod : require
+
+uniform sampler${param.dimensions} s;
+attribute vec4 pos;
+attribute ${param.coord} coord;
+attribute ${param.grad} dPdx;
+attribute ${param.grad} dPdy;
+varying vec4 color;
+
+void main()
+{
+  gl_Position = pos;
+  color = ${param.mode}GradARB(s, coord, dPdx, dPdy);
+}
-- 
2.1.3



More information about the Piglit mailing list