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
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."""
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
86 '0xbff92e73', # -1.9467300
87 '0x80800000', # Negative minimum normalized
88 '0x00800000', # Positive minimum normalized
89 '0x3ff92e73', # 1.9467300
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
112 BYTE_VALUES
= ['-128', # Minimum
130 USHORT_VALUES
= ['0', # Minimum
131 '32767', # Signed short low frontier
132 '32768', # Signed short up frontier
148 SHORT_VALUES
= ['-32768', # Minimum
166 UINT_VALUES
= ['0', # Minimum
167 '2147483647', # Signed int low frontier
168 '2147483648', # Signed int up frontier
169 '4294967295', # Maximum
184 INT_VALUES
= ['-2147483648', # Minimum
190 '2147483647', # Maximum
202 GL_TYPES_VALUES
= {'double': DOUBLE_NORMAL_VALUES
+ DOUBLE_POS_ZERO
,
203 'float': FLOAT_NORMAL_VALUES
+ FLOAT_POS_ZERO
,
204 'ubyte': UBYTE_VALUES
,
206 'ushort': USHORT_VALUES
,
207 'short': SHORT_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.
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()
251 feature_dir
= 'glsl-{}.{}'.format(ver
[0], ver
[1:])
253 return os
.path
.join('spec', feature_dir
, 'execution',
256 def __init__(self
, ver
, names_only
):
257 assert isinstance(ver
, str)
258 assert isinstance(names_only
, bool)
261 self
._names
_only
= names_only
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.
274 def create_in_types_array(*types_arrays
):
275 """Creates vertex input combinations."""
277 for product_item
in itertools
.product(*types_arrays
):
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)
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(
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':
308 # Skip the test if it needs too many inputs
309 if num_vs_in
> MAX_VERTEX_ATTRIBS
:
312 yield ver
, in_types
, gl_types
, position_order
, arrays
, num_vs_in
, names_only
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
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'],
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
)),
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'],
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
)),
361 [[1, 1], [1, 3], [5, 1], [5, 3]],
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
)),
371 [[1, 1], [1, 3], [5, 1], [5, 3]],
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
)),
381 [[1, 1], [1, 3], [5, 1], [5, 3]],
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
)),
391 [[1, 1], [1, 2], [3, 1], [3, 2]],
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
)),
401 [[1, 1], [1, 2], [3, 1], [3, 2]],
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
)),
411 [[1, 1], [1, 2], [3, 1], [3, 2]],
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'],
421 [[1, 1], [1, 2], [3, 1], [3, 2]],
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
)),
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
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
:
467 test_file
.write(TEMPLATES
.get_template(
468 'regular.shader_test.mako').render_unicode(
470 in_types
=self
._in
_types
,
471 gl_types
=self
._gl
_types
,
472 position_order
=self
._position
_order
,
474 num_vs_in
=self
._num
_vs
_in
,
475 gl_types_values
=GL_TYPES_VALUES
))
477 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
483 class ColumnsTestTuple(TestTuple
):
484 """Derived class for conversion tests using regular values within the
485 edges of the used types.
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']
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
):
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
)
511 self
._columns
= columns
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
):
520 filename
+= '-{}'.format(idx
)
521 filename
+= '.shader_test'
523 if not self
._names
_only
:
524 with
open(filename
, 'w') as test_file
:
526 test_file
.write(TEMPLATES
.get_template(
527 'columns.shader_test.mako').render_unicode(
530 columns
=self
._columns
,
531 dvalues
=GL_TYPES_VALUES
['double']))
533 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
542 parser
= argparse
.ArgumentParser(
543 description
="Generate non-flat interpolation qualifier tests with fp64 types")
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
)):
557 if __name__
== '__main__':