Add CTS_ARB_shader_draw_parameters tests implementation
[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                                                 "967f96c92bae15baa1a4326a55222984befdc9ed",
42                                                 "f281f2dc6b2206a8852670d161e15fa43723dac5042a991ff4e1702e29d7403d")
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_EXT_bgra',
51         'GL_EXT_geometry_point_size',
52         'GL_EXT_tessellation_shader',
53         'GL_EXT_geometry_shader',
54         'GL_EXT_robustness',
55         'GL_EXT_texture_buffer',
56         'GL_EXT_texture_cube_map_array',
57         'GL_EXT_texture_snorm',
58         'GL_EXT_primitive_bounding_box',
59         'GL_EXT_texture_compression_s3tc',
60         'GL_EXT_texture_type_2_10_10_10_REV',
61         'GL_EXT_copy_image',
62         'GL_EXT_depth_bounds_test',
63         'GL_EXT_direct_state_access',
64         'GL_EXT_draw_buffers_indexed',
65         'GL_EXT_draw_elements_base_vertex',
66         'GL_EXT_direct_state_access',
67         'GL_EXT_read_format_bgra',
68         'GL_EXT_texture_storage',
69         'GL_EXT_texture_sRGB_decode',
70         'GL_EXT_texture_border_clamp',
71         'GL_EXT_texture_sRGB_R8',
72         'GL_EXT_texture_sRGB_RG8',
73         'GL_EXT_debug_marker',
74         'GL_IMG_texture_compression_pvrtc',
75         'GL_OES_EGL_image',
76         'GL_OES_EGL_image_external',
77         'GL_OES_compressed_ETC1_RGB8_texture',
78         'GL_OES_compressed_paletted_texture',
79         'GL_OES_required_internalformat',
80         'GL_OES_packed_depth_stencil',
81         'GL_OES_texture_3D',
82         'GL_OES_texture_half_float',
83         'GL_OES_texture_storage_multisample_2d_array',
84         'GL_OES_sample_shading',
85         'GL_OES_standard_derivatives',
86         'GL_OES_stencil1',
87         'GL_OES_stencil4',
88         'GL_OES_surfaceless_context',
89         'GL_OES_mapbuffer',
90         'GL_OES_vertex_array_object',
91         'GL_OES_viewport_array',
92         'GL_ARB_clip_control',
93         'GL_ARB_buffer_storage',
94         'GL_ARB_compute_shader',
95         'GL_ARB_draw_instanced',
96         'GL_ARB_draw_elements_base_vertex',
97         'GL_ARB_direct_state_access',
98         'GL_ARB_get_program_binary',
99         'GL_ARB_indirect_parameters',
100         'GL_ARB_internalformat_query',
101         'GL_ARB_instanced_arrays',
102         'GL_ARB_multi_draw_indirect',
103         'GL_ARB_parallel_shader_compile',
104         'GL_ARB_program_interface_query',
105         'GL_ARB_separate_shader_objects',
106         'GL_ARB_shader_ballot',
107         'GL_ARB_shader_image_load_store',
108         'GL_ARB_sparse_buffer',
109         'GL_ARB_sparse_texture',
110         'GL_ARB_tessellation_shader',
111         'GL_ARB_texture_barrier',
112         'GL_ARB_texture_filter_minmax',
113         'GL_ARB_texture_gather',
114         'GL_ARB_texture_storage',
115         'GL_ARB_texture_storage_multisample',
116         'GL_ARB_texture_multisample',
117         'GL_ARB_texture_view',
118         'GL_ARB_transform_feedback2',
119         'GL_ARB_transform_feedback3',
120         'GL_ARB_transform_feedback_instanced',
121         'GL_ARB_transform_feedback_overflow_query',
122         'GL_ARB_vertex_array_bgra',
123         'GL_ARB_vertex_attrib_64bit',
124         'GL_ARB_vertex_attrib_binding',
125         'GL_NV_deep_texture3D',
126         'GL_NV_internalformat_sample_query',
127 ]
128
129 def getGLRegistry ():
130         return khr_util.registry_cache.getRegistry(GL_SOURCE)
131
132 def getHybridInterface (stripAliasedExtCommands = True):
133         # This is a bit awkward, since we have to create a strange hybrid
134         # interface that includes both GL and ES features and extensions.
135         registry = getGLRegistry()
136         glFeatures = registry.getFeatures('gl')
137         esFeatures = registry.getFeatures('gles2')
138         spec = khr_util.registry.InterfaceSpec()
139
140         for feature in registry.getFeatures('gl'):
141                 spec.addFeature(feature, 'gl', 'core')
142
143         for feature in registry.getFeatures('gles2'):
144                 spec.addFeature(feature, 'gles2')
145
146         for extName in EXTENSIONS:
147                 extension = registry.extensions[extName]
148                 # Add all extensions using the ES2 api, but force even non-ES2
149                 # extensions to be included.
150                 spec.addExtension(extension, 'gles2', 'core', force=True)
151
152         iface = khr_util.registry.createInterface(registry, spec, 'gles2')
153
154         if stripAliasedExtCommands:
155                 # Remove redundant extension commands that are already provided by core.
156                 strippedCmds = []
157
158                 for command in iface.commands:
159                         if command.alias == None:
160                                 strippedCmds.append(command)
161
162                 iface.commands = strippedCmds
163
164         return iface
165
166 def getInterface (registry, api, version=None, profile=None, **kwargs):
167         spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
168         if api == 'gl' and profile == 'core' and version < "3.2":
169                 gl32 = registry.features['GL_VERSION_3_2']
170                 for eRemove in gl32.xpath('remove'):
171                         spec.addComponent(eRemove)
172         return khr_util.registry.createInterface(registry, spec, api)
173
174 def getVersionToken (api, version):
175         prefixes = { 'gles2': "ES", 'gl': "GL" }
176         return prefixes[api] + version.replace(".", "")
177
178 def genCommandList(iface, renderCommand, directory, filename, align=False):
179         lines = map(renderCommand, iface.commands)
180         lines = filter(lambda l: l != None, lines)
181         if align:
182                 lines = indentLines(lines)
183         writeInlFile(os.path.join(directory, filename), lines)
184
185 def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False):
186         for eFeature in registry.features:
187                 api                     = eFeature.get('api')
188                 version         = eFeature.get('number')
189                 profile         = check(api, version)
190                 if profile is True:
191                         profile = None
192                 elif profile is False:
193                         continue
194                 iface           = getInterface(registry, api, version=version, profile=profile)
195                 filename        = filePattern % getVersionToken(api, version)
196                 genCommandList(iface, renderCommand, directory, filename, align)
197
198 def getFunctionTypeName (funcName):
199         return "%sFunc" % funcName
200
201 def getFunctionMemberName (funcName):
202         assert funcName[:2] == "gl"
203         if funcName[:5] == "glEGL":
204                 # Otherwise we end up with gl.eGLImage...
205                 return "egl%s" % funcName[5:]
206         else:
207                 return "%c%s" % (funcName[2].lower(), funcName[3:])
208
209 INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision())
210
211 def writeInlFile (filename, source):
212         khr_util.format.writeInlFile(filename, INL_HEADER, source)
213
214 # Aliases from khr_util.common
215 indentLines                     = khr_util.format.indentLines
216 normalizeConstant       = khr_util.format.normalizeConstant
217 commandParams           = khr_util.format.commandParams
218 commandArgs                     = khr_util.format.commandArgs