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.
26 from operator
import neg
28 from templates
import template_file
29 from modules
import utils
31 TEMPLATE
= template_file(os
.path
.basename(os
.path
.splitext(__file__
)[0]),
32 'template.shader_test.mako')
35 def floatBitsToInt(f
): # pylint: disable=invalid-name
36 return struct
.unpack('i', struct
.pack('f', f
))[0]
39 def floatBitsToUint(f
): # pylint: disable=invalid-name
40 return struct
.unpack('I', struct
.pack('f', f
))[0]
43 def intBitsToFloat(i
): # pylint: disable=invalid-name
44 return struct
.unpack('f', struct
.pack('i', i
))[0]
47 def uintBitsToFloat(u
): # pylint: disable=invalid-name
48 return struct
.unpack('f', struct
.pack('I', u
))[0]
58 # pylint: disable=bad-whitespace
60 # Interesting floating-point inputs
61 'mixed': (2.0, 9.5, -4.5, -25.0),
62 '0.0': vec4( 0.0), # int 0
63 '-0.0': vec4(-0.0), # INT_MIN
66 'normalized smallest': vec4( 1.1754944e-38),
67 'normalized smallest negative': vec4(-1.1754944e-38),
68 'normalized largest': vec4( 3.4028235e+38),
69 'normalized largest negative': vec4(-3.4028235e+38),
71 # Don't test +inf or -inf, since we don't have a way to pass them via
72 # shader_runner [test] sections. Don't test NaN, since it has many
73 # representations. Don't test subnormal values, since hardware might
76 # pylint: enable=bad-whitespace
78 # in_func: Function to convert floating-point data in test_data (above) into
79 # input (given) data to pass the shader.
80 # out_func: Function to convert floating-point data in test_data (above) into
81 # output (expected) data to pass the shader.
85 'in_func': lambda x
: x
,
86 'out_func': floatBitsToInt
,
91 'in_func': lambda x
: x
,
92 'out_func': floatBitsToUint
,
97 'in_func': floatBitsToInt
,
98 'out_func': intBitsToFloat
,
103 'in_func': floatBitsToUint
,
104 'out_func': uintBitsToFloat
,
118 'ARB_shader_bit_encoding': {
120 'extension': 'GL_ARB_shader_bit_encoding'
124 'extension': 'GL_ARB_gpu_shader5'
135 # pylint: disable=line-too-long
136 for api
, requirement
in REQUIREMENTS
.items():
137 version
= requirement
['version']
138 extensions
= [requirement
['extension']] if requirement
['extension'] else []
140 dirname
= os
.path
.join('spec', api
.lower(), 'execution',
141 'built-in-functions')
142 utils
.safe_makedirs(dirname
)
144 for func
, attrib
in FUNCS
.items():
145 for execution_stage
in ('vs', 'fs'):
146 for in_modifier_func
, modifier_func
in MODIFIER_FUNCS
.items():
147 # Modifying the sign of an unsigned number doesn't make sense.
148 if func
== 'uintBitsToFloat' and in_modifier_func
!= '':
151 modifier_name
= '-' + in_modifier_func
if in_modifier_func
!= '' else ''
152 filename
= os
.path
.join(
154 "{0}-{1}{2}.shader_test".format(execution_stage
, func
,
158 if in_modifier_func
== 'neg':
159 in_modifier_func
= '-'
160 elif in_modifier_func
== 'neg_abs':
161 in_modifier_func
= '-abs'
163 with
open(filename
, 'w') as f
:
164 f
.write(TEMPLATE
.render_unicode(
166 extensions
=extensions
,
167 execution_stage
=execution_stage
,
169 modifier_func
=modifier_func
,
170 in_modifier_func
=in_modifier_func
,
171 in_func
=attrib
['in_func'],
172 out_func
=attrib
['out_func'],
173 input_type
=attrib
['input'],
174 output_type
=attrib
['output'],
175 test_data
=TEST_DATA
))
178 if __name__
== '__main__':