Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 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 | # |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 10 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | # of this software and/or associated documentation files (the "Materials"), to |
| 12 | # deal in the Materials without restriction, including without limitation the |
| 13 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 14 | # sell copies of the Materials, and to permit persons to whom the Materials |
| 15 | # are furnished to do so, subject to the following conditions: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 16 | # |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 17 | # The above copyright notice(s) and this permission notice shall be included |
| 18 | # in all copies or substantial portions of the Materials. |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 19 | # |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 20 | # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 21 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 23 | # |
| 24 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 25 | # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 26 | # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 27 | # USE OR OTHER DEALINGS IN THE MATERIALS |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 28 | # |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 29 | # Author: Tobin Ehlis <tobine@google.com> |
| 30 | # Author: Courtney Goeltzenleuchter <courtneygo@google.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 31 | # Author: Jon Ashburn <jon@lunarg.com> |
| 32 | # Author: Mark Lobodzinski <mark@lunarg.com> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 33 | # Author: Mike Stroyan <stroyan@google.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 34 | # Author: Tony Barbour <tony@LunarG.com> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 35 | # Author: Chia-I Wu <olv@google.com> |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 36 | # Author: Gwan-gyeong Mun <kk.moon@samsung.com> |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 37 | |
| 38 | import sys |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 39 | import os |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 40 | import re |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 41 | |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 42 | import vulkan |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | import vk_helper |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 44 | from source_line_info import sourcelineinfo |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 45 | from collections import defaultdict |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 46 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 47 | def proto_is_global(proto): |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 48 | global_function_names = [ |
| 49 | "CreateInstance", |
| 50 | "EnumerateInstanceLayerProperties", |
| 51 | "EnumerateInstanceExtensionProperties", |
| 52 | "EnumerateDeviceLayerProperties", |
| 53 | "EnumerateDeviceExtensionProperties", |
| 54 | "CreateXcbSurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 55 | "GetPhysicalDeviceXcbPresentationSupportKHR", |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 56 | "CreateXlibSurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 57 | "GetPhysicalDeviceXlibPresentationSupportKHR", |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 58 | "CreateWaylandSurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 59 | "GetPhysicalDeviceWaylandPresentationSupportKHR", |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 60 | "CreateMirSurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 61 | "GetPhysicalDeviceMirPresentationSupportKHR", |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 62 | "CreateAndroidSurfaceKHR", |
| 63 | "CreateWin32SurfaceKHR", |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 64 | "GetPhysicalDeviceWin32PresentationSupportKHR" |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 65 | ] |
| 66 | if proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice" or proto.name in global_function_names: |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 67 | return True |
| 68 | else: |
| 69 | return False |
| 70 | |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 71 | def wsi_name(ext_name): |
| 72 | wsi_prefix = "" |
| 73 | if 'Xcb' in ext_name: |
| 74 | wsi_prefix = 'XCB' |
| 75 | elif 'Xlib' in ext_name: |
| 76 | wsi_prefix = 'XLIB' |
| 77 | elif 'Win32' in ext_name: |
| 78 | wsi_prefix = 'WIN32' |
| 79 | elif 'Mir' in ext_name: |
| 80 | wsi_prefix = 'MIR' |
| 81 | elif 'Wayland' in ext_name: |
| 82 | wsi_prefix = 'WAYLAND' |
| 83 | elif 'Android' in ext_name: |
| 84 | wsi_prefix = 'ANDROID' |
| 85 | else: |
| 86 | wsi_prefix = '' |
| 87 | return wsi_prefix |
| 88 | |
| 89 | def wsi_ifdef(ext_name): |
| 90 | wsi_prefix = wsi_name(ext_name) |
| 91 | if not wsi_prefix: |
| 92 | return '' |
| 93 | else: |
| 94 | return "#ifdef VK_USE_PLATFORM_%s_KHR" % wsi_prefix |
| 95 | |
| 96 | def wsi_endif(ext_name): |
| 97 | wsi_prefix = wsi_name(ext_name) |
| 98 | if not wsi_prefix: |
| 99 | return '' |
| 100 | else: |
| 101 | return "#endif // VK_USE_PLATFORM_%s_KHR" % wsi_prefix |
| 102 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 103 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 104 | return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ |
| 105 | " return NULL;" % ((name,) * 3) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 106 | |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 107 | def ucc_to_U_C_C(CamelCase): |
| 108 | temp = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', CamelCase) |
| 109 | return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).upper() |
| 110 | |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 111 | # Parse complete struct chain and add any new ndo_uses to the dict |
| 112 | def gather_object_uses_in_struct(obj_list, struct_type): |
| 113 | struct_uses = {} |
| 114 | if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict: |
| 115 | struct_type = vk_helper.typedef_rev_dict[struct_type] |
| 116 | # Parse elements of this struct param to identify objects and/or arrays of objects |
| 117 | for m in sorted(vk_helper.struct_dict[struct_type]): |
| 118 | array_len = "%s" % (str(vk_helper.struct_dict[struct_type][m]['array_size'])) |
| 119 | base_type = vk_helper.struct_dict[struct_type][m]['type'] |
| 120 | mem_name = vk_helper.struct_dict[struct_type][m]['name'] |
| 121 | if array_len != '0': |
| 122 | mem_name = "%s[%s]" % (mem_name, array_len) |
| 123 | if base_type in obj_list: |
| 124 | #if array_len not in ndo_uses: |
| 125 | # struct_uses[array_len] = [] |
| 126 | #struct_uses[array_len].append("%s%s,%s" % (name_prefix, struct_name, base_type)) |
| 127 | struct_uses[mem_name] = base_type |
| 128 | elif vk_helper.is_type(base_type, 'struct'): |
| 129 | sub_uses = gather_object_uses_in_struct(obj_list, base_type) |
| 130 | if len(sub_uses) > 0: |
| 131 | struct_uses[mem_name] = sub_uses |
| 132 | return struct_uses |
| 133 | |
| 134 | # For the given list of object types, Parse the given list of params |
| 135 | # and return dict of params that use one of the obj_list types |
| 136 | # Format of the dict is that terminal elements have <name>,<type> |
| 137 | # non-terminal elements will have <name>[<array_size>] |
| 138 | # TODO : This analysis could be done up-front at vk_helper time |
| 139 | def get_object_uses(obj_list, params): |
| 140 | obj_uses = {} |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 141 | local_decls = {} |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 142 | param_count = 'NONE' # track params that give array sizes |
| 143 | for p in params: |
| 144 | base_type = p.ty.replace('const ', '').strip('*') |
| 145 | array_len = '' |
| 146 | is_ptr = False |
| 147 | if 'count' in p.name.lower(): |
| 148 | param_count = p.name |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 149 | ptr_txt = '' |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 150 | if '*' in p.ty: |
| 151 | is_ptr = True |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 152 | ptr_txt = '*' |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 153 | if base_type in obj_list: |
| 154 | if is_ptr and 'const' in p.ty and param_count != 'NONE': |
| 155 | array_len = "[%s]" % param_count |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 156 | # Non-arrays we can overwrite in place, but need local decl for arrays |
| 157 | local_decls[p.name] = '%s%s' % (base_type, ptr_txt) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 158 | #if array_len not in obj_uses: |
| 159 | # obj_uses[array_len] = {} |
| 160 | # obj_uses[array_len][p.name] = base_type |
| 161 | obj_uses["%s%s" % (p.name, array_len)] = base_type |
| 162 | elif vk_helper.is_type(base_type, 'struct'): |
| 163 | struct_name = p.name |
| 164 | if 'NONE' != param_count: |
| 165 | struct_name = "%s[%s]" % (struct_name, param_count) |
| 166 | struct_uses = gather_object_uses_in_struct(obj_list, base_type) |
| 167 | if len(struct_uses) > 0: |
| 168 | obj_uses[struct_name] = struct_uses |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 169 | # This is a top-level struct w/ uses below it, so need local decl |
| 170 | local_decls['%s' % (p.name)] = '%s%s' % (base_type, ptr_txt) |
| 171 | return (obj_uses, local_decls) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 172 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 173 | class Subcommand(object): |
| 174 | def __init__(self, argv): |
| 175 | self.argv = argv |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 176 | self.headers = vulkan.headers |
| 177 | self.protos = vulkan.protos |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 178 | self.no_addr = False |
| 179 | self.layer_name = "" |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 180 | self.lineinfo = sourcelineinfo() |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 181 | self.wsi = sys.argv[1] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 182 | |
| 183 | def run(self): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 184 | print(self.generate()) |
| 185 | |
| 186 | def generate(self): |
| 187 | copyright = self.generate_copyright() |
| 188 | header = self.generate_header() |
| 189 | body = self.generate_body() |
| 190 | footer = self.generate_footer() |
| 191 | |
| 192 | contents = [] |
| 193 | if copyright: |
| 194 | contents.append(copyright) |
| 195 | if header: |
| 196 | contents.append(header) |
| 197 | if body: |
| 198 | contents.append(body) |
| 199 | if footer: |
| 200 | contents.append(footer) |
| 201 | |
| 202 | return "\n\n".join(contents) |
| 203 | |
| 204 | def generate_copyright(self): |
| 205 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 206 | |
| 207 | /* |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 208 | * Copyright (c) 2015-2016 The Khronos Group Inc. |
| 209 | * Copyright (c) 2015-2016 Valve Corporation |
| 210 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 211 | * Copyright (c) 2015 Google, Inc. |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 212 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 213 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 214 | * of this software and/or associated documentation files (the "Materials"), to |
| 215 | * deal in the Materials without restriction, including without limitation the |
| 216 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 217 | * sell copies of the Materials, and to permit persons to whom the Materials |
| 218 | * are furnished to do so, subject to the following conditions: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 219 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 220 | * The above copyright notice(s) and this permission notice shall be included |
| 221 | * in all copies or substantial portions of the Materials. |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 222 | * |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 223 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 224 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Mark Lobodzinski | 6eda00a | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 225 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 226 | * |
| 227 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 228 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 229 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 230 | * USE OR OTHER DEALINGS IN THE MATERIALS |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 231 | * |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 232 | * Author: Tobin Ehlis <tobine@google.com> |
| 233 | * Author: Courtney Goeltzenleuchter <courtneygo@google.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 234 | * Author: Jon Ashburn <jon@lunarg.com> |
| 235 | * Author: Mark Lobodzinski <mark@lunarg.com> |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 236 | * Author: Mike Stroyan <stroyan@google.com> |
Courtney Goeltzenleuchter | 0555952 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 237 | * Author: Tony Barbour <tony@LunarG.com> |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 238 | */""" |
| 239 | |
| 240 | def generate_header(self): |
| 241 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 242 | |
| 243 | def generate_body(self): |
| 244 | pass |
| 245 | |
| 246 | def generate_footer(self): |
| 247 | pass |
| 248 | |
| 249 | # Return set of printf '%' qualifier and input to that qualifier |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 250 | def _get_printf_params(self, vk_type, name, output_param, cpp=False): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 251 | # TODO : Need ENUM and STRUCT checks here |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 252 | 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] | 253 | return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name)) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 254 | if "char*" == vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 255 | return ("%s", name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 256 | if "uint64" in vk_type: |
| 257 | if '*' in vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 258 | return ("%lu", "*%s" % name) |
| 259 | return ("%lu", name) |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 260 | if vk_type.strip('*') in vulkan.object_non_dispatch_list: |
| 261 | if '*' in vk_type: |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 262 | return ("%lu", "%s" % name) |
| 263 | return ("%lu", "%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 264 | if "size" in vk_type: |
| 265 | if '*' in vk_type: |
Mark Lobodzinski | a145649 | 2015-10-06 09:57:52 -0600 | [diff] [blame] | 266 | return ("%lu", "(unsigned long)*%s" % name) |
| 267 | return ("%lu", "(unsigned long)%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 268 | if "float" in vk_type: |
| 269 | 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] | 270 | if cpp: |
| 271 | 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] | 272 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 273 | return ("%f", name) |
Courtney Goeltzenleuchter | cd2a099 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 274 | 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] | 275 | return ("%u", name) |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 276 | 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] | 277 | 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] | 278 | if cpp: |
| 279 | 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] | 280 | 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] | 281 | if '*' in vk_type: |
Tobin Ehlis | d2b88e8 | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 282 | if 'pUserData' == name: |
| 283 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Tobin Ehlis | c62cb89 | 2015-04-17 13:26:33 -0600 | [diff] [blame] | 284 | if 'const' in vk_type.lower(): |
| 285 | return ("%p", "(void*)(%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 286 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 287 | return ("%i", name) |
Tobin Ehlis | 3a1cc8d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 288 | # 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] | 289 | if "VkFormat" == vk_type: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 290 | if cpp: |
| 291 | return ("%p", "&%s" % name) |
Chia-I Wu | 1b99bb2 | 2015-10-27 19:25:11 +0800 | [diff] [blame] | 292 | 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] | 293 | if output_param: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 294 | return ("%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 295 | 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] | 296 | return ("%p", "(void*)(&%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 297 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 298 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 299 | def _gen_create_msg_callback(self): |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 300 | r_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 301 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 302 | r_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(') |
| 303 | r_body.append(' VkInstance instance,') |
| 304 | r_body.append(' const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,') |
| 305 | r_body.append(' const VkAllocationCallbacks* pAllocator,') |
| 306 | r_body.append(' VkDebugReportCallbackEXT* pCallback)') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 307 | r_body.append('{') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 308 | # Switch to this code section for the new per-instance storage and debug callbacks |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 309 | if self.layer_name in ['object_tracker', 'threading', 'unique_objects']: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 310 | 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] | 311 | r_body.append(' VkResult result = pInstanceTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 312 | r_body.append(' if (VK_SUCCESS == result) {') |
| 313 | 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] | 314 | r_body.append(' result = layer_create_msg_callback(my_data->report_data,') |
| 315 | r_body.append(' pCreateInfo,') |
| 316 | r_body.append(' pAllocator,') |
| 317 | r_body.append(' pCallback);') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 318 | r_body.append(' }') |
| 319 | r_body.append(' return result;') |
| 320 | else: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 321 | 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] | 322 | r_body.append(' if (VK_SUCCESS == result) {') |
| 323 | 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] | 324 | 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] | 325 | r_body.append(' }') |
| 326 | r_body.append(' return result;') |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 327 | r_body.append('}') |
| 328 | return "\n".join(r_body) |
| 329 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 330 | def _gen_destroy_msg_callback(self): |
| 331 | r_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 332 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 333 | 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] | 334 | r_body.append('{') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 335 | # Switch to this code section for the new per-instance storage and debug callbacks |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 336 | if self.layer_name in ['object_tracker', 'threading', 'unique_objects']: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 337 | 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] | 338 | else: |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 339 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 340 | r_body.append(' pInstanceTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 341 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
| 342 | 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] | 343 | r_body.append('}') |
| 344 | return "\n".join(r_body) |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 345 | |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 346 | def _gen_debug_report_msg(self): |
| 347 | r_body = [] |
| 348 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 349 | 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] | 350 | r_body.append('{') |
| 351 | # Switch to this code section for the new per-instance storage and debug callbacks |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 352 | if self.layer_name == 'object_tracker' or self.layer_name == 'threading': |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 353 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
| 354 | else: |
| 355 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 356 | 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] | 357 | r_body.append('}') |
| 358 | return "\n".join(r_body) |
| 359 | |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 360 | def _gen_layer_get_global_extension_props(self, layer="object_tracker"): |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 361 | ggep_body = [] |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 362 | # generated layers do not provide any global extensions |
| 363 | ggep_body.append('%s' % self.lineinfo.get()) |
| 364 | |
| 365 | ggep_body.append('') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 366 | if self.layer_name == 'object_tracker' or self.layer_name == 'threading': |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 367 | ggep_body.append('static const VkExtensionProperties instance_extensions[] = {') |
| 368 | ggep_body.append(' {') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 369 | ggep_body.append(' VK_EXT_DEBUG_REPORT_EXTENSION_NAME,') |
Courtney Goeltzenleuchter | b69cd59 | 2016-01-19 16:08:39 -0700 | [diff] [blame] | 370 | ggep_body.append(' VK_EXT_DEBUG_REPORT_SPEC_VERSION') |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 371 | ggep_body.append(' }') |
| 372 | ggep_body.append('};') |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 373 | 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] | 374 | ggep_body.append('{') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 375 | if self.layer_name == 'object_tracker' or self.layer_name == 'threading': |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 376 | ggep_body.append(' return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);') |
| 377 | else: |
| 378 | ggep_body.append(' return util_GetExtensionProperties(0, NULL, pCount, pProperties);') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 379 | ggep_body.append('}') |
| 380 | return "\n".join(ggep_body) |
| 381 | |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 382 | def _gen_layer_get_global_layer_props(self, layer="object_tracker"): |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 383 | ggep_body = [] |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 384 | layer_name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', layer) |
| 385 | layer_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', layer_name).lower() |
| 386 | ggep_body.append('%s' % self.lineinfo.get()) |
| 387 | ggep_body.append('static const VkLayerProperties globalLayerProps[] = {') |
| 388 | ggep_body.append(' {') |
Courtney Goeltzenleuchter | fb4c1c3 | 2016-02-08 11:16:21 -0700 | [diff] [blame] | 389 | if self.layer_name in ['threading', 'unique_objects']: |
| 390 | ggep_body.append(' "VK_LAYER_GOOGLE_%s",' % layer) |
| 391 | ggep_body.append(' VK_API_VERSION, // specVersion') |
| 392 | ggep_body.append(' 1, // implementationVersion') |
| 393 | ggep_body.append(' "Google Validation Layer"') |
| 394 | else: |
| 395 | ggep_body.append(' "VK_LAYER_LUNARG_%s",' % layer) |
| 396 | ggep_body.append(' VK_API_VERSION, // specVersion') |
| 397 | ggep_body.append(' 1, // implementationVersion') |
| 398 | ggep_body.append(' "LunarG Validation Layer"') |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 399 | ggep_body.append(' }') |
| 400 | ggep_body.append('};') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 401 | ggep_body.append('') |
| 402 | ggep_body.append('%s' % self.lineinfo.get()) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 403 | ggep_body.append('') |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 404 | 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] | 405 | ggep_body.append('{') |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 406 | ggep_body.append(' return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 407 | ggep_body.append('}') |
| 408 | return "\n".join(ggep_body) |
| 409 | |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 410 | def _gen_layer_get_physical_device_layer_props(self, layer="object_tracker"): |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 411 | gpdlp_body = [] |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 412 | gpdlp_body.append('%s' % self.lineinfo.get()) |
| 413 | gpdlp_body.append('static const VkLayerProperties deviceLayerProps[] = {') |
| 414 | gpdlp_body.append(' {') |
Courtney Goeltzenleuchter | fb4c1c3 | 2016-02-08 11:16:21 -0700 | [diff] [blame] | 415 | if self.layer_name in ['threading', 'unique_objects']: |
| 416 | gpdlp_body.append(' "VK_LAYER_GOOGLE_%s",' % layer) |
| 417 | gpdlp_body.append(' VK_API_VERSION, // specVersion') |
| 418 | gpdlp_body.append(' 1, // implementationVersion') |
| 419 | gpdlp_body.append(' "Google Validation Layer"') |
| 420 | else: |
| 421 | gpdlp_body.append(' "VK_LAYER_LUNARG_%s",' % layer) |
| 422 | gpdlp_body.append(' VK_API_VERSION, // specVersion') |
| 423 | gpdlp_body.append(' 1, // implementationVersion') |
| 424 | gpdlp_body.append(' "LunarG Validation Layer"') |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 425 | gpdlp_body.append(' }') |
| 426 | gpdlp_body.append('};') |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 427 | 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] | 428 | gpdlp_body.append('{') |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 429 | gpdlp_body.append(' return util_GetLayerProperties(ARRAY_SIZE(deviceLayerProps), deviceLayerProps, pCount, pProperties);') |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 430 | gpdlp_body.append('}') |
| 431 | gpdlp_body.append('') |
| 432 | return "\n".join(gpdlp_body) |
| 433 | |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 434 | def _generate_dispatch_entrypoints(self, qual=""): |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 435 | if qual: |
| 436 | qual += " " |
| 437 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 438 | funcs = [] |
| 439 | intercepted = [] |
| 440 | for proto in self.protos: |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 441 | if proto.name == "GetDeviceProcAddr" or proto.name == "GetInstanceProcAddr": |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 442 | continue |
Mike Stroyan | 70c05e8 | 2015-04-08 10:27:43 -0600 | [diff] [blame] | 443 | else: |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 444 | intercept = self.generate_intercept(proto, qual) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 445 | if intercept is None: |
| 446 | # fill in default intercept for certain entrypoints |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 447 | if 'CreateDebugReportCallbackEXT' == proto.name: |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 448 | intercept = self._gen_layer_dbg_create_msg_callback() |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 449 | elif 'DestroyDebugReportCallbackEXT' == proto.name: |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 450 | intercept = self._gen_layer_dbg_destroy_msg_callback() |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 451 | elif 'DebugReportMessageEXT' == proto.name: |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 452 | intercept = self._gen_debug_report_msg() |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 453 | elif 'CreateDevice' == proto.name: |
| 454 | funcs.append('/* CreateDevice HERE */') |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 455 | elif 'EnumerateInstanceExtensionProperties' == proto.name: |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 456 | intercept = self._gen_layer_get_global_extension_props(self.layer_name) |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 457 | elif 'EnumerateInstanceLayerProperties' == proto.name: |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 458 | intercept = self._gen_layer_get_global_layer_props(self.layer_name) |
Courtney Goeltzenleuchter | 35985f6 | 2015-09-14 17:22:16 -0600 | [diff] [blame] | 459 | elif 'EnumerateDeviceLayerProperties' == proto.name: |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 460 | intercept = self._gen_layer_get_physical_device_layer_props(self.layer_name) |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 461 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 462 | if intercept is not None: |
| 463 | funcs.append(intercept) |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 464 | if not "KHR" in proto.name: |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 465 | intercepted.append(proto) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 466 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 467 | prefix="vk" |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 468 | lookups = [] |
| 469 | for proto in intercepted: |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 470 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 471 | lookups.append(" return (PFN_vkVoidFunction) %s%s;" % |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 472 | (prefix, proto.name)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 473 | |
| 474 | # add customized layer_intercept_proc |
| 475 | body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 476 | body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 477 | body.append("static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)") |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 478 | body.append("{") |
| 479 | body.append(generate_get_proc_addr_check("name")) |
| 480 | body.append("") |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 481 | body.append(" name += 2;") |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 482 | body.append(" %s" % "\n ".join(lookups)) |
| 483 | body.append("") |
| 484 | body.append(" return NULL;") |
| 485 | body.append("}") |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 486 | # add layer_intercept_instance_proc |
| 487 | lookups = [] |
| 488 | for proto in self.protos: |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 489 | if not proto_is_global(proto): |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 490 | continue |
| 491 | |
| 492 | if not proto in intercepted: |
| 493 | continue |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 494 | if proto.name == "CreateInstance": |
| 495 | continue |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 496 | if proto.name == "CreateDevice": |
| 497 | continue |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 498 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 499 | lookups.append(" return (PFN_vkVoidFunction) %s%s;" % (prefix, proto.name)) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 500 | |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 501 | 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] | 502 | body.append("{") |
| 503 | body.append(generate_get_proc_addr_check("name")) |
| 504 | body.append("") |
| 505 | body.append(" name += 2;") |
| 506 | body.append(" %s" % "\n ".join(lookups)) |
| 507 | body.append("") |
| 508 | body.append(" return NULL;") |
| 509 | body.append("}") |
| 510 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 511 | funcs.append("\n".join(body)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 512 | return "\n\n".join(funcs) |
| 513 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 514 | def _generate_extensions(self): |
| 515 | exts = [] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 516 | exts.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 517 | exts.append(self._gen_create_msg_callback()) |
| 518 | exts.append(self._gen_destroy_msg_callback()) |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 519 | exts.append(self._gen_debug_report_msg()) |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 520 | return "\n".join(exts) |
| 521 | |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 522 | def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]): |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 523 | func_body = [] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 524 | # |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 525 | # 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] | 526 | # |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 527 | if self.layer_name in ['object_tracker', 'threading', 'unique_objects']: |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 528 | 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] | 529 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 530 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 531 | " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 532 | " return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 533 | " }\n\n" |
| 534 | " addr = layer_intercept_proc(funcName);\n" |
| 535 | " if (addr)\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 536 | " return addr;\n" |
| 537 | " if (device == VK_NULL_HANDLE) {\n" |
| 538 | " return NULL;\n" |
| 539 | " }\n") |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 540 | if 0 != len(extensions): |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 541 | func_body.append('%s' % self.lineinfo.get()) |
| 542 | 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] | 543 | for (ext_enable, ext_list) in extensions: |
| 544 | extra_space = "" |
| 545 | if 0 != len(ext_enable): |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 546 | func_body.append(' if (my_device_data->%s) {' % ext_enable) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 547 | extra_space = " " |
| 548 | for ext_name in ext_list: |
| 549 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 550 | ' %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] | 551 | if 0 != len(ext_enable): |
| 552 | func_body.append(' }\n') |
| 553 | func_body.append("\n if (get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr == NULL)\n" |
| 554 | " return NULL;\n" |
| 555 | " return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n" |
| 556 | "}\n" % (self.layer_name, self.layer_name)) |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 557 | 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] | 558 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 559 | " PFN_vkVoidFunction addr;\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 560 | " if (!strcmp(funcName, \"vkGetInstanceProcAddr\"))\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 561 | " return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 562 | " if (!strcmp(funcName, \"vkCreateInstance\"))\n" |
| 563 | " return (PFN_vkVoidFunction) vkCreateInstance;\n" |
| 564 | " if (!strcmp(funcName, \"vkCreateDevice\"))\n" |
| 565 | " return (PFN_vkVoidFunction) vkCreateDevice;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 566 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 567 | " if (addr) {\n" |
| 568 | " return addr;" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 569 | " }\n" |
| 570 | " if (instance == VK_NULL_HANDLE) {\n" |
| 571 | " return NULL;\n" |
| 572 | " }\n" |
| 573 | ) |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 574 | |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 575 | table_declared = False |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 576 | if 0 != len(instance_extensions): |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 577 | for (ext_enable, ext_list) in instance_extensions: |
| 578 | extra_space = "" |
| 579 | if 0 != len(ext_enable): |
| 580 | if ext_enable == 'msg_callback_get_proc_addr': |
| 581 | 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] | 582 | " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n" |
| 583 | " if (addr) {\n" |
| 584 | " return addr;\n" |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 585 | " }\n") |
| 586 | else: |
| 587 | if table_declared == False: |
| 588 | func_body.append(" VkLayerInstanceDispatchTable* pTable = get_dispatch_table(%s_instance_table_map, instance);" % self.layer_name) |
| 589 | table_declared = True |
| 590 | func_body.append(' if (instanceExtMap.size() != 0 && instanceExtMap[pTable].%s)' % ext_enable) |
| 591 | func_body.append(' {') |
| 592 | extra_space = " " |
| 593 | for ext_name in ext_list: |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 594 | if wsi_name(ext_name): |
| 595 | func_body.append('%s' % wsi_ifdef(ext_name)) |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 596 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
| 597 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name)) |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 598 | if wsi_name(ext_name): |
| 599 | func_body.append('%s' % wsi_endif(ext_name)) |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 600 | if 0 != len(ext_enable): |
| 601 | func_body.append(' }\n') |
| 602 | |
| 603 | func_body.append(" if (get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr == NULL) {\n" |
| 604 | " return NULL;\n" |
| 605 | " }\n" |
| 606 | " return get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);\n" |
| 607 | "}\n" % (self.layer_name, self.layer_name)) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 608 | return "\n".join(func_body) |
| 609 | else: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 610 | func_body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 611 | 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] | 612 | "{\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 613 | " PFN_vkVoidFunction addr;\n") |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 614 | func_body.append("\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 615 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 616 | " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 617 | " return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 618 | " }\n\n" |
| 619 | " addr = layer_intercept_proc(funcName);\n" |
| 620 | " if (addr)\n" |
| 621 | " return addr;" % self.layer_name) |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 622 | func_body.append(" if (device == VK_NULL_HANDLE) {\n" |
| 623 | " return NULL;\n" |
| 624 | " }\n") |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 625 | func_body.append('') |
| 626 | func_body.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 627 | if 0 != len(extensions): |
| 628 | extra_space = "" |
| 629 | for (ext_enable, ext_list) in extensions: |
| 630 | if 0 != len(ext_enable): |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 631 | func_body.append(' if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].%s)' % ext_enable) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 632 | func_body.append(' {') |
| 633 | extra_space = " " |
| 634 | for ext_name in ext_list: |
| 635 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 636 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name)) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 637 | if 0 != len(ext_enable): |
| 638 | func_body.append(' }') |
| 639 | func_body.append('%s' % self.lineinfo.get()) |
| 640 | func_body.append(" {\n" |
| 641 | " if (pDisp->GetDeviceProcAddr == NULL)\n" |
| 642 | " return NULL;\n" |
| 643 | " return pDisp->GetDeviceProcAddr(device, funcName);\n" |
| 644 | " }\n" |
| 645 | "}\n") |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 646 | func_body.append('%s' % self.lineinfo.get()) |
Chia-I Wu | 9ab6150 | 2015-11-06 06:42:02 +0800 | [diff] [blame] | 647 | 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] | 648 | "{\n" |
Courtney Goeltzenleuchter | 2d3ba63 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 649 | " PFN_vkVoidFunction addr;\n" |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 650 | " if (!strcmp(funcName, \"vkGetInstanceProcAddr\"))\n" |
| 651 | " return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n" |
| 652 | " if (!strcmp(funcName, \"vkCreateInstance\"))\n" |
| 653 | " return (PFN_vkVoidFunction) vkCreateInstance;\n" |
| 654 | " if (!strcmp(funcName, \"vkCreateDevice\"))\n" |
| 655 | " return (PFN_vkVoidFunction) vkCreateDevice;\n" |
| 656 | ) |
Jon Ashburn | 1f32a44 | 2016-02-02 13:13:01 -0700 | [diff] [blame] | 657 | func_body.append( |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 658 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 659 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 660 | " if (addr)\n" |
| 661 | " return addr;" % self.layer_name) |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 662 | func_body.append(" if (instance == VK_NULL_HANDLE) {\n" |
| 663 | " return NULL;\n" |
| 664 | " }\n") |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 665 | func_body.append("") |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 666 | func_body.append(" VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);\n") |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 667 | if 0 != len(instance_extensions): |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 668 | extra_space = "" |
| 669 | for (ext_enable, ext_list) in instance_extensions: |
| 670 | if 0 != len(ext_enable): |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 671 | if ext_enable == 'msg_callback_get_proc_addr': |
| 672 | func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n" |
| 673 | " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n" |
| 674 | " if (addr) {\n" |
| 675 | " return addr;\n" |
| 676 | " }\n") |
| 677 | else: |
| 678 | func_body.append(' if (instanceExtMap.size() != 0 && instanceExtMap[pTable].%s)' % ext_enable) |
| 679 | func_body.append(' {') |
| 680 | extra_space = " " |
| 681 | for ext_name in ext_list: |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 682 | if wsi_name(ext_name): |
| 683 | func_body.append('%s' % wsi_ifdef(ext_name)) |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 684 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 685 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name)) |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 686 | if wsi_name(ext_name): |
| 687 | func_body.append('%s' % wsi_endif(ext_name)) |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 688 | if 0 != len(ext_enable): |
| 689 | func_body.append(' }\n') |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 690 | |
| 691 | func_body.append(" if (pTable->GetInstanceProcAddr == NULL)\n" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 692 | " return NULL;\n" |
| 693 | " return pTable->GetInstanceProcAddr(instance, funcName);\n" |
| 694 | "}\n") |
| 695 | return "\n".join(func_body) |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 696 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 697 | |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 698 | 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] | 699 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 700 | func_body.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 701 | 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] | 702 | '{\n' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 703 | if init_opts: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 704 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 705 | func_body.append(' uint32_t report_flags = 0;') |
| 706 | func_body.append(' uint32_t debug_action = 0;') |
| 707 | func_body.append(' FILE *log_output = NULL;') |
| 708 | func_body.append(' const char *option_str;\n') |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 709 | func_body.append(' // initialize %s options' % self.layer_name) |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 710 | func_body.append(' report_flags = getLayerOptionFlags("%sReportFlags", 0);' % self.layer_name) |
| 711 | func_body.append(' getLayerOptionEnum("%sDebugAction", (uint32_t *) &debug_action);' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 712 | func_body.append('') |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 713 | func_body.append(' if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 714 | func_body.append(' {') |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 715 | func_body.append(' option_str = getLayerOption("%sLogFilename");' % self.layer_name) |
| 716 | func_body.append(' log_output = getLayerLogOutput(option_str,"%s");' % self.layer_name) |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 717 | func_body.append(' VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 718 | func_body.append(' memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 719 | func_body.append(' dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 720 | func_body.append(' dbgCreateInfo.flags = report_flags;') |
| 721 | func_body.append(' dbgCreateInfo.pfnCallback = log_callback;') |
| 722 | func_body.append(' dbgCreateInfo.pUserData = NULL;') |
| 723 | func_body.append(' layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator,') |
Jon Ashburn | 3a278b7 | 2015-10-06 17:05:21 -0600 | [diff] [blame] | 724 | func_body.append(' &my_data->logging_callback);') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 725 | func_body.append(' }') |
| 726 | func_body.append('') |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 727 | if lockname is not None: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 728 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 729 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 730 | func_body.append(" {") |
| 731 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 732 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 733 | if condname is not None: |
| 734 | func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname) |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 735 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 736 | func_body.append(" }") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 737 | func_body.append("}\n") |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 738 | func_body.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 739 | return "\n".join(func_body) |
| 740 | |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 741 | def _generate_new_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None): |
| 742 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
| 743 | func_body.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 744 | func_body.append('static void init_%s(layer_data *my_data, const VkAllocationCallbacks *pAllocator)\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 745 | '{\n' % self.layer_name) |
| 746 | if init_opts: |
| 747 | func_body.append('%s' % self.lineinfo.get()) |
| 748 | func_body.append(' uint32_t report_flags = 0;') |
| 749 | func_body.append(' uint32_t debug_action = 0;') |
| 750 | func_body.append(' FILE *log_output = NULL;') |
| 751 | func_body.append(' const char *strOpt;') |
| 752 | func_body.append(' // initialize %s options' % self.layer_name) |
| 753 | func_body.append(' report_flags = getLayerOptionFlags("%sReportFlags", 0);' % self.layer_name) |
Jon Ashburn | 9ff6ae9 | 2015-10-06 17:20:01 -0600 | [diff] [blame] | 754 | func_body.append(' getLayerOptionEnum("%sDebugAction", (uint32_t *) &debug_action);' % self.layer_name) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 755 | func_body.append('') |
| 756 | func_body.append(' if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)') |
| 757 | func_body.append(' {') |
| 758 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name) |
Tobin Ehlis | b1df55e | 2015-09-15 09:55:54 -0600 | [diff] [blame] | 759 | func_body.append(' log_output = getLayerLogOutput(strOpt, "%s");' % self.layer_name) |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 760 | func_body.append(' VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 761 | func_body.append(' memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 762 | func_body.append(' dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 763 | func_body.append(' dbgCreateInfo.flags = report_flags;') |
| 764 | func_body.append(' dbgCreateInfo.pfnCallback = log_callback;') |
| 765 | func_body.append(' dbgCreateInfo.pUserData = log_output;') |
| 766 | func_body.append(' layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator,') |
| 767 | func_body.append(' &my_data->logging_callback);') |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 768 | func_body.append(' }') |
| 769 | func_body.append('') |
| 770 | if lockname is not None: |
| 771 | func_body.append('%s' % self.lineinfo.get()) |
| 772 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 773 | func_body.append(" {") |
| 774 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 775 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
| 776 | if condname is not None: |
| 777 | func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname) |
| 778 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 779 | func_body.append(" }") |
| 780 | func_body.append("}\n") |
| 781 | func_body.append('') |
| 782 | return "\n".join(func_body) |
| 783 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 784 | class ObjectTrackerSubcommand(Subcommand): |
| 785 | def generate_header(self): |
| 786 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 787 | header_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 788 | header_txt.append('#include <stdio.h>') |
| 789 | header_txt.append('#include <stdlib.h>') |
| 790 | header_txt.append('#include <string.h>') |
| 791 | header_txt.append('#include <inttypes.h>') |
| 792 | header_txt.append('') |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 793 | header_txt.append('#include "vulkan/vulkan.h"') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 794 | header_txt.append('#include "vk_loader_platform.h"') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 795 | header_txt.append('') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 796 | header_txt.append('#include <unordered_map>') |
| 797 | header_txt.append('using namespace std;') |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 798 | header_txt.append('#include "vulkan/vk_layer.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 799 | header_txt.append('#include "vk_layer_config.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 800 | header_txt.append('#include "vk_layer_table.h"') |
| 801 | header_txt.append('#include "vk_layer_data.h"') |
| 802 | header_txt.append('#include "vk_layer_logging.h"') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 803 | header_txt.append('') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 804 | # NOTE: The non-autoGenerated code is in the object_tracker.h header file |
| 805 | header_txt.append('#include "object_tracker.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 806 | header_txt.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 807 | return "\n".join(header_txt) |
| 808 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 809 | def generate_maps(self): |
| 810 | maps_txt = [] |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 811 | for o in vulkan.object_type_list: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 812 | maps_txt.append('unordered_map<uint64_t, OBJTRACK_NODE*> %sMap;' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 813 | return "\n".join(maps_txt) |
| 814 | |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 815 | def _gather_object_uses(self, obj_list, struct_type, obj_set): |
| 816 | # for each member of struct_type |
| 817 | # add objs in obj_list to obj_set |
| 818 | # call self for structs |
| 819 | for m in vk_helper.struct_dict[struct_type]: |
| 820 | if vk_helper.struct_dict[struct_type][m]['type'] in obj_list: |
| 821 | obj_set.add(vk_helper.struct_dict[struct_type][m]['type']) |
| 822 | elif vk_helper.is_type(vk_helper.struct_dict[struct_type][m]['type'], 'struct'): |
| 823 | obj_set = obj_set.union(self._gather_object_uses(obj_list, vk_helper.struct_dict[struct_type][m]['type'], obj_set)) |
| 824 | return obj_set |
| 825 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 826 | def generate_procs(self): |
| 827 | procs_txt = [] |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 828 | # First parse through funcs and gather dict of all objects seen by each call |
| 829 | obj_use_dict = {} |
| 830 | 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 |
| 831 | for proto in proto_list: |
| 832 | disp_obj = proto.params[0].ty.strip('*').replace('const ', '') |
| 833 | if disp_obj in vulkan.object_dispatch_list: |
| 834 | if disp_obj not in obj_use_dict: |
| 835 | obj_use_dict[disp_obj] = set() |
| 836 | for p in proto.params[1:]: |
| 837 | base_type = p.ty.strip('*').replace('const ', '') |
| 838 | if base_type in vulkan.object_type_list: |
| 839 | obj_use_dict[disp_obj].add(base_type) |
| 840 | if vk_helper.is_type(base_type, 'struct'): |
| 841 | obj_use_dict[disp_obj] = self._gather_object_uses(vulkan.object_type_list, base_type, obj_use_dict[disp_obj]) |
| 842 | #for do in obj_use_dict: |
| 843 | # print "Disp obj %s has uses for objs: %s" % (do, ', '.join(obj_use_dict[do])) |
| 844 | |
| 845 | for o in vulkan.object_type_list:# vulkan.core.objects: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 846 | procs_txt.append('%s' % self.lineinfo.get()) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 847 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o) |
| 848 | 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] | 849 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 850 | 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] | 851 | else: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 852 | 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] | 853 | procs_txt.append('{') |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 854 | 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] | 855 | 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] | 856 | procs_txt.append(' (uint64_t)(vkObj));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 857 | procs_txt.append('') |
| 858 | procs_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;') |
| 859 | procs_txt.append(' pNewObjNode->objType = objType;') |
| 860 | procs_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 861 | procs_txt.append(' pNewObjNode->vkObj = (uint64_t)(vkObj);') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 862 | procs_txt.append(' %sMap[(uint64_t)vkObj] = pNewObjNode;' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 863 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(objType);') |
| 864 | procs_txt.append(' numObjs[objIndex]++;') |
| 865 | procs_txt.append(' numTotalObjs++;') |
| 866 | procs_txt.append('}') |
| 867 | procs_txt.append('') |
| 868 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 869 | if o in vulkan.object_dispatch_list: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 870 | 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] | 871 | else: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 872 | 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] | 873 | procs_txt.append('{') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 874 | procs_txt.append(' uint64_t object_handle = (uint64_t)(object);') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 875 | procs_txt.append(' if (%sMap.find(object_handle) != %sMap.end()) {' % (o, o)) |
| 876 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(uint64_t)object];' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 877 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);') |
| 878 | procs_txt.append(' assert(numTotalObjs > 0);') |
| 879 | procs_txt.append(' numTotalObjs--;') |
| 880 | procs_txt.append(' assert(numObjs[objIndex] > 0);') |
| 881 | procs_txt.append(' numObjs[objIndex]--;') |
Mark Lobodzinski | 510e20d | 2016-02-11 09:26:16 -0700 | [diff] [blame] | 882 | 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] | 883 | 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] | 884 | 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] | 885 | procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 886 | procs_txt.append(' delete pNode;') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 887 | procs_txt.append(' %sMap.erase(object_handle);' % (o)) |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 888 | procs_txt.append(' } else {') |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 889 | 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] | 890 | 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] | 891 | procs_txt.append(' object_handle);') |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 892 | procs_txt.append(' }') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 893 | procs_txt.append('}') |
| 894 | procs_txt.append('') |
| 895 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 896 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 897 | 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] | 898 | else: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 899 | 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] | 900 | procs_txt.append('{') |
| 901 | procs_txt.append(' if (object != VK_NULL_HANDLE) {') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 902 | procs_txt.append(' uint64_t object_handle = (uint64_t)(object);') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 903 | procs_txt.append(' if (%sMap.find(object_handle) != %sMap.end()) {' % (o, o)) |
| 904 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object_handle];' % (o)) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 905 | procs_txt.append(' pNode->status |= status_flag;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 906 | procs_txt.append(' }') |
| 907 | procs_txt.append(' else {') |
| 908 | procs_txt.append(' // If we do not find it print an error') |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 909 | 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] | 910 | 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] | 911 | procs_txt.append(' object_handle, string_VkDebugReportObjectTypeEXT(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 912 | procs_txt.append(' }') |
| 913 | procs_txt.append(' }') |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 914 | procs_txt.append(' return VK_FALSE;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 915 | procs_txt.append('}') |
| 916 | procs_txt.append('') |
| 917 | procs_txt.append('%s' % self.lineinfo.get()) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 918 | procs_txt.append('static VkBool32 validate_%s_status(' % (name)) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 919 | if o in vulkan.object_dispatch_list: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 920 | procs_txt.append('%s dispatchable_object, %s object,' % (o, o)) |
| 921 | else: |
| 922 | procs_txt.append('VkDevice dispatchable_object, %s object,' % (o)) |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 923 | procs_txt.append(' VkDebugReportObjectTypeEXT objType,') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 924 | procs_txt.append(' ObjectStatusFlags status_mask,') |
| 925 | procs_txt.append(' ObjectStatusFlags status_flag,') |
| 926 | procs_txt.append(' VkFlags msg_flags,') |
| 927 | procs_txt.append(' OBJECT_TRACK_ERROR error_code,') |
| 928 | procs_txt.append(' const char *fail_msg)') |
| 929 | procs_txt.append('{') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 930 | procs_txt.append(' uint64_t object_handle = (uint64_t)(object);') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 931 | procs_txt.append(' if (%sMap.find(object_handle) != %sMap.end()) {' % (o, o)) |
| 932 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object_handle];' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 933 | procs_txt.append(' if ((pNode->status & status_mask) != status_flag) {') |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 934 | 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] | 935 | 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] | 936 | procs_txt.append(' object_handle, fail_msg);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 937 | procs_txt.append(' return VK_FALSE;') |
| 938 | procs_txt.append(' }') |
| 939 | procs_txt.append(' return VK_TRUE;') |
| 940 | procs_txt.append(' }') |
| 941 | procs_txt.append(' else {') |
| 942 | procs_txt.append(' // If we do not find it print an error') |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 943 | 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] | 944 | 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] | 945 | procs_txt.append(' object_handle, string_VkDebugReportObjectTypeEXT(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 946 | procs_txt.append(' return VK_FALSE;') |
| 947 | procs_txt.append(' }') |
| 948 | procs_txt.append('}') |
| 949 | procs_txt.append('') |
| 950 | procs_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 951 | if o in vulkan.object_dispatch_list: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 952 | 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] | 953 | else: |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 954 | 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] | 955 | procs_txt.append('{') |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 956 | procs_txt.append(' uint64_t object_handle = (uint64_t)(object);') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 957 | procs_txt.append(' if (%sMap.find(object_handle) != %sMap.end()) {' % (o, o)) |
| 958 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object_handle];' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 959 | procs_txt.append(' pNode->status &= ~status_flag;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 960 | procs_txt.append(' }') |
| 961 | procs_txt.append(' else {') |
| 962 | procs_txt.append(' // If we do not find it print an error') |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 963 | 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] | 964 | 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] | 965 | procs_txt.append(' object_handle, string_VkDebugReportObjectTypeEXT(objType));') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 966 | procs_txt.append(' }') |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 967 | procs_txt.append(' return VK_FALSE;') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 968 | procs_txt.append('}') |
| 969 | procs_txt.append('') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 970 | procs_txt.append('%s' % self.lineinfo.get()) |
| 971 | # Generate the permutations of validate_* functions where for each |
| 972 | # dispatchable object type, we have a corresponding validate_* function |
| 973 | # for that object and all non-dispatchable objects that are used in API |
| 974 | # calls with that dispatchable object. |
| 975 | procs_txt.append('//%s' % str(obj_use_dict)) |
| 976 | for do in obj_use_dict: |
| 977 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', do) |
| 978 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
| 979 | # First create validate_* func for disp obj |
| 980 | procs_txt.append('%s' % self.lineinfo.get()) |
| 981 | procs_txt.append('static VkBool32 validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, do)) |
| 982 | procs_txt.append('{') |
| 983 | procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))') |
| 984 | procs_txt.append(' return VK_FALSE;') |
| 985 | 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] | 986 | procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
| 987 | procs_txt.append(' "Invalid %s Object 0x%%" PRIx64 ,(uint64_t)(object));' % do) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 988 | procs_txt.append(' }') |
| 989 | procs_txt.append(' return VK_FALSE;') |
| 990 | procs_txt.append('}') |
| 991 | procs_txt.append('') |
| 992 | for o in obj_use_dict[do]: |
| 993 | if o == do: # We already generated this case above so skip here |
| 994 | continue |
| 995 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o) |
| 996 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
| 997 | procs_txt.append('%s' % self.lineinfo.get()) |
| 998 | procs_txt.append('static VkBool32 validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, o)) |
| 999 | procs_txt.append('{') |
| 1000 | procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))') |
| 1001 | procs_txt.append(' return VK_FALSE;') |
| 1002 | if o == "VkImage": |
| 1003 | procs_txt.append(' // We need to validate normal image objects and those from the swapchain') |
| 1004 | procs_txt.append(' if ((%sMap.find((uint64_t)object) == %sMap.end()) &&' % (o, o)) |
| 1005 | procs_txt.append(' (swapchainImageMap.find((uint64_t)object) == swapchainImageMap.end())) {') |
| 1006 | else: |
| 1007 | 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] | 1008 | procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
| 1009 | procs_txt.append(' "Invalid %s Object 0x%%" PRIx64, (uint64_t)(object));' % o) |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1010 | procs_txt.append(' }') |
| 1011 | procs_txt.append(' return VK_FALSE;') |
| 1012 | procs_txt.append('}') |
| 1013 | procs_txt.append('') |
| 1014 | procs_txt.append('') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1015 | return "\n".join(procs_txt) |
| 1016 | |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1017 | def generate_destroy_instance(self): |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1018 | gedi_txt = [] |
| 1019 | gedi_txt.append('%s' % self.lineinfo.get()) |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1020 | 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] | 1021 | gedi_txt.append('VkInstance instance,') |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1022 | gedi_txt.append('const VkAllocationCallbacks* pAllocator)') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1023 | gedi_txt.append('{') |
| 1024 | gedi_txt.append(' loader_platform_thread_lock_mutex(&objLock);') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1025 | 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] | 1026 | gedi_txt.append('') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1027 | gedi_txt.append(' destroy_instance(instance, instance);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1028 | gedi_txt.append(' // Report any remaining objects in LL') |
| 1029 | for o in vulkan.core.objects: |
Mike Stroyan | 0699a79 | 2015-08-18 14:48:34 -0600 | [diff] [blame] | 1030 | if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue']: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1031 | continue |
| 1032 | gedi_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end(); ++it) {' % (o, o)) |
| 1033 | gedi_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 1034 | gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1035 | gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),') |
Tony Barbour | 343d621 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1036 | gedi_txt.append(' pNode->vkObj);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1037 | gedi_txt.append(' }') |
Mike Stroyan | 0699a79 | 2015-08-18 14:48:34 -0600 | [diff] [blame] | 1038 | gedi_txt.append(' %sMap.clear();' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1039 | gedi_txt.append('') |
| 1040 | gedi_txt.append(' dispatch_key key = get_dispatch_key(instance);') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1041 | 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] | 1042 | gedi_txt.append(' pInstanceTable->DestroyInstance(instance, pAllocator);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1043 | gedi_txt.append('') |
| 1044 | gedi_txt.append(' // Clean up logging callback, if any') |
| 1045 | gedi_txt.append(' layer_data *my_data = get_my_data_ptr(key, layer_data_map);') |
| 1046 | gedi_txt.append(' if (my_data->logging_callback) {') |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 1047 | gedi_txt.append(' layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback, pAllocator);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1048 | gedi_txt.append(' }') |
| 1049 | gedi_txt.append('') |
| 1050 | gedi_txt.append(' layer_debug_report_destroy_instance(mid(instance));') |
| 1051 | gedi_txt.append(' layer_data_map.erase(pInstanceTable);') |
| 1052 | gedi_txt.append('') |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 1053 | gedi_txt.append(' instanceExtMap.erase(pInstanceTable);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1054 | gedi_txt.append(' loader_platform_thread_unlock_mutex(&objLock);') |
Mike Stroyan | 0699a79 | 2015-08-18 14:48:34 -0600 | [diff] [blame] | 1055 | # The loader holds a mutex that protects this from other threads |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1056 | gedi_txt.append(' object_tracker_instance_table_map.erase(key);') |
| 1057 | gedi_txt.append(' if (object_tracker_instance_table_map.empty()) {') |
Mike Stroyan | 0699a79 | 2015-08-18 14:48:34 -0600 | [diff] [blame] | 1058 | gedi_txt.append(' // Release mutex when destroying last instance.') |
| 1059 | gedi_txt.append(' loader_platform_thread_delete_mutex(&objLock);') |
| 1060 | gedi_txt.append(' objLockInitialized = 0;') |
| 1061 | gedi_txt.append(' }') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1062 | gedi_txt.append('}') |
| 1063 | gedi_txt.append('') |
| 1064 | return "\n".join(gedi_txt) |
| 1065 | |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1066 | def generate_destroy_device(self): |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1067 | gedd_txt = [] |
| 1068 | gedd_txt.append('%s' % self.lineinfo.get()) |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1069 | 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] | 1070 | gedd_txt.append('VkDevice device,') |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1071 | gedd_txt.append('const VkAllocationCallbacks* pAllocator)') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1072 | gedd_txt.append('{') |
| 1073 | gedd_txt.append(' loader_platform_thread_lock_mutex(&objLock);') |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1074 | 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] | 1075 | gedd_txt.append('') |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1076 | gedd_txt.append(' destroy_device(device, device);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1077 | gedd_txt.append(' // Report any remaining objects in LL') |
| 1078 | for o in vulkan.core.objects: |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1079 | # DescriptorSets and Command Buffers are destroyed through their pools, not explicitly |
| 1080 | if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue', 'VkDevice', 'VkDescriptorSet', 'VkCommandBuffer']: |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1081 | continue |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1082 | gedd_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end(); ++it) {' % (o, o)) |
| 1083 | gedd_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 1084 | gedd_txt.append(' log_msg(mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1085 | gedd_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),') |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1086 | gedd_txt.append(' pNode->vkObj);') |
| 1087 | gedd_txt.append(' }') |
Mike Stroyan | 0699a79 | 2015-08-18 14:48:34 -0600 | [diff] [blame] | 1088 | gedd_txt.append(' %sMap.clear();' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1089 | gedd_txt.append('') |
| 1090 | gedd_txt.append(" // Clean up Queue's MemRef Linked Lists") |
| 1091 | gedd_txt.append(' destroyQueueMemRefLists();') |
| 1092 | gedd_txt.append('') |
| 1093 | gedd_txt.append(' loader_platform_thread_unlock_mutex(&objLock);') |
| 1094 | gedd_txt.append('') |
| 1095 | gedd_txt.append(' dispatch_key key = get_dispatch_key(device);') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1096 | 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] | 1097 | gedd_txt.append(' pDisp->DestroyDevice(device, pAllocator);') |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1098 | gedd_txt.append(' object_tracker_device_table_map.erase(key);') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1099 | gedd_txt.append('') |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1100 | gedd_txt.append('}') |
| 1101 | gedd_txt.append('') |
| 1102 | return "\n".join(gedd_txt) |
| 1103 | |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 1104 | # Special-case validating some objects -- they may be non-NULL but should |
| 1105 | # only be validated upon meeting some condition specified below. |
| 1106 | def _dereference_conditionally(self, indent, prefix, type_name, name): |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1107 | s_code = '' |
| 1108 | if type_name == 'pBufferInfo': |
| 1109 | s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||\n' % (indent, prefix) |
| 1110 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||\n' % (indent, prefix) |
| 1111 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||\n' % (indent, prefix) |
| 1112 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) ) {\n' % (indent, prefix) |
| 1113 | elif type_name == 'pImageInfo': |
| 1114 | s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||\n' % (indent, prefix) |
| 1115 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||\n' % (indent, prefix) |
| 1116 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) ||\n' % (indent, prefix) |
| 1117 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||\n' % (indent, prefix) |
| 1118 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ) {\n' % (indent, prefix) |
| 1119 | elif type_name == 'pTexelBufferView': |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 1120 | s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||\n' % (indent, prefix) |
| 1121 | s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) ) {\n' % (indent, prefix) |
| 1122 | elif name == 'pBeginInfo->pInheritanceInfo': |
| 1123 | s_code += '%sOBJTRACK_NODE* pNode = VkCommandBufferMap[(uint64_t)commandBuffer];\n' % (indent) |
| 1124 | 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] | 1125 | else: |
| 1126 | s_code += '%sif (%s) {\n' % (indent, name) |
| 1127 | return s_code |
| 1128 | |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1129 | def _gen_obj_validate_code(self, struct_uses, obj_type_mapping, func_name, valid_null_dict, param0_name, indent, prefix, array_index): |
| 1130 | pre_code = '' |
| 1131 | for obj in sorted(struct_uses): |
| 1132 | name = obj |
| 1133 | array = '' |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1134 | type_name = '' |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1135 | if '[' in obj: |
| 1136 | (name, array) = obj.split('[') |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1137 | type_name = name |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1138 | array = array.strip(']') |
| 1139 | if isinstance(struct_uses[obj], dict): |
| 1140 | local_prefix = '' |
| 1141 | name = '%s%s' % (prefix, name) |
| 1142 | ptr_type = False |
| 1143 | if 'p' == obj[0]: |
| 1144 | ptr_type = True |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 1145 | tmp_pre = self._dereference_conditionally(indent, prefix, type_name, name) |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1146 | pre_code += tmp_pre |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1147 | indent += ' ' |
| 1148 | if array != '': |
| 1149 | idx = 'idx%s' % str(array_index) |
| 1150 | array_index += 1 |
| 1151 | pre_code += '%s\n' % self.lineinfo.get() |
| 1152 | pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx) |
| 1153 | indent += ' ' |
| 1154 | local_prefix = '%s[%s].' % (name, idx) |
| 1155 | elif ptr_type: |
| 1156 | local_prefix = '%s->' % (name) |
| 1157 | else: |
| 1158 | local_prefix = '%s.' % (name) |
| 1159 | 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) |
| 1160 | pre_code += tmp_pre |
| 1161 | if array != '': |
| 1162 | indent = indent[4:] |
| 1163 | pre_code += '%s}\n' % (indent) |
| 1164 | if ptr_type: |
| 1165 | indent = indent[4:] |
| 1166 | pre_code += '%s}\n' % (indent) |
| 1167 | else: |
| 1168 | ptype = struct_uses[obj] |
| 1169 | dbg_obj_type = obj_type_mapping[ptype] |
| 1170 | fname = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', ptype) |
| 1171 | fname = re.sub('([a-z0-9])([A-Z])', r'\1_\2', fname).lower()[3:] |
| 1172 | full_name = '%s%s' % (prefix, name) |
| 1173 | null_obj_ok = 'false' |
| 1174 | # If a valid null param is defined for this func and we have a match, allow NULL |
| 1175 | if func_name in valid_null_dict and True in [name in pn for pn in valid_null_dict[func_name]]: |
| 1176 | null_obj_ok = 'true' |
| 1177 | if (array_index > 0) or '' != array: |
Mark Lobodzinski | 2fba032 | 2016-01-23 18:31:23 -0700 | [diff] [blame] | 1178 | tmp_pre = self._dereference_conditionally(indent, prefix, type_name, full_name) |
Mark Lobodzinski | 9fde639 | 2016-01-19 09:57:24 -0700 | [diff] [blame] | 1179 | pre_code += tmp_pre |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1180 | indent += ' ' |
| 1181 | if array != '': |
| 1182 | idx = 'idx%s' % str(array_index) |
| 1183 | array_index += 1 |
| 1184 | pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx) |
| 1185 | indent += ' ' |
| 1186 | full_name = '%s[%s]' % (full_name, idx) |
| 1187 | pre_code += '%s\n' % self.lineinfo.get() |
| 1188 | pre_code += '%sskipCall |= validate_%s(%s, %s, %s, %s);\n' %(indent, fname, param0_name, full_name, dbg_obj_type, null_obj_ok) |
| 1189 | if array != '': |
| 1190 | indent = indent[4:] |
| 1191 | pre_code += '%s}\n' % (indent) |
| 1192 | indent = indent[4:] |
| 1193 | pre_code += '%s}\n' % (indent) |
| 1194 | else: |
| 1195 | pre_code += '%s\n' % self.lineinfo.get() |
| 1196 | pre_code += '%sskipCall |= validate_%s(%s, %s, %s, %s);\n' %(indent, fname, param0_name, full_name, dbg_obj_type, null_obj_ok) |
| 1197 | return pre_code |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1198 | |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1199 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1200 | if proto.name in [ 'CreateDebugReportCallbackEXT', 'EnumerateInstanceLayerProperties', 'EnumerateInstanceExtensionProperties','EnumerateDeviceLayerProperties', 'EnumerateDeviceExtensionProperties' ]: |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1201 | # use default version |
| 1202 | return None |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1203 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1204 | # 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] | 1205 | 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] | 1206 | # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES |
| 1207 | for objectName, objectTypeEnum in obj_type_mapping.items(): |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1208 | obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum) + '_EXT'; |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1209 | # Command Buffer Object doesn't follow the rule. |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1210 | obj_type_mapping['VkCommandBuffer'] = "VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT" |
| 1211 | obj_type_mapping['VkShaderModule'] = "VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT" |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1212 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1213 | explicit_object_tracker_functions = [ |
| 1214 | "CreateInstance", |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1215 | "EnumeratePhysicalDevices", |
Cody Northrop | d080288 | 2015-08-03 17:04:53 -0600 | [diff] [blame] | 1216 | "GetPhysicalDeviceQueueFamilyProperties", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1217 | "CreateDevice", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1218 | "GetDeviceQueue", |
Chia-I Wu | 1ff4c3d | 2015-10-26 16:55:27 +0800 | [diff] [blame] | 1219 | "QueueBindSparse", |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1220 | "AllocateDescriptorSets", |
Tony Barbour | 770f80d | 2015-07-20 10:52:13 -0600 | [diff] [blame] | 1221 | "FreeDescriptorSets", |
Mark Lobodzinski | 154329b | 2016-01-26 09:55:28 -0700 | [diff] [blame] | 1222 | "CreateGraphicsPipelines", |
| 1223 | "CreateComputePipelines", |
Mark Lobodzinski | 5f5c0e1 | 2015-11-12 16:02:35 -0700 | [diff] [blame] | 1224 | "AllocateCommandBuffers", |
| 1225 | "FreeCommandBuffers", |
| 1226 | "DestroyDescriptorPool", |
| 1227 | "DestroyCommandPool", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1228 | "MapMemory", |
| 1229 | "UnmapMemory", |
| 1230 | "FreeMemory", |
Mark Lobodzinski | e6d3f2c | 2015-10-14 13:16:33 -0600 | [diff] [blame] | 1231 | "DestroySwapchainKHR", |
| 1232 | "GetSwapchainImagesKHR" |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1233 | ] |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1234 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1235 | param0_name = proto.params[0].name |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1236 | using_line = '' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1237 | create_line = '' |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1238 | destroy_line = '' |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1239 | # 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] | 1240 | # 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] | 1241 | 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] | 1242 | loop_types = defaultdict(list) |
Tobin Ehlis | 2717d13 | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1243 | # 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] | 1244 | # or better yet, these should be encoded into an API json definition and we generate checks from there |
| 1245 | # 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) |
| 1246 | # param names may be directly passed to the function, or may be a field in a struct param |
| 1247 | valid_null_object_names = {'CreateGraphicsPipelines' : ['basePipelineHandle'], |
| 1248 | 'CreateComputePipelines' : ['basePipelineHandle'], |
| 1249 | 'BeginCommandBuffer' : ['renderPass', 'framebuffer'], |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1250 | 'QueueSubmit' : ['fence'], |
Jon Ashburn | 9216ae4 | 2016-01-14 15:11:55 -0700 | [diff] [blame] | 1251 | 'AcquireNextImageKHR' : ['fence', 'semaphore' ], |
Tobin Ehlis | ba31cab | 2015-11-02 15:24:32 -0700 | [diff] [blame] | 1252 | 'UpdateDescriptorSets' : ['pTexelBufferView'], |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1253 | 'CreateSwapchainKHR' : ['oldSwapchain'], |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1254 | } |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1255 | param_count = 'NONE' # keep track of arrays passed directly into API functions |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1256 | for p in proto.params: |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1257 | base_type = p.ty.replace('const ', '').strip('*') |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1258 | if 'count' in p.name.lower(): |
| 1259 | param_count = p.name |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1260 | if base_type in vulkan.core.objects: |
| 1261 | # This is an object to potentially check for validity. First see if it's an array |
| 1262 | if '*' in p.ty and 'const' in p.ty and param_count != 'NONE': |
| 1263 | loop_params[param_count].append(p.name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1264 | loop_types[param_count].append(str(p.ty[6:-1])) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1265 | # Not an array, check for just a base Object that's not in exceptions |
| 1266 | 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] | 1267 | loop_params[0].append(p.name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1268 | loop_types[0].append(str(p.ty)) |
Tobin Ehlis | ec59830 | 2015-09-15 15:02:17 -0600 | [diff] [blame] | 1269 | elif vk_helper.is_type(base_type, 'struct'): |
| 1270 | struct_type = base_type |
Tobin Ehlis | 9d67594 | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1271 | if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict: |
| 1272 | struct_type = vk_helper.typedef_rev_dict[struct_type] |
Tobin Ehlis | 82b3db5 | 2015-10-23 17:52:53 -0600 | [diff] [blame] | 1273 | # 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] | 1274 | for m in sorted(vk_helper.struct_dict[struct_type]): |
| 1275 | 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] | 1276 | 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] | 1277 | # This is not great, but gets the job done for now, but If we have a count and this param is a ptr w/ |
| 1278 | # last letter 's' OR non-'count' string of count is in the param name, then this is a dynamically sized array param |
| 1279 | param_array = False |
| 1280 | if param_count != 'NONE': |
| 1281 | if '*' in p.ty: |
| 1282 | if 's' == p.name[-1] or param_count.lower().replace('count', '') in p.name.lower(): |
| 1283 | param_array = True |
| 1284 | if param_array: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1285 | 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] | 1286 | else: |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1287 | param_name = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name']) |
| 1288 | if vk_helper.struct_dict[struct_type][m]['dyn_array']: |
Tobin Ehlis | 82b3db5 | 2015-10-23 17:52:53 -0600 | [diff] [blame] | 1289 | if param_count != 'NONE': # this will be a double-embedded loop, use comma delineated 'count,name' for param_name |
| 1290 | loop_count = '%s[i].%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size']) |
| 1291 | loop_params[param_count].append('%s,%s' % (loop_count, param_name)) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1292 | 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] | 1293 | else: |
| 1294 | loop_count = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size']) |
| 1295 | loop_params[loop_count].append(param_name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1296 | 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] | 1297 | else: |
| 1298 | if '[' in param_name: # dynamic array param, set size |
| 1299 | loop_params[param_count].append(param_name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1300 | 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] | 1301 | else: |
| 1302 | loop_params[0].append(param_name) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1303 | 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] | 1304 | last_param_index = None |
| 1305 | create_func = False |
| 1306 | if True in [create_txt in proto.name for create_txt in ['Create', 'Allocate']]: |
| 1307 | create_func = True |
| 1308 | last_param_index = -1 # For create funcs don't validate last object |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1309 | (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] | 1310 | funcs = [] |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1311 | mutex_unlock = False |
Tobin Ehlis | 154e046 | 2015-08-26 11:22:09 -0600 | [diff] [blame] | 1312 | funcs.append('%s\n' % self.lineinfo.get()) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1313 | if proto.name in explicit_object_tracker_functions: |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1314 | funcs.append('%s%s\n' |
| 1315 | '{\n' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1316 | ' return explicit_%s;\n' |
| 1317 | '}' % (qual, decl, proto.c_call())) |
| 1318 | return "".join(funcs) |
Mark Lobodzinski | 308d779 | 2015-11-24 10:28:31 -0700 | [diff] [blame] | 1319 | # 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] | 1320 | elif 'DestroyInstance' in proto.name or 'DestroyDevice' in proto.name: |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1321 | return "" |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1322 | else: |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1323 | if create_func: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1324 | typ = proto.params[-1].ty.strip('*').replace('const ', ''); |
| 1325 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ) |
| 1326 | name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1327 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1328 | create_line += ' if (result == VK_SUCCESS) {\n' |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1329 | create_line += ' create_%s(%s, *%s, %s);\n' % (name, param0_name, proto.params[-1].name, obj_type_mapping[typ]) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1330 | create_line += ' }\n' |
| 1331 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Courtney Goeltzenleuchter | bee18a9 | 2015-10-23 14:21:05 -0600 | [diff] [blame] | 1332 | if 'FreeCommandBuffers' in proto.name: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1333 | typ = proto.params[-1].ty.strip('*').replace('const ', ''); |
| 1334 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ) |
| 1335 | 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] | 1336 | funcs.append('%s\n' % self.lineinfo.get()) |
| 1337 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Chia-I Wu | d50a7d7 | 2015-10-26 20:48:51 +0800 | [diff] [blame] | 1338 | destroy_line += ' for (uint32_t i = 0; i < commandBufferCount; i++) {\n' |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1339 | 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] | 1340 | destroy_line += ' }\n' |
| 1341 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1342 | if 'Destroy' in proto.name: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1343 | typ = proto.params[-2].ty.strip('*').replace('const ', ''); |
| 1344 | name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ) |
| 1345 | 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] | 1346 | funcs.append('%s\n' % self.lineinfo.get()) |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1347 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1348 | destroy_line += ' destroy_%s(%s, %s);\n' % (name, param0_name, proto.params[-2].name) |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1349 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1350 | indent = ' ' |
| 1351 | if len(struct_uses) > 0: |
| 1352 | using_line += '%sVkBool32 skipCall = VK_FALSE;\n' % (indent) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1353 | if not mutex_unlock: |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1354 | using_line += '%sloader_platform_thread_lock_mutex(&objLock);\n' % (indent) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1355 | mutex_unlock = True |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1356 | using_line += '// objects to validate: %s\n' % str(struct_uses) |
| 1357 | using_line += self._gen_obj_validate_code(struct_uses, obj_type_mapping, proto.name, valid_null_object_names, param0_name, ' ', '', 0) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1358 | if mutex_unlock: |
Tobin Ehlis | 86684f9 | 2016-01-05 10:33:58 -0700 | [diff] [blame] | 1359 | using_line += '%sloader_platform_thread_unlock_mutex(&objLock);\n' % (indent) |
| 1360 | if len(struct_uses) > 0: |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 1361 | using_line += ' if (skipCall)\n' |
| 1362 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 52fee65 | 2015-12-10 16:41:22 -0700 | [diff] [blame] | 1363 | using_line += ' return VK_ERROR_VALIDATION_FAILED_EXT;\n' |
Tobin Ehlis | c9ac2b6 | 2015-09-11 12:57:55 -0600 | [diff] [blame] | 1364 | else: |
| 1365 | using_line += ' return;\n' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1366 | ret_val = '' |
| 1367 | stmt = '' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1368 | if proto.ret != "void": |
| 1369 | ret_val = "%s result = " % proto.ret |
| 1370 | stmt = " return result;\n" |
| 1371 | |
| 1372 | dispatch_param = proto.params[0].name |
| 1373 | if 'CreateInstance' in proto.name: |
| 1374 | dispatch_param = '*' + proto.params[1].name |
| 1375 | |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1376 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 1377 | table_type = "" |
| 1378 | if proto_is_global(proto): |
| 1379 | table_type = "instance" |
| 1380 | else: |
| 1381 | table_type = "device" |
Mark Lobodzinski | a8a5f85 | 2015-12-10 16:25:21 -0700 | [diff] [blame] | 1382 | if wsi_name(proto.name): |
| 1383 | funcs.append('%s' % wsi_ifdef(proto.name)) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1384 | funcs.append('%s%s\n' |
| 1385 | '{\n' |
| 1386 | '%s' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1387 | '%s' |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1388 | ' %sget_dispatch_table(object_tracker_%s_table_map, %s)->%s;\n' |
Mike Stroyan | 38820b3 | 2015-09-28 13:47:29 -0600 | [diff] [blame] | 1389 | '%s' |
| 1390 | '%s' |
| 1391 | '}' % (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] | 1392 | if wsi_name(proto.name): |
| 1393 | funcs.append('%s' % wsi_endif(proto.name)) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1394 | return "\n\n".join(funcs) |
| 1395 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1396 | def generate_body(self): |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1397 | self.layer_name = "object_tracker" |
Ian Elliott | 1064fe3 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 1398 | extensions=[('wsi_enabled', |
Ian Elliott | 0584606 | 2015-11-20 14:13:17 -0700 | [diff] [blame] | 1399 | ['vkCreateSwapchainKHR', |
Jon Ashburn | 8acd233 | 2015-09-16 18:08:32 -0600 | [diff] [blame] | 1400 | 'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR', |
| 1401 | 'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])] |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1402 | if self.wsi == 'Win32': |
Michael Lentine | 64e2ebd | 2015-12-03 14:33:09 -0800 | [diff] [blame] | 1403 | instance_extensions=[('msg_callback_get_proc_addr', []), |
| 1404 | ('wsi_enabled', |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 1405 | ['vkDestroySurfaceKHR', |
| 1406 | 'vkGetPhysicalDeviceSurfaceSupportKHR', |
Michael Lentine | 64e2ebd | 2015-12-03 14:33:09 -0800 | [diff] [blame] | 1407 | 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR', |
| 1408 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
| 1409 | 'vkGetPhysicalDeviceSurfacePresentModesKHR', |
| 1410 | 'vkCreateWin32SurfaceKHR', |
| 1411 | 'vkGetPhysicalDeviceWin32PresentationSupportKHR'])] |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1412 | elif self.wsi == 'Android': |
| 1413 | instance_extensions=[('msg_callback_get_proc_addr', []), |
| 1414 | ('wsi_enabled', |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 1415 | ['vkDestroySurfaceKHR', |
| 1416 | 'vkGetPhysicalDeviceSurfaceSupportKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1417 | 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR', |
| 1418 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 1419 | 'vkGetPhysicalDeviceSurfacePresentModesKHR', |
| 1420 | 'vkCreateAndroidSurfaceKHR'])] |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame^] | 1421 | 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] | 1422 | instance_extensions=[('msg_callback_get_proc_addr', []), |
| 1423 | ('wsi_enabled', |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 1424 | ['vkDestroySurfaceKHR', |
| 1425 | 'vkGetPhysicalDeviceSurfaceSupportKHR', |
Michael Lentine | 64e2ebd | 2015-12-03 14:33:09 -0800 | [diff] [blame] | 1426 | 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR', |
| 1427 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
| 1428 | 'vkGetPhysicalDeviceSurfacePresentModesKHR', |
| 1429 | 'vkCreateXcbSurfaceKHR', |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame^] | 1430 | 'vkGetPhysicalDeviceXcbPresentationSupportKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1431 | 'vkCreateXlibSurfaceKHR', |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame^] | 1432 | 'vkGetPhysicalDeviceXlibPresentationSupportKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1433 | 'vkCreateWaylandSurfaceKHR', |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame^] | 1434 | 'vkGetPhysicalDeviceWaylandPresentationSupportKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1435 | 'vkCreateMirSurfaceKHR', |
| 1436 | 'vkGetPhysicalDeviceMirPresentationSupportKHR'])] |
Mark Lobodzinski | d53098f | 2016-02-25 18:14:56 -0700 | [diff] [blame] | 1437 | else: |
| 1438 | print('Error: Undefined DisplayServer') |
| 1439 | instance_extensions=[] |
| 1440 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1441 | body = [self.generate_maps(), |
| 1442 | self.generate_procs(), |
Mark Lobodzinski | 64d5775 | 2015-07-17 11:51:24 -0600 | [diff] [blame] | 1443 | self.generate_destroy_instance(), |
| 1444 | self.generate_destroy_device(), |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1445 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1446 | self._generate_extensions(), |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1447 | self._generate_layer_gpa_function(extensions, |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 1448 | instance_extensions)] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1449 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1450 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1451 | class UniqueObjectsSubcommand(Subcommand): |
| 1452 | def generate_header(self): |
| 1453 | header_txt = [] |
| 1454 | header_txt.append('%s' % self.lineinfo.get()) |
| 1455 | header_txt.append('#include "unique_objects.h"') |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1456 | return "\n".join(header_txt) |
| 1457 | |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1458 | # 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] | 1459 | # vector_name_set is used to make sure we don't replicate vector names |
| 1460 | # 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] | 1461 | # TODO : Comment this code |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1462 | 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] | 1463 | decls = '' |
| 1464 | pre_code = '' |
| 1465 | post_code = '' |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1466 | for obj in sorted(struct_uses): |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1467 | name = obj |
| 1468 | array = '' |
| 1469 | if '[' in obj: |
| 1470 | (name, array) = obj.split('[') |
| 1471 | array = array.strip(']') |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1472 | ptr_type = False |
Tobin Ehlis | 991d45a | 2016-01-06 08:48:41 -0700 | [diff] [blame] | 1473 | if 'p' == obj[0] and obj[1] != obj[1].lower(): # TODO : Not idea way to determine ptr |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1474 | ptr_type = True |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1475 | if isinstance(struct_uses[obj], dict): |
| 1476 | local_prefix = '' |
| 1477 | name = '%s%s' % (prefix, name) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1478 | if ptr_type: |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1479 | if first_level_param and name in param_type: |
| 1480 | pre_code += '%sif (%s) {\n' % (indent, name) |
| 1481 | else: # shadow ptr will have been initialized at this point so check it vs. source ptr |
| 1482 | pre_code += '%sif (local_%s) {\n' % (indent, name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1483 | indent += ' ' |
| 1484 | if array != '': |
| 1485 | idx = 'idx%s' % str(array_index) |
| 1486 | array_index += 1 |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1487 | if first_level_param and name in param_type: |
| 1488 | pre_code += '%slocal_%s = new safe_%s[%s];\n' % (indent, name, param_type[name].strip('*'), array) |
| 1489 | post_code += ' if (local_%s)\n' % (name) |
| 1490 | post_code += ' delete[] local_%s;\n' % (name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1491 | 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] | 1492 | indent += ' ' |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1493 | if first_level_param: |
| 1494 | 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] | 1495 | local_prefix = '%s[%s].' % (name, idx) |
| 1496 | elif ptr_type: |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1497 | if first_level_param and name in param_type: |
| 1498 | pre_code += '%slocal_%s = new safe_%s(%s);\n' % (indent, name, param_type[name].strip('*'), name) |
| 1499 | post_code += ' if (local_%s)\n' % (name) |
| 1500 | post_code += ' delete local_%s;\n' % (name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1501 | local_prefix = '%s->' % (name) |
| 1502 | else: |
| 1503 | local_prefix = '%s.' % (name) |
| 1504 | assert isinstance(decls, object) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1505 | (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] | 1506 | decls += tmp_decl |
| 1507 | pre_code += tmp_pre |
| 1508 | post_code += tmp_post |
| 1509 | if array != '': |
| 1510 | indent = indent[4:] |
| 1511 | pre_code += '%s}\n' % (indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1512 | if ptr_type: |
| 1513 | indent = indent[4:] |
| 1514 | pre_code += '%s}\n' % (indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1515 | else: |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1516 | 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] | 1517 | if first_level_param: |
| 1518 | pre_code += '%s%s* local_%s = NULL;\n' % (indent, struct_uses[obj], name) |
Tobin Ehlis | 6dd0fc3 | 2016-02-12 14:37:09 -0700 | [diff] [blame] | 1519 | if array != '' and not first_level_param: # ptrs under structs will have been initialized so use local_* |
| 1520 | pre_code += '%sif (local_%s%s) {\n' %(indent, prefix, name) |
| 1521 | else: |
| 1522 | pre_code += '%sif (%s%s) {\n' %(indent, prefix, name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1523 | indent += ' ' |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1524 | if array != '': |
| 1525 | idx = 'idx%s' % str(array_index) |
| 1526 | array_index += 1 |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1527 | if first_level_param: |
| 1528 | pre_code += '%slocal_%s = new %s[%s];\n' % (indent, name, struct_uses[obj], array) |
| 1529 | post_code += ' if (local_%s)\n' % (name) |
| 1530 | post_code += ' delete[] local_%s;\n' % (name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1531 | 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] | 1532 | indent += ' ' |
| 1533 | name = '%s[%s]' % (name, idx) |
| 1534 | pName = 'p%s' % (struct_uses[obj][2:]) |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1535 | if name not in vector_name_set: |
| 1536 | vector_name_set.add(name) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1537 | pre_code += '%slocal_%s%s = (%s)((VkUniqueObject*)%s%s)->actualObject;\n' % (indent, prefix, name, struct_uses[obj], prefix, name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1538 | if array != '': |
| 1539 | indent = indent[4:] |
| 1540 | pre_code += '%s}\n' % (indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1541 | indent = indent[4:] |
| 1542 | pre_code += '%s}\n' % (indent) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1543 | else: |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1544 | pre_code += '%s\n' % (self.lineinfo.get()) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1545 | pre_code += '%sif (%s%s) {\n' %(indent, prefix, name) |
| 1546 | indent += ' ' |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1547 | deref_txt = '&' |
| 1548 | if ptr_type: |
| 1549 | deref_txt = '' |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1550 | if '->' in prefix: # need to update local struct |
| 1551 | pre_code += '%slocal_%s%s = (%s)((VkUniqueObject*)%s%s)->actualObject;\n' % (indent, prefix, name, struct_uses[obj], prefix, name) |
| 1552 | else: |
| 1553 | pre_code += '%s%s* p%s = (%s*)%s%s%s;\n' % (indent, struct_uses[obj], name, struct_uses[obj], deref_txt, prefix, name) |
| 1554 | pre_code += '%s*p%s = (%s)((VkUniqueObject*)%s%s)->actualObject;\n' % (indent, name, struct_uses[obj], prefix, name) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1555 | indent = indent[4:] |
| 1556 | pre_code += '%s}\n' % (indent) |
| 1557 | return decls, pre_code, post_code |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1558 | |
| 1559 | def generate_intercept(self, proto, qual): |
| 1560 | create_func = False |
| 1561 | destroy_func = False |
| 1562 | last_param_index = None #typcially we look at all params for ndos |
| 1563 | pre_call_txt = '' # code prior to calling down chain such as unwrap uses of ndos |
| 1564 | post_call_txt = '' # code following call down chain such to wrap newly created ndos, or destroy local wrap struct |
| 1565 | funcs = [] |
| 1566 | indent = ' ' # indent level for generated code |
| 1567 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1568 | # A few API cases that are manual code |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1569 | # TODO : Special case Create*Pipelines funcs to handle creating multiple unique objects |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1570 | explicit_object_tracker_functions = ['GetSwapchainImagesKHR', |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1571 | 'CreateInstance', |
Tobin Ehlis | a39c26a | 2016-01-05 16:34:59 -0700 | [diff] [blame] | 1572 | 'CreateDevice', |
| 1573 | 'CreateComputePipelines', |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1574 | 'CreateGraphicsPipelines' |
| 1575 | ] |
Tobin Ehlis | 453e91f | 2016-01-29 14:24:42 -0700 | [diff] [blame] | 1576 | # 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] | 1577 | ifdef_dict = {'CreateXcbSurfaceKHR': 'VK_USE_PLATFORM_XCB_KHR', |
| 1578 | 'CreateAndroidSurfaceKHR': 'VK_USE_PLATFORM_ANDROID_KHR', |
| 1579 | 'CreateWin32SurfaceKHR': 'VK_USE_PLATFORM_WIN32_KHR'} |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1580 | # Give special treatment to create functions that return multiple new objects |
| 1581 | # This dict stores array name and size of array |
Jon Ashburn | f19916e | 2016-01-11 13:12:43 -0700 | [diff] [blame] | 1582 | custom_create_dict = {'pDescriptorSets' : 'pAllocateInfo->descriptorSetCount'} |
Courtney Goeltzenleuchter | 5a0f283 | 2016-02-11 11:44:04 -0700 | [diff] [blame] | 1583 | pre_call_txt += '%s\n' % (self.lineinfo.get()) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1584 | if proto.name in explicit_object_tracker_functions: |
| 1585 | funcs.append('%s%s\n' |
| 1586 | '{\n' |
| 1587 | ' return explicit_%s;\n' |
| 1588 | '}' % (qual, decl, proto.c_call())) |
| 1589 | return "".join(funcs) |
| 1590 | if True in [create_txt in proto.name for create_txt in ['Create', 'Allocate']]: |
| 1591 | create_func = True |
| 1592 | last_param_index = -1 # For create funcs don't care if last param is ndo |
| 1593 | if True in [destroy_txt in proto.name for destroy_txt in ['Destroy', 'Free']]: |
| 1594 | destroy_obj_type = proto.params[-2].ty |
| 1595 | if destroy_obj_type in vulkan.object_non_dispatch_list: |
| 1596 | destroy_func = True |
| 1597 | |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1598 | # 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] | 1599 | (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] | 1600 | |
| 1601 | if len(struct_uses) > 0: |
| 1602 | pre_call_txt += '// STRUCT USES:%s\n' % struct_uses |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1603 | if len(local_decls) > 0: |
| 1604 | pre_call_txt += '//LOCAL DECLS:%s\n' % local_decls |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1605 | if destroy_func: # only one object |
| 1606 | for del_obj in struct_uses: |
| 1607 | pre_call_txt += '%s%s local_%s = %s;\n' % (indent, struct_uses[del_obj], del_obj, del_obj) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1608 | (pre_decl, pre_code, post_code) = self._gen_obj_code(struct_uses, local_decls, ' ', '', 0, set(), True) |
| 1609 | # This is a bit hacky but works for now. Need to decl local versions of top-level structs |
| 1610 | for ld in local_decls: |
| 1611 | init_null_txt = 'NULL'; |
| 1612 | if '*' not in local_decls[ld]: |
| 1613 | init_null_txt = '{}'; |
| 1614 | if local_decls[ld].strip('*') not in vulkan.object_non_dispatch_list: |
| 1615 | pre_decl += ' safe_%s local_%s = %s;\n' % (local_decls[ld], ld, init_null_txt) |
Tobin Ehlis | 65f44e4 | 2016-01-05 09:46:03 -0700 | [diff] [blame] | 1616 | pre_call_txt += '%s%s' % (pre_decl, pre_code) |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1617 | post_call_txt += '%s' % (post_code) |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1618 | elif create_func: |
| 1619 | base_type = proto.params[-1].ty.replace('const ', '').strip('*') |
| 1620 | if base_type not in vulkan.object_non_dispatch_list: |
| 1621 | return None |
| 1622 | else: |
| 1623 | return None |
| 1624 | |
| 1625 | ret_val = '' |
| 1626 | ret_stmt = '' |
| 1627 | if proto.ret != "void": |
| 1628 | ret_val = "%s result = " % proto.ret |
| 1629 | ret_stmt = " return result;\n" |
| 1630 | dispatch_param = proto.params[0].name |
| 1631 | if 'CreateInstance' in proto.name: |
| 1632 | dispatch_param = '*' + proto.params[1].name |
| 1633 | if create_func: |
| 1634 | obj_type = proto.params[-1].ty.strip('*') |
| 1635 | obj_name = proto.params[-1].name |
| 1636 | if obj_type in vulkan.object_non_dispatch_list: |
| 1637 | local_name = "unique%s" % obj_type[2:] |
| 1638 | post_call_txt += '%sif (VK_SUCCESS == result) {\n' % (indent) |
| 1639 | indent += ' ' |
| 1640 | if obj_name in custom_create_dict: |
| 1641 | post_call_txt += '%s\n' % (self.lineinfo.get()) |
| 1642 | local_name = '%ss' % (local_name) # add 's' to end for vector of many |
| 1643 | post_call_txt += '%sstd::vector<VkUniqueObject*> %s = {};\n' % (indent, local_name) |
| 1644 | post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, custom_create_dict[obj_name]) |
| 1645 | indent += ' ' |
| 1646 | post_call_txt += '%s%s.push_back(new VkUniqueObject());\n' % (indent, local_name) |
| 1647 | post_call_txt += '%s%s[i]->actualObject = (uint64_t)%s[i];\n' % (indent, local_name, obj_name) |
| 1648 | post_call_txt += '%s%s[i] = (%s)%s[i];\n' % (indent, obj_name, obj_type, local_name) |
| 1649 | indent = indent[4:] |
| 1650 | post_call_txt += '%s}\n' % (indent) |
| 1651 | else: |
| 1652 | post_call_txt += '%s\n' % (self.lineinfo.get()) |
| 1653 | post_call_txt += '%sVkUniqueObject* %s = new VkUniqueObject();\n' % (indent, local_name) |
| 1654 | post_call_txt += '%s%s->actualObject = (uint64_t)*%s;\n' % (indent, local_name, obj_name) |
| 1655 | post_call_txt += '%s*%s = (%s)%s;\n' % (indent, obj_name, obj_type, local_name) |
| 1656 | indent = indent[4:] |
| 1657 | post_call_txt += '%s}\n' % (indent) |
| 1658 | elif destroy_func: |
| 1659 | del_obj = proto.params[-2].name |
| 1660 | if 'count' in del_obj.lower(): |
| 1661 | post_call_txt += '%s\n' % (self.lineinfo.get()) |
| 1662 | post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, del_obj) |
| 1663 | del_obj = proto.params[-1].name |
| 1664 | indent += ' ' |
| 1665 | post_call_txt += '%sdelete (VkUniqueObject*)%s[i];\n' % (indent, del_obj) |
| 1666 | indent = indent[4:] |
| 1667 | post_call_txt += '%s}\n' % (indent) |
| 1668 | else: |
| 1669 | post_call_txt += '%s\n' % (self.lineinfo.get()) |
| 1670 | post_call_txt = '%sdelete (VkUniqueObject*)local_%s;\n' % (indent, proto.params[-2].name) |
| 1671 | |
| 1672 | call_sig = proto.c_call() |
Tobin Ehlis | 8bb7c2f | 2016-02-10 15:38:45 -0700 | [diff] [blame] | 1673 | # Replace default params with any custom local params |
| 1674 | for ld in local_decls: |
| 1675 | 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] | 1676 | if proto_is_global(proto): |
| 1677 | table_type = "instance" |
| 1678 | else: |
| 1679 | table_type = "device" |
| 1680 | pre_call_txt += '%s\n' % (self.lineinfo.get()) |
Tobin Ehlis | 453e91f | 2016-01-29 14:24:42 -0700 | [diff] [blame] | 1681 | open_ifdef = '' |
| 1682 | close_ifdef = '' |
| 1683 | if proto.name in ifdef_dict: |
| 1684 | open_ifdef = '#ifdef %s\n' % (ifdef_dict[proto.name]) |
| 1685 | close_ifdef = '#endif\n' |
| 1686 | funcs.append('%s' |
| 1687 | '%s%s\n' |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1688 | '{\n' |
| 1689 | '%s' |
| 1690 | ' %sget_dispatch_table(unique_objects_%s_table_map, %s)->%s;\n' |
| 1691 | '%s' |
| 1692 | '%s' |
Tobin Ehlis | 453e91f | 2016-01-29 14:24:42 -0700 | [diff] [blame] | 1693 | '}\n' |
| 1694 | '%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] | 1695 | return "\n\n".join(funcs) |
| 1696 | |
| 1697 | def generate_body(self): |
| 1698 | self.layer_name = "unique_objects" |
| 1699 | extensions=[('wsi_enabled', |
| 1700 | ['vkCreateSwapchainKHR', |
| 1701 | 'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR', |
| 1702 | 'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])] |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1703 | if self.wsi == 'Win32': |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1704 | instance_extensions=[('wsi_enabled', |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 1705 | ['vkDestroySurfaceKHR', |
| 1706 | 'vkGetPhysicalDeviceSurfaceSupportKHR', |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1707 | 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR', |
| 1708 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
| 1709 | 'vkGetPhysicalDeviceSurfacePresentModesKHR', |
Jon Ashburn | 00dc741 | 2016-01-07 16:13:06 -0700 | [diff] [blame] | 1710 | 'vkCreateWin32SurfaceKHR' |
| 1711 | ])] |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1712 | elif self.wsi == 'Android': |
| 1713 | instance_extensions=[('wsi_enabled', |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 1714 | ['vkDestroySurfaceKHR', |
| 1715 | 'vkGetPhysicalDeviceSurfaceSupportKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1716 | 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR', |
| 1717 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 1718 | 'vkGetPhysicalDeviceSurfacePresentModesKHR', |
| 1719 | 'vkCreateAndroidSurfaceKHR'])] |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame^] | 1720 | 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] | 1721 | instance_extensions=[('wsi_enabled', |
Michael Lentine | 56512bb | 2016-03-02 17:28:55 -0600 | [diff] [blame] | 1722 | ['vkDestroySurfaceKHR', |
| 1723 | 'vkGetPhysicalDeviceSurfaceSupportKHR', |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1724 | 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR', |
| 1725 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
| 1726 | 'vkGetPhysicalDeviceSurfacePresentModesKHR', |
Courtney Goeltzenleuchter | 5a0f283 | 2016-02-11 11:44:04 -0700 | [diff] [blame] | 1727 | 'vkCreateXcbSurfaceKHR', |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame^] | 1728 | 'vkCreateXlibSurfaceKHR', |
| 1729 | 'vkCreateWaylandSurfaceKHR', |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 1730 | 'vkCreateMirSurfaceKHR' |
| 1731 | ])] |
Karl Schultz | 9daf7a3 | 2016-03-08 15:14:11 -0700 | [diff] [blame^] | 1732 | else: |
| 1733 | print('Error: Undefined DisplayServer') |
| 1734 | instance_extensions=[] |
| 1735 | |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 1736 | body = [self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
| 1737 | self._generate_layer_gpa_function(extensions, |
| 1738 | instance_extensions)] |
| 1739 | return "\n\n".join(body) |
| 1740 | |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1741 | class ThreadingSubcommand(Subcommand): |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1742 | thread_check_dispatchable_objects = [ |
| 1743 | "VkQueue", |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1744 | "VkCommandBuffer", |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1745 | ] |
| 1746 | thread_check_nondispatchable_objects = [ |
| 1747 | "VkDeviceMemory", |
| 1748 | "VkBuffer", |
| 1749 | "VkImage", |
| 1750 | "VkDescriptorSet", |
| 1751 | "VkDescriptorPool", |
| 1752 | "VkSemaphore" |
| 1753 | ] |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1754 | thread_check_object_types = { |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1755 | 'VkInstance' : 'VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT', |
| 1756 | 'VkPhysicalDevice' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT', |
| 1757 | 'VkDevice' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT', |
| 1758 | 'VkQueue' : 'VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT', |
| 1759 | 'VkCommandBuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT', |
| 1760 | 'VkFence' : 'VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT', |
| 1761 | 'VkDeviceMemory' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT', |
| 1762 | 'VkBuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT', |
| 1763 | 'VkImage' : 'VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT', |
| 1764 | 'VkSemaphore' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT', |
| 1765 | 'VkEvent' : 'VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT', |
| 1766 | 'VkQueryPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT', |
| 1767 | 'VkBufferView' : 'VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT', |
| 1768 | 'VkImageView' : 'VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT', |
| 1769 | 'VkShaderModule' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT', |
| 1770 | 'VkShader' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SHADER', |
| 1771 | 'VkPipelineCache' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT', |
| 1772 | 'VkPipelineLayout' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT', |
| 1773 | 'VkRenderPass' : 'VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT', |
| 1774 | 'VkPipeline' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT', |
| 1775 | 'VkDescriptorSetLayout' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT', |
| 1776 | 'VkSampler' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT', |
| 1777 | 'VkDescriptorPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT', |
| 1778 | 'VkDescriptorSet' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT', |
| 1779 | 'VkFramebuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT', |
| 1780 | 'VkCommandPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT', |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1781 | } |
| 1782 | def generate_useObject(self, ty): |
| 1783 | obj_type = self.thread_check_object_types[ty] |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1784 | key = "object" |
Mark Young | 93ecb1d | 2016-01-13 13:47:16 -0700 | [diff] [blame] | 1785 | msg_object = "(uint64_t)(object)" |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1786 | header_txt = [] |
| 1787 | header_txt.append('%s' % self.lineinfo.get()) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1788 | header_txt.append('static void use%s(const void* dispatchable_object, %s object)' % (ty, ty)) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1789 | header_txt.append('{') |
| 1790 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
| 1791 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1792 | header_txt.append(' if (%sObjectsInUse.find(%s) == %sObjectsInUse.end()) {' % (ty, key, ty)) |
| 1793 | header_txt.append(' %sObjectsInUse[%s] = tid;' % (ty, key)) |
| 1794 | header_txt.append(' } else {') |
| 1795 | header_txt.append(' if (%sObjectsInUse[%s] != tid) {' % (ty, key)) |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1796 | header_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, %s, %s,' % (obj_type, msg_object)) |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 1797 | header_txt.append(' __LINE__, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING",') |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1798 | header_txt.append(' "THREADING ERROR : object of type %s is simultaneously used in thread %%ld and thread %%ld",' % (ty)) |
| 1799 | header_txt.append(' %sObjectsInUse[%s], tid);' % (ty, key)) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1800 | header_txt.append(' // Wait for thread-safe access to object') |
| 1801 | header_txt.append(' while (%sObjectsInUse.find(%s) != %sObjectsInUse.end()) {' % (ty, key, ty)) |
| 1802 | header_txt.append(' loader_platform_thread_cond_wait(&threadingCond, &threadingLock);') |
| 1803 | header_txt.append(' }') |
| 1804 | header_txt.append(' %sObjectsInUse[%s] = tid;' % (ty, key)) |
| 1805 | header_txt.append(' } else {') |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1806 | header_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, %s, %s,' % (obj_type, msg_object)) |
Mark Lobodzinski | 6085c2b | 2016-01-04 15:48:11 -0700 | [diff] [blame] | 1807 | header_txt.append(' __LINE__, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING",') |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1808 | header_txt.append(' "THREADING ERROR : object of type %s is recursively used in thread %%ld",' % (ty)) |
| 1809 | header_txt.append(' tid);') |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1810 | header_txt.append(' }') |
| 1811 | header_txt.append(' }') |
| 1812 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1813 | header_txt.append('}') |
| 1814 | return "\n".join(header_txt) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1815 | def generate_finishUsingObject(self, ty): |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1816 | key = "object" |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1817 | header_txt = [] |
| 1818 | header_txt.append('%s' % self.lineinfo.get()) |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1819 | header_txt.append('static void finishUsing%s(%s object)' % (ty, ty)) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1820 | header_txt.append('{') |
| 1821 | header_txt.append(' // Object is no longer in use') |
| 1822 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1823 | header_txt.append(' %sObjectsInUse.erase(%s);' % (ty, key)) |
| 1824 | header_txt.append(' loader_platform_thread_cond_broadcast(&threadingCond);') |
| 1825 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1826 | header_txt.append('}') |
| 1827 | return "\n".join(header_txt) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1828 | def generate_header(self): |
| 1829 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1830 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1831 | header_txt.append('#include <stdio.h>') |
| 1832 | header_txt.append('#include <stdlib.h>') |
| 1833 | header_txt.append('#include <string.h>') |
| 1834 | header_txt.append('#include <unordered_map>') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1835 | header_txt.append('#include "vk_loader_platform.h"') |
David Pinedo | 9316d3b | 2015-11-06 12:54:48 -0700 | [diff] [blame] | 1836 | header_txt.append('#include "vulkan/vk_layer.h"') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1837 | header_txt.append('#include "threading.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1838 | header_txt.append('#include "vk_layer_config.h"') |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 1839 | header_txt.append('#include "vk_layer_extension_utils.h"') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1840 | header_txt.append('#include "vk_enum_validate_helper.h"') |
| 1841 | header_txt.append('#include "vk_struct_validate_helper.h"') |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1842 | header_txt.append('#include "vk_layer_table.h"') |
| 1843 | header_txt.append('#include "vk_layer_logging.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1844 | header_txt.append('') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1845 | header_txt.append('') |
| 1846 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
| 1847 | header_txt.append('') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1848 | header_txt.append('using namespace std;') |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1849 | for ty in self.thread_check_dispatchable_objects: |
| 1850 | header_txt.append('static unordered_map<%s, loader_platform_thread_id> %sObjectsInUse;' % (ty, ty)) |
| 1851 | for ty in self.thread_check_nondispatchable_objects: |
Chia-I Wu | e2fc552 | 2015-10-26 20:04:44 +0800 | [diff] [blame] | 1852 | header_txt.append('static unordered_map<%s, loader_platform_thread_id> %sObjectsInUse;' % (ty, ty)) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1853 | header_txt.append('static int threadingLockInitialized = 0;') |
| 1854 | header_txt.append('static loader_platform_thread_mutex threadingLock;') |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1855 | header_txt.append('static loader_platform_thread_cond threadingCond;') |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1856 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1857 | for ty in self.thread_check_dispatchable_objects + self.thread_check_nondispatchable_objects: |
| 1858 | header_txt.append(self.generate_useObject(ty)) |
| 1859 | header_txt.append(self.generate_finishUsingObject(ty)) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1860 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1861 | return "\n".join(header_txt) |
| 1862 | |
| 1863 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 7415d5a | 2015-12-09 15:48:16 -0700 | [diff] [blame] | 1864 | if proto.name in [ 'CreateDebugReportCallbackEXT' ]: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1865 | # use default version |
| 1866 | return None |
| 1867 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
| 1868 | ret_val = '' |
| 1869 | stmt = '' |
| 1870 | funcs = [] |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1871 | table = 'device' |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1872 | if proto.ret != "void": |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1873 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1874 | stmt = " return result;\n" |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1875 | if proto_is_global(proto): |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1876 | table = 'instance' |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1877 | |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1878 | # Memory range calls are special in needed thread checking within structs |
| 1879 | if proto.name in ["FlushMappedMemoryRanges","InvalidateMappedMemoryRanges"]: |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1880 | funcs.append('%s' % self.lineinfo.get()) |
| 1881 | funcs.append('%s%s\n' % (qual, decl) + |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1882 | '{\n' |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1883 | ' for (uint32_t i=0; i<memoryRangeCount; i++) {\n' |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1884 | ' useVkDeviceMemory((const void *) %s, pMemoryRanges[i].memory);\n' % proto.params[0].name + |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1885 | ' }\n' |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1886 | ' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(threading_%s_table_map, %s);\n' % (table, proto.params[0].name) + |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1887 | ' %s pDeviceTable->%s;\n' % (ret_val, proto.c_call()) + |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1888 | ' for (uint32_t i=0; i<memoryRangeCount; i++) {\n' |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1889 | ' finishUsingVkDeviceMemory(pMemoryRanges[i].memory);\n' |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1890 | ' }\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1891 | '%s' % (stmt) + |
| 1892 | '}') |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1893 | return "\n".join(funcs) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1894 | # All functions that do a Get are thread safe |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1895 | if 'Get' in proto.name: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1896 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1897 | # All WSI functions are thread safe |
Ian Elliott | 7e40db9 | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 1898 | if 'KHR' in proto.name: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1899 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1900 | # Initialize in early calls |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1901 | if proto.name == "CreateDevice": |
| 1902 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1903 | funcs.append('%s%s\n' % (qual, decl) + |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1904 | '{\n' |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1905 | ' VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);\n' |
| 1906 | ' PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;\n' |
| 1907 | ' PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;\n' |
| 1908 | ' PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");\n' |
| 1909 | ' if (fpCreateDevice == NULL) {\n' |
| 1910 | ' return VK_ERROR_INITIALIZATION_FAILED;\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1911 | ' }\n' |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1912 | ' // Advance the link info for the next element on the chain\n' |
| 1913 | ' chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;\n' |
| 1914 | ' VkResult result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);\n' |
| 1915 | ' if (result != VK_SUCCESS) {\n' |
| 1916 | ' return result;\n' |
| 1917 | ' }\n' |
| 1918 | ' layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);\n' |
| 1919 | ' layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);\n' |
| 1920 | ' initDeviceTable(*pDevice, fpGetDeviceProcAddr, threading_device_table_map);\n' |
| 1921 | ' my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);\n' |
| 1922 | ' return result;\n' |
| 1923 | '}\n') |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1924 | return "\n".join(funcs) |
| 1925 | elif proto.params[0].ty == "VkPhysicalDevice": |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1926 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1927 | # Functions changing command buffers need thread safe use of first parameter |
Chia-I Wu | 3432a0c | 2015-10-27 18:04:07 +0800 | [diff] [blame] | 1928 | if proto.params[0].ty == "VkCommandBuffer": |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1929 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1930 | funcs.append('%s%s\n' % (qual, decl) + |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1931 | '{\n' |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1932 | ' use%s((const void *) %s, %s);\n' % (proto.params[0].ty, proto.params[0].name, proto.params[0].name) + |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1933 | ' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(threading_%s_table_map, %s);\n' % (table, proto.params[0].name) + |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1934 | ' %spDeviceTable->%s;\n' % (ret_val, proto.c_call()) + |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 1935 | ' finishUsing%s(%s);\n' % (proto.params[0].ty, proto.params[0].name) + |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1936 | '%s' % stmt + |
| 1937 | '}') |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1938 | return "\n".join(funcs) |
| 1939 | # Non-Cmd functions that do a Wait are thread safe |
| 1940 | if 'Wait' in proto.name: |
| 1941 | return None |
| 1942 | # Watch use of certain types of objects passed as any parameter |
| 1943 | checked_params = [] |
| 1944 | for param in proto.params: |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1945 | if param.ty in self.thread_check_dispatchable_objects or param.ty in self.thread_check_nondispatchable_objects: |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1946 | checked_params.append(param) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1947 | if proto.name == "DestroyDevice": |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1948 | funcs.append('%s%s\n' % (qual, decl) + |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1949 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1950 | ' dispatch_key key = get_dispatch_key(device);\n' |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1951 | ' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(threading_%s_table_map, %s);\n' % (table, proto.params[0].name) + |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1952 | ' %spDeviceTable->%s;\n' % (ret_val, proto.c_call()) + |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1953 | ' threading_device_table_map.erase(key);\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1954 | '}\n') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1955 | return "\n".join(funcs); |
| 1956 | elif proto.name == "DestroyInstance": |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1957 | funcs.append('%s%s\n' % (qual, decl) + |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1958 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1959 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1960 | ' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(threading_instance_table_map, %s);\n' % proto.params[0].name + |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1961 | ' %spInstanceTable->%s;\n' % (ret_val, proto.c_call()) + |
Courtney Goeltzenleuchter | 951af52 | 2016-01-15 11:58:33 -0700 | [diff] [blame] | 1962 | ' destroy_dispatch_table(threading_instance_table_map, key);\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1963 | '\n' |
| 1964 | ' // Clean up logging callback, if any\n' |
| 1965 | ' layer_data *my_data = get_my_data_ptr(key, layer_data_map);\n' |
| 1966 | ' if (my_data->logging_callback) {\n' |
Courtney Goeltzenleuchter | 05854bf | 2015-11-30 12:13:14 -0700 | [diff] [blame] | 1967 | ' layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback, pAllocator);\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1968 | ' }\n' |
| 1969 | '\n' |
| 1970 | ' layer_debug_report_destroy_instance(my_data->report_data);\n' |
| 1971 | ' layer_data_map.erase(pInstanceTable);\n' |
| 1972 | '\n' |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 1973 | ' threading_instance_table_map.erase(key);\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 1974 | '}\n') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1975 | return "\n".join(funcs); |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1976 | elif proto.name == "CreateInstance": |
| 1977 | funcs.append('%s%s\n' |
| 1978 | '{\n' |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1979 | ' VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);\n' |
| 1980 | ' PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;\n' |
| 1981 | ' PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");\n' |
| 1982 | ' if (fpCreateInstance == NULL) {\n' |
| 1983 | ' return VK_ERROR_INITIALIZATION_FAILED;\n' |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1984 | ' }\n' |
Courtney Goeltzenleuchter | 00150eb | 2016-01-08 12:18:43 -0700 | [diff] [blame] | 1985 | ' // Advance the link info for the next element on the chain\n' |
| 1986 | ' chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;\n' |
| 1987 | ' VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);\n' |
| 1988 | ' if (result != VK_SUCCESS) {\n' |
| 1989 | ' return result;\n' |
| 1990 | ' }\n' |
| 1991 | ' VkLayerInstanceDispatchTable *pTable = initInstanceTable(*pInstance, fpGetInstanceProcAddr, threading_instance_table_map);\n' |
| 1992 | ' layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);\n' |
| 1993 | ' my_data->report_data = debug_report_create_instance(\n' |
| 1994 | ' pTable,\n' |
| 1995 | ' *pInstance,\n' |
| 1996 | ' pCreateInfo->enabledExtensionCount,\n' |
| 1997 | ' pCreateInfo->ppEnabledExtensionNames);\n' |
| 1998 | ' init_threading(my_data, pAllocator);\n' |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1999 | ' return result;\n' |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 2000 | '}\n' % (qual, decl)) |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 2001 | return "\n".join(funcs); |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 2002 | if len(checked_params) == 0: |
| 2003 | return None |
| 2004 | # Surround call with useObject and finishUsingObject for each checked_param |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 2005 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 2006 | funcs.append('%s%s' % (qual, decl)) |
| 2007 | funcs.append('{') |
| 2008 | for param in checked_params: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 2009 | funcs.append(' use%s((const void *) %s, %s);' % (param.ty, proto.params[0].name, param.name)) |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 2010 | funcs.append(' VkLayerDispatchTable *pDeviceTable = get_dispatch_table(threading_%s_table_map, %s);' % (table, proto.params[0].name)); |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 2011 | funcs.append(' %spDeviceTable->%s;' % (ret_val, proto.c_call())) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 2012 | for param in checked_params: |
Michael Lentine | 13803dc | 2015-11-04 14:35:12 -0800 | [diff] [blame] | 2013 | funcs.append(' finishUsing%s(%s);' % (param.ty, param.name)) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 2014 | funcs.append('%s' |
| 2015 | '}' % stmt) |
| 2016 | return "\n".join(funcs) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 2017 | |
| 2018 | def generate_body(self): |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 2019 | self.layer_name = "threading" |
Mike Stroyan | 313f7e6 | 2015-08-10 16:42:53 -0600 | [diff] [blame] | 2020 | body = [self._generate_new_layer_initialization(True, lockname='threading', condname='threading'), |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 2021 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | 1727417 | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 2022 | self._generate_layer_gpa_function(extensions=[], |
Jon Ashburn | 3dc3938 | 2015-09-17 10:00:32 -0600 | [diff] [blame] | 2023 | instance_extensions=[('msg_callback_get_proc_addr', [])]), |
Courtney Goeltzenleuchter | 1727417 | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 2024 | self._gen_create_msg_callback(), |
Courtney Goeltzenleuchter | f0de724 | 2015-12-01 14:10:55 -0700 | [diff] [blame] | 2025 | self._gen_destroy_msg_callback(), |
| 2026 | self._gen_debug_report_msg()] |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 2027 | return "\n\n".join(body) |
| 2028 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 2029 | def main(): |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 2030 | wsi = { |
| 2031 | "Win32", |
| 2032 | "Android", |
| 2033 | "Xcb", |
| 2034 | "Xlib", |
| 2035 | "Wayland", |
| 2036 | "Mir", |
| 2037 | } |
| 2038 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 2039 | subcommands = { |
Mark Lobodzinski | 0d054fe | 2015-12-30 08:16:12 -0700 | [diff] [blame] | 2040 | "object_tracker" : ObjectTrackerSubcommand, |
| 2041 | "threading" : ThreadingSubcommand, |
Tobin Ehlis | d34a4c5 | 2015-12-08 10:50:10 -0700 | [diff] [blame] | 2042 | "unique_objects" : UniqueObjectsSubcommand, |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 2043 | } |
| 2044 | |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 2045 | 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]): |
| 2046 | print("Usage: %s <wsi> <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 2047 | print |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 2048 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 2049 | exit(1) |
| 2050 | |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 2051 | hfp = vk_helper.HeaderFileParser(sys.argv[3]) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 2052 | hfp.parse() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2053 | vk_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 2054 | vk_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 2055 | vk_helper.struct_dict = hfp.get_struct_dict() |
| 2056 | vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 2057 | vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 2058 | vk_helper.types_dict = hfp.get_types_dict() |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 2059 | |
Mun, Gwan-gyeong | bd4dd59 | 2016-02-22 09:43:09 +0900 | [diff] [blame] | 2060 | subcmd = subcommands[sys.argv[2]](sys.argv[3:]) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 2061 | subcmd.run() |
| 2062 | |
| 2063 | if __name__ == "__main__": |
| 2064 | main() |