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."""
27 from templates
import template_dir
28 from modules
.utils
import lazy_property
, safe_makedirs
30 TEMPLATES
= template_dir(os
.path
.basename(os
.path
.splitext(__file__
)[0]))
31 FS_TEMPLATE
= TEMPLATES
.get_template('fs.shader_test.mako')
32 VS_TEMPLATE
= TEMPLATES
.get_template('vs.shader_test.mako')
33 DIRNAME
= os
.path
.join('spec', 'glsl-{}', 'execution', 'variable-indexing')
36 class TestParams(object):
37 """Parameters for a single test.
39 This is all of the non-formatting logic of the test. Each property is
40 wrapped with a lazy_property decorator, which means the data is cached
41 after it is calculated once.
44 def __init__(self
, matrix_dim
, array_dim
, mode
, index_value
, col
,
45 expect_type
, glsl_version
):
46 self
.matrix_dim
= matrix_dim
47 self
.array_dim
= array_dim
49 self
.index_value
= index_value
51 self
.expect_type
= expect_type
53 assert glsl_version
in [110, 120]
54 self
.glsl_version
= glsl_version
58 if self
.array_dim
!= 0:
59 return '[{}]'.format(self
.index_value
)
65 return 'mat{0}x{0}'.format(self
.matrix_dim
)
69 if self
.glsl_version
== 120:
72 return 'mat{}'.format(self
.matrix_dim
)
76 if self
.array_dim
!= 0 and self
.glsl_version
== 120:
77 return '{}[{}]'.format(self
.base_type
, self
.array_dim
)
83 if self
.array_dim
!= 0 and self
.glsl_version
== 110:
84 return '[{}]'.format(self
.array_dim
)
86 # XXX: should this be an error?
91 if self
.expect_type
== 'float':
94 # XXX: Should this be an error?
99 return '[{}]'.format(self
.__col
)
102 def test_sizes(self
):
103 if self
.array_dim
== 0:
105 elif self
.index_value
== 'index':
106 return list(range(1, 1 + self
.array_dim
))
111 def test_columns(self
):
112 if self
.col
== '[col]':
113 return list(range(1, 1 + self
.matrix_dim
))
119 if self
.expect_type
== 'float':
120 return list(range(1, 1 + self
.matrix_dim
))
125 def test_array_dim(self
):
126 if (self
.mode
== 'uniform' and
127 self
.glsl_version
== 110 and
128 self
.array_dim
!= 0 and
129 self
.index_value
!= 'index'):
130 return self
.index_value
+ 1
132 return self
.array_dim
135 def varying_comps(self
):
136 if self
.array_dim
!= 0:
137 return 4 + self
.matrix_dim
**2 * self
.array_dim
139 return 4 + self
.matrix_dim
**2
142 def formated_version(self
):
143 return '{:.2f}'.format(float(self
.glsl_version
) / 100)
146 def make_fs(name
, params
):
147 """Generate a fragment shader test."""
148 dirname
= DIRNAME
.format(params
.formated_version
)
149 safe_makedirs(dirname
)
150 with
open(os
.path
.join(dirname
, name
), 'w') as f
:
151 f
.write(FS_TEMPLATE
.render_unicode(params
=params
))
155 def make_vs(name
, params
):
156 """Generate a vertex shader test."""
157 dirname
= DIRNAME
.format(params
.formated_version
)
158 safe_makedirs(dirname
)
159 with
open(os
.path
.join(dirname
, name
), 'w') as f
:
160 f
.write(VS_TEMPLATE
.render_unicode(params
=params
))
165 """Generate the tests."""
166 modes
= ['temp', 'uniform', 'varying']
168 matrix_dims
= [2, 3, 4]
169 glsl_versions
= [110, 120]
171 stages
= ['fs', 'vs']
172 iter_
= itertools
.product(stages
, modes
, array_dims
, matrix_dims
,
174 for stage
, mode
, array_dim
, matrix_dim
, glsl_version
, col
in iter_
:
180 for expect
in ['float', 'vec{}'.format(matrix_dim
)]:
186 '{stage}-{mode}-{arr}mat{matrix_dim}-{col}{row}rd.shader_test'.format(
190 matrix_dim
=matrix_dim
,
191 col
='col-' if col
== 'col' else '',
192 row
='row-' if expect
== 'float' else ''),
193 TestParams(matrix_dim
, array_dim
, mode
, 1, col
, expect
,
200 '{stage}-{mode}-{arr}mat{matrix_dim}-{idx_text}{col}{row}rd.shader_test'.format(
204 matrix_dim
=matrix_dim
,
206 col
='col-' if col
== 'col' else '',
207 row
='row-' if expect
== 'float' else ''),
208 TestParams(matrix_dim
, array_dim
, mode
, 'index', col
, expect
,
212 if __name__
== '__main__':