summary/html: specify lang="en" in html tag
[piglit.git] / generated_tests / gen_shader_bit_encoding_tests.py
blob21db127e1a75262dc6c5895794412495b0af1d6f
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 from __future__ import print_function, division, absolute_import
25 import struct
26 import os
27 from operator import neg
29 import six
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]
54 def neg_abs(num):
55 return neg(abs(num))
58 def vec4(f):
59 return [f, f, f, f]
61 # pylint: disable=bad-whitespace
62 TEST_DATA = {
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
67 '1.0': vec4( 1.0),
68 '-1.0': vec4(-1.0),
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
77 # flush them to zero.
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.
86 FUNCS = {
87 'floatBitsToInt': {
88 'in_func': lambda x: x,
89 'out_func': floatBitsToInt,
90 'input': 'vec4',
91 'output': 'ivec4'
93 'floatBitsToUint': {
94 'in_func': lambda x: x,
95 'out_func': floatBitsToUint,
96 'input': 'vec4',
97 'output': 'uvec4'
99 'intBitsToFloat': {
100 'in_func': floatBitsToInt,
101 'out_func': intBitsToFloat,
102 'input': 'ivec4',
103 'output': 'vec4'
105 'uintBitsToFloat': {
106 'in_func': floatBitsToUint,
107 'out_func': uintBitsToFloat,
108 'input': 'uvec4',
109 'output': 'vec4'
113 MODIFIER_FUNCS = {
114 '': lambda x: x,
115 'abs': abs,
116 'neg': neg,
117 'neg_abs': neg_abs,
120 REQUIREMENTS = {
121 'ARB_shader_bit_encoding': {
122 'version': '1.30',
123 'extension': 'GL_ARB_shader_bit_encoding'
125 'ARB_gpu_shader5': {
126 'version': '1.50',
127 'extension': 'GL_ARB_gpu_shader5'
129 'glsl-3.30': {
130 'version': '3.30',
131 'extension': ''
136 def main():
137 """main function."""
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 != '':
152 continue
154 modifier_name = '-' + in_modifier_func if in_modifier_func != '' else ''
155 filename = os.path.join(
156 dirname,
157 "{0}-{1}{2}.shader_test".format(execution_stage, func,
158 modifier_name))
159 print(filename)
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(
168 version=version,
169 extensions=extensions,
170 execution_stage=execution_stage,
171 func=func,
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__':
182 main()