| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
| Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 2 | # | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | # VK | 
| Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 4 | # | 
 | 5 | # Copyright (C) 2014 LunarG, Inc. | 
| Michael Lentine | 695f2c2 | 2015-09-09 12:39:13 -0700 | [diff] [blame] | 6 | # Copyright (C) 2015 Google Inc. | 
| Chia-I Wu | 701f3f6 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 7 | # | 
 | 8 | # Permission is hereby granted, free of charge, to any person obtaining a | 
 | 9 | # copy of this software and associated documentation files (the "Software"), | 
 | 10 | # to deal in the Software without restriction, including without limitation | 
 | 11 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
 | 12 | # and/or sell copies of the Software, and to permit persons to whom the | 
 | 13 | # Software is furnished to do so, subject to the following conditions: | 
 | 14 | # | 
 | 15 | # The above copyright notice and this permission notice shall be included | 
 | 16 | # in all copies or substantial portions of the Software. | 
 | 17 | # | 
 | 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
 | 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
 | 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
 | 21 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
 | 22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 
 | 23 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
 | 24 | # DEALINGS IN THE SOFTWARE. | 
 | 25 | # | 
 | 26 | # Authors: | 
 | 27 | #   Chia-I Wu <olv@lunarg.com> | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 28 |  | 
 | 29 | import sys | 
 | 30 |  | 
| Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 31 | import vulkan | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 32 |  | 
| Chia-I Wu | 6cdaedb | 2015-01-05 12:55:13 +0800 | [diff] [blame] | 33 | def generate_get_proc_addr_check(name): | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 34 |     return "    if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ | 
 | 35 |            "        return NULL;" % ((name,) * 3) | 
| Chia-I Wu | 6cdaedb | 2015-01-05 12:55:13 +0800 | [diff] [blame] | 36 |  | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 37 | class Subcommand(object): | 
 | 38 |     def __init__(self, argv): | 
 | 39 |         self.argv = argv | 
| Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 40 |         self.headers = vulkan.headers | 
 | 41 |         self.protos = vulkan.protos | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 42 |  | 
 | 43 |     def run(self): | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 44 |         print(self.generate()) | 
 | 45 |  | 
 | 46 |     def generate(self): | 
 | 47 |         copyright = self.generate_copyright() | 
 | 48 |         header = self.generate_header() | 
 | 49 |         body = self.generate_body() | 
 | 50 |         footer = self.generate_footer() | 
 | 51 |  | 
 | 52 |         contents = [] | 
 | 53 |         if copyright: | 
 | 54 |             contents.append(copyright) | 
 | 55 |         if header: | 
 | 56 |             contents.append(header) | 
 | 57 |         if body: | 
 | 58 |             contents.append(body) | 
 | 59 |         if footer: | 
 | 60 |             contents.append(footer) | 
 | 61 |  | 
 | 62 |         return "\n\n".join(contents) | 
 | 63 |  | 
 | 64 |     def generate_copyright(self): | 
 | 65 |         return """/* THIS FILE IS GENERATED.  DO NOT EDIT. */ | 
 | 66 |  | 
 | 67 | /* | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 68 |  * Vulkan | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 69 |  * | 
 | 70 |  * Copyright (C) 2014 LunarG, Inc. | 
 | 71 |  * | 
 | 72 |  * Permission is hereby granted, free of charge, to any person obtaining a | 
 | 73 |  * copy of this software and associated documentation files (the "Software"), | 
 | 74 |  * to deal in the Software without restriction, including without limitation | 
 | 75 |  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
 | 76 |  * and/or sell copies of the Software, and to permit persons to whom the | 
 | 77 |  * Software is furnished to do so, subject to the following conditions: | 
 | 78 |  * | 
 | 79 |  * The above copyright notice and this permission notice shall be included | 
 | 80 |  * in all copies or substantial portions of the Software. | 
 | 81 |  * | 
 | 82 |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
 | 83 |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
 | 84 |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
 | 85 |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
 | 86 |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 
 | 87 |  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
 | 88 |  * DEALINGS IN THE SOFTWARE. | 
 | 89 |  */""" | 
 | 90 |  | 
 | 91 |     def generate_header(self): | 
| Chia-I Wu | 6bdf019 | 2014-09-13 13:36:06 +0800 | [diff] [blame] | 92 |         return "\n".join(["#include <" + h + ">" for h in self.headers]) | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 93 |  | 
 | 94 |     def generate_body(self): | 
 | 95 |         pass | 
 | 96 |  | 
 | 97 |     def generate_footer(self): | 
 | 98 |         pass | 
 | 99 |  | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 100 | class DispatchTableOpsSubcommand(Subcommand): | 
 | 101 |     def run(self): | 
 | 102 |         if len(self.argv) != 1: | 
 | 103 |             print("DispatchTableOpsSubcommand: <prefix> unspecified") | 
 | 104 |             return | 
 | 105 |  | 
 | 106 |         self.prefix = self.argv[0] | 
| Michael Lentine | 695f2c2 | 2015-09-09 12:39:13 -0700 | [diff] [blame] | 107 |         super(DispatchTableOpsSubcommand, self).run() | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 108 |  | 
 | 109 |     def generate_header(self): | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 110 |         return "\n".join(["#include <vulkan.h>", | 
| Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 111 |                           "#include <vk_layer.h>", | 
| Jon Ashburn | 1dd0a5c | 2015-05-04 09:16:41 -0600 | [diff] [blame] | 112 |                           "#include <string.h>"]) | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 113 |  | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 114 |     def _generate_init_dispatch(self, type): | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 115 |         stmts = [] | 
| Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 116 |         func = [] | 
 | 117 |         if type == "device": | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 118 |             # GPA has to be first one and uses wrapped object | 
 | 119 |             stmts.append("VkDevice device = (VkDevice) devw->nextObject;") | 
 | 120 |             stmts.append("PFN_vkGetDeviceProcAddr gpa = (PFN_vkGetDeviceProcAddr) devw->pGPA;") | 
 | 121 |             stmts.append("VkDevice baseDevice = (VkDevice) devw->baseObject;") | 
 | 122 |             stmts.append("// GPA has to be first entry inited and uses wrapped object since it triggers init") | 
| Courtney Goeltzenleuchter | 47fbcf3 | 2015-06-26 15:05:29 -0600 | [diff] [blame] | 123 |             stmts.append("memset(table, 0, sizeof(*table));") | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 124 |             stmts.append("table->GetDeviceProcAddr =(PFN_vkGetDeviceProcAddr)  gpa(device,\"vkGetDeviceProcAddr\");") | 
| Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 125 |             for proto in self.protos: | 
| Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 126 |                 if proto.name == "CreateInstance" or proto.name == "EnumerateInstanceExtensionProperties" or proto.name == "EnumerateInstanceLayerProperties" or proto.params[0].ty == "VkInstance" or (proto.params[0].ty == "VkPhysicalDevice" and proto.name != "CreateDevice"): | 
| Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 127 |                     continue | 
| Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 128 |                 if proto.name != "GetDeviceProcAddr" and 'KHR' not in proto.name: | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 129 |                     stmts.append("table->%s = (PFN_vk%s) gpa(baseDevice, \"vk%s\");" % | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 130 |                         (proto.name, proto.name, proto.name)) | 
| Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 131 |             func.append("static inline void %s_initialize_dispatch_table(VkLayerDispatchTable *table," | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 132 |                 % self.prefix) | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 133 |             func.append("%s                                              const VkBaseLayerObject *devw)" | 
| Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 134 |                 % (" " * len(self.prefix))) | 
 | 135 |         else: | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 136 |             # GPA has to be first one and uses wrapped object | 
 | 137 |             stmts.append("VkInstance instance = (VkInstance) instw->nextObject;") | 
 | 138 |             stmts.append("PFN_vkGetInstanceProcAddr gpa = (PFN_vkGetInstanceProcAddr) instw->pGPA;") | 
 | 139 |             stmts.append("VkInstance baseInstance = (VkInstance) instw->baseObject;") | 
 | 140 |             stmts.append("// GPA has to be first entry inited and uses wrapped object since it triggers init") | 
 | 141 |             stmts.append("table->GetInstanceProcAddr =(PFN_vkGetInstanceProcAddr)  gpa(instance,\"vkGetInstanceProcAddr\");") | 
| Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 142 |             for proto in self.protos: | 
| Jon Ashburn | b19ddbf | 2015-06-16 12:44:51 -0600 | [diff] [blame] | 143 |                 if proto.name != "CreateInstance"  and proto.params[0].ty != "VkInstance" and proto.params[0].ty != "VkPhysicalDevice": | 
| Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 144 |                     continue | 
| Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 145 |                 if proto.name == "CreateDevice": | 
 | 146 |                     continue | 
| Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 147 |                 if proto.name != "GetInstanceProcAddr" and 'KHR' not in proto.name: | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 148 |                     stmts.append("table->%s = (PFN_vk%s) gpa(baseInstance, \"vk%s\");" % | 
| Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 149 |                           (proto.name, proto.name, proto.name)) | 
 | 150 |             func.append("static inline void %s_init_instance_dispatch_table(VkLayerInstanceDispatchTable *table," | 
 | 151 |                 % self.prefix) | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 152 |             func.append("%s                                              const VkBaseLayerObject *instw)" | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 153 |                 % (" " * len(self.prefix))) | 
 | 154 |         func.append("{") | 
 | 155 |         func.append("    %s" % "\n    ".join(stmts)) | 
 | 156 |         func.append("}") | 
 | 157 |  | 
 | 158 |         return "\n".join(func) | 
 | 159 |  | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 160 |     def generate_body(self): | 
| Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 161 |         body = [self._generate_init_dispatch("device"), | 
 | 162 |                 self._generate_init_dispatch("instance")] | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 163 |  | 
 | 164 |         return "\n\n".join(body) | 
 | 165 |  | 
| Chia-I Wu | eeb0ab6 | 2015-01-03 23:48:15 +0800 | [diff] [blame] | 166 | class IcdDummyEntrypointsSubcommand(Subcommand): | 
| Chia-I Wu | df3c432 | 2014-08-04 10:08:08 +0800 | [diff] [blame] | 167 |     def run(self): | 
| Chia-I Wu | eeb0ab6 | 2015-01-03 23:48:15 +0800 | [diff] [blame] | 168 |         if len(self.argv) == 1: | 
 | 169 |             self.prefix = self.argv[0] | 
 | 170 |             self.qual = "static" | 
 | 171 |         else: | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 172 |             self.prefix = "vk" | 
| Chia-I Wu | eeb0ab6 | 2015-01-03 23:48:15 +0800 | [diff] [blame] | 173 |             self.qual = "ICD_EXPORT" | 
| Chia-I Wu | df3c432 | 2014-08-04 10:08:08 +0800 | [diff] [blame] | 174 |  | 
 | 175 |         super().run() | 
 | 176 |  | 
 | 177 |     def generate_header(self): | 
 | 178 |         return "#include \"icd.h\"" | 
 | 179 |  | 
 | 180 |     def _generate_stub_decl(self, proto): | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 181 |         return proto.c_pretty_decl(self.prefix + proto.name, attr="VKAPI") | 
| Chia-I Wu | df3c432 | 2014-08-04 10:08:08 +0800 | [diff] [blame] | 182 |  | 
 | 183 |     def _generate_stubs(self): | 
 | 184 |         stubs = [] | 
 | 185 |         for proto in self.protos: | 
| Chia-I Wu | df3c432 | 2014-08-04 10:08:08 +0800 | [diff] [blame] | 186 |             decl = self._generate_stub_decl(proto) | 
| Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 187 |             if proto.ret != "void": | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 188 |                 stmt = "    return VK_ERROR_UNKNOWN;\n" | 
| Chia-I Wu | df3c432 | 2014-08-04 10:08:08 +0800 | [diff] [blame] | 189 |             else: | 
 | 190 |                 stmt = "" | 
 | 191 |  | 
| Chia-I Wu | eeb0ab6 | 2015-01-03 23:48:15 +0800 | [diff] [blame] | 192 |             stubs.append("%s %s\n{\n%s}" % (self.qual, decl, stmt)) | 
| Chia-I Wu | df3c432 | 2014-08-04 10:08:08 +0800 | [diff] [blame] | 193 |  | 
 | 194 |         return "\n\n".join(stubs) | 
 | 195 |  | 
| Chia-I Wu | df3c432 | 2014-08-04 10:08:08 +0800 | [diff] [blame] | 196 |     def generate_body(self): | 
| Chia-I Wu | eeb0ab6 | 2015-01-03 23:48:15 +0800 | [diff] [blame] | 197 |         return self._generate_stubs() | 
| Chia-I Wu | df3c432 | 2014-08-04 10:08:08 +0800 | [diff] [blame] | 198 |  | 
| Chia-I Wu | 7f6d66e | 2015-01-04 00:11:17 +0800 | [diff] [blame] | 199 | class IcdGetProcAddrSubcommand(IcdDummyEntrypointsSubcommand): | 
 | 200 |     def generate_header(self): | 
 | 201 |         return "\n".join(["#include <string.h>", "#include \"icd.h\""]) | 
 | 202 |  | 
 | 203 |     def generate_body(self): | 
 | 204 |         for proto in self.protos: | 
| Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 205 |             if proto.name == "GetDeviceProcAddr": | 
| Chia-I Wu | 7f6d66e | 2015-01-04 00:11:17 +0800 | [diff] [blame] | 206 |                 gpa_proto = proto | 
| Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 207 |             if proto.name == "GetInstanceProcAddr": | 
 | 208 |                 gpa_instance_proto = proto | 
| Chia-I Wu | 7f6d66e | 2015-01-04 00:11:17 +0800 | [diff] [blame] | 209 |  | 
| Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 210 |         gpa_instance_decl = self._generate_stub_decl(gpa_instance_proto) | 
| Chia-I Wu | 7f6d66e | 2015-01-04 00:11:17 +0800 | [diff] [blame] | 211 |         gpa_decl = self._generate_stub_decl(gpa_proto) | 
 | 212 |         gpa_pname = gpa_proto.params[-1].name | 
 | 213 |  | 
 | 214 |         lookups = [] | 
 | 215 |         for proto in self.protos: | 
 | 216 |             lookups.append("if (!strcmp(%s, \"%s\"))" % | 
 | 217 |                     (gpa_pname, proto.name)) | 
 | 218 |             lookups.append("    return (%s) %s%s;" % | 
 | 219 |                     (gpa_proto.ret, self.prefix, proto.name)) | 
 | 220 |  | 
 | 221 |         body = [] | 
| Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 222 |         body.append("%s %s" % (self.qual, gpa_instance_decl)) | 
 | 223 |         body.append("{") | 
| Jon Ashburn | 2577d63 | 2015-07-16 10:12:59 -0600 | [diff] [blame] | 224 |         body.append(generate_get_proc_addr_check(gpa_pname)) | 
 | 225 |         body.append("") | 
 | 226 |         body.append("    %s += 2;" % gpa_pname) | 
 | 227 |         body.append("    %s" % "\n    ".join(lookups)) | 
 | 228 |         body.append("") | 
| Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 229 |         body.append("    return NULL;") | 
 | 230 |         body.append("}") | 
 | 231 |         body.append("") | 
 | 232 |  | 
| Chia-I Wu | 7f6d66e | 2015-01-04 00:11:17 +0800 | [diff] [blame] | 233 |         body.append("%s %s" % (self.qual, gpa_decl)) | 
 | 234 |         body.append("{") | 
| Chia-I Wu | 6cdaedb | 2015-01-05 12:55:13 +0800 | [diff] [blame] | 235 |         body.append(generate_get_proc_addr_check(gpa_pname)) | 
| Chia-I Wu | 7f6d66e | 2015-01-04 00:11:17 +0800 | [diff] [blame] | 236 |         body.append("") | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 237 |         body.append("    %s += 2;" % gpa_pname) | 
| Chia-I Wu | 7f6d66e | 2015-01-04 00:11:17 +0800 | [diff] [blame] | 238 |         body.append("    %s" % "\n    ".join(lookups)) | 
 | 239 |         body.append("") | 
 | 240 |         body.append("    return NULL;") | 
 | 241 |         body.append("}") | 
 | 242 |  | 
 | 243 |         return "\n".join(body) | 
 | 244 |  | 
| Chia-I Wu | 0a6644b | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 245 | class WinDefFileSubcommand(Subcommand): | 
 | 246 |     def run(self): | 
 | 247 |         library_exports = { | 
 | 248 |                 "all": [], | 
 | 249 |                 "icd": [ | 
| Jon Ashburn | 2919a01 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 250 |                     "vkEnumeratePhysicalDevices", | 
 | 251 |                     "vkCreateInstance", | 
 | 252 |                     "vkDestroyInstance", | 
 | 253 |                     "vkGetDeviceProcAddr", | 
 | 254 |                     "vkGetInstanceProcAddr", | 
| Chia-I Wu | 0a6644b | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 255 |                 ], | 
 | 256 |                 "layer": [ | 
| Jon Ashburn | 2919a01 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 257 |                     "vkGetInstanceProcAddr", | 
 | 258 |                     "vkGetDeviceProcAddr", | 
| Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 259 |                     "vkEnumerateInstanceLayerProperties", | 
 | 260 |                     "vkEnumerateInstanceExtensionProperties" | 
| Chia-I Wu | 0a6644b | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 261 |                 ], | 
| Jon Ashburn | 2919a01 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 262 |                 "layerMulti": [ | 
 | 263 |                     "multi2GetInstanceProcAddr", | 
 | 264 |                     "multi1GetDeviceProcAddr" | 
 | 265 |                 ] | 
| Chia-I Wu | 0a6644b | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 266 |         } | 
 | 267 |  | 
 | 268 |         if len(self.argv) != 2 or self.argv[1] not in library_exports: | 
 | 269 |             print("WinDefFileSubcommand: <library-name> {%s}" % | 
 | 270 |                     "|".join(library_exports.keys())) | 
 | 271 |             return | 
 | 272 |  | 
 | 273 |         self.library = self.argv[0] | 
| Jon Ashburn | 2919a01 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 274 |         if self.library == "VKLayerMulti": | 
 | 275 |             self.exports = library_exports["layerMulti"] | 
 | 276 |         else: | 
 | 277 |             self.exports = library_exports[self.argv[1]] | 
| Chia-I Wu | 0a6644b | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 278 |  | 
 | 279 |         super().run() | 
 | 280 |  | 
 | 281 |     def generate_copyright(self): | 
 | 282 |         return """; THIS FILE IS GENERATED.  DO NOT EDIT. | 
 | 283 |  | 
 | 284 | ;;;; Begin Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 
| Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 285 | ; Vulkan | 
| Chia-I Wu | 0a6644b | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 286 | ; | 
 | 287 | ; Copyright (C) 2015 LunarG, Inc. | 
 | 288 | ; | 
 | 289 | ; Permission is hereby granted, free of charge, to any person obtaining a | 
 | 290 | ; copy of this software and associated documentation files (the "Software"), | 
 | 291 | ; to deal in the Software without restriction, including without limitation | 
 | 292 | ; the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
 | 293 | ; and/or sell copies of the Software, and to permit persons to whom the | 
 | 294 | ; Software is furnished to do so, subject to the following conditions: | 
 | 295 | ; | 
 | 296 | ; The above copyright notice and this permission notice shall be included | 
 | 297 | ; in all copies or substantial portions of the Software. | 
 | 298 | ; | 
 | 299 | ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
 | 300 | ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
 | 301 | ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
 | 302 | ; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
 | 303 | ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 
 | 304 | ; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
 | 305 | ; DEALINGS IN THE SOFTWARE. | 
 | 306 | ;;;;  End Copyright Notice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;""" | 
 | 307 |  | 
 | 308 |     def generate_header(self): | 
 | 309 |         return "; The following is required on Windows, for exporting symbols from the DLL" | 
 | 310 |  | 
 | 311 |     def generate_body(self): | 
 | 312 |         body = [] | 
 | 313 |  | 
 | 314 |         body.append("LIBRARY " + self.library) | 
 | 315 |         body.append("EXPORTS") | 
 | 316 |  | 
| Jon Ashburn | 2919a01 | 2015-08-13 14:15:07 -0700 | [diff] [blame] | 317 |         for proto in self.exports: | 
| Ian Elliott | 0b4d624 | 2015-09-22 10:51:24 -0600 | [diff] [blame] | 318 |             if self.library != "VKLayerSwapchain" or proto != "vkEnumerateInstanceExtensionProperties" and proto != "vkEnumerateInstanceLayerProperties": | 
 | 319 |                 body.append( proto) | 
| Chia-I Wu | 0a6644b | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 320 |  | 
 | 321 |         return "\n".join(body) | 
 | 322 |  | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 323 | def main(): | 
 | 324 |     subcommands = { | 
| Chia-I Wu | 29271d7 | 2015-01-04 10:19:50 +0800 | [diff] [blame] | 325 |             "dispatch-table-ops": DispatchTableOpsSubcommand, | 
| Chia-I Wu | eeb0ab6 | 2015-01-03 23:48:15 +0800 | [diff] [blame] | 326 |             "icd-dummy-entrypoints": IcdDummyEntrypointsSubcommand, | 
| Chia-I Wu | 7f6d66e | 2015-01-04 00:11:17 +0800 | [diff] [blame] | 327 |             "icd-get-proc-addr": IcdGetProcAddrSubcommand, | 
| Chia-I Wu | 0a6644b | 2015-04-11 10:56:50 +0800 | [diff] [blame] | 328 |             "win-def-file": WinDefFileSubcommand, | 
| Chia-I Wu | fb2559d | 2014-08-01 11:19:52 +0800 | [diff] [blame] | 329 |     } | 
 | 330 |  | 
 | 331 |     if len(sys.argv) < 2 or sys.argv[1] not in subcommands: | 
 | 332 |         print("Usage: %s <subcommand> [options]" % sys.argv[0]) | 
 | 333 |         print | 
 | 334 |         print("Available sucommands are: %s" % " ".join(subcommands)) | 
 | 335 |         exit(1) | 
 | 336 |  | 
 | 337 |     subcmd = subcommands[sys.argv[1]](sys.argv[2:]) | 
 | 338 |     subcmd.run() | 
 | 339 |  | 
 | 340 | if __name__ == "__main__": | 
 | 341 |     main() |