arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / generated_tests / gen_vs_in_fp64.py
blob69b010b93f8b3d628f63ac05b68c61781daa2131
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 fp64 vertex shader input tests."""
26 import abc
27 import argparse
28 import itertools
29 import os
30 import types
32 from templates import template_dir
33 from modules import utils
34 from modules import types as glsltypes
36 TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
38 # Hard limit so we don't generate useless tests that cannot be run in any existing HW.
39 MAX_VERTEX_ATTRIBS = 32
41 # pylint: disable=bad-whitespace,line-too-long
42 DOUBLE_INFS = ['0xfff0000000000000', # -inf
43 '0x7ff0000000000000'] # +inf
45 DOUBLE_NEG_ZERO = ['0x8000000000000000'] # Negative underflow (-0.0)
47 DOUBLE_POS_ZERO = ['0x0000000000000000'] # Positive underflow (+0.0)
49 # Double values causing an underflow to zero in any other type
50 DOUBLE_DENORMAL_VALUES = ['0x800fffffffffffff', # Negative maximum denormalized -- Denormalized may be flushed to 0
51 '0x8000000000000001', # Negative minimum denormalized -- Denormalized may be flushed to 0
52 '0x0000000000000001', # Positive minimum denormalized -- Denormalized may be flushed to 0
53 '0x000fffffffffffff'] # Positive maximum denormalized -- Denormalized may be flushed to 0
55 DOUBLE_NORMAL_VALUES = ['0xffefffffffffffff', # Negative maximum normalized
56 '0xcb1e35ed24eb6496', # -7.23401345e+53
57 '0xc8b1381a93a87849', # -1.5e+42
58 '0xc7efffffefffffff', # Negative maximum float normalized
59 '0xc170000000000000', # -16777216.0
60 '0xc014000000000000', # -5.0
61 '0xbfff25ce60000000', # -1.9467300176620483
62 '0x8010000000000000', # Negative minimum normalized
63 '0x0010000000000000', # Positive minimum normalized
64 '0x3fff25ce60000000', # +1.9467300176620483
65 '0x4014000000000000', # +5.0
66 '0x4170000000000000', # +16777216.0
67 '0x47efffffefffffff', # Positive maximum float normalized
68 '0x48b1381a93a87849', # +1.5e+42
69 '0x4b1e35ed24eb6496', # +7.23401345e+53
70 '0x7fefffffffffffff'] # Positive maximum normalized
72 FLOAT_POS_ZERO = ['0x00000000'] # 0.0
74 FLOAT_NORMAL_VALUES = ['0xc21620c5', # -3.7532
75 '0x75bc289b', # 4.7703e32
76 '0x54c1c081', # 6.6572e12
77 '0x878218f8', # -1.9575e-34
78 '0x7e0857ed', # 4.5307886e37
79 '0x2bb561bf', # 1.2887954e-12
80 '0xff7fffff', # Negative maximum normalized
81 '0xcb800000', # -16777216.0
82 '0xc0a00000', # -5.0
83 '0xbff92e73', # -1.9467300
84 '0x80800000', # Negative minimum normalized
85 '0x00800000', # Positive minimum normalized
86 '0x3ff92e73', # 1.9467300
87 '0x40a00000', # 5.0
88 '0x4b800000', # 16777216.0
89 '0x7f7fffff'] # Positive maximum normalized
91 UBYTE_VALUES = ['0', # Minimum
92 '127', # Signed byte low frontier
93 '128', # Signed byte up frontier
94 '255', # Maximum
95 '1',
96 '5',
97 '14',
98 '23',
99 '58',
100 '91',
101 '113',
102 '135',
103 '179',
104 '185',
105 '205',
106 '207',
107 '212']
109 BYTE_VALUES = ['-128', # Minimum
110 '-5',
111 '-1',
112 '0',
113 '1',
114 '5',
115 '127', # Maximum
116 '-125',
117 '-120',
118 '-117',
119 '-69',
120 '-24',
121 '-20',
122 '21',
123 '89',
124 '106',
125 '119']
127 USHORT_VALUES = ['0', # Minimum
128 '32767', # Signed short low frontier
129 '32768', # Signed short up frontier
130 '65535', # Maximum
131 '1',
132 '5',
133 '12610',
134 '17110',
135 '19962',
136 '23589',
137 '37265',
138 '41792',
139 '45699',
140 '47934',
141 '55916',
142 '56412',
143 '65142']
145 SHORT_VALUES = ['-32768', # Minimum
146 '-5',
147 '-1',
148 '0',
149 '1',
150 '5',
151 '32767', # Maximum
152 '-16255',
153 '-12480',
154 '-12360',
155 '1706',
156 '5386',
157 '7315',
158 '18137',
159 '25871',
160 '26255',
161 '26472']
163 UINT_VALUES = ['0', # Minimum
164 '2147483647', # Signed int low frontier
165 '2147483648', # Signed int up frontier
166 '4294967295', # Maximum
167 '1',
168 '5',
169 '1073294963',
170 '1084227584',
171 '1266679808',
172 '1421983873',
173 '2114476013',
174 '2273450232',
175 '3220778611',
176 '3231711232',
177 '3256230085',
178 '3414163456',
179 '4294967294']
181 INT_VALUES = ['-2147483648', # Minimum
182 '-5',
183 '-1',
184 '0',
185 '1',
186 '5',
187 '2147483647', # Maximum
188 '-1038737211',
189 '-1063256064',
190 '-1074188685',
191 '-880803840',
192 '1073294963',
193 '1084227584',
194 '1266679808',
195 '1421983873',
196 '1975265435',
197 '2114476013']
199 GL_TYPES_VALUES = {'double': DOUBLE_NORMAL_VALUES + DOUBLE_POS_ZERO,
200 'float': FLOAT_NORMAL_VALUES + FLOAT_POS_ZERO,
201 'ubyte': UBYTE_VALUES,
202 'byte': BYTE_VALUES,
203 'ushort': USHORT_VALUES,
204 'short': SHORT_VALUES,
205 'uint': UINT_VALUES,
206 'int': INT_VALUES}
208 GLSL_DSCALAR_TYPES = [glsltypes.DOUBLE]
210 GLSL_DVEC_TYPES = [glsltypes.DVEC2, glsltypes.DVEC3, glsltypes.DVEC4]
212 GLSL_DMAT_TYPES = [glsltypes.DMAT2, glsltypes.DMAT2X3, glsltypes.DMAT2X4,
213 glsltypes.DMAT3X2, glsltypes.DMAT3, glsltypes.DMAT3X4,
214 glsltypes.DMAT4X2, glsltypes.DMAT4X3, glsltypes.DMAT4]
216 GLSL_FSCALAR_TYPES = [glsltypes.FLOAT]
218 GLSL_FVEC_TYPES = [glsltypes.VEC2, glsltypes.VEC3, glsltypes.VEC4]
220 GLSL_FMAT_TYPES = [glsltypes.MAT2, glsltypes.MAT2X3, glsltypes.MAT2X4,
221 glsltypes.MAT3X2, glsltypes.MAT3, glsltypes.MAT3X4,
222 glsltypes.MAT4X2, glsltypes.MAT4X3, glsltypes.MAT4]
224 GLSL_ISCALAR_TYPES = [glsltypes.INT]
226 GLSL_IVEC_TYPES = [glsltypes.IVEC2, glsltypes.IVEC3, glsltypes.IVEC4]
228 GLSL_USCALAR_TYPES = [glsltypes.UINT]
230 GLSL_UVEC_TYPES = [glsltypes.UVEC2, glsltypes.UVEC3, glsltypes.UVEC4]
233 # pylint: enable=bad-whitespace,line-too-long
236 class TestTuple(object):
237 """A float64 derived and other type derived tuple to generate the
238 needed conversion tests.
240 @staticmethod
241 def get_dir_name(ver):
242 """Returns the directory name to save tests given a GLSL version."""
244 assert isinstance(ver, str)
245 if ver.startswith('GL_'):
246 feature_dir = ver[3:].lower()
247 else:
248 feature_dir = 'glsl-{}.{}'.format(ver[0], ver[1:])
250 return os.path.join('spec', feature_dir, 'execution',
251 'vs_in')
253 def __init__(self, ver, names_only):
254 assert isinstance(ver, str)
255 assert isinstance(names_only, bool)
257 self._ver = ver
258 self._names_only = names_only
260 @abc.abstractmethod
261 def generate(self):
262 """Generate the GLSL parser tests."""
265 class RegularTestTuple(TestTuple):
266 """Derived class for conversion tests using regular values within the
267 edges of the used types.
270 @staticmethod
271 def create_in_types_array(*types_arrays):
272 """Creates vertex input combinations."""
274 for product_item in itertools.product(*types_arrays):
275 yield product_item
277 @staticmethod
278 def create_tests(glsl_vers, in_types_array, gl_types,
279 position_orders, arrays_array, names_only):
280 """Creates combinations for flat qualifier tests."""
282 assert isinstance(glsl_vers, list)
283 assert isinstance(in_types_array, types.GeneratorType)
284 assert isinstance(gl_types, list)
285 assert isinstance(position_orders, list)
286 assert isinstance(arrays_array, list)
287 assert isinstance(names_only, bool)
289 if not names_only:
290 for ver in glsl_vers:
291 utils.safe_makedirs(TestTuple.get_dir_name(ver))
293 for in_types, position_order, arrays, ver in itertools.product(
294 in_types_array,
295 position_orders,
296 arrays_array,
297 glsl_vers):
298 num_vs_in = 1 # We use an additional vec3 piglit_vertex input
299 for idx, in_type in enumerate(in_types):
300 num_vs_in += (in_type.columns or 1) * arrays[idx] * \
301 (2 if in_type.type.name == 'double' and in_type.rows in [3, 4] else 1)
302 # dvec* and dmat* didn't appear in GLSL until 4.20
303 if (in_type.type.name == 'double' and not in_type.scalar) and ver == '410':
304 ver = '420'
305 # Skip the test if it needs too many inputs
306 if num_vs_in > MAX_VERTEX_ATTRIBS:
307 continue
309 yield ver, in_types, gl_types, position_order, arrays, num_vs_in, names_only
311 @staticmethod
312 def all_tests(names_only):
313 """Creates all the combinations for flat qualifier tests."""
315 assert isinstance(names_only, bool)
317 # We need additional directories for GLSL 420
318 if not names_only:
319 utils.safe_makedirs(TestTuple.get_dir_name('420'))
320 for test_args in RegularTestTuple.create_tests(
321 ['GL_ARB_vertex_attrib_64bit', '410'],
322 RegularTestTuple.create_in_types_array(
323 itertools.chain(GLSL_USCALAR_TYPES, GLSL_UVEC_TYPES),
324 itertools.chain(GLSL_ISCALAR_TYPES, GLSL_IVEC_TYPES),
325 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
326 ['ubyte', 'short', 'double'],
327 [1, 2, 3, 4],
328 [[1, 1, 1]],
329 names_only):
330 yield RegularTestTuple(*test_args)
331 for test_args in RegularTestTuple.create_tests(
332 ['GL_ARB_vertex_attrib_64bit', '410'],
333 RegularTestTuple.create_in_types_array(
334 itertools.chain(GLSL_ISCALAR_TYPES, GLSL_IVEC_TYPES),
335 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
336 ['byte', 'double'],
337 [1, 2, 3],
338 [[1, 1]],
339 names_only):
340 yield RegularTestTuple(*test_args)
341 for test_args in RegularTestTuple.create_tests(
342 ['GL_ARB_vertex_attrib_64bit', '410'],
343 RegularTestTuple.create_in_types_array(
344 itertools.chain(GLSL_USCALAR_TYPES, GLSL_UVEC_TYPES),
345 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
346 ['ushort', 'double'],
347 [1, 2, 3],
348 [[1, 1]],
349 names_only):
350 yield RegularTestTuple(*test_args)
351 for test_args in RegularTestTuple.create_tests(
352 ['GL_ARB_vertex_attrib_64bit', '410'],
353 RegularTestTuple.create_in_types_array(
354 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES),
355 itertools.chain(GLSL_FSCALAR_TYPES, GLSL_FVEC_TYPES, GLSL_FMAT_TYPES)),
356 ['double', 'float'],
357 [1, 2, 3],
358 [[1, 1], [1, 3], [5, 1], [5, 3]],
359 names_only):
360 yield RegularTestTuple(*test_args)
361 for test_args in RegularTestTuple.create_tests(
362 ['GL_ARB_vertex_attrib_64bit', '410'],
363 RegularTestTuple.create_in_types_array(
364 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES),
365 itertools.chain(GLSL_ISCALAR_TYPES, GLSL_IVEC_TYPES)),
366 ['double', 'int'],
367 [1, 2, 3],
368 [[1, 1], [1, 3], [5, 1], [5, 3]],
369 names_only):
370 yield RegularTestTuple(*test_args)
371 for test_args in RegularTestTuple.create_tests(
372 ['GL_ARB_vertex_attrib_64bit', '410'],
373 RegularTestTuple.create_in_types_array(
374 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES),
375 itertools.chain(GLSL_USCALAR_TYPES, GLSL_UVEC_TYPES)),
376 ['double', 'uint'],
377 [1, 2, 3],
378 [[1, 1], [1, 3], [5, 1], [5, 3]],
379 names_only):
380 yield RegularTestTuple(*test_args)
381 for test_args in RegularTestTuple.create_tests(
382 ['GL_ARB_vertex_attrib_64bit', '410'],
383 RegularTestTuple.create_in_types_array(
384 itertools.chain(GLSL_FSCALAR_TYPES, GLSL_FVEC_TYPES, GLSL_FMAT_TYPES),
385 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
386 ['float', 'double'],
387 [1, 2, 3],
388 [[1, 1], [1, 2], [3, 1], [3, 2]],
389 names_only):
390 yield RegularTestTuple(*test_args)
391 for test_args in RegularTestTuple.create_tests(
392 ['GL_ARB_vertex_attrib_64bit', '410'],
393 RegularTestTuple.create_in_types_array(
394 itertools.chain(GLSL_ISCALAR_TYPES, GLSL_IVEC_TYPES),
395 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
396 ['int', 'double'],
397 [1, 2, 3],
398 [[1, 1], [1, 2], [3, 1], [3, 2]],
399 names_only):
400 yield RegularTestTuple(*test_args)
401 for test_args in RegularTestTuple.create_tests(
402 ['GL_ARB_vertex_attrib_64bit', '410'],
403 RegularTestTuple.create_in_types_array(
404 itertools.chain(GLSL_USCALAR_TYPES, GLSL_UVEC_TYPES),
405 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
406 ['uint', 'double'],
407 [1, 2, 3],
408 [[1, 1], [1, 2], [3, 1], [3, 2]],
409 names_only):
410 yield RegularTestTuple(*test_args)
411 for test_args in RegularTestTuple.create_tests(
412 ['GL_ARB_vertex_attrib_64bit', '410'],
413 RegularTestTuple.create_in_types_array(
414 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES),
415 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
416 ['double', 'double'],
417 [1, 2, 3],
418 [[1, 1], [1, 2], [3, 1], [3, 2]],
419 names_only):
420 yield RegularTestTuple(*test_args)
421 for test_args in RegularTestTuple.create_tests(
422 ['GL_ARB_vertex_attrib_64bit', '410'],
423 RegularTestTuple.create_in_types_array(
424 itertools.chain(GLSL_DSCALAR_TYPES, GLSL_DVEC_TYPES, GLSL_DMAT_TYPES)),
425 ['double'],
426 [1, 2],
427 [[1], [5]],
428 names_only):
429 yield RegularTestTuple(*test_args)
431 def __init__(self, ver, in_types, gl_types, position_order, arrays, num_vs_in, names_only):
432 assert ver in ('GL_ARB_vertex_attrib_64bit', '410', '420')
433 assert isinstance(in_types, tuple)
434 assert isinstance(gl_types, list)
435 assert len(gl_types) == len(in_types)
436 assert isinstance(position_order, int)
437 assert (position_order > 0) and (position_order - 1 <= len(in_types))
438 assert isinstance(arrays, list)
439 assert isinstance(num_vs_in, int) and (num_vs_in <= MAX_VERTEX_ATTRIBS)
440 super(RegularTestTuple, self).__init__(ver, names_only)
442 self._in_types = in_types
443 self._gl_types = gl_types
444 self._position_order = position_order
445 self._arrays = arrays
446 self._num_vs_in = num_vs_in
448 def generate(self):
449 """Generate GLSL parser tests."""
450 filename = os.path.join(TestTuple.get_dir_name(self._ver), 'vs-input')
451 for idx, in_type in enumerate(self._in_types):
452 if idx == self._position_order - 1:
453 filename += '-position'
454 filename += '-{}_{}{}'.format(
455 self._gl_types[idx], in_type.name, '_array{}'.format(
456 self._arrays[idx]) if self._arrays[idx] - 1 else '')
457 if self._position_order > len(self._in_types):
458 filename += '-position'
459 filename += '.shader_test'
461 if not self._names_only:
462 with open(filename, 'w') as test_file:
463 test_file.write(TEMPLATES.get_template(
464 'regular.shader_test.mako').render_unicode(
465 ver=self._ver,
466 in_types=self._in_types,
467 gl_types=self._gl_types,
468 position_order=self._position_order,
469 arrays=self._arrays,
470 num_vs_in=self._num_vs_in,
471 gl_types_values=GL_TYPES_VALUES))
473 print(filename)
476 class ColumnsTestTuple(TestTuple):
477 """Derived class for conversion tests using regular values within the
478 edges of the used types.
481 @staticmethod
482 def all_tests(names_only):
483 """Creates all the combinations for flat qualifier tests."""
485 assert isinstance(names_only, bool)
486 glsl_vers = ['GL_ARB_vertex_attrib_64bit', '420']
488 if not names_only:
489 for ver in glsl_vers:
490 utils.safe_makedirs(TestTuple.get_dir_name(ver))
492 for mat in GLSL_DMAT_TYPES:
493 for columns in itertools.product(range(2), repeat=mat.columns):
494 if (0 not in columns) or (1 not in columns):
495 continue
496 for ver in glsl_vers:
497 yield ColumnsTestTuple(ver, mat, columns, names_only)
499 def __init__(self, ver, mat, columns, names_only):
500 assert ver in ('GL_ARB_vertex_attrib_64bit', '420')
501 super(ColumnsTestTuple, self).__init__(ver, names_only)
503 self._mat = mat
504 self._columns = columns
506 def generate(self):
507 """Generate GLSL parser tests."""
509 filename = os.path.join(TestTuple.get_dir_name(self._ver),
510 'vs-input-columns-{}'.format(self._mat.name))
511 for idx, column in enumerate(self._columns):
512 if column == 1:
513 filename += '-{}'.format(idx)
514 filename += '.shader_test'
516 if not self._names_only:
517 with open(filename, 'w') as test_file:
518 test_file.write(TEMPLATES.get_template(
519 'columns.shader_test.mako').render_unicode(
520 ver=self._ver,
521 mat=self._mat,
522 columns=self._columns,
523 dvalues=GL_TYPES_VALUES['double']))
525 print(filename)
528 def main():
529 """Main function."""
531 parser = argparse.ArgumentParser(
532 description="Generate non-flat interpolation qualifier tests with fp64 types")
533 parser.add_argument(
534 '--names-only',
535 dest='names_only',
536 action='store_true',
537 default=False,
538 help="Don't output files, just generate a list of filenames to stdout")
539 args = parser.parse_args()
541 for test in itertools.chain(RegularTestTuple.all_tests(args.names_only),
542 ColumnsTestTuple.all_tests(args.names_only)):
543 test.generate()
546 if __name__ == '__main__':
547 main()