Update Vulkan CTS to version 1.0.2.3 am: 148890e79f
[platform/upstream/VK-GL-CTS.git] / scripts / opengl / src_util.py
1 # -*- coding: utf-8 -*-
2
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
6 #
7 # Copyright 2015-2017 The Android Open Source Project
8 #
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 #
21 #-------------------------------------------------------------------------
22
23 import os
24 import re
25 import sys
26
27 sys.path.append(os.path.dirname(os.path.dirname(__file__)))
28
29 import khr_util.format
30 import khr_util.registry
31 import khr_util.registry_cache
32
33 SCRIPTS_DIR                     = os.path.dirname(__file__)
34 OPENGL_DIR                      = os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "opengl"))
35 EGL_DIR                         = os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "egl"))
36 OPENGL_INC_DIR          = os.path.join(OPENGL_DIR, "wrapper")
37
38 GL_SOURCE                       = khr_util.registry_cache.RegistrySource(
39                                                 "https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry",
40                                                 "xml/gl.xml",
41                                                 "97558118d4a8ab2af749867899555273c20827ce",
42                                                 "2475e1ff6d69048e67a49188d8be09195b261ed96b2b4108a0f7d7a459834674")
43
44 EXTENSIONS                      = [
45         'GL_KHR_texture_compression_astc_ldr',
46         'GL_KHR_blend_equation_advanced',
47         'GL_KHR_blend_equation_advanced_coherent',
48         'GL_KHR_debug',
49         'GL_KHR_robustness',
50         'GL_KHR_no_error',
51         'GL_EXT_bgra',
52         'GL_EXT_geometry_point_size',
53         'GL_EXT_tessellation_shader',
54         'GL_EXT_geometry_shader',
55         'GL_EXT_robustness',
56         'GL_EXT_texture_buffer',
57         'GL_EXT_texture_filter_anisotropic',
58         'GL_EXT_texture_cube_map_array',
59         'GL_EXT_texture_snorm',
60         'GL_EXT_primitive_bounding_box',
61         'GL_EXT_texture_compression_s3tc',
62         'GL_EXT_texture_type_2_10_10_10_REV',
63         'GL_EXT_copy_image',
64         'GL_EXT_depth_bounds_test',
65         'GL_EXT_direct_state_access',
66         'GL_EXT_draw_buffers_indexed',
67         'GL_EXT_draw_elements_base_vertex',
68         'GL_EXT_direct_state_access',
69         'GL_EXT_read_format_bgra',
70         'GL_EXT_texture_storage',
71         'GL_EXT_texture_sRGB_decode',
72         'GL_EXT_texture_border_clamp',
73         'GL_EXT_texture_sRGB_R8',
74         'GL_EXT_texture_sRGB_RG8',
75         'GL_EXT_debug_marker',
76         'GL_EXT_polygon_offset_clamp',
77         'GL_IMG_texture_compression_pvrtc',
78         'GL_OES_EGL_image',
79         'GL_OES_EGL_image_external',
80         'GL_OES_compressed_ETC1_RGB8_texture',
81         'GL_OES_compressed_paletted_texture',
82         'GL_OES_required_internalformat',
83         'GL_OES_packed_depth_stencil',
84         'GL_OES_texture_3D',
85         'GL_OES_texture_half_float',
86         'GL_OES_texture_storage_multisample_2d_array',
87         'GL_OES_sample_shading',
88         'GL_OES_standard_derivatives',
89         'GL_OES_stencil1',
90         'GL_OES_stencil4',
91         'GL_OES_surfaceless_context',
92         'GL_OES_mapbuffer',
93         'GL_OES_vertex_array_object',
94         'GL_OES_viewport_array',
95         'GL_ARB_clip_control',
96         'GL_ARB_buffer_storage',
97         'GL_ARB_compute_shader',
98         'GL_ARB_draw_instanced',
99         'GL_ARB_draw_elements_base_vertex',
100         'GL_ARB_direct_state_access',
101         'GL_ARB_get_program_binary',
102         'GL_ARB_indirect_parameters',
103         'GL_ARB_internalformat_query',
104         'GL_ARB_instanced_arrays',
105         'GL_ARB_multi_draw_indirect',
106         'GL_ARB_parallel_shader_compile',
107         'GL_ARB_program_interface_query',
108         'GL_ARB_separate_shader_objects',
109         'GL_ARB_shader_ballot',
110         'GL_ARB_shader_image_load_store',
111         'GL_ARB_shader_viewport_layer_array',
112         'GL_ARB_sparse_buffer',
113         'GL_ARB_sparse_texture',
114         'GL_ARB_tessellation_shader',
115         'GL_ARB_texture_barrier',
116         'GL_ARB_texture_filter_minmax',
117         'GL_ARB_texture_gather',
118         'GL_ARB_texture_storage',
119         'GL_ARB_texture_storage_multisample',
120         'GL_ARB_texture_multisample',
121         'GL_ARB_texture_view',
122         'GL_ARB_transform_feedback2',
123         'GL_ARB_transform_feedback3',
124         'GL_ARB_transform_feedback_instanced',
125         'GL_ARB_transform_feedback_overflow_query',
126         'GL_ARB_vertex_array_bgra',
127         'GL_ARB_vertex_attrib_64bit',
128         'GL_ARB_vertex_attrib_binding',
129         'GL_NV_deep_texture3D',
130         'GL_NV_internalformat_sample_query',
131         'GL_OES_draw_elements_base_vertex',
132 ]
133
134 def getGLRegistry ():
135         return khr_util.registry_cache.getRegistry(GL_SOURCE)
136
137 def getHybridInterface (stripAliasedExtCommands = True):
138         # This is a bit awkward, since we have to create a strange hybrid
139         # interface that includes both GL and ES features and extensions.
140         registry = getGLRegistry()
141         glFeatures = registry.getFeatures('gl')
142         esFeatures = registry.getFeatures('gles2')
143         spec = khr_util.registry.InterfaceSpec()
144
145         for feature in registry.getFeatures('gl'):
146                 spec.addFeature(feature, 'gl', 'core')
147
148         for feature in registry.getFeatures('gles2'):
149                 spec.addFeature(feature, 'gles2')
150
151         for extName in EXTENSIONS:
152                 extension = registry.extensions[extName]
153                 # Add all extensions using the ES2 api, but force even non-ES2
154                 # extensions to be included.
155                 spec.addExtension(extension, 'gles2', 'core', force=True)
156
157         iface = khr_util.registry.createInterface(registry, spec, 'gles2')
158
159         if stripAliasedExtCommands:
160                 # Remove redundant extension commands that are already provided by core.
161                 strippedCmds = []
162
163                 for command in iface.commands:
164                         if command.alias == None:
165                                 strippedCmds.append(command)
166
167                 iface.commands = strippedCmds
168
169         return iface
170
171 def getInterface (registry, api, version=None, profile=None, **kwargs):
172         spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
173         if api == 'gl' and profile == 'core' and version < "3.2":
174                 gl32 = registry.features['GL_VERSION_3_2']
175                 for eRemove in gl32.xpath('remove'):
176                         spec.addComponent(eRemove)
177         return khr_util.registry.createInterface(registry, spec, api)
178
179 def getVersionToken (api, version):
180         prefixes = { 'gles2': "ES", 'gl': "GL" }
181         return prefixes[api] + version.replace(".", "")
182
183 def genCommandList(iface, renderCommand, directory, filename, align=False):
184         lines = map(renderCommand, iface.commands)
185         lines = filter(lambda l: l != None, lines)
186         if align:
187                 lines = indentLines(lines)
188         writeInlFile(os.path.join(directory, filename), lines)
189
190 def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
191         for eFeature in registry.features:
192                 api                     = eFeature.get('api')
193                 version         = eFeature.get('number')
194                 profile         = check(api, version)
195                 if profile is True:
196                         profile = None
197                 elif profile is False:
198                         continue
199                 iface           = getInterface(registry, api, version=version, profile=profile)
200                 filename        = filePattern % getVersionToken(api, version)
201                 genCommandList(iface, renderCommand, directory, filename, align)
202
203 def getFunctionTypeName (funcName):
204         return "%sFunc" % funcName
205
206 def getFunctionMemberName (funcName):
207         assert funcName[:2] == "gl"
208         if funcName[:5] == "glEGL":
209                 # Otherwise we end up with gl.eGLImage...
210                 return "egl%s" % funcName[5:]
211         else:
212                 return "%c%s" % (funcName[2].lower(), funcName[3:])
213
214 INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
215
216 def writeInlFile (filename, source):
217         khr_util.format.writeInlFile(filename, INL_HEADER, source)
218
219 # Aliases from khr_util.common
220 indentLines                     = khr_util.format.indentLines
221 normalizeConstant       = khr_util.format.normalizeConstant
222 commandParams           = khr_util.format.commandParams
223 commandArgs                     = khr_util.format.commandArgs