summary/html: specify lang="en" in html tag
[piglit.git] / generated_tests / gen_variable_index_write_tests.py
blob15cb7bccf226adc949d4db4de169007e5613d698
1 # coding=utf-8
2 # Copyright (c) 2015-2016 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
20 # SOFTWARE.
22 """Generate tests for variable index writes.
24 This creates a TestParams object for each invocation (using a factory to reduce
25 the number of duplicate objects), and then passes that into a mako template.
26 The template then formats that information into a shader_test for either the
27 fragment shader stage or the vertex shader stage.
29 """
31 from __future__ import (
32 print_function, absolute_import, division, unicode_literals
34 import copy
35 import itertools
36 import os
38 from six.moves import range # pylint: disable=redefined-builtin
40 from modules import utils, glsl
41 from templates import template_dir
43 _TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
44 _VS_TEMPLATE = _TEMPLATES.get_template('vs.shader_test.mako')
45 _FS_TEMPLATE = _TEMPLATES.get_template('fs.shader_test.mako')
46 _DIRNAME = os.path.join('spec', 'glsl-{}', 'execution', 'variable-indexing')
49 class TestParams(object):
50 """Object representing all of the parameters of a single test instance.
52 Provides all of the values using lazy properties, which tie in with the
53 ParamsFactory to store all of the values, speeding up run times.
55 """
56 def __init__(self, mode, array_dim, matrix_dim, index_value, col,
57 value_type, glsl_version):
58 # pylint: disable=too-many-arguments
59 assert array_dim in [0, 3]
60 assert matrix_dim in [2, 3, 4]
62 self.mode = mode
63 self.array_dim = array_dim
64 self.matrix_dim = matrix_dim
65 self.index_value = index_value
66 self.col = '[{}]'.format(col)
67 self.value_type = value_type
68 self.version = glsl.Version(glsl_version)
70 @utils.lazy_property
71 def varying_comps(self):
72 if self.array_dim != 0:
73 return self.matrix_dim**2 * self.array_dim
74 else:
75 return self.matrix_dim**2
77 @utils.lazy_property
78 def base_type(self):
79 if int(self.version) >= 120:
80 return 'mat{0}x{0}'.format(self.matrix_dim)
81 else:
82 return 'mat{}'.format(self.matrix_dim)
84 @utils.lazy_property
85 def type(self):
86 if self.array_dim != 0 and int(self.version) >= 120:
87 return '{}[{}]'.format(self.base_type, self.array_dim)
88 else:
89 return self.base_type
91 @utils.lazy_property
92 def dim(self):
93 if self.array_dim != 0 and int(self.version) < 120:
94 return '[{}]'.format(self.array_dim)
95 else:
96 return ''
98 @utils.lazy_property
99 def row(self):
100 if self.value_type == 'float':
101 return '[row]'
102 else:
103 return ''
105 @utils.lazy_property
106 def idx(self):
107 if self.array_dim != 0:
108 return '[{}]'.format(self.index_value)
109 else:
110 return ''
112 @utils.lazy_property
113 def test_vec(self):
114 if self.matrix_dim == 2:
115 return ["0.803161418975390", "0.852987140792140"]
116 elif self.matrix_dim == 3:
117 return ["0.681652305322399", "0.210426138878113",
118 "0.185916924650237"]
119 elif self.matrix_dim == 4:
120 return ["0.0394868046587045", "0.8922408276905568",
121 "0.3337495624366961", "0.8732295730825839"]
123 @utils.lazy_property
124 def test_exp(self):
125 if self.matrix_dim == 2:
126 return ["0.708718134966688", "1.452243795483797"]
127 elif self.matrix_dim == 3:
128 return ["0.610649606928364", "0.711906885823636",
129 "0.312244778977868"]
130 elif self.matrix_dim == 4:
131 return ["1.03935908892461", "1.18846180713529", "1.10078681232072",
132 "1.72434439561820"]
134 @utils.lazy_property
135 def test_mat(self):
136 if self.matrix_dim == 2:
137 return [["0.241498998195656", "0.861223395812970"],
138 ["0.603473877011433", "0.891622340451180"]]
139 elif self.matrix_dim == 3:
140 return [
141 ["0.493944462129466", "0.722190133917966", "0.239853948232558"],
142 ["0.550143078409278", "0.591962645398579", "0.467616286531193"],
143 ["0.850846377186973", "0.511303112962423", "0.270815003356504"]
145 elif self.matrix_dim == 4:
146 return [["0.922040144261674", "0.158053783109488",
147 "0.357016429866574", "0.836368810383957"],
148 ["0.560251913703792", "0.171634921595771",
149 "0.602494709909111", "0.693273570571311"],
150 ["0.350720358904176", "0.912192627475775",
151 "0.688544081259531", "0.913891056231967"],
152 ["0.442058176039301", "0.829835836794679",
153 "0.365674411003021", "0.879197364462782"]]
155 @utils.lazy_property
156 def test_sizes(self):
157 if self.array_dim == 0:
158 return [1]
159 elif self.index_value == 'index':
160 return list(range(1, self.array_dim + 1))
161 else:
162 return [2]
164 @utils.lazy_property
165 def test_columns(self):
166 if self.col == '[col]':
167 return list(range(1, self.matrix_dim + 1))
168 return [2]
170 @utils.lazy_property
171 def test_rows(self):
172 if self.value_type == 'float':
173 return list(range(1, self.matrix_dim + 1))
174 return [1]
176 @utils.lazy_property
177 def test_type(self):
178 # shader_runner always uses matDxD format
179 return 'mat{0}x{0}'.format(self.matrix_dim)
181 def test_matrix(self, column, row):
182 """Generate the matrix used in a test section.
184 This will take the matrix used by the test, and replace specific values
185 with sentinal values, and return the matrix as a string.
188 bad = ['666.0', '777.0', '888.0', '999.0']
189 mat = copy.deepcopy(self.test_mat)
191 if self.value_type == 'float':
192 mat[column][row] = bad[0]
193 else:
194 mat[column] = bad[0:self.matrix_dim]
196 ret = ''
197 for c in mat:
198 ret += ' '.join(c)
199 ret += ' '
200 return ret
202 @utils.lazy_property
203 def formated_version(self):
204 # Note: GLSLVersion.float() does division by 100
205 return '{:.2f}'.format(float(self.version))
208 class ParamsFactory(object): # pylint: disable=too-few-public-methods
209 """A factory class that provides TestParam objects.
211 This cuts the number of new objects created by roughly 3/5.
214 def __init__(self):
215 self.__stored = {}
217 def get(self, *args):
218 args = tuple(args)
219 try:
220 return self.__stored[args]
221 except KeyError:
222 params = TestParams(*args)
223 self.__stored[args] = params
224 return params
227 def make_vs(name, params):
228 """Create a vertex shader test."""
229 dirname = _DIRNAME.format(params.formated_version)
230 utils.safe_makedirs(dirname)
231 with open(os.path.join(dirname, name), 'w') as f:
232 f.write(_VS_TEMPLATE.render_unicode(params=params))
233 print(name)
236 def make_fs(name, params):
237 """Create a fragment shader test."""
238 dirname = _DIRNAME.format(params.formated_version)
239 utils.safe_makedirs(dirname)
240 with open(os.path.join(dirname, name), 'w') as f:
241 f.write(_FS_TEMPLATE.render_unicode(params=params))
242 print(name)
245 def main():
246 """The main function."""
247 # Various choices that can be put together to produce a single test.
248 iter_ = itertools.product(
249 ['110', '120'], # GLSL versions
250 [0, 3], # Array dimensions
251 [2, 3, 4], # Matrix dimensions
252 ['varying', 'temp'], # modes
253 ['col', 1], # columns
254 ['fs', 'vs'], # shader stages
257 factory = ParamsFactory()
259 # This can be filled in to produce the file name for the test.
260 # Note that idx, col, row, and arr will need to have a '-' added to the end
261 # of the value if it is not empty
262 name = '{stage}-{mode}-{arr}mat{matrix_dim}-{idx}{col}{row}wr.shader_test'
264 for v, a, d, m, c, s in iter_:
265 for t in ['float', 'vec{}'.format(d)]:
266 if s == 'vs':
267 func = make_vs
268 elif s == 'fs':
269 if m == 'varying':
270 # Fragment shaders cannot write varyings
271 continue
272 func = make_fs
274 if a != 0:
275 arr = 'array-'
277 func(
278 name.format(stage=s,
279 mode=m,
280 matrix_dim=d,
281 arr=arr,
282 idx='',
283 col='col-' if c == 'col' else '',
284 row='row-' if t == 'float' else ''),
285 factory.get(m, a, d, 1, c, t, v))
286 else:
287 arr = ''
289 func(
290 name.format(stage=s,
291 mode=m,
292 matrix_dim=d,
293 arr=arr,
294 idx='index-' if a != 0 else '',
295 col='col-' if c == 'col' else '',
296 row='row-' if t == 'float' else ''),
297 factory.get(m, a, d, 'index', c, t, v))
300 if __name__ == '__main__':
301 main()