• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
23import os
24import re
25import sys
26
27sys.path.append(os.path.dirname(os.path.dirname(__file__)))
28
29import khr_util.format
30import khr_util.registry
31import khr_util.registry_cache
32
33SCRIPTS_DIR			= os.path.dirname(__file__)
34OPENGL_DIR			= os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "opengl"))
35EGL_DIR				= os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "egl"))
36OPENGL_INC_DIR		= os.path.join(OPENGL_DIR, "wrapper")
37
38GL_SOURCE			= khr_util.registry_cache.RegistrySource(
39						"https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry",
40						"xml/gl.xml",
41						"9d534f9312e56c72df763207e449c6719576fd54",
42						"245e90331c83c4c743a2b9d0dad51e27a699f2040ebd34dd5338637adf276752")
43
44EXTENSIONS			= [
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_EXT_robustness',
50	'GL_KHR_robustness',
51	'GL_KHR_no_error',
52	'GL_KHR_parallel_shader_compile',
53	'GL_KHR_shader_subgroup',
54	'GL_EXT_bgra',
55	'GL_EXT_geometry_point_size',
56	'GL_EXT_tessellation_shader',
57	'GL_EXT_geometry_shader',
58	'GL_EXT_texture_buffer',
59	'GL_EXT_texture_filter_anisotropic',
60	'GL_EXT_texture_cube_map_array',
61	'GL_EXT_texture_snorm',
62	'GL_EXT_primitive_bounding_box',
63	'GL_EXT_texture_compression_s3tc',
64	'GL_EXT_texture_type_2_10_10_10_REV',
65	'GL_EXT_clip_control',
66	'GL_EXT_copy_image',
67	'GL_EXT_depth_bounds_test',
68	'GL_EXT_direct_state_access',
69	'GL_EXT_draw_buffers_indexed',
70	'GL_EXT_draw_elements_base_vertex',
71	'GL_EXT_direct_state_access',
72	'GL_EXT_read_format_bgra',
73	'GL_EXT_texture_storage',
74	'GL_EXT_texture_sRGB_decode',
75	'GL_EXT_texture_border_clamp',
76	'GL_EXT_texture_sRGB_R8',
77	'GL_EXT_texture_sRGB_RG8',
78	'GL_EXT_multisampled_render_to_texture',
79	'GL_EXT_debug_marker',
80	'GL_EXT_polygon_offset_clamp',
81	'GL_IMG_texture_compression_pvrtc',
82	'GL_OES_EGL_image',
83	'GL_OES_EGL_image_external',
84	'GL_OES_compressed_ETC1_RGB8_texture',
85	'GL_OES_compressed_paletted_texture',
86	'GL_OES_required_internalformat',
87	'GL_OES_packed_depth_stencil',
88	'GL_OES_texture_3D',
89	'GL_OES_texture_half_float',
90	'GL_OES_texture_storage_multisample_2d_array',
91	'GL_OES_sample_shading',
92	'GL_OES_standard_derivatives',
93	'GL_OES_stencil1',
94	'GL_OES_stencil4',
95	'GL_OES_surfaceless_context',
96	'GL_OES_mapbuffer',
97	'GL_OES_vertex_array_object',
98	'GL_OES_viewport_array',
99	'GL_ARB_clip_control',
100	'GL_ARB_buffer_storage',
101	'GL_ARB_compute_shader',
102	'GL_ARB_draw_indirect',
103	'GL_ARB_draw_instanced',
104	'GL_ARB_draw_elements_base_vertex',
105	'GL_ARB_direct_state_access',
106	'GL_ARB_get_program_binary',
107	'GL_ARB_gl_spirv',
108	'GL_ARB_indirect_parameters',
109	'GL_ARB_internalformat_query',
110	'GL_ARB_instanced_arrays',
111	'GL_ARB_multi_draw_indirect',
112	'GL_ARB_parallel_shader_compile',
113	'GL_ARB_program_interface_query',
114	'GL_ARB_separate_shader_objects',
115	'GL_ARB_shader_ballot',
116	'GL_ARB_shader_image_load_store',
117	'GL_ARB_shader_viewport_layer_array',
118	'GL_ARB_sparse_buffer',
119	'GL_ARB_sparse_texture',
120	'GL_ARB_spirv_extensions',
121	'GL_ARB_tessellation_shader',
122	'GL_ARB_texture_barrier',
123	'GL_ARB_texture_filter_minmax',
124	'GL_ARB_texture_gather',
125	'GL_ARB_texture_storage',
126	'GL_ARB_texture_storage_multisample',
127	'GL_ARB_texture_multisample',
128	'GL_ARB_texture_view',
129	'GL_ARB_transform_feedback2',
130	'GL_ARB_transform_feedback3',
131	'GL_ARB_transform_feedback_instanced',
132	'GL_ARB_transform_feedback_overflow_query',
133	'GL_ARB_vertex_array_bgra',
134	'GL_ARB_vertex_attrib_64bit',
135	'GL_ARB_vertex_attrib_binding',
136	'GL_NV_deep_texture3D',
137	'GL_NV_gpu_multicast',
138	'GL_NV_internalformat_sample_query',
139	'GL_NV_shader_subgroup_partitioned',
140	'GL_NVX_cross_process_interop',
141	'GL_OES_draw_elements_base_vertex',
142	'GL_OVR_multiview',
143	'GL_OVR_multiview_multisampled_render_to_texture',
144]
145
146ALIASING_EXCEPTIONS = [
147	# registry insists that this aliases glRenderbufferStorageMultisample,
148	# and from a desktop GL / GLX perspective it *must*, but for ES they are
149	# unfortunately separate functions with different semantics.
150	'glRenderbufferStorageMultisampleEXT',
151]
152
153def getGLRegistry ():
154	return khr_util.registry_cache.getRegistry(GL_SOURCE)
155
156def getHybridInterface (stripAliasedExtCommands = True):
157	# This is a bit awkward, since we have to create a strange hybrid
158	# interface that includes both GL and ES features and extensions.
159	registry = getGLRegistry()
160	glFeatures = registry.getFeatures('gl')
161	esFeatures = registry.getFeatures('gles2')
162	spec = khr_util.registry.InterfaceSpec()
163
164	for feature in registry.getFeatures('gl'):
165		spec.addFeature(feature, 'gl', 'core')
166
167	for feature in registry.getFeatures('gles2'):
168		spec.addFeature(feature, 'gles2')
169
170	for extName in EXTENSIONS:
171		extension = registry.extensions[extName]
172		# Add all extensions using the ES2 api, but force even non-ES2
173		# extensions to be included.
174		spec.addExtension(extension, 'gles2', 'core', force=True)
175
176	iface = khr_util.registry.createInterface(registry, spec, 'gles2')
177
178	if stripAliasedExtCommands:
179		# Remove redundant extension commands that are already provided by core.
180		strippedCmds = []
181
182		for command in iface.commands:
183			if command.alias == None or command.name in ALIASING_EXCEPTIONS:
184				strippedCmds.append(command)
185
186		iface.commands = strippedCmds
187
188	return iface
189
190def versionCheck(version):
191	if type(version) is bool:
192		if version == False:
193			return True
194	if type(version) is str:
195		return version < "3.2"
196	raise "Version check failed"
197
198def getInterface (registry, api, version=None, profile=None, **kwargs):
199	spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
200	if api == 'gl' and profile == 'core' and versionCheck(version):
201		gl32 = registry.features['GL_VERSION_3_2']
202		for eRemove in gl32.xpath('remove'):
203			spec.addComponent(eRemove)
204	return khr_util.registry.createInterface(registry, spec, api)
205
206def getVersionToken (api, version):
207	prefixes = { 'gles2': "ES", 'gl': "GL" }
208	return prefixes[api] + version.replace(".", "")
209
210def genCommandList(iface, renderCommand, directory, filename, align=False):
211	lines = map(renderCommand, iface.commands)
212	lines = filter(lambda l: l != None, lines)
213	if align:
214		lines = indentLines(lines)
215	writeInlFile(os.path.join(directory, filename), lines)
216
217def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
218	for eFeature in registry.features:
219		api			= eFeature.get('api')
220		version		= eFeature.get('number')
221		profile		= check(api, version)
222		if profile is True:
223			profile = None
224		elif profile is False:
225			continue
226		iface		= getInterface(registry, api, version=version, profile=profile)
227		filename	= filePattern % getVersionToken(api, version)
228		genCommandList(iface, renderCommand, directory, filename, align)
229
230def getFunctionTypeName (funcName):
231	return "%sFunc" % funcName
232
233def getFunctionMemberName (funcName):
234	assert funcName[:2] == "gl"
235	if funcName[:5] == "glEGL":
236		# Otherwise we end up with gl.eGLImage...
237		return "egl%s" % funcName[5:]
238	else:
239		return "%c%s" % (funcName[2].lower(), funcName[3:])
240
241INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
242
243def writeInlFile (filename, source):
244	khr_util.format.writeInlFile(filename, INL_HEADER, source)
245
246# Aliases from khr_util.common
247indentLines			= khr_util.format.indentLines
248normalizeConstant	= khr_util.format.normalizeConstant
249commandParams		= khr_util.format.commandParams
250commandArgs			= khr_util.format.commandArgs
251