glsl-1.10: test a complex partial unroll scenario
[piglit.git] / generated_tests / gen_shader_bit_encoding_tests.py
blobfcdc5dd39cfdf0b679a15e52e19d1fc1a0fc1992
1 # coding=utf-8
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
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 import struct
25 import os
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]
51 def neg_abs(num):
52 return neg(abs(num))
55 def vec4(f):
56 return [f, f, f, f]
58 # pylint: disable=bad-whitespace
59 TEST_DATA = {
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
64 '1.0': vec4( 1.0),
65 '-1.0': vec4(-1.0),
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
74 # flush them to zero.
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.
83 FUNCS = {
84 'floatBitsToInt': {
85 'in_func': lambda x: x,
86 'out_func': floatBitsToInt,
87 'input': 'vec4',
88 'output': 'ivec4'
90 'floatBitsToUint': {
91 'in_func': lambda x: x,
92 'out_func': floatBitsToUint,
93 'input': 'vec4',
94 'output': 'uvec4'
96 'intBitsToFloat': {
97 'in_func': floatBitsToInt,
98 'out_func': intBitsToFloat,
99 'input': 'ivec4',
100 'output': 'vec4'
102 'uintBitsToFloat': {
103 'in_func': floatBitsToUint,
104 'out_func': uintBitsToFloat,
105 'input': 'uvec4',
106 'output': 'vec4'
110 MODIFIER_FUNCS = {
111 '': lambda x: x,
112 'abs': abs,
113 'neg': neg,
114 'neg_abs': neg_abs,
117 REQUIREMENTS = {
118 'ARB_shader_bit_encoding': {
119 'version': '1.30',
120 'extension': 'GL_ARB_shader_bit_encoding'
122 'ARB_gpu_shader5': {
123 'version': '1.50',
124 'extension': 'GL_ARB_gpu_shader5'
126 'glsl-3.30': {
127 'version': '3.30',
128 'extension': ''
133 def main():
134 """main function."""
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 != '':
149 continue
151 modifier_name = '-' + in_modifier_func if in_modifier_func != '' else ''
152 filename = os.path.join(
153 dirname,
154 "{0}-{1}{2}.shader_test".format(execution_stage, func,
155 modifier_name))
156 print(filename)
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(
165 version=version,
166 extensions=extensions,
167 execution_stage=execution_stage,
168 func=func,
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__':
179 main()