perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / generated_tests / gen_gpu_shader4_tests.py
blobc92f938558c14b2ef90e660f634628da3b301c69
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
27 import sys
29 from mako import exceptions
31 from templates import template_dir
32 from modules import utils
34 TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
36 vec = ['vec2', 'vec3', 'vec4']
37 ivec = ['ivec2', 'ivec3', 'ivec4']
38 uvec = ['uvec2', 'uvec3', 'uvec4']
40 genType = ['float'] + vec
41 genIType = ['int'] + ivec
42 genUType = ['unsigned int'] + uvec
44 ShiftOpTypes = [
45 ('int', 'int'), ('unsigned int', 'unsigned int'),
46 ('ivec2', 'ivec2'), ('ivec3', 'ivec3'), ('ivec4', 'ivec4'),
47 ('uvec2', 'uvec2'), ('uvec3', 'uvec3'), ('uvec4', 'uvec4'),
49 ('ivec2', 'int'), ('ivec3', 'int'), ('ivec4', 'int'),
50 ('uvec2', 'unsigned int'), ('uvec3', 'unsigned int'), ('uvec4', 'unsigned int'),
53 BinaryOpTypes = ShiftOpTypes + [
54 ('int', 'ivec2'), ('int', 'ivec3'), ('int', 'ivec4'),
55 ('unsigned int', 'uvec2'), ('unsigned int', 'uvec3'), ('unsigned int', 'uvec4'),
58 OperatorParams = collections.namedtuple(
59 'OperatorParams', ['name', 'op', 'types'])
61 UNARY_OP_TESTS = [
62 OperatorParams('bitwise-not', '~', genIType + genUType),
65 BINARY_OP_TESTS = [
66 OperatorParams('mod', '%', BinaryOpTypes),
67 OperatorParams('bitwise-and', '&', BinaryOpTypes),
68 OperatorParams('bitwise-or', '|', BinaryOpTypes),
69 OperatorParams('xor', '^', BinaryOpTypes),
70 OperatorParams('lshift', '<<', ShiftOpTypes),
71 OperatorParams('rshift', '>>', ShiftOpTypes),
75 Type1Params = collections.namedtuple(
76 'Type1Params', ['func', 'type1'])
77 Type2Params = collections.namedtuple(
78 'Type2Params', ['func', 'type1', 'type2'])
80 UNARY_TESTS = [
81 Type1Params('abs', genIType),
82 Type1Params('sign', genIType),
83 Type1Params('truncate', genType),
84 Type1Params('round', genType),
87 BINARY_TESTS = [
88 Type1Params('min', genIType),
89 Type2Params('min', ivec, 'int'),
90 Type1Params('min', genUType),
91 Type2Params('min', uvec, 'unsigned int'),
93 Type1Params('max', genIType),
94 Type2Params('max', ivec, 'int'),
95 Type1Params('max', genUType),
96 Type2Params('max', uvec, 'unsigned int'),
99 TERNARY_TESTS = [
100 Type1Params('clamp', genIType),
101 Type2Params('clamp', ivec, 'int'),
102 Type1Params('clamp', genUType),
103 Type2Params('clamp', uvec, 'unsigned int'),
106 VEC_COMPARE_TESTS = [
107 Type1Params('lessThan', uvec),
108 Type1Params('lessThanEqual', uvec),
109 Type1Params('greaterThan', uvec),
110 Type1Params('greaterThanEqual', uvec),
111 Type1Params('equal', uvec),
112 Type1Params('notEqual', uvec),
116 FLOAT = ['']
117 INT = ['i', 'u']
118 ALL = FLOAT + INT
120 FetchParams = collections.namedtuple(
121 'FetchParams', ['sampler', 'coord', 'offsetcoord', 'variants'])
123 FETCH_TESTS = [
124 FetchParams('1D', 'int', 'int', ALL),
125 FetchParams('2D', 'ivec2', 'ivec2', ALL),
126 FetchParams('3D', 'ivec3', 'ivec3', ALL),
127 FetchParams('2DRect', 'ivec2', 'ivec2', ALL),
128 FetchParams('1DArray', 'ivec2', 'int', ALL),
129 FetchParams('2DArray', 'ivec3', 'ivec2', ALL),
130 FetchParams('Buffer', 'int', '', ALL),
133 SIZE_TESTS = FETCH_TESTS + [
134 FetchParams('Cube', 'ivec2', '', ALL),
138 TextureParams = collections.namedtuple(
139 'TextureParams', ['func', 'sampler', 'coord', 'offsetcoord', 'variants'])
141 # Variants: std, bias, lod
142 COMMON_TEXTURE_TESTS = [
143 # Inherited from GLSL 1.10, test integer textures
144 TextureParams('texture1D', '1D', 'float', 'int', INT),
145 TextureParams('texture1DProj', '1D', 'vec2', 'int', INT),
146 TextureParams('texture1DProj', '1D', 'vec4', 'int', INT),
148 TextureParams('texture2D', '2D', 'vec2', 'ivec2', INT),
149 TextureParams('texture2DProj', '2D', 'vec3', 'ivec2', INT),
150 TextureParams('texture2DProj', '2D', 'vec4', 'ivec2', INT),
152 TextureParams('texture3D', '3D', 'vec3', 'ivec3', INT),
153 TextureParams('texture3DProj', '3D', 'vec4', 'ivec3', INT),
155 TextureParams('textureCube', 'Cube', 'vec3', '', INT),
157 # Added by GL_EXT_gpu_shader4
158 TextureParams('texture1DArray', '1DArray', 'vec2', 'int', ALL),
159 TextureParams('texture2DArray', '2DArray', 'vec3', 'ivec2', ALL),
161 TextureParams('shadow1D', '1DShadow', 'vec3', 'int', FLOAT),
162 TextureParams('shadow2D', '2DShadow', 'vec3', 'ivec2', FLOAT),
163 TextureParams('shadow1DProj', '1DShadow', 'vec4', 'int', FLOAT),
164 TextureParams('shadow2DProj', '2DShadow', 'vec4', 'ivec2', FLOAT),
165 TextureParams('shadow1DArray', '1DArrayShadow', 'vec3', 'int', FLOAT),
168 TEXTURE_TESTS = COMMON_TEXTURE_TESTS + [
169 TextureParams('shadow2DArray', '2DArrayShadow', 'vec4', 'ivec2', FLOAT),
170 TextureParams('shadowCube', 'CubeShadow', 'vec4', '', FLOAT),
172 # Inherited from ARB_texture_rectangle, test integer textures
173 TextureParams('texture2DRect', '2DRect', 'vec2', 'ivec2', INT),
174 TextureParams('texture2DRectProj', '2DRect', 'vec3', 'ivec2', INT),
175 TextureParams('texture2DRectProj', '2DRect', 'vec4', 'ivec2', INT),
176 TextureParams('shadow2DRect', '2DRectShadow', 'vec3', 'ivec2', FLOAT),
177 TextureParams('shadow2DRectProj', '2DRectShadow', 'vec4', 'ivec2', FLOAT),
180 LOD_TESTS = COMMON_TEXTURE_TESTS
181 BIAS_TESTS = COMMON_TEXTURE_TESTS
184 GradParams = collections.namedtuple(
185 'GradParams', ['coord', 'grad', 'offsetcoord', 'sampler', 'func', 'variants'])
187 GRAD_TESTS = [
188 GradParams('float', 'float', 'int', '1D', 'texture1D', ALL),
189 GradParams('vec2', 'float', 'int', '1D', 'texture1DProj', ALL),
190 GradParams('vec4', 'float', 'int', '1D', 'texture1DProj', ALL),
191 GradParams('vec2', 'float', 'int', '1DArray', 'texture1DArray', ALL),
193 GradParams('vec2', 'vec2', 'ivec2', '2D', 'texture2D', ALL),
194 GradParams('vec3', 'vec2', 'ivec2', '2D', 'texture2DProj', ALL),
195 GradParams('vec4', 'vec2', 'ivec2', '2D', 'texture2DProj', ALL),
196 GradParams('vec3', 'vec2', 'ivec2', '2DArray', 'texture2DArray', ALL),
198 GradParams('vec3', 'vec3', 'ivec3', '3D', 'texture3D', ALL),
199 GradParams('vec4', 'vec3', 'ivec3', '3D', 'texture3DProj', ALL),
201 GradParams('vec3', 'vec3', '', 'Cube', 'textureCube', ALL),
203 GradParams('vec3', 'float', 'int', '1DShadow', 'shadow1D', FLOAT),
204 GradParams('vec4', 'float', 'int', '1DShadow', 'shadow1DProj', FLOAT),
205 GradParams('vec3', 'float', 'int', '1DArrayShadow', 'shadow1DArray', FLOAT),
207 GradParams('vec3', 'vec2', 'ivec2', '2DShadow', 'shadow2D', FLOAT),
208 GradParams('vec4', 'vec2', 'ivec2', '2DShadow', 'shadow2DProj', FLOAT),
209 GradParams('vec4', 'vec2', 'ivec2', '2DArrayShadow', 'shadow2DArray', FLOAT),
211 GradParams('vec2', 'vec2', 'ivec2', '2DRect', 'texture2DRect', ALL),
212 GradParams('vec3', 'vec2', 'ivec2', '2DRect', 'texture2DRectProj', ALL),
213 GradParams('vec4', 'vec2', 'ivec2', '2DRect', 'texture2DRectProj', ALL),
215 GradParams('vec3', 'vec2', 'ivec2', '2DRectShadow', 'shadow2DRect', FLOAT),
216 GradParams('vec4', 'vec2', 'ivec2', '2DRectShadow', 'shadow2DRectProj', FLOAT),
218 GradParams('vec4', 'vec3', '', 'CubeShadow', 'shadowCube', FLOAT),
221 def get_swizzle(vtype):
223 Expand the type to vec4.
225 if '3' in vtype:
226 return '.xyzz';
227 if '2' in vtype:
228 return '.xyyy';
229 return '';
231 def get_bvec(vtype):
233 Return the corresponding bvec type.
235 if '4' in vtype:
236 return 'bvec4';
237 if '3' in vtype:
238 return 'bvec3';
239 if '2' in vtype:
240 return 'bvec2';
241 return 'invalid';
243 def get_extensions(sampler):
244 """ If this test uses GL_ARB_texture_rectangle add it
246 GL_ARB_texture_rectangle is an odd extension, it is on by default, so don't
247 generate a #extension in the shader, just in the config block.
250 if 'Rect' in sampler:
251 return 'GL_EXT_gpu_shader4 GL_ARB_texture_rectangle'
253 if 'Array' in sampler:
254 return 'GL_EXT_gpu_shader4 GL_EXT_texture_array'
256 if 'Buffer' in sampler:
257 return 'GL_EXT_gpu_shader4 GL_EXT_texture_buffer_object'
259 return 'GL_EXT_gpu_shader4'
262 def main():
263 """ Main function
265 Writes tests to generated_tests/spec/ext_gpu_shader4/ directory
268 dirname = 'spec/ext_gpu_shader4/compiler'
269 utils.safe_makedirs(dirname)
271 for params in UNARY_OP_TESTS:
272 for type1 in params.types:
273 name = os.path.join(
274 dirname,
275 "{func}-{type1}".format(
276 func=params.name,
277 type1=type1.replace(' ', '_')))
279 for stage in ['frag', 'vert']:
280 filename = '{0}.{1}'.format(name, stage)
281 print(filename)
282 with open(filename, 'w+') as f:
283 try:
284 f.write(TEMPLATES.get_template(
285 '{0}.{1}.mako'.format('unary_op', stage)).render_unicode(
286 param=params,
287 type1=type1,
288 swizzle=get_swizzle(type1)))
289 except:
290 print(exceptions.text_error_template().render(), file=sys.stderr)
291 raise
293 for params in BINARY_OP_TESTS:
294 for types in params.types:
295 name = os.path.join(
296 dirname,
297 "{func}-{type1}-{type2}".format(
298 func=params.name,
299 type1=types[0].replace(' ', '_'),
300 type2=types[1].replace(' ', '_')))
301 result_type = types[0] if 'int' in types[1] else types[1]
303 for stage in ['frag', 'vert']:
304 filename = '{0}.{1}'.format(name, stage)
305 print(filename)
306 with open(filename, 'w+') as f:
307 try:
308 f.write(TEMPLATES.get_template(
309 '{0}.{1}.mako'.format('binary_op', stage)).render_unicode(
310 param=params,
311 types=types,
312 result_type=result_type,
313 swizzle=get_swizzle(result_type)))
314 except:
315 print(exceptions.text_error_template().render(), file=sys.stderr)
316 raise
318 for tests in [('unary', UNARY_TESTS),
319 ('binary', BINARY_TESTS),
320 ('ternary', TERNARY_TESTS),
321 ('vec_compare', VEC_COMPARE_TESTS)]:
322 for params in tests[1]:
323 for type1 in params.type1:
324 name = os.path.join(
325 dirname,
326 "{func}-{type1}{type2}".format(
327 func=params.func,
328 type1=type1.replace(' ', '_'),
329 type2=('-' + params.type2 if 'type2' in params._fields else '').replace(' ', '_')))
331 for stage in ['frag', 'vert']:
332 filename = '{0}.{1}'.format(name, stage)
333 print(filename)
334 with open(filename, 'w+') as f:
335 try:
336 f.write(TEMPLATES.get_template(
337 '{0}.{1}.mako'.format(tests[0], stage)).render_unicode(
338 param=params,
339 type1=type1,
340 type2=params.type2 if 'type2' in params._fields else type1,
341 swizzle=get_swizzle(type1),
342 bvec=get_bvec(type1)))
343 except:
344 print(exceptions.text_error_template().render(), file=sys.stderr)
345 raise
347 for tests in [('texture_size', SIZE_TESTS, ''),
348 ('texel_fetch', FETCH_TESTS, ''),
349 ('tex', TEXTURE_TESTS, ''),
350 ('tex_bias', BIAS_TESTS, ''),
351 ('tex_lod', LOD_TESTS, ''),
352 ('tex_grad', GRAD_TESTS, ''),
353 ('texel_fetch', FETCH_TESTS, 'Offset'),
354 ('tex', TEXTURE_TESTS, 'Offset'),
355 ('tex_bias', BIAS_TESTS, 'Offset'),
356 ('tex_lod', LOD_TESTS, 'Offset'),
357 ('tex_grad', GRAD_TESTS, 'Offset')]:
358 for params in tests[1]:
359 if tests[2] == 'Offset' and params.offsetcoord == '':
360 continue
362 for prefix in params.variants:
363 name = os.path.join(
364 dirname,
365 "{0}{func}{offset}-{prefix}sampler{sampler}-{coord}".format(
366 tests[0],
367 func='-' + params.func if 'func' in params._fields else '',
368 offset=tests[2],
369 prefix=prefix,
370 sampler=params.sampler,
371 coord=params.coord))
373 stages = ['frag']
374 if tests[0] != 'tex_bias':
375 stages = stages + ['vert']
377 for stage in stages:
378 filename = '{0}.{1}'.format(name, stage)
379 print(filename)
380 with open(filename, 'w+') as f:
381 try:
382 f.write(TEMPLATES.get_template(
383 '{0}.{1}.mako'.format(tests[0], stage)).render_unicode(
384 param=params,
385 extensions=get_extensions(params.sampler),
386 prefix=prefix,
387 swizzle=get_swizzle(params.coord),
388 offset=tests[2]))
389 except:
390 print(exceptions.text_error_template().render(), file=sys.stderr)
391 raise
393 if __name__ == '__main__':
394 main()