Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | # VK |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 4 | # |
| 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 | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 29 | import os |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 30 | import re |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 31 | |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 32 | import vulkan |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 33 | import vk_helper |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 34 | from source_line_info import sourcelineinfo |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 35 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 36 | def proto_is_global(proto): |
Courtney Goeltzenleuchter | 110fdf9 | 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 | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 38 | return True |
| 39 | else: |
| 40 | return False |
| 41 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 42 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | d8e229c | 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 | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 45 | |
Mark Lobodzinski | 7c75b85 | 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 | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 50 | class Subcommand(object): |
| 51 | def __init__(self, argv): |
| 52 | self.argv = argv |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 53 | self.headers = vulkan.headers |
| 54 | self.protos = vulkan.protos |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 55 | self.no_addr = False |
| 56 | self.layer_name = "" |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 57 | self.lineinfo = sourcelineinfo() |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 58 | |
| 59 | def run(self): |
Tobin Ehlis | 12076fc | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 84 | * Vulkan |
Tobin Ehlis | 12076fc | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 117 | def _get_printf_params(self, vk_type, name, output_param, cpp=False): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 118 | # TODO : Need ENUM and STRUCT checks here |
Courtney Goeltzenleuchter | d8e229c | 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 | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 120 | return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name)) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | if "char*" == vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 122 | return ("%s", name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 123 | if "uint64" in vk_type: |
| 124 | if '*' in vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 125 | return ("%lu", "*%s" % name) |
| 126 | return ("%lu", name) |
Tobin Ehlis | a30e7e5 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 131 | if "size" in vk_type: |
| 132 | if '*' in vk_type: |
Chia-I Wu | 99ff89d | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 133 | return ("%zu", "*%s" % name) |
| 134 | return ("%zu", name) |
Courtney Goeltzenleuchter | d8e229c | 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 | 99f8867 | 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 | 12076fc | 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 | cd2a099 | 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 | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 142 | return ("%u", name) |
Tobin Ehlis | b870cbb | 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 | d8e229c | 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 | 99f8867 | 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 | 12076fc | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 148 | if '*' in vk_type: |
Tobin Ehlis | d2b88e8 | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 149 | if 'pUserData' == name: |
| 150 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Tobin Ehlis | c62cb89 | 2015-04-17 13:26:33 -0600 | [diff] [blame] | 151 | if 'const' in vk_type.lower(): |
| 152 | return ("%p", "(void*)(%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 153 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 154 | return ("%i", name) |
Tobin Ehlis | 3a1cc8d | 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 | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 156 | if "VkFormat" == vk_type: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 157 | if cpp: |
| 158 | return ("%p", "&%s" % name) |
Courtney Goeltzenleuchter | c729b3a | 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 | e727157 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 160 | if output_param: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 161 | return ("%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 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 | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 163 | return ("%p", "(void*)(&%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 164 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 165 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 166 | def _gen_create_msg_callback(self): |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 167 | r_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 168 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | f579fa6 | 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 | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 170 | r_body.append('{') |
Mark Lobodzinski | fae7885 | 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 | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 183 | r_body.append('}') |
| 184 | return "\n".join(r_body) |
| 185 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 186 | def _gen_destroy_msg_callback(self): |
| 187 | r_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 188 | r_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | f579fa6 | 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 | fae7885 | 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 | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 201 | r_body.append('}') |
| 202 | return "\n".join(r_body) |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 203 | |
Tony Barbour | 59a4732 | 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 | 110fdf9 | 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 | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 220 | ggep_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame] | 221 | else: |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 222 | ggep_body.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 223 | ggep_body.append('static const VkLayerProperties globalLayerProps[] = {') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 224 | ggep_body.append(' {') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 225 | ggep_body.append(' "%s",' % layer) |
Courtney Goeltzenleuchter | 110fdf9 | 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 | 59a4732 | 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 | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 233 | ggep_body.append('') |
Courtney Goeltzenleuchter | 110fdf9 | 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 | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 235 | ggep_body.append('{') |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 236 | ggep_body.append(' return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);') |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 237 | ggep_body.append('}') |
| 238 | return "\n".join(ggep_body) |
| 239 | |
Courtney Goeltzenleuchter | 3f9f7c4 | 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 | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 247 | gpdlp_body.append('static const VkLayerProperties deviceLayerProps[] = {') |
Courtney Goeltzenleuchter | 3f9f7c4 | 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 | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 257 | gpdlp_body.append(' return util_GetLayerProperties(ARRAY_SIZE(deviceLayerProps), deviceLayerProps, pCount, pProperties);') |
Courtney Goeltzenleuchter | 3f9f7c4 | 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 | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 262 | def _generate_dispatch_entrypoints(self, qual=""): |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 263 | if qual: |
| 264 | qual += " " |
| 265 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 266 | funcs = [] |
| 267 | intercepted = [] |
| 268 | for proto in self.protos: |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 269 | if proto.name == "GetDeviceProcAddr" or proto.name == "GetInstanceProcAddr": |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 270 | continue |
Mike Stroyan | 70c05e8 | 2015-04-08 10:27:43 -0600 | [diff] [blame] | 271 | else: |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 272 | intercept = self.generate_intercept(proto, qual) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 273 | if intercept is None: |
| 274 | # fill in default intercept for certain entrypoints |
Courtney Goeltzenleuchter | f579fa6 | 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 | 59a4732 | 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 | 110fdf9 | 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 | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 287 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 288 | if intercept is not None: |
| 289 | funcs.append(intercept) |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 290 | if not "WSI" in proto.name: |
| 291 | intercepted.append(proto) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 292 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 293 | prefix="vk" |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 294 | lookups = [] |
| 295 | for proto in intercepted: |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 296 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
| 297 | lookups.append(" return (void*) %s%s;" % |
| 298 | (prefix, proto.name)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 299 | |
| 300 | # add customized layer_intercept_proc |
| 301 | body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 302 | body.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 303 | body.append("static inline void* layer_intercept_proc(const char *name)") |
| 304 | body.append("{") |
| 305 | body.append(generate_get_proc_addr_check("name")) |
| 306 | body.append("") |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 307 | body.append(" name += 2;") |
Mike Stroyan | 938c253 | 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 | f6b33db | 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 | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 315 | if not proto_is_global(proto): |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 316 | continue |
| 317 | |
| 318 | if not proto in intercepted: |
| 319 | continue |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 320 | if proto.name == "CreateDevice": |
| 321 | continue |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 322 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
| 323 | lookups.append(" return (void*) %s%s;" % (prefix, proto.name)) |
| 324 | |
| 325 | body.append("static inline void* layer_intercept_instance_proc(const char *name)") |
| 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 | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 335 | funcs.append("\n".join(body)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 336 | return "\n\n".join(funcs) |
| 337 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 338 | def _generate_extensions(self): |
| 339 | exts = [] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 340 | exts.append('%s' % self.lineinfo.get()) |
Courtney Goeltzenleuchter | f579fa6 | 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 | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 343 | return "\n".join(exts) |
| 344 | |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 345 | def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]): |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 346 | func_body = [] |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 347 | # |
Courtney Goeltzenleuchter | 3f9f7c4 | 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 | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 349 | # |
| 350 | if self.layer_name == 'ObjectTracker': |
| 351 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
| 352 | "{\n" |
| 353 | " void* addr;\n" |
| 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" |
| 360 | " return (void *) vkGetDeviceProcAddr;\n" |
| 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 | 3f9f7c4 | 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 | fae7885 | 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 | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 371 | func_body.append(' if (my_device_data->%s) {' % ext_enable) |
Mark Lobodzinski | fae7885 | 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' |
| 375 | ' %sreturn reinterpret_cast<void*>(%s);' % (extra_space, ext_name, extra_space, ext_name)) |
| 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)) |
| 382 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
| 383 | "{\n" |
| 384 | " void* addr;\n" |
| 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" |
| 391 | " return (void *) vkGetInstanceProcAddr;\n" |
| 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 | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 397 | |
Mark Lobodzinski | fae7885 | 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()) |
| 416 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n" |
| 417 | "{\n" |
| 418 | " void* addr;\n" |
| 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" |
| 426 | " return (void *) vkGetDeviceProcAddr;\n" |
| 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' |
| 442 | ' return reinterpret_cast<void*>(%s);' % (extra_space, ext_name, ext_name)) |
| 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") |
| 452 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
| 453 | "{\n" |
| 454 | " void* addr;\n" |
| 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" |
| 462 | " return (void *) vkGetInstanceProcAddr;\n" |
| 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" |
| 470 | " void *fptr;\n" |
| 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 | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 480 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 481 | |
Mike Stroyan | ed238bb | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 483 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 484 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 485 | func_body.append('static void init%s(void)\n' |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 486 | '{\n' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 487 | if init_opts: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 488 | func_body.append('%s' % self.lineinfo.get()) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 489 | func_body.append(' const char *strOpt;') |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 490 | func_body.append(' // initialize %s options' % self.layer_name) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 491 | func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportFlags);' % self.layer_name) |
Mike Stroyan | 3e3a1eb | 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 | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 493 | func_body.append('') |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 494 | func_body.append(' if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 495 | func_body.append(' {') |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 496 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name) |
Jon Ashburn | d6badbc | 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 | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 505 | if lockname is not None: |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 506 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | 36f1b46 | 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 | ed238bb | 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 | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 513 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 514 | func_body.append(" }") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 515 | func_body.append("}\n") |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 516 | func_body.append('') |
Tobin Ehlis | 12076fc | 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 | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 521 | return '#include <vk_layer.h>\n#include "loader.h"' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 522 | |
| 523 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 524 | return self._generate_dispatch_entrypoints("static") |
Tobin Ehlis | 12076fc | 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 | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 531 | return self._generate_layer_initialization() |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 532 | |
| 533 | class GenericLayerSubcommand(Subcommand): |
| 534 | def generate_header(self): |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 535 | gen_header = [] |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 536 | gen_header.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fb5437a | 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 | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 541 | gen_header.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 542 | gen_header.append('#include "vk_layer.h"') |
Mark Lobodzinski | fb5437a | 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 | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 545 | gen_header.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | a0cb02e | 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 | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 549 | gen_header.append('#include "vk_layer_extension_utils.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 550 | gen_header.append('') |
Courtney Goeltzenleuchter | 79a5a96 | 2015-07-07 17:51:45 -0600 | [diff] [blame] | 551 | gen_header.append('#include "generic.h"') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 552 | gen_header.append('') |
Tobin Ehlis | a30e7e5 | 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 | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 556 | gen_header.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 557 | gen_header.append('struct devExts {') |
| 558 | gen_header.append(' bool wsi_lunarg_enabled;') |
| 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('{') |
| 564 | gen_header.append(' uint32_t i, ext_idx;') |
| 565 | gen_header.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 566 | gen_header.append(' deviceExtMap[pDisp].wsi_lunarg_enabled = false;') |
| 567 | gen_header.append(' for (i = 0; i < pCreateInfo->extensionCount; i++) {') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 568 | gen_header.append(' if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_WSI_LUNARG_EXTENSION_NAME) == 0)') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 569 | gen_header.append(' deviceExtMap[pDisp].wsi_lunarg_enabled = true;') |
| 570 | gen_header.append('') |
| 571 | gen_header.append(' }') |
| 572 | gen_header.append('}') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 573 | gen_header.append('') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 574 | return "\n".join(gen_header) |
Tobin Ehlis | 7a314ea | 2015-07-07 11:02:44 -0600 | [diff] [blame] | 575 | |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 576 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 577 | if proto.name in [ 'GetGlobalLayerProperties', 'GetGlobalExtensionProperties', 'GetPhysicalDeviceLayerProperties', 'GetPhysicalDeviceExtensionProperties' ]: |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 578 | # use default version |
| 579 | return None |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 580 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 581 | ret_val = '' |
| 582 | stmt = '' |
| 583 | funcs = [] |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 584 | table = '' |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 585 | if proto_is_global(proto): |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 586 | table = 'Instance' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 587 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 588 | funcs.append('%s' % self.lineinfo.get()) |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 589 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 590 | stmt = " return result;\n" |
Jon Ashburn | 8ced421 | 2015-05-22 12:01:50 -0600 | [diff] [blame] | 591 | if proto.name == "CreateDevice": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 592 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 593 | funcs.append('%s%s\n' |
| 594 | '{\n' |
Mark Lobodzinski | fb5437a | 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 | a05dbaa | 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 | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 598 | ' %sdevice_dispatch_table(*pDevice)->%s;\n' |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 599 | ' if (result == VK_SUCCESS) {\n' |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 600 | ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->ppEnabledExtensionNames);\n' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 601 | ' createDeviceRegisterExtensions(pCreateInfo, *pDevice);\n' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 602 | ' }\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 603 | ' sprintf(str, "Completed layered %s\\n");\n' |
Tony Barbour | a05dbaa | 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 | fb5437a | 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 | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 609 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 610 | funcs.append('%s%s\n' |
| 611 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 612 | ' dispatch_key key = get_dispatch_key(device);\n' |
Jon Ashburn | 747f2b6 | 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 | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 616 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 617 | ' return res;\n' |
| 618 | '}\n' % (qual, decl)) |
| 619 | elif proto.name == "DestroyInstance": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 620 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 621 | funcs.append('%s%s\n' |
| 622 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 623 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 624 | ' VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 625 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 626 | ' return res;\n' |
| 627 | '}\n' % (qual, decl)) |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 628 | else: |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 629 | funcs.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fb5437a | 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 | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 640 | funcs.append('%s%s\n' |
| 641 | '{\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 642 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 643 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 644 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), stmt)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 645 | return "\n\n".join(funcs) |
| 646 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 647 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 648 | self.layer_name = "Generic" |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 649 | extensions=[('wsi_lunarg_enabled', |
| 650 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
| 651 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI'])] |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 652 | body = [self._generate_layer_initialization(True), |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 653 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 654 | self._gen_create_msg_callback(), |
| 655 | self._gen_destroy_msg_callback(), |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 656 | self._generate_layer_gpa_function(extensions)] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 657 | |
| 658 | return "\n\n".join(body) |
| 659 | |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 660 | class APIDumpSubcommand(Subcommand): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 661 | def generate_header(self): |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 662 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 663 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | e78dbd8 | 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 | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 667 | header_txt.append('#include <string.h>') |
Tobin Ehlis | e78dbd8 | 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 | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 694 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 695 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 696 | header_txt.append('#include "vk_layer.h"') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 697 | header_txt.append('#include "vk_struct_string_helper_cpp.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 698 | header_txt.append('#include "vk_layer_table.h"') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 699 | header_txt.append('#include "vk_layer_extension_utils.h"') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 700 | header_txt.append('#include <unordered_map>') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 701 | header_txt.append('') |
Ian Elliott | 655cad7 | 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 | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 703 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 704 | header_txt.append('') |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 705 | header_txt.append('static VkBaseLayerObject *pCurObj;') |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 706 | header_txt.append('static bool g_APIDumpDetailed = true;') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 707 | header_txt.append('') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 708 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 709 | header_txt.append('') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 710 | header_txt.append('static int printLockInitialized = 0;') |
Tobin Ehlis | e78dbd8 | 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 | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 713 | header_txt.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | a30e7e5 | 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 | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 716 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 717 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | d009bae | 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 | 2d4ab1e | 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 | d009bae | 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 | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 728 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | d009bae | 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 | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 733 | header_txt.append('struct devExts {') |
| 734 | header_txt.append(' bool wsi_lunarg_enabled;') |
| 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('{') |
| 741 | header_txt.append(' uint32_t i, ext_idx;') |
| 742 | header_txt.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);') |
| 743 | header_txt.append(' deviceExtMap[pDisp].wsi_lunarg_enabled = false;') |
| 744 | header_txt.append(' for (i = 0; i < pCreateInfo->extensionCount; i++) {') |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 745 | header_txt.append(' if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_WSI_LUNARG_EXTENSION_NAME) == 0)') |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 746 | header_txt.append(' deviceExtMap[pDisp].wsi_lunarg_enabled = true;') |
| 747 | header_txt.append('') |
| 748 | header_txt.append(' }') |
| 749 | header_txt.append('}') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 750 | header_txt.append('') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 751 | return "\n".join(header_txt) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 752 | |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 753 | def generate_init(self): |
| 754 | func_body = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 755 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 756 | func_body.append('#include "vk_dispatch_table_helper.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 757 | func_body.append('#include "vk_layer_config.h"') |
Tobin Ehlis | e78dbd8 | 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 | a2b199c | 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 | e78dbd8 | 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 | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 790 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | e78dbd8 | 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 | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 818 | func_body.append('%s' % self.lineinfo.get()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 819 | func_body.append(' ConfigureOutputStream(writeToFile, flushAfterWrite);') |
| 820 | func_body.append('') |
Tobin Ehlis | e78dbd8 | 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 | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 830 | |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 831 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 832 | if proto.name in [ 'GetGlobalLayerProperties','GetGlobalExtensionProperties','GetPhysicalDeviceLayerProperties','GetPhysicalDeviceExtensionProperties']: |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 833 | return None |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 834 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | bf237d7 | 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 | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 840 | if 'AllocDescriptorSets' in proto.name: |
Mike Stroyan | bf237d7 | 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 | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 845 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 846 | stmt = " return result;\n" |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 847 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n ' |
Tobin Ehlis | 08fafd0 | 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 | e78dbd8 | 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 | bf237d7 | 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) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 863 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 864 | if "%p" == pft: |
| 865 | log_func_no_addr += '%s = address, ' % (p.name) |
| 866 | else: |
| 867 | log_func_no_addr += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | 0854174 | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 868 | if prev_count_name != '' and (prev_count_name.replace('Count', '')[1:] in p.name): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 869 | sp_param_dict[pindex] = prev_count_name |
Tobin Ehlis | 0854174 | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 870 | prev_count_name = '' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 871 | elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount': |
| 872 | sp_param_dict[pindex] = '*pCount' |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 873 | elif vk_helper.is_type(p.ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 874 | sp_param_dict[pindex] = 'index' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 875 | if p.name.endswith('Count'): |
| 876 | if '*' in p.ty: |
| 877 | prev_count_name = "*%s" % p.name |
| 878 | else: |
| 879 | prev_count_name = p.name |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 880 | pindex += 1 |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 881 | log_func = log_func.strip(', ') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 882 | log_func_no_addr = log_func_no_addr.strip(', ') |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 883 | if proto.ret == "VkResult": |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 884 | log_func += ') = " << string_VkResult((VkResult)result) << endl' |
| 885 | log_func_no_addr += ') = " << string_VkResult((VkResult)result) << endl' |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 886 | elif proto.ret == "void*": |
| 887 | log_func += ') = " << result << endl' |
| 888 | log_func_no_addr += ') = " << result << endl' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 889 | else: |
| 890 | log_func += ')\\n"' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 891 | log_func_no_addr += ')\\n"' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 892 | log_func += ';' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 893 | log_func_no_addr += ';' |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 894 | log_func += '\n }\n else {%s\n }' % log_func_no_addr; |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 895 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 896 | #print("Proto %s has param_dict: %s" % (proto.name, sp_param_dict)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 897 | if len(sp_param_dict) > 0: |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 898 | indent = ' ' |
| 899 | log_func += '\n%sif (g_APIDumpDetailed) {' % indent |
| 900 | indent += ' ' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 901 | i_decl = False |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 902 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 903 | log_func += '\n%sstring tmp_str;' % indent |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 904 | for sp_index in sp_param_dict: |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 905 | #print("sp_index: %s" % str(sp_index)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 906 | if 'index' == sp_param_dict[sp_index]: |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 907 | cis_print_func = 'vk_print_%s' % (proto.params[sp_index].ty.replace('const ', '').strip('*').lower()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 908 | local_name = proto.params[sp_index].name |
| 909 | if '*' not in proto.params[sp_index].ty: |
| 910 | local_name = '&%s' % proto.params[sp_index].name |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 911 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 912 | log_func += '\n%sif (%s) {' % (indent, local_name) |
| 913 | indent += ' ' |
| 914 | log_func += '\n%stmp_str = %s(%s, " ");' % (indent, cis_print_func, local_name) |
| 915 | log_func += '\n%s(*outputStream) << " %s (" << %s << ")" << endl << tmp_str << endl;' % (indent, local_name, local_name) |
| 916 | indent = indent[4:] |
| 917 | log_func += '\n%s}' % (indent) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 918 | else: # We have a count value stored to iterate over an array |
| 919 | print_cast = '' |
| 920 | print_func = '' |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 921 | if vk_helper.is_type(proto.params[sp_index].ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 922 | print_cast = '&' |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 923 | print_func = 'vk_print_%s' % proto.params[sp_index].ty.replace('const ', '').strip('*').lower() |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 924 | else: |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 925 | print_cast = '' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 926 | print_func = 'string_convert_helper' |
| 927 | #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name |
Tobin Ehlis | a30e7e5 | 2015-07-06 14:02:36 -0600 | [diff] [blame] | 928 | if proto.params[sp_index].ty.strip('*').replace('const ', '') in vulkan.object_non_dispatch_list: |
| 929 | cis_print_func = 'tmp_str = %s(%s%s[i].handle, " ");' % (print_func, print_cast, proto.params[sp_index].name) |
| 930 | else: |
| 931 | cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 932 | if not i_decl: |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 933 | log_func += '\n%suint32_t i;' % (indent) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 934 | i_decl = True |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 935 | log_func += '\n%sif (%s) {' % (indent, proto.params[sp_index].name) |
| 936 | indent += ' ' |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 937 | log_func += '\n%s' % self.lineinfo.get() |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 938 | log_func += '\n%sfor (i = 0; i < %s; i++) {' % (indent, sp_param_dict[sp_index]) |
| 939 | indent += ' ' |
| 940 | log_func += '\n%s%s' % (indent, cis_print_func) |
Tobin Ehlis | 45a23a8 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 941 | log_func += '\n%sif (StreamControl::writeAddress == true) {' % (indent) |
| 942 | indent += ' ' |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 943 | 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) |
| 944 | indent = indent[4:] |
Tobin Ehlis | 45a23a8 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 945 | log_func += '\n%s} else {' % (indent) |
| 946 | indent += ' ' |
| 947 | log_func += '\n%s(*outputStream) << " %s[" << i << "] (address)" << endl << " address" << endl;' % (indent, proto.params[sp_index].name) |
| 948 | indent = indent[4:] |
| 949 | log_func += '\n%s}' % (indent) |
| 950 | indent = indent[4:] |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 951 | log_func += '\n%s}' % (indent) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 952 | indent = indent[4:] |
| 953 | log_func += '\n%s}' % (indent) |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 954 | indent = indent[4:] |
| 955 | log_func += '\n%s}' % (indent) |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 956 | table_type = '' |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 957 | if proto_is_global(proto): |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 958 | table_type = 'instance' |
| 959 | else: |
| 960 | table_type = 'device' |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 961 | |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 962 | if proto.name == "CreateInstance": |
| 963 | dispatch_param = '*' + proto.params[1].name |
| 964 | else: |
| 965 | dispatch_param = proto.params[0].name |
| 966 | |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 967 | if proto.name == "CreateDevice": |
Courtney Goeltzenleuchter | 0de9e21 | 2015-06-26 15:07:53 -0600 | [diff] [blame] | 968 | funcs.append('%s\n' % self.lineinfo.get()) |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 969 | funcs.append('%s%s\n' |
| 970 | '{\n' |
| 971 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 972 | ' %sdevice_dispatch_table(*pDevice)->%s;\n' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 973 | ' if (result == VK_SUCCESS)\n' |
| 974 | ' createDeviceRegisterExtensions(pCreateInfo, *pDevice);\n' |
| 975 | ' %s%s%s\n' |
| 976 | '%s' |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 977 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 978 | elif proto.name == "DestroyDevice": |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 979 | funcs.append('%s%s\n' |
| 980 | '{\n' |
| 981 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 982 | ' dispatch_key key = get_dispatch_key(device);\n' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 983 | ' VkLayerDispatchTable *pDisp = %s_dispatch_table(%s);\n' |
| 984 | ' %spDisp->%s;\n' |
| 985 | ' deviceExtMap.erase(pDisp);\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 986 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 987 | ' %s%s%s\n' |
| 988 | '%s' |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 989 | '}' % (qual, decl, table_type, dispatch_param, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 990 | elif proto.name == "DestroyInstance": |
| 991 | funcs.append('%s%s\n' |
| 992 | '{\n' |
| 993 | ' using namespace StreamControl;\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 994 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 995 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 996 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 997 | ' %s%s%s\n' |
| 998 | '%s' |
| 999 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 1000 | else: |
| 1001 | funcs.append('%s%s\n' |
| 1002 | '{\n' |
| 1003 | ' using namespace StreamControl;\n' |
| 1004 | ' %s%s_dispatch_table(%s)->%s;\n' |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1005 | ' %s%s%s\n' |
| 1006 | '%s' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1007 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1008 | return "\n\n".join(funcs) |
| 1009 | |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1010 | def generate_body(self): |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1011 | self.layer_name = "APIDump" |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1012 | extensions=[('wsi_lunarg_enabled', |
| 1013 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
| 1014 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI'])] |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1015 | body = [self.generate_init(), |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1016 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1017 | self._generate_layer_gpa_function(extensions)] |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1018 | return "\n\n".join(body) |
| 1019 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1020 | class ObjectTrackerSubcommand(Subcommand): |
| 1021 | def generate_header(self): |
| 1022 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1023 | header_txt.append('%s' % self.lineinfo.get()) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1024 | header_txt.append('#include <stdio.h>') |
| 1025 | header_txt.append('#include <stdlib.h>') |
| 1026 | header_txt.append('#include <string.h>') |
| 1027 | header_txt.append('#include <inttypes.h>') |
| 1028 | header_txt.append('') |
| 1029 | header_txt.append('#include "vulkan.h"') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1030 | header_txt.append('#include "vk_loader_platform.h"') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1031 | header_txt.append('') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1032 | header_txt.append('#include <unordered_map>') |
| 1033 | header_txt.append('using namespace std;') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1034 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1035 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1036 | header_txt.append('#include "vk_layer_config.h"') |
| 1037 | header_txt.append('#include "vk_layer_msg.h"') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1038 | header_txt.append('#include "vk_debug_report_lunarg.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1039 | header_txt.append('#include "vk_layer_table.h"') |
| 1040 | header_txt.append('#include "vk_layer_data.h"') |
| 1041 | header_txt.append('#include "vk_layer_logging.h"') |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1042 | header_txt.append('') |
| 1043 | # NOTE: The non-autoGenerated code is in the object_track.h header file |
| 1044 | header_txt.append('#include "object_track.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1045 | header_txt.append('') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 1046 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1047 | header_txt.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1048 | return "\n".join(header_txt) |
| 1049 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1050 | def generate_maps(self): |
| 1051 | maps_txt = [] |
| 1052 | for o in vulkan.core.objects: |
| 1053 | maps_txt.append('unordered_map<const void*, OBJTRACK_NODE*> %sMap;' % (o)) |
| 1054 | maps_txt.append('unordered_map<const void*, OBJTRACK_NODE*> VkSwapChainWSIMap;') |
| 1055 | return "\n".join(maps_txt) |
| 1056 | |
| 1057 | def generate_procs(self): |
| 1058 | procs_txt = [] |
| 1059 | for o in vulkan.core.objects: |
| 1060 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1061 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1062 | procs_txt.append('static void create_obj(%s dispatchable_object, %s vkObj, VkDbgObjectType objType)' % (o, o)) |
| 1063 | procs_txt.append('{') |
| 1064 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, reinterpret_cast<VkUintPtrLeast64>(vkObj), 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1065 | procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType),') |
| 1066 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(vkObj));') |
| 1067 | else: |
| 1068 | procs_txt.append('static void create_obj(VkDevice dispatchable_object, %s vkObj, VkDbgObjectType objType)' % (o)) |
| 1069 | procs_txt.append('{') |
| 1070 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, objType, vkObj.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1071 | procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDbgObjectType(objType),') |
| 1072 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(vkObj.handle));') |
| 1073 | procs_txt.append('') |
| 1074 | procs_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;') |
| 1075 | procs_txt.append(' pNewObjNode->objType = objType;') |
| 1076 | procs_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;') |
| 1077 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1078 | procs_txt.append(' pNewObjNode->vkObj = reinterpret_cast<VkUintPtrLeast64>(vkObj);') |
| 1079 | procs_txt.append(' %sMap[vkObj] = pNewObjNode;' % (o)) |
| 1080 | else: |
| 1081 | procs_txt.append(' pNewObjNode->vkObj = reinterpret_cast<VkUintPtrLeast64>(vkObj.handle);') |
| 1082 | procs_txt.append(' %sMap[(void*)vkObj.handle] = pNewObjNode;' % (o)) |
| 1083 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(objType);') |
| 1084 | procs_txt.append(' numObjs[objIndex]++;') |
| 1085 | procs_txt.append(' numTotalObjs++;') |
| 1086 | procs_txt.append('}') |
| 1087 | procs_txt.append('') |
| 1088 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1089 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1090 | procs_txt.append('static void validate_object(%s dispatchable_object, %s object)' % (o, o)) |
| 1091 | else: |
| 1092 | procs_txt.append('static void validate_object(VkDevice dispatchable_object, %s object)' % (o)) |
| 1093 | procs_txt.append('{') |
| 1094 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1095 | procs_txt.append(' if (%sMap.find(object) == %sMap.end()) {' % (o, o)) |
| 1096 | 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 | 2717d13 | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1097 | procs_txt.append(' "Invalid %s Object %%p",reinterpret_cast<VkUintPtrLeast64>(object));' % o) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1098 | else: |
| 1099 | procs_txt.append(' if (%sMap.find((void*)object.handle) == %sMap.end()) {' % (o, o)) |
| 1100 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
Tobin Ehlis | 2717d13 | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1101 | procs_txt.append(' "Invalid %s Object %%p",reinterpret_cast<VkUintPtrLeast64>(object.handle));' % o) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1102 | procs_txt.append(' }') |
| 1103 | procs_txt.append('}') |
| 1104 | procs_txt.append('') |
| 1105 | procs_txt.append('') |
| 1106 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1107 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1108 | procs_txt.append('static void destroy_obj(%s dispatchable_object, %s object)' % (o, o)) |
| 1109 | else: |
| 1110 | procs_txt.append('static void destroy_obj(VkDevice dispatchable_object, %s object)' % (o)) |
| 1111 | procs_txt.append('{') |
| 1112 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1113 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1114 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1115 | else: |
| 1116 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1117 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1118 | procs_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);') |
| 1119 | procs_txt.append(' assert(numTotalObjs > 0);') |
| 1120 | procs_txt.append(' numTotalObjs--;') |
| 1121 | procs_txt.append(' assert(numObjs[objIndex] > 0);') |
| 1122 | procs_txt.append(' numObjs[objIndex]--;') |
| 1123 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1124 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, pNode->objType, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1125 | procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%lu total objs remain & %lu %s objs).",') |
| 1126 | procs_txt.append(' string_VkDbgObjectType(pNode->objType), reinterpret_cast<VkUintPtrLeast64>(object), numTotalObjs, numObjs[objIndex],') |
| 1127 | else: |
| 1128 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_INFO_BIT, pNode->objType, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1129 | procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%lu total objs remain & %lu %s objs).",') |
| 1130 | procs_txt.append(' string_VkDbgObjectType(pNode->objType), reinterpret_cast<VkUintPtrLeast64>(object.handle), numTotalObjs, numObjs[objIndex],') |
| 1131 | procs_txt.append(' string_VkDbgObjectType(pNode->objType));') |
| 1132 | procs_txt.append(' delete pNode;') |
| 1133 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1134 | procs_txt.append(' %sMap.erase(object);' % (o)) |
| 1135 | procs_txt.append(' } else {') |
| 1136 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1137 | procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",') |
| 1138 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object));') |
| 1139 | procs_txt.append(' }') |
| 1140 | else: |
| 1141 | procs_txt.append(' %sMap.erase((void*)object.handle);' % (o)) |
| 1142 | procs_txt.append(' } else {') |
| 1143 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1144 | procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",') |
| 1145 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object.handle));') |
| 1146 | procs_txt.append(' }') |
| 1147 | procs_txt.append('}') |
| 1148 | procs_txt.append('') |
| 1149 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1150 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1151 | procs_txt.append('static void set_status(%s dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o, o)) |
| 1152 | procs_txt.append('{') |
| 1153 | procs_txt.append(' if (object != VK_NULL_HANDLE) {') |
| 1154 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1155 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1156 | else: |
| 1157 | procs_txt.append('static void set_status(VkDevice dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o)) |
| 1158 | procs_txt.append('{') |
| 1159 | procs_txt.append(' if (object.handle != VK_NULL_HANDLE) {') |
| 1160 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1161 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1162 | procs_txt.append(' pNode->status |= status_flag;') |
| 1163 | procs_txt.append(' return;') |
| 1164 | procs_txt.append(' }') |
| 1165 | procs_txt.append(' else {') |
| 1166 | procs_txt.append(' // If we do not find it print an error') |
| 1167 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1168 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1169 | procs_txt.append(' "Unable to set status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
| 1170 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object), string_VkDbgObjectType(objType));') |
| 1171 | else: |
| 1172 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_NONE, "OBJTRACK",') |
| 1173 | procs_txt.append(' "Unable to set status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
| 1174 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object.handle), string_VkDbgObjectType(objType));') |
| 1175 | procs_txt.append(' }') |
| 1176 | procs_txt.append(' }') |
| 1177 | procs_txt.append('}') |
| 1178 | procs_txt.append('') |
| 1179 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1180 | procs_txt.append('static VkBool32 validate_status(') |
| 1181 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1182 | procs_txt.append('%s dispatchable_object, %s object,' % (o, o)) |
| 1183 | else: |
| 1184 | procs_txt.append('VkDevice dispatchable_object, %s object,' % (o)) |
| 1185 | procs_txt.append(' VkDbgObjectType objType,') |
| 1186 | procs_txt.append(' ObjectStatusFlags status_mask,') |
| 1187 | procs_txt.append(' ObjectStatusFlags status_flag,') |
| 1188 | procs_txt.append(' VkFlags msg_flags,') |
| 1189 | procs_txt.append(' OBJECT_TRACK_ERROR error_code,') |
| 1190 | procs_txt.append(' const char *fail_msg)') |
| 1191 | procs_txt.append('{') |
| 1192 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1193 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1194 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1195 | else: |
| 1196 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1197 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1198 | procs_txt.append(' if ((pNode->status & status_mask) != status_flag) {') |
| 1199 | procs_txt.append(' char str[1024];') |
| 1200 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1201 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, pNode->objType, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1202 | procs_txt.append(' "OBJECT VALIDATION WARNING: %s object 0x%" PRIxLEAST64 ": %s", string_VkDbgObjectType(objType),') |
| 1203 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object), fail_msg);') |
| 1204 | else: |
| 1205 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, pNode->objType, object.handle, 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.handle), fail_msg);') |
| 1208 | procs_txt.append(' return VK_FALSE;') |
| 1209 | procs_txt.append(' }') |
| 1210 | procs_txt.append(' return VK_TRUE;') |
| 1211 | procs_txt.append(' }') |
| 1212 | procs_txt.append(' else {') |
| 1213 | procs_txt.append(' // If we do not find it print an error') |
| 1214 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1215 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, (VkDbgObjectType) 0, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1216 | procs_txt.append(' "Unable to obtain status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
| 1217 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object), string_VkDbgObjectType(objType));') |
| 1218 | else: |
| 1219 | procs_txt.append(' log_msg(mdd(dispatchable_object), msg_flags, (VkDbgObjectType) 0, object.handle, 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.handle), string_VkDbgObjectType(objType));') |
| 1222 | procs_txt.append(' return VK_FALSE;') |
| 1223 | procs_txt.append(' }') |
| 1224 | procs_txt.append('}') |
| 1225 | procs_txt.append('') |
| 1226 | procs_txt.append('%s' % self.lineinfo.get()) |
| 1227 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1228 | procs_txt.append('static void reset_status(%s dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o, o)) |
| 1229 | procs_txt.append('{') |
| 1230 | procs_txt.append(' if (%sMap.find(object) != %sMap.end()) {' % (o, o)) |
| 1231 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[object];' % (o)) |
| 1232 | else: |
| 1233 | procs_txt.append('static void reset_status(VkDevice dispatchable_object, %s object, VkDbgObjectType objType, ObjectStatusFlags status_flag)' % (o)) |
| 1234 | procs_txt.append('{') |
| 1235 | procs_txt.append(' if (%sMap.find((void*)object.handle) != %sMap.end()) {' % (o, o)) |
| 1236 | procs_txt.append(' OBJTRACK_NODE* pNode = %sMap[(void*)object.handle];' % (o)) |
| 1237 | procs_txt.append(' pNode->status &= ~status_flag;') |
| 1238 | procs_txt.append(' return;') |
| 1239 | procs_txt.append(' }') |
| 1240 | procs_txt.append(' else {') |
| 1241 | procs_txt.append(' // If we do not find it print an error') |
| 1242 | if o in [ 'VkInstance', 'VkPhysicalDevice', 'VkDevice', 'VkQueue', 'VkCmdBuffer']: |
| 1243 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, objType, reinterpret_cast<VkUintPtrLeast64>(object), 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",') |
| 1244 | procs_txt.append(' "Unable to reset status for non-existent object 0x%" PRIxLEAST64 " of %s type",') |
| 1245 | procs_txt.append(' reinterpret_cast<VkUintPtrLeast64>(object), string_VkDbgObjectType(objType));') |
| 1246 | else: |
| 1247 | procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, objType, object.handle, 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.handle), string_VkDbgObjectType(objType));') |
| 1250 | procs_txt.append(' }') |
| 1251 | procs_txt.append('}') |
| 1252 | procs_txt.append('') |
| 1253 | return "\n".join(procs_txt) |
| 1254 | |
| 1255 | def generate_explicit_destroy_instance(self): |
| 1256 | gedi_txt = [] |
| 1257 | gedi_txt.append('%s' % self.lineinfo.get()) |
| 1258 | gedi_txt.append('VkResult explicit_DestroyInstance(') |
| 1259 | gedi_txt.append('VkInstance instance)') |
| 1260 | gedi_txt.append('{') |
| 1261 | gedi_txt.append(' loader_platform_thread_lock_mutex(&objLock);') |
| 1262 | gedi_txt.append(' validate_object(instance, instance);') |
| 1263 | gedi_txt.append('') |
| 1264 | gedi_txt.append(' destroy_obj(instance, instance);') |
| 1265 | gedi_txt.append(' // Report any remaining objects in LL') |
| 1266 | for o in vulkan.core.objects: |
| 1267 | if o in ['VkPhysicalDevice', 'VkQueue']: |
| 1268 | continue |
| 1269 | gedi_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end(); ++it) {' % (o, o)) |
| 1270 | gedi_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
| 1271 | gedi_txt.append(' log_msg(mid(instance), VK_DBG_REPORT_ERROR_BIT, pNode->objType, pNode->vkObj, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 1272 | gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDbgObjectType(pNode->objType),') |
| 1273 | gedi_txt.append(' reinterpret_cast<VkUintPtrLeast64>(pNode->vkObj));') |
| 1274 | gedi_txt.append(' }') |
| 1275 | gedi_txt.append('') |
| 1276 | gedi_txt.append(' dispatch_key key = get_dispatch_key(instance);') |
| 1277 | gedi_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(ObjectTracker_instance_table_map, instance);') |
| 1278 | gedi_txt.append(' VkResult result = pInstanceTable->DestroyInstance(instance);') |
| 1279 | gedi_txt.append('') |
| 1280 | gedi_txt.append(' // Clean up logging callback, if any') |
| 1281 | gedi_txt.append(' layer_data *my_data = get_my_data_ptr(key, layer_data_map);') |
| 1282 | gedi_txt.append(' if (my_data->logging_callback) {') |
| 1283 | gedi_txt.append(' layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);') |
| 1284 | gedi_txt.append(' }') |
| 1285 | gedi_txt.append('') |
| 1286 | gedi_txt.append(' layer_debug_report_destroy_instance(mid(instance));') |
| 1287 | gedi_txt.append(' layer_data_map.erase(pInstanceTable);') |
| 1288 | gedi_txt.append('') |
| 1289 | gedi_txt.append(' ObjectTracker_instance_table_map.erase(key);') |
| 1290 | gedi_txt.append(' assert(ObjectTracker_instance_table_map.size() == 0 && "Should not have any instance mappings hanging around");') |
| 1291 | gedi_txt.append('') |
| 1292 | gedi_txt.append(' loader_platform_thread_unlock_mutex(&objLock);') |
| 1293 | gedi_txt.append(' return result;') |
| 1294 | gedi_txt.append('}') |
| 1295 | gedi_txt.append('') |
| 1296 | return "\n".join(gedi_txt) |
| 1297 | |
| 1298 | def generate_explicit_destroy_device(self): |
| 1299 | gedd_txt = [] |
| 1300 | gedd_txt.append('%s' % self.lineinfo.get()) |
| 1301 | gedd_txt.append('VkResult explicit_DestroyDevice(') |
| 1302 | gedd_txt.append('VkDevice device)') |
| 1303 | gedd_txt.append('{') |
| 1304 | gedd_txt.append(' loader_platform_thread_lock_mutex(&objLock);') |
| 1305 | gedd_txt.append(' validate_object(device, device);') |
| 1306 | gedd_txt.append('') |
| 1307 | gedd_txt.append(' destroy_obj(device, device);') |
| 1308 | gedd_txt.append(' // Report any remaining objects in LL') |
| 1309 | for o in vulkan.core.objects: |
| 1310 | if o in ['VkPhysicalDevice', 'VkQueue']: |
| 1311 | continue |
| 1312 | gedd_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end(); ++it) {' % (o, o)) |
| 1313 | gedd_txt.append(' OBJTRACK_NODE* pNode = it->second;') |
| 1314 | gedd_txt.append(' log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, pNode->objType, pNode->vkObj, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK",') |
| 1315 | gedd_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDbgObjectType(pNode->objType),') |
| 1316 | gedd_txt.append(' reinterpret_cast<VkUintPtrLeast64>(pNode->vkObj));') |
| 1317 | gedd_txt.append(' }') |
| 1318 | gedd_txt.append('') |
| 1319 | gedd_txt.append(" // Clean up Queue's MemRef Linked Lists") |
| 1320 | gedd_txt.append(' destroyQueueMemRefLists();') |
| 1321 | gedd_txt.append('') |
| 1322 | gedd_txt.append(' loader_platform_thread_unlock_mutex(&objLock);') |
| 1323 | gedd_txt.append('') |
| 1324 | gedd_txt.append(' dispatch_key key = get_dispatch_key(device);') |
| 1325 | gedd_txt.append(' VkLayerDispatchTable *pDisp = get_dispatch_table(ObjectTracker_device_table_map, device);') |
| 1326 | gedd_txt.append(' VkResult result = pDisp->DestroyDevice(device);') |
| 1327 | gedd_txt.append(' ObjectTracker_device_table_map.erase(key);') |
| 1328 | gedd_txt.append(' assert(ObjectTracker_device_table_map.size() == 0 && "Should not have any instance mappings hanging around");') |
| 1329 | gedd_txt.append('') |
| 1330 | gedd_txt.append(' return result;') |
| 1331 | gedd_txt.append('}') |
| 1332 | gedd_txt.append('') |
| 1333 | return "\n".join(gedd_txt) |
| 1334 | |
| 1335 | def generate_command_buffer_validates(self): |
| 1336 | cbv_txt = [] |
| 1337 | cbv_txt.append('%s' % self.lineinfo.get()) |
| 1338 | for o in ['VkPipeline', 'VkDynamicViewportState', 'VkDynamicRasterState', 'VkDynamicColorBlendState', 'VkDynamicDepthStencilState', |
| 1339 | 'VkPipelineLayout', 'VkBuffer', 'VkEvent', 'VkQueryPool', 'VkRenderPass', 'VkFramebuffer']: |
| 1340 | cbv_txt.append('static void validate_object(VkCmdBuffer dispatchable_object, %s object)' % (o)) |
| 1341 | cbv_txt.append('{') |
| 1342 | cbv_txt.append(' if (%sMap.find((void*)object.handle) == %sMap.end()) {' % (o, o)) |
| 1343 | cbv_txt.append(' log_msg(mdd(dispatchable_object), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, object.handle, 0, OBJTRACK_INVALID_OBJECT, "OBJTRACK",') |
Tobin Ehlis | 2717d13 | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1344 | cbv_txt.append(' "Invalid %s Object %%p",reinterpret_cast<VkUintPtrLeast64>(object.handle));' % (o)) |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1345 | cbv_txt.append(' }') |
| 1346 | cbv_txt.append('}') |
| 1347 | cbv_txt.append('') |
| 1348 | return "\n".join(cbv_txt) |
| 1349 | |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1350 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1351 | if proto.name in [ 'DbgCreateMsgCallback', 'GetGlobalLayerProperties', 'GetGlobalExtensionProperties','GetPhysicalDeviceLayerProperties', 'GetPhysicalDeviceExtensionProperties' ]: |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1352 | # use default version |
| 1353 | return None |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1354 | |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1355 | # Create map of object names to object type enums of the form VkName : VkObjectTypeName |
| 1356 | obj_type_mapping = {base_t : base_t.replace("Vk", "VkObjectType") for base_t in vulkan.object_type_list} |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1357 | # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES |
| 1358 | for objectName, objectTypeEnum in obj_type_mapping.items(): |
| 1359 | obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum); |
| 1360 | # Command Buffer Object doesn't follow the rule. |
| 1361 | obj_type_mapping['VkCmdBuffer'] = "VK_OBJECT_TYPE_COMMAND_BUFFER" |
Courtney Goeltzenleuchter | ee4027d | 2015-06-28 13:01:17 -0600 | [diff] [blame] | 1362 | obj_type_mapping['VkShaderModule'] = "VK_OBJECT_TYPE_SHADER_MODULE" |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1363 | |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1364 | explicit_object_tracker_functions = [ |
| 1365 | "CreateInstance", |
| 1366 | "DestroyInstance", |
Tony Barbour | 59a4732 | 2015-06-24 16:06:58 -0600 | [diff] [blame] | 1367 | "GetPhysicalDeviceQueueProperties", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1368 | "CreateDevice", |
| 1369 | "DestroyDevice", |
| 1370 | "GetDeviceQueue", |
| 1371 | "QueueSubmit", |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1372 | "QueueBindSparseImageMemory", |
| 1373 | "QueueBindSparseBufferMemory", |
| 1374 | "GetFenceStatus", |
| 1375 | "WaitForFences", |
| 1376 | "AllocDescriptorSets", |
| 1377 | "MapMemory", |
| 1378 | "UnmapMemory", |
| 1379 | "FreeMemory", |
| 1380 | "DestroySwapChainWSI" |
| 1381 | ] |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1382 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1383 | param0_name = proto.params[0].name |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1384 | using_line = '' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1385 | create_line = '' |
Tobin Ehlis | 9d67594 | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1386 | object_params = {} # dict of parameters that are VkObject types mapping to the size of array types or '0' if not array |
Tobin Ehlis | 2717d13 | 2015-07-10 18:25:07 -0600 | [diff] [blame] | 1387 | # TODO : For now skipping objs that can be NULL. Really should check these and have special case that allows them to be NULL |
| 1388 | valid_null_object_names = ['basePipelineHandle', 'renderPass', 'framebuffer'] |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1389 | # TODO : A few of the skipped types are just "hard" cases that need some more work to support |
| 1390 | # Need to handle NULL fences on queue submit, binding null memory, and WSI Image objects |
| 1391 | for p in proto.params: |
| 1392 | if p.ty in vulkan.core.objects and p.ty not in ['VkPhysicalDevice', 'VkQueue', 'VkFence', 'VkImage', 'VkDeviceMemory']: |
Tobin Ehlis | 46d5362 | 2015-07-10 11:10:21 -0600 | [diff] [blame] | 1393 | if p.name not in valid_null_object_names: |
| 1394 | object_params[p.name] = 0 |
Tobin Ehlis | 9d67594 | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1395 | elif vk_helper.is_type(p.ty.replace('const ', '').strip('*'), 'struct'): |
| 1396 | struct_type = p.ty.replace('const ', '').strip('*') |
| 1397 | if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict: |
| 1398 | struct_type = vk_helper.typedef_rev_dict[struct_type] |
| 1399 | for m in sorted(vk_helper.struct_dict[struct_type]): |
| 1400 | 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 | 46d5362 | 2015-07-10 11:10:21 -0600 | [diff] [blame] | 1401 | if vk_helper.struct_dict[struct_type][m]['name'] not in valid_null_object_names: |
| 1402 | param_name = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name']) |
| 1403 | object_params[param_name] = {} |
| 1404 | if vk_helper.struct_dict[struct_type][m]['dyn_array']: |
| 1405 | object_params[param_name] = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size']) |
| 1406 | else: |
| 1407 | object_params[param_name] = 0 |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1408 | funcs = [] |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1409 | mutex_unlock = False |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1410 | if proto.name in explicit_object_tracker_functions: |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1411 | funcs.append('%s%s\n' |
| 1412 | '{\n' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1413 | ' return explicit_%s;\n' |
| 1414 | '}' % (qual, decl, proto.c_call())) |
| 1415 | return "".join(funcs) |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1416 | else: |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1417 | if 'Create' in proto.name or 'Alloc' in proto.name: |
| 1418 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1419 | create_line += ' if (result == VK_SUCCESS) {\n' |
| 1420 | create_line += ' create_obj(%s, *%s, %s);\n' % (param0_name, proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').replace('const ', '')]) |
| 1421 | create_line += ' }\n' |
| 1422 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1423 | if len(object_params) > 0: |
| 1424 | if not mutex_unlock: |
| 1425 | using_line += ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1426 | mutex_unlock = True |
| 1427 | for opn in object_params: |
Tobin Ehlis | 9d67594 | 2015-06-30 14:32:16 -0600 | [diff] [blame] | 1428 | if 0 != object_params[opn]: |
| 1429 | using_line += ' for (uint32_t i=0; i<%s; i++)\n' % object_params[opn] |
| 1430 | using_line += ' validate_object(%s, %s[i]);\n' % (param0_name, opn) |
| 1431 | else: |
| 1432 | if '->' in opn: |
| 1433 | using_line += ' if (%s)\n' % (opn.split('-')[0]) |
| 1434 | using_line += ' validate_object(%s, %s);\n' % (param0_name, opn) |
| 1435 | else: |
| 1436 | using_line += ' validate_object(%s, %s);\n' % (param0_name, opn) |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1437 | if mutex_unlock: |
| 1438 | using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1439 | ret_val = '' |
| 1440 | stmt = '' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1441 | if proto.ret != "void": |
| 1442 | ret_val = "%s result = " % proto.ret |
| 1443 | stmt = " return result;\n" |
| 1444 | |
| 1445 | dispatch_param = proto.params[0].name |
| 1446 | if 'CreateInstance' in proto.name: |
| 1447 | dispatch_param = '*' + proto.params[1].name |
| 1448 | |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1449 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 1450 | table_type = "" |
| 1451 | if proto_is_global(proto): |
| 1452 | table_type = "instance" |
| 1453 | else: |
| 1454 | table_type = "device" |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1455 | funcs.append('%s%s\n' |
| 1456 | '{\n' |
| 1457 | '%s' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1458 | ' %sget_dispatch_table(ObjectTracker_%s_table_map, %s)->%s;\n' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1459 | '%s' |
Mark Lobodzinski | fae7885 | 2015-06-23 11:35:12 -0600 | [diff] [blame] | 1460 | '%s' |
| 1461 | '}' % (qual, decl, using_line, ret_val, table_type, dispatch_param, proto.c_call(), create_line, stmt)) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1462 | return "\n\n".join(funcs) |
| 1463 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1464 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1465 | self.layer_name = "ObjectTracker" |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1466 | extensions=[('wsi_lunarg_enabled', |
| 1467 | ['vkCreateSwapChainWSI', 'vkDestroySwapChainWSI', |
Courtney Goeltzenleuchter | 14e8e50 | 2015-07-06 22:30:28 -0600 | [diff] [blame] | 1468 | 'vkGetSwapChainInfoWSI', 'vkQueuePresentWSI'])] |
Tony Barbour | a05dbaa | 2015-07-09 17:31:46 -0600 | [diff] [blame] | 1469 | body = [self.generate_maps(), |
| 1470 | self.generate_procs(), |
| 1471 | self.generate_explicit_destroy_instance(), |
| 1472 | self.generate_explicit_destroy_device(), |
| 1473 | self.generate_command_buffer_validates(), |
| 1474 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1475 | self._generate_extensions(), |
Jon Ashburn | 747f2b6 | 2015-06-18 15:02:58 -0600 | [diff] [blame] | 1476 | self._generate_layer_gpa_function(extensions, |
Courtney Goeltzenleuchter | 1727417 | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 1477 | instance_extensions=['msg_callback_get_proc_addr'])] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1478 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1479 | |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1480 | class ThreadingSubcommand(Subcommand): |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1481 | thread_check_dispatchable_objects = [ |
| 1482 | "VkQueue", |
| 1483 | "VkCmdBuffer", |
| 1484 | ] |
| 1485 | thread_check_nondispatchable_objects = [ |
| 1486 | "VkDeviceMemory", |
| 1487 | "VkBuffer", |
| 1488 | "VkImage", |
| 1489 | "VkDescriptorSet", |
| 1490 | "VkDescriptorPool", |
| 1491 | "VkSemaphore" |
| 1492 | ] |
| 1493 | def generate_useObject(self, ty, key): |
| 1494 | header_txt = [] |
| 1495 | header_txt.append('%s' % self.lineinfo.get()) |
| 1496 | header_txt.append('static void useObject(%s object, const char* type)' % ty) |
| 1497 | header_txt.append('{') |
| 1498 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
| 1499 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1500 | header_txt.append(' if (%sObjectsInUse.find(%s) == %sObjectsInUse.end()) {' % (ty, key, ty)) |
| 1501 | header_txt.append(' %sObjectsInUse[%s] = tid;' % (ty, key)) |
| 1502 | header_txt.append(' } else {') |
| 1503 | header_txt.append(' if (%sObjectsInUse[%s] != tid) {' % (ty, key)) |
| 1504 | header_txt.append(' char str[1024];') |
| 1505 | 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)) |
| 1506 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING", str);') |
| 1507 | header_txt.append(' // Wait for thread-safe access to object') |
| 1508 | header_txt.append(' while (%sObjectsInUse.find(%s) != %sObjectsInUse.end()) {' % (ty, key, ty)) |
| 1509 | header_txt.append(' loader_platform_thread_cond_wait(&threadingCond, &threadingLock);') |
| 1510 | header_txt.append(' }') |
| 1511 | header_txt.append(' %sObjectsInUse[%s] = tid;' % (ty, key)) |
| 1512 | header_txt.append(' } else {') |
| 1513 | header_txt.append(' char str[1024];') |
| 1514 | header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is recursively used in thread %ld", type, tid);') |
| 1515 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, THREADING_CHECKER_SINGLE_THREAD_REUSE, "THREADING", str);') |
| 1516 | header_txt.append(' }') |
| 1517 | header_txt.append(' }') |
| 1518 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1519 | header_txt.append('}') |
| 1520 | return "\n".join(header_txt) |
| 1521 | def generate_finishUsingObject(self, ty, key): |
| 1522 | header_txt = [] |
| 1523 | header_txt.append('%s' % self.lineinfo.get()) |
| 1524 | header_txt.append('static void finishUsingObject(%s object)' % ty) |
| 1525 | header_txt.append('{') |
| 1526 | header_txt.append(' // Object is no longer in use') |
| 1527 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1528 | header_txt.append(' %sObjectsInUse.erase(%s);' % (ty, key)) |
| 1529 | header_txt.append(' loader_platform_thread_cond_broadcast(&threadingCond);') |
| 1530 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1531 | header_txt.append('}') |
| 1532 | return "\n".join(header_txt) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1533 | def generate_header(self): |
| 1534 | header_txt = [] |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1535 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1536 | header_txt.append('#include <stdio.h>') |
| 1537 | header_txt.append('#include <stdlib.h>') |
| 1538 | header_txt.append('#include <string.h>') |
| 1539 | header_txt.append('#include <unordered_map>') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1540 | header_txt.append('#include "vk_loader_platform.h"') |
Tobin Ehlis | 0c6f9ee | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 1541 | header_txt.append('#include "vk_layer.h"') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1542 | header_txt.append('#include "threading.h"') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1543 | header_txt.append('#include "vk_layer_config.h"') |
Courtney Goeltzenleuchter | 3f9f7c4 | 2015-07-06 09:11:12 -0600 | [diff] [blame] | 1544 | header_txt.append('#include "vk_layer_extension_utils.h"') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1545 | header_txt.append('#include "vk_enum_validate_helper.h"') |
| 1546 | header_txt.append('#include "vk_struct_validate_helper.h"') |
| 1547 | header_txt.append('//The following is #included again to catch certain OS-specific functions being used:') |
Tobin Ehlis | b835d1b | 2015-07-03 10:34:49 -0600 | [diff] [blame] | 1548 | header_txt.append('#include "vk_loader_platform.h"\n') |
Tobin Ehlis | a0cb02e | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 1549 | header_txt.append('#include "vk_layer_msg.h"\n') |
| 1550 | header_txt.append('#include "vk_layer_table.h"\n') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1551 | header_txt.append('') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1552 | header_txt.append('') |
| 1553 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
| 1554 | header_txt.append('') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1555 | header_txt.append('using namespace std;') |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1556 | for ty in self.thread_check_dispatchable_objects: |
| 1557 | header_txt.append('static unordered_map<%s, loader_platform_thread_id> %sObjectsInUse;' % (ty, ty)) |
| 1558 | for ty in self.thread_check_nondispatchable_objects: |
| 1559 | header_txt.append('static unordered_map<uint64_t, loader_platform_thread_id> %sObjectsInUse;' % ty) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1560 | header_txt.append('static int threadingLockInitialized = 0;') |
| 1561 | header_txt.append('static loader_platform_thread_mutex threadingLock;') |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1562 | header_txt.append('static loader_platform_thread_cond threadingCond;') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1563 | header_txt.append('static int printLockInitialized = 0;') |
| 1564 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1565 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1566 | for ty in self.thread_check_dispatchable_objects: |
| 1567 | header_txt.append(self.generate_useObject(ty, "object")) |
| 1568 | header_txt.append(self.generate_finishUsingObject(ty, "object")) |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1569 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1570 | for ty in self.thread_check_nondispatchable_objects: |
| 1571 | header_txt.append(self.generate_useObject(ty, "object.handle")) |
| 1572 | header_txt.append(self.generate_finishUsingObject(ty, "object.handle")) |
| 1573 | header_txt.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1574 | return "\n".join(header_txt) |
| 1575 | |
| 1576 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1577 | if proto.name in [ 'DbgCreateMsgCallback' ]: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1578 | # use default version |
| 1579 | return None |
| 1580 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
| 1581 | ret_val = '' |
| 1582 | stmt = '' |
| 1583 | funcs = [] |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1584 | table = 'device' |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1585 | if proto.ret != "void": |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1586 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1587 | stmt = " return result;\n" |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1588 | if proto_is_global(proto): |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1589 | table = 'instance' |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1590 | |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1591 | # Memory range calls are special in needed thread checking within structs |
| 1592 | if proto.name in ["FlushMappedMemoryRanges","InvalidateMappedMemoryRanges"]: |
| 1593 | funcs.append('%s%s\n' |
| 1594 | '{\n' |
| 1595 | ' for (int i=0; i<memRangeCount; i++) {\n' |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1596 | ' useObject(pMemRanges[i].mem, "VkDeviceMemory");\n' |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1597 | ' }\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1598 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1599 | ' for (int i=0; i<memRangeCount; i++) {\n' |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1600 | ' finishUsingObject(pMemRanges[i].mem);\n' |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1601 | ' }\n' |
| 1602 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1603 | '}' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call(), stmt)) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1604 | return "\n".join(funcs) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1605 | # All functions that do a Get are thread safe |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1606 | if 'Get' in proto.name: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1607 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1608 | # All WSI functions are thread safe |
| 1609 | if 'WSI' in proto.name: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1610 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1611 | # Initialize in early calls |
Courtney Goeltzenleuchter | ca173b8 | 2015-06-25 18:01:43 -0600 | [diff] [blame] | 1612 | if proto.name == "CreateDevice": |
| 1613 | funcs.append('%s' % self.lineinfo.get()) |
| 1614 | funcs.append('%s%s\n' |
| 1615 | '{\n' |
| 1616 | ' %sdevice_dispatch_table(*pDevice)->%s;\n' |
| 1617 | '%s' |
| 1618 | '}' % (qual, decl, ret_val, proto.c_call(), stmt)) |
| 1619 | return "\n".join(funcs) |
| 1620 | elif proto.params[0].ty == "VkPhysicalDevice": |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1621 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1622 | funcs.append('%s%s\n' |
| 1623 | '{\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1624 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1625 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1626 | '}' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call(), stmt)) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1627 | return "\n".join(funcs) |
| 1628 | # Functions changing command buffers need thread safe use of first parameter |
| 1629 | if proto.params[0].ty == "VkCmdBuffer": |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1630 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1631 | funcs.append('%s%s\n' |
| 1632 | '{\n' |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1633 | ' useObject(%s, "%s");\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1634 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1635 | ' finishUsingObject(%s);\n' |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1636 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1637 | '}' % (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 | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1638 | return "\n".join(funcs) |
| 1639 | # Non-Cmd functions that do a Wait are thread safe |
| 1640 | if 'Wait' in proto.name: |
| 1641 | return None |
| 1642 | # Watch use of certain types of objects passed as any parameter |
| 1643 | checked_params = [] |
| 1644 | for param in proto.params: |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1645 | if param.ty in self.thread_check_dispatchable_objects or param.ty in self.thread_check_nondispatchable_objects: |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1646 | checked_params.append(param) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1647 | if proto.name == "DestroyDevice": |
| 1648 | funcs.append('%s%s\n' |
| 1649 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1650 | ' dispatch_key key = get_dispatch_key(device);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1651 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1652 | ' destroy_device_dispatch_table(key);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1653 | ' return result;\n' |
| 1654 | '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) |
| 1655 | return "\n".join(funcs); |
| 1656 | elif proto.name == "DestroyInstance": |
| 1657 | funcs.append('%s%s\n' |
| 1658 | '{\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1659 | ' dispatch_key key = get_dispatch_key(instance);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1660 | ' %s%s_dispatch_table(%s)->%s;\n' |
Courtney Goeltzenleuchter | 0daf228 | 2015-06-13 21:22:12 -0600 | [diff] [blame] | 1661 | ' destroy_instance_dispatch_table(key);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1662 | ' return result;\n' |
| 1663 | '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) |
| 1664 | return "\n".join(funcs); |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1665 | elif proto.name == "CreateInstance": |
| 1666 | funcs.append('%s%s\n' |
| 1667 | '{\n' |
| 1668 | ' loader_platform_thread_once(&initOnce, initThreading);\n' |
| 1669 | '\n' |
| 1670 | ' %s %s_dispatch_table(*pInstance)->CreateInstance(pCreateInfo, pInstance);\n' |
| 1671 | '\n' |
| 1672 | ' if (result == VK_SUCCESS) {\n' |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1673 | ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->ppEnabledExtensionNames);\n' |
Courtney Goeltzenleuchter | d02a964 | 2015-06-08 14:58:39 -0600 | [diff] [blame] | 1674 | ' VkLayerInstanceDispatchTable *pTable = instance_dispatch_table(*pInstance);\n' |
| 1675 | ' debug_report_init_instance_extension_dispatch_table(\n' |
| 1676 | ' pTable,\n' |
| 1677 | ' pTable->GetInstanceProcAddr,\n' |
| 1678 | ' *pInstance);\n' |
| 1679 | ' }\n' |
| 1680 | ' return result;\n' |
| 1681 | '}\n' % (qual, decl, ret_val, table)) |
| 1682 | return "\n".join(funcs); |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1683 | if len(checked_params) == 0: |
| 1684 | return None |
| 1685 | # Surround call with useObject and finishUsingObject for each checked_param |
Tobin Ehlis | 08fafd0 | 2015-06-12 12:49:01 -0600 | [diff] [blame] | 1686 | funcs.append('%s' % self.lineinfo.get()) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1687 | funcs.append('%s%s' % (qual, decl)) |
| 1688 | funcs.append('{') |
| 1689 | for param in checked_params: |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1690 | funcs.append(' useObject(%s, "%s");' % (param.name, param.ty)) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1691 | funcs.append(' %s%s_dispatch_table(%s)->%s;' % (ret_val, table, proto.params[0].name, proto.c_call())) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1692 | for param in checked_params: |
Mike Stroyan | be2b5d8 | 2015-07-09 11:01:07 -0600 | [diff] [blame] | 1693 | funcs.append(' finishUsingObject(%s);' % param.name) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1694 | funcs.append('%s' |
| 1695 | '}' % stmt) |
| 1696 | return "\n".join(funcs) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1697 | |
| 1698 | def generate_body(self): |
| 1699 | self.layer_name = "Threading" |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1700 | body = [self._generate_layer_initialization(True, lockname='threading', condname='threading'), |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1701 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | 1727417 | 2015-06-01 14:52:57 -0600 | [diff] [blame] | 1702 | self._generate_layer_gpa_function(extensions=[], |
| 1703 | instance_extensions=['msg_callback_get_proc_addr']), |
| 1704 | self._gen_create_msg_callback(), |
| 1705 | self._gen_destroy_msg_callback()] |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1706 | return "\n\n".join(body) |
| 1707 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1708 | def main(): |
| 1709 | subcommands = { |
| 1710 | "layer-funcs" : LayerFuncsSubcommand, |
| 1711 | "layer-dispatch" : LayerDispatchSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1712 | "Generic" : GenericLayerSubcommand, |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1713 | "APIDump" : APIDumpSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1714 | "ObjectTracker" : ObjectTrackerSubcommand, |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1715 | "Threading" : ThreadingSubcommand, |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1716 | } |
| 1717 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1718 | if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]): |
| 1719 | print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1720 | print |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1721 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1722 | exit(1) |
| 1723 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1724 | hfp = vk_helper.HeaderFileParser(sys.argv[2]) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1725 | hfp.parse() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1726 | vk_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1727 | vk_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1728 | vk_helper.struct_dict = hfp.get_struct_dict() |
| 1729 | vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1730 | vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1731 | vk_helper.types_dict = hfp.get_types_dict() |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1732 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1733 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1734 | subcmd.run() |
| 1735 | |
| 1736 | if __name__ == "__main__": |
| 1737 | main() |