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