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