Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 2 | # |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 3 | # Copyright (c) 2015-2016 The Khronos Group Inc. |
| 4 | # Copyright (c) 2015-2016 Valve Corporation |
| 5 | # Copyright (c) 2015-2016 LunarG, Inc. |
| 6 | # Copyright (c) 2015-2016 Google Inc. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 7 | # |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 11 | # |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 13 | # |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
Chia-I Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 19 | # |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 20 | # Author: Chia-I Wu <olv@lunarg.com> |
| 21 | # Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
| 22 | # Author: Jon Ashburn <jon@lunarg.com> |
Mun, Gwan-gyeong | 83ae0c0 | 2016-02-22 20:23:59 +0900 | [diff] [blame] | 23 | # Author: Gwan-gyeong Mun <kk.moon@samsung.com> |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 24 | |
| 25 | import sys |
| 26 | |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 27 | import vulkan |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 28 | |
Chia-I Wu | f7d6d3c | 2015-01-05 12:55:13 +0800 | [diff] [blame] | 29 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 30 | return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ |
| 31 | " return NULL;" % ((name,) * 3) |
Chia-I Wu | f7d6d3c | 2015-01-05 12:55:13 +0800 | [diff] [blame] | 32 | |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 33 | class Subcommand(object): |
| 34 | def __init__(self, argv): |
| 35 | self.argv = argv |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 36 | self.headers = vulkan.headers |
| 37 | self.protos = vulkan.protos |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 38 | |
| 39 | def run(self): |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 40 | print(self.generate()) |
| 41 | |
| 42 | def generate(self): |
| 43 | copyright = self.generate_copyright() |
| 44 | header = self.generate_header() |
| 45 | body = self.generate_body() |
| 46 | footer = self.generate_footer() |
| 47 | |
| 48 | contents = [] |
| 49 | if copyright: |
| 50 | contents.append(copyright) |
| 51 | if header: |
| 52 | contents.append(header) |
| 53 | if body: |
| 54 | contents.append(body) |
| 55 | if footer: |
| 56 | contents.append(footer) |
| 57 | |
| 58 | return "\n\n".join(contents) |
| 59 | |
| 60 | def generate_copyright(self): |
| 61 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 62 | |
| 63 | /* |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 64 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 65 | * Copyright (c) 2015-2016 Valve Corporation |
| 66 | * Copyright (c) 2015-2016 LunarG, Inc. |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 67 | * |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 68 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 69 | * you may not use this file except in compliance with the License. |
| 70 | * You may obtain a copy of the License at |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 71 | * |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 72 | * http://www.apache.org/licenses/LICENSE-2.0 |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 73 | * |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 74 | * Unless required by applicable law or agreed to in writing, software |
| 75 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 76 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 77 | * See the License for the specific language governing permissions and |
| 78 | * limitations under the License. |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 79 | * |
| 80 | * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 81 | */""" |
| 82 | |
| 83 | def generate_header(self): |
Chia-I Wu | 6ae460f | 2014-09-13 13:36:06 +0800 | [diff] [blame] | 84 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 85 | |
| 86 | def generate_body(self): |
| 87 | pass |
| 88 | |
| 89 | def generate_footer(self): |
| 90 | pass |
| 91 | |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 92 | class DispatchTableOpsSubcommand(Subcommand): |
| 93 | def run(self): |
| 94 | if len(self.argv) != 1: |
| 95 | print("DispatchTableOpsSubcommand: <prefix> unspecified") |
| 96 | return |
| 97 | |
| 98 | self.prefix = self.argv[0] |
Michael Lentine | 9268944 | 2015-09-09 12:39:13 -0700 | [diff] [blame] | 99 | super(DispatchTableOpsSubcommand, self).run() |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 100 | |
| 101 | def generate_header(self): |
David Pinedo | 329ca9e | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 102 | return "\n".join(["#include <vulkan/vulkan.h>", |
| 103 | "#include <vulkan/vk_layer.h>", |
Jon Ashburn | aef6588 | 2015-05-04 09:16:41 -0600 | [diff] [blame] | 104 | "#include <string.h>"]) |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 105 | |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 106 | def _generate_init_dispatch(self, type): |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 107 | stmts = [] |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 108 | func = [] |
| 109 | if type == "device": |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 110 | # GPA has to be first one and uses wrapped object |
Courtney Goeltzenleuchter | f83cd4a | 2015-06-26 15:05:29 -0600 | [diff] [blame] | 111 | stmts.append("memset(table, 0, sizeof(*table));") |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 112 | stmts.append("table->GetDeviceProcAddr =(PFN_vkGetDeviceProcAddr) gpa(device,\"vkGetDeviceProcAddr\");") |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 113 | for proto in self.protos: |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 114 | if proto.name == "CreateInstance" or proto.name == "EnumerateInstanceExtensionProperties" or proto.name == "EnumerateInstanceLayerProperties" or proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice": |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 115 | continue |
Jon Ashburn | 83334db | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 116 | if proto.name != "GetDeviceProcAddr" and 'KHR' not in proto.name: |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 117 | stmts.append("table->%s = (PFN_vk%s) gpa(device, \"vk%s\");" % |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 118 | (proto.name, proto.name, proto.name)) |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 119 | func.append("static inline void %s_init_device_dispatch_table(VkDevice device," |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 120 | % self.prefix) |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 121 | func.append("%s VkLayerDispatchTable *table," |
| 122 | % (" " * len(self.prefix))) |
| 123 | func.append("%s PFN_vkGetDeviceProcAddr gpa)" |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 124 | % (" " * len(self.prefix))) |
| 125 | else: |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 126 | stmts.append("table->GetInstanceProcAddr =(PFN_vkGetInstanceProcAddr) gpa(instance,\"vkGetInstanceProcAddr\");") |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 127 | for proto in self.protos: |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 128 | if proto.params[0].ty != "VkInstance" and proto.params[0].ty != "VkPhysicalDevice": |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 129 | continue |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 130 | if proto.name == "CreateDevice": |
| 131 | continue |
Jon Ashburn | 83334db | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 132 | if proto.name != "GetInstanceProcAddr" and 'KHR' not in proto.name: |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 133 | stmts.append("table->%s = (PFN_vk%s) gpa(instance, \"vk%s\");" % |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 134 | (proto.name, proto.name, proto.name)) |
Courtney Goeltzenleuchter | 2bdf6da | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 135 | func.append("static inline void %s_init_instance_dispatch_table(" % self.prefix) |
| 136 | func.append("%s VkInstance instance," % (" " * len(self.prefix))) |
| 137 | func.append("%s VkLayerInstanceDispatchTable *table," % (" " * len(self.prefix))) |
| 138 | func.append("%s PFN_vkGetInstanceProcAddr gpa)" % (" " * len(self.prefix))) |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 139 | func.append("{") |
| 140 | func.append(" %s" % "\n ".join(stmts)) |
| 141 | func.append("}") |
| 142 | |
| 143 | return "\n".join(func) |
| 144 | |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 145 | def generate_body(self): |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 146 | body = [self._generate_init_dispatch("device"), |
| 147 | self._generate_init_dispatch("instance")] |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 148 | |
| 149 | return "\n\n".join(body) |
| 150 | |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 151 | class WinDefFileSubcommand(Subcommand): |
| 152 | def run(self): |
| 153 | library_exports = { |
| 154 | "all": [], |
| 155 | "icd": [ |
Jon Ashburn | 89a1c46 | 2016-01-07 09:46:26 -0700 | [diff] [blame] | 156 | "vk_icdGetInstanceProcAddr", |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 157 | ], |
| 158 | "layer": [ |
Jon Ashburn | 88049b1 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 159 | "vkGetInstanceProcAddr", |
| 160 | "vkGetDeviceProcAddr", |
Courtney Goeltzenleuchter | 74c4ce9 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 161 | "vkEnumerateInstanceLayerProperties", |
| 162 | "vkEnumerateInstanceExtensionProperties" |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 163 | ], |
Mark Lobodzinski | 2e87e61 | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 164 | "layer_multi": [ |
Jon Ashburn | 88049b1 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 165 | "multi2GetInstanceProcAddr", |
| 166 | "multi1GetDeviceProcAddr" |
| 167 | ] |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | if len(self.argv) != 2 or self.argv[1] not in library_exports: |
| 171 | print("WinDefFileSubcommand: <library-name> {%s}" % |
| 172 | "|".join(library_exports.keys())) |
| 173 | return |
| 174 | |
| 175 | self.library = self.argv[0] |
Mark Lobodzinski | 2e87e61 | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 176 | if self.library == "VkLayer_multi": |
| 177 | self.exports = library_exports["layer_multi"] |
Jon Ashburn | 88049b1 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 178 | else: |
| 179 | self.exports = library_exports[self.argv[1]] |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 180 | |
Jamie Madill | 725788c | 2016-04-04 11:20:24 -0400 | [diff] [blame] | 181 | super(WinDefFileSubcommand, self).run() |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 182 | |
| 183 | def generate_copyright(self): |
| 184 | return """; THIS FILE IS GENERATED. DO NOT EDIT. |
| 185 | |
| 186 | ;;;; Begin Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 187 | ; Vulkan |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 188 | ; |
Karl Schultz | c85a02f | 2016-02-02 19:32:33 -0700 | [diff] [blame] | 189 | ; Copyright (c) 2015-2016 The Khronos Group Inc. |
| 190 | ; Copyright (c) 2015-2016 Valve Corporation |
| 191 | ; Copyright (c) 2015-2016 LunarG, Inc. |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 192 | ; |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 193 | ; Licensed under the Apache License, Version 2.0 (the "License"); |
| 194 | ; you may not use this file except in compliance with the License. |
| 195 | ; You may obtain a copy of the License at |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 196 | ; |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 197 | ; http://www.apache.org/licenses/LICENSE-2.0 |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 198 | ; |
Jon Ashburn | 43b53e8 | 2016-04-19 11:30:31 -0600 | [diff] [blame^] | 199 | ; Unless required by applicable law or agreed to in writing, software |
| 200 | ; distributed under the License is distributed on an "AS IS" BASIS, |
| 201 | ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 202 | ; See the License for the specific language governing permissions and |
| 203 | ; limitations under the License. |
Courtney Goeltzenleuchter | cf8ff4f | 2015-12-16 14:57:27 -0700 | [diff] [blame] | 204 | ; |
| 205 | ; Author: Courtney Goeltzenleuchter <courtney@LunarG.com> |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 206 | ;;;; End Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;""" |
| 207 | |
| 208 | def generate_header(self): |
| 209 | return "; The following is required on Windows, for exporting symbols from the DLL" |
| 210 | |
| 211 | def generate_body(self): |
| 212 | body = [] |
| 213 | |
| 214 | body.append("LIBRARY " + self.library) |
| 215 | body.append("EXPORTS") |
| 216 | |
Jon Ashburn | 88049b1 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 217 | for proto in self.exports: |
Mark Lobodzinski | 2e87e61 | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 218 | if self.library != "VkLayerSwapchain" or proto != "vkEnumerateInstanceExtensionProperties" and proto != "vkEnumerateInstanceLayerProperties": |
Ian Elliott | 329da01 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 219 | body.append( proto) |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 220 | |
| 221 | return "\n".join(body) |
| 222 | |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 223 | def main(): |
Mun, Gwan-gyeong | 83ae0c0 | 2016-02-22 20:23:59 +0900 | [diff] [blame] | 224 | wsi = { |
| 225 | "Win32", |
| 226 | "Android", |
| 227 | "Xcb", |
| 228 | "Xlib", |
| 229 | "Wayland", |
| 230 | "Mir" |
| 231 | } |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 232 | subcommands = { |
Chia-I Wu | 28b8d8c | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 233 | "dispatch-table-ops": DispatchTableOpsSubcommand, |
Chia-I Wu | d98a23c | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 234 | "win-def-file": WinDefFileSubcommand, |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 235 | } |
| 236 | |
Mun, Gwan-gyeong | 83ae0c0 | 2016-02-22 20:23:59 +0900 | [diff] [blame] | 237 | if len(sys.argv) < 3 or sys.argv[1] not in wsi or sys.argv[2] not in subcommands: |
| 238 | print("Usage: %s <wsi> <subcommand> [options]" % sys.argv[0]) |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 239 | print |
| 240 | print("Available sucommands are: %s" % " ".join(subcommands)) |
| 241 | exit(1) |
| 242 | |
Mun, Gwan-gyeong | 83ae0c0 | 2016-02-22 20:23:59 +0900 | [diff] [blame] | 243 | subcmd = subcommands[sys.argv[2]](sys.argv[3:]) |
Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 244 | subcmd.run() |
| 245 | |
| 246 | if __name__ == "__main__": |
| 247 | main() |