[Piglit] [PATCH 16/45] gen_shader_bit_encoding: cleanup some style issues

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


Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/gen_shader_bit_encoding_tests.py | 142 ++++++++++++-----------
 1 file changed, 76 insertions(+), 66 deletions(-)

diff --git a/generated_tests/gen_shader_bit_encoding_tests.py b/generated_tests/gen_shader_bit_encoding_tests.py
index 84b9390..d409db0 100644
--- a/generated_tests/gen_shader_bit_encoding_tests.py
+++ b/generated_tests/gen_shader_bit_encoding_tests.py
@@ -29,31 +29,42 @@ from templates import template_file
 TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
                          'template.shader_test.mako')
 
-
-def floatBitsToInt(f):
+def floatbitstoint(f):
     return struct.unpack('i', struct.pack('f', f))[0]
 
-def floatBitsToUint(f):
+
+def floatbitstouint(f):
     return struct.unpack('I', struct.pack('f', f))[0]
 
-def intBitsToFloat(i):
+
+def intbitstofloat(i):
     return struct.unpack('f', struct.pack('i', i))[0]
 
-def uintBitsToFloat(u):
+
+def uintbitstofloat(u):
     return struct.unpack('f', struct.pack('I', u))[0]
 
+
 def passthrough(f):
     return f
 
+
 def neg(num):
     return -num
 
+
 def neg_abs(num):
     return -abs(num)
 
+
 def vec4(f):
     return [f, f, f, f]
 
+
+# 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
+# flush them to zero.
 test_data = {
     # Interesting floating-point inputs
     'mixed':                        (2.0, 9.5, -4.5, -25.0),
@@ -65,11 +76,6 @@ test_data = {
     'normalized smallest negative': vec4(-1.1754944e-38),
     'normalized largest':           vec4( 3.4028235e+38),
     'normalized largest negative':  vec4(-3.4028235e+38)
-
-    # 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
-    # flush them to zero.
 }
 
 # in_func: Function to convert floating-point data in test_data (above) into
@@ -80,25 +86,25 @@ test_data = {
 funcs = {
     'floatBitsToInt': {
         'in_func':  passthrough,
-        'out_func': floatBitsToInt,
+        'out_func': floatbitstoint,
         'input':    'vec4',
         'output':   'ivec4'
     },
     'floatBitsToUint': {
         'in_func':  passthrough,
-        'out_func': floatBitsToUint,
+        'out_func': floatbitstouint,
         'input':    'vec4',
         'output':   'uvec4'
     },
     'intBitsToFloat': {
-        'in_func':  floatBitsToInt,
-        'out_func': intBitsToFloat,
+        'in_func':  floatbitstoint,
+        'out_func': intbitstofloat,
         'input':    'ivec4',
         'output':   'vec4'
     },
     'uintBitsToFloat': {
-        'in_func':  floatBitsToUint,
-        'out_func': uintBitsToFloat,
+        'in_func':  floatbitstouint,
+        'out_func': uintbitstofloat,
         'input':    'uvec4',
         'output':   'vec4'
     }
@@ -127,53 +133,57 @@ requirements = {
 }
 
 
-for api, requirement in requirements.iteritems():
-    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 execution_stage in ('vs', 'fs'):
-            file_extension = 'frag' if execution_stage == 'fs' else 'vert'
-
-            for in_modifier_func, modifier_func in modifier_funcs.iteritems():
-                # Modifying the sign of an unsigned number doesn't make sense.
-                if func == 'uintBitsToFloat' and in_modifier_func != '':
-                    continue
-
-                modifier_name = '-' + in_modifier_func if in_modifier_func != '' else ''
-                filename = os.path.join('spec',
-                                        api.lower(),
-                                        'execution',
-                                        'built-in-functions',
-                                        "{0}-{1}{2}.shader_test".format(execution_stage,
-                                                                        func,
-                                                                        modifier_name))
-                print filename
-
-                dirname = os.path.dirname(filename)
-                if not os.path.exists(dirname):
-                    os.makedirs(dirname)
-
-                if in_modifier_func == 'neg':
-                    in_modifier_func = '-'
-                elif in_modifier_func == 'neg_abs':
-                    in_modifier_func = '-abs'
-
-                f = open(filename, 'w')
-                f.write(TEMPLATE.render(version=version,
-                                        extensions=extensions,
-                                        execution_stage=execution_stage,
-                                        func=func,
-                                        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))
-                f.close()
+def main():
+    """main function."""
+    for api, requirement in requirements.iteritems():
+        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 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.
+                    if func == 'uintBitsToFloat' and in_modifier_func != '':
+                        continue
+
+                    modifier_name = '-' + in_modifier_func if in_modifier_func != '' else ''
+                    filename = os.path.join(
+                        'spec',
+                        api.lower(),
+                        'execution',
+                        'built-in-functions',
+                        "{0}-{1}{2}.shader_test".format(execution_stage, func,
+                                                        modifier_name))
+                    print filename
+
+                    dirname = os.path.dirname(filename)
+                    if not os.path.exists(dirname):
+                        os.makedirs(dirname)
+
+                    if in_modifier_func == 'neg':
+                        in_modifier_func = '-'
+                    elif in_modifier_func == 'neg_abs':
+                        in_modifier_func = '-abs'
+
+                    f = open(filename, 'w')
+                    f.write(TEMPLATE.render(version=version,
+                                            extensions=extensions,
+                                            execution_stage=execution_stage,
+                                            func=func,
+                                            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))
+                    f.close()
+
+
+if __name__ == '__main__':
+    main()
-- 
2.1.3



More information about the Piglit mailing list