am c807fa97: (-s ours) am c0636411: am 0870de9a: DO NOT MERGE Do not require signed...
[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 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                                                 "gl.xml",
40                                                 30159,
41                                                 "0af7e185d0db15e9f44a1b6ff6c72102f67509a8590f19a289b983d652008070")
42
43 EXTENSIONS                      = [
44         'GL_KHR_texture_compression_astc_ldr',
45         'GL_KHR_blend_equation_advanced',
46         'GL_KHR_blend_equation_advanced_coherent',
47         'GL_KHR_debug',
48         'GL_EXT_geometry_point_size',
49         'GL_EXT_tessellation_shader',
50         'GL_EXT_geometry_shader',
51         'GL_EXT_texture_buffer',
52         'GL_EXT_texture_snorm',
53         'GL_EXT_primitive_bounding_box',
54         'GL_OES_EGL_image',
55         'GL_OES_compressed_ETC1_RGB8_texture',
56         'GL_OES_texture_half_float',
57         'GL_OES_texture_storage_multisample_2d_array',
58         'GL_OES_sample_shading',
59         'GL_EXT_texture_compression_s3tc',
60         'GL_IMG_texture_compression_pvrtc',
61         'GL_EXT_copy_image',
62         'GL_EXT_draw_buffers_indexed',
63         'GL_EXT_texture_sRGB_decode',
64         'GL_EXT_texture_border_clamp',
65         'GL_EXT_texture_sRGB_R8',
66         'GL_EXT_texture_sRGB_RG8',
67 ]
68
69 def getGLRegistry ():
70         return khr_util.registry_cache.getRegistry(GL_SOURCE)
71
72 # return the name of a core command corresponding to an extension command.
73 # Ideally this should be done using the alias attribute of commands, but dEQP
74 # just strips the extension suffix.
75 def getCoreName (name):
76         return re.sub('[A-Z]+$', '', name)
77
78 def getHybridInterface ():
79         # This is a bit awkward, since we have to create a strange hybrid
80         # interface that includes both GL and ES features and extensions.
81         registry = getGLRegistry()
82         glFeatures = registry.getFeatures('gl')
83         esFeatures = registry.getFeatures('gles2')
84         spec = khr_util.registry.InterfaceSpec()
85
86         for feature in registry.getFeatures('gl'):
87                 spec.addFeature(feature, 'gl', 'core')
88
89         for feature in registry.getFeatures('gles2'):
90                 spec.addFeature(feature, 'gles2')
91
92         for extName in EXTENSIONS:
93                 extension = registry.extensions[extName]
94                 # Add all extensions using the ES2 api, but force even non-ES2
95                 # extensions to be included.
96                 spec.addExtension(extension, 'gles2', 'core', force=True)
97
98         # Remove redundant extension commands that are already provided by core.
99         for commandName in list(spec.commands):
100                 coreName = getCoreName(commandName)
101                 if coreName != commandName and coreName in spec.commands:
102                         spec.commands.remove(commandName)
103
104         return khr_util.registry.createInterface(registry, spec, 'gles2')
105
106 def getInterface (registry, api, version=None, profile=None, **kwargs):
107         spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
108         if api == 'gl' and profile == 'core' and version < "3.2":
109                 gl32 = registry.features['GL_VERSION_3_2']
110                 for eRemove in gl32.xpath('remove'):
111                         spec.addComponent(eRemove)
112         return khr_util.registry.createInterface(registry, spec, api)
113
114 def getVersionToken (api, version):
115         prefixes = { 'gles2': "ES", 'gl': "GL" }
116         return prefixes[api] + version.replace(".", "")
117
118 def genCommandList(iface, renderCommand, directory, filename, align=False):
119         lines = map(renderCommand, iface.commands)
120         if align:
121                 lines = indentLines(lines)
122         writeInlFile(os.path.join(directory, filename), lines)
123
124 def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
125         for eFeature in registry.features:
126                 api                     = eFeature.get('api')
127                 version         = eFeature.get('number')
128                 profile         = check(api, version)
129                 if profile is True:
130                         profile = None
131                 elif profile is False:
132                         continue
133                 iface           = getInterface(registry, api, version=version, profile=profile)
134                 filename        = filePattern % getVersionToken(api, version)
135                 genCommandList(iface, renderCommand, directory, filename, align)
136
137 def getFunctionTypeName (funcName):
138         return "%sFunc" % funcName
139
140 def getFunctionMemberName (funcName):
141         assert funcName[:2] == "gl"
142         if funcName[:5] == "glEGL":
143                 # Otherwise we end up with gl.eGLImage...
144                 return "egl%s" % funcName[5:]
145         else:
146                 return "%c%s" % (funcName[2].lower(), funcName[3:])
147
148 INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
149
150 def writeInlFile (filename, source):
151         khr_util.format.writeInlFile(filename, INL_HEADER, source)
152
153 # Aliases from khr_util.common
154 indentLines                     = khr_util.format.indentLines
155 normalizeConstant       = khr_util.format.normalizeConstant
156 commandParams           = khr_util.format.commandParams
157 commandArgs                     = khr_util.format.commandArgs