Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | # VK |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 4 | # |
| 5 | # Copyright (C) 2014 LunarG, Inc. |
| 6 | # |
| 7 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | # copy of this software and associated documentation files (the "Software"), |
| 9 | # to deal in the Software without restriction, including without limitation |
| 10 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | # and/or sell copies of the Software, and to permit persons to whom the |
| 12 | # Software is furnished to do so, subject to the following conditions: |
| 13 | # |
| 14 | # The above copyright notice and this permission notice shall be included |
| 15 | # in all copies or substantial portions of the Software. |
| 16 | # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | # DEALINGS IN THE SOFTWARE. |
| 24 | # |
| 25 | # Authors: |
| 26 | # Chia-I Wu <olv@lunarg.com> |
| 27 | |
| 28 | import sys |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 29 | import os |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 30 | import re |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 31 | |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 32 | import vulkan |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 33 | import vk_helper |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 34 | from source_line_info import sourcelineinfo |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 35 | |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 36 | def proto_is_global(proto): |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 37 | if proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice" or proto.name == "CreateInstance" or proto.name == "GetGlobalLayerProperties" or proto.name == "GetGlobalExtensionProperties" or proto.name == "GetPhysicalDeviceLayerProperties" or proto.name == "GetPhysicalDeviceExtensionProperties": |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 38 | return True |
| 39 | else: |
| 40 | return False |
| 41 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 42 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 43 | return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ |
| 44 | " return NULL;" % ((name,) * 3) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 45 | |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 46 | def ucc_to_U_C_C(CamelCase): |
| 47 | temp = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', CamelCase) |
| 48 | return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).upper() |
| 49 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 50 | class Subcommand(object): |
| 51 | def __init__(self, argv): |
| 52 | self.argv = argv |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 53 | self.headers = vulkan.headers |
| 54 | self.protos = vulkan.protos |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 55 | self.no_addr = False |
| 56 | self.layer_name = "" |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 57 | self.lineinfo = sourcelineinfo() |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 58 | |
| 59 | def run(self): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 60 | print(self.generate()) |
| 61 | |
| 62 | def generate(self): |
| 63 | copyright = self.generate_copyright() |
| 64 | header = self.generate_header() |
| 65 | body = self.generate_body() |
| 66 | footer = self.generate_footer() |
| 67 | |
| 68 | contents = [] |
| 69 | if copyright: |
| 70 | contents.append(copyright) |
| 71 | if header: |
| 72 | contents.append(header) |
| 73 | if body: |
| 74 | contents.append(body) |
| 75 | if footer: |
| 76 | contents.append(footer) |
| 77 | |
| 78 | return "\n\n".join(contents) |
| 79 | |
| 80 | def generate_copyright(self): |
| 81 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 82 | |
| 83 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 84 | * Vulkan |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 85 | * |
| 86 | * Copyright (C) 2014 LunarG, Inc. |
| 87 | * |
| 88 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 89 | * copy of this software and associated documentation files (the "Software"), |
| 90 | * to deal in the Software without restriction, including without limitation |
| 91 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 92 | * and/or sell copies of the Software, and to permit persons to whom the |
| 93 | * Software is furnished to do so, subject to the following conditions: |
| 94 | * |
| 95 | * The above copyright notice and this permission notice shall be included |
| 96 | * in all copies or substantial portions of the Software. |
| 97 | * |
| 98 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 99 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 100 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 101 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 102 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 103 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 104 | * DEALINGS IN THE SOFTWARE. |
| 105 | */""" |
| 106 | |
| 107 | def generate_header(self): |
| 108 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 109 | |
| 110 | def generate_body(self): |
| 111 | pass |
| 112 | |
| 113 | def generate_footer(self): |
| 114 | pass |
| 115 | |
| 116 | # Return set of printf '%' qualifier and input to that qualifier |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 117 | def _get_printf_params(self, vk_type, name, output_param, cpp=False): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 118 | # TODO : Need ENUM and STRUCT checks here |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 119 | if vk_helper.is_type(vk_type, 'enum'):#"_TYPE" in vk_type: # TODO : This should be generic ENUM check |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 120 | return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | if "char*" == vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 122 | return ("%s", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 123 | if "uint64" in vk_type: |
| 124 | if '*' in vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 125 | return ("%lu", "*%s" % name) |
| 126 | return ("%lu", name) |
Tobin Ehlis | 0b9c195 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 127 | if vk_type.strip('*') in vulkan.object_non_dispatch_list: |
| 128 | if '*' in vk_type: |
| 129 | return ("%lu", "%s->handle" % name) |
| 130 | return ("%lu", "%s.handle" % name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 131 | if "size" in vk_type: |
| 132 | if '*' in vk_type: |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 133 | return ("%zu", "*%s" % name) |
| 134 | return ("%zu", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 135 | if "float" in vk_type: |
| 136 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 137 | if cpp: |
| 138 | return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 139 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 140 | return ("%f", name) |
Courtney Goeltzenleuchter | 1f41f54 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 141 | if "bool" in vk_type.lower() or 'xcb_randr_crtc_t' in vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 142 | return ("%u", name) |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 143 | if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 144 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 145 | if cpp: |
| 146 | return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 147 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 148 | if '*' in vk_type: |
Tobin Ehlis | 1336c8d | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 149 | if 'pUserData' == name: |
| 150 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Tobin Ehlis | a74d53a | 2015-04-17 13:26:33 -0600 | [diff] [blame] | 151 | if 'const' in vk_type.lower(): |
| 152 | return ("%p", "(void*)(%s)" % name) |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 153 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 154 | return ("%i", name) |
Tobin Ehlis | 0a1e06d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 155 | # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 156 | if "VkFormat" == vk_type: |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 157 | if cpp: |
| 158 | return ("%p", "&%s" % name) |
Courtney Goeltzenleuchter | ab36aa6 | 2015-07-12 12:40:29 -0600 | [diff] [blame] | 159 | return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_CHANNEL_FORMAT(%s.channelFormat), string_VK_FORMAT_NUM(%s.numericFormat)" % (name, name)) |
Tobin Ehlis | a554dc3 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 160 | if output_param: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 161 | return ("%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 162 | if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type: |
Courtney Goeltzenleuchter | 9a1ded8 | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 163 | return ("%p", "(void*)(&%s)" % name) |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 164 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 165 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 166 | def _gen_create_msg_callback(self): |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 167 | r_body = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 168 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 169 | r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(VkInstance instance, VkFlags msgFlags, const PFN_vkDbgMsgCallback pfnMsgCallback, void* pUserData, VkDbgMsgCallback* pMsgCallback)') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 170 | r_body.append('{') |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 171 | # Switch to this code section for the new per-instance storage and debug callbacks |
| 172 | if self.layer_name == 'ObjectTracker': |
| 173 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
| 174 | r_body.append(' VkResult result = pInstanceTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
| 175 | r_body.append(' if (VK_SUCCESS == result) {') |
| 176 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
| 177 | r_body.append(' result = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
| 178 | r_body.append(' }') |
| 179 | r_body.append(' return result;') |
| 180 | else: |
| 181 | # Old version of callbacks for compatibility |
| 182 | r_body.append(' return layer_create_msg_callback(instance, instance_dispatch_table(instance), msgFlags, pfnMsgCallback, pUserData, pMsgCallback);') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 183 | r_body.append('}') |
| 184 | return "\n".join(r_body) |
| 185 | |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 186 | def _gen_destroy_msg_callback(self): |
| 187 | r_body = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 188 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 189 | r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(VkInstance instance, VkDbgMsgCallback msgCallback)') |
| 190 | r_body.append('{') |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 191 | # Switch to this code section for the new per-instance storage and debug callbacks |
| 192 | if self.layer_name == 'ObjectTracker': |
| 193 | r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name ) |
| 194 | r_body.append(' VkResult result = pInstanceTable->DbgDestroyMsgCallback(instance, msgCallback);') |
| 195 | r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);') |
| 196 | r_body.append(' layer_destroy_msg_callback(my_data->report_data, msgCallback);') |
| 197 | r_body.append(' return result;') |
| 198 | else: |
| 199 | # Old version of callbacks for compatibility |
| 200 | r_body.append(' return layer_destroy_msg_callback(instance, instance_dispatch_table(instance), msgCallback);') |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 201 | r_body.append('}') |
| 202 | return "\n".join(r_body) |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 203 | |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 204 | def _gen_layer_get_global_extension_props(self, layer="Generic"): |
| 205 | ggep_body = [] |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 206 | # generated layers do not provide any global extensions |
| 207 | ggep_body.append('%s' % self.lineinfo.get()) |
| 208 | |
| 209 | ggep_body.append('') |
| 210 | ggep_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)') |
| 211 | ggep_body.append('{') |
| 212 | ggep_body.append(' return util_GetExtensionProperties(0, NULL, pCount, pProperties);') |
| 213 | ggep_body.append('}') |
| 214 | return "\n".join(ggep_body) |
| 215 | |
| 216 | def _gen_layer_get_global_layer_props(self, layer="Generic"): |
| 217 | ggep_body = [] |
| 218 | if layer == 'Generic': |
| 219 | # Do nothing, extension definition part of generic.h |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 220 | ggep_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 23b5f8d | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 221 | else: |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 222 | ggep_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 79d8d2c | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 223 | ggep_body.append('static const VkLayerProperties globalLayerProps[] = {') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 224 | ggep_body.append(' {') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 225 | ggep_body.append(' "%s",' % layer) |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 226 | ggep_body.append(' VK_API_VERSION, // specVersion') |
| 227 | ggep_body.append(' VK_MAKE_VERSION(0, 1, 0), // implVersion') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 228 | ggep_body.append(' "layer: %s",' % layer) |
| 229 | ggep_body.append(' }') |
| 230 | ggep_body.append('};') |
| 231 | ggep_body.append('') |
| 232 | ggep_body.append('%s' % self.lineinfo.get()) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 233 | ggep_body.append('') |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 234 | ggep_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 235 | ggep_body.append('{') |
Courtney Goeltzenleuchter | 79d8d2c | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 236 | ggep_body.append(' return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 237 | ggep_body.append('}') |
| 238 | return "\n".join(ggep_body) |
| 239 | |
Courtney Goeltzenleuchter | 03f1c8c | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 240 | def _gen_layer_get_physical_device_layer_props(self, layer="Generic"): |
| 241 | gpdlp_body = [] |
| 242 | if layer == 'Generic': |
| 243 | # Do nothing, extension definition part of generic.h |
| 244 | gpdlp_body.append('%s' % self.lineinfo.get()) |
| 245 | else: |
| 246 | gpdlp_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 79d8d2c | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 247 | gpdlp_body.append('static const VkLayerProperties deviceLayerProps[] = {') |
Courtney Goeltzenleuchter | 03f1c8c | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 248 | gpdlp_body.append(' {') |
| 249 | gpdlp_body.append(' "%s",' % layer) |
| 250 | gpdlp_body.append(' VK_API_VERSION,') |
| 251 | gpdlp_body.append(' VK_MAKE_VERSION(0, 1, 0),') |
| 252 | gpdlp_body.append(' "layer: %s",' % layer) |
| 253 | gpdlp_body.append(' }') |
| 254 | gpdlp_body.append('};') |
| 255 | gpdlp_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties* pProperties)') |
| 256 | gpdlp_body.append('{') |
Courtney Goeltzenleuchter | 79d8d2c | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 257 | gpdlp_body.append(' return util_GetLayerProperties(ARRAY_SIZE(deviceLayerProps), deviceLayerProps, pCount, pProperties);') |
Courtney Goeltzenleuchter | 03f1c8c | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 258 | gpdlp_body.append('}') |
| 259 | gpdlp_body.append('') |
| 260 | return "\n".join(gpdlp_body) |
| 261 | |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 262 | def _generate_dispatch_entrypoints(self, qual=""): |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 263 | if qual: |
| 264 | qual += " " |
| 265 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 266 | funcs = [] |
| 267 | intercepted = [] |
| 268 | for proto in self.protos: |
Jon Ashburn | 1245cec | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 269 | if proto.name == "GetDeviceProcAddr" or proto.name == "GetInstanceProcAddr": |
Jon Ashburn | 4f2575f | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 270 | continue |
Mike Stroyan | 88f0ecf | 2015-04-08 10:27:43 -0600 | [diff] [blame] | 271 | else: |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 272 | intercept = self.generate_intercept(proto, qual) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 273 | if intercept is None: |
| 274 | # fill in default intercept for certain entrypoints |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 275 | if 'DbgCreateMsgCallback' == proto.name: |
| 276 | intercept = self._gen_layer_dbg_create_msg_callback() |
| 277 | elif 'DbgDestroyMsgCallback' == proto.name: |
| 278 | intercept = self._gen_layer_dbg_destroy_msg_callback() |
| 279 | elif 'CreateDevice' == proto.name: |
| 280 | funcs.append('/* CreateDevice HERE */') |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 281 | elif 'GetGlobalExtensionProperties' == proto.name: |
| 282 | intercept = self._gen_layer_get_global_extension_props(self.layer_name) |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 283 | elif 'GetGlobalLayerProperties' == proto.name: |
| 284 | intercept = self._gen_layer_get_global_layer_props(self.layer_name) |
| 285 | elif 'GetPhysicalDeviceLayerProperties' == proto.name: |
| 286 | intercept = self._gen_layer_get_physical_device_layer_props(self.layer_name) |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 287 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 288 | if intercept is not None: |
| 289 | funcs.append(intercept) |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 290 | if not "WSI" in proto.name: |
| 291 | intercepted.append(proto) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 292 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 293 | prefix="vk" |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 294 | lookups = [] |
| 295 | for proto in intercepted: |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 296 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 297 | lookups.append(" return (PFN_vkVoidFunction) %s%s;" % |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 298 | (prefix, proto.name)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 299 | |
| 300 | # add customized layer_intercept_proc |
| 301 | body = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 302 | body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 303 | body.append("static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)") |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 304 | body.append("{") |
| 305 | body.append(generate_get_proc_addr_check("name")) |
| 306 | body.append("") |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 307 | body.append(" name += 2;") |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 308 | body.append(" %s" % "\n ".join(lookups)) |
| 309 | body.append("") |
| 310 | body.append(" return NULL;") |
| 311 | body.append("}") |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 312 | # add layer_intercept_instance_proc |
| 313 | lookups = [] |
| 314 | for proto in self.protos: |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 315 | if not proto_is_global(proto): |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 316 | continue |
| 317 | |
| 318 | if not proto in intercepted: |
| 319 | continue |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 320 | if proto.name == "CreateDevice": |
| 321 | continue |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 322 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 323 | lookups.append(" return (PFN_vkVoidFunction) %s%s;" % (prefix, proto.name)) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 324 | |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 325 | body.append("static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)") |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 326 | body.append("{") |
| 327 | body.append(generate_get_proc_addr_check("name")) |
| 328 | body.append("") |
| 329 | body.append(" name += 2;") |
| 330 | body.append(" %s" % "\n ".join(lookups)) |
| 331 | body.append("") |
| 332 | body.append(" return NULL;") |
| 333 | body.append("}") |
| 334 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 335 | funcs.append("\n".join(body)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 336 | return "\n\n".join(funcs) |
| 337 | |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 338 | def _generate_extensions(self): |
| 339 | exts = [] |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 340 | exts.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 341 | exts.append(self._gen_create_msg_callback()) |
| 342 | exts.append(self._gen_destroy_msg_callback()) |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 343 | return "\n".join(exts) |
| 344 | |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 345 | def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]): |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 346 | func_body = [] |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 347 | # |
Courtney Goeltzenleuchter | 03f1c8c | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 348 | # New style of GPA Functions for the new layer_data/layer_logging changes |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 349 | # |
| 350 | if self.layer_name == 'ObjectTracker': |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 351 | func_body.append("VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 352 | "{\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 353 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 354 | " if (device == VK_NULL_HANDLE) {\n" |
| 355 | " return NULL;\n" |
| 356 | " }\n" |
| 357 | " /* loader uses this to force layer initialization; device object is wrapped */\n" |
| 358 | " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n" |
| 359 | " initDeviceTable(%s_device_table_map, (const VkBaseLayerObject *) device);\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 360 | " return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 361 | " }\n\n" |
| 362 | " addr = layer_intercept_proc(funcName);\n" |
| 363 | " if (addr)\n" |
| 364 | " return addr;" % self.layer_name) |
| 365 | if 0 != len(extensions): |
Courtney Goeltzenleuchter | 03f1c8c | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 366 | func_body.append('%s' % self.lineinfo.get()) |
| 367 | func_body.append(' layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);') |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 368 | for (ext_enable, ext_list) in extensions: |
| 369 | extra_space = "" |
| 370 | if 0 != len(ext_enable): |
Courtney Goeltzenleuchter | 03f1c8c | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 371 | func_body.append(' if (my_device_data->%s) {' % ext_enable) |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 372 | extra_space = " " |
| 373 | for ext_name in ext_list: |
| 374 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 375 | ' %sreturn reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, extra_space, ext_name)) |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 376 | if 0 != len(ext_enable): |
| 377 | func_body.append(' }\n') |
| 378 | func_body.append("\n if (get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr == NULL)\n" |
| 379 | " return NULL;\n" |
| 380 | " return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n" |
| 381 | "}\n" % (self.layer_name, self.layer_name)) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 382 | func_body.append("VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 383 | "{\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 384 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 385 | " if (instance == VK_NULL_HANDLE) {\n" |
| 386 | " return NULL;\n" |
| 387 | " }\n" |
| 388 | " /* loader uses this to force layer initialization; instance object is wrapped */\n" |
| 389 | " if (!strcmp(\"vkGetInstanceProcAddr\", funcName)) {\n" |
| 390 | " initInstanceTable(%s_instance_table_map, (const VkBaseLayerObject *) instance);\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 391 | " return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 392 | " }\n\n" |
| 393 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 394 | " if (addr) {\n" |
| 395 | " return addr;" |
| 396 | " }\n" % self.layer_name) |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 397 | |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 398 | if 0 != len(instance_extensions): |
| 399 | for ext_name in instance_extensions: |
| 400 | func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n" |
| 401 | " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n" |
| 402 | " if (addr) {\n" |
| 403 | " return addr;\n" |
| 404 | " }\n" |
| 405 | " if (get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr == NULL) {\n" |
| 406 | " return NULL;\n" |
| 407 | " }\n" |
| 408 | " return get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);\n" |
| 409 | "}\n" % (self.layer_name, self.layer_name)) |
| 410 | return "\n".join(func_body) |
| 411 | else: |
| 412 | # |
| 413 | # TODO:: Old-style GPA Functions -- no local storage, no new logging mechanism. Left for compatibility. |
| 414 | # |
| 415 | func_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 416 | func_body.append("VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 417 | "{\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 418 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 419 | " if (device == VK_NULL_HANDLE) {\n" |
| 420 | " return NULL;\n" |
| 421 | " }\n" |
| 422 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
| 423 | " /* loader uses this to force layer initialization; device object is wrapped */\n" |
| 424 | " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n" |
| 425 | " initDeviceTable((const VkBaseLayerObject *) device);\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 426 | " return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 427 | " }\n\n" |
| 428 | " addr = layer_intercept_proc(funcName);\n" |
| 429 | " if (addr)\n" |
| 430 | " return addr;" % self.layer_name) |
| 431 | func_body.append('') |
| 432 | func_body.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 433 | if 0 != len(extensions): |
| 434 | extra_space = "" |
| 435 | for (ext_enable, ext_list) in extensions: |
| 436 | if 0 != len(ext_enable): |
| 437 | func_body.append(' if (deviceExtMap.size() == 0 || deviceExtMap[pDisp].%s)' % ext_enable) |
| 438 | func_body.append(' {') |
| 439 | extra_space = " " |
| 440 | for ext_name in ext_list: |
| 441 | func_body.append(' %sif (!strcmp("%s", funcName))\n' |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 442 | ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name)) |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 443 | if 0 != len(ext_enable): |
| 444 | func_body.append(' }') |
| 445 | func_body.append('%s' % self.lineinfo.get()) |
| 446 | func_body.append(" {\n" |
| 447 | " if (pDisp->GetDeviceProcAddr == NULL)\n" |
| 448 | " return NULL;\n" |
| 449 | " return pDisp->GetDeviceProcAddr(device, funcName);\n" |
| 450 | " }\n" |
| 451 | "}\n") |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 452 | func_body.append("VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 453 | "{\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 454 | " PFN_vkVoidFunction addr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 455 | " if (instance == VK_NULL_HANDLE) {\n" |
| 456 | " return NULL;\n" |
| 457 | " }\n" |
| 458 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
| 459 | " /* loader uses this to force layer initialization; instance object is wrapped */\n" |
| 460 | " if (!strcmp(\"vkGetInstanceProcAddr\", funcName)) {\n" |
| 461 | " initInstanceTable((const VkBaseLayerObject *) instance);\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 462 | " return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 463 | " }\n\n" |
| 464 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 465 | " if (addr)\n" |
| 466 | " return addr;" % self.layer_name) |
| 467 | if 0 != len(instance_extensions): |
| 468 | for ext_name in instance_extensions: |
| 469 | func_body.append(" {\n" |
Courtney Goeltzenleuchter | a4c8c71 | 2015-07-12 14:35:22 -0600 | [diff] [blame] | 470 | " PFN_vkVoidFunction fptr;\n" |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 471 | " fptr = %s(funcName);\n" |
| 472 | " if (fptr) return fptr;\n" |
| 473 | " }\n" % ext_name) |
| 474 | func_body.append(" VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);\n" |
| 475 | " if (pTable->GetInstanceProcAddr == NULL)\n" |
| 476 | " return NULL;\n" |
| 477 | " return pTable->GetInstanceProcAddr(instance, funcName);\n" |
| 478 | "}\n") |
| 479 | return "\n".join(func_body) |
Jon Ashburn | 79b78ac | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 480 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 481 | |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 482 | def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 483 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 484 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 485 | func_body.append('static void init%s(void)\n' |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 486 | '{\n' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 487 | if init_opts: |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 488 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 489 | func_body.append(' const char *strOpt;') |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 490 | func_body.append(' // initialize %s options' % self.layer_name) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 491 | func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportFlags);' % self.layer_name) |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 492 | func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 493 | func_body.append('') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 494 | func_body.append(' if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)') |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 495 | func_body.append(' {') |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 496 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 497 | func_body.append(' if (strOpt)') |
| 498 | func_body.append(' {') |
| 499 | func_body.append(' g_logFile = fopen(strOpt, "w");') |
| 500 | func_body.append(' }') |
| 501 | func_body.append(' if (g_logFile == NULL)') |
| 502 | func_body.append(' g_logFile = stdout;') |
| 503 | func_body.append(' }') |
| 504 | func_body.append('') |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 505 | if lockname is not None: |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 506 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 507 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 508 | func_body.append(" {") |
| 509 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 510 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 511 | if condname is not None: |
| 512 | func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname) |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 513 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 514 | func_body.append(" }") |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 515 | func_body.append("}\n") |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 516 | func_body.append('') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 517 | return "\n".join(func_body) |
| 518 | |
| 519 | class LayerFuncsSubcommand(Subcommand): |
| 520 | def generate_header(self): |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 521 | return '#include <vk_layer.h>\n#include "loader.h"' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 522 | |
| 523 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 524 | return self._generate_dispatch_entrypoints("static") |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 525 | |
| 526 | class LayerDispatchSubcommand(Subcommand): |
| 527 | def generate_header(self): |
| 528 | return '#include "layer_wrappers.h"' |
| 529 | |
| 530 | def generate_body(self): |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 531 | return self._generate_layer_initialization() |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 532 | |
| 533 | class GenericLayerSubcommand(Subcommand): |
| 534 | def generate_header(self): |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 535 | gen_header = [] |
Courtney Goeltzenleuchter | 79d8d2c | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 536 | gen_header.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 537 | gen_header.append('#include <stdio.h>') |
| 538 | gen_header.append('#include <stdlib.h>') |
| 539 | gen_header.append('#include <string.h>') |
| 540 | gen_header.append('#include <unordered_map>') |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 541 | gen_header.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 542 | gen_header.append('#include "vk_layer.h"') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 543 | gen_header.append('//The following is #included again to catch certain OS-specific functions being used:') |
| 544 | gen_header.append('') |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 545 | gen_header.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 546 | gen_header.append('#include "vk_layer_config.h"') |
| 547 | gen_header.append('#include "vk_layer_msg.h"') |
| 548 | gen_header.append('#include "vk_layer_table.h"') |
Courtney Goeltzenleuchter | 03f1c8c | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 549 | gen_header.append('#include "vk_layer_extension_utils.h"') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 550 | gen_header.append('') |
Courtney Goeltzenleuchter | 79d8d2c | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 551 | gen_header.append('#include "generic.h"') |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 552 | gen_header.append('') |
Tobin Ehlis | 0b9c195 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 553 | gen_header.append('%s' % self.lineinfo.get()) |
| 554 | gen_header.append('#define LAYER_EXT_ARRAY_SIZE 1') |
| 555 | gen_header.append('#define LAYER_DEV_EXT_ARRAY_SIZE 1') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 556 | gen_header.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 557 | gen_header.append('struct devExts {') |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 558 | gen_header.append(' bool wsi_enabled;') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 559 | gen_header.append('};') |
| 560 | gen_header.append('static std::unordered_map<void *, struct devExts> deviceExtMap;') |
| 561 | gen_header.append('') |
| 562 | gen_header.append('static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)') |
| 563 | gen_header.append('{') |
Tony Barbour | 29b1206 | 2015-07-13 13:37:24 -0600 | [diff] [blame] | 564 | gen_header.append(' uint32_t i;') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 565 | gen_header.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 566 | gen_header.append(' deviceExtMap[pDisp].wsi_enabled = false;') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 567 | gen_header.append(' for (i = 0; i < pCreateInfo->extensionCount; i++) {') |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 568 | gen_header.append(' if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_WSI_SWAPCHAIN_EXTENSION_NAME) == 0)') |
| 569 | gen_header.append(' deviceExtMap[pDisp].wsi_enabled = true;') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 570 | gen_header.append('') |
| 571 | gen_header.append(' }') |
| 572 | gen_header.append('}') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 573 | gen_header.append('') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 574 | return "\n".join(gen_header) |
Tobin Ehlis | 65d94ad | 2015-07-07 11:02:44 -0600 | [diff] [blame] | 575 | |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 576 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 577 | if proto.name in [ 'GetGlobalLayerProperties', 'GetGlobalExtensionProperties', 'GetPhysicalDeviceLayerProperties', 'GetPhysicalDeviceExtensionProperties' ]: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 578 | # use default version |
| 579 | return None |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 580 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 581 | ret_val = '' |
| 582 | stmt = '' |
| 583 | funcs = [] |
Jon Ashburn | 52c1d73 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 584 | table = '' |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 585 | if proto_is_global(proto): |
Jon Ashburn | 52c1d73 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 586 | table = 'Instance' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 587 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 588 | funcs.append('%s' % self.lineinfo.get()) |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 589 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 590 | stmt = " return result;\n" |
Jon Ashburn | 7cdb8c3 | 2015-05-22 12:01:50 -0600 | [diff] [blame] | 591 | if proto.name == "CreateDevice": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 592 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 593 | funcs.append('%s%s\n' |
| 594 | '{\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 595 | ' char str[1024];\n' |
| 596 | ' sprintf(str, "At start of layered %s\\n");\n' |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 597 | ' layerCbMsg(VK_DBG_REPORT_INFO_BIT,VK_OBJECT_TYPE_PHYSICAL_DEVICE, (uint64_t)physicalDevice, 0, 0, (char *) "GENERIC", (char *) str);\n' |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 598 | ' %sdevice_dispatch_table(*pDevice)->%s;\n' |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 599 | ' if (result == VK_SUCCESS) {\n' |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 600 | ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->ppEnabledExtensionNames);\n' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 601 | ' createDeviceRegisterExtensions(pCreateInfo, *pDevice);\n' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 602 | ' }\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 603 | ' sprintf(str, "Completed layered %s\\n");\n' |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 604 | ' layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, (uint64_t)physicalDevice, 0, 0, (char *) "GENERIC", (char *) str);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 605 | ' fflush(stdout);\n' |
| 606 | ' %s' |
| 607 | '}' % (qual, decl, proto.name, ret_val, proto.c_call(), proto.name, stmt)) |
| 608 | elif proto.name == "DestroyDevice": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 609 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 610 | funcs.append('%s%s\n' |
| 611 | '{\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 612 | ' dispatch_key key = get_dispatch_key(device);\n' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 613 | ' VkLayerDispatchTable *pDisp = device_dispatch_table(device);\n' |
| 614 | ' VkResult res = pDisp->DestroyDevice(device);\n' |
| 615 | ' deviceExtMap.erase(pDisp);\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 616 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 617 | ' return res;\n' |
| 618 | '}\n' % (qual, decl)) |
| 619 | elif proto.name == "DestroyInstance": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 620 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 621 | funcs.append('%s%s\n' |
| 622 | '{\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 623 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 624 | ' VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 625 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 626 | ' return res;\n' |
| 627 | '}\n' % (qual, decl)) |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 628 | else: |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 629 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 630 | # CreateInstance needs to use the second parm instead of the first to set the correct dispatch table |
| 631 | dispatch_param = proto.params[0].name |
| 632 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 633 | table_type = "" |
| 634 | if proto_is_global(proto): |
| 635 | table_type = "instance" |
| 636 | else: |
| 637 | table_type = "device" |
| 638 | if 'CreateInstance' in proto.name: |
| 639 | dispatch_param = '*' + proto.params[1].name |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 640 | funcs.append('%s%s\n' |
| 641 | '{\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 642 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 643 | '%s' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 644 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), stmt)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 645 | return "\n\n".join(funcs) |
| 646 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 647 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 648 | self.layer_name = "Generic" |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 649 | extensions=[('wsi_enabled', |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 650 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
| 651 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI'])] |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 652 | body = [self._generate_layer_initialization(True), |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 653 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 654 | self._gen_create_msg_callback(), |
| 655 | self._gen_destroy_msg_callback(), |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 656 | self._generate_layer_gpa_function(extensions)] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 657 | |
| 658 | return "\n\n".join(body) |
| 659 | |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 660 | class APIDumpSubcommand(Subcommand): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 661 | def generate_header(self): |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 662 | header_txt = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 663 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 664 | header_txt.append('#include <fstream>') |
| 665 | header_txt.append('#include <iostream>') |
| 666 | header_txt.append('#include <string>') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 667 | header_txt.append('#include <string.h>') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 668 | header_txt.append('') |
| 669 | header_txt.append('static std::ofstream fileStream;') |
| 670 | header_txt.append('static std::string fileName = "vk_apidump.txt";') |
| 671 | header_txt.append('std::ostream* outputStream = NULL;') |
| 672 | header_txt.append('void ConfigureOutputStream(bool writeToFile, bool flushAfterWrite)') |
| 673 | header_txt.append('{') |
| 674 | header_txt.append(' if(writeToFile)') |
| 675 | header_txt.append(' {') |
| 676 | header_txt.append(' fileStream.open(fileName);') |
| 677 | header_txt.append(' outputStream = &fileStream;') |
| 678 | header_txt.append(' }') |
| 679 | header_txt.append(' else') |
| 680 | header_txt.append(' {') |
| 681 | header_txt.append(' outputStream = &std::cout;') |
| 682 | header_txt.append(' }') |
| 683 | header_txt.append('') |
| 684 | header_txt.append(' if(flushAfterWrite)') |
| 685 | header_txt.append(' {') |
| 686 | header_txt.append(' outputStream->sync_with_stdio(true);') |
| 687 | header_txt.append(' }') |
| 688 | header_txt.append(' else') |
| 689 | header_txt.append(' {') |
| 690 | header_txt.append(' outputStream->sync_with_stdio(false);') |
| 691 | header_txt.append(' }') |
| 692 | header_txt.append('}') |
| 693 | header_txt.append('') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 694 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 695 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 696 | header_txt.append('#include "vk_layer.h"') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 697 | header_txt.append('#include "vk_struct_string_helper_cpp.h"') |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 698 | header_txt.append('#include "vk_layer_table.h"') |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 699 | header_txt.append('#include "vk_layer_extension_utils.h"') |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 700 | header_txt.append('#include <unordered_map>') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 701 | header_txt.append('') |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 702 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 703 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 704 | header_txt.append('') |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 705 | header_txt.append('static VkBaseLayerObject *pCurObj;') |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 706 | header_txt.append('static bool g_APIDumpDetailed = true;') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 707 | header_txt.append('') |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 708 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 709 | header_txt.append('') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 710 | header_txt.append('static int printLockInitialized = 0;') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 711 | header_txt.append('static loader_platform_thread_mutex printLock;') |
| 712 | header_txt.append('') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 713 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 0b9c195 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 714 | header_txt.append('#define LAYER_EXT_ARRAY_SIZE 1') |
| 715 | header_txt.append('#define LAYER_DEV_EXT_ARRAY_SIZE 1') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 716 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 717 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 718 | header_txt.append('static uint32_t maxTID = 0;') |
| 719 | header_txt.append('// Map actual TID to an index value and return that index') |
| 720 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 721 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 722 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 723 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 724 | header_txt.append(' if (tid == tidMapping[i])') |
| 725 | header_txt.append(' return i;') |
| 726 | header_txt.append(' }') |
| 727 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 728 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 729 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 730 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 731 | header_txt.append(' return retVal;') |
| 732 | header_txt.append('}') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 733 | header_txt.append('struct devExts {') |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 734 | header_txt.append(' bool wsi_enabled;') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 735 | header_txt.append('};') |
| 736 | header_txt.append('') |
| 737 | header_txt.append('static std::unordered_map<void *, struct devExts> deviceExtMap;') |
| 738 | header_txt.append('') |
| 739 | header_txt.append('static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)') |
| 740 | header_txt.append('{') |
Tony Barbour | 29b1206 | 2015-07-13 13:37:24 -0600 | [diff] [blame] | 741 | header_txt.append(' uint32_t i;') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 742 | header_txt.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 743 | header_txt.append(' deviceExtMap[pDisp].wsi_enabled = false;') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 744 | header_txt.append(' for (i = 0; i < pCreateInfo->extensionCount; i++) {') |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 745 | header_txt.append(' if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_WSI_SWAPCHAIN_EXTENSION_NAME) == 0)') |
| 746 | header_txt.append(' deviceExtMap[pDisp].wsi_enabled = true;') |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 747 | header_txt.append('') |
| 748 | header_txt.append(' }') |
| 749 | header_txt.append('}') |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 750 | header_txt.append('') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 751 | return "\n".join(header_txt) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 752 | |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 753 | def generate_init(self): |
| 754 | func_body = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 755 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 756 | func_body.append('#include "vk_dispatch_table_helper.h"') |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 757 | func_body.append('#include "vk_layer_config.h"') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 758 | func_body.append('') |
| 759 | func_body.append('static void init%s(void)' % self.layer_name) |
| 760 | func_body.append('{') |
| 761 | func_body.append(' using namespace StreamControl;') |
| 762 | func_body.append('') |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 763 | func_body.append(' char const*const detailedStr = getLayerOption("APIDumpDetailed");') |
| 764 | func_body.append(' if(detailedStr != NULL)') |
| 765 | func_body.append(' {') |
| 766 | func_body.append(' if(strcmp(detailedStr, "TRUE") == 0)') |
| 767 | func_body.append(' {') |
| 768 | func_body.append(' g_APIDumpDetailed = true;') |
| 769 | func_body.append(' }') |
| 770 | func_body.append(' else if(strcmp(detailedStr, "FALSE") == 0)') |
| 771 | func_body.append(' {') |
| 772 | func_body.append(' g_APIDumpDetailed = false;') |
| 773 | func_body.append(' }') |
| 774 | func_body.append(' }') |
| 775 | func_body.append('') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 776 | func_body.append(' char const*const writeToFileStr = getLayerOption("APIDumpFile");') |
| 777 | func_body.append(' bool writeToFile = false;') |
| 778 | func_body.append(' if(writeToFileStr != NULL)') |
| 779 | func_body.append(' {') |
| 780 | func_body.append(' if(strcmp(writeToFileStr, "TRUE") == 0)') |
| 781 | func_body.append(' {') |
| 782 | func_body.append(' writeToFile = true;') |
| 783 | func_body.append(' }') |
| 784 | func_body.append(' else if(strcmp(writeToFileStr, "FALSE") == 0)') |
| 785 | func_body.append(' {') |
| 786 | func_body.append(' writeToFile = false;') |
| 787 | func_body.append(' }') |
| 788 | func_body.append(' }') |
| 789 | func_body.append('') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 790 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 791 | func_body.append(' char const*const noAddrStr = getLayerOption("APIDumpNoAddr");') |
| 792 | func_body.append(' if(noAddrStr != NULL)') |
| 793 | func_body.append(' {') |
| 794 | func_body.append(' if(strcmp(noAddrStr, "FALSE") == 0)') |
| 795 | func_body.append(' {') |
| 796 | func_body.append(' StreamControl::writeAddress = true;') |
| 797 | func_body.append(' }') |
| 798 | func_body.append(' else if(strcmp(noAddrStr, "TRUE") == 0)') |
| 799 | func_body.append(' {') |
| 800 | func_body.append(' StreamControl::writeAddress = false;') |
| 801 | func_body.append(' }') |
| 802 | func_body.append(' }') |
| 803 | func_body.append('') |
| 804 | func_body.append(' char const*const flushAfterWriteStr = getLayerOption("APIDumpFlush");') |
| 805 | func_body.append(' bool flushAfterWrite = false;') |
| 806 | func_body.append(' if(flushAfterWriteStr != NULL)') |
| 807 | func_body.append(' {') |
| 808 | func_body.append(' if(strcmp(flushAfterWriteStr, "TRUE") == 0)') |
| 809 | func_body.append(' {') |
| 810 | func_body.append(' flushAfterWrite = true;') |
| 811 | func_body.append(' }') |
| 812 | func_body.append(' else if(strcmp(flushAfterWriteStr, "FALSE") == 0)') |
| 813 | func_body.append(' {') |
| 814 | func_body.append(' flushAfterWrite = false;') |
| 815 | func_body.append(' }') |
| 816 | func_body.append(' }') |
| 817 | func_body.append('') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 818 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 819 | func_body.append(' ConfigureOutputStream(writeToFile, flushAfterWrite);') |
| 820 | func_body.append('') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 821 | func_body.append(' if (!printLockInitialized)') |
| 822 | func_body.append(' {') |
| 823 | func_body.append(' // TODO/TBD: Need to delete this mutex sometime. How???') |
| 824 | func_body.append(' loader_platform_thread_create_mutex(&printLock);') |
| 825 | func_body.append(' printLockInitialized = 1;') |
| 826 | func_body.append(' }') |
| 827 | func_body.append('}') |
| 828 | func_body.append('') |
| 829 | return "\n".join(func_body) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 830 | |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 831 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 832 | if proto.name in [ 'GetGlobalLayerProperties','GetGlobalExtensionProperties','GetPhysicalDeviceLayerProperties','GetPhysicalDeviceExtensionProperties']: |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 833 | return None |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 834 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 835 | ret_val = '' |
| 836 | stmt = '' |
| 837 | funcs = [] |
| 838 | sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print |
| 839 | create_params = 0 # Num of params at end of function that are created and returned as output values |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 840 | if 'AllocDescriptorSets' in proto.name: |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 841 | create_params = -2 |
| 842 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 843 | create_params = -1 |
| 844 | if proto.ret != "void": |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 845 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 846 | stmt = " return result;\n" |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 847 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n ' |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 848 | log_func = '%s\n' % self.lineinfo.get() |
| 849 | log_func += ' if (StreamControl::writeAddress == true) {' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 850 | log_func += '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 851 | log_func_no_addr = '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 852 | f_close = '\n loader_platform_thread_unlock_mutex(&printLock);' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 853 | pindex = 0 |
| 854 | prev_count_name = '' |
| 855 | for p in proto.params: |
| 856 | cp = False |
| 857 | if 0 != create_params: |
| 858 | # If this is any of the N last params of the func, treat as output |
| 859 | for y in range(-1, create_params-1, -1): |
| 860 | if p.name == proto.params[y].name: |
| 861 | cp = True |
| 862 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True) |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 863 | if p.name == "pSwapChain": |
| 864 | log_func += '%s = " << %s->handle << ", ' % (p.name, p.name) |
| 865 | elif p.name == "swapChain": |
| 866 | log_func += '%s = " << %s.handle << ", ' % (p.name, p.name) |
| 867 | else: |
| 868 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 869 | if "%p" == pft: |
| 870 | log_func_no_addr += '%s = address, ' % (p.name) |
| 871 | else: |
| 872 | log_func_no_addr += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | c99cb0d | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 873 | if prev_count_name != '' and (prev_count_name.replace('Count', '')[1:] in p.name): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 874 | sp_param_dict[pindex] = prev_count_name |
Tobin Ehlis | c99cb0d | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 875 | prev_count_name = '' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 876 | elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount': |
| 877 | sp_param_dict[pindex] = '*pCount' |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 878 | elif vk_helper.is_type(p.ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 879 | sp_param_dict[pindex] = 'index' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 880 | if p.name.endswith('Count'): |
| 881 | if '*' in p.ty: |
| 882 | prev_count_name = "*%s" % p.name |
| 883 | else: |
| 884 | prev_count_name = p.name |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 885 | pindex += 1 |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 886 | log_func = log_func.strip(', ') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 887 | log_func_no_addr = log_func_no_addr.strip(', ') |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 888 | if proto.ret == "VkResult": |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 889 | log_func += ') = " << string_VkResult((VkResult)result) << endl' |
| 890 | log_func_no_addr += ') = " << string_VkResult((VkResult)result) << endl' |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 891 | elif proto.ret == "void*": |
| 892 | log_func += ') = " << result << endl' |
| 893 | log_func_no_addr += ') = " << result << endl' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 894 | else: |
| 895 | log_func += ')\\n"' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 896 | log_func_no_addr += ')\\n"' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 897 | log_func += ';' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 898 | log_func_no_addr += ';' |
Tobin Ehlis | 0b9c195 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 899 | log_func += '\n }\n else {%s\n }' % log_func_no_addr; |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 900 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 901 | #print("Proto %s has param_dict: %s" % (proto.name, sp_param_dict)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 902 | if len(sp_param_dict) > 0: |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 903 | indent = ' ' |
| 904 | log_func += '\n%sif (g_APIDumpDetailed) {' % indent |
| 905 | indent += ' ' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 906 | i_decl = False |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 907 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 908 | log_func += '\n%sstring tmp_str;' % indent |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 909 | for sp_index in sp_param_dict: |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 910 | #print("sp_index: %s" % str(sp_index)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 911 | if 'index' == sp_param_dict[sp_index]: |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 912 | cis_print_func = 'vk_print_%s' % (proto.params[sp_index].ty.replace('const ', '').strip('*').lower()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 913 | local_name = proto.params[sp_index].name |
| 914 | if '*' not in proto.params[sp_index].ty: |
| 915 | local_name = '&%s' % proto.params[sp_index].name |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 916 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 917 | log_func += '\n%sif (%s) {' % (indent, local_name) |
| 918 | indent += ' ' |
| 919 | log_func += '\n%stmp_str = %s(%s, " ");' % (indent, cis_print_func, local_name) |
| 920 | log_func += '\n%s(*outputStream) << " %s (" << %s << ")" << endl << tmp_str << endl;' % (indent, local_name, local_name) |
| 921 | indent = indent[4:] |
| 922 | log_func += '\n%s}' % (indent) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 923 | else: # We have a count value stored to iterate over an array |
| 924 | print_cast = '' |
| 925 | print_func = '' |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 926 | if vk_helper.is_type(proto.params[sp_index].ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 927 | print_cast = '&' |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 928 | print_func = 'vk_print_%s' % proto.params[sp_index].ty.replace('const ', '').strip('*').lower() |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 929 | else: |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 930 | print_cast = '' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 931 | print_func = 'string_convert_helper' |
| 932 | #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name |
Tobin Ehlis | 0b9c195 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 933 | if proto.params[sp_index].ty.strip('*').replace('const ', '') in vulkan.object_non_dispatch_list: |
| 934 | cis_print_func = 'tmp_str = %s(%s%s[i].handle, " ");' % (print_func, print_cast, proto.params[sp_index].name) |
| 935 | else: |
| 936 | cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 937 | if not i_decl: |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 938 | log_func += '\n%suint32_t i;' % (indent) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 939 | i_decl = True |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 940 | log_func += '\n%sif (%s) {' % (indent, proto.params[sp_index].name) |
| 941 | indent += ' ' |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 942 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 943 | log_func += '\n%sfor (i = 0; i < %s; i++) {' % (indent, sp_param_dict[sp_index]) |
| 944 | indent += ' ' |
| 945 | log_func += '\n%s%s' % (indent, cis_print_func) |
Tobin Ehlis | 8ad1574 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 946 | log_func += '\n%sif (StreamControl::writeAddress == true) {' % (indent) |
| 947 | indent += ' ' |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 948 | 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) |
| 949 | indent = indent[4:] |
Tobin Ehlis | 8ad1574 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 950 | log_func += '\n%s} else {' % (indent) |
| 951 | indent += ' ' |
| 952 | log_func += '\n%s(*outputStream) << " %s[" << i << "] (address)" << endl << " address" << endl;' % (indent, proto.params[sp_index].name) |
| 953 | indent = indent[4:] |
| 954 | log_func += '\n%s}' % (indent) |
| 955 | indent = indent[4:] |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 956 | log_func += '\n%s}' % (indent) |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 957 | indent = indent[4:] |
| 958 | log_func += '\n%s}' % (indent) |
Tobin Ehlis | 55c4041 | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 959 | indent = indent[4:] |
| 960 | log_func += '\n%s}' % (indent) |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 961 | table_type = '' |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 962 | if proto_is_global(proto): |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 963 | table_type = 'instance' |
| 964 | else: |
| 965 | table_type = 'device' |
Jon Ashburn | 52c1d73 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 966 | |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 967 | if proto.name == "CreateInstance": |
| 968 | dispatch_param = '*' + proto.params[1].name |
| 969 | else: |
| 970 | dispatch_param = proto.params[0].name |
| 971 | |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 972 | if proto.name == "CreateDevice": |
Courtney Goeltzenleuchter | 4843dda | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 973 | funcs.append('%s\n' % self.lineinfo.get()) |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 974 | funcs.append('%s%s\n' |
| 975 | '{\n' |
| 976 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 977 | ' %sdevice_dispatch_table(*pDevice)->%s;\n' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 978 | ' if (result == VK_SUCCESS)\n' |
| 979 | ' createDeviceRegisterExtensions(pCreateInfo, *pDevice);\n' |
| 980 | ' %s%s%s\n' |
| 981 | '%s' |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 982 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 983 | elif proto.name == "DestroyDevice": |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 984 | funcs.append('%s%s\n' |
| 985 | '{\n' |
| 986 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 987 | ' dispatch_key key = get_dispatch_key(device);\n' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 988 | ' VkLayerDispatchTable *pDisp = %s_dispatch_table(%s);\n' |
| 989 | ' %spDisp->%s;\n' |
| 990 | ' deviceExtMap.erase(pDisp);\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 991 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 992 | ' %s%s%s\n' |
| 993 | '%s' |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 994 | '}' % (qual, decl, table_type, dispatch_param, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 995 | elif proto.name == "DestroyInstance": |
| 996 | funcs.append('%s%s\n' |
| 997 | '{\n' |
| 998 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 999 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1000 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1001 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1002 | ' %s%s%s\n' |
| 1003 | '%s' |
| 1004 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 1005 | else: |
| 1006 | funcs.append('%s%s\n' |
| 1007 | '{\n' |
| 1008 | ' using namespace StreamControl;\n' |
| 1009 | ' %s%s_dispatch_table(%s)->%s;\n' |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1010 | ' %s%s%s\n' |
| 1011 | '%s' |
Mark Lobodzinski | bf7c700 | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1012 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1013 | return "\n\n".join(funcs) |
| 1014 | |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1015 | def generate_body(self): |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1016 | self.layer_name = "APIDump" |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 1017 | extensions=[('wsi_enabled', |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1018 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
| 1019 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI'])] |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1020 | body = [self.generate_init(), |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1021 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1022 | self._generate_layer_gpa_function(extensions)] |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1023 | return "\n\n".join(body) |
| 1024 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1025 | class ObjectTrackerSubcommand(Subcommand): |
| 1026 | def generate_header(self): |
| 1027 | header_txt = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1028 | header_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1029 | header_txt.append('#include <stdio.h>') |
| 1030 | header_txt.append('#include <stdlib.h>') |
| 1031 | header_txt.append('#include <string.h>') |
| 1032 | header_txt.append('#include <inttypes.h>') |
| 1033 | header_txt.append('') |
| 1034 | header_txt.append('#include "vulkan.h"') |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1035 | header_txt.append('#include "vk_loader_platform.h"') |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1036 | header_txt.append('') |
Tobin Ehlis | 586aa01 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1037 | header_txt.append('#include <unordered_map>') |
| 1038 | header_txt.append('using namespace std;') |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1039 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1040 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1041 | header_txt.append('#include "vk_layer_config.h"') |
| 1042 | header_txt.append('#include "vk_layer_msg.h"') |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1043 | header_txt.append('#include "vk_debug_report_lunarg.h"') |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1044 | header_txt.append('#include "vk_layer_table.h"') |
| 1045 | header_txt.append('#include "vk_layer_data.h"') |
| 1046 | header_txt.append('#include "vk_layer_logging.h"') |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1047 | header_txt.append('') |
| 1048 | # NOTE: The non-autoGenerated code is in the object_track.h header file |
| 1049 | header_txt.append('#include "object_track.h"') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1050 | header_txt.append('') |
Jon Ashburn | d956400 | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 1051 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1052 | header_txt.append('') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1053 | return "\n".join(header_txt) |
| 1054 | |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1055 | def generate_maps(self): |
| 1056 | maps_txt = [] |
| 1057 | for o in vulkan.core.objects: |
| 1058 | maps_txt.append('unordered_map<const void*, OBJTRACK_NODE*> %sMap;' % (o)) |
| 1059 | maps_txt.append('unordered_map<const void*, OBJTRACK_NODE*> VkSwapChainWSIMap;') |
| 1060 | return "\n".join(maps_txt) |
| 1061 | |
| 1062 | def generate_procs(self): |
| 1063 | procs_txt = [] |
| 1064 | for o in vulkan.core.objects: |
| 1065 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1066 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1067 | procs_txt.append('static void create_obj(%s dispatchable_object, %s vkObj, VkDbgObjectType objType)' % (o, o)) |
| 1068 | procs_txt.append('{') |
| 1069 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, reinterpret_cast<VkUintPtrLeast64>(vkObj), 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1070 | procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType),') |
| 1071 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(vkObj));') |
| 1072 | else: |
| 1073 | procs_txt.append('static void create_obj(VkDevice dispatchable_object, %s vkObj, VkDbgObjectType objType)' % (o)) |
| 1074 | procs_txt.append('{') |
| 1075 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, vkObj.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1076 | procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType),') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1077 | procs_txt.append(' vkObj.handle);') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1078 | procs_txt.append('') |
| 1079 | procs_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;') |
| 1080 | procs_txt.append(' pNewObjNode->objType = objType;') |
| 1081 | procs_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;') |
| 1082 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1083 | procs_txt.append(' pNewObjNode->vkObj = reinterpret_cast<VkUintPtrLeast64>(vkObj);') |
| 1084 | procs_txt.append(' %sMap[vkObj] = pNewObjNode;' % (o)) |
| 1085 | else: |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1086 | procs_txt.append(' pNewObjNode->vkObj = vkObj.handle;') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1087 | procs_txt.append(' %sMap[(void*)vkObj.handle] = pNewObjNode;' % (o)) |
| 1088 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(objType);') |
| 1089 | procs_txt.append(' numObjs[objIndex]++;') |
| 1090 | procs_txt.append(' numTotalObjs++;') |
| 1091 | procs_txt.append('}') |
| 1092 | procs_txt.append('') |
| 1093 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1094 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1095 | procs_txt.append('static void validate_object(%s dispatchable_object, %s object)' % (o, o)) |
| 1096 | else: |
| 1097 | procs_txt.append('static void validate_object(VkDevice dispatchable_object, %s object)' % (o)) |
| 1098 | procs_txt.append('{') |
| 1099 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1100 | procs_txt.append(' if (%sMap.find(object) == %sMap.end()) {' % (o, o)) |
| 1101 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
Tobin Ehlis | 33ce8fd | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1102 | procs_txt.append(' "Invalid %s Object %%p",reinterpret_cast<VkUintPtrLeast64>(object));' % o) |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1103 | else: |
| 1104 | procs_txt.append(' if (%sMap.find((void*)object.handle) == %sMap.end()) {' % (o, o)) |
| 1105 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1106 | procs_txt.append(' "Invalid %s Object %%p", object.handle);' % o) |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1107 | procs_txt.append(' }') |
| 1108 | procs_txt.append('}') |
| 1109 | procs_txt.append('') |
| 1110 | procs_txt.append('') |
| 1111 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1112 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1113 | procs_txt.append('static void destroy_obj(%s dispatchable_object, %s object)' % (o, o)) |
| 1114 | else: |
| 1115 | procs_txt.append('static void destroy_obj(VkDevice dispatchable_object, %s object)' % (o)) |
| 1116 | procs_txt.append('{') |
| 1117 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1118 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1119 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1120 | else: |
| 1121 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1122 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1123 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);') |
| 1124 | procs_txt.append(' assert(numTotalObjs > 0);') |
| 1125 | procs_txt.append(' numTotalObjs--;') |
| 1126 | procs_txt.append(' assert(numObjs[objIndex] > 0);') |
| 1127 | procs_txt.append(' numObjs[objIndex]--;') |
| 1128 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1129 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, pNode->objType, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1130 | procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%lu total objs remain & %lu %s objs).",') |
| 1131 | procs_txt.append(' string_VkDbgObjectType(pNode->objType), reinterpret_cast<VkUintPtrLeast64>(object), numTotalObjs, numObjs[objIndex],') |
| 1132 | else: |
| 1133 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, pNode->objType, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1134 | procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%lu total objs remain & %lu %s objs).",') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1135 | procs_txt.append(' string_VkDbgObjectType(pNode->objType), object.handle, numTotalObjs, numObjs[objIndex],') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1136 | procs_txt.append(' string_VkDbgObjectType(pNode->objType));') |
| 1137 | procs_txt.append(' delete pNode;') |
| 1138 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1139 | procs_txt.append(' %sMap.erase(object);' % (o)) |
| 1140 | procs_txt.append(' } else {') |
| 1141 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1142 | procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",') |
| 1143 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object));') |
| 1144 | procs_txt.append(' }') |
| 1145 | else: |
| 1146 | procs_txt.append(' %sMap.erase((void*)object.handle);' % (o)) |
| 1147 | procs_txt.append(' } else {') |
| 1148 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1149 | procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1150 | procs_txt.append(' object.handle);') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1151 | procs_txt.append(' }') |
| 1152 | procs_txt.append('}') |
| 1153 | procs_txt.append('') |
| 1154 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1155 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1156 | procs_txt.append('static void set_status(%s dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o, o)) |
| 1157 | procs_txt.append('{') |
| 1158 | procs_txt.append(' if (object != VK_NULL_HANDLE) {') |
| 1159 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1160 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1161 | else: |
| 1162 | procs_txt.append('static void set_status(VkDevice dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o)) |
| 1163 | procs_txt.append('{') |
| 1164 | procs_txt.append(' if (object.handle != VK_NULL_HANDLE) {') |
| 1165 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1166 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1167 | procs_txt.append(' pNode->status |= status_flag;') |
| 1168 | procs_txt.append(' return;') |
| 1169 | procs_txt.append(' }') |
| 1170 | procs_txt.append(' else {') |
| 1171 | procs_txt.append(' // If we do not find it print an error') |
| 1172 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1173 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1174 | procs_txt.append(' "Unable to set status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
| 1175 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object), string_VkDbgObjectType(objType));') |
| 1176 | else: |
| 1177 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1178 | procs_txt.append(' "Unable to set status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1179 | procs_txt.append(' object.handle, string_VkDbgObjectType(objType));') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1180 | procs_txt.append(' }') |
| 1181 | procs_txt.append(' }') |
| 1182 | procs_txt.append('}') |
| 1183 | procs_txt.append('') |
| 1184 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1185 | procs_txt.append('static VkBool32 validate_status(') |
| 1186 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1187 | procs_txt.append('%s dispatchable_object, %s object,' % (o, o)) |
| 1188 | else: |
| 1189 | procs_txt.append('VkDevice dispatchable_object, %s object,' % (o)) |
| 1190 | procs_txt.append(' VkDbgObjectType objType,') |
| 1191 | procs_txt.append(' ObjectStatusFlags status_mask,') |
| 1192 | procs_txt.append(' ObjectStatusFlags status_flag,') |
| 1193 | procs_txt.append(' VkFlags msg_flags,') |
| 1194 | procs_txt.append(' OBJECT_TRACK_ERROR error_code,') |
| 1195 | procs_txt.append(' const char *fail_msg)') |
| 1196 | procs_txt.append('{') |
| 1197 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1198 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1199 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1200 | else: |
| 1201 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1202 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1203 | procs_txt.append(' if ((pNode->status & status_mask) != status_flag) {') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1204 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1205 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, pNode->objType, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1206 | procs_txt.append(' "OBJECT VALIDATION WARNING: %s object 0x%" PRIxLEAST64 ": %s", string_VkDbgObjectType(objType),') |
| 1207 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object), fail_msg);') |
| 1208 | else: |
| 1209 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, pNode->objType, object.handle, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1210 | procs_txt.append(' "OBJECT VALIDATION WARNING: %s object 0x%" PRIxLEAST64 ": %s", string_VkDbgObjectType(objType),') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1211 | procs_txt.append(' object.handle, fail_msg);') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1212 | procs_txt.append(' return VK_FALSE;') |
| 1213 | procs_txt.append(' }') |
| 1214 | procs_txt.append(' return VK_TRUE;') |
| 1215 | procs_txt.append(' }') |
| 1216 | procs_txt.append(' else {') |
| 1217 | procs_txt.append(' // If we do not find it print an error') |
| 1218 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1219 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, (VkDbgObjectType) 0, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1220 | procs_txt.append(' "Unable to obtain status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
| 1221 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object), string_VkDbgObjectType(objType));') |
| 1222 | else: |
| 1223 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1224 | procs_txt.append(' "Unable to obtain status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1225 | procs_txt.append(' object.handle, string_VkDbgObjectType(objType));') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1226 | procs_txt.append(' return VK_FALSE;') |
| 1227 | procs_txt.append(' }') |
| 1228 | procs_txt.append('}') |
| 1229 | procs_txt.append('') |
| 1230 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1231 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1232 | procs_txt.append('static void reset_status(%s dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o, o)) |
| 1233 | procs_txt.append('{') |
| 1234 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1235 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1236 | else: |
| 1237 | procs_txt.append('static void reset_status(VkDevice dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o)) |
| 1238 | procs_txt.append('{') |
| 1239 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1240 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1241 | procs_txt.append(' pNode->status &= ~status_flag;') |
| 1242 | procs_txt.append(' return;') |
| 1243 | procs_txt.append(' }') |
| 1244 | procs_txt.append(' else {') |
| 1245 | procs_txt.append(' // If we do not find it print an error') |
| 1246 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1247 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, objType, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1248 | procs_txt.append(' "Unable to reset status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
| 1249 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object), string_VkDbgObjectType(objType));') |
| 1250 | else: |
| 1251 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, objType, object.handle, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1252 | procs_txt.append(' "Unable to reset status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1253 | procs_txt.append(' object.handle, string_VkDbgObjectType(objType));') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1254 | procs_txt.append(' }') |
| 1255 | procs_txt.append('}') |
| 1256 | procs_txt.append('') |
| 1257 | return "\n".join(procs_txt) |
| 1258 | |
| 1259 | def generate_explicit_destroy_instance(self): |
| 1260 | gedi_txt = [] |
| 1261 | gedi_txt.append('%s' % self.lineinfo.get()) |
| 1262 | gedi_txt.append('VkResult explicit_DestroyInstance(') |
| 1263 | gedi_txt.append('VkInstance instance)') |
| 1264 | gedi_txt.append('{') |
| 1265 | gedi_txt.append(' loader_platform_thread_lock_mutex(&objLock);') |
| 1266 | gedi_txt.append(' validate_object(instance, instance);') |
| 1267 | gedi_txt.append('') |
| 1268 | gedi_txt.append(' destroy_obj(instance, instance);') |
| 1269 | gedi_txt.append(' // Report any remaining objects in LL') |
| 1270 | for o in vulkan.core.objects: |
| 1271 | if o in ['VkPhysicalDevice', 'VkQueue']: |
| 1272 | continue |
| 1273 | gedi_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end(); ++it) {' % (o, o)) |
| 1274 | gedi_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
| 1275 | gedi_txt.append(' log_msg(mid(instance), VK_DBG_REPORT_ERROR_BIT, pNode->objType, pNode->vkObj, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 1276 | gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDbgObjectType(pNode->objType),') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1277 | gedi_txt.append(' pNode->vkObj);') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1278 | gedi_txt.append(' }') |
| 1279 | gedi_txt.append('') |
| 1280 | gedi_txt.append(' dispatch_key key = get_dispatch_key(instance);') |
| 1281 | gedi_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ObjectTracker_instance_table_map, instance);') |
| 1282 | gedi_txt.append(' VkResult result = pInstanceTable->DestroyInstance(instance);') |
| 1283 | gedi_txt.append('') |
| 1284 | gedi_txt.append(' // Clean up logging callback, if any') |
| 1285 | gedi_txt.append(' layer_data *my_data = get_my_data_ptr(key, layer_data_map);') |
| 1286 | gedi_txt.append(' if (my_data->logging_callback) {') |
| 1287 | gedi_txt.append(' layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);') |
| 1288 | gedi_txt.append(' }') |
| 1289 | gedi_txt.append('') |
| 1290 | gedi_txt.append(' layer_debug_report_destroy_instance(mid(instance));') |
| 1291 | gedi_txt.append(' layer_data_map.erase(pInstanceTable);') |
| 1292 | gedi_txt.append('') |
| 1293 | gedi_txt.append(' ObjectTracker_instance_table_map.erase(key);') |
| 1294 | gedi_txt.append(' assert(ObjectTracker_instance_table_map.size() == 0 && "Should not have any instance mappings hanging around");') |
| 1295 | gedi_txt.append('') |
| 1296 | gedi_txt.append(' loader_platform_thread_unlock_mutex(&objLock);') |
| 1297 | gedi_txt.append(' return result;') |
| 1298 | gedi_txt.append('}') |
| 1299 | gedi_txt.append('') |
| 1300 | return "\n".join(gedi_txt) |
| 1301 | |
| 1302 | def generate_explicit_destroy_device(self): |
| 1303 | gedd_txt = [] |
| 1304 | gedd_txt.append('%s' % self.lineinfo.get()) |
| 1305 | gedd_txt.append('VkResult explicit_DestroyDevice(') |
| 1306 | gedd_txt.append('VkDevice device)') |
| 1307 | gedd_txt.append('{') |
| 1308 | gedd_txt.append(' loader_platform_thread_lock_mutex(&objLock);') |
| 1309 | gedd_txt.append(' validate_object(device, device);') |
| 1310 | gedd_txt.append('') |
| 1311 | gedd_txt.append(' destroy_obj(device, device);') |
| 1312 | gedd_txt.append(' // Report any remaining objects in LL') |
| 1313 | for o in vulkan.core.objects: |
| 1314 | if o in ['VkPhysicalDevice', 'VkQueue']: |
| 1315 | continue |
| 1316 | gedd_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end(); ++it) {' % (o, o)) |
| 1317 | gedd_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
| 1318 | gedd_txt.append(' log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, pNode->objType, pNode->vkObj, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 1319 | gedd_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDbgObjectType(pNode->objType),') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1320 | gedd_txt.append(' pNode->vkObj);') |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1321 | gedd_txt.append(' }') |
| 1322 | gedd_txt.append('') |
| 1323 | gedd_txt.append(" // Clean up Queue's MemRef Linked Lists") |
| 1324 | gedd_txt.append(' destroyQueueMemRefLists();') |
| 1325 | gedd_txt.append('') |
| 1326 | gedd_txt.append(' loader_platform_thread_unlock_mutex(&objLock);') |
| 1327 | gedd_txt.append('') |
| 1328 | gedd_txt.append(' dispatch_key key = get_dispatch_key(device);') |
| 1329 | gedd_txt.append(' VkLayerDispatchTable *pDisp = get_dispatch_table(ObjectTracker_device_table_map, device);') |
| 1330 | gedd_txt.append(' VkResult result = pDisp->DestroyDevice(device);') |
| 1331 | gedd_txt.append(' ObjectTracker_device_table_map.erase(key);') |
| 1332 | gedd_txt.append(' assert(ObjectTracker_device_table_map.size() == 0 && "Should not have any instance mappings hanging around");') |
| 1333 | gedd_txt.append('') |
| 1334 | gedd_txt.append(' return result;') |
| 1335 | gedd_txt.append('}') |
| 1336 | gedd_txt.append('') |
| 1337 | return "\n".join(gedd_txt) |
| 1338 | |
| 1339 | def generate_command_buffer_validates(self): |
| 1340 | cbv_txt = [] |
| 1341 | cbv_txt.append('%s' % self.lineinfo.get()) |
| 1342 | for o in ['VkPipeline', 'VkDynamicViewportState', 'VkDynamicRasterState', 'VkDynamicColorBlendState', 'VkDynamicDepthStencilState', |
| 1343 | 'VkPipelineLayout', 'VkBuffer', 'VkEvent', 'VkQueryPool', 'VkRenderPass', 'VkFramebuffer']: |
| 1344 | cbv_txt.append('static void validate_object(VkCmdBuffer dispatchable_object, %s object)' % (o)) |
| 1345 | cbv_txt.append('{') |
| 1346 | cbv_txt.append(' if (%sMap.find((void*)object.handle) == %sMap.end()) {' % (o, o)) |
| 1347 | cbv_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
Tony Barbour | 8db6537 | 2015-07-10 18:32:33 -0600 | [diff] [blame] | 1348 | cbv_txt.append(' "Invalid %s Object %%p", object.handle);' % (o)) |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1349 | cbv_txt.append(' }') |
| 1350 | cbv_txt.append('}') |
| 1351 | cbv_txt.append('') |
| 1352 | return "\n".join(cbv_txt) |
| 1353 | |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1354 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1355 | if proto.name in [ 'DbgCreateMsgCallback', 'GetGlobalLayerProperties', 'GetGlobalExtensionProperties','GetPhysicalDeviceLayerProperties', 'GetPhysicalDeviceExtensionProperties' ]: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1356 | # use default version |
| 1357 | return None |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1358 | |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1359 | # Create map of object names to object type enums of the form VkName : VkObjectTypeName |
| 1360 | obj_type_mapping = {base_t : base_t.replace("Vk", "VkObjectType") for base_t in vulkan.object_type_list} |
Mark Lobodzinski | 4e5016f | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1361 | # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES |
| 1362 | for objectName, objectTypeEnum in obj_type_mapping.items(): |
| 1363 | obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum); |
| 1364 | # Command Buffer Object doesn't follow the rule. |
| 1365 | obj_type_mapping['VkCmdBuffer'] = "VK_OBJECT_TYPE_COMMAND_BUFFER" |
Courtney Goeltzenleuchter | 2d034fd | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1366 | obj_type_mapping['VkShaderModule'] = "VK_OBJECT_TYPE_SHADER_MODULE" |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1367 | |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1368 | explicit_object_tracker_functions = [ |
| 1369 | "CreateInstance", |
| 1370 | "DestroyInstance", |
Tony Barbour | 426b905 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1371 | "GetPhysicalDeviceQueueProperties", |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1372 | "CreateDevice", |
| 1373 | "DestroyDevice", |
| 1374 | "GetDeviceQueue", |
| 1375 | "QueueSubmit", |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1376 | "QueueBindSparseImageMemory", |
| 1377 | "QueueBindSparseBufferMemory", |
| 1378 | "GetFenceStatus", |
| 1379 | "WaitForFences", |
| 1380 | "AllocDescriptorSets", |
| 1381 | "MapMemory", |
| 1382 | "UnmapMemory", |
| 1383 | "FreeMemory", |
| 1384 | "DestroySwapChainWSI" |
| 1385 | ] |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1386 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1387 | param0_name = proto.params[0].name |
Mark Lobodzinski | c44a5a1 | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1388 | using_line = '' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1389 | create_line = '' |
Tobin Ehlis | 25756af | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1390 | object_params = {} # dict of parameters that are VkObject types mapping to the size of array types or '0' if not array |
Tobin Ehlis | 33ce8fd | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1391 | # TODO : For now skipping objs that can be NULL. Really should check these and have special case that allows them to be NULL |
| 1392 | valid_null_object_names = ['basePipelineHandle', 'renderPass', 'framebuffer'] |
Tobin Ehlis | 586aa01 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1393 | # TODO : A few of the skipped types are just "hard" cases that need some more work to support |
| 1394 | # Need to handle NULL fences on queue submit, binding null memory, and WSI Image objects |
| 1395 | for p in proto.params: |
| 1396 | if p.ty in vulkan.core.objects and p.ty not in ['VkPhysicalDevice', 'VkQueue', 'VkFence', 'VkImage', 'VkDeviceMemory']: |
Tobin Ehlis | 157e28d | 2015-07-10 11:10:21 -0600 | [diff] [blame] | 1397 | if p.name not in valid_null_object_names: |
| 1398 | object_params[p.name] = 0 |
Tobin Ehlis | 25756af | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1399 | elif vk_helper.is_type(p.ty.replace('const ', '').strip('*'), 'struct'): |
| 1400 | struct_type = p.ty.replace('const ', '').strip('*') |
| 1401 | if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict: |
| 1402 | struct_type = vk_helper.typedef_rev_dict[struct_type] |
| 1403 | for m in sorted(vk_helper.struct_dict[struct_type]): |
| 1404 | 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 | 157e28d | 2015-07-10 11:10:21 -0600 | [diff] [blame] | 1405 | if vk_helper.struct_dict[struct_type][m]['name'] not in valid_null_object_names: |
| 1406 | param_name = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name']) |
| 1407 | object_params[param_name] = {} |
| 1408 | if vk_helper.struct_dict[struct_type][m]['dyn_array']: |
| 1409 | object_params[param_name] = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size']) |
| 1410 | else: |
| 1411 | object_params[param_name] = 0 |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1412 | funcs = [] |
Tobin Ehlis | 586aa01 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1413 | mutex_unlock = False |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1414 | if proto.name in explicit_object_tracker_functions: |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1415 | funcs.append('%s%s\n' |
| 1416 | '{\n' |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1417 | ' return explicit_%s;\n' |
| 1418 | '}' % (qual, decl, proto.c_call())) |
| 1419 | return "".join(funcs) |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1420 | else: |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1421 | if 'Create' in proto.name or 'Alloc' in proto.name: |
| 1422 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1423 | create_line += ' if (result == VK_SUCCESS) {\n' |
| 1424 | create_line += ' create_obj(%s, *%s, %s);\n' % (param0_name, proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').replace('const ', '')]) |
| 1425 | create_line += ' }\n' |
| 1426 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1427 | if len(object_params) > 0: |
| 1428 | if not mutex_unlock: |
| 1429 | using_line += ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1430 | mutex_unlock = True |
| 1431 | for opn in object_params: |
Tobin Ehlis | 25756af | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1432 | if 0 != object_params[opn]: |
| 1433 | using_line += ' for (uint32_t i=0; i<%s; i++)\n' % object_params[opn] |
| 1434 | using_line += ' validate_object(%s, %s[i]);\n' % (param0_name, opn) |
| 1435 | else: |
| 1436 | if '->' in opn: |
| 1437 | using_line += ' if (%s)\n' % (opn.split('-')[0]) |
| 1438 | using_line += ' validate_object(%s, %s);\n' % (param0_name, opn) |
| 1439 | else: |
| 1440 | using_line += ' validate_object(%s, %s);\n' % (param0_name, opn) |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1441 | if mutex_unlock: |
| 1442 | using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1443 | ret_val = '' |
| 1444 | stmt = '' |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1445 | if proto.ret != "void": |
| 1446 | ret_val = "%s result = " % proto.ret |
| 1447 | stmt = " return result;\n" |
| 1448 | |
| 1449 | dispatch_param = proto.params[0].name |
| 1450 | if 'CreateInstance' in proto.name: |
| 1451 | dispatch_param = '*' + proto.params[1].name |
| 1452 | |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1453 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 1454 | table_type = "" |
| 1455 | if proto_is_global(proto): |
| 1456 | table_type = "instance" |
| 1457 | else: |
| 1458 | table_type = "device" |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1459 | funcs.append('%s%s\n' |
| 1460 | '{\n' |
| 1461 | '%s' |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1462 | ' %sget_dispatch_table(ObjectTracker_%s_table_map, %s)->%s;\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1463 | '%s' |
Mark Lobodzinski | 14305ad | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1464 | '%s' |
| 1465 | '}' % (qual, decl, using_line, ret_val, table_type, dispatch_param, proto.c_call(), create_line, stmt)) |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1466 | return "\n\n".join(funcs) |
| 1467 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1468 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1469 | self.layer_name = "ObjectTracker" |
Ian Elliott | b134e84 | 2015-07-06 14:31:32 -0600 | [diff] [blame] | 1470 | extensions=[('wsi_enabled', |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1471 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
Courtney Goeltzenleuchter | 8a934ba | 2015-07-06 22:30:28 -0600 | [diff] [blame] | 1472 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI'])] |
Tony Barbour | 2a199c1 | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1473 | body = [self.generate_maps(), |
| 1474 | self.generate_procs(), |
| 1475 | self.generate_explicit_destroy_instance(), |
| 1476 | self.generate_explicit_destroy_device(), |
| 1477 | self.generate_command_buffer_validates(), |
| 1478 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1479 | self._generate_extensions(), |
Jon Ashburn | 7e07faf | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1480 | self._generate_layer_gpa_function(extensions, |
Courtney Goeltzenleuchter | ce445ad | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 1481 | instance_extensions=['msg_callback_get_proc_addr'])] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1482 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | e6094fc | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1483 | |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1484 | class ThreadingSubcommand(Subcommand): |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1485 | thread_check_dispatchable_objects = [ |
| 1486 | "VkQueue", |
| 1487 | "VkCmdBuffer", |
| 1488 | ] |
| 1489 | thread_check_nondispatchable_objects = [ |
| 1490 | "VkDeviceMemory", |
| 1491 | "VkBuffer", |
| 1492 | "VkImage", |
| 1493 | "VkDescriptorSet", |
| 1494 | "VkDescriptorPool", |
| 1495 | "VkSemaphore" |
| 1496 | ] |
| 1497 | def generate_useObject(self, ty, key): |
| 1498 | header_txt = [] |
| 1499 | header_txt.append('%s' % self.lineinfo.get()) |
| 1500 | header_txt.append('static void useObject(%s object, const char* type)' % ty) |
| 1501 | header_txt.append('{') |
| 1502 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
| 1503 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1504 | header_txt.append(' if (%sObjectsInUse.find(%s) == %sObjectsInUse.end()) {' % (ty, key, ty)) |
| 1505 | header_txt.append(' %sObjectsInUse[%s] = tid;' % (ty, key)) |
| 1506 | header_txt.append(' } else {') |
| 1507 | header_txt.append(' if (%sObjectsInUse[%s] != tid) {' % (ty, key)) |
| 1508 | header_txt.append(' char str[1024];') |
| 1509 | header_txt.append(' sprintf(str, "THREADING ERROR : object of type %%s is simultaneously used in thread %%ld and thread %%ld", type, %sObjectsInUse[%s], tid);' % (ty, key)) |
| 1510 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING", str);') |
| 1511 | header_txt.append(' // Wait for thread-safe access to object') |
| 1512 | header_txt.append(' while (%sObjectsInUse.find(%s) != %sObjectsInUse.end()) {' % (ty, key, ty)) |
| 1513 | header_txt.append(' loader_platform_thread_cond_wait(&threadingCond, &threadingLock);') |
| 1514 | header_txt.append(' }') |
| 1515 | header_txt.append(' %sObjectsInUse[%s] = tid;' % (ty, key)) |
| 1516 | header_txt.append(' } else {') |
| 1517 | header_txt.append(' char str[1024];') |
| 1518 | header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is recursively used in thread %ld", type, tid);') |
| 1519 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, THREADING_CHECKER_SINGLE_THREAD_REUSE, "THREADING", str);') |
| 1520 | header_txt.append(' }') |
| 1521 | header_txt.append(' }') |
| 1522 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1523 | header_txt.append('}') |
| 1524 | return "\n".join(header_txt) |
| 1525 | def generate_finishUsingObject(self, ty, key): |
| 1526 | header_txt = [] |
| 1527 | header_txt.append('%s' % self.lineinfo.get()) |
| 1528 | header_txt.append('static void finishUsingObject(%s object)' % ty) |
| 1529 | header_txt.append('{') |
| 1530 | header_txt.append(' // Object is no longer in use') |
| 1531 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1532 | header_txt.append(' %sObjectsInUse.erase(%s);' % (ty, key)) |
| 1533 | header_txt.append(' loader_platform_thread_cond_broadcast(&threadingCond);') |
| 1534 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1535 | header_txt.append('}') |
| 1536 | return "\n".join(header_txt) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1537 | def generate_header(self): |
| 1538 | header_txt = [] |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1539 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1540 | header_txt.append('#include <stdio.h>') |
| 1541 | header_txt.append('#include <stdlib.h>') |
| 1542 | header_txt.append('#include <string.h>') |
| 1543 | header_txt.append('#include <unordered_map>') |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1544 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 1545 | header_txt.append('#include "vk_layer.h"') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1546 | header_txt.append('#include "threading.h"') |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1547 | header_txt.append('#include "vk_layer_config.h"') |
Courtney Goeltzenleuchter | 03f1c8c | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 1548 | header_txt.append('#include "vk_layer_extension_utils.h"') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1549 | header_txt.append('#include "vk_enum_validate_helper.h"') |
| 1550 | header_txt.append('#include "vk_struct_validate_helper.h"') |
| 1551 | header_txt.append('//The following is #included again to catch certain OS-specific functions being used:') |
Tobin Ehlis | 7a51d90 | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1552 | header_txt.append('#include "vk_loader_platform.h"\n') |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1553 | header_txt.append('#include "vk_layer_msg.h"\n') |
| 1554 | header_txt.append('#include "vk_layer_table.h"\n') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1555 | header_txt.append('') |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1556 | header_txt.append('') |
| 1557 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
| 1558 | header_txt.append('') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1559 | header_txt.append('using namespace std;') |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1560 | for ty in self.thread_check_dispatchable_objects: |
| 1561 | header_txt.append('static unordered_map<%s, loader_platform_thread_id> %sObjectsInUse;' % (ty, ty)) |
| 1562 | for ty in self.thread_check_nondispatchable_objects: |
| 1563 | header_txt.append('static unordered_map<uint64_t, loader_platform_thread_id> %sObjectsInUse;' % ty) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1564 | header_txt.append('static int threadingLockInitialized = 0;') |
| 1565 | header_txt.append('static loader_platform_thread_mutex threadingLock;') |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1566 | header_txt.append('static loader_platform_thread_cond threadingCond;') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1567 | header_txt.append('static int printLockInitialized = 0;') |
| 1568 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1569 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1570 | for ty in self.thread_check_dispatchable_objects: |
| 1571 | header_txt.append(self.generate_useObject(ty, "object")) |
| 1572 | header_txt.append(self.generate_finishUsingObject(ty, "object")) |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1573 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1574 | for ty in self.thread_check_nondispatchable_objects: |
| 1575 | header_txt.append(self.generate_useObject(ty, "object.handle")) |
| 1576 | header_txt.append(self.generate_finishUsingObject(ty, "object.handle")) |
| 1577 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1578 | return "\n".join(header_txt) |
| 1579 | |
| 1580 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 1c7c65d | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1581 | if proto.name in [ 'DbgCreateMsgCallback' ]: |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1582 | # use default version |
| 1583 | return None |
| 1584 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
| 1585 | ret_val = '' |
| 1586 | stmt = '' |
| 1587 | funcs = [] |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1588 | table = 'device' |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1589 | if proto.ret != "void": |
Jon Ashburn | 53c1677 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1590 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1591 | stmt = " return result;\n" |
Jon Ashburn | 2666e2f | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1592 | if proto_is_global(proto): |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1593 | table = 'instance' |
Jon Ashburn | 52c1d73 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1594 | |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1595 | # Memory range calls are special in needed thread checking within structs |
| 1596 | if proto.name in ["FlushMappedMemoryRanges","InvalidateMappedMemoryRanges"]: |
| 1597 | funcs.append('%s%s\n' |
| 1598 | '{\n' |
Tony Barbour | b2cc40a | 2015-07-13 15:28:47 -0600 | [diff] [blame] | 1599 | ' for (uint32_t i=0; i<memRangeCount; i++) {\n' |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1600 | ' useObject(pMemRanges[i].mem, "VkDeviceMemory");\n' |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1601 | ' }\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1602 | ' %s%s_dispatch_table(%s)->%s;\n' |
Tony Barbour | b2cc40a | 2015-07-13 15:28:47 -0600 | [diff] [blame] | 1603 | ' for (uint32_t i=0; i<memRangeCount; i++) {\n' |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1604 | ' finishUsingObject(pMemRanges[i].mem);\n' |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1605 | ' }\n' |
| 1606 | '%s' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1607 | '}' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call(), stmt)) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1608 | return "\n".join(funcs) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1609 | # All functions that do a Get are thread safe |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1610 | if 'Get' in proto.name: |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1611 | return None |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1612 | # All WSI functions are thread safe |
| 1613 | if 'WSI' in proto.name: |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1614 | return None |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1615 | # Initialize in early calls |
Courtney Goeltzenleuchter | be63799 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1616 | if proto.name == "CreateDevice": |
| 1617 | funcs.append('%s' % self.lineinfo.get()) |
| 1618 | funcs.append('%s%s\n' |
| 1619 | '{\n' |
| 1620 | ' %sdevice_dispatch_table(*pDevice)->%s;\n' |
| 1621 | '%s' |
| 1622 | '}' % (qual, decl, ret_val, proto.c_call(), stmt)) |
| 1623 | return "\n".join(funcs) |
| 1624 | elif proto.params[0].ty == "VkPhysicalDevice": |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1625 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1626 | funcs.append('%s%s\n' |
| 1627 | '{\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1628 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1629 | '%s' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1630 | '}' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call(), stmt)) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1631 | return "\n".join(funcs) |
| 1632 | # Functions changing command buffers need thread safe use of first parameter |
| 1633 | if proto.params[0].ty == "VkCmdBuffer": |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1634 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1635 | funcs.append('%s%s\n' |
| 1636 | '{\n' |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1637 | ' useObject(%s, "%s");\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1638 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1639 | ' finishUsingObject(%s);\n' |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1640 | '%s' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1641 | '}' % (qual, decl, proto.params[0].name, proto.params[0].ty, ret_val, table, proto.params[0].name, proto.c_call(), proto.params[0].name, stmt)) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1642 | return "\n".join(funcs) |
| 1643 | # Non-Cmd functions that do a Wait are thread safe |
| 1644 | if 'Wait' in proto.name: |
| 1645 | return None |
| 1646 | # Watch use of certain types of objects passed as any parameter |
| 1647 | checked_params = [] |
| 1648 | for param in proto.params: |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1649 | if param.ty in self.thread_check_dispatchable_objects or param.ty in self.thread_check_nondispatchable_objects: |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1650 | checked_params.append(param) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1651 | if proto.name == "DestroyDevice": |
| 1652 | funcs.append('%s%s\n' |
| 1653 | '{\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1654 | ' dispatch_key key = get_dispatch_key(device);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1655 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1656 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1657 | ' return result;\n' |
| 1658 | '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) |
| 1659 | return "\n".join(funcs); |
| 1660 | elif proto.name == "DestroyInstance": |
| 1661 | funcs.append('%s%s\n' |
| 1662 | '{\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1663 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1664 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 9f17194 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1665 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1666 | ' return result;\n' |
| 1667 | '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) |
| 1668 | return "\n".join(funcs); |
Courtney Goeltzenleuchter | f4a2eba | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1669 | elif proto.name == "CreateInstance": |
| 1670 | funcs.append('%s%s\n' |
| 1671 | '{\n' |
| 1672 | ' loader_platform_thread_once(&initOnce, initThreading);\n' |
| 1673 | '\n' |
| 1674 | ' %s %s_dispatch_table(*pInstance)->CreateInstance(pCreateInfo, pInstance);\n' |
| 1675 | '\n' |
| 1676 | ' if (result == VK_SUCCESS) {\n' |
Courtney Goeltzenleuchter | 18061cd | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1677 | ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->ppEnabledExtensionNames);\n' |
Courtney Goeltzenleuchter | f4a2eba | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1678 | ' VkLayerInstanceDispatchTable *pTable = instance_dispatch_table(*pInstance);\n' |
| 1679 | ' debug_report_init_instance_extension_dispatch_table(\n' |
| 1680 | ' pTable,\n' |
| 1681 | ' pTable->GetInstanceProcAddr,\n' |
| 1682 | ' *pInstance);\n' |
| 1683 | ' }\n' |
| 1684 | ' return result;\n' |
| 1685 | '}\n' % (qual, decl, ret_val, table)) |
| 1686 | return "\n".join(funcs); |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1687 | if len(checked_params) == 0: |
| 1688 | return None |
| 1689 | # Surround call with useObject and finishUsingObject for each checked_param |
Tobin Ehlis | fde2fc3 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1690 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1691 | funcs.append('%s%s' % (qual, decl)) |
| 1692 | funcs.append('{') |
| 1693 | for param in checked_params: |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1694 | funcs.append(' useObject(%s, "%s");' % (param.name, param.ty)) |
Mark Lobodzinski | bbbc484 | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1695 | funcs.append(' %s%s_dispatch_table(%s)->%s;' % (ret_val, table, proto.params[0].name, proto.c_call())) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1696 | for param in checked_params: |
Mike Stroyan | c0e49b2 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1697 | funcs.append(' finishUsingObject(%s);' % param.name) |
Mike Stroyan | ae0eafd | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1698 | funcs.append('%s' |
| 1699 | '}' % stmt) |
| 1700 | return "\n".join(funcs) |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1701 | |
| 1702 | def generate_body(self): |
| 1703 | self.layer_name = "Threading" |
Mike Stroyan | 354ed67 | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1704 | body = [self._generate_layer_initialization(True, lockname='threading', condname='threading'), |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1705 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | ce445ad | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 1706 | self._generate_layer_gpa_function(extensions=[], |
| 1707 | instance_extensions=['msg_callback_get_proc_addr']), |
| 1708 | self._gen_create_msg_callback(), |
| 1709 | self._gen_destroy_msg_callback()] |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1710 | return "\n\n".join(body) |
| 1711 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1712 | def main(): |
| 1713 | subcommands = { |
| 1714 | "layer-funcs" : LayerFuncsSubcommand, |
| 1715 | "layer-dispatch" : LayerDispatchSubcommand, |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1716 | "Generic" : GenericLayerSubcommand, |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1717 | "APIDump" : APIDumpSubcommand, |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1718 | "ObjectTracker" : ObjectTrackerSubcommand, |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1719 | "Threading" : ThreadingSubcommand, |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1720 | } |
| 1721 | |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1722 | if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]): |
| 1723 | print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1724 | print |
Tobin Ehlis | 2f3726c | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1725 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1726 | exit(1) |
| 1727 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1728 | hfp = vk_helper.HeaderFileParser(sys.argv[2]) |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1729 | hfp.parse() |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1730 | vk_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1731 | vk_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1732 | vk_helper.struct_dict = hfp.get_struct_dict() |
| 1733 | vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1734 | vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1735 | vk_helper.types_dict = hfp.get_types_dict() |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1736 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1737 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1738 | subcmd.run() |
| 1739 | |
| 1740 | if __name__ == "__main__": |
| 1741 | main() |