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