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