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
23 """ Generate spec/EXT_gpu_shader4 tests """
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
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'])
62 OperatorParams('bitwise-not', '~', genIType
+ genUType
),
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'])
81 Type1Params('abs', genIType
),
82 Type1Params('sign', genIType
),
83 Type1Params('truncate', genType
),
84 Type1Params('round', genType
),
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'),
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
),
120 FetchParams
= collections
.namedtuple(
121 'FetchParams', ['sampler', 'coord', 'offsetcoord', 'variants'])
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'])
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.
233 Return the corresponding bvec type.
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'
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
:
275 "{func}-{type1}".format(
277 type1
=type1
.replace(' ', '_')))
279 for stage
in ['frag', 'vert']:
280 filename
= '{0}.{1}'.format(name
, stage
)
282 with
open(filename
, 'w+') as f
:
284 f
.write(TEMPLATES
.get_template(
285 '{0}.{1}.mako'.format('unary_op', stage
)).render_unicode(
288 swizzle
=get_swizzle(type1
)))
290 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
293 for params
in BINARY_OP_TESTS
:
294 for types
in params
.types
:
297 "{func}-{type1}-{type2}".format(
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
)
306 with
open(filename
, 'w+') as f
:
308 f
.write(TEMPLATES
.get_template(
309 '{0}.{1}.mako'.format('binary_op', stage
)).render_unicode(
312 result_type
=result_type
,
313 swizzle
=get_swizzle(result_type
)))
315 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
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
:
326 "{func}-{type1}{type2}".format(
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
)
334 with
open(filename
, 'w+') as f
:
336 f
.write(TEMPLATES
.get_template(
337 '{0}.{1}.mako'.format(tests
[0], stage
)).render_unicode(
340 type2
=params
.type2
if 'type2' in params
._fields
else type1
,
341 swizzle
=get_swizzle(type1
),
342 bvec
=get_bvec(type1
)))
344 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
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
== '':
362 for prefix
in params
.variants
:
365 "{0}{func}{offset}-{prefix}sampler{sampler}-{coord}".format(
367 func
='-' + params
.func
if 'func' in params
._fields
else '',
370 sampler
=params
.sampler
,
374 if tests
[0] != 'tex_bias':
375 stages
= stages
+ ['vert']
378 filename
= '{0}.{1}'.format(name
, stage
)
380 with
open(filename
, 'w+') as f
:
382 f
.write(TEMPLATES
.get_template(
383 '{0}.{1}.mako'.format(tests
[0], stage
)).render_unicode(
385 extensions
=get_extensions(params
.sampler
),
387 swizzle
=get_swizzle(params
.coord
),
390 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
393 if __name__
== '__main__':