gl-1.1: Test that unused normal array in ff shader doesn't affect other arrays
[piglit.git] / generated_tests / gen_gpu_shader4_tests.py
blob4c946b326f5dfc9911a3112a2768b03c6e38d357
1 # coding=utf-8
2 # Copyright (c) 2014 Intel Corporation
3 # Copyright (c) 2018 Advanced Micro Devices, Inc.
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
23 """ Generate spec/EXT_gpu_shader4 tests """
25 import os
26 import collections
28 from templates import template_dir
29 from modules import utils
31 TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
33 vec = ['vec2', 'vec3', 'vec4']
34 ivec = ['ivec2', 'ivec3', 'ivec4']
35 uvec = ['uvec2', 'uvec3', 'uvec4']
37 genType = ['float'] + vec
38 genIType = ['int'] + ivec
39 genUType = ['unsigned int'] + uvec
41 ShiftOpTypes = [
42 ('int', 'int'), ('unsigned int', 'unsigned int'),
43 ('ivec2', 'ivec2'), ('ivec3', 'ivec3'), ('ivec4', 'ivec4'),
44 ('uvec2', 'uvec2'), ('uvec3', 'uvec3'), ('uvec4', 'uvec4'),
46 ('ivec2', 'int'), ('ivec3', 'int'), ('ivec4', 'int'),
47 ('uvec2', 'unsigned int'), ('uvec3', 'unsigned int'), ('uvec4', 'unsigned int'),
50 BinaryOpTypes = ShiftOpTypes + [
51 ('int', 'ivec2'), ('int', 'ivec3'), ('int', 'ivec4'),
52 ('unsigned int', 'uvec2'), ('unsigned int', 'uvec3'), ('unsigned int', 'uvec4'),
55 OperatorParams = collections.namedtuple(
56 'OperatorParams', ['name', 'op', 'types'])
58 UNARY_OP_TESTS = [
59 OperatorParams('bitwise-not', '~', genIType + genUType),
62 BINARY_OP_TESTS = [
63 OperatorParams('mod', '%', BinaryOpTypes),
64 OperatorParams('bitwise-and', '&', BinaryOpTypes),
65 OperatorParams('bitwise-or', '|', BinaryOpTypes),
66 OperatorParams('xor', '^', BinaryOpTypes),
67 OperatorParams('lshift', '<<', ShiftOpTypes),
68 OperatorParams('rshift', '>>', ShiftOpTypes),
72 Type1Params = collections.namedtuple(
73 'Type1Params', ['func', 'type1'])
74 Type2Params = collections.namedtuple(
75 'Type2Params', ['func', 'type1', 'type2'])
77 UNARY_TESTS = [
78 Type1Params('abs', genIType),
79 Type1Params('sign', genIType),
80 Type1Params('truncate', genType),
81 Type1Params('round', genType),
84 BINARY_TESTS = [
85 Type1Params('min', genIType),
86 Type2Params('min', ivec, 'int'),
87 Type1Params('min', genUType),
88 Type2Params('min', uvec, 'unsigned int'),
90 Type1Params('max', genIType),
91 Type2Params('max', ivec, 'int'),
92 Type1Params('max', genUType),
93 Type2Params('max', uvec, 'unsigned int'),
96 TERNARY_TESTS = [
97 Type1Params('clamp', genIType),
98 Type2Params('clamp', ivec, 'int'),
99 Type1Params('clamp', genUType),
100 Type2Params('clamp', uvec, 'unsigned int'),
103 VEC_COMPARE_TESTS = [
104 Type1Params('lessThan', uvec),
105 Type1Params('lessThanEqual', uvec),
106 Type1Params('greaterThan', uvec),
107 Type1Params('greaterThanEqual', uvec),
108 Type1Params('equal', uvec),
109 Type1Params('notEqual', uvec),
113 FLOAT = ['']
114 INT = ['i', 'u']
115 ALL = FLOAT + INT
117 FetchParams = collections.namedtuple(
118 'FetchParams', ['sampler', 'coord', 'offsetcoord', 'variants'])
120 FETCH_TESTS = [
121 FetchParams('1D', 'int', 'int', ALL),
122 FetchParams('2D', 'ivec2', 'ivec2', ALL),
123 FetchParams('3D', 'ivec3', 'ivec3', ALL),
124 FetchParams('2DRect', 'ivec2', 'ivec2', ALL),
125 FetchParams('1DArray', 'ivec2', 'int', ALL),
126 FetchParams('2DArray', 'ivec3', 'ivec2', ALL),
127 FetchParams('Buffer', 'int', '', ALL),
130 SIZE_TESTS = FETCH_TESTS + [
131 FetchParams('Cube', 'ivec2', '', ALL),
135 TextureParams = collections.namedtuple(
136 'TextureParams', ['func', 'sampler', 'coord', 'offsetcoord', 'variants'])
138 # Variants: std, bias, lod
139 COMMON_TEXTURE_TESTS = [
140 # Inherited from GLSL 1.10, test integer textures
141 TextureParams('texture1D', '1D', 'float', 'int', INT),
142 TextureParams('texture1DProj', '1D', 'vec2', 'int', INT),
143 TextureParams('texture1DProj', '1D', 'vec4', 'int', INT),
145 TextureParams('texture2D', '2D', 'vec2', 'ivec2', INT),
146 TextureParams('texture2DProj', '2D', 'vec3', 'ivec2', INT),
147 TextureParams('texture2DProj', '2D', 'vec4', 'ivec2', INT),
149 TextureParams('texture3D', '3D', 'vec3', 'ivec3', INT),
150 TextureParams('texture3DProj', '3D', 'vec4', 'ivec3', INT),
152 TextureParams('textureCube', 'Cube', 'vec3', '', INT),
154 # Added by GL_EXT_gpu_shader4
155 TextureParams('texture1DArray', '1DArray', 'vec2', 'int', ALL),
156 TextureParams('texture2DArray', '2DArray', 'vec3', 'ivec2', ALL),
158 TextureParams('shadow1D', '1DShadow', 'vec3', 'int', FLOAT),
159 TextureParams('shadow2D', '2DShadow', 'vec3', 'ivec2', FLOAT),
160 TextureParams('shadow1DProj', '1DShadow', 'vec4', 'int', FLOAT),
161 TextureParams('shadow2DProj', '2DShadow', 'vec4', 'ivec2', FLOAT),
162 TextureParams('shadow1DArray', '1DArrayShadow', 'vec3', 'int', FLOAT),
165 TEXTURE_TESTS = COMMON_TEXTURE_TESTS + [
166 TextureParams('shadow2DArray', '2DArrayShadow', 'vec4', 'ivec2', FLOAT),
167 TextureParams('shadowCube', 'CubeShadow', 'vec4', '', FLOAT),
169 # Inherited from ARB_texture_rectangle, test integer textures
170 TextureParams('texture2DRect', '2DRect', 'vec2', 'ivec2', INT),
171 TextureParams('texture2DRectProj', '2DRect', 'vec3', 'ivec2', INT),
172 TextureParams('texture2DRectProj', '2DRect', 'vec4', 'ivec2', INT),
173 TextureParams('shadow2DRect', '2DRectShadow', 'vec3', 'ivec2', FLOAT),
174 TextureParams('shadow2DRectProj', '2DRectShadow', 'vec4', 'ivec2', FLOAT),
177 LOD_TESTS = COMMON_TEXTURE_TESTS
178 BIAS_TESTS = COMMON_TEXTURE_TESTS
181 GradParams = collections.namedtuple(
182 'GradParams', ['coord', 'grad', 'offsetcoord', 'sampler', 'func', 'variants'])
184 GRAD_TESTS = [
185 GradParams('float', 'float', 'int', '1D', 'texture1D', ALL),
186 GradParams('vec2', 'float', 'int', '1D', 'texture1DProj', ALL),
187 GradParams('vec4', 'float', 'int', '1D', 'texture1DProj', ALL),
188 GradParams('vec2', 'float', 'int', '1DArray', 'texture1DArray', ALL),
190 GradParams('vec2', 'vec2', 'ivec2', '2D', 'texture2D', ALL),
191 GradParams('vec3', 'vec2', 'ivec2', '2D', 'texture2DProj', ALL),
192 GradParams('vec4', 'vec2', 'ivec2', '2D', 'texture2DProj', ALL),
193 GradParams('vec3', 'vec2', 'ivec2', '2DArray', 'texture2DArray', ALL),
195 GradParams('vec3', 'vec3', 'ivec3', '3D', 'texture3D', ALL),
196 GradParams('vec4', 'vec3', 'ivec3', '3D', 'texture3DProj', ALL),
198 GradParams('vec3', 'vec3', '', 'Cube', 'textureCube', ALL),
200 GradParams('vec3', 'float', 'int', '1DShadow', 'shadow1D', FLOAT),
201 GradParams('vec4', 'float', 'int', '1DShadow', 'shadow1DProj', FLOAT),
202 GradParams('vec3', 'float', 'int', '1DArrayShadow', 'shadow1DArray', FLOAT),
204 GradParams('vec3', 'vec2', 'ivec2', '2DShadow', 'shadow2D', FLOAT),
205 GradParams('vec4', 'vec2', 'ivec2', '2DShadow', 'shadow2DProj', FLOAT),
206 GradParams('vec4', 'vec2', 'ivec2', '2DArrayShadow', 'shadow2DArray', FLOAT),
208 GradParams('vec2', 'vec2', 'ivec2', '2DRect', 'texture2DRect', ALL),
209 GradParams('vec3', 'vec2', 'ivec2', '2DRect', 'texture2DRectProj', ALL),
210 GradParams('vec4', 'vec2', 'ivec2', '2DRect', 'texture2DRectProj', ALL),
212 GradParams('vec3', 'vec2', 'ivec2', '2DRectShadow', 'shadow2DRect', FLOAT),
213 GradParams('vec4', 'vec2', 'ivec2', '2DRectShadow', 'shadow2DRectProj', FLOAT),
215 GradParams('vec4', 'vec3', '', 'CubeShadow', 'shadowCube', FLOAT),
218 def get_swizzle(vtype):
220 Expand the type to vec4.
222 if '3' in vtype:
223 return '.xyzz';
224 if '2' in vtype:
225 return '.xyyy';
226 return '';
228 def get_bvec(vtype):
230 Return the corresponding bvec type.
232 if '4' in vtype:
233 return 'bvec4';
234 if '3' in vtype:
235 return 'bvec3';
236 if '2' in vtype:
237 return 'bvec2';
238 return 'invalid';
240 def get_extensions(sampler):
241 """ If this test uses GL_ARB_texture_rectangle add it
243 GL_ARB_texture_rectangle is an odd extension, it is on by default, so don't
244 generate a #extension in the shader, just in the config block.
247 if 'Rect' in sampler:
248 return 'GL_EXT_gpu_shader4 GL_ARB_texture_rectangle'
250 if 'Array' in sampler:
251 return 'GL_EXT_gpu_shader4 GL_EXT_texture_array'
253 if 'Buffer' in sampler:
254 return 'GL_EXT_gpu_shader4 GL_EXT_texture_buffer_object'
256 return 'GL_EXT_gpu_shader4'
259 def main():
260 """ Main function
262 Writes tests to generated_tests/spec/ext_gpu_shader4/ directory
265 dirname = 'spec/ext_gpu_shader4/compiler'
266 utils.safe_makedirs(dirname)
268 for params in UNARY_OP_TESTS:
269 for type1 in params.types:
270 name = os.path.join(
271 dirname,
272 "{func}-{type1}".format(
273 func=params.name,
274 type1=type1.replace(' ', '_')))
276 for stage in ['frag', 'vert']:
277 filename = '{0}.{1}'.format(name, stage)
278 print(filename)
279 with open(filename, 'w+') as f:
280 f.write(TEMPLATES.get_template(
281 '{0}.{1}.mako'.format('unary_op', stage)).render_unicode(
282 param=params,
283 type1=type1,
284 swizzle=get_swizzle(type1)))
286 for params in BINARY_OP_TESTS:
287 for types in params.types:
288 name = os.path.join(
289 dirname,
290 "{func}-{type1}-{type2}".format(
291 func=params.name,
292 type1=types[0].replace(' ', '_'),
293 type2=types[1].replace(' ', '_')))
294 result_type = types[0] if 'int' in types[1] else types[1]
296 for stage in ['frag', 'vert']:
297 filename = '{0}.{1}'.format(name, stage)
298 print(filename)
299 with open(filename, 'w+') as f:
300 f.write(TEMPLATES.get_template(
301 '{0}.{1}.mako'.format('binary_op', stage)).render_unicode(
302 param=params,
303 types=types,
304 result_type=result_type,
305 swizzle=get_swizzle(result_type)))
307 for tests in [('unary', UNARY_TESTS),
308 ('binary', BINARY_TESTS),
309 ('ternary', TERNARY_TESTS),
310 ('vec_compare', VEC_COMPARE_TESTS)]:
311 for params in tests[1]:
312 for type1 in params.type1:
313 name = os.path.join(
314 dirname,
315 "{func}-{type1}{type2}".format(
316 func=params.func,
317 type1=type1.replace(' ', '_'),
318 type2=('-' + params.type2 if 'type2' in params._fields else '').replace(' ', '_')))
320 for stage in ['frag', 'vert']:
321 filename = '{0}.{1}'.format(name, stage)
322 print(filename)
323 with open(filename, 'w+') as f:
324 f.write(TEMPLATES.get_template(
325 '{0}.{1}.mako'.format(tests[0], stage)).render_unicode(
326 param=params,
327 type1=type1,
328 type2=params.type2 if 'type2' in params._fields else type1,
329 swizzle=get_swizzle(type1),
330 bvec=get_bvec(type1)))
332 for tests in [('texture_size', SIZE_TESTS, ''),
333 ('texel_fetch', FETCH_TESTS, ''),
334 ('tex', TEXTURE_TESTS, ''),
335 ('tex_bias', BIAS_TESTS, ''),
336 ('tex_lod', LOD_TESTS, ''),
337 ('tex_grad', GRAD_TESTS, ''),
338 ('texel_fetch', FETCH_TESTS, 'Offset'),
339 ('tex', TEXTURE_TESTS, 'Offset'),
340 ('tex_bias', BIAS_TESTS, 'Offset'),
341 ('tex_lod', LOD_TESTS, 'Offset'),
342 ('tex_grad', GRAD_TESTS, 'Offset')]:
343 for params in tests[1]:
344 if tests[2] == 'Offset' and params.offsetcoord == '':
345 continue
347 for prefix in params.variants:
348 name = os.path.join(
349 dirname,
350 "{0}{func}{offset}-{prefix}sampler{sampler}-{coord}".format(
351 tests[0],
352 func='-' + params.func if 'func' in params._fields else '',
353 offset=tests[2],
354 prefix=prefix,
355 sampler=params.sampler,
356 coord=params.coord))
358 stages = ['frag']
359 if tests[0] != 'tex_bias':
360 stages = stages + ['vert']
362 for stage in stages:
363 filename = '{0}.{1}'.format(name, stage)
364 print(filename)
365 with open(filename, 'w+') as f:
366 f.write(TEMPLATES.get_template(
367 '{0}.{1}.mako'.format(tests[0], stage)).render_unicode(
368 param=params,
369 extensions=get_extensions(params.sampler),
370 prefix=prefix,
371 swizzle=get_swizzle(params.coord),
372 offset=tests[2]))
374 if __name__ == '__main__':
375 main()