2 # Copyright (c) 2015 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 """Generate tests for glsl 1.10 and 1.20 variable index reads."""
28 from mako
import exceptions
30 from templates
import template_dir
31 from modules
.utils
import lazy_property
, safe_makedirs
33 TEMPLATES
= template_dir(os
.path
.basename(os
.path
.splitext(__file__
)[0]))
34 FS_TEMPLATE
= TEMPLATES
.get_template('fs.shader_test.mako')
35 VS_TEMPLATE
= TEMPLATES
.get_template('vs.shader_test.mako')
36 DIRNAME
= os
.path
.join('spec', 'glsl-{}', 'execution', 'variable-indexing')
39 class TestParams(object):
40 """Parameters for a single test.
42 This is all of the non-formatting logic of the test. Each property is
43 wrapped with a lazy_property decorator, which means the data is cached
44 after it is calculated once.
47 def __init__(self
, matrix_dim
, array_dim
, mode
, index_value
, col
,
48 expect_type
, glsl_version
):
49 self
.matrix_dim
= matrix_dim
50 self
.array_dim
= array_dim
52 self
.index_value
= index_value
54 self
.expect_type
= expect_type
56 assert glsl_version
in [110, 120]
57 self
.glsl_version
= glsl_version
61 if self
.array_dim
!= 0:
62 return '[{}]'.format(self
.index_value
)
68 return 'mat{0}x{0}'.format(self
.matrix_dim
)
72 if self
.glsl_version
== 120:
75 return 'mat{}'.format(self
.matrix_dim
)
79 if self
.array_dim
!= 0 and self
.glsl_version
== 120:
80 return '{}[{}]'.format(self
.base_type
, self
.array_dim
)
86 if self
.array_dim
!= 0 and self
.glsl_version
== 110:
87 return '[{}]'.format(self
.array_dim
)
89 # XXX: should this be an error?
94 if self
.expect_type
== 'float':
97 # XXX: Should this be an error?
102 return '[{}]'.format(self
.__col
)
105 def test_sizes(self
):
106 if self
.array_dim
== 0:
108 elif self
.index_value
== 'index':
109 return list(range(1, 1 + self
.array_dim
))
114 def test_columns(self
):
115 if self
.col
== '[col]':
116 return list(range(1, 1 + self
.matrix_dim
))
122 if self
.expect_type
== 'float':
123 return list(range(1, 1 + self
.matrix_dim
))
128 def test_array_dim(self
):
129 if (self
.mode
== 'uniform' and
130 self
.glsl_version
== 110 and
131 self
.array_dim
!= 0 and
132 self
.index_value
!= 'index'):
133 return self
.index_value
+ 1
135 return self
.array_dim
138 def varying_comps(self
):
139 if self
.array_dim
!= 0:
140 return 4 + self
.matrix_dim
**2 * self
.array_dim
142 return 4 + self
.matrix_dim
**2
145 def formated_version(self
):
146 return '{:.2f}'.format(float(self
.glsl_version
) / 100)
149 def make_fs(name
, params
):
150 """Generate a fragment shader test."""
151 dirname
= DIRNAME
.format(params
.formated_version
)
152 safe_makedirs(dirname
)
153 with
open(os
.path
.join(dirname
, name
), 'w') as f
:
155 f
.write(FS_TEMPLATE
.render_unicode(params
=params
))
157 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
162 def make_vs(name
, params
):
163 """Generate a vertex shader test."""
164 dirname
= DIRNAME
.format(params
.formated_version
)
165 safe_makedirs(dirname
)
166 with
open(os
.path
.join(dirname
, name
), 'w') as f
:
168 f
.write(VS_TEMPLATE
.render_unicode(params
=params
))
170 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
176 """Generate the tests."""
177 modes
= ['temp', 'uniform', 'varying']
179 matrix_dims
= [2, 3, 4]
180 glsl_versions
= [110, 120]
182 stages
= ['fs', 'vs']
183 iter_
= itertools
.product(stages
, modes
, array_dims
, matrix_dims
,
185 for stage
, mode
, array_dim
, matrix_dim
, glsl_version
, col
in iter_
:
191 for expect
in ['float', 'vec{}'.format(matrix_dim
)]:
197 '{stage}-{mode}-{arr}mat{matrix_dim}-{col}{row}rd.shader_test'.format(
201 matrix_dim
=matrix_dim
,
202 col
='col-' if col
== 'col' else '',
203 row
='row-' if expect
== 'float' else ''),
204 TestParams(matrix_dim
, array_dim
, mode
, 1, col
, expect
,
211 '{stage}-{mode}-{arr}mat{matrix_dim}-{idx_text}{col}{row}rd.shader_test'.format(
215 matrix_dim
=matrix_dim
,
217 col
='col-' if col
== 'col' else '',
218 row
='row-' if expect
== 'float' else ''),
219 TestParams(matrix_dim
, array_dim
, mode
, 'index', col
, expect
,
223 if __name__
== '__main__':