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