Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
Jarkko Pöyry | 3c77ed4 | 2015-01-06 12:54:34 -0800 | [diff] [blame] | 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 | |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 23 | import os |
| 24 | import re |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 25 | import sys |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 26 | |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 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 |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 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")) |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 36 | OPENGL_INC_DIR = os.path.join(OPENGL_DIR, "wrapper") |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 37 | |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 38 | GL_SOURCE = khr_util.registry_cache.RegistrySource( |
| 39 | "gl.xml", |
Daniel Andrade Groppe | 485a2d1 | 2015-12-02 15:45:41 -0600 | [diff] [blame] | 40 | 32093, |
| 41 | "3292120320cacbc27009e7507656d7be17bb25f06876814c67eeffa369281eed") |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 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', |
Alexander Galazin | d99ba13 | 2017-02-23 13:01:18 +0100 | [diff] [blame] | 51 | 'GL_EXT_robustness', |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 52 | 'GL_EXT_texture_buffer', |
| 53 | 'GL_EXT_texture_snorm', |
Jarkko Pöyry | 1f99d69 | 2014-11-17 14:21:54 -0800 | [diff] [blame] | 54 | 'GL_EXT_primitive_bounding_box', |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 55 | 'GL_OES_EGL_image', |
| 56 | 'GL_OES_compressed_ETC1_RGB8_texture', |
| 57 | 'GL_OES_texture_half_float', |
| 58 | 'GL_OES_texture_storage_multisample_2d_array', |
| 59 | 'GL_OES_sample_shading', |
Jarkko Pöyry | eb0aaf2 | 2014-12-16 14:11:01 -0800 | [diff] [blame] | 60 | 'GL_EXT_texture_compression_s3tc', |
| 61 | 'GL_IMG_texture_compression_pvrtc', |
Mika Isojärvi | 13e452c | 2015-01-08 16:11:32 -0800 | [diff] [blame] | 62 | 'GL_EXT_copy_image', |
Jarkko Pöyry | 7af3c6f | 2015-02-12 15:27:33 -0800 | [diff] [blame] | 63 | 'GL_EXT_draw_buffers_indexed', |
| 64 | 'GL_EXT_texture_sRGB_decode', |
| 65 | 'GL_EXT_texture_border_clamp', |
Jarkko Pöyry | 8bf16f2 | 2015-03-17 13:48:45 -0700 | [diff] [blame] | 66 | 'GL_EXT_texture_sRGB_R8', |
| 67 | 'GL_EXT_texture_sRGB_RG8', |
Pyry Haulos | 1a9576a | 2015-05-20 15:36:20 -0700 | [diff] [blame] | 68 | 'GL_EXT_debug_marker', |
Mika Isojärvi | 68cdd49 | 2016-03-10 13:35:20 -0800 | [diff] [blame] | 69 | 'GL_EXT_robustness', |
| 70 | 'GL_KHR_robustness', |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 71 | ] |
| 72 | |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 73 | def getGLRegistry (): |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 74 | return khr_util.registry_cache.getRegistry(GL_SOURCE) |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 75 | |
| 76 | # return the name of a core command corresponding to an extension command. |
| 77 | # Ideally this should be done using the alias attribute of commands, but dEQP |
| 78 | # just strips the extension suffix. |
| 79 | def getCoreName (name): |
| 80 | return re.sub('[A-Z]+$', '', name) |
| 81 | |
| 82 | def getHybridInterface (): |
| 83 | # This is a bit awkward, since we have to create a strange hybrid |
| 84 | # interface that includes both GL and ES features and extensions. |
| 85 | registry = getGLRegistry() |
| 86 | glFeatures = registry.getFeatures('gl') |
| 87 | esFeatures = registry.getFeatures('gles2') |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 88 | spec = khr_util.registry.InterfaceSpec() |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 89 | |
| 90 | for feature in registry.getFeatures('gl'): |
| 91 | spec.addFeature(feature, 'gl', 'core') |
| 92 | |
| 93 | for feature in registry.getFeatures('gles2'): |
| 94 | spec.addFeature(feature, 'gles2') |
| 95 | |
| 96 | for extName in EXTENSIONS: |
| 97 | extension = registry.extensions[extName] |
| 98 | # Add all extensions using the ES2 api, but force even non-ES2 |
| 99 | # extensions to be included. |
| 100 | spec.addExtension(extension, 'gles2', 'core', force=True) |
| 101 | |
| 102 | # Remove redundant extension commands that are already provided by core. |
| 103 | for commandName in list(spec.commands): |
| 104 | coreName = getCoreName(commandName) |
| 105 | if coreName != commandName and coreName in spec.commands: |
| 106 | spec.commands.remove(commandName) |
| 107 | |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 108 | return khr_util.registry.createInterface(registry, spec, 'gles2') |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 109 | |
| 110 | def getInterface (registry, api, version=None, profile=None, **kwargs): |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 111 | spec = khr_util.registry.spec(registry, api, version, profile, **kwargs) |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 112 | if api == 'gl' and profile == 'core' and version < "3.2": |
| 113 | gl32 = registry.features['GL_VERSION_3_2'] |
| 114 | for eRemove in gl32.xpath('remove'): |
| 115 | spec.addComponent(eRemove) |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 116 | return khr_util.registry.createInterface(registry, spec, api) |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 117 | |
| 118 | def getVersionToken (api, version): |
| 119 | prefixes = { 'gles2': "ES", 'gl': "GL" } |
| 120 | return prefixes[api] + version.replace(".", "") |
| 121 | |
| 122 | def genCommandList(iface, renderCommand, directory, filename, align=False): |
| 123 | lines = map(renderCommand, iface.commands) |
| 124 | if align: |
| 125 | lines = indentLines(lines) |
| 126 | writeInlFile(os.path.join(directory, filename), lines) |
| 127 | |
| 128 | def genCommandLists(registry, renderCommand, check, directory, filePattern, align=False): |
| 129 | for eFeature in registry.features: |
| 130 | api = eFeature.get('api') |
| 131 | version = eFeature.get('number') |
| 132 | profile = check(api, version) |
| 133 | if profile is True: |
| 134 | profile = None |
| 135 | elif profile is False: |
| 136 | continue |
| 137 | iface = getInterface(registry, api, version=version, profile=profile) |
| 138 | filename = filePattern % getVersionToken(api, version) |
| 139 | genCommandList(iface, renderCommand, directory, filename, align) |
| 140 | |
| 141 | def getFunctionTypeName (funcName): |
| 142 | return "%sFunc" % funcName |
| 143 | |
| 144 | def getFunctionMemberName (funcName): |
| 145 | assert funcName[:2] == "gl" |
| 146 | if funcName[:5] == "glEGL": |
| 147 | # Otherwise we end up with gl.eGLImage... |
| 148 | return "egl%s" % funcName[5:] |
| 149 | else: |
| 150 | return "%c%s" % (funcName[2].lower(), funcName[3:]) |
| 151 | |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 152 | INL_HEADER = khr_util.format.genInlHeader("Khronos GL API description (gl.xml)", GL_SOURCE.getRevision()) |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 153 | |
| 154 | def writeInlFile (filename, source): |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 155 | khr_util.format.writeInlFile(filename, INL_HEADER, source) |
Pyry Haulos | 1abab60 | 2014-11-05 17:41:42 -0800 | [diff] [blame] | 156 | |
Pyry Haulos | a017863 | 2014-11-21 14:56:21 -0800 | [diff] [blame] | 157 | # Aliases from khr_util.common |
Pyry Haulos | 3c67e4f | 2014-12-19 15:45:39 -0800 | [diff] [blame] | 158 | indentLines = khr_util.format.indentLines |
| 159 | normalizeConstant = khr_util.format.normalizeConstant |
| 160 | commandParams = khr_util.format.commandParams |
| 161 | commandArgs = khr_util.format.commandArgs |