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
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."""
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])
53 feature_dir
= 'glsl-{}.{}'.format(ver
[0], ver
[1:])
55 return os
.path
.join('spec', feature_dir
, 'compiler',
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(
72 '{}{}{}{}-{}{}.frag'.format(mode
,
73 '-interface_block' if interface_block
else '',
74 '-struct' if struct
else '',
75 '-array' if array
else '',
77 '-bad' if mode
!= 'flat' else ''))
82 with
open(filename
, 'w') as test_file
:
83 test_file
.write(TEMPLATES
.get_template(
84 'template.frag.mako').render_unicode(
88 interface_block
=interface_block
,
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]
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
,
114 if ver
.endswith(' es'):
115 # There is no "noperspective" interpolation mode in GLSL ES
116 if mode
== 'noperspective':
118 # There is no support for arrays in input structs in GLSL ES
121 # Input interface blocks didn't appear in GLSL until 1.50
122 if interface_block
and ver
== '130':
124 # Input interface blocks didn't appear in GLSL ES until 3.20
125 if interface_block
and ver
== '300 es':
127 # Input structs weren't allowed until 1.50
128 if struct
and ver
== '130':
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
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
,
145 + list(create_tests(DOUBLE_TYPES
,
146 ['GL_ARB_gpu_shader_fp64', '400'],
154 parser
= argparse
.ArgumentParser(
155 description
="Generate non-flat interpolation qualifier tests with fp64 types")
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
):
168 if __name__
== '__main__':