3 # Copyright © 2013, 2014 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 from __future__
import print_function
, division
, absolute_import
27 from operator
import neg
31 from templates
import template_file
32 from modules
import utils
34 TEMPLATE
= template_file(os
.path
.basename(os
.path
.splitext(__file__
)[0]),
35 'template.shader_test.mako')
38 def floatBitsToInt(f
): # pylint: disable=invalid-name
39 return struct
.unpack('i', struct
.pack('f', f
))[0]
42 def floatBitsToUint(f
): # pylint: disable=invalid-name
43 return struct
.unpack('I', struct
.pack('f', f
))[0]
46 def intBitsToFloat(i
): # pylint: disable=invalid-name
47 return struct
.unpack('f', struct
.pack('i', i
))[0]
50 def uintBitsToFloat(u
): # pylint: disable=invalid-name
51 return struct
.unpack('f', struct
.pack('I', u
))[0]
61 # pylint: disable=bad-whitespace
63 # Interesting floating-point inputs
64 'mixed': (2.0, 9.5, -4.5, -25.0),
65 '0.0': vec4( 0.0), # int 0
66 '-0.0': vec4(-0.0), # INT_MIN
69 'normalized smallest': vec4( 1.1754944e-38),
70 'normalized smallest negative': vec4(-1.1754944e-38),
71 'normalized largest': vec4( 3.4028235e+38),
72 'normalized largest negative': vec4(-3.4028235e+38),
74 # Don't test +inf or -inf, since we don't have a way to pass them via
75 # shader_runner [test] sections. Don't test NaN, since it has many
76 # representations. Don't test subnormal values, since hardware might
79 # pylint: enable=bad-whitespace
81 # in_func: Function to convert floating-point data in test_data (above) into
82 # input (given) data to pass the shader.
83 # out_func: Function to convert floating-point data in test_data (above) into
84 # output (expected) data to pass the shader.
88 'in_func': lambda x
: x
,
89 'out_func': floatBitsToInt
,
94 'in_func': lambda x
: x
,
95 'out_func': floatBitsToUint
,
100 'in_func': floatBitsToInt
,
101 'out_func': intBitsToFloat
,
106 'in_func': floatBitsToUint
,
107 'out_func': uintBitsToFloat
,
121 'ARB_shader_bit_encoding': {
123 'extension': 'GL_ARB_shader_bit_encoding'
127 'extension': 'GL_ARB_gpu_shader5'
138 # pylint: disable=line-too-long
139 for api
, requirement
in six
.iteritems(REQUIREMENTS
):
140 version
= requirement
['version']
141 extensions
= [requirement
['extension']] if requirement
['extension'] else []
143 dirname
= os
.path
.join('spec', api
.lower(), 'execution',
144 'built-in-functions')
145 utils
.safe_makedirs(dirname
)
147 for func
, attrib
in six
.iteritems(FUNCS
):
148 for execution_stage
in ('vs', 'fs'):
149 for in_modifier_func
, modifier_func
in six
.iteritems(MODIFIER_FUNCS
):
150 # Modifying the sign of an unsigned number doesn't make sense.
151 if func
== 'uintBitsToFloat' and in_modifier_func
!= '':
154 modifier_name
= '-' + in_modifier_func
if in_modifier_func
!= '' else ''
155 filename
= os
.path
.join(
157 "{0}-{1}{2}.shader_test".format(execution_stage
, func
,
161 if in_modifier_func
== 'neg':
162 in_modifier_func
= '-'
163 elif in_modifier_func
== 'neg_abs':
164 in_modifier_func
= '-abs'
166 with
open(filename
, 'w') as f
:
167 f
.write(TEMPLATE
.render_unicode(
169 extensions
=extensions
,
170 execution_stage
=execution_stage
,
172 modifier_func
=modifier_func
,
173 in_modifier_func
=in_modifier_func
,
174 in_func
=attrib
['in_func'],
175 out_func
=attrib
['out_func'],
176 input_type
=attrib
['input'],
177 output_type
=attrib
['output'],
178 test_data
=TEST_DATA
))
181 if __name__
== '__main__':