[Piglit] [PATCH 07/21] gen_uniform_initializer_tests templates: minor cleanups and refactors
Dylan Baker
baker.dylan.c at gmail.com
Mon Nov 24 13:17:26 PST 2014
This patch changes some of the implementation details of the templates.
These can be changes can be broken down into two types,
using mako features:
- converting from ${'{}.{}'.format(a, b)} to ${a}.${b}
making the code more pythonic and less C-like
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
.../fs-initializer-from-const.shader_test.mako | 12 ++++++------
.../fs-initializer-set-by-API.shader_test.mako | 18 ++++++++----------
.../fs-initializer-set-by-other-stage.shader_test.mako | 12 ++++++------
.../fs-initializer.shader_test.mako | 8 ++++----
.../vs-initializer-from-const.shader_test.mako | 12 ++++++------
.../vs-initializer-set-by-API.shader_test.mako | 18 ++++++++----------
.../vs-initializer-set-by-other-stage.shader_test.mako | 12 ++++++------
.../vs-initializer.shader_test.mako | 8 ++++----
8 files changed, 48 insertions(+), 52 deletions(-)
diff --git a/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-from-const.shader_test.mako b/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-from-const.shader_test.mako
index 29f10ed..3f869d8 100644
--- a/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-from-const.shader_test.mako
+++ b/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-from-const.shader_test.mako
@@ -1,5 +1,5 @@
[require]
-GLSL >= ${"{0}.{1}".format(major, minor)}
+GLSL >= ${major}.${minor}
[vertex shader]
@@ -10,17 +10,17 @@ void main()
[fragment shader]
-% for (type, name, value) in type_list:
-const ${type} c${name} = ${value};
+% for type_, name, value in type_list:
+const ${type_} c${name} = ${value};
% endfor
-% for (type, name, value) in type_list:
-uniform ${type} ${name} = c${name};
+% for type_, name, value in type_list:
+uniform ${type_} ${name} = c${name};
% endfor
void main()
{
- if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
+ if (${" && ".join('{0} == {1}'.format(n, v) for _, n, v in type_list)}) {
gl_FragColor = vec4(0, 1, 0, 1);
} else {
gl_FragColor = vec4(1, 0, 0, 1);
diff --git a/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-set-by-API.shader_test.mako b/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-set-by-API.shader_test.mako
index 415df81..8e94633 100644
--- a/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-set-by-API.shader_test.mako
+++ b/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-set-by-API.shader_test.mako
@@ -1,9 +1,5 @@
-<%!
-def constructor(type, values):
- return "{0}({1})".format(type, ", ".join(values))
-
-%>[require]
-GLSL >= ${"{0}.{1}".format(major, minor)}
+[require]
+GLSL >= ${major}.${minor}
[vertex shader]
@@ -14,13 +10,15 @@ void main()
[fragment shader]
-% for (type, name, value) in type_list:
-uniform ${type} ${name} = ${value};
+% for type_, name, value in type_list:
+uniform ${type_} ${name} = ${value};
% endfor
void main()
{
- if (${"\n && ".join('{0} == {1}'.format(type_list[i][1], constructor(type_list[i][0], api_types[i][2])) for i in range(1, len(type_list) - 1))}) {
+ ## This is a little bit complex too look at, but it's actually pretty simple.
+ ## What it does is use the name and type values from type_list, but the values from api_types
+ if (${' && '.join('{0} == {1}({2})'.format(n, t, ', '.join(api_types[i][2])) for i, (t, n, _) in enumerate(type_list[1:-1], start=1))}) {
gl_FragColor = vec4(0, 1, 0, 1);
} else {
gl_FragColor = vec4(1, 0, 0, 1);
@@ -28,7 +26,7 @@ void main()
}
[test]
-% for (api_type, name, values) in api_types:
+% for api_type, name, values in api_types:
uniform ${api_type} ${name} ${" ".join(values)}
% endfor
draw rect -1 -1 2 2
diff --git a/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-set-by-other-stage.shader_test.mako b/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-set-by-other-stage.shader_test.mako
index 626f6b5..6a78096 100644
--- a/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-set-by-other-stage.shader_test.mako
+++ b/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer-set-by-other-stage.shader_test.mako
@@ -1,10 +1,10 @@
[require]
-GLSL >= ${"{0}.{1}".format(major, minor)}
+GLSL >= ${major}.${minor}
[vertex shader]
-% for (type, name, value) in type_list:
-uniform ${type} ${name} = ${value};
+% for type_, name, value in type_list:
+uniform ${type_} ${name} = ${value};
% endfor
void main()
@@ -14,13 +14,13 @@ void main()
[fragment shader]
-% for (type, name, value) in type_list:
-uniform ${type} ${name};
+% for type_, name, value in type_list:
+uniform ${type_} ${name};
% endfor
void main()
{
- if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
+ if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
gl_FragColor = vec4(0, 1, 0, 1);
} else {
gl_FragColor = vec4(1, 0, 0, 1);
diff --git a/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer.shader_test.mako b/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer.shader_test.mako
index a4f84af..d6f5fb0 100644
--- a/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer.shader_test.mako
+++ b/generated_tests/templates/gen_uniform_initializer_tests/fs-initializer.shader_test.mako
@@ -1,5 +1,5 @@
[require]
-GLSL >= ${"{0}.{1}".format(major, minor)}
+GLSL >= ${major}.${minor}
[vertex shader]
@@ -10,13 +10,13 @@ void main()
[fragment shader]
-% for (type, name, value) in type_list:
-uniform ${type} ${name} = ${value};
+% for type_, name, value in type_list:
+uniform ${type_} ${name} = ${value};
% endfor
void main()
{
- if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
+ if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
gl_FragColor = vec4(0, 1, 0, 1);
} else {
gl_FragColor = vec4(1, 0, 0, 1);
diff --git a/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-from-const.shader_test.mako b/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-from-const.shader_test.mako
index bbb6c66..e2c3be8 100644
--- a/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-from-const.shader_test.mako
+++ b/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-from-const.shader_test.mako
@@ -1,20 +1,20 @@
[require]
-GLSL >= ${"{0}.{1}".format(major, minor)}
+GLSL >= ${major}.${minor}
[vertex shader]
varying vec4 color;
-% for (type, name, value) in type_list:
-const ${type} c${name} = ${value};
+% for type_, name, value in type_list:
+const ${type_} c${name} = ${value};
% endfor
-% for (type, name, value) in type_list:
-uniform ${type} ${name} = c${name};
+% for type_, name, value in type_list:
+uniform ${type_} ${name} = c${name};
% endfor
void main()
{
- if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
+ if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
color = vec4(0, 1, 0, 1);
} else {
color = vec4(1, 0, 0, 1);
diff --git a/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-set-by-API.shader_test.mako b/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-set-by-API.shader_test.mako
index 458e711..ca56ec5 100644
--- a/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-set-by-API.shader_test.mako
+++ b/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-set-by-API.shader_test.mako
@@ -1,20 +1,18 @@
-<%!
-def constructor(type, values):
- return "{0}({1})".format(type, ", ".join(values))
-
-%>[require]
-GLSL >= ${"{0}.{1}".format(major, minor)}
+[require]
+GLSL >= ${major}.${minor}
[vertex shader]
varying vec4 color;
-% for (type, name, value) in type_list:
-uniform ${type} ${name} = ${value};
+% for type_, name, value in type_list:
+uniform ${type_} ${name} = ${value};
% endfor
void main()
{
- if (${"\n && ".join('{0} == {1}'.format(type_list[i][1], constructor(type_list[i][0], api_types[i][2])) for i in range(1, len(type_list) - 1))}) {
+ ## This is a little bit complex too look at, but it's actually pretty simple.
+ ## What it does is use the name and type values from type_list, but the values from api_types
+ if (${' && '.join('{0} == {1}({2})'.format(n, t, ', '.join(api_types[i][2])) for i, (t, n, _) in enumerate(type_list[1:-1], start=1))}) {
color = vec4(0, 1, 0, 1);
} else {
color = vec4(1, 0, 0, 1);
@@ -32,7 +30,7 @@ void main()
}
[test]
-% for (api_type, name, values) in api_types:
+% for api_type, name, values in api_types:
uniform ${api_type} ${name} ${" ".join(values)}
% endfor
draw rect -1 -1 2 2
diff --git a/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-set-by-other-stage.shader_test.mako b/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-set-by-other-stage.shader_test.mako
index 6f337d5..d00b37d 100644
--- a/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-set-by-other-stage.shader_test.mako
+++ b/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer-set-by-other-stage.shader_test.mako
@@ -1,16 +1,16 @@
[require]
-GLSL >= ${"{0}.{1}".format(major, minor)}
+GLSL >= ${major}.${minor}
[vertex shader]
varying vec4 color;
-% for (type, name, value) in type_list:
-uniform ${type} ${name};
+% for type_, name, _ in type_list:
+uniform ${type_} ${name};
% endfor
void main()
{
- if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
+ if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
color = vec4(0, 1, 0, 1);
} else {
color = vec4(1, 0, 0, 1);
@@ -22,8 +22,8 @@ void main()
[fragment shader]
varying vec4 color;
-% for (type, name, value) in type_list:
-uniform ${type} ${name} = ${value};
+% for type_, name, value in type_list:
+uniform ${type_} ${name} = ${value};
% endfor
void main()
diff --git a/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer.shader_test.mako b/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer.shader_test.mako
index 94442da..4a24795 100644
--- a/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer.shader_test.mako
+++ b/generated_tests/templates/gen_uniform_initializer_tests/vs-initializer.shader_test.mako
@@ -1,16 +1,16 @@
[require]
-GLSL >= ${"{0}.{1}".format(major, minor)}
+GLSL >= ${major}.${minor}
[vertex shader]
varying vec4 color;
-% for (type, name, value) in type_list:
-uniform ${type} ${name} = ${value};
+% for type_, name, value in type_list:
+uniform ${type_} ${name} = ${value};
% endfor
void main()
{
- if (${"\n && ".join('{0} == {1}'.format(name, value) for type, name, value in type_list)}) {
+ if (${" && ".join('{0} == {1}'.format(name, value) for _, name, value in type_list)}) {
color = vec4(0, 1, 0, 1);
} else {
color = vec4(1, 0, 0, 1);
--
2.1.3
More information about the Piglit
mailing list