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