[Piglit] [PATCH 19/45] gen_shader_bit_encoding_tests.py: minor refactors
Dylan Baker
baker.dylan.c at gmail.com
Wed Nov 12 15:46:01 PST 2014
Makes two changes:
- Use a namedtuple instead of a dictionary to represent functions (the
sub elements of the funcs dict). This reduces the number of variables
passed into the mako template
- convert funcs into a set of tuples. Since the dictionary is never
actually used as a dictionary (ie, to select a key's associated
value), it is faster to use tuples.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
generated_tests/gen_shader_bit_encoding_tests.py | 48 +++++++---------------
.../template.shader_test.mako | 12 +++---
2 files changed, 20 insertions(+), 40 deletions(-)
diff --git a/generated_tests/gen_shader_bit_encoding_tests.py b/generated_tests/gen_shader_bit_encoding_tests.py
index 5cfb274..cbed383 100644
--- a/generated_tests/gen_shader_bit_encoding_tests.py
+++ b/generated_tests/gen_shader_bit_encoding_tests.py
@@ -24,6 +24,7 @@
from __future__ import print_function
import struct
import os
+import collections
from operator import neg
from templates import template_file
@@ -51,6 +52,10 @@ def vec4(f):
return [f, f, f, f]
+Functions = collections.namedtuple(
+ 'Functions', ['in_func', 'out_func', 'input_type', 'output_type'])
+
+
# Don't test +inf or -inf, since we don't have a way to pass them via
# shader_runner [test] sections. Don't test NaN, since it has many
# representations. Don't test subnormal values, since hardware might
@@ -74,30 +79,13 @@ test_data = {
# output (expected) data to pass the shader.
funcs = {
- 'floatBitsToInt': {
- 'in_func': lambda x: x,
- 'out_func': floatbitstoint,
- 'input': 'vec4',
- 'output': 'ivec4'
- },
- 'floatBitsToUint': {
- 'in_func': lambda x: x,
- 'out_func': floatbitstouint,
- 'input': 'vec4',
- 'output': 'uvec4'
- },
- 'intBitsToFloat': {
- 'in_func': floatbitstoint,
- 'out_func': intbitstofloat,
- 'input': 'ivec4',
- 'output': 'vec4'
- },
- 'uintBitsToFloat': {
- 'in_func': floatbitstouint,
- 'out_func': uintbitstofloat,
- 'input': 'uvec4',
- 'output': 'vec4'
- }
+ ('floatBitsToInt', Functions(lambda x: x, floatbitstoint, 'vec4', 'ivec4')),
+ ('floatBitsToUint', Functions(lambda x: x, floatbitstouint, 'vec4',
+ 'uvec4')),
+ ('intBitsToFloat', Functions(floatbitstoint, intbitstofloat, 'ivec4',
+ 'vec4')),
+ ('uintBitsToFloat', Functions(floatbitstouint, uintbitstofloat, 'uvec4',
+ 'vec4'))
}
modifier_funcs = {
@@ -129,12 +117,7 @@ def main():
version = requirement['version']
extensions = [requirement['extension']] if requirement['extension'] else []
- for func, attrib in funcs.iteritems():
- in_func = attrib['in_func']
- out_func = attrib['out_func']
- input_type = attrib['input']
- output_type = attrib['output']
-
+ for func, attrib in funcs:
for execution_stage in ('vs', 'fs'):
for in_modifier_func, modifier_func in modifier_funcs.iteritems():
# Modifying the sign of an unsigned number doesn't make sense.
@@ -166,12 +149,9 @@ def main():
extensions=extensions,
execution_stage=execution_stage,
func=func,
+ funcs=attrib,
modifier_func=modifier_func,
in_modifier_func=in_modifier_func,
- in_func=in_func,
- out_func=out_func,
- input_type=input_type,
- output_type=output_type,
test_data=test_data))
diff --git a/generated_tests/templates/gen_shader_bit_encoding_tests/template.shader_test.mako b/generated_tests/templates/gen_shader_bit_encoding_tests/template.shader_test.mako
index 83eb567..75ead4c 100644
--- a/generated_tests/templates/gen_shader_bit_encoding_tests/template.shader_test.mako
+++ b/generated_tests/templates/gen_shader_bit_encoding_tests/template.shader_test.mako
@@ -10,8 +10,8 @@ ${extension}
#extension ${extension}: enable
% endfor
-uniform ${input_type} given;
-uniform ${output_type} expected;
+uniform ${funcs.input_type} given;
+uniform ${funcs.output_type} expected;
out vec4 color;
% endif
@@ -40,8 +40,8 @@ void main() {
#extension ${extension}: enable
% endfor
-uniform ${input_type} given;
-uniform ${output_type} expected;
+uniform ${funcs.input_type} given;
+uniform ${funcs.output_type} expected;
% else:
in vec4 color;
% endif
@@ -78,8 +78,8 @@ vertex/float/2
# ${in_modifier_func}(INT_MIN) doesn't fit in a 32-bit int. Cannot test.
% else:
# ${name}
-uniform ${input_type} given ${' '.join(str(in_func(d)) for d in data)}
-uniform ${output_type} expected ${' '.join(str(out_func(modifier_func(in_func(d)))) for d in data)}
+uniform ${funcs.input_type} given ${' '.join(str(funcs.in_func(d)) for d in data)}
+uniform ${funcs.output_type} expected ${' '.join(str(funcs.out_func(modifier_func(funcs.in_func(d)))) for d in data)}
draw arrays GL_TRIANGLE_FAN 0 4
probe all rgba 0.0 1.0 0.0 1.0
% endif
--
2.1.3
More information about the Piglit
mailing list