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."""
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
83 '0xbff92e73', # -1.9467300
84 '0x80800000', # Negative minimum normalized
85 '0x00800000', # Positive minimum normalized
86 '0x3ff92e73', # 1.9467300
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
109 BYTE_VALUES
= ['-128', # Minimum
127 USHORT_VALUES
= ['0', # Minimum
128 '32767', # Signed short low frontier
129 '32768', # Signed short up frontier
145 SHORT_VALUES
= ['-32768', # Minimum
163 UINT_VALUES
= ['0', # Minimum
164 '2147483647', # Signed int low frontier
165 '2147483648', # Signed int up frontier
166 '4294967295', # Maximum
181 INT_VALUES
= ['-2147483648', # Minimum
187 '2147483647', # Maximum
199 GL_TYPES_VALUES
= {'double': DOUBLE_NORMAL_VALUES
+ DOUBLE_POS_ZERO
,
200 'float': FLOAT_NORMAL_VALUES
+ FLOAT_POS_ZERO
,
201 'ubyte': UBYTE_VALUES
,
203 'ushort': USHORT_VALUES
,
204 'short': SHORT_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.
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()
248 feature_dir
= 'glsl-{}.{}'.format(ver
[0], ver
[1:])
250 return os
.path
.join('spec', feature_dir
, 'execution',
253 def __init__(self
, ver
, names_only
):
254 assert isinstance(ver
, str)
255 assert isinstance(names_only
, bool)
258 self
._names
_only
= names_only
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.
271 def create_in_types_array(*types_arrays
):
272 """Creates vertex input combinations."""
274 for product_item
in itertools
.product(*types_arrays
):
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)
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(
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':
305 # Skip the test if it needs too many inputs
306 if num_vs_in
> MAX_VERTEX_ATTRIBS
:
309 yield ver
, in_types
, gl_types
, position_order
, arrays
, num_vs_in
, names_only
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
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'],
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
)),
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'],
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
)),
358 [[1, 1], [1, 3], [5, 1], [5, 3]],
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
)),
368 [[1, 1], [1, 3], [5, 1], [5, 3]],
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
)),
378 [[1, 1], [1, 3], [5, 1], [5, 3]],
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
)),
388 [[1, 1], [1, 2], [3, 1], [3, 2]],
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
)),
398 [[1, 1], [1, 2], [3, 1], [3, 2]],
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
)),
408 [[1, 1], [1, 2], [3, 1], [3, 2]],
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'],
418 [[1, 1], [1, 2], [3, 1], [3, 2]],
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
)),
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
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(
466 in_types
=self
._in
_types
,
467 gl_types
=self
._gl
_types
,
468 position_order
=self
._position
_order
,
470 num_vs_in
=self
._num
_vs
_in
,
471 gl_types_values
=GL_TYPES_VALUES
))
476 class ColumnsTestTuple(TestTuple
):
477 """Derived class for conversion tests using regular values within the
478 edges of the used types.
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']
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
):
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
)
504 self
._columns
= columns
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
):
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(
522 columns
=self
._columns
,
523 dvalues
=GL_TYPES_VALUES
['double']))
531 parser
= argparse
.ArgumentParser(
532 description
="Generate non-flat interpolation qualifier tests with fp64 types")
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
)):
546 if __name__
== '__main__':