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
44 from templates
import template_dir
45 from modules
import utils
, glsl
47 _TEMPLATES
= template_dir(os
.path
.basename(os
.path
.splitext(__file__
)[0]))
48 ENABLED_TEMPLATE
= _TEMPLATES
.get_template('enabled.glsl.mako')
49 DISABLED_TEMPLATE
= _TEMPLATES
.get_template('disabled.glsl.mako')
50 UNDEFINED_TEMPLATE
= _TEMPLATES
.get_template('undefined-require.glsl.mako')
52 # A list of tuples with the full preprocess defined name, and the minimum
53 # supported version of that extension.
55 ("GL_ARB_draw_instanced", "110"),
56 ("GL_ARB_draw_buffers", "110"),
57 ("GL_ARB_enhanced_layouts", "140"),
58 ("GL_ARB_separate_shader_objects", "110"),
59 ("GL_ARB_texture_rectangle", "110"),
60 ("GL_AMD_shader_trinary_minmax", "110"),
61 ("GL_EXT_texture_array", "110"),
62 ("GL_ARB_ES3_1_compatibility", "430"),
63 ("GL_ARB_arrays_of_arrays", "110"),
64 ("GL_ARB_fragment_coord_conventions", "110"),
65 ("GL_ARB_fragment_layer_viewport", "150"),
66 ("GL_ARB_explicit_attrib_location", "110"),
67 ("GL_ARB_explicit_uniform_location", "110"),
68 ("GL_ARB_shader_texture_lod", "110"),
69 ("GL_AMD_conservative_depth", "110"),
70 ("GL_ARB_conservative_depth", "110"),
71 ("GL_ARB_shader_bit_encoding", "110"),
72 ("GL_ARB_shader_clock", "110"),
73 ("GL_ARB_uniform_buffer_object", "110"),
74 ("GL_ARB_texture_cube_map_array", "110"),
75 ("GL_ARB_shading_language_packing", "110"),
76 ("GL_ARB_texture_multisample", "110"),
77 ("GL_ARB_texture_query_levels", "110"),
78 ("GL_ARB_texture_query_lod", "110"),
79 ("GL_ARB_gpu_shader5", "150"),
80 ("GL_ARB_gpu_shader_fp64", "150"),
81 ("GL_ARB_vertex_attrib_64bit", "150"),
82 ("GL_AMD_vertex_shader_layer", "130"),
83 ("GL_AMD_vertex_shader_viewport_index", "110"),
84 ("GL_ARB_shading_language_420pack", "110"),
85 ("GL_ARB_sample_shading", "110"),
86 ("GL_ARB_texture_gather", "110"),
87 ("GL_ARB_shader_atomic_counters", "110"),
88 ("GL_ARB_shader_atomic_counter_ops", "140"),
89 ("GL_ARB_viewport_array", "110"),
90 ("GL_ARB_compute_shader", "110"),
91 ("GL_ARB_shader_image_load_store", "130"),
92 ("GL_ARB_shader_image_size", "110"),
93 ("GL_ARB_shader_texture_image_samples", "110"),
94 # That is what the original hand written test required.
95 ("GL_ARB_derivative_control", "150"),
96 ("GL_ARB_shader_precision", "110"),
97 ("GL_ARB_shader_storage_buffer_object", "110"),
98 ("GL_ARB_tessellation_shader", "150"),
99 ("GL_ARB_shader_subroutine", "150"),
100 ("GL_ARB_shader_draw_parameters", "140"),
101 ("GL_EXT_separate_shader_objects", "100"),
102 ("GL_EXT_draw_buffers", "100"),
103 ("GL_EXT_draw_instanced", "100"),
104 ("GL_AMD_shader_stencil_export", "120"),
105 ("GL_ARB_shader_stencil_export", "120"),
106 ("GL_ARB_geometry_shader4", "110"),
107 ("GL_OES_EGL_image_external", "100"),
108 ("GL_EXT_shader_samples_identical", "110"),
109 ("GL_ARB_shader_group_vote", "110"),
110 ("GL_EXT_shader_samples_identical", "310 es"),
111 ("GL_OES_sample_variables", "300 es"),
112 ("GL_OES_multisample_interpolation", "300 es"),
113 ("GL_OES_standard_derivatives", "100"),
114 ("GL_OES_texture_storage_multisample_2d_array", "310 es"),
115 ("GL_OES_blend_func_extended", "100"),
116 ("GL_OES_shader_image_atomic", "310 es"),
117 ("GL_OES_shader_io_blocks", "310 es"),
118 ("GL_EXT_shader_io_blocks", "310 es"),
119 ("GL_OES_geometry_shader", "310 es"),
120 ("GL_EXT_geometry_shader", "310 es"),
121 ("GL_OES_geometry_point_size", "310 es"),
122 ("GL_EXT_geometry_point_size", "310 es"),
123 ("GL_EXT_gpu_shader5", "310 es"),
124 ("GL_OES_gpu_shader5", "310 es"),
125 ("GL_EXT_texture_buffer", "310 es"),
126 ("GL_OES_texture_buffer", "310 es"),
127 ("GL_EXT_clip_cull_distance", "300 es"),
128 ("GL_NV_image_formats", "310 es"),
130 EXTENSIONS
= [(n
, glsl
.Version(v
)) for n
, v
in EXTENSIONS
]
133 def _gen_tests(ext
, version
, stage
, path
, extra_name
, extra_extensions
):
134 """Generate the actual test files.
136 This generates both a disabled test for both disabled and enabled
140 ext -- the extension to be tested
141 version -- the minimum required version
142 stage -- the shader stage to test
143 path -- the path to put the test in, without the test name
144 extra_name -- An extra string to put in the test name.
145 extra_extensions -- Any extra extensions requires.
148 for test
, template
in [('enabled', ENABLED_TEMPLATE
),
149 ('disabled-defined', DISABLED_TEMPLATE
),
150 ('disabled-undefined', UNDEFINED_TEMPLATE
)]:
151 name
= os
.path
.join(path
, '{}-{}.{}'.format(test
, extra_name
, stage
))
153 # Open in bytes mode to avoid weirdness in python 2/3 compatibility
154 with
open(name
, 'wb') as f
:
155 f
.write(template
.render(
158 extra_extensions
=extra_extensions
))
164 for ext
, ver
in EXTENSIONS
:
165 # Lower ext in the path name, but keep it capitalized for the generated
167 path
= os
.path
.join('spec', ext
[3:].lower(), 'preprocessor')
168 utils
.safe_makedirs(path
)
170 for stage
in ['vert', 'frag', 'geom', 'tesc', 'tese', 'comp']:
171 # Calculate the minimum version for the stage, with extensions.
172 # This makes the maximum number of tests run on the widest swath of
174 version
, extra_ext
= glsl
.MinVersion
.for_stage_with_ext(stage
, ver
)
175 if extra_ext
is not None:
176 extra_extensions
= [extra_ext
]
178 extra_extensions
= []
180 if not version
.is_es
:
181 # if the actual version is less than 140 make a compat test and
182 # a core test, otherwise just make a core test
184 _gen_tests(ext
, version
, stage
, path
, 'compat',
186 _gen_tests(ext
, glsl
.Version('140'), stage
, path
, 'core',
189 _gen_tests(ext
, version
, stage
, path
, 'core',
192 _gen_tests(ext
, version
, stage
, path
, 'es', extra_extensions
)
195 if __name__
== '__main__':