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