ext_packed_depth_stencil: initialize GLuint array
[piglit.git] / generated_tests / gen_flat_interpolation_qualifier.py
blob2099473bad8994a3fdc54ede59229722bf19f079
1 # coding=utf-8
3 # Copyright © 2016 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
24 """Generate non-flat interpolation qualifier tests."""
26 import argparse
27 import os
28 import itertools
30 from templates import template_dir
31 from modules import utils
33 TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
35 INT_TYPES = ['int', 'ivec2', 'ivec3', 'ivec4']
37 UINT_TYPES = ['uint', 'uvec2', 'uvec3', 'uvec4']
39 DOUBLE_TYPES = ['double', 'dvec2', 'dvec3', 'dvec4',
40 'dmat2', 'dmat2x3', 'dmat2x4',
41 'dmat3x2', 'dmat3', 'dmat3x4',
42 'dmat4x2', 'dmat4x3', 'dmat4']
44 def get_dir_name(ver):
45 """Returns the directory name to save tests given a GLSL version."""
47 assert isinstance(ver, str)
48 if ver.startswith('GL_'):
49 feature_dir = ver[3:].lower()
50 elif ver.endswith(' es'):
51 feature_dir = 'glsl-es-{}.{}'.format(ver[0], ver[1:3])
52 else:
53 feature_dir = 'glsl-{}.{}'.format(ver[0], ver[1:])
55 return os.path.join('spec', feature_dir, 'compiler',
56 'flat_interpolation')
59 def generate(type_name, mode, interface_block, struct, array, ver, names_only):
60 """Generate GLSL parser tests."""
62 assert isinstance(type_name, str)
63 assert isinstance(mode, str)
64 assert isinstance(interface_block, bool)
65 assert isinstance(struct, bool)
66 assert isinstance(array, bool)
67 assert isinstance(ver, str)
68 assert isinstance(names_only, bool)
70 filename = os.path.join(
71 get_dir_name(ver),
72 '{}{}{}{}-{}{}.frag'.format(mode,
73 '-interface_block' if interface_block else '',
74 '-struct' if struct else '',
75 '-array' if array else '',
76 type_name,
77 '-bad' if mode != 'flat' else ''))
79 print(filename)
81 if not names_only:
82 with open(filename, 'w') as test_file:
83 test_file.write(TEMPLATES.get_template(
84 'template.frag.mako').render_unicode(
85 ver=ver,
86 mode=mode,
87 type_name=type_name,
88 interface_block=interface_block,
89 struct=struct,
90 array=array))
93 def create_tests(type_names, glsl_vers, names_only):
94 """Creates combinations for flat qualifier tests."""
96 assert isinstance(type_names, list)
97 assert isinstance(glsl_vers, list)
98 assert isinstance(names_only, bool)
100 modes = ['flat', 'noperspective', 'smooth', 'default']
101 interface_blocks = [True, False]
102 structs = [True, False]
103 arrays = [True, False]
104 if not names_only:
105 for ver in glsl_vers:
106 utils.safe_makedirs(get_dir_name(ver))
108 for t_name, mode, interface_block, struct, array, ver in itertools.product(type_names,
109 modes,
110 interface_blocks,
111 structs,
112 arrays,
113 glsl_vers):
114 if ver.endswith(' es'):
115 # There is no "noperspective" interpolation mode in GLSL ES
116 if mode == 'noperspective':
117 continue
118 # There is no support for arrays in input structs in GLSL ES
119 if struct and array:
120 continue
121 # Input interface blocks didn't appear in GLSL until 1.50
122 if interface_block and ver == '130':
123 ver = '150'
124 # Input interface blocks didn't appear in GLSL ES until 3.20
125 if interface_block and ver == '300 es':
126 ver = '320 es'
127 # Input structs weren't allowed until 1.50
128 if struct and ver == '130':
129 ver = '150'
130 yield t_name, mode, interface_block, struct, array, ver, names_only
133 def all_tests(names_only):
134 """Creates all the combinations for flat qualifier tests."""
136 assert isinstance(names_only, bool)
138 # We need additional directories for GLSL 150 and GLSL ES 320
139 if not names_only:
140 utils.safe_makedirs(get_dir_name('150'))
141 utils.safe_makedirs(get_dir_name('320 es'))
142 for test_args in (list(create_tests(INT_TYPES + UINT_TYPES,
143 ['130', '300 es'],
144 names_only))
145 + list(create_tests(DOUBLE_TYPES,
146 ['GL_ARB_gpu_shader_fp64', '400'],
147 names_only))):
148 yield test_args
151 def main():
152 """Main function."""
154 parser = argparse.ArgumentParser(
155 description="Generate non-flat interpolation qualifier tests with fp64 types")
156 parser.add_argument(
157 '--names-only',
158 dest='names_only',
159 action='store_true',
160 default=False,
161 help="Don't output files, just generate a list of filenames to stdout")
162 args = parser.parse_args()
164 for test_args in all_tests(args.names_only):
165 generate(*test_args)
168 if __name__ == '__main__':
169 main()