2 # Copyright © 2016 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 """Generate tests for extensions that affect the shading language.
24 This generates three tests per extensions.
25 - The first test asserts that if the extension is required it's defined
26 - The second test asserts that if the extension isn't available it's not
28 - The third test asserts that if the extension isn't available trying to
29 require it is an error.
31 These are glslparsertests.
33 If the requirement for the test is less than OpenGL Shader Language 140, then
34 two tests will be made, a core and a compat. If it's greater then only a core
35 will be made, these will have compat and core added to the name, respectively.
37 For OpenGL ES only one test will be generated, it will have es added to the
42 from __future__
import (
43 absolute_import
, division
, print_function
, unicode_literals
47 from templates
import template_dir
48 from modules
import utils
, glsl
50 _TEMPLATES
= template_dir(os
.path
.basename(os
.path
.splitext(__file__
)[0]))
51 ENABLED_TEMPLATE
= _TEMPLATES
.get_template('enabled.glsl.mako')
52 DISABLED_TEMPLATE
= _TEMPLATES
.get_template('disabled.glsl.mako')
53 UNDEFINED_TEMPLATE
= _TEMPLATES
.get_template('undefined-require.glsl.mako')
55 # A list of tuples with the full preprocess defined name, and the minimum
56 # supported version of that extension.
58 ("GL_ARB_draw_instanced", "110"),
59 ("GL_ARB_draw_buffers", "110"),
60 ("GL_ARB_enhanced_layouts", "140"),
61 ("GL_ARB_separate_shader_objects", "110"),
62 ("GL_ARB_texture_rectangle", "110"),
63 ("GL_AMD_shader_trinary_minmax", "110"),
64 ("GL_EXT_texture_array", "110"),
65 ("GL_ARB_ES3_1_compatibility", "430"),
66 ("GL_ARB_arrays_of_arrays", "110"),
67 ("GL_ARB_fragment_coord_conventions", "110"),
68 ("GL_ARB_fragment_layer_viewport", "150"),
69 ("GL_ARB_explicit_attrib_location", "110"),
70 ("GL_ARB_explicit_uniform_location", "110"),
71 ("GL_ARB_shader_texture_lod", "110"),
72 ("GL_AMD_conservative_depth", "110"),
73 ("GL_ARB_conservative_depth", "110"),
74 ("GL_ARB_shader_bit_encoding", "110"),
75 ("GL_ARB_shader_clock", "110"),
76 ("GL_ARB_uniform_buffer_object", "110"),
77 ("GL_ARB_texture_cube_map_array", "110"),
78 ("GL_ARB_shading_language_packing", "110"),
79 ("GL_ARB_texture_multisample", "110"),
80 ("GL_ARB_texture_query_levels", "110"),
81 ("GL_ARB_texture_query_lod", "110"),
82 ("GL_ARB_gpu_shader5", "150"),
83 ("GL_ARB_gpu_shader_fp64", "150"),
84 ("GL_ARB_vertex_attrib_64bit", "150"),
85 ("GL_AMD_vertex_shader_layer", "130"),
86 ("GL_AMD_vertex_shader_viewport_index", "110"),
87 ("GL_ARB_shading_language_420pack", "110"),
88 ("GL_ARB_sample_shading", "110"),
89 ("GL_ARB_texture_gather", "110"),
90 ("GL_ARB_shader_atomic_counters", "110"),
91 ("GL_ARB_shader_atomic_counter_ops", "140"),
92 ("GL_ARB_viewport_array", "110"),
93 ("GL_ARB_compute_shader", "110"),
94 ("GL_ARB_shader_image_load_store", "130"),
95 ("GL_ARB_shader_image_size", "110"),
96 ("GL_ARB_shader_texture_image_samples", "110"),
97 # That is what the original hand written test required.
98 ("GL_ARB_derivative_control", "150"),
99 ("GL_ARB_shader_precision", "110"),
100 ("GL_ARB_shader_storage_buffer_object", "110"),
101 ("GL_ARB_tessellation_shader", "150"),
102 ("GL_ARB_shader_subroutine", "150"),
103 ("GL_ARB_shader_draw_parameters", "140"),
104 ("GL_EXT_separate_shader_objects", "100"),
105 ("GL_EXT_draw_buffers", "100"),
106 ("GL_AMD_shader_stencil_export", "120"),
107 ("GL_ARB_shader_stencil_export", "120"),
108 ("GL_ARB_geometry_shader4", "110"),
109 ("GL_OES_EGL_image_external", "100"),
110 ("GL_EXT_shader_samples_identical", "110"),
111 ("GL_ARB_shader_group_vote", "110"),
112 ("GL_EXT_shader_samples_identical", "310 es"),
113 ("GL_OES_sample_variables", "300 es"),
114 ("GL_OES_multisample_interpolation", "300 es"),
115 ("GL_OES_standard_derivatives", "100"),
116 ("GL_OES_texture_storage_multisample_2d_array", "310 es"),
117 ("GL_OES_blend_func_extended", "100"),
118 ("GL_OES_shader_image_atomic", "310 es"),
119 ("GL_OES_shader_io_blocks", "310 es"),
120 ("GL_EXT_shader_io_blocks", "310 es"),
121 ("GL_OES_geometry_shader", "310 es"),
122 ("GL_EXT_geometry_shader", "310 es"),
123 ("GL_OES_geometry_point_size", "310 es"),
124 ("GL_EXT_geometry_point_size", "310 es"),
125 ("GL_EXT_gpu_shader5", "310 es"),
126 ("GL_OES_gpu_shader5", "310 es"),
127 ("GL_EXT_texture_buffer", "310 es"),
128 ("GL_OES_texture_buffer", "310 es"),
129 ("GL_EXT_clip_cull_distance", "300 es"),
130 ("GL_NV_image_formats", "310 es"),
132 EXTENSIONS
= [(n
, glsl
.Version(v
)) for n
, v
in EXTENSIONS
]
135 def _gen_tests(ext
, version
, stage
, path
, extra_name
, extra_extensions
):
136 """Generate the actual test files.
138 This generates both a disabled test for both disabled and enabled
142 ext -- the extension to be tested
143 version -- the minimum required version
144 stage -- the shader stage to test
145 path -- the path to put the test in, without the test name
146 extra_name -- An extra string to put in the test name.
147 extra_extensions -- Any extra extensions requires.
150 for test
, template
in [('enabled', ENABLED_TEMPLATE
),
151 ('disabled-defined', DISABLED_TEMPLATE
),
152 ('disabled-undefined', UNDEFINED_TEMPLATE
)]:
153 name
= os
.path
.join(path
, '{}-{}.{}'.format(test
, extra_name
, stage
))
155 # Open in bytes mode to avoid weirdness in python 2/3 compatibility
156 with
open(name
, 'wb') as f
:
157 f
.write(template
.render(
160 extra_extensions
=extra_extensions
))
166 for ext
, ver
in EXTENSIONS
:
167 # Lower ext in the path name, but keep it capitalized for the generated
169 path
= os
.path
.join('spec', ext
[3:].lower(), 'preprocessor')
170 utils
.safe_makedirs(path
)
172 for stage
in ['vert', 'frag', 'geom', 'tesc', 'tese', 'comp']:
173 # Calculate the minimum version for the stage, with extensions.
174 # This makes the maximum number of tests run on the widest swath of
176 version
, extra_ext
= glsl
.MinVersion
.for_stage_with_ext(stage
, ver
)
177 if extra_ext
is not None:
178 extra_extensions
= [extra_ext
]
180 extra_extensions
= []
182 if not version
.is_es
:
183 # if the actual version is less than 140 make a compat test and
184 # a core test, otherwise just make a core test
186 _gen_tests(ext
, version
, stage
, path
, 'compat',
188 _gen_tests(ext
, glsl
.Version('140'), stage
, path
, 'core',
191 _gen_tests(ext
, version
, stage
, path
, 'core',
194 _gen_tests(ext
, version
, stage
, path
, 'es', extra_extensions
)
197 if __name__
== '__main__':