Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 2 | # |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | # VK |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 4 | # |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 5 | # Copyright (c) 2015-2016 The Khronos Group Inc. |
| 6 | # Copyright (c) 2015-2016 Valve Corporation |
| 7 | # Copyright (c) 2015-2016 LunarG, Inc. |
| 8 | # Copyright (c) 2015-2016 Google Inc. |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 9 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | # you may not use this file except in compliance with the License. |
| 12 | # You may obtain a copy of the License at |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 13 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 14 | # http://www.apache.org/licenses/LICENSE-2.0 |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 15 | # |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 16 | # Unless required by applicable law or agreed to in writing, software |
| 17 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | # See the License for the specific language governing permissions and |
| 20 | # limitations under the License. |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 21 | # |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 22 | # Author: Tobin Ehlis <tobine@google.com> |
| 23 | # Author: Courtney Goeltzenleuchter <courtneygo@google.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 24 | # Author: Jon Ashburn <jon@lunarg.com> |
| 25 | # Author: Mark Lobodzinski <mark@lunarg.com> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 26 | # Author: Mike Stroyan <stroyan@google.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 27 | # Author: Tony Barbour <tony@LunarG.com> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 28 | # Author: Chia-I Wu <olv@google.com> |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 29 | # Author: Gwan-gyeong Mun <kk.moon@samsung.com> |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 30 | |
| 31 | import sys |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 32 | import os |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 33 | import re |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 34 | |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 35 | import vulkan |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 36 | import vk_helper |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 37 | from source_line_info import sourcelineinfo |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 38 | from collections import defaultdict |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 39 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 40 | def proto_is_global(proto): |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 41 | global_function_names = [ |
| 42 | "CreateInstance", |
| 43 | "EnumerateInstanceLayerProperties", |
| 44 | "EnumerateInstanceExtensionProperties", |
| 45 | "EnumerateDeviceLayerProperties", |
| 46 | "EnumerateDeviceExtensionProperties", |
| 47 | "CreateXcbSurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 48 | "GetPhysicalDeviceXcbPresentationSupportKHR", |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 49 | "CreateXlibSurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 50 | "GetPhysicalDeviceXlibPresentationSupportKHR", |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 51 | "CreateWaylandSurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 52 | "GetPhysicalDeviceWaylandPresentationSupportKHR", |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 53 | "CreateMirSurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 54 | "GetPhysicalDeviceMirPresentationSupportKHR", |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 55 | "CreateAndroidSurfaceKHR", |
| 56 | "CreateWin32SurfaceKHR", |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 57 | "GetPhysicalDeviceWin32PresentationSupportKHR", |
| 58 | "GetPhysicalDeviceDisplayPropertiesKHR", |
| 59 | "GetPhysicalDeviceDisplayPlanePropertiesKHR", |
| 60 | "GetDisplayPlaneSupportedDisplaysKHR", |
| 61 | "GetDisplayModePropertiesKHR", |
| 62 | "CreateDisplayModeKHR", |
| 63 | "GetDisplayPlaneCapabilitiesKHR", |
| 64 | "CreateDisplayPlaneSurfaceKHR" |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 65 | ] |
| 66 | if proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice" or proto.name in global_function_names: |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 67 | return True |
| 68 | else: |
| 69 | return False |
| 70 | |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 71 | def wsi_name(ext_name): |
| 72 | wsi_prefix = "" |
| 73 | if 'Xcb' in ext_name: |
| 74 | wsi_prefix = 'XCB' |
| 75 | elif 'Xlib' in ext_name: |
| 76 | wsi_prefix = 'XLIB' |
| 77 | elif 'Win32' in ext_name: |
| 78 | wsi_prefix = 'WIN32' |
| 79 | elif 'Mir' in ext_name: |
| 80 | wsi_prefix = 'MIR' |
| 81 | elif 'Wayland' in ext_name: |
| 82 | wsi_prefix = 'WAYLAND' |
| 83 | elif 'Android' in ext_name: |
| 84 | wsi_prefix = 'ANDROID' |
| 85 | else: |
| 86 | wsi_prefix = '' |
| 87 | return wsi_prefix |
| 88 | |
| 89 | def wsi_ifdef(ext_name): |
| 90 | wsi_prefix = wsi_name(ext_name) |
| 91 | if not wsi_prefix: |
| 92 | return '' |
| 93 | else: |
| 94 | return "#ifdef VK_USE_PLATFORM_%s_KHR" % wsi_prefix |
| 95 | |
| 96 | def wsi_endif(ext_name): |
| 97 | wsi_prefix = wsi_name(ext_name) |
| 98 | if not wsi_prefix: |
| 99 | return '' |
| 100 | else: |
| 101 | return "#endif // VK_USE_PLATFORM_%s_KHR" % wsi_prefix |
| 102 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 103 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 104 | return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ |
| 105 | " return NULL;" % ((name,) * 3) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 106 | |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 107 | def ucc_to_U_C_C(CamelCase): |
| 108 | temp = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', CamelCase) |
| 109 | return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).upper() |
| 110 | |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 111 | # Parse complete struct chain and add any new ndo_uses to the dict |
| 112 | def gather_object_uses_in_struct(obj_list, struct_type): |
| 113 | struct_uses = {} |
| 114 | if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict: |
| 115 | struct_type = vk_helper.typedef_rev_dict[struct_type] |
| 116 | # Parse elements of this struct param to identify objects and/or arrays of objects |
| 117 | for m in sorted(vk_helper.struct_dict[struct_type]): |
| 118 | array_len = "%s" % (str(vk_helper.struct_dict[struct_type][m]['array_size'])) |
| 119 | base_type = vk_helper.struct_dict[struct_type][m]['type'] |
| 120 | mem_name = vk_helper.struct_dict[struct_type][m]['name'] |
| 121 | if array_len != '0': |
| 122 | mem_name = "%s[%s]" % (mem_name, array_len) |
| 123 | if base_type in obj_list: |
| 124 | #if array_len not in ndo_uses: |
| 125 | # struct_uses[array_len] = [] |
| 126 | #struct_uses[array_len].append("%s%s,%s" % (name_prefix, struct_name, base_type)) |
| 127 | struct_uses[mem_name] = base_type |
| 128 | elif vk_helper.is_type(base_type, 'struct'): |
| 129 | sub_uses = gather_object_uses_in_struct(obj_list, base_type) |
| 130 | if len(sub_uses) > 0: |
| 131 | struct_uses[mem_name] = sub_uses |
| 132 | return struct_uses |
| 133 | |
| 134 | # For the given list of object types, Parse the given list of params |
| 135 | # and return dict of params that use one of the obj_list types |
| 136 | # Format of the dict is that terminal elements have <name>,<type> |
| 137 | # non-terminal elements will have <name>[<array_size>] |
| 138 | # TODO : This analysis could be done up-front at vk_helper time |
| 139 | def get_object_uses(obj_list, params): |
| 140 | obj_uses = {} |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 141 | local_decls = {} |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 142 | param_count = 'NONE' # track params that give array sizes |
| 143 | for p in params: |
| 144 | base_type = p.ty.replace('const ', '').strip('*') |
| 145 | array_len = '' |
| 146 | is_ptr = False |
| 147 | if 'count' in p.name.lower(): |
| 148 | param_count = p.name |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 149 | ptr_txt = '' |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 150 | if '*' in p.ty: |
| 151 | is_ptr = True |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 152 | ptr_txt = '*' |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 153 | if base_type in obj_list: |
| 154 | if is_ptr and 'const' in p.ty and param_count != 'NONE': |
| 155 | array_len = "[%s]" % param_count |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 156 | # Non-arrays we can overwrite in place, but need local decl for arrays |
| 157 | local_decls[p.name] = '%s%s' % (base_type, ptr_txt) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 158 | #if array_len not in obj_uses: |
| 159 | # obj_uses[array_len] = {} |
| 160 | # obj_uses[array_len][p.name] = base_type |
| 161 | obj_uses["%s%s" % (p.name, array_len)] = base_type |
| 162 | elif vk_helper.is_type(base_type, 'struct'): |
| 163 | struct_name = p.name |
| 164 | if 'NONE' != param_count: |
| 165 | struct_name = "%s[%s]" % (struct_name, param_count) |
| 166 | struct_uses = gather_object_uses_in_struct(obj_list, base_type) |
| 167 | if len(struct_uses) > 0: |
| 168 | obj_uses[struct_name] = struct_uses |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 169 | # This is a top-level struct w/ uses below it, so need local decl |
| 170 | local_decls['%s' % (p.name)] = '%s%s' % (base_type, ptr_txt) |
| 171 | return (obj_uses, local_decls) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 172 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 173 | class Subcommand(object): |
Jamie Madill | dbda66b | 2016-05-10 07:36:20 -0700 | [diff] [blame] | 174 | def __init__(self, outfile): |
| 175 | self.outfile = outfile |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 176 | self.headers = vulkan.headers |
| 177 | self.protos = vulkan.protos |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 178 | self.no_addr = False |
| 179 | self.layer_name = "" |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 180 | self.lineinfo = sourcelineinfo() |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 181 | self.wsi = sys.argv[1] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 182 | |
| 183 | def run(self): |
Jamie Madill | dbda66b | 2016-05-10 07:36:20 -0700 | [diff] [blame] | 184 | if self.outfile: |
| 185 | with open(self.outfile, "w") as outfile: |
| 186 | outfile.write(self.generate()) |
| 187 | else: |
| 188 | print(self.generate()) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 189 | |
| 190 | def generate(self): |
| 191 | copyright = self.generate_copyright() |
| 192 | header = self.generate_header() |
| 193 | body = self.generate_body() |
| 194 | footer = self.generate_footer() |
| 195 | |
| 196 | contents = [] |
| 197 | if copyright: |
| 198 | contents.append(copyright) |
| 199 | if header: |
| 200 | contents.append(header) |
| 201 | if body: |
| 202 | contents.append(body) |
| 203 | if footer: |
| 204 | contents.append(footer) |
| 205 | |
| 206 | return "\n\n".join(contents) |
| 207 | |
| 208 | def generate_copyright(self): |
| 209 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 210 | |
| 211 | /* |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 212 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 213 | * Copyright (c) 2015-2016 Valve Corporation |
| 214 | * Copyright (c) 2015-2016 LunarG, Inc. |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 215 | * Copyright (c) 2015-2016 Google, Inc. |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 216 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 217 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 218 | * you may not use this file except in compliance with the License. |
| 219 | * You may obtain a copy of the License at |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 220 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 221 | * http://www.apache.org/licenses/LICENSE-2.0 |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 222 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 223 | * Unless required by applicable law or agreed to in writing, software |
| 224 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 225 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 226 | * See the License for the specific language governing permissions and |
| 227 | * limitations under the License. |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 228 | * |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 229 | * Author: Tobin Ehlis <tobine@google.com> |
| 230 | * Author: Courtney Goeltzenleuchter <courtneygo@google.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 231 | * Author: Jon Ashburn <jon@lunarg.com> |
| 232 | * Author: Mark Lobodzinski <mark@lunarg.com> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 233 | * Author: Mike Stroyan <stroyan@google.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 234 | * Author: Tony Barbour <tony@LunarG.com> |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 235 | */""" |
| 236 | |
| 237 | def generate_header(self): |
| 238 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 239 | |
| 240 | def generate_body(self): |
| 241 | pass |
| 242 | |
| 243 | def generate_footer(self): |
| 244 | pass |
| 245 | |
| 246 | # Return set of printf '%' qualifier and input to that qualifier |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 247 | def _get_printf_params(self, vk_type, name, output_param, cpp=False): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 248 | # TODO : Need ENUM and STRUCT checks here |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 249 | if vk_helper.is_type(vk_type, 'enum'):#"_TYPE" in vk_type: # TODO : This should be generic ENUM check |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 250 | return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name)) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 251 | if "char*" == vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 252 | return ("%s", name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 253 | if "uint64" in vk_type: |
| 254 | if '*' in vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 255 | return ("%lu", "*%s" % name) |
| 256 | return ("%lu", name) |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 257 | if vk_type.strip('*') in vulkan.object_non_dispatch_list: |
| 258 | if '*' in vk_type: |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 259 | return ("%lu", "%s" % name) |
| 260 | return ("%lu", "%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 261 | if "size" in vk_type: |
| 262 | if '*' in vk_type: |
Mark Lobodzinski | a145649 | 2015-10-06 09:57:52 -0600 | [diff] [blame] | 263 | return ("%lu", "(unsigned long)*%s" % name) |
| 264 | return ("%lu", "(unsigned long)%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 265 | if "float" in vk_type: |
| 266 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 267 | if cpp: |
| 268 | return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 269 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 270 | return ("%f", name) |
Courtney Goeltzenleuchter | cd2a099 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 271 | if "bool" in vk_type.lower() or 'xcb_randr_crtc_t' in vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 272 | return ("%u", name) |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 273 | if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]: |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 274 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 275 | if cpp: |
| 276 | return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 277 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 278 | if '*' in vk_type: |
Tobin Ehlis | d2b88e8 | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 279 | if 'pUserData' == name: |
| 280 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Tobin Ehlis | c62cb89 | 2015-04-17 13:26:33 -0600 | [diff] [blame] | 281 | if 'const' in vk_type.lower(): |
Mark Mueller | aab3650 | 2016-05-03 13:17:29 -0600 | [diff] [blame] | 282 | return ("0x%p", "(void*)(%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 283 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 284 | return ("%i", name) |
Tobin Ehlis | 3a1cc8d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 285 | # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 286 | if "VkFormat" == vk_type: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 287 | if cpp: |
Mark Mueller | aab3650 | 2016-05-03 13:17:29 -0600 | [diff] [blame] | 288 | return ("0x%p", "&%s" % name) |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 289 | return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_COLOR_COMPONENT_FORMAT(%s.channelFormat), string_VK_FORMAT_RANGE_SIZE(%s.numericFormat)" % (name, name)) |
Tobin Ehlis | e727157 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 290 | if output_param: |
Mark Mueller | aab3650 | 2016-05-03 13:17:29 -0600 | [diff] [blame] | 291 | return ("0x%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 292 | if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type: |
Mark Mueller | aab3650 | 2016-05-03 13:17:29 -0600 | [diff] [blame] | 293 | return ("0x%p", "(void*)(&%s)" % name) |
| 294 | return ("0x%p", "(void*)(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 295 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 296 | def _gen_create_msg_callback(self): |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 297 | r_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 298 | r_body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 299 | r_body.append('VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 300 | r_body.append(' VkInstance instance,') |
| 301 | r_body.append(' const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,') |
| 302 | r_body.append(' const VkAllocationCallbacks* pAllocator,') |
| 303 | r_body.append(' VkDebugReportCallbackEXT* pCallback)') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 304 | r_body.append('{') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 305 | # Switch to this code section for the new per-instance storage and debug callbacks |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 306 | if self.layer_name in ['object_tracker', 'unique_objects']: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 307 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 308 | r_body.append(' VkResult result = pInstanceTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 309 | r_body.append(' if (VK_SUCCESS == result) {') |
| 310 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 311 | r_body.append(' result = layer_create_msg_callback(my_data->report_data,') |
Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 312 | r_body.append(' false,') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 313 | r_body.append(' pCreateInfo,') |
| 314 | r_body.append(' pAllocator,') |
| 315 | r_body.append(' pCallback);') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 316 | r_body.append(' }') |
| 317 | r_body.append(' return result;') |
| 318 | else: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 319 | r_body.append(' VkResult result = instance_dispatch_table(instance)->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);') |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 320 | r_body.append(' if (VK_SUCCESS == result) {') |
| 321 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
Mark Lobodzinski | 97c4d51 | 2016-05-19 15:27:18 -0600 | [diff] [blame] | 322 | r_body.append(' result = layer_create_msg_callback(my_data->report_data, false, pCreateInfo, pAllocator, pCallback);') |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 323 | r_body.append(' }') |
| 324 | r_body.append(' return result;') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 325 | r_body.append('}') |
| 326 | return "\n".join(r_body) |
| 327 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 328 | def _gen_destroy_msg_callback(self): |
| 329 | r_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 330 | r_body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 331 | r_body.append('VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator)') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 332 | r_body.append('{') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 333 | # Switch to this code section for the new per-instance storage and debug callbacks |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 334 | if self.layer_name in ['object_tracker', 'unique_objects']: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 335 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 336 | else: |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 337 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 338 | r_body.append(' pInstanceTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 339 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
| 340 | r_body.append(' layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 341 | r_body.append('}') |
| 342 | return "\n".join(r_body) |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 343 | |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 344 | def _gen_debug_report_msg(self): |
| 345 | r_body = [] |
| 346 | r_body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 347 | r_body.append('VKAPI_ATTR void VKAPI_CALL DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg)') |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 348 | r_body.append('{') |
| 349 | # Switch to this code section for the new per-instance storage and debug callbacks |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 350 | if self.layer_name == 'object_tracker': |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 351 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
| 352 | else: |
| 353 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 354 | r_body.append(' pInstanceTable->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);') |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 355 | r_body.append('}') |
| 356 | return "\n".join(r_body) |
| 357 | |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 358 | def _gen_layer_logging_workaround(self): |
| 359 | body = [] |
| 360 | body.append('%s' % self.lineinfo.get()) |
| 361 | body.append('// vk_layer_logging.h expects these to be defined') |
| 362 | body.append('') |
| 363 | body.append('VKAPI_ATTR VkResult VKAPI_CALL') |
| 364 | body.append('vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,') |
| 365 | body.append(' const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) {') |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 366 | body.append(' return %s::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);' % self.layer_name) |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 367 | body.append('}') |
| 368 | body.append('') |
| 369 | body.append('VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance,') |
| 370 | body.append(' VkDebugReportCallbackEXT msgCallback,') |
| 371 | body.append(' const VkAllocationCallbacks *pAllocator) {') |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 372 | body.append(' %s::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);' % self.layer_name) |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 373 | body.append('}') |
| 374 | body.append('') |
| 375 | body.append('VKAPI_ATTR void VKAPI_CALL') |
| 376 | body.append('vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object,') |
| 377 | body.append(' size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {') |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 378 | body.append(' %s::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);' % self.layer_name) |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 379 | body.append('}') |
| 380 | |
| 381 | return "\n".join(body) |
| 382 | |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 383 | def _gen_layer_interface_v0_functions(self): |
| 384 | body = [] |
| 385 | body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 386 | body.append('// loader-layer interface v0, just wrappers since there is only a layer') |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 387 | body.append('') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 388 | |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 389 | body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)') |
| 390 | body.append('{') |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 391 | body.append(' return %s::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);' % self.layer_name) |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 392 | body.append('}') |
| 393 | body.append('') |
| 394 | body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)') |
| 395 | body.append('{') |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 396 | body.append(' return %s::EnumerateInstanceLayerProperties(pCount, pProperties);' % self.layer_name) |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 397 | body.append('}') |
| 398 | body.append('') |
| 399 | body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties* pProperties)') |
| 400 | body.append('{') |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 401 | body.append(' // the layer command handles VK_NULL_HANDLE just fine internally') |
| 402 | body.append(' assert(physicalDevice == VK_NULL_HANDLE);') |
| 403 | body.append(' return %s::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);' % self.layer_name) |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 404 | body.append('}') |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 405 | body.append('') |
| 406 | body.append('VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName)') |
| 407 | body.append('{') |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 408 | body.append(' return %s::GetDeviceProcAddr(dev, funcName);' % self.layer_name) |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 409 | body.append('}') |
| 410 | body.append('') |
| 411 | body.append('VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName)') |
| 412 | body.append('{') |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 413 | body.append(' return %s::GetInstanceProcAddr(instance, funcName);' % self.layer_name) |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 414 | body.append('}') |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 415 | body.append('') |
| 416 | body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,') |
| 417 | body.append(' const char *pLayerName, uint32_t *pCount,') |
| 418 | body.append(' VkExtensionProperties *pProperties)') |
| 419 | body.append('{') |
| 420 | body.append(' // the layer command handles VK_NULL_HANDLE just fine internally') |
| 421 | body.append(' assert(physicalDevice == VK_NULL_HANDLE);') |
| 422 | body.append(' return %s::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);' % self.layer_name) |
| 423 | body.append('}') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 424 | |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 425 | return "\n".join(body) |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 426 | |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 427 | def _generate_dispatch_entrypoints(self, qual=""): |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 428 | if qual: |
| 429 | qual += " " |
| 430 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 431 | funcs = [] |
| 432 | intercepted = [] |
| 433 | for proto in self.protos: |
Chia-I Wu | d579a5d | 2016-05-16 07:43:38 +0800 | [diff] [blame] | 434 | if proto.name in ["EnumerateInstanceExtensionProperties", |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 435 | "EnumerateInstanceLayerProperties", |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 436 | "EnumerateDeviceLayerProperties", |
| 437 | "GetDeviceProcAddr", |
| 438 | "GetInstanceProcAddr"]: |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 439 | funcs.append(proto.c_func(attr="VKAPI") + ';') |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 440 | intercepted.append(proto) |
Mike Stroyan | 70c05e8 | 2015-04-08 10:27:43 -0600 | [diff] [blame] | 441 | else: |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 442 | intercept = self.generate_intercept(proto, qual) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 443 | if intercept is None: |
| 444 | # fill in default intercept for certain entrypoints |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 445 | if 'CreateDebugReportCallbackEXT' == proto.name: |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 446 | intercept = self._gen_layer_dbg_create_msg_callback() |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 447 | elif 'DestroyDebugReportCallbackEXT' == proto.name: |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 448 | intercept = self._gen_layer_dbg_destroy_msg_callback() |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 449 | elif 'DebugReportMessageEXT' == proto.name: |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 450 | intercept = self._gen_debug_report_msg() |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 451 | elif 'CreateDevice' == proto.name: |
| 452 | funcs.append('/* CreateDevice HERE */') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 453 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 454 | if intercept is not None: |
| 455 | funcs.append(intercept) |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 456 | if not "KHR" in proto.name: |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 457 | intercepted.append(proto) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 458 | |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 459 | instance_lookups = [] |
| 460 | device_lookups = [] |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 461 | for proto in intercepted: |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 462 | if proto_is_global(proto): |
| 463 | instance_lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 464 | instance_lookups.append(" return (PFN_vkVoidFunction) %s;" % (proto.name)) |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 465 | else: |
| 466 | device_lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 467 | device_lookups.append(" return (PFN_vkVoidFunction) %s;" % (proto.name)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 468 | |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 469 | # add customized intercept_core_device_command |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 470 | body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 471 | body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 472 | body.append("static inline PFN_vkVoidFunction intercept_core_device_command(const char *name)") |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 473 | body.append("{") |
| 474 | body.append(generate_get_proc_addr_check("name")) |
| 475 | body.append("") |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 476 | body.append(" name += 2;") |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 477 | body.append(" %s" % "\n ".join(device_lookups)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 478 | body.append("") |
| 479 | body.append(" return NULL;") |
| 480 | body.append("}") |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 481 | # add intercept_core_instance_command |
| 482 | body.append("static inline PFN_vkVoidFunction intercept_core_instance_command(const char *name)") |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 483 | body.append("{") |
| 484 | body.append(generate_get_proc_addr_check("name")) |
| 485 | body.append("") |
| 486 | body.append(" name += 2;") |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 487 | body.append(" %s" % "\n ".join(instance_lookups)) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 488 | body.append("") |
| 489 | body.append(" return NULL;") |
| 490 | body.append("}") |
| 491 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 492 | funcs.append("\n".join(body)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 493 | return "\n\n".join(funcs) |
| 494 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 495 | def _generate_extensions(self): |
| 496 | exts = [] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 497 | exts.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 498 | exts.append(self._gen_create_msg_callback()) |
| 499 | exts.append(self._gen_destroy_msg_callback()) |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 500 | exts.append(self._gen_debug_report_msg()) |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 501 | return "\n".join(exts) |
| 502 | |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 503 | def _generate_layer_introspection_function(self): |
| 504 | body = [] |
| 505 | body.append('%s' % self.lineinfo.get()) |
| 506 | if self.layer_name == 'object_tracker': |
| 507 | body.append('static const VkExtensionProperties instance_extensions[] = {') |
| 508 | body.append(' {') |
| 509 | body.append(' VK_EXT_DEBUG_REPORT_EXTENSION_NAME,') |
| 510 | body.append(' VK_EXT_DEBUG_REPORT_SPEC_VERSION') |
| 511 | body.append(' }') |
| 512 | body.append('};') |
| 513 | body.append('') |
| 514 | |
| 515 | body.append('static const VkLayerProperties globalLayerProps = {') |
| 516 | body.append(' "VK_LAYER_LUNARG_%s",' % self.layer_name) |
| 517 | body.append(' VK_LAYER_API_VERSION, // specVersion') |
| 518 | body.append(' 1, // implementationVersion') |
| 519 | body.append(' "LunarG Validation Layer"') |
| 520 | body.append('};') |
| 521 | body.append('') |
| 522 | else: |
| 523 | body.append('static const VkLayerProperties globalLayerProps = {') |
| 524 | body.append(' "VK_LAYER_GOOGLE_%s",' % self.layer_name) |
| 525 | body.append(' VK_LAYER_API_VERSION, // specVersion') |
| 526 | body.append(' 1, // implementationVersion') |
| 527 | body.append(' "Google Validation Layer"') |
| 528 | body.append('};') |
| 529 | body.append('') |
| 530 | |
| 531 | body.append('VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)') |
| 532 | body.append('{') |
| 533 | body.append(' return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);') |
| 534 | body.append('}') |
| 535 | body.append('') |
| 536 | body.append('VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties* pProperties)') |
| 537 | body.append('{') |
| 538 | body.append(' return util_GetLayerProperties(1, &globalLayerProps, pCount, pProperties);') |
| 539 | body.append('}') |
| 540 | body.append('') |
| 541 | body.append('VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)') |
| 542 | body.append('{') |
| 543 | body.append(' if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName))') |
| 544 | if self.layer_name == 'object_tracker': |
| 545 | body.append(' return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);') |
| 546 | else: |
| 547 | body.append(' return util_GetExtensionProperties(0, NULL, pCount, pProperties);') |
| 548 | body.append('') |
| 549 | body.append(' return VK_ERROR_LAYER_NOT_PRESENT;') |
| 550 | body.append('}') |
| 551 | body.append('') |
| 552 | body.append('VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,') |
| 553 | body.append(' const char *pLayerName, uint32_t *pCount,') |
| 554 | body.append(' VkExtensionProperties *pProperties)') |
| 555 | body.append('{') |
| 556 | body.append(' if (pLayerName && !strcmp(pLayerName, globalLayerProps.layerName))') |
| 557 | body.append(' return util_GetExtensionProperties(0, nullptr, pCount, pProperties);') |
| 558 | body.append('') |
| 559 | body.append(' assert(physicalDevice);') |
| 560 | body.append(' VkLayerInstanceDispatchTable* pTable = get_dispatch_table(%s_instance_table_map, physicalDevice);' % self.layer_name) |
| 561 | body.append(' return pTable->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties);') |
| 562 | body.append('}') |
| 563 | |
| 564 | return "\n".join(body) |
| 565 | |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 566 | def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]): |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 567 | func_body = [] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 568 | # |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 569 | # New style of GPA Functions for the new layer_data/layer_logging changes |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 570 | # |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 571 | if self.layer_name in ['object_tracker', 'unique_objects']: |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 572 | for ext_enable, ext_list in extensions: |
| 573 | func_body.append('%s' % self.lineinfo.get()) |
| 574 | func_body.append('static inline PFN_vkVoidFunction intercept_%s_command(const char *name, VkDevice dev)' % ext_enable) |
| 575 | func_body.append('{') |
Chia-I Wu | 5b2f057 | 2016-05-17 07:43:59 +0800 | [diff] [blame] | 576 | func_body.append(' if (dev) {') |
| 577 | func_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);') |
| 578 | func_body.append(' if (!my_data->%s)' % ext_enable) |
| 579 | func_body.append(' return nullptr;') |
| 580 | func_body.append(' }\n') |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 581 | |
| 582 | for ext_name in ext_list: |
| 583 | func_body.append(' if (!strcmp("%s", name))\n' |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 584 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (ext_name, ext_name[2:])) |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 585 | func_body.append('\n return nullptr;') |
| 586 | func_body.append('}\n') |
| 587 | |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 588 | func_body.append("VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 589 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 590 | " PFN_vkVoidFunction addr;\n" |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 591 | " addr = intercept_core_device_command(funcName);\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 592 | " if (addr)\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 593 | " return addr;\n" |
Chia-I Wu | f5b039d | 2016-05-17 07:39:31 +0800 | [diff] [blame] | 594 | " assert(device);\n") |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 595 | for ext_enable, _ in extensions: |
| 596 | func_body.append(' addr = intercept_%s_command(funcName, device);' % ext_enable) |
| 597 | func_body.append(' if (addr)\n' |
| 598 | ' return addr;') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 599 | func_body.append("\n if (get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr == NULL)\n" |
| 600 | " return NULL;\n" |
| 601 | " return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n" |
| 602 | "}\n" % (self.layer_name, self.layer_name)) |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 603 | |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 604 | # The WSI-related extensions have independent extension enables |
| 605 | wsi_sub_enables = {'WIN32': 'win32_enabled', |
| 606 | 'XLIB': 'xlib_enabled', |
| 607 | 'XCB': 'xcb_enabled', |
| 608 | 'MIR': 'mir_enabled', |
| 609 | 'WAYLAND': 'wayland_enabled', |
| 610 | 'ANDROID': 'android_enabled'} |
| 611 | |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 612 | for ext_enable, ext_list in instance_extensions: |
| 613 | func_body.append('%s' % self.lineinfo.get()) |
| 614 | func_body.append('static inline PFN_vkVoidFunction intercept_%s_command(const char *name, VkInstance instance)' % ext_enable) |
| 615 | func_body.append('{') |
| 616 | if ext_enable == 'msg_callback_get_proc_addr': |
| 617 | func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n" |
| 618 | " return debug_report_get_instance_proc_addr(my_data->report_data, name);") |
| 619 | else: |
| 620 | func_body.append(" VkLayerInstanceDispatchTable* pTable = get_dispatch_table(%s_instance_table_map, instance);" % self.layer_name) |
| 621 | func_body.append(' if (instanceExtMap.size() == 0 || !instanceExtMap[pTable].%s)' % ext_enable) |
| 622 | func_body.append(' return nullptr;\n') |
| 623 | |
| 624 | for ext_name in ext_list: |
| 625 | if wsi_name(ext_name): |
| 626 | func_body.append('%s' % wsi_ifdef(ext_name)) |
Mark Lobodzinski | fe1f066 | 2016-06-24 09:57:32 -0600 | [diff] [blame] | 627 | if wsi_sub_enables[wsi_name(ext_name)]: |
| 628 | func_body.append(' if ((instanceExtMap[pTable].%s == true) && !strcmp("%s", name))\n' |
| 629 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (wsi_sub_enables[wsi_name(ext_name)], ext_name, ext_name[2:])) |
| 630 | else: |
| 631 | func_body.append(' if (!strcmp("%s", name))\n' |
| 632 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (ext_name, ext_name[2:])) |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 633 | if wsi_name(ext_name): |
| 634 | func_body.append('%s' % wsi_endif(ext_name)) |
| 635 | |
| 636 | func_body.append('\n return nullptr;') |
| 637 | func_body.append('}\n') |
| 638 | |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 639 | func_body.append("VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 640 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 641 | " PFN_vkVoidFunction addr;\n" |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 642 | " addr = intercept_core_instance_command(funcName);\n" |
Chia-I Wu | 5b2f057 | 2016-05-17 07:43:59 +0800 | [diff] [blame] | 643 | " if (!addr) {\n" |
| 644 | " addr = intercept_core_device_command(funcName);\n" |
| 645 | " }") |
| 646 | |
| 647 | for ext_enable, _ in extensions: |
| 648 | func_body.append(" if (!addr) {\n" |
| 649 | " addr = intercept_%s_command(funcName, VkDevice(VK_NULL_HANDLE));\n" |
| 650 | " }" % ext_enable) |
| 651 | |
| 652 | func_body.append(" if (addr) {\n" |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 653 | " return addr;\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 654 | " }\n" |
Chia-I Wu | f5b039d | 2016-05-17 07:39:31 +0800 | [diff] [blame] | 655 | " assert(instance);\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 656 | ) |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 657 | |
Chia-I Wu | fcf7eb9 | 2016-05-16 13:01:39 +0800 | [diff] [blame] | 658 | for ext_enable, _ in instance_extensions: |
| 659 | func_body.append(' addr = intercept_%s_command(funcName, instance);' % ext_enable) |
| 660 | func_body.append(' if (addr)\n' |
| 661 | ' return addr;\n') |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 662 | |
| 663 | func_body.append(" if (get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr == NULL) {\n" |
| 664 | " return NULL;\n" |
| 665 | " }\n" |
| 666 | " return get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);\n" |
| 667 | "}\n" % (self.layer_name, self.layer_name)) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 668 | return "\n".join(func_body) |
| 669 | else: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 670 | func_body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 671 | func_body.append("VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 672 | "{\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 673 | " PFN_vkVoidFunction addr;\n") |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 674 | func_body.append("\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 675 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 676 | " addr = intercept_core_device_command(funcName);\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 677 | " if (addr)\n" |
| 678 | " return addr;" % self.layer_name) |
Chia-I Wu | f5b039d | 2016-05-17 07:39:31 +0800 | [diff] [blame] | 679 | func_body.append(" assert(device);\n") |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 680 | func_body.append('') |
| 681 | func_body.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 682 | if 0 != len(extensions): |
| 683 | extra_space = "" |
| 684 | for (ext_enable, ext_list) in extensions: |
| 685 | if 0 != len(ext_enable): |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 686 | func_body.append(' if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].%s)' % ext_enable) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 687 | func_body.append(' {') |
| 688 | extra_space = " " |
| 689 | for ext_name in ext_list: |
| 690 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 691 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name)) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 692 | if 0 != len(ext_enable): |
| 693 | func_body.append(' }') |
| 694 | func_body.append('%s' % self.lineinfo.get()) |
| 695 | func_body.append(" {\n" |
| 696 | " if (pDisp->GetDeviceProcAddr == NULL)\n" |
| 697 | " return NULL;\n" |
| 698 | " return pDisp->GetDeviceProcAddr(device, funcName);\n" |
| 699 | " }\n" |
| 700 | "}\n") |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 701 | func_body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 702 | func_body.append("VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 703 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 704 | " PFN_vkVoidFunction addr;\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 705 | ) |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 706 | func_body.append( |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 707 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
Chia-I Wu | 2985b14 | 2016-05-16 12:27:03 +0800 | [diff] [blame] | 708 | " addr = intercept_core_instance_command(funcName);\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 709 | " if (addr)\n" |
| 710 | " return addr;" % self.layer_name) |
Chia-I Wu | f5b039d | 2016-05-17 07:39:31 +0800 | [diff] [blame] | 711 | func_body.append(" assert(instance);\n") |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 712 | func_body.append("") |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 713 | func_body.append(" VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);\n") |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 714 | if 0 != len(instance_extensions): |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 715 | extra_space = "" |
| 716 | for (ext_enable, ext_list) in instance_extensions: |
| 717 | if 0 != len(ext_enable): |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 718 | if ext_enable == 'msg_callback_get_proc_addr': |
| 719 | func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n" |
| 720 | " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n" |
| 721 | " if (addr) {\n" |
| 722 | " return addr;\n" |
| 723 | " }\n") |
| 724 | else: |
| 725 | func_body.append(' if (instanceExtMap.size() != 0 && instanceExtMap[pTable].%s)' % ext_enable) |
| 726 | func_body.append(' {') |
| 727 | extra_space = " " |
| 728 | for ext_name in ext_list: |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 729 | if wsi_name(ext_name): |
| 730 | func_body.append('%s' % wsi_ifdef(ext_name)) |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 731 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 732 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name)) |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 733 | if wsi_name(ext_name): |
| 734 | func_body.append('%s' % wsi_endif(ext_name)) |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 735 | if 0 != len(ext_enable): |
| 736 | func_body.append(' }\n') |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 737 | |
| 738 | func_body.append(" if (pTable->GetInstanceProcAddr == NULL)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 739 | " return NULL;\n" |
| 740 | " return pTable->GetInstanceProcAddr(instance, funcName);\n" |
| 741 | "}\n") |
| 742 | return "\n".join(func_body) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 743 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 744 | |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 745 | def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 746 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 747 | func_body.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 748 | func_body.append('static void init_%s(layer_data *my_data, const VkAllocationCallbacks *pAllocator)\n' |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 749 | '{\n' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 750 | if init_opts: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 751 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 752 | func_body.append('') |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 753 | func_body.append(' layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_%s");' % self.layer_name) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 754 | func_body.append('') |
| 755 | if lockname is not None: |
| 756 | func_body.append('%s' % self.lineinfo.get()) |
| 757 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 758 | func_body.append(" {") |
| 759 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 760 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
| 761 | if condname is not None: |
| 762 | func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname) |
| 763 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 764 | func_body.append(" }") |
| 765 | func_body.append("}\n") |
| 766 | func_body.append('') |
| 767 | return "\n".join(func_body) |
| 768 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 769 | class ObjectTrackerSubcommand(Subcommand): |
| 770 | def generate_header(self): |
| 771 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 772 | header_txt.append('%s' % self.lineinfo.get()) |
Jamie Madill | df5d573 | 2016-04-04 11:54:43 -0400 | [diff] [blame] | 773 | header_txt.append('#include "vk_loader_platform.h"') |
| 774 | header_txt.append('#include "vulkan/vulkan.h"') |
| 775 | header_txt.append('') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 776 | header_txt.append('#include <stdio.h>') |
| 777 | header_txt.append('#include <stdlib.h>') |
| 778 | header_txt.append('#include <string.h>') |
Karl Schultz | d7f3754 | 2016-05-10 11:36:08 -0600 | [diff] [blame] | 779 | header_txt.append('#include <cinttypes>') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 780 | header_txt.append('') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 781 | header_txt.append('#include <unordered_map>') |
Mark Lobodzinski | f93272b | 2016-05-02 12:08:24 -0600 | [diff] [blame] | 782 | header_txt.append('') |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 783 | header_txt.append('#include "vulkan/vk_layer.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 784 | header_txt.append('#include "vk_layer_config.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 785 | header_txt.append('#include "vk_layer_table.h"') |
| 786 | header_txt.append('#include "vk_layer_data.h"') |
| 787 | header_txt.append('#include "vk_layer_logging.h"') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 788 | header_txt.append('') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 789 | # NOTE: The non-autoGenerated code is in the object_tracker.h header file |
| 790 | header_txt.append('#include "object_tracker.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 791 | header_txt.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 792 | return "\n".join(header_txt) |
| 793 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 794 | def generate_maps(self): |
| 795 | maps_txt = [] |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 796 | for o in vulkan.object_type_list: |
Mark Lobodzinski | f93272b | 2016-05-02 12:08:24 -0600 | [diff] [blame] | 797 | maps_txt.append('std::unordered_map<uint64_t, OBJTRACK_NODE*> %sMap;' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 798 | return "\n".join(maps_txt) |
| 799 | |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 800 | def _gather_object_uses(self, obj_list, struct_type, obj_set): |
| 801 | # for each member of struct_type |
| 802 | # add objs in obj_list to obj_set |
| 803 | # call self for structs |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 804 | for m in sorted(vk_helper.struct_dict[struct_type]): |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 805 | if vk_helper.struct_dict[struct_type][m]['type'] in obj_list: |
| 806 | obj_set.add(vk_helper.struct_dict[struct_type][m]['type']) |
| 807 | elif vk_helper.is_type(vk_helper.struct_dict[struct_type][m]['type'], 'struct'): |
| 808 | obj_set = obj_set.union(self._gather_object_uses(obj_list, vk_helper.struct_dict[struct_type][m]['type'], obj_set)) |
| 809 | return obj_set |
| 810 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 811 | def generate_procs(self): |
| 812 | procs_txt = [] |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 813 | # First parse through funcs and gather dict of all objects seen by each call |
| 814 | obj_use_dict = {} |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 815 | proto_list = [] |
| 816 | for grp in vulkan.extensions: |
| 817 | proto_list += grp.protos |
| 818 | #vulkan.core.protos + vulkan.ext_khr_surface.protos + vulkan.ext_khr_surface.protos + vulkan.ext_khr_win32_surface.protos + vulkan.ext_khr_device_swapchain.protos |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 819 | for proto in proto_list: |
| 820 | disp_obj = proto.params[0].ty.strip('*').replace('const ', '') |
| 821 | if disp_obj in vulkan.object_dispatch_list: |
| 822 | if disp_obj not in obj_use_dict: |
| 823 | obj_use_dict[disp_obj] = set() |
| 824 | for p in proto.params[1:]: |
| 825 | base_type = p.ty.strip('*').replace('const ', '') |
| 826 | if base_type in vulkan.object_type_list: |
| 827 | obj_use_dict[disp_obj].add(base_type) |
| 828 | if vk_helper.is_type(base_type, 'struct'): |
| 829 | obj_use_dict[disp_obj] = self._gather_object_uses(vulkan.object_type_list, base_type, obj_use_dict[disp_obj]) |
| 830 | #for do in obj_use_dict: |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 831 | # print("Disp obj %s has uses for objs: %s" % (do, ', '.join(obj_use_dict[do]))) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 832 | |
| 833 | for o in vulkan.object_type_list:# vulkan.core.objects: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 834 | procs_txt.append('%s' % self.lineinfo.get()) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 835 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o) |
| 836 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 837 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 838 | procs_txt.append('static void create_%s(%s dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o, o)) |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 839 | elif o in ['VkSurfaceKHR', 'VkDisplayKHR', 'VkDisplayModeKHR']: |
| 840 | procs_txt.append('static void create_%s(VkPhysicalDevice dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 841 | else: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 842 | procs_txt.append('static void create_%s(VkDevice dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o)) |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 843 | procs_txt.append('{') |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 844 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType,(uint64_t)(vkObj), __LINE__, OBJTRACK_NONE, "OBJTRACK",') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 845 | procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDebugReportObjectTypeEXT(objType),') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 846 | procs_txt.append(' (uint64_t)(vkObj));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 847 | procs_txt.append('') |
| 848 | procs_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;') |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 849 | procs_txt.append(' pNewObjNode->belongsTo = (uint64_t)dispatchable_object;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 850 | procs_txt.append(' pNewObjNode->objType = objType;') |
| 851 | procs_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 852 | procs_txt.append(' pNewObjNode->vkObj = (uint64_t)(vkObj);') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 853 | procs_txt.append(' %sMap[(uint64_t)vkObj] = pNewObjNode;' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 854 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(objType);') |
| 855 | procs_txt.append(' numObjs[objIndex]++;') |
| 856 | procs_txt.append(' numTotalObjs++;') |
| 857 | procs_txt.append('}') |
| 858 | procs_txt.append('') |
| 859 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 860 | if o in vulkan.object_dispatch_list: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 861 | procs_txt.append('static void destroy_%s(%s dispatchable_object, %s object)' % (name, o, o)) |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 862 | elif o in ['VkSurfaceKHR', 'VkDisplayKHR', 'VkDisplayModeKHR']: |
| 863 | procs_txt.append('static void destroy_%s(VkPhysicalDevice dispatchable_object, %s object)' % (name, o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 864 | else: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 865 | procs_txt.append('static void destroy_%s(VkDevice dispatchable_object, %s object)' % (name, o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 866 | procs_txt.append('{') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 867 | procs_txt.append(' uint64_t object_handle = (uint64_t)(object);') |
Chris Forbes | bdbc113 | 2016-03-09 12:06:45 +1300 | [diff] [blame] | 868 | procs_txt.append(' auto it = %sMap.find(object_handle);' % o) |
| 869 | procs_txt.append(' if (it != %sMap.end()) {' % o) |
| 870 | procs_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 871 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);') |
| 872 | procs_txt.append(' assert(numTotalObjs > 0);') |
| 873 | procs_txt.append(' numTotalObjs--;') |
| 874 | procs_txt.append(' assert(numObjs[objIndex] > 0);') |
| 875 | procs_txt.append(' numObjs[objIndex]--;') |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 876 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType, object_handle, __LINE__, OBJTRACK_NONE, "OBJTRACK",') |
Michael Lentine | 010f469 | 2015-11-03 16:19:46 -0800 | [diff] [blame] | 877 | procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 878 | procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType), (uint64_t)(object), numTotalObjs, numObjs[objIndex],') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 879 | procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 880 | procs_txt.append(' delete pNode;') |
Chris Forbes | bdbc113 | 2016-03-09 12:06:45 +1300 | [diff] [blame] | 881 | procs_txt.append(' %sMap.erase(it);' % (o)) |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 882 | procs_txt.append(' } else {') |
Mark Lobodzinski | a1bf5db | 2016-05-02 13:19:15 -0600 | [diff] [blame] | 883 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT ) 0,') |
| 884 | procs_txt.append(' object_handle, __LINE__, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 885 | procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",') |
Mark Lobodzinski | a1bf5db | 2016-05-02 13:19:15 -0600 | [diff] [blame] | 886 | procs_txt.append(' object_handle);') |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 887 | procs_txt.append(' }') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 888 | procs_txt.append('}') |
| 889 | procs_txt.append('') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 890 | # Generate the permutations of validate_* functions where for each |
| 891 | # dispatchable object type, we have a corresponding validate_* function |
| 892 | # for that object and all non-dispatchable objects that are used in API |
| 893 | # calls with that dispatchable object. |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 894 | procs_txt.append('//%s' % str(sorted(obj_use_dict))) |
| 895 | for do in sorted(obj_use_dict): |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 896 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', do) |
| 897 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
| 898 | # First create validate_* func for disp obj |
| 899 | procs_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 900 | procs_txt.append('static bool validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, do)) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 901 | procs_txt.append('{') |
| 902 | procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))') |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 903 | procs_txt.append(' return false;') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 904 | procs_txt.append(' if (%sMap.find((uint64_t)object) == %sMap.end()) {' % (do, do)) |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 905 | procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
| 906 | procs_txt.append(' "Invalid %s Object 0x%%" PRIx64 ,(uint64_t)(object));' % do) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 907 | procs_txt.append(' }') |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 908 | procs_txt.append(' return false;') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 909 | procs_txt.append('}') |
| 910 | procs_txt.append('') |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 911 | for o in sorted(obj_use_dict[do]): |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 912 | if o == do: # We already generated this case above so skip here |
| 913 | continue |
| 914 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o) |
| 915 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
| 916 | procs_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 917 | procs_txt.append('static bool validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, o)) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 918 | procs_txt.append('{') |
| 919 | procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))') |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 920 | procs_txt.append(' return false;') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 921 | if o == "VkImage": |
| 922 | procs_txt.append(' // We need to validate normal image objects and those from the swapchain') |
| 923 | procs_txt.append(' if ((%sMap.find((uint64_t)object) == %sMap.end()) &&' % (o, o)) |
| 924 | procs_txt.append(' (swapchainImageMap.find((uint64_t)object) == swapchainImageMap.end())) {') |
| 925 | else: |
| 926 | procs_txt.append(' if (%sMap.find((uint64_t)object) == %sMap.end()) {' % (o, o)) |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 927 | procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
| 928 | procs_txt.append(' "Invalid %s Object 0x%%" PRIx64, (uint64_t)(object));' % o) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 929 | procs_txt.append(' }') |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 930 | procs_txt.append(' return false;') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 931 | procs_txt.append('}') |
| 932 | procs_txt.append('') |
| 933 | procs_txt.append('') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 934 | return "\n".join(procs_txt) |
| 935 | |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 936 | def generate_destroy_instance(self): |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 937 | gedi_txt = [] |
| 938 | gedi_txt.append('%s' % self.lineinfo.get()) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 939 | gedi_txt.append('VKAPI_ATTR void VKAPI_CALL DestroyInstance(') |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 940 | gedi_txt.append('VkInstance instance,') |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 941 | gedi_txt.append('const VkAllocationCallbacks* pAllocator)') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 942 | gedi_txt.append('{') |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 943 | gedi_txt.append(' std::unique_lock<std::mutex> lock(global_lock);') |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 944 | gedi_txt.append('') |
| 945 | gedi_txt.append(' dispatch_key key = get_dispatch_key(instance);') |
| 946 | gedi_txt.append(' layer_data *my_data = get_my_data_ptr(key, layer_data_map);') |
| 947 | gedi_txt.append('') |
| 948 | gedi_txt.append(' // Enable the temporary callback(s) here to catch cleanup issues:') |
| 949 | gedi_txt.append(' bool callback_setup = false;') |
| 950 | gedi_txt.append(' if (my_data->num_tmp_callbacks > 0) {') |
| 951 | gedi_txt.append(' if (!layer_enable_tmp_callbacks(my_data->report_data,') |
| 952 | gedi_txt.append(' my_data->num_tmp_callbacks,') |
| 953 | gedi_txt.append(' my_data->tmp_dbg_create_infos,') |
| 954 | gedi_txt.append(' my_data->tmp_callbacks)) {') |
| 955 | gedi_txt.append(' callback_setup = true;') |
| 956 | gedi_txt.append(' }') |
| 957 | gedi_txt.append(' }') |
| 958 | gedi_txt.append('') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 959 | gedi_txt.append(' validate_instance(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, false);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 960 | gedi_txt.append('') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 961 | gedi_txt.append(' destroy_instance(instance, instance);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 962 | gedi_txt.append(' // Report any remaining objects in LL') |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 963 | gedi_txt.append('') |
| 964 | gedi_txt.append(' for (auto iit = VkDeviceMap.begin(); iit != VkDeviceMap.end();) {') |
| 965 | gedi_txt.append(' OBJTRACK_NODE* pNode = iit->second;') |
| 966 | gedi_txt.append(' if (pNode->belongsTo == (uint64_t)instance) {') |
| 967 | gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 968 | gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),') |
| 969 | gedi_txt.append(' pNode->vkObj);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 970 | for o in vulkan.core.objects: |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 971 | if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue', 'VkDevice']: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 972 | continue |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 973 | gedi_txt.append(' for (auto idt = %sMap.begin(); idt != %sMap.end();) {' % (o, o)) |
| 974 | gedi_txt.append(' OBJTRACK_NODE* pNode = idt->second;') |
| 975 | gedi_txt.append(' if (pNode->belongsTo == iit->first) {') |
| 976 | gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 977 | gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),') |
| 978 | gedi_txt.append(' pNode->vkObj);') |
| 979 | gedi_txt.append(' %sMap.erase(idt++);' % o ) |
| 980 | gedi_txt.append(' } else {') |
| 981 | gedi_txt.append(' ++idt;') |
| 982 | gedi_txt.append(' }') |
| 983 | gedi_txt.append(' }') |
| 984 | gedi_txt.append(' VkDeviceMap.erase(iit++);') |
| 985 | gedi_txt.append(' } else {') |
| 986 | gedi_txt.append(' ++iit;') |
| 987 | gedi_txt.append(' }') |
| 988 | gedi_txt.append(' }') |
| 989 | gedi_txt.append('') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 990 | gedi_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, instance);') |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 991 | gedi_txt.append(' pInstanceTable->DestroyInstance(instance, pAllocator);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 992 | gedi_txt.append('') |
Ian Elliott | ed6b5ac | 2016-04-28 09:08:13 -0600 | [diff] [blame] | 993 | gedi_txt.append(' // Disable and cleanup the temporary callback(s):') |
| 994 | gedi_txt.append(' if (callback_setup) {') |
| 995 | gedi_txt.append(' layer_disable_tmp_callbacks(my_data->report_data,') |
| 996 | gedi_txt.append(' my_data->num_tmp_callbacks,') |
| 997 | gedi_txt.append(' my_data->tmp_callbacks);') |
| 998 | gedi_txt.append(' }') |
| 999 | gedi_txt.append(' if (my_data->num_tmp_callbacks > 0) {') |
| 1000 | gedi_txt.append(' layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos,') |
| 1001 | gedi_txt.append(' my_data->tmp_callbacks);') |
| 1002 | gedi_txt.append(' my_data->num_tmp_callbacks = 0;') |
| 1003 | gedi_txt.append(' }') |
| 1004 | gedi_txt.append('') |
Mark Lobodzinski | 1079e1b | 2016-03-15 14:21:59 -0600 | [diff] [blame] | 1005 | gedi_txt.append(' // Clean up logging callback, if any') |
| 1006 | gedi_txt.append(' while (my_data->logging_callback.size() > 0) {') |
| 1007 | gedi_txt.append(' VkDebugReportCallbackEXT callback = my_data->logging_callback.back();') |
| 1008 | gedi_txt.append(' layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);') |
| 1009 | gedi_txt.append(' my_data->logging_callback.pop_back();') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1010 | gedi_txt.append(' }') |
| 1011 | gedi_txt.append('') |
| 1012 | gedi_txt.append(' layer_debug_report_destroy_instance(mid(instance));') |
Tobin Ehlis | 4192fdf | 2016-04-18 15:40:59 -0600 | [diff] [blame] | 1013 | gedi_txt.append(' layer_data_map.erase(key);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1014 | gedi_txt.append('') |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 1015 | gedi_txt.append(' instanceExtMap.erase(pInstanceTable);') |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1016 | gedi_txt.append(' lock.unlock();') |
Mike Stroyan | 0699a79 | 2015-08-18 14:48:34 -0600 | [diff] [blame] | 1017 | # The loader holds a mutex that protects this from other threads |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1018 | gedi_txt.append(' object_tracker_instance_table_map.erase(key);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1019 | gedi_txt.append('}') |
| 1020 | gedi_txt.append('') |
| 1021 | return "\n".join(gedi_txt) |
| 1022 | |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1023 | def generate_destroy_device(self): |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1024 | gedd_txt = [] |
| 1025 | gedd_txt.append('%s' % self.lineinfo.get()) |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 1026 | gedd_txt.append('VKAPI_ATTR void VKAPI_CALL DestroyDevice(') |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1027 | gedd_txt.append('VkDevice device,') |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1028 | gedd_txt.append('const VkAllocationCallbacks* pAllocator)') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1029 | gedd_txt.append('{') |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1030 | gedd_txt.append(' std::unique_lock<std::mutex> lock(global_lock);') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1031 | gedd_txt.append(' validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1032 | gedd_txt.append('') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1033 | gedd_txt.append(' destroy_device(device, device);') |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 1034 | gedd_txt.append(' // Report any remaining objects associated with this VkDevice object in LL') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1035 | for o in vulkan.core.objects: |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1036 | # DescriptorSets and Command Buffers are destroyed through their pools, not explicitly |
| 1037 | if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue', 'VkDevice', 'VkDescriptorSet', 'VkCommandBuffer']: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1038 | continue |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 1039 | gedd_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end();) {' % (o, o)) |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1040 | gedd_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
Mark Lobodzinski | c857fb3 | 2016-03-08 15:10:00 -0700 | [diff] [blame] | 1041 | gedd_txt.append(' if (pNode->belongsTo == (uint64_t)device) {') |
| 1042 | gedd_txt.append(' log_msg(mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 1043 | gedd_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),') |
| 1044 | gedd_txt.append(' pNode->vkObj);') |
| 1045 | gedd_txt.append(' %sMap.erase(it++);' % o ) |
| 1046 | gedd_txt.append(' } else {') |
| 1047 | gedd_txt.append(' ++it;') |
| 1048 | gedd_txt.append(' }') |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1049 | gedd_txt.append(' }') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1050 | gedd_txt.append('') |
| 1051 | gedd_txt.append(" // Clean up Queue's MemRef Linked Lists") |
| 1052 | gedd_txt.append(' destroyQueueMemRefLists();') |
| 1053 | gedd_txt.append('') |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1054 | gedd_txt.append(' lock.unlock();') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1055 | gedd_txt.append('') |
| 1056 | gedd_txt.append(' dispatch_key key = get_dispatch_key(device);') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1057 | gedd_txt.append(' VkLayerDispatchTable *pDisp = get_dispatch_table(object_tracker_device_table_map, device);') |
Chia-I Wu | f7458c5 | 2015-10-26 21:10:41 +0800 | [diff] [blame] | 1058 | gedd_txt.append(' pDisp->DestroyDevice(device, pAllocator);') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1059 | gedd_txt.append(' object_tracker_device_table_map.erase(key);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1060 | gedd_txt.append('') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1061 | gedd_txt.append('}') |
| 1062 | gedd_txt.append('') |
| 1063 | return "\n".join(gedd_txt) |
| 1064 | |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 1065 | # Special-case validating some objects -- they may be non-NULL but should |
| 1066 | # only be validated upon meeting some condition specified below. |
| 1067 | def _dereference_conditionally(self, indent, prefix, type_name, name): |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1068 | s_code = '' |
| 1069 | if type_name == 'pBufferInfo': |
| 1070 | s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||\n' % (indent, prefix) |
| 1071 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||\n' % (indent, prefix) |
| 1072 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||\n' % (indent, prefix) |
| 1073 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) ) {\n' % (indent, prefix) |
| 1074 | elif type_name == 'pImageInfo': |
| 1075 | s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||\n' % (indent, prefix) |
| 1076 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||\n' % (indent, prefix) |
| 1077 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) ||\n' % (indent, prefix) |
| 1078 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||\n' % (indent, prefix) |
| 1079 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ) {\n' % (indent, prefix) |
| 1080 | elif type_name == 'pTexelBufferView': |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 1081 | s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||\n' % (indent, prefix) |
| 1082 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) ) {\n' % (indent, prefix) |
| 1083 | elif name == 'pBeginInfo->pInheritanceInfo': |
| 1084 | s_code += '%sOBJTRACK_NODE* pNode = VkCommandBufferMap[(uint64_t)commandBuffer];\n' % (indent) |
| 1085 | s_code += '%sif ((%s) && (pNode->status & OBJSTATUS_COMMAND_BUFFER_SECONDARY)) {\n' % (indent, name) |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1086 | else: |
| 1087 | s_code += '%sif (%s) {\n' % (indent, name) |
| 1088 | return s_code |
| 1089 | |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1090 | def _gen_obj_validate_code(self, struct_uses, obj_type_mapping, func_name, valid_null_dict, param0_name, indent, prefix, array_index): |
| 1091 | pre_code = '' |
| 1092 | for obj in sorted(struct_uses): |
| 1093 | name = obj |
| 1094 | array = '' |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1095 | type_name = '' |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1096 | if '[' in obj: |
| 1097 | (name, array) = obj.split('[') |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1098 | type_name = name |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1099 | array = array.strip(']') |
| 1100 | if isinstance(struct_uses[obj], dict): |
| 1101 | local_prefix = '' |
| 1102 | name = '%s%s' % (prefix, name) |
| 1103 | ptr_type = False |
| 1104 | if 'p' == obj[0]: |
| 1105 | ptr_type = True |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 1106 | tmp_pre = self._dereference_conditionally(indent, prefix, type_name, name) |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1107 | pre_code += tmp_pre |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1108 | indent += ' ' |
| 1109 | if array != '': |
| 1110 | idx = 'idx%s' % str(array_index) |
| 1111 | array_index += 1 |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1112 | deref = '' |
| 1113 | if 'p' == array[0]: |
| 1114 | deref = '*' |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1115 | pre_code += '%s\n' % self.lineinfo.get() |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1116 | pre_code += '%sfor (uint32_t %s=0; %s<%s%s%s; ++%s) {\n' % (indent, idx, idx, deref, prefix, array, idx) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1117 | indent += ' ' |
| 1118 | local_prefix = '%s[%s].' % (name, idx) |
| 1119 | elif ptr_type: |
| 1120 | local_prefix = '%s->' % (name) |
| 1121 | else: |
| 1122 | local_prefix = '%s.' % (name) |
| 1123 | tmp_pre = self._gen_obj_validate_code(struct_uses[obj], obj_type_mapping, func_name, valid_null_dict, param0_name, indent, local_prefix, array_index) |
| 1124 | pre_code += tmp_pre |
| 1125 | if array != '': |
| 1126 | indent = indent[4:] |
| 1127 | pre_code += '%s}\n' % (indent) |
| 1128 | if ptr_type: |
| 1129 | indent = indent[4:] |
| 1130 | pre_code += '%s}\n' % (indent) |
| 1131 | else: |
| 1132 | ptype = struct_uses[obj] |
| 1133 | dbg_obj_type = obj_type_mapping[ptype] |
| 1134 | fname = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', ptype) |
| 1135 | fname = re.sub('([a-z0-9])([A-Z])', r'\1_\2', fname).lower()[3:] |
| 1136 | full_name = '%s%s' % (prefix, name) |
| 1137 | null_obj_ok = 'false' |
| 1138 | # If a valid null param is defined for this func and we have a match, allow NULL |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 1139 | if func_name in valid_null_dict and True in [name in pn for pn in sorted(valid_null_dict[func_name])]: |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1140 | null_obj_ok = 'true' |
| 1141 | if (array_index > 0) or '' != array: |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 1142 | tmp_pre = self._dereference_conditionally(indent, prefix, type_name, full_name) |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1143 | pre_code += tmp_pre |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1144 | indent += ' ' |
| 1145 | if array != '': |
| 1146 | idx = 'idx%s' % str(array_index) |
| 1147 | array_index += 1 |
| 1148 | pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx) |
| 1149 | indent += ' ' |
| 1150 | full_name = '%s[%s]' % (full_name, idx) |
| 1151 | pre_code += '%s\n' % self.lineinfo.get() |
| 1152 | pre_code += '%sskipCall |= validate_%s(%s, %s, %s, %s);\n' %(indent, fname, param0_name, full_name, dbg_obj_type, null_obj_ok) |
| 1153 | if array != '': |
| 1154 | indent = indent[4:] |
| 1155 | pre_code += '%s}\n' % (indent) |
| 1156 | indent = indent[4:] |
| 1157 | pre_code += '%s}\n' % (indent) |
| 1158 | else: |
| 1159 | pre_code += '%s\n' % self.lineinfo.get() |
| 1160 | pre_code += '%sskipCall |= validate_%s(%s, %s, %s, %s);\n' %(indent, fname, param0_name, full_name, dbg_obj_type, null_obj_ok) |
| 1161 | return pre_code |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1162 | |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1163 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1164 | if proto.name in [ 'CreateDebugReportCallbackEXT', 'EnumerateInstanceLayerProperties', 'EnumerateInstanceExtensionProperties','EnumerateDeviceLayerProperties', 'EnumerateDeviceExtensionProperties' ]: |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1165 | # use default version |
| 1166 | return None |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1167 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1168 | # Create map of object names to object type enums of the form VkName : VkObjectTypeName |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1169 | obj_type_mapping = {base_t : base_t.replace("Vk", "VkDebugReportObjectType") for base_t in vulkan.object_type_list} |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1170 | # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES |
| 1171 | for objectName, objectTypeEnum in obj_type_mapping.items(): |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1172 | obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum) + '_EXT'; |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1173 | # Command Buffer Object doesn't follow the rule. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1174 | obj_type_mapping['VkCommandBuffer'] = "VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT" |
| 1175 | obj_type_mapping['VkShaderModule'] = "VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT" |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1176 | obj_type_mapping['VkDisplayKHR'] = "VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT" |
| 1177 | obj_type_mapping['VkDisplayModeKHR'] = "VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT" |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1178 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1179 | explicit_object_tracker_functions = [ |
| 1180 | "CreateInstance", |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1181 | "EnumeratePhysicalDevices", |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 1182 | "GetPhysicalDeviceQueueFamilyProperties", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1183 | "CreateDevice", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1184 | "GetDeviceQueue", |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 1185 | "QueueBindSparse", |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1186 | "AllocateDescriptorSets", |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 1187 | "FreeDescriptorSets", |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1188 | "CreateGraphicsPipelines", |
| 1189 | "CreateComputePipelines", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1190 | "AllocateCommandBuffers", |
| 1191 | "FreeCommandBuffers", |
| 1192 | "DestroyDescriptorPool", |
| 1193 | "DestroyCommandPool", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1194 | "MapMemory", |
| 1195 | "UnmapMemory", |
| 1196 | "FreeMemory", |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1197 | "DestroySwapchainKHR", |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1198 | "GetSwapchainImagesKHR", |
Jon Ashburn | 665d1d5 | 2016-06-28 16:59:36 -0600 | [diff] [blame] | 1199 | "GetPhysicalDeviceDisplayPropertiesKHR", |
| 1200 | "GetDisplayModePropertiesKHR" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1201 | ] |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 1202 | decl = proto.c_func(attr="VKAPI") |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1203 | param0_name = proto.params[0].name |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1204 | using_line = '' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1205 | create_line = '' |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1206 | destroy_line = '' |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1207 | # Dict below tracks params that are vk objects. Dict is "loop count"->["params w/ that loop count"] where '0' is params that aren't in an array |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1208 | # TODO : Should integrate slightly better code for this purpose from unique_objects layer |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1209 | loop_params = defaultdict(list) # Dict uses loop count as key to make final code generation cleaner so params shared in single loop where needed |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1210 | loop_types = defaultdict(list) |
Tobin Ehlis | 2717d13 | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1211 | # TODO : For now skipping objs that can be NULL. Really should check these and have special case that allows them to be NULL |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1212 | # or better yet, these should be encoded into an API json definition and we generate checks from there |
| 1213 | # Until then, this is a dict where each func name is a list of object params that can be null (so don't need to be validated) |
| 1214 | # param names may be directly passed to the function, or may be a field in a struct param |
| 1215 | valid_null_object_names = {'CreateGraphicsPipelines' : ['basePipelineHandle'], |
| 1216 | 'CreateComputePipelines' : ['basePipelineHandle'], |
| 1217 | 'BeginCommandBuffer' : ['renderPass', 'framebuffer'], |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1218 | 'QueueSubmit' : ['fence'], |
Jon Ashburn | 9216ae4 | 2016-01-14 15:11:55 -0700 | [diff] [blame] | 1219 | 'AcquireNextImageKHR' : ['fence', 'semaphore' ], |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 1220 | 'UpdateDescriptorSets' : ['pTexelBufferView'], |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1221 | 'CreateSwapchainKHR' : ['oldSwapchain'], |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1222 | } |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1223 | param_count = 'NONE' # keep track of arrays passed directly into API functions |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1224 | for p in proto.params: |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1225 | base_type = p.ty.replace('const ', '').strip('*') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1226 | if 'count' in p.name.lower(): |
| 1227 | param_count = p.name |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1228 | if base_type in vulkan.core.objects: |
| 1229 | # This is an object to potentially check for validity. First see if it's an array |
| 1230 | if '*' in p.ty and 'const' in p.ty and param_count != 'NONE': |
| 1231 | loop_params[param_count].append(p.name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1232 | loop_types[param_count].append(str(p.ty[6:-1])) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1233 | # Not an array, check for just a base Object that's not in exceptions |
| 1234 | elif '*' not in p.ty and (proto.name not in valid_null_object_names or p.name not in valid_null_object_names[proto.name]): |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1235 | loop_params[0].append(p.name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1236 | loop_types[0].append(str(p.ty)) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1237 | elif vk_helper.is_type(base_type, 'struct'): |
| 1238 | struct_type = base_type |
Tobin Ehlis | 9d67594 | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1239 | if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict: |
| 1240 | struct_type = vk_helper.typedef_rev_dict[struct_type] |
Tobin Ehlis | 82b3db5 | 2015-10-23 17:52:53 -0600 | [diff] [blame] | 1241 | # Parse elements of this struct param to identify objects and/or arrays of objects |
Tobin Ehlis | 9d67594 | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1242 | for m in sorted(vk_helper.struct_dict[struct_type]): |
| 1243 | if vk_helper.struct_dict[struct_type][m]['type'] in vulkan.core.objects and vk_helper.struct_dict[struct_type][m]['type'] not in ['VkPhysicalDevice', 'VkQueue', 'VkFence', 'VkImage', 'VkDeviceMemory']: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1244 | if proto.name not in valid_null_object_names or vk_helper.struct_dict[struct_type][m]['name'] not in valid_null_object_names[proto.name]: |
Tobin Ehlis | 82b3db5 | 2015-10-23 17:52:53 -0600 | [diff] [blame] | 1245 | # This is not great, but gets the job done for now, but If we have a count and this param is a ptr w/ |
| 1246 | # last letter 's' OR non-'count' string of count is in the param name, then this is a dynamically sized array param |
| 1247 | param_array = False |
| 1248 | if param_count != 'NONE': |
| 1249 | if '*' in p.ty: |
| 1250 | if 's' == p.name[-1] or param_count.lower().replace('count', '') in p.name.lower(): |
| 1251 | param_array = True |
| 1252 | if param_array: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1253 | param_name = '%s[i].%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name']) |
Tobin Ehlis | 46d5362 | 2015-07-10 11:10:21 -0600 | [diff] [blame] | 1254 | else: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1255 | param_name = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name']) |
| 1256 | if vk_helper.struct_dict[struct_type][m]['dyn_array']: |
Tobin Ehlis | 82b3db5 | 2015-10-23 17:52:53 -0600 | [diff] [blame] | 1257 | if param_count != 'NONE': # this will be a double-embedded loop, use comma delineated 'count,name' for param_name |
| 1258 | loop_count = '%s[i].%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size']) |
| 1259 | loop_params[param_count].append('%s,%s' % (loop_count, param_name)) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1260 | loop_types[param_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type'])) |
Tobin Ehlis | 82b3db5 | 2015-10-23 17:52:53 -0600 | [diff] [blame] | 1261 | else: |
| 1262 | loop_count = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size']) |
| 1263 | loop_params[loop_count].append(param_name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1264 | loop_types[loop_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type'])) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1265 | else: |
| 1266 | if '[' in param_name: # dynamic array param, set size |
| 1267 | loop_params[param_count].append(param_name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1268 | loop_types[param_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type'])) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1269 | else: |
| 1270 | loop_params[0].append(param_name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1271 | loop_types[0].append('%s' % (vk_helper.struct_dict[struct_type][m]['type'])) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1272 | last_param_index = None |
| 1273 | create_func = False |
| 1274 | if True in [create_txt in proto.name for create_txt in ['Create', 'Allocate']]: |
| 1275 | create_func = True |
| 1276 | last_param_index = -1 # For create funcs don't validate last object |
Jon Ashburn | 665d1d5 | 2016-06-28 16:59:36 -0600 | [diff] [blame] | 1277 | if proto.name == 'GetDisplayPlaneSupportedDisplaysKHR': |
| 1278 | last_param_index = -1 # don't validate the DisplayKHR objects which are non-created output parameters |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1279 | (struct_uses, local_decls) = get_object_uses(vulkan.object_type_list, proto.params[:last_param_index]) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1280 | funcs = [] |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1281 | mutex_unlock = False |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1282 | funcs.append('%s\n' % self.lineinfo.get()) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1283 | if proto.name in explicit_object_tracker_functions: |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1284 | funcs.append('%s%s\n' |
| 1285 | '{\n' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1286 | ' return explicit_%s;\n' |
| 1287 | '}' % (qual, decl, proto.c_call())) |
| 1288 | return "".join(funcs) |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1289 | elif 'DestroyInstance' in proto.name or 'DestroyDevice' in proto.name: |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1290 | return "" |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1291 | else: |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1292 | if create_func: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1293 | typ = proto.params[-1].ty.strip('*').replace('const ', ''); |
| 1294 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ) |
| 1295 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1296 | create_line = ' {\n' |
| 1297 | create_line += ' std::lock_guard<std::mutex> lock(global_lock);\n' |
| 1298 | create_line += ' if (result == VK_SUCCESS) {\n' |
| 1299 | create_line += ' create_%s(%s, *%s, %s);\n' % (name, param0_name, proto.params[-1].name, obj_type_mapping[typ]) |
| 1300 | create_line += ' }\n' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1301 | create_line += ' }\n' |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 1302 | if 'FreeCommandBuffers' in proto.name: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1303 | typ = proto.params[-1].ty.strip('*').replace('const ', ''); |
| 1304 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ) |
| 1305 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 1306 | funcs.append('%s\n' % self.lineinfo.get()) |
| 1307 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1308 | destroy_line += ' for (uint32_t i = 0; i < commandBufferCount; i++) {\n' |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1309 | destroy_line += ' destroy_%s(%s[i], %s[i]);\n' % (name, proto.params[-1].name, proto.params[-1].name) |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 1310 | destroy_line += ' }\n' |
| 1311 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1312 | if 'Destroy' in proto.name: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1313 | typ = proto.params[-2].ty.strip('*').replace('const ', ''); |
| 1314 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ) |
| 1315 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 1316 | funcs.append('%s\n' % self.lineinfo.get()) |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1317 | destroy_line = ' {\n' |
| 1318 | destroy_line += ' std::lock_guard<std::mutex> lock(global_lock);\n' |
| 1319 | destroy_line += ' destroy_%s(%s, %s);\n' % (name, param0_name, proto.params[-2].name) |
| 1320 | destroy_line += ' }\n' |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1321 | indent = ' ' |
| 1322 | if len(struct_uses) > 0: |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1323 | using_line += '%sbool skipCall = false;\n' % (indent) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1324 | if not mutex_unlock: |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1325 | using_line += '%s{\n' % (indent) |
| 1326 | indent += ' ' |
| 1327 | using_line += '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % (indent) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1328 | mutex_unlock = True |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 1329 | using_line += '// objects to validate: %s\n' % str(sorted(struct_uses)) |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1330 | using_line += self._gen_obj_validate_code(struct_uses, obj_type_mapping, proto.name, valid_null_object_names, param0_name, indent, '', 0) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1331 | if mutex_unlock: |
Jeremy Hayes | 2f065b1 | 2016-04-13 10:54:17 -0600 | [diff] [blame] | 1332 | indent = indent[4:] |
| 1333 | using_line += '%s}\n' % (indent) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1334 | if len(struct_uses) > 0: |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 1335 | using_line += ' if (skipCall)\n' |
Mark Lobodzinski | 2abefa9 | 2016-05-05 11:45:57 -0600 | [diff] [blame] | 1336 | if proto.ret == "bool": |
| 1337 | using_line += ' return false;\n' |
Jamie Madill | 940c4bd | 2016-05-11 16:11:47 -0400 | [diff] [blame] | 1338 | elif proto.ret == "VkBool32": |
| 1339 | using_line += ' return VK_FALSE;\n' |
Jamie Madill | 2bf385b | 2016-04-04 12:15:39 -0400 | [diff] [blame] | 1340 | elif proto.ret != "void": |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1341 | using_line += ' return VK_ERROR_VALIDATION_FAILED_EXT;\n' |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 1342 | else: |
| 1343 | using_line += ' return;\n' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1344 | ret_val = '' |
| 1345 | stmt = '' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1346 | if proto.ret != "void": |
| 1347 | ret_val = "%s result = " % proto.ret |
| 1348 | stmt = " return result;\n" |
| 1349 | |
| 1350 | dispatch_param = proto.params[0].name |
| 1351 | if 'CreateInstance' in proto.name: |
| 1352 | dispatch_param = '*' + proto.params[1].name |
| 1353 | |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1354 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 1355 | table_type = "" |
| 1356 | if proto_is_global(proto): |
| 1357 | table_type = "instance" |
| 1358 | else: |
| 1359 | table_type = "device" |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 1360 | if wsi_name(proto.name): |
| 1361 | funcs.append('%s' % wsi_ifdef(proto.name)) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1362 | funcs.append('%s%s\n' |
| 1363 | '{\n' |
| 1364 | '%s' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1365 | '%s' |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1366 | ' %sget_dispatch_table(object_tracker_%s_table_map, %s)->%s;\n' |
Mike Stroyan | 38820b3 | 2015-09-28 13:47:29 -0600 | [diff] [blame] | 1367 | '%s' |
| 1368 | '%s' |
| 1369 | '}' % (qual, decl, using_line, destroy_line, ret_val, table_type, dispatch_param, proto.c_call(), create_line, stmt)) |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 1370 | if wsi_name(proto.name): |
| 1371 | funcs.append('%s' % wsi_endif(proto.name)) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1372 | return "\n\n".join(funcs) |
| 1373 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1374 | def generate_body(self): |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1375 | self.layer_name = "object_tracker" |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 1376 | extensions=[('wsi_enabled', |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 1377 | ['vkCreateSwapchainKHR', |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 1378 | 'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR', |
| 1379 | 'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])] |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1380 | additional_instance_extensions = [ |
| 1381 | 'vkDestroySurfaceKHR', |
| 1382 | 'vkGetPhysicalDeviceSurfaceSupportKHR', |
| 1383 | 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR', |
| 1384 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
| 1385 | 'vkGetPhysicalDeviceSurfacePresentModesKHR', |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1386 | 'vkGetPhysicalDeviceDisplayPropertiesKHR', |
| 1387 | 'vkGetPhysicalDeviceDisplayPlanePropertiesKHR', |
| 1388 | 'vkGetDisplayPlaneSupportedDisplaysKHR', |
| 1389 | 'vkGetDisplayModePropertiesKHR', |
| 1390 | 'vkCreateDisplayModeKHR', |
| 1391 | 'vkGetDisplayPlaneCapabilitiesKHR', |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1392 | 'vkCreateDisplayPlaneSurfaceKHR', |
| 1393 | ] |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1394 | if self.wsi == 'Win32': |
Michael Lentine | 64e2ebd | 2015-12-03 14:33:09 -0800 | [diff] [blame] | 1395 | instance_extensions=[('msg_callback_get_proc_addr', []), |
| 1396 | ('wsi_enabled', |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1397 | ['vkCreateWin32SurfaceKHR', |
| 1398 | 'vkGetPhysicalDeviceWin32PresentationSupportKHR'] + additional_instance_extensions)] |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1399 | elif self.wsi == 'Android': |
| 1400 | instance_extensions=[('msg_callback_get_proc_addr', []), |
| 1401 | ('wsi_enabled', |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1402 | ['vkCreateAndroidSurfaceKHR'] + additional_instance_extensions)] |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame] | 1403 | elif self.wsi == 'Xcb' or self.wsi == 'Xlib' or self.wsi == 'Wayland' or self.wsi == 'Mir': |
Michael Lentine | 64e2ebd | 2015-12-03 14:33:09 -0800 | [diff] [blame] | 1404 | instance_extensions=[('msg_callback_get_proc_addr', []), |
| 1405 | ('wsi_enabled', |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1406 | additional_instance_extensions + ['vkCreateXcbSurfaceKHR', |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame] | 1407 | 'vkGetPhysicalDeviceXcbPresentationSupportKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1408 | 'vkCreateXlibSurfaceKHR', |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame] | 1409 | 'vkGetPhysicalDeviceXlibPresentationSupportKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1410 | 'vkCreateWaylandSurfaceKHR', |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame] | 1411 | 'vkGetPhysicalDeviceWaylandPresentationSupportKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1412 | 'vkCreateMirSurfaceKHR', |
| 1413 | 'vkGetPhysicalDeviceMirPresentationSupportKHR'])] |
Mark Lobodzinski | d53098f | 2016-02-25 18:14:56 -0700 | [diff] [blame] | 1414 | else: |
| 1415 | print('Error: Undefined DisplayServer') |
| 1416 | instance_extensions=[] |
| 1417 | |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 1418 | body = ["namespace %s {" % self.layer_name, |
| 1419 | self.generate_maps(), |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1420 | self.generate_procs(), |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1421 | self.generate_destroy_instance(), |
| 1422 | self.generate_destroy_device(), |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 1423 | self._generate_dispatch_entrypoints(), |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1424 | self._generate_extensions(), |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1425 | self._generate_layer_introspection_function(), |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1426 | self._generate_layer_gpa_function(extensions, |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 1427 | instance_extensions), |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 1428 | "} // namespace %s" % self.layer_name, |
| 1429 | self._gen_layer_logging_workaround(), |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 1430 | self._gen_layer_interface_v0_functions()] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1431 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1432 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1433 | class UniqueObjectsSubcommand(Subcommand): |
| 1434 | def generate_header(self): |
| 1435 | header_txt = [] |
| 1436 | header_txt.append('%s' % self.lineinfo.get()) |
| 1437 | header_txt.append('#include "unique_objects.h"') |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1438 | return "\n".join(header_txt) |
| 1439 | |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1440 | # Generate UniqueObjects code for given struct_uses dict of objects that need to be unwrapped |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1441 | # vector_name_set is used to make sure we don't replicate vector names |
| 1442 | # first_level_param indicates if elements are passed directly into the function else they're below a ptr/struct |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1443 | # TODO : Comment this code |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1444 | def _gen_obj_code(self, struct_uses, param_type, indent, prefix, array_index, vector_name_set, first_level_param): |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1445 | decls = '' |
| 1446 | pre_code = '' |
| 1447 | post_code = '' |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1448 | for obj in sorted(struct_uses): |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1449 | name = obj |
| 1450 | array = '' |
| 1451 | if '[' in obj: |
| 1452 | (name, array) = obj.split('[') |
| 1453 | array = array.strip(']') |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1454 | ptr_type = False |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1455 | if 'p' == obj[0] and obj[1] != obj[1].lower(): # TODO : Not ideal way to determine ptr |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1456 | ptr_type = True |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1457 | if isinstance(struct_uses[obj], dict): |
| 1458 | local_prefix = '' |
| 1459 | name = '%s%s' % (prefix, name) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1460 | if ptr_type: |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1461 | if first_level_param and name in param_type: |
| 1462 | pre_code += '%sif (%s) {\n' % (indent, name) |
| 1463 | else: # shadow ptr will have been initialized at this point so check it vs. source ptr |
| 1464 | pre_code += '%sif (local_%s) {\n' % (indent, name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1465 | indent += ' ' |
| 1466 | if array != '': |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1467 | if 'p' == array[0] and array[1] != array[1].lower(): # TODO : Not ideal way to determine ptr |
| 1468 | count_prefix = '*' |
| 1469 | else: |
| 1470 | count_prefix = '' |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1471 | idx = 'idx%s' % str(array_index) |
| 1472 | array_index += 1 |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1473 | if first_level_param and name in param_type: |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1474 | pre_code += '%slocal_%s = new safe_%s[%s%s];\n' % (indent, name, param_type[name].strip('*'), count_prefix, array) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1475 | post_code += ' if (local_%s)\n' % (name) |
| 1476 | post_code += ' delete[] local_%s;\n' % (name) |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1477 | pre_code += '%sfor (uint32_t %s=0; %s<%s%s%s; ++%s) {\n' % (indent, idx, idx, count_prefix, prefix, array, idx) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1478 | indent += ' ' |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1479 | if first_level_param: |
| 1480 | pre_code += '%slocal_%s[%s].initialize(&%s[%s]);\n' % (indent, name, idx, name, idx) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1481 | local_prefix = '%s[%s].' % (name, idx) |
| 1482 | elif ptr_type: |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1483 | if first_level_param and name in param_type: |
| 1484 | pre_code += '%slocal_%s = new safe_%s(%s);\n' % (indent, name, param_type[name].strip('*'), name) |
| 1485 | post_code += ' if (local_%s)\n' % (name) |
| 1486 | post_code += ' delete local_%s;\n' % (name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1487 | local_prefix = '%s->' % (name) |
| 1488 | else: |
| 1489 | local_prefix = '%s.' % (name) |
| 1490 | assert isinstance(decls, object) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1491 | (tmp_decl, tmp_pre, tmp_post) = self._gen_obj_code(struct_uses[obj], param_type, indent, local_prefix, array_index, vector_name_set, False) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1492 | decls += tmp_decl |
| 1493 | pre_code += tmp_pre |
| 1494 | post_code += tmp_post |
| 1495 | if array != '': |
| 1496 | indent = indent[4:] |
| 1497 | pre_code += '%s}\n' % (indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1498 | if ptr_type: |
| 1499 | indent = indent[4:] |
| 1500 | pre_code += '%s}\n' % (indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1501 | else: |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1502 | if (array_index > 0) or array != '': # TODO : This is not ideal, really want to know if we're anywhere under an array |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1503 | if first_level_param: |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1504 | decls += '%s%s* local_%s = NULL;\n' % (indent, struct_uses[obj], name) |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1505 | if array != '' and not first_level_param: # ptrs under structs will have been initialized so use local_* |
| 1506 | pre_code += '%sif (local_%s%s) {\n' %(indent, prefix, name) |
| 1507 | else: |
| 1508 | pre_code += '%sif (%s%s) {\n' %(indent, prefix, name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1509 | indent += ' ' |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1510 | if array != '': |
| 1511 | idx = 'idx%s' % str(array_index) |
| 1512 | array_index += 1 |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1513 | if first_level_param: |
| 1514 | pre_code += '%slocal_%s = new %s[%s];\n' % (indent, name, struct_uses[obj], array) |
| 1515 | post_code += ' if (local_%s)\n' % (name) |
| 1516 | post_code += ' delete[] local_%s;\n' % (name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1517 | pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1518 | indent += ' ' |
| 1519 | name = '%s[%s]' % (name, idx) |
| 1520 | pName = 'p%s' % (struct_uses[obj][2:]) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1521 | if name not in vector_name_set: |
| 1522 | vector_name_set.add(name) |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 1523 | pre_code += '%slocal_%s%s = (%s)my_map_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(%s%s)];\n' % (indent, prefix, name, struct_uses[obj], prefix, name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1524 | if array != '': |
| 1525 | indent = indent[4:] |
| 1526 | pre_code += '%s}\n' % (indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1527 | indent = indent[4:] |
| 1528 | pre_code += '%s}\n' % (indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1529 | else: |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1530 | pre_code += '%s\n' % (self.lineinfo.get()) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1531 | deref_txt = '&' |
| 1532 | if ptr_type: |
| 1533 | deref_txt = '' |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1534 | if '->' in prefix: # need to update local struct |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 1535 | pre_code += '%slocal_%s%s = (%s)my_map_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(%s%s)];\n' % (indent, prefix, name, struct_uses[obj], prefix, name) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1536 | else: |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 1537 | pre_code += '%s%s = (%s)my_map_data->unique_id_mapping[reinterpret_cast<uint64_t &>(%s)];\n' % (indent, name, struct_uses[obj], name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1538 | return decls, pre_code, post_code |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1539 | |
| 1540 | def generate_intercept(self, proto, qual): |
| 1541 | create_func = False |
| 1542 | destroy_func = False |
| 1543 | last_param_index = None #typcially we look at all params for ndos |
| 1544 | pre_call_txt = '' # code prior to calling down chain such as unwrap uses of ndos |
| 1545 | post_call_txt = '' # code following call down chain such to wrap newly created ndos, or destroy local wrap struct |
| 1546 | funcs = [] |
| 1547 | indent = ' ' # indent level for generated code |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 1548 | decl = proto.c_func(attr="VKAPI") |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1549 | # A few API cases that are manual code |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1550 | # TODO : Special case Create*Pipelines funcs to handle creating multiple unique objects |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1551 | explicit_unique_objects_functions = ['GetSwapchainImagesKHR', |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1552 | 'CreateSwapchainKHR', |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1553 | 'CreateInstance', |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1554 | 'DestroyInstance', |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1555 | 'CreateDevice', |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1556 | 'DestroyDevice', |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1557 | 'CreateComputePipelines', |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1558 | 'CreateGraphicsPipelines', |
Jon Ashburn | 73a3435 | 2016-06-29 16:12:51 -0600 | [diff] [blame^] | 1559 | 'GetPhysicalDeviceDisplayPropertiesKHR', |
Jon Ashburn | 32e042d | 2016-06-28 14:46:12 -0600 | [diff] [blame] | 1560 | 'GetDisplayPlaneSupportedDisplaysKHR', |
| 1561 | 'GetDisplayModePropertiesKHR' |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1562 | ] |
Tobin Ehlis | 453e91f | 2016-01-29 14:24:42 -0700 | [diff] [blame] | 1563 | # TODO : This is hacky, need to make this a more general-purpose solution for all layers |
Cody Northrop | 0a179fe | 2016-02-24 12:28:41 -0700 | [diff] [blame] | 1564 | ifdef_dict = {'CreateXcbSurfaceKHR': 'VK_USE_PLATFORM_XCB_KHR', |
| 1565 | 'CreateAndroidSurfaceKHR': 'VK_USE_PLATFORM_ANDROID_KHR', |
Tony Barbour | e66d4e4 | 2016-04-12 13:35:51 -0600 | [diff] [blame] | 1566 | 'CreateWin32SurfaceKHR': 'VK_USE_PLATFORM_WIN32_KHR', |
| 1567 | 'CreateXlibSurfaceKHR': 'VK_USE_PLATFORM_XLIB_KHR', |
| 1568 | 'CreateWaylandSurfaceKHR': 'VK_USE_PLATFORM_WAYLAND_KHR', |
| 1569 | 'CreateMirSurfaceKHR': 'VK_USE_PLATFORM_MIR_KHR'} |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1570 | # Give special treatment to create functions that return multiple new objects |
| 1571 | # This dict stores array name and size of array |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1572 | custom_create_dict = {'pDescriptorSets' : 'pAllocateInfo->descriptorSetCount'} |
Courtney Goeltzenleuchter | 5a0f283 | 2016-02-11 11:44:04 -0700 | [diff] [blame] | 1573 | pre_call_txt += '%s\n' % (self.lineinfo.get()) |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1574 | if proto.name in explicit_unique_objects_functions: |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1575 | funcs.append('%s%s\n' |
| 1576 | '{\n' |
| 1577 | ' return explicit_%s;\n' |
| 1578 | '}' % (qual, decl, proto.c_call())) |
| 1579 | return "".join(funcs) |
| 1580 | if True in [create_txt in proto.name for create_txt in ['Create', 'Allocate']]: |
| 1581 | create_func = True |
| 1582 | last_param_index = -1 # For create funcs don't care if last param is ndo |
| 1583 | if True in [destroy_txt in proto.name for destroy_txt in ['Destroy', 'Free']]: |
| 1584 | destroy_obj_type = proto.params[-2].ty |
| 1585 | if destroy_obj_type in vulkan.object_non_dispatch_list: |
| 1586 | destroy_func = True |
| 1587 | |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1588 | # First thing we need to do is gather uses of non-dispatchable-objects (ndos) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1589 | (struct_uses, local_decls) = get_object_uses(vulkan.object_non_dispatch_list, proto.params[1:last_param_index]) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1590 | |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1591 | dispatch_param = proto.params[0].name |
| 1592 | if 'CreateInstance' in proto.name: |
| 1593 | dispatch_param = '*' + proto.params[1].name |
| 1594 | pre_call_txt += '%slayer_data *my_map_data = get_my_data_ptr(get_dispatch_key(%s), layer_data_map);\n' % (indent, dispatch_param) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1595 | if len(struct_uses) > 0: |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 1596 | pre_call_txt += '// STRUCT USES:%s\n' % sorted(struct_uses) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1597 | if len(local_decls) > 0: |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 1598 | pre_call_txt += '//LOCAL DECLS:%s\n' % sorted(local_decls) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1599 | if destroy_func: # only one object |
Karl Schultz | 2d6c90e | 2016-04-29 17:22:50 -0600 | [diff] [blame] | 1600 | pre_call_txt += '%sstd::unique_lock<std::mutex> lock(global_lock);\n' % (indent) |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 1601 | for del_obj in sorted(struct_uses): |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 1602 | pre_call_txt += '%suint64_t local_%s = reinterpret_cast<uint64_t &>(%s);\n' % (indent, del_obj, del_obj) |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1603 | pre_call_txt += '%s%s = (%s)my_map_data->unique_id_mapping[local_%s];\n' % (indent, del_obj, struct_uses[del_obj], del_obj) |
Karl Schultz | 2d6c90e | 2016-04-29 17:22:50 -0600 | [diff] [blame] | 1604 | pre_call_txt += '%slock.unlock();\n' % (indent) |
| 1605 | (pre_decl, pre_code, post_code) = ('', '', '') |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1606 | else: |
| 1607 | (pre_decl, pre_code, post_code) = self._gen_obj_code(struct_uses, local_decls, ' ', '', 0, set(), True) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1608 | # This is a bit hacky but works for now. Need to decl local versions of top-level structs |
Mike Stroyan | 04be783 | 2016-04-07 12:14:30 -0600 | [diff] [blame] | 1609 | for ld in sorted(local_decls): |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1610 | init_null_txt = 'NULL'; |
| 1611 | if '*' not in local_decls[ld]: |
| 1612 | init_null_txt = '{}'; |
| 1613 | if local_decls[ld].strip('*') not in vulkan.object_non_dispatch_list: |
| 1614 | pre_decl += ' safe_%s local_%s = %s;\n' % (local_decls[ld], ld, init_null_txt) |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1615 | if pre_code != '': # lock around map uses |
| 1616 | pre_code = '%s{\n%sstd::lock_guard<std::mutex> lock(global_lock);\n%s%s}\n' % (indent, indent, pre_code, indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1617 | pre_call_txt += '%s%s' % (pre_decl, pre_code) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1618 | post_call_txt += '%s' % (post_code) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1619 | elif create_func: |
| 1620 | base_type = proto.params[-1].ty.replace('const ', '').strip('*') |
| 1621 | if base_type not in vulkan.object_non_dispatch_list: |
| 1622 | return None |
| 1623 | else: |
| 1624 | return None |
| 1625 | |
| 1626 | ret_val = '' |
| 1627 | ret_stmt = '' |
| 1628 | if proto.ret != "void": |
| 1629 | ret_val = "%s result = " % proto.ret |
| 1630 | ret_stmt = " return result;\n" |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1631 | if create_func: |
| 1632 | obj_type = proto.params[-1].ty.strip('*') |
| 1633 | obj_name = proto.params[-1].name |
| 1634 | if obj_type in vulkan.object_non_dispatch_list: |
| 1635 | local_name = "unique%s" % obj_type[2:] |
| 1636 | post_call_txt += '%sif (VK_SUCCESS == result) {\n' % (indent) |
| 1637 | indent += ' ' |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1638 | post_call_txt += '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % (indent) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1639 | if obj_name in custom_create_dict: |
| 1640 | post_call_txt += '%s\n' % (self.lineinfo.get()) |
| 1641 | local_name = '%ss' % (local_name) # add 's' to end for vector of many |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1642 | post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, custom_create_dict[obj_name]) |
| 1643 | indent += ' ' |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 1644 | post_call_txt += '%suint64_t unique_id = global_unique_id++;\n' % (indent) |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 1645 | post_call_txt += '%smy_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(%s[i]);\n' % (indent, obj_name) |
| 1646 | post_call_txt += '%s%s[i] = reinterpret_cast<%s&>(unique_id);\n' % (indent, obj_name, obj_type) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1647 | indent = indent[4:] |
| 1648 | post_call_txt += '%s}\n' % (indent) |
| 1649 | else: |
| 1650 | post_call_txt += '%s\n' % (self.lineinfo.get()) |
Mark Lobodzinski | fdf8f47 | 2016-04-28 16:36:58 -0600 | [diff] [blame] | 1651 | post_call_txt += '%suint64_t unique_id = global_unique_id++;\n' % (indent) |
Dustin Graves | a7622d8 | 2016-04-14 17:29:20 -0600 | [diff] [blame] | 1652 | post_call_txt += '%smy_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*%s);\n' % (indent, obj_name) |
| 1653 | post_call_txt += '%s*%s = reinterpret_cast<%s&>(unique_id);\n' % (indent, obj_name, obj_type) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1654 | indent = indent[4:] |
| 1655 | post_call_txt += '%s}\n' % (indent) |
| 1656 | elif destroy_func: |
| 1657 | del_obj = proto.params[-2].name |
| 1658 | if 'count' in del_obj.lower(): |
| 1659 | post_call_txt += '%s\n' % (self.lineinfo.get()) |
| 1660 | post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, del_obj) |
| 1661 | del_obj = proto.params[-1].name |
| 1662 | indent += ' ' |
| 1663 | post_call_txt += '%sdelete (VkUniqueObject*)%s[i];\n' % (indent, del_obj) |
| 1664 | indent = indent[4:] |
| 1665 | post_call_txt += '%s}\n' % (indent) |
| 1666 | else: |
| 1667 | post_call_txt += '%s\n' % (self.lineinfo.get()) |
Karl Schultz | 2d6c90e | 2016-04-29 17:22:50 -0600 | [diff] [blame] | 1668 | post_call_txt += '%slock.lock();\n' % (indent) |
Tobin Ehlis | 10ba1de | 2016-04-13 12:59:43 -0600 | [diff] [blame] | 1669 | post_call_txt += '%smy_map_data->unique_id_mapping.erase(local_%s);\n' % (indent, proto.params[-2].name) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1670 | |
| 1671 | call_sig = proto.c_call() |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1672 | # Replace default params with any custom local params |
| 1673 | for ld in local_decls: |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1674 | const_qualifier = '' |
| 1675 | for p in proto.params: |
| 1676 | if ld == p.name and 'const' in p.ty: |
| 1677 | const_qualifier = 'const' |
| 1678 | call_sig = call_sig.replace(ld, '(%s %s)local_%s' % (const_qualifier, local_decls[ld], ld)) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1679 | if proto_is_global(proto): |
| 1680 | table_type = "instance" |
| 1681 | else: |
| 1682 | table_type = "device" |
| 1683 | pre_call_txt += '%s\n' % (self.lineinfo.get()) |
Tobin Ehlis | 453e91f | 2016-01-29 14:24:42 -0700 | [diff] [blame] | 1684 | open_ifdef = '' |
| 1685 | close_ifdef = '' |
| 1686 | if proto.name in ifdef_dict: |
| 1687 | open_ifdef = '#ifdef %s\n' % (ifdef_dict[proto.name]) |
| 1688 | close_ifdef = '#endif\n' |
| 1689 | funcs.append('%s' |
| 1690 | '%s%s\n' |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1691 | '{\n' |
| 1692 | '%s' |
| 1693 | ' %sget_dispatch_table(unique_objects_%s_table_map, %s)->%s;\n' |
| 1694 | '%s' |
| 1695 | '%s' |
Tobin Ehlis | 453e91f | 2016-01-29 14:24:42 -0700 | [diff] [blame] | 1696 | '}\n' |
| 1697 | '%s' % (open_ifdef, qual, decl, pre_call_txt, ret_val, table_type, dispatch_param, call_sig, post_call_txt, ret_stmt, close_ifdef)) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1698 | return "\n\n".join(funcs) |
| 1699 | |
| 1700 | def generate_body(self): |
| 1701 | self.layer_name = "unique_objects" |
| 1702 | extensions=[('wsi_enabled', |
| 1703 | ['vkCreateSwapchainKHR', |
| 1704 | 'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR', |
| 1705 | 'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])] |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1706 | surface_wsi_instance_exts = [ |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1707 | 'vkDestroySurfaceKHR', |
| 1708 | 'vkGetPhysicalDeviceSurfaceSupportKHR', |
| 1709 | 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR', |
| 1710 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1711 | 'vkGetPhysicalDeviceSurfacePresentModesKHR'] |
| 1712 | display_wsi_instance_exts = [ |
| 1713 | 'vkGetPhysicalDeviceDisplayPropertiesKHR', |
| 1714 | 'vkGetPhysicalDeviceDisplayPlanePropertiesKHR', |
| 1715 | 'vkGetDisplayPlaneSupportedDisplaysKHR', |
| 1716 | 'vkGetDisplayModePropertiesKHR', |
| 1717 | 'vkCreateDisplayModeKHR', |
| 1718 | 'vkGetDisplayPlaneCapabilitiesKHR', |
Petros Bantolas | 2b40be7 | 2016-04-15 11:02:59 +0100 | [diff] [blame] | 1719 | 'vkCreateDisplayPlaneSurfaceKHR'] |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1720 | if self.wsi == 'Win32': |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1721 | instance_extensions=[('wsi_enabled', surface_wsi_instance_exts), |
| 1722 | ('display_enabled', display_wsi_instance_exts), |
| 1723 | ('win32_enabled', ['vkCreateWin32SurfaceKHR'])] |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1724 | elif self.wsi == 'Android': |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1725 | instance_extensions=[('wsi_enabled', surface_wsi_instance_exts), |
| 1726 | ('display_enabled', display_wsi_instance_exts), |
| 1727 | ('android_enabled', ['vkCreateAndroidSurfaceKHR'])] |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame] | 1728 | elif self.wsi == 'Xcb' or self.wsi == 'Xlib' or self.wsi == 'Wayland' or self.wsi == 'Mir': |
Jon Ashburn | 5e026df | 2016-06-15 08:19:07 -0600 | [diff] [blame] | 1729 | instance_extensions=[('wsi_enabled', surface_wsi_instance_exts), |
| 1730 | ('display_enabled', display_wsi_instance_exts), |
| 1731 | ('xcb_enabled', ['vkCreateXcbSurfaceKHR']), |
| 1732 | ('xlib_enabled', ['vkCreateXlibSurfaceKHR']), |
| 1733 | ('wayland_enabled', ['vkCreateWaylandSurfaceKHR']), |
| 1734 | ('mir_enabled', ['vkCreateMirSurfaceKHR'])] |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame] | 1735 | else: |
| 1736 | print('Error: Undefined DisplayServer') |
| 1737 | instance_extensions=[] |
| 1738 | |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 1739 | body = ["namespace %s {" % self.layer_name, |
Chia-I Wu | c57d5c8 | 2016-05-13 14:37:49 +0800 | [diff] [blame] | 1740 | self._generate_dispatch_entrypoints(), |
Chia-I Wu | b02600c | 2016-05-20 07:11:22 +0800 | [diff] [blame] | 1741 | self._generate_layer_introspection_function(), |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1742 | self._generate_layer_gpa_function(extensions, |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 1743 | instance_extensions), |
Chia-I Wu | cdb7096 | 2016-05-13 14:07:36 +0800 | [diff] [blame] | 1744 | "} // namespace %s" % self.layer_name, |
Chia-I Wu | 40b8bab | 2016-05-13 14:06:08 +0800 | [diff] [blame] | 1745 | self._gen_layer_interface_v0_functions()] |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1746 | return "\n\n".join(body) |
| 1747 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1748 | def main(): |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1749 | wsi = { |
| 1750 | "Win32", |
| 1751 | "Android", |
| 1752 | "Xcb", |
| 1753 | "Xlib", |
| 1754 | "Wayland", |
| 1755 | "Mir", |
| 1756 | } |
| 1757 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1758 | subcommands = { |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1759 | "object_tracker" : ObjectTrackerSubcommand, |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1760 | "unique_objects" : UniqueObjectsSubcommand, |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1761 | } |
| 1762 | |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1763 | if len(sys.argv) < 4 or sys.argv[1] not in wsi or sys.argv[2] not in subcommands or not os.path.exists(sys.argv[3]): |
Jamie Madill | dbda66b | 2016-05-10 07:36:20 -0700 | [diff] [blame] | 1764 | print("Usage: %s <wsi> <subcommand> <input_header> [outdir]" % sys.argv[0]) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1765 | print |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1766 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1767 | exit(1) |
| 1768 | |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1769 | hfp = vk_helper.HeaderFileParser(sys.argv[3]) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1770 | hfp.parse() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1771 | vk_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1772 | vk_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1773 | vk_helper.struct_dict = hfp.get_struct_dict() |
| 1774 | vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1775 | vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1776 | vk_helper.types_dict = hfp.get_types_dict() |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1777 | |
Jamie Madill | dbda66b | 2016-05-10 07:36:20 -0700 | [diff] [blame] | 1778 | outfile = None |
| 1779 | if len(sys.argv) >= 5: |
| 1780 | outfile = sys.argv[4] |
| 1781 | |
| 1782 | subcmd = subcommands[sys.argv[2]](outfile) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1783 | subcmd.run() |
| 1784 | |
| 1785 | if __name__ == "__main__": |
| 1786 | main() |