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