Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | # VK |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 4 | # |
| 5 | # Copyright (C) 2014 LunarG, Inc. |
| 6 | # |
| 7 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | # copy of this software and associated documentation files (the "Software"), |
| 9 | # to deal in the Software without restriction, including without limitation |
| 10 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | # and/or sell copies of the Software, and to permit persons to whom the |
| 12 | # Software is furnished to do so, subject to the following conditions: |
| 13 | # |
| 14 | # The above copyright notice and this permission notice shall be included |
| 15 | # in all copies or substantial portions of the Software. |
| 16 | # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | # DEALINGS IN THE SOFTWARE. |
| 24 | # |
| 25 | # Authors: |
| 26 | # Chia-I Wu <olv@lunarg.com> |
| 27 | |
| 28 | import sys |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 29 | import os |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 30 | import re |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 31 | |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 32 | import vulkan |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 33 | import vk_helper |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 34 | |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 35 | def proto_is_global(proto): |
Courtney Goeltzenleuchter | d971b61 | 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 | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 37 | return True |
| 38 | else: |
| 39 | return False |
| 40 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 41 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | d8e229c | 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 | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 44 | |
Mark Lobodzinski | 7c75b85 | 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 | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 49 | class Subcommand(object): |
| 50 | def __init__(self, argv): |
| 51 | self.argv = argv |
Courtney Goeltzenleuchter | f53c3cb | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 52 | self.headers = vulkan.headers |
| 53 | self.protos = vulkan.protos |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 54 | self.no_addr = False |
| 55 | self.layer_name = "" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 56 | |
| 57 | def run(self): |
Tobin Ehlis | 12076fc | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 82 | * Vulkan |
Tobin Ehlis | 12076fc | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 115 | def _get_printf_params(self, vk_type, name, output_param, cpp=False): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 116 | # TODO : Need ENUM and STRUCT checks here |
Courtney Goeltzenleuchter | d8e229c | 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 | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 118 | return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name)) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 119 | if "char*" == vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 120 | return ("%s", name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | if "uint64" in vk_type: |
| 122 | if '*' in vk_type: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 123 | return ("%lu", "*%s" % name) |
| 124 | return ("%lu", name) |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 125 | if "size" in vk_type: |
| 126 | if '*' in vk_type: |
Chia-I Wu | 99ff89d | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 127 | return ("%zu", "*%s" % name) |
| 128 | return ("%zu", name) |
Courtney Goeltzenleuchter | d8e229c | 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 | 99f8867 | 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 | 12076fc | 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 | d8e229c | 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 | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 136 | return ("%u", name) |
Tobin Ehlis | b870cbb | 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 | d8e229c | 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 | 99f8867 | 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 | 12076fc | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 142 | if '*' in vk_type: |
Tobin Ehlis | d2b88e8 | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 143 | if 'pUserData' == name: |
| 144 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Tobin Ehlis | c62cb89 | 2015-04-17 13:26:33 -0600 | [diff] [blame] | 145 | if 'const' in vk_type.lower(): |
| 146 | return ("%p", "(void*)(%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 147 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 148 | return ("%i", name) |
Tobin Ehlis | 3a1cc8d | 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 | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 150 | if "VkFormat" == vk_type: |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 151 | if cpp: |
| 152 | return ("%p", "&%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 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 | e727157 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 154 | if output_param: |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 155 | return ("%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | d8e229c | 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 | d462fba | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 157 | return ("%p", "(void*)(&%s)" % name) |
Jon Ashburn | 52f79b5 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 158 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 159 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 160 | def _gen_create_msg_callback(self): |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 161 | r_body = [] |
Courtney Goeltzenleuchter | f579fa6 | 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 | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 163 | r_body.append('{') |
Mark Lobodzinski | fb5437a | 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 | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 165 | r_body.append('}') |
| 166 | return "\n".join(r_body) |
| 167 | |
Courtney Goeltzenleuchter | f579fa6 | 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 | fb5437a | 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 | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 173 | r_body.append('}') |
| 174 | return "\n".join(r_body) |
Tobin Ehlis | e818506 | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 175 | |
Jon Ashburn | 9fd4cc4 | 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 | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame^] | 178 | if layer == 'APIDump': |
| 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 | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 204 | ggei_body.append('') |
Mark Lobodzinski | a2727c9 | 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 | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 206 | ggei_body.append('{') |
Jon Ashburn | 9fd4cc4 | 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 | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 226 | ggei_body.append(' memcpy((VkExtensionProperties *) pData, &layerExts[extensionIndex], sizeof(VkExtensionProperties));') |
Jon Ashburn | 9fd4cc4 | 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 | 5f3960e | 2015-04-02 12:06:28 -0600 | [diff] [blame] | 234 | |
Courtney Goeltzenleuchter | d971b61 | 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 | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 268 | def _generate_dispatch_entrypoints(self, qual=""): |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 269 | if qual: |
| 270 | qual += " " |
| 271 | |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 272 | funcs = [] |
| 273 | intercepted = [] |
| 274 | for proto in self.protos: |
Jon Ashburn | 8d1b0b5 | 2015-05-18 13:20:15 -0600 | [diff] [blame] | 275 | if proto.name == "GetDeviceProcAddr" or proto.name == "GetInstanceProcAddr": |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 276 | continue |
Mike Stroyan | 70c05e8 | 2015-04-08 10:27:43 -0600 | [diff] [blame] | 277 | else: |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 278 | intercept = self.generate_intercept(proto, qual) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 279 | if intercept is None: |
| 280 | # fill in default intercept for certain entrypoints |
Courtney Goeltzenleuchter | f579fa6 | 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 | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 287 | elif 'GetGlobalExtensionInfo' == proto.name: |
Mike Stroyan | e90a222 | 2015-05-11 13:44:24 -0600 | [diff] [blame] | 288 | intercept = self._gen_layer_get_global_extension_info(self.layer_name) |
Courtney Goeltzenleuchter | d971b61 | 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 | 938c253 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 295 | prefix="vk" |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 296 | lookups = [] |
| 297 | for proto in intercepted: |
Mike Stroyan | 938c253 | 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 | 938c253 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 308 | body.append(" name += 2;") |
Mike Stroyan | 938c253 | 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 | f6b33db | 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 | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 316 | if not proto_is_global(proto): |
Jon Ashburn | f6b33db | 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 | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 334 | funcs.append("\n".join(body)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 335 | return "\n\n".join(funcs) |
| 336 | |
| 337 | |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 338 | def _generate_extensions(self): |
| 339 | exts = [] |
Courtney Goeltzenleuchter | f579fa6 | 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 | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 343 | exts.append('{') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 344 | exts.append(' return numTotalObjs;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 345 | exts.append('}') |
| 346 | exts.append('') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 347 | exts.append('VkResult objTrackGetObjects(VkObjectType type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)') |
Tobin Ehlis | ca91587 | 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 | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 350 | exts.append(' // Check the count first thing') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 351 | exts.append(' uint64_t maxObjCount = numTotalObjs;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 352 | exts.append(' if (objCount > maxObjCount) {') |
| 353 | exts.append(' char str[1024];') |
Mark Lobodzinski | 7c75b85 | 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 | f579fa6 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 356 | exts.append(' return VK_ERROR_INVALID_VALUE;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 357 | exts.append(' }') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 358 | exts.append(' auto it = objMap.begin();') |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 359 | exts.append(' for (uint64_t i = 0; i < objCount; i++) {') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 360 | exts.append(' if (objMap.end() == it) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 361 | exts.append(' char str[1024];') |
Mark Lobodzinski | 7c75b85 | 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 | f579fa6 | 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 | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 364 | exts.append(' return VK_ERROR_UNKNOWN;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 365 | exts.append(' }') |
Tobin Ehlis | 803cc49 | 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 | 7c75b85 | 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 | f579fa6 | 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 | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 384 | exts.append(' return VK_ERROR_INVALID_VALUE;') |
| 385 | exts.append(' }') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 386 | exts.append(' auto it = objMap.begin();') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 387 | exts.append(' for (uint64_t i = 0; i < objCount; i++) {') |
Tobin Ehlis | 803cc49 | 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 | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 392 | exts.append(' char str[1024];') |
Courtney Goeltzenleuchter | f579fa6 | 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 | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 395 | exts.append(' return VK_ERROR_UNKNOWN;') |
| 396 | exts.append(' }') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 397 | exts.append(' memcpy(&pObjNodeArray[i], it->second, sizeof(OBJTRACK_NODE));') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 398 | exts.append(' }') |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 399 | exts.append(' return VK_SUCCESS;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 400 | exts.append('}') |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 401 | return "\n".join(exts) |
| 402 | |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 403 | def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]): |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 404 | func_body = [] |
Jon Ashburn | 8d1b0b5 | 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 | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 406 | "{\n" |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 407 | " void* addr;\n" |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 408 | " if (device == VK_NULL_HANDLE) {\n" |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 409 | " return NULL;\n" |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 410 | " }\n" |
Jon Ashburn | 8fd0825 | 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 | bacb0f5 | 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 | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 421 | if 0 != len(extensions): |
Mark Lobodzinski | 38f0db2 | 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 | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 427 | for ext_name in extensions: |
Mark Lobodzinski | fb5437a | 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 | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 430 | func_body.append(" else {\n" |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 431 | " VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) device;\n" |
| 432 | " VkLayerDispatchTable* pTable = tableMap[*ppDisp];\n" |
| 433 | " if (pTable->GetDeviceProcAddr == NULL)\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 434 | " return NULL;\n" |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 435 | " return pTable->GetDeviceProcAddr(device, funcName);\n" |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 436 | " }\n" |
| 437 | "}\n") |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 438 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n" |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 439 | "{\n" |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 440 | " void* addr;\n" |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 441 | " if (instance == VK_NULL_HANDLE) {\n" |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 442 | " return NULL;\n" |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 443 | " }\n" |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 444 | " loader_platform_thread_once(&initOnce, init%s);\n\n" |
| 445 | " /* loader uses this to force layer initialization; instance object is wrapped */\n" |
| 446 | " if (!strcmp(\"vkGetInstanceProcAddr\", funcName)) {\n" |
| 447 | " initInstanceTable((const VkBaseLayerObject *) instance);\n" |
| 448 | " return (void *) vkGetInstanceProcAddr;\n" |
| 449 | " }\n\n" |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 450 | " addr = layer_intercept_instance_proc(funcName);\n" |
| 451 | " if (addr)\n" |
| 452 | " return addr;" % self.layer_name) |
| 453 | |
| 454 | if 0 != len(instance_extensions): |
| 455 | for ext_name in instance_extensions: |
| 456 | func_body.append(' else if (!strcmp("%s", funcName))\n' |
| 457 | ' return %s;' % (ext_name, ext_name)) |
| 458 | func_body.append(" else {\n" |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 459 | " VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instance;\n" |
| 460 | " VkLayerInstanceDispatchTable* pTable = tableInstanceMap[*ppDisp];\n" |
| 461 | " if (pTable->GetInstanceProcAddr == NULL)\n" |
Jon Ashburn | f6b33db | 2015-05-05 14:22:52 -0600 | [diff] [blame] | 462 | " return NULL;\n" |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 463 | " return pTable->GetInstanceProcAddr(instance, funcName);\n" |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 464 | " }\n" |
| 465 | "}\n") |
| 466 | return "\n".join(func_body) |
| 467 | |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 468 | def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 469 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 470 | func_body.append('static void init%s(void)\n' |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 471 | '{\n' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 472 | if init_opts: |
| 473 | func_body.append(' const char *strOpt;') |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 474 | func_body.append(' // initialize %s options' % self.layer_name) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 475 | func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportFlags);' % self.layer_name) |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 476 | func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 477 | func_body.append('') |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 478 | func_body.append(' if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 479 | func_body.append(' {') |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 480 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name) |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 481 | func_body.append(' if (strOpt)') |
| 482 | func_body.append(' {') |
| 483 | func_body.append(' g_logFile = fopen(strOpt, "w");') |
| 484 | func_body.append(' }') |
| 485 | func_body.append(' if (g_logFile == NULL)') |
| 486 | func_body.append(' g_logFile = stdout;') |
| 487 | func_body.append(' }') |
| 488 | func_body.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 489 | |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 490 | if lockname is not None: |
| 491 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 492 | func_body.append(" {") |
| 493 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 494 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 495 | if condname is not None: |
| 496 | func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname) |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 497 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 498 | func_body.append(" }") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 499 | func_body.append("}\n") |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 500 | func_body.append('') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 501 | func_body.append('static VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw)') |
| 502 | func_body.append(' {') |
| 503 | func_body.append(' VkLayerDispatchTable *pTable;') |
| 504 | func_body.append('') |
| 505 | func_body.append(' assert(devw);') |
| 506 | func_body.append(' VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) (devw->baseObject);') |
| 507 | func_body.append('') |
| 508 | func_body.append(' std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap.find((void *) *ppDisp);') |
| 509 | func_body.append(' if (it == tableMap.end())') |
| 510 | func_body.append(' {') |
| 511 | func_body.append(' pTable = new VkLayerDispatchTable;') |
| 512 | func_body.append(' tableMap[(void *) *ppDisp] = pTable;') |
| 513 | func_body.append(' } else') |
| 514 | func_body.append(' {') |
| 515 | func_body.append(' return it->second;') |
| 516 | func_body.append(' }') |
| 517 | func_body.append('') |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 518 | func_body.append(' layer_initialize_dispatch_table(pTable, devw);') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 519 | func_body.append('') |
| 520 | func_body.append(' return pTable;') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 521 | func_body.append('}') |
| 522 | func_body.append('') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 523 | func_body.append('static VkLayerInstanceDispatchTable * initInstanceTable(const VkBaseLayerObject *instw)') |
| 524 | func_body.append(' {') |
| 525 | func_body.append(' VkLayerInstanceDispatchTable *pTable;') |
| 526 | func_body.append(' assert(instw);') |
| 527 | func_body.append(' VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject;') |
| 528 | func_body.append('') |
| 529 | func_body.append(' std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap.find((void *) *ppDisp);') |
| 530 | func_body.append(' if (it == tableInstanceMap.end())') |
| 531 | func_body.append(' {') |
| 532 | func_body.append(' pTable = new VkLayerInstanceDispatchTable;') |
| 533 | func_body.append(' tableInstanceMap[(void *) *ppDisp] = pTable;') |
| 534 | func_body.append(' } else') |
| 535 | func_body.append(' {') |
| 536 | func_body.append(' return it->second;') |
| 537 | func_body.append(' }') |
| 538 | func_body.append('') |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 539 | func_body.append(' layer_init_instance_dispatch_table(pTable, instw);') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 540 | func_body.append('') |
| 541 | func_body.append(' return pTable;') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 542 | func_body.append('}') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 543 | func_body.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 544 | return "\n".join(func_body) |
| 545 | |
| 546 | class LayerFuncsSubcommand(Subcommand): |
| 547 | def generate_header(self): |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 548 | return '#include <vkLayer.h>\n#include "loader.h"' |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 549 | |
| 550 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 551 | return self._generate_dispatch_entrypoints("static") |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 552 | |
| 553 | class LayerDispatchSubcommand(Subcommand): |
| 554 | def generate_header(self): |
| 555 | return '#include "layer_wrappers.h"' |
| 556 | |
| 557 | def generate_body(self): |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 558 | return self._generate_layer_initialization() |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 559 | |
| 560 | class GenericLayerSubcommand(Subcommand): |
| 561 | def generate_header(self): |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 562 | gen_header = [] |
| 563 | gen_header.append('#include <stdio.h>') |
| 564 | gen_header.append('#include <stdlib.h>') |
| 565 | gen_header.append('#include <string.h>') |
| 566 | gen_header.append('#include <unordered_map>') |
| 567 | gen_header.append('#include "loader_platform.h"') |
| 568 | gen_header.append('#include "vkLayer.h"') |
| 569 | gen_header.append('//The following is #included again to catch certain OS-specific functions being used:') |
| 570 | gen_header.append('') |
| 571 | gen_header.append('#include "loader_platform.h"') |
| 572 | gen_header.append('#include "layers_config.h"') |
| 573 | gen_header.append('#include "layers_msg.h"') |
| 574 | gen_header.append('') |
| 575 | gen_header.append('static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;') |
| 576 | gen_header.append('static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;') |
| 577 | gen_header.append('') |
| 578 | gen_header.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
| 579 | gen_header.append('') |
| 580 | gen_header.append(' static inline VkLayerDispatchTable *device_dispatch_table(VkObject object) {') |
| 581 | gen_header.append(' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object;') |
| 582 | gen_header.append(' VkLayerDispatchTable *pTable = tableMap[pDisp];') |
| 583 | gen_header.append(' return pTable;') |
| 584 | gen_header.append('}') |
| 585 | gen_header.append('') |
| 586 | gen_header.append('static inline VkLayerInstanceDispatchTable *instance_dispatch_table(VkObject object) {') |
| 587 | gen_header.append(' VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) object;') |
| 588 | gen_header.append(' VkLayerInstanceDispatchTable *pInstanceTable = tableInstanceMap[*ppDisp];') |
| 589 | gen_header.append(' return pInstanceTable;') |
| 590 | gen_header.append('}') |
| 591 | return "\n".join(gen_header) |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 592 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame^] | 593 | if proto.name in [ 'GetGlobalExtensionInfo', 'GetPhysicalDeviceExtensionInfo' ]: |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 594 | # use default version |
| 595 | return None |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 596 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 597 | ret_val = '' |
| 598 | stmt = '' |
| 599 | funcs = [] |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 600 | table = '' |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 601 | if proto_is_global(proto): |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 602 | table = 'Instance' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 603 | if proto.ret != "void": |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 604 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 605 | stmt = " return result;\n" |
Jon Ashburn | 8ced421 | 2015-05-22 12:01:50 -0600 | [diff] [blame] | 606 | if proto.name == "CreateDevice": |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 607 | funcs.append('%s%s\n' |
| 608 | '{\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 609 | ' char str[1024];\n' |
| 610 | ' sprintf(str, "At start of layered %s\\n");\n' |
| 611 | ' layerCbMsg(VK_DBG_REPORT_INFO_BIT,VK_OBJECT_TYPE_PHYSICAL_DEVICE, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n' |
| 612 | ' %sinstance_dispatch_table(gpu)->%s;\n' |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 613 | ' if (result == VK_SUCCESS) {\n' |
| 614 | ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);\n' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 615 | ' }\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 616 | ' sprintf(str, "Completed layered %s\\n");\n' |
| 617 | ' layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n' |
| 618 | ' fflush(stdout);\n' |
| 619 | ' %s' |
| 620 | '}' % (qual, decl, proto.name, ret_val, proto.c_call(), proto.name, stmt)) |
| 621 | elif proto.name == "DestroyDevice": |
| 622 | funcs.append('%s%s\n' |
| 623 | '{\n' |
| 624 | ' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;\n' |
| 625 | ' VkResult res = device_dispatch_table(device)->DestroyDevice(device);\n' |
| 626 | ' tableMap.erase(pDisp);\n' |
| 627 | ' return res;\n' |
| 628 | '}\n' % (qual, decl)) |
| 629 | elif proto.name == "DestroyInstance": |
| 630 | funcs.append('%s%s\n' |
| 631 | '{\n' |
| 632 | ' VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;\n' |
| 633 | ' VkResult res = instance_dispatch_table(instance)->DestroyInstance(instance);\n' |
| 634 | ' tableInstanceMap.erase(pDisp);\n' |
| 635 | ' return res;\n' |
| 636 | '}\n' % (qual, decl)) |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 637 | else: |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 638 | # CreateInstance needs to use the second parm instead of the first to set the correct dispatch table |
| 639 | dispatch_param = proto.params[0].name |
| 640 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 641 | table_type = "" |
| 642 | if proto_is_global(proto): |
| 643 | table_type = "instance" |
| 644 | else: |
| 645 | table_type = "device" |
| 646 | if 'CreateInstance' in proto.name: |
| 647 | dispatch_param = '*' + proto.params[1].name |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 648 | funcs.append('%s%s\n' |
| 649 | '{\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 650 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 651 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 652 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), stmt)) |
Mike Stroyan | 938c253 | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 653 | return "\n\n".join(funcs) |
| 654 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 655 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 656 | self.layer_name = "Generic" |
| 657 | body = [self._generate_layer_initialization(True), |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 658 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 659 | self._gen_create_msg_callback(), |
| 660 | self._gen_destroy_msg_callback(), |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 661 | self._generate_layer_gpa_function()] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 662 | |
| 663 | return "\n\n".join(body) |
| 664 | |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 665 | class APIDumpSubcommand(Subcommand): |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 666 | def generate_header(self): |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 667 | header_txt = [] |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 668 | header_txt.append('#include <fstream>') |
| 669 | header_txt.append('#include <iostream>') |
| 670 | header_txt.append('#include <string>') |
| 671 | header_txt.append('') |
| 672 | header_txt.append('static std::ofstream fileStream;') |
| 673 | header_txt.append('static std::string fileName = "vk_apidump.txt";') |
| 674 | header_txt.append('std::ostream* outputStream = NULL;') |
| 675 | header_txt.append('void ConfigureOutputStream(bool writeToFile, bool flushAfterWrite)') |
| 676 | header_txt.append('{') |
| 677 | header_txt.append(' if(writeToFile)') |
| 678 | header_txt.append(' {') |
| 679 | header_txt.append(' fileStream.open(fileName);') |
| 680 | header_txt.append(' outputStream = &fileStream;') |
| 681 | header_txt.append(' }') |
| 682 | header_txt.append(' else') |
| 683 | header_txt.append(' {') |
| 684 | header_txt.append(' outputStream = &std::cout;') |
| 685 | header_txt.append(' }') |
| 686 | header_txt.append('') |
| 687 | header_txt.append(' if(flushAfterWrite)') |
| 688 | header_txt.append(' {') |
| 689 | header_txt.append(' outputStream->sync_with_stdio(true);') |
| 690 | header_txt.append(' }') |
| 691 | header_txt.append(' else') |
| 692 | header_txt.append(' {') |
| 693 | header_txt.append(' outputStream->sync_with_stdio(false);') |
| 694 | header_txt.append(' }') |
| 695 | header_txt.append('}') |
| 696 | header_txt.append('') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 697 | header_txt.append('#include "loader_platform.h"') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 698 | header_txt.append('#include "vkLayer.h"') |
| 699 | header_txt.append('#include "vk_struct_string_helper_cpp.h"') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 700 | header_txt.append('#include <unordered_map>') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 701 | header_txt.append('') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 702 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 703 | header_txt.append('#include "loader_platform.h"') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 704 | header_txt.append('') |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 705 | header_txt.append('static VkLayerDispatchTable nextTable;') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 706 | header_txt.append('static VkLayerInstanceDispatchTable nextInstanceTable;') |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 707 | header_txt.append('static VkBaseLayerObject *pCurObj;') |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 708 | header_txt.append('static bool g_APIDumpDetailed = true;') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 709 | header_txt.append('') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 710 | header_txt.append('static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;') |
| 711 | header_txt.append('static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 712 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 713 | header_txt.append('') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 714 | header_txt.append('static int printLockInitialized = 0;') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 715 | header_txt.append('static loader_platform_thread_mutex printLock;') |
| 716 | header_txt.append('') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 717 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 718 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 719 | header_txt.append('static uint32_t maxTID = 0;') |
| 720 | header_txt.append('// Map actual TID to an index value and return that index') |
| 721 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 722 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 723 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 724 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 725 | header_txt.append(' if (tid == tidMapping[i])') |
| 726 | header_txt.append(' return i;') |
| 727 | header_txt.append(' }') |
| 728 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 729 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 730 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 731 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 732 | header_txt.append(' return retVal;') |
| 733 | header_txt.append('}') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 734 | header_txt.append('') |
| 735 | header_txt.append('static inline VkLayerDispatchTable *device_dispatch_table(VkObject object) {') |
| 736 | header_txt.append(' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object;') |
| 737 | header_txt.append(' VkLayerDispatchTable *pTable = tableMap[pDisp];') |
| 738 | header_txt.append(' return pTable;') |
| 739 | header_txt.append('}') |
| 740 | header_txt.append('') |
| 741 | header_txt.append('static inline VkLayerInstanceDispatchTable *instance_dispatch_table(VkObject object) {') |
| 742 | header_txt.append(' VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) object;') |
| 743 | header_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = tableInstanceMap[*ppDisp];') |
| 744 | header_txt.append(' return pInstanceTable;') |
| 745 | header_txt.append('}') |
Tobin Ehlis | d009bae | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 746 | return "\n".join(header_txt) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 747 | |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 748 | def generate_init(self): |
| 749 | func_body = [] |
| 750 | func_body.append('#include "vk_dispatch_table_helper.h"') |
| 751 | func_body.append('#include "layers_config.h"') |
| 752 | func_body.append('') |
| 753 | func_body.append('static void init%s(void)' % self.layer_name) |
| 754 | func_body.append('{') |
| 755 | func_body.append(' using namespace StreamControl;') |
| 756 | func_body.append('') |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 757 | func_body.append(' char const*const detailedStr = getLayerOption("APIDumpDetailed");') |
| 758 | func_body.append(' if(detailedStr != NULL)') |
| 759 | func_body.append(' {') |
| 760 | func_body.append(' if(strcmp(detailedStr, "TRUE") == 0)') |
| 761 | func_body.append(' {') |
| 762 | func_body.append(' g_APIDumpDetailed = true;') |
| 763 | func_body.append(' }') |
| 764 | func_body.append(' else if(strcmp(detailedStr, "FALSE") == 0)') |
| 765 | func_body.append(' {') |
| 766 | func_body.append(' g_APIDumpDetailed = false;') |
| 767 | func_body.append(' }') |
| 768 | func_body.append(' }') |
| 769 | func_body.append('') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 770 | func_body.append(' char const*const writeToFileStr = getLayerOption("APIDumpFile");') |
| 771 | func_body.append(' bool writeToFile = false;') |
| 772 | func_body.append(' if(writeToFileStr != NULL)') |
| 773 | func_body.append(' {') |
| 774 | func_body.append(' if(strcmp(writeToFileStr, "TRUE") == 0)') |
| 775 | func_body.append(' {') |
| 776 | func_body.append(' writeToFile = true;') |
| 777 | func_body.append(' }') |
| 778 | func_body.append(' else if(strcmp(writeToFileStr, "FALSE") == 0)') |
| 779 | func_body.append(' {') |
| 780 | func_body.append(' writeToFile = false;') |
| 781 | func_body.append(' }') |
| 782 | func_body.append(' }') |
| 783 | func_body.append('') |
| 784 | func_body.append(' char const*const noAddrStr = getLayerOption("APIDumpNoAddr");') |
| 785 | func_body.append(' if(noAddrStr != NULL)') |
| 786 | func_body.append(' {') |
| 787 | func_body.append(' if(strcmp(noAddrStr, "FALSE") == 0)') |
| 788 | func_body.append(' {') |
| 789 | func_body.append(' StreamControl::writeAddress = true;') |
| 790 | func_body.append(' }') |
| 791 | func_body.append(' else if(strcmp(noAddrStr, "TRUE") == 0)') |
| 792 | func_body.append(' {') |
| 793 | func_body.append(' StreamControl::writeAddress = false;') |
| 794 | func_body.append(' }') |
| 795 | func_body.append(' }') |
| 796 | func_body.append('') |
| 797 | func_body.append(' char const*const flushAfterWriteStr = getLayerOption("APIDumpFlush");') |
| 798 | func_body.append(' bool flushAfterWrite = false;') |
| 799 | func_body.append(' if(flushAfterWriteStr != NULL)') |
| 800 | func_body.append(' {') |
| 801 | func_body.append(' if(strcmp(flushAfterWriteStr, "TRUE") == 0)') |
| 802 | func_body.append(' {') |
| 803 | func_body.append(' flushAfterWrite = true;') |
| 804 | func_body.append(' }') |
| 805 | func_body.append(' else if(strcmp(flushAfterWriteStr, "FALSE") == 0)') |
| 806 | func_body.append(' {') |
| 807 | func_body.append(' flushAfterWrite = false;') |
| 808 | func_body.append(' }') |
| 809 | func_body.append(' }') |
| 810 | func_body.append('') |
| 811 | func_body.append(' ConfigureOutputStream(writeToFile, flushAfterWrite);') |
| 812 | func_body.append('') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 813 | func_body.append(' if (!printLockInitialized)') |
| 814 | func_body.append(' {') |
| 815 | func_body.append(' // TODO/TBD: Need to delete this mutex sometime. How???') |
| 816 | func_body.append(' loader_platform_thread_create_mutex(&printLock);') |
| 817 | func_body.append(' printLockInitialized = 1;') |
| 818 | func_body.append(' }') |
| 819 | func_body.append('}') |
| 820 | func_body.append('') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 821 | func_body.append('static VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw)') |
| 822 | func_body.append(' {') |
| 823 | func_body.append(' VkLayerDispatchTable *pTable;') |
| 824 | func_body.append('') |
| 825 | func_body.append(' assert(devw);') |
| 826 | func_body.append(' VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) (devw->baseObject);') |
| 827 | func_body.append('') |
| 828 | func_body.append(' std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap.find((void *) *ppDisp);') |
| 829 | func_body.append(' if (it == tableMap.end())') |
| 830 | func_body.append(' {') |
| 831 | func_body.append(' pTable = new VkLayerDispatchTable;') |
| 832 | func_body.append(' tableMap[(void *) *ppDisp] = pTable;') |
| 833 | func_body.append(' } else') |
| 834 | func_body.append(' {') |
| 835 | func_body.append(' return it->second;') |
| 836 | func_body.append(' }') |
| 837 | func_body.append('') |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 838 | func_body.append(' layer_initialize_dispatch_table(pTable, devw);') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 839 | func_body.append('') |
| 840 | func_body.append(' return pTable;') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 841 | func_body.append('}') |
| 842 | func_body.append('') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 843 | func_body.append('static VkLayerInstanceDispatchTable * initInstanceTable(const VkBaseLayerObject *instw)') |
| 844 | func_body.append(' {') |
| 845 | func_body.append(' VkLayerInstanceDispatchTable *pTable;') |
| 846 | func_body.append(' assert(instw);') |
| 847 | func_body.append(' VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) instw->baseObject;') |
| 848 | func_body.append('') |
| 849 | func_body.append(' std::unordered_map<void *, VkLayerInstanceDispatchTable *>::const_iterator it = tableInstanceMap.find((void *) *ppDisp);') |
| 850 | func_body.append(' if (it == tableInstanceMap.end())') |
| 851 | func_body.append(' {') |
| 852 | func_body.append(' pTable = new VkLayerInstanceDispatchTable;') |
| 853 | func_body.append(' tableInstanceMap[(void *) *ppDisp] = pTable;') |
| 854 | func_body.append(' } else') |
| 855 | func_body.append(' {') |
| 856 | func_body.append(' return it->second;') |
| 857 | func_body.append(' }') |
| 858 | func_body.append('') |
Jon Ashburn | 8fd0825 | 2015-05-28 16:25:02 -0600 | [diff] [blame] | 859 | func_body.append(' layer_init_instance_dispatch_table(pTable, instw);') |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 860 | func_body.append('') |
| 861 | func_body.append(' return pTable;') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 862 | func_body.append('}') |
| 863 | func_body.append('') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 864 | return "\n".join(func_body) |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 865 | |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 866 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame^] | 867 | if proto.name in [ 'GetGlobalExtensionInfo', 'GetPhysicalDeviceExtensionInfo']: |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 868 | return None |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 869 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 870 | ret_val = '' |
| 871 | stmt = '' |
| 872 | funcs = [] |
| 873 | sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print |
| 874 | create_params = 0 # Num of params at end of function that are created and returned as output values |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 875 | if 'AllocDescriptorSets' in proto.name: |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 876 | create_params = -2 |
| 877 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 878 | create_params = -1 |
| 879 | if proto.ret != "void": |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 880 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 881 | stmt = " return result;\n" |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 882 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n ' |
| 883 | log_func = ' if (StreamControl::writeAddress == true) {' |
| 884 | log_func += '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 885 | log_func_no_addr = '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 886 | f_close = '\n loader_platform_thread_unlock_mutex(&printLock);' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 887 | pindex = 0 |
| 888 | prev_count_name = '' |
| 889 | for p in proto.params: |
| 890 | cp = False |
| 891 | if 0 != create_params: |
| 892 | # If this is any of the N last params of the func, treat as output |
| 893 | for y in range(-1, create_params-1, -1): |
| 894 | if p.name == proto.params[y].name: |
| 895 | cp = True |
| 896 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 897 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 898 | if "%p" == pft: |
| 899 | log_func_no_addr += '%s = address, ' % (p.name) |
| 900 | else: |
| 901 | log_func_no_addr += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | 0854174 | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 902 | if prev_count_name != '' and (prev_count_name.replace('Count', '')[1:] in p.name): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 903 | sp_param_dict[pindex] = prev_count_name |
Tobin Ehlis | 0854174 | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 904 | prev_count_name = '' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 905 | elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount': |
| 906 | sp_param_dict[pindex] = '*pCount' |
Chia-I Wu | f869338 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 907 | elif vk_helper.is_type(p.ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 908 | sp_param_dict[pindex] = 'index' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 909 | if p.name.endswith('Count'): |
| 910 | if '*' in p.ty: |
| 911 | prev_count_name = "*%s" % p.name |
| 912 | else: |
| 913 | prev_count_name = p.name |
Jon Ashburn | 9fd4cc4 | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 914 | pindex += 1 |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 915 | log_func = log_func.strip(', ') |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 916 | log_func_no_addr = log_func_no_addr.strip(', ') |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 917 | if proto.ret == "VkResult": |
Courtney Goeltzenleuchter | fb4efc6 | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 918 | log_func += ') = " << string_VkResult((VkResult)result) << endl' |
| 919 | log_func_no_addr += ') = " << string_VkResult((VkResult)result) << endl' |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 920 | elif proto.ret == "void*": |
| 921 | log_func += ') = " << result << endl' |
| 922 | log_func_no_addr += ') = " << result << endl' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 923 | else: |
| 924 | log_func += ')\\n"' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 925 | log_func_no_addr += ')\\n"' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 926 | log_func += ';' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 927 | log_func_no_addr += ';' |
| 928 | log_func += '\n }\n else {%s;\n }' % log_func_no_addr; |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 929 | #print("Proto %s has param_dict: %s" % (proto.name, sp_param_dict)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 930 | if len(sp_param_dict) > 0: |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 931 | indent = ' ' |
| 932 | log_func += '\n%sif (g_APIDumpDetailed) {' % indent |
| 933 | indent += ' ' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 934 | i_decl = False |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 935 | log_func += '\n%sstring tmp_str;' % indent |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 936 | for sp_index in sp_param_dict: |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 937 | #print("sp_index: %s" % str(sp_index)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 938 | if 'index' == sp_param_dict[sp_index]: |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 939 | cis_print_func = 'vk_print_%s' % (proto.params[sp_index].ty.replace('const ', '').strip('*').lower()) |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 940 | local_name = proto.params[sp_index].name |
| 941 | if '*' not in proto.params[sp_index].ty: |
| 942 | local_name = '&%s' % proto.params[sp_index].name |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 943 | log_func += '\n%sif (%s) {' % (indent, local_name) |
| 944 | indent += ' ' |
| 945 | log_func += '\n%stmp_str = %s(%s, " ");' % (indent, cis_print_func, local_name) |
| 946 | log_func += '\n%s(*outputStream) << " %s (" << %s << ")" << endl << tmp_str << endl;' % (indent, local_name, local_name) |
| 947 | indent = indent[4:] |
| 948 | log_func += '\n%s}' % (indent) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 949 | else: # We have a count value stored to iterate over an array |
| 950 | print_cast = '' |
| 951 | print_func = '' |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 952 | if vk_helper.is_type(proto.params[sp_index].ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 953 | print_cast = '&' |
Courtney Goeltzenleuchter | 95487bc | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 954 | print_func = 'vk_print_%s' % proto.params[sp_index].ty.replace('const ', '').strip('*').lower() |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 955 | else: |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 956 | print_cast = '' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 957 | print_func = 'string_convert_helper' |
| 958 | #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name |
| 959 | cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 960 | if not i_decl: |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 961 | log_func += '\n%suint32_t i;' % (indent) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 962 | i_decl = True |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 963 | log_func += '\n%sif (%s) {' % (indent, proto.params[sp_index].name) |
| 964 | indent += ' ' |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 965 | log_func += '\n%sfor (i = 0; i < %s; i++) {' % (indent, sp_param_dict[sp_index]) |
| 966 | indent += ' ' |
| 967 | log_func += '\n%s%s' % (indent, cis_print_func) |
Tobin Ehlis | 45a23a8 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 968 | log_func += '\n%sif (StreamControl::writeAddress == true) {' % (indent) |
| 969 | indent += ' ' |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 970 | 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) |
| 971 | indent = indent[4:] |
Tobin Ehlis | 45a23a8 | 2015-04-28 10:58:20 -0600 | [diff] [blame] | 972 | log_func += '\n%s} else {' % (indent) |
| 973 | indent += ' ' |
| 974 | log_func += '\n%s(*outputStream) << " %s[" << i << "] (address)" << endl << " address" << endl;' % (indent, proto.params[sp_index].name) |
| 975 | indent = indent[4:] |
| 976 | log_func += '\n%s}' % (indent) |
| 977 | indent = indent[4:] |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 978 | log_func += '\n%s}' % (indent) |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 979 | indent = indent[4:] |
| 980 | log_func += '\n%s}' % (indent) |
Tobin Ehlis | a2b199c | 2015-04-27 17:30:04 -0600 | [diff] [blame] | 981 | indent = indent[4:] |
| 982 | log_func += '\n%s}' % (indent) |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 983 | table_type = '' |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 984 | if proto_is_global(proto): |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 985 | table_type = 'instance' |
| 986 | else: |
| 987 | table_type = 'device' |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 988 | |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 989 | if proto.name == "CreateInstance": |
| 990 | dispatch_param = '*' + proto.params[1].name |
| 991 | else: |
| 992 | dispatch_param = proto.params[0].name |
| 993 | |
| 994 | if proto.name == "EnumerateLayers": |
| 995 | funcs.append('%s%s\n' |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 996 | '{\n' |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 997 | ' using namespace StreamControl;\n' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 998 | ' if (gpu != VK_NULL_HANDLE) {\n' |
| 999 | ' %sinstance_dispatch_table(gpu)->%s;\n' |
| 1000 | ' %s %s %s\n' |
| 1001 | ' %s' |
| 1002 | ' } else {\n' |
| 1003 | ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
| 1004 | ' return VK_ERROR_INVALID_POINTER;\n' |
| 1005 | ' // This layer compatible with all GPUs\n' |
| 1006 | ' *pLayerCount = 1;\n' |
| 1007 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
| 1008 | ' return VK_SUCCESS;\n' |
| 1009 | ' }\n' |
| 1010 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt, self.layer_name)) |
| 1011 | elif proto.name == "DestroyDevice": |
| 1012 | funcs.append('%s%s\n' |
| 1013 | '{\n' |
| 1014 | ' using namespace StreamControl;\n' |
| 1015 | ' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;\n' |
| 1016 | ' %s%s_dispatch_table(%s)->%s;\n' |
| 1017 | ' tableMap.erase(pDisp);\n' |
| 1018 | ' %s%s%s\n' |
| 1019 | '%s' |
| 1020 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 1021 | elif proto.name == "DestroyInstance": |
| 1022 | funcs.append('%s%s\n' |
| 1023 | '{\n' |
| 1024 | ' using namespace StreamControl;\n' |
| 1025 | ' VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;\n' |
| 1026 | ' %s%s_dispatch_table(%s)->%s;\n' |
| 1027 | ' tableInstanceMap.erase(pDisp);\n' |
| 1028 | ' %s%s%s\n' |
| 1029 | '%s' |
| 1030 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 1031 | else: |
| 1032 | funcs.append('%s%s\n' |
| 1033 | '{\n' |
| 1034 | ' using namespace StreamControl;\n' |
| 1035 | ' %s%s_dispatch_table(%s)->%s;\n' |
Jon Ashburn | bacb0f5 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 1036 | ' %s%s%s\n' |
| 1037 | '%s' |
Mark Lobodzinski | 4c7ac0a | 2015-05-26 09:29:09 -0500 | [diff] [blame] | 1038 | '}' % (qual, decl, ret_val, table_type, dispatch_param, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mike Stroyan | bf237d7 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1039 | return "\n\n".join(funcs) |
| 1040 | |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1041 | def generate_body(self): |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1042 | self.layer_name = "APIDump" |
| 1043 | body = [self.generate_init(), |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1044 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1045 | self._generate_layer_gpa_function()] |
Tobin Ehlis | 99f8867 | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 1046 | return "\n\n".join(body) |
| 1047 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1048 | class ObjectTrackerSubcommand(Subcommand): |
| 1049 | def generate_header(self): |
| 1050 | header_txt = [] |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1051 | header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <inttypes.h>\n') |
| 1052 | header_txt.append('#include "loader_platform.h"\n') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 1053 | header_txt.append('#include "object_track.h"\n\n') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1054 | header_txt.append('#include <unordered_map>') |
| 1055 | header_txt.append('using namespace std;') |
Ian Elliott | 655cad7 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 1056 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 1057 | header_txt.append('#include "loader_platform.h"') |
Jon Ashburn | 9a7f9a2 | 2015-02-17 11:03:12 -0700 | [diff] [blame] | 1058 | header_txt.append('#include "layers_config.h"') |
Jon Ashburn | d6badbc | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 1059 | header_txt.append('#include "layers_msg.h"') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1060 | header_txt.append('#include "vk_debug_report_lunarg.h"') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1061 | header_txt.append('') |
| 1062 | header_txt.append('static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;') |
| 1063 | header_txt.append('static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;') |
Jon Ashburn | 8c5cbcf | 2015-05-07 10:27:37 -0600 | [diff] [blame] | 1064 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1065 | header_txt.append('') |
| 1066 | header_txt.append('static inline VkLayerDispatchTable *device_dispatch_table(VkObject object) {') |
| 1067 | header_txt.append(' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object;') |
| 1068 | header_txt.append(' VkLayerDispatchTable *pTable = tableMap[pDisp];') |
| 1069 | header_txt.append(' return pTable;') |
| 1070 | header_txt.append('}') |
| 1071 | header_txt.append('') |
| 1072 | header_txt.append('static inline VkLayerInstanceDispatchTable *instance_dispatch_table(VkObject object) {') |
| 1073 | header_txt.append(' VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) object;') |
| 1074 | header_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = tableInstanceMap[*ppDisp];') |
| 1075 | header_txt.append(' return pInstanceTable;') |
| 1076 | header_txt.append('}') |
| 1077 | header_txt.append('') |
Ian Elliott | 2d4ab1e | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 1078 | header_txt.append('static long long unsigned int object_track_index = 0;') |
Tobin Ehlis | 36f1b46 | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 1079 | header_txt.append('static int objLockInitialized = 0;') |
| 1080 | header_txt.append('static loader_platform_thread_mutex objLock;') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1081 | header_txt.append('// Objects stored in a global map w/ struct containing basic info') |
| 1082 | header_txt.append('unordered_map<VkObject, OBJTRACK_NODE*> objMap;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1083 | header_txt.append('') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1084 | header_txt.append('#define NUM_OBJECT_TYPES (VK_NUM_OBJECT_TYPE + (VK_OBJECT_TYPE_SWAP_CHAIN_WSI - VK_OBJECT_TYPE_DISPLAY_WSI))') |
| 1085 | header_txt.append('') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1086 | header_txt.append('static uint64_t numObjs[NUM_OBJECT_TYPES] = {0};') |
| 1087 | header_txt.append('static uint64_t numTotalObjs = 0;') |
| 1088 | header_txt.append('static VkPhysicalDeviceQueueProperties *queueInfo = NULL;') |
| 1089 | header_txt.append('static uint32_t queueCount = 0;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1090 | header_txt.append('') |
| 1091 | header_txt.append('// For each Queue\'s doubly linked-list of mem refs') |
| 1092 | header_txt.append('typedef struct _OT_MEM_INFO {') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1093 | header_txt.append(' VkDeviceMemory mem;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1094 | header_txt.append(' struct _OT_MEM_INFO *pNextMI;') |
| 1095 | header_txt.append(' struct _OT_MEM_INFO *pPrevMI;') |
| 1096 | header_txt.append('') |
| 1097 | header_txt.append('} OT_MEM_INFO;') |
| 1098 | header_txt.append('') |
| 1099 | header_txt.append('// Track Queue information') |
| 1100 | header_txt.append('typedef struct _OT_QUEUE_INFO {') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1101 | header_txt.append(' OT_MEM_INFO *pMemRefList;') |
| 1102 | header_txt.append(' struct _OT_QUEUE_INFO *pNextQI;') |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1103 | header_txt.append(' uint32_t queueNodeIndex;') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1104 | header_txt.append(' VkQueue queue;') |
| 1105 | header_txt.append(' uint32_t refCount;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1106 | header_txt.append('} OT_QUEUE_INFO;') |
| 1107 | header_txt.append('') |
| 1108 | header_txt.append('// Global list of QueueInfo structures, one per queue') |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1109 | header_txt.append('static OT_QUEUE_INFO *g_pQueueInfo = NULL;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1110 | header_txt.append('') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1111 | header_txt.append('// Convert an object type enum to an object type array index') |
| 1112 | header_txt.append('static uint32_t objTypeToIndex(uint32_t objType)') |
| 1113 | header_txt.append('{') |
| 1114 | header_txt.append(' uint32_t index = objType;') |
| 1115 | header_txt.append(' if (objType > VK_OBJECT_TYPE_END_RANGE) {') |
| 1116 | header_txt.append(' // These come from vk_wsi_lunarg.h, rebase') |
| 1117 | header_txt.append(' index = (index -(VK_WSI_LUNARG_EXTENSION_NUMBER * -1000)) + VK_OBJECT_TYPE_END_RANGE;') |
| 1118 | header_txt.append(' }') |
| 1119 | header_txt.append(' return index;') |
| 1120 | header_txt.append('}') |
| 1121 | header_txt.append('') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1122 | header_txt.append('// Validate that object is in the object map') |
Mark Lobodzinski | a999a26 | 2015-06-11 13:51:41 -0500 | [diff] [blame] | 1123 | header_txt.append('static void validate_object(const VkObject object)') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1124 | header_txt.append('{') |
| 1125 | header_txt.append(' if (objMap.find(object) == objMap.end()) {') |
| 1126 | header_txt.append(' char str[1024];') |
| 1127 | header_txt.append(' sprintf(str, "Invalid Object %p", (void*)object);') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1128 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, OBJTRACK_OBJECT_TYPE_MISMATCH, "OBJTRACK", str);') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1129 | header_txt.append(' }') |
| 1130 | header_txt.append('}') |
| 1131 | header_txt.append('') |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1132 | header_txt.append('// Validate that object parameter matches designated object type') |
| 1133 | header_txt.append('static void validateObjectType(') |
| 1134 | header_txt.append(' const char *apiName,') |
| 1135 | header_txt.append(' VkObjectType objType,') |
| 1136 | header_txt.append(' VkObject object)') |
| 1137 | header_txt.append('{') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1138 | header_txt.append(' if (objMap.find(object) != objMap.end()) {') |
| 1139 | header_txt.append(' OBJTRACK_NODE* pNode = objMap[object];') |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1140 | header_txt.append(' // Found our object, check type') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1141 | header_txt.append(' if (strcmp(string_VkObjectType(pNode->objType), string_VkObjectType(objType)) != 0) {') |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1142 | header_txt.append(' char str[1024];') |
| 1143 | header_txt.append(' sprintf(str, "ERROR: Object Parameter Type %s does not match designated type %s",') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1144 | header_txt.append(' string_VkObjectType(pNode->objType), string_VkObjectType(objType));') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1145 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, objType, object, 0, OBJTRACK_OBJECT_TYPE_MISMATCH, "OBJTRACK", str);') |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1146 | header_txt.append(' }') |
| 1147 | header_txt.append(' }') |
| 1148 | header_txt.append('}') |
| 1149 | header_txt.append('') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1150 | header_txt.append('// Add new queue to head of global queue list') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1151 | header_txt.append('static void addQueueInfo(uint32_t queueNodeIndex, VkQueue queue)') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1152 | header_txt.append('{') |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 1153 | header_txt.append(' OT_QUEUE_INFO *pQueueInfo = new OT_QUEUE_INFO;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1154 | header_txt.append('') |
| 1155 | header_txt.append(' if (pQueueInfo != NULL) {') |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1156 | header_txt.append(' memset(pQueueInfo, 0, sizeof(OT_QUEUE_INFO));') |
| 1157 | header_txt.append(' pQueueInfo->queue = queue;') |
| 1158 | header_txt.append(' pQueueInfo->queueNodeIndex = queueNodeIndex;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1159 | header_txt.append(' pQueueInfo->pNextQI = g_pQueueInfo;') |
| 1160 | header_txt.append(' g_pQueueInfo = pQueueInfo;') |
| 1161 | header_txt.append(' }') |
| 1162 | header_txt.append(' else {') |
| 1163 | header_txt.append(' char str[1024];') |
Tony Barbour | d1c3572 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1164 | header_txt.append(' sprintf(str, "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1165 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_QUEUE, queue, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1166 | header_txt.append(' }') |
| 1167 | header_txt.append('}') |
| 1168 | header_txt.append('') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1169 | header_txt.append('// Destroy memRef lists and free all memory') |
| 1170 | header_txt.append('static void destroyQueueMemRefLists()') |
| 1171 | header_txt.append('{') |
| 1172 | header_txt.append(' OT_QUEUE_INFO *pQueueInfo = g_pQueueInfo;') |
| 1173 | header_txt.append(' OT_QUEUE_INFO *pDelQueueInfo = NULL;') |
| 1174 | header_txt.append(' while (pQueueInfo != NULL) {') |
| 1175 | header_txt.append(' OT_MEM_INFO *pMemInfo = pQueueInfo->pMemRefList;') |
| 1176 | header_txt.append(' while (pMemInfo != NULL) {') |
| 1177 | header_txt.append(' OT_MEM_INFO *pDelMemInfo = pMemInfo;') |
| 1178 | header_txt.append(' pMemInfo = pMemInfo->pNextMI;') |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 1179 | header_txt.append(' delete pDelMemInfo;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1180 | header_txt.append(' }') |
| 1181 | header_txt.append(' pDelQueueInfo = pQueueInfo;') |
| 1182 | header_txt.append(' pQueueInfo = pQueueInfo->pNextQI;') |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 1183 | header_txt.append(' delete pDelQueueInfo;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1184 | header_txt.append(' }') |
Jon Ashburn | 1db2014 | 2015-05-18 15:56:55 -0600 | [diff] [blame] | 1185 | header_txt.append(' g_pQueueInfo = pQueueInfo;') |
Mark Lobodzinski | ebc5cb4 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1186 | header_txt.append('}') |
| 1187 | header_txt.append('') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1188 | header_txt.append('static void create_obj(VkObject vkObj, VkObjectType objType) {') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1189 | header_txt.append(' char str[1024];') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1190 | header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkObjectType(objType), reinterpret_cast<VkUintPtrLeast64>(vkObj));') |
| 1191 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_INFO_BIT, objType, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1192 | header_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;') |
| 1193 | header_txt.append(' pNewObjNode->vkObj = vkObj;') |
| 1194 | header_txt.append(' pNewObjNode->objType = objType;') |
| 1195 | header_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;') |
| 1196 | header_txt.append(' objMap[vkObj] = pNewObjNode;') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1197 | header_txt.append(' uint32_t objIndex = objTypeToIndex(objType);') |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1198 | header_txt.append(' numObjs[objIndex]++;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1199 | header_txt.append(' numTotalObjs++;') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1200 | header_txt.append('}') |
| 1201 | header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally') |
| 1202 | header_txt.append('// remove obj from global list') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1203 | header_txt.append('static void destroy_obj(VkObject vkObj) {') |
| 1204 | header_txt.append(' if (objMap.find(vkObj) != objMap.end()) {') |
| 1205 | header_txt.append(' OBJTRACK_NODE* pNode = objMap[vkObj];') |
| 1206 | header_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);') |
| 1207 | header_txt.append(' assert(numTotalObjs > 0);') |
| 1208 | header_txt.append(' numTotalObjs--;') |
| 1209 | header_txt.append(' assert(numObjs[objIndex] > 0);') |
| 1210 | header_txt.append(' numObjs[objIndex]--;') |
| 1211 | header_txt.append(' char str[1024];') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1212 | 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));') |
| 1213 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_INFO_BIT, pNode->objType, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1214 | header_txt.append(' delete pNode;') |
| 1215 | header_txt.append(' objMap.erase(vkObj);') |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1216 | header_txt.append(' }') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1217 | header_txt.append(' else {') |
| 1218 | header_txt.append(' char str[1024];') |
| 1219 | 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 | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1220 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1221 | header_txt.append(' }') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1222 | header_txt.append('}') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1223 | header_txt.append('// Set selected flag state for an object node') |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 1224 | header_txt.append('static void set_status(VkObject vkObj, VkObjectType objType, ObjectStatusFlags status_flag) {') |
Tony Barbour | 9671531 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1225 | header_txt.append(' if (vkObj != VK_NULL_HANDLE) {') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1226 | header_txt.append(' if (objMap.find(vkObj) != objMap.end()) {') |
| 1227 | header_txt.append(' OBJTRACK_NODE* pNode = objMap[vkObj];') |
| 1228 | header_txt.append(' pNode->status |= status_flag;') |
| 1229 | header_txt.append(' return;') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1230 | header_txt.append(' }') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1231 | header_txt.append(' else {') |
| 1232 | header_txt.append(' // If we do not find it print an error') |
| 1233 | header_txt.append(' char str[1024];') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1234 | 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));') |
| 1235 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1236 | header_txt.append(' }') |
| 1237 | header_txt.append(' }') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1238 | header_txt.append('}') |
| 1239 | header_txt.append('') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1240 | header_txt.append('// Reset selected flag state for an object node') |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 1241 | header_txt.append('static void reset_status(VkObject vkObj, VkObjectType objType, ObjectStatusFlags status_flag) {') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1242 | header_txt.append(' if (objMap.find(vkObj) != objMap.end()) {') |
| 1243 | header_txt.append(' OBJTRACK_NODE* pNode = objMap[vkObj];') |
| 1244 | header_txt.append(' pNode->status &= ~status_flag;') |
| 1245 | header_txt.append(' return;') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1246 | header_txt.append(' }') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1247 | header_txt.append(' else {') |
| 1248 | header_txt.append(' // If we do not find it print an error') |
| 1249 | header_txt.append(' char str[1024];') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1250 | 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));') |
| 1251 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, objType, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1252 | header_txt.append(' }') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1253 | header_txt.append('}') |
| 1254 | header_txt.append('') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1255 | header_txt.append('static void setGpuQueueInfoState(size_t* pDataSize, void *pData) {') |
| 1256 | header_txt.append(' queueCount = ((uint32_t)*pDataSize / sizeof(VkPhysicalDeviceQueueProperties));') |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1257 | header_txt.append(' queueInfo = (VkPhysicalDeviceQueueProperties*)realloc((void*)queueInfo, *pDataSize);') |
| 1258 | header_txt.append(' if (queueInfo != NULL) {') |
| 1259 | header_txt.append(' memcpy(queueInfo, pData, *pDataSize);') |
| 1260 | header_txt.append(' }') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1261 | header_txt.append('}') |
| 1262 | header_txt.append('') |
Mark Lobodzinski | 38f0db2 | 2015-05-20 17:33:47 -0500 | [diff] [blame] | 1263 | header_txt.append('// Check Queue type flags for selected queue operations') |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1264 | header_txt.append('static void validateQueueFlags(VkQueue queue, const char *function) {') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1265 | header_txt.append(' OT_QUEUE_INFO *pQueueInfo = g_pQueueInfo;') |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1266 | header_txt.append(' while ((pQueueInfo != NULL) && (pQueueInfo->queue != queue)) {') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1267 | header_txt.append(' pQueueInfo = pQueueInfo->pNextQI;') |
| 1268 | header_txt.append(' }') |
| 1269 | header_txt.append(' if (pQueueInfo != NULL) {') |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1270 | header_txt.append(' char str[1024];\n') |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 1271 | header_txt.append(' if ((queueInfo != NULL) && (queueInfo[pQueueInfo->queueNodeIndex].queueFlags & VK_QUEUE_SPARSE_MEMMGR_BIT) == 0) {') |
| 1272 | header_txt.append(' sprintf(str, "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_SPARSE_MEMMGR_BIT not set", function);') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1273 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_QUEUE, queue, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1274 | header_txt.append(' } else {') |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 1275 | 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 | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1276 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_QUEUE, queue, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1277 | header_txt.append(' }') |
| 1278 | header_txt.append(' }') |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1279 | header_txt.append('}') |
| 1280 | header_txt.append('') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1281 | header_txt.append('// Check object status for selected flag state') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1282 | 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 | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1283 | header_txt.append(' if (objMap.find(vkObj) != objMap.end()) {') |
| 1284 | header_txt.append(' OBJTRACK_NODE* pNode = objMap[vkObj];') |
| 1285 | header_txt.append(' if ((pNode->status & status_mask) != status_flag) {') |
| 1286 | header_txt.append(' char str[1024];') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1287 | header_txt.append(' sprintf(str, "OBJECT VALIDATION WARNING: %s object 0x%" PRIxLEAST64 ": %s", string_VkObjectType(objType), reinterpret_cast<VkUintPtrLeast64>(vkObj), fail_msg);') |
| 1288 | header_txt.append(' layerCbMsg(msg_flags, pNode->objType, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1289 | header_txt.append(' return VK_FALSE;') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1290 | header_txt.append(' }') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1291 | header_txt.append(' return VK_TRUE;') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1292 | header_txt.append(' }') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1293 | header_txt.append(' else {') |
| 1294 | header_txt.append(' // If we do not find it print an error') |
| 1295 | header_txt.append(' char str[1024];') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1296 | 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));') |
| 1297 | header_txt.append(' layerCbMsg(msg_flags, (VkObjectType) 0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1298 | header_txt.append(' return VK_FALSE;') |
| 1299 | header_txt.append(' }') |
Tobin Ehlis | 91ce77e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1300 | header_txt.append('}') |
Mark Lobodzinski | 4037087 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1301 | header_txt.append('') |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1302 | return "\n".join(header_txt) |
| 1303 | |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1304 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | d971b61 | 2015-06-17 20:51:59 -0600 | [diff] [blame^] | 1305 | if proto.name in [ 'DbgCreateMsgCallback', 'GetGlobalExtensionInfo', 'GetPhysicalDeviceExtensionInfo' ]: |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1306 | # use default version |
| 1307 | return None |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1308 | |
| 1309 | # Create map of object names to object type enums of the form VkName : VkObjectTypeName |
Tobin Ehlis | b870cbb | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 1310 | obj_type_mapping = {base_t : base_t.replace("Vk", "VkObjectType") for base_t in vulkan.object_type_list} |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1311 | # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES |
| 1312 | for objectName, objectTypeEnum in obj_type_mapping.items(): |
| 1313 | obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum); |
| 1314 | # Command Buffer Object doesn't follow the rule. |
| 1315 | obj_type_mapping['VkCmdBuffer'] = "VK_OBJECT_TYPE_COMMAND_BUFFER" |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1316 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1317 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1318 | param0_name = proto.params[0].name |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1319 | using_line = '' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1320 | create_line = '' |
| 1321 | destroy_line = '' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1322 | object_params = [] |
| 1323 | # TODO : Should also check through struct params & add any objects embedded in struct chains |
| 1324 | # TODO : A few of the skipped types are just "hard" cases that need some more work to support |
| 1325 | # Need to handle NULL fences on queue submit, binding null memory, and WSI Image objects |
| 1326 | for p in proto.params: |
| 1327 | if p.ty in vulkan.core.objects and p.ty not in ['VkPhysicalDevice', 'VkQueue', 'VkFence', 'VkImage', 'VkDeviceMemory']: |
| 1328 | object_params.append(p.name) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1329 | funcs = [] |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1330 | mutex_unlock = False |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1331 | if 'QueueSubmit' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1332 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1333 | using_line += ' set_status(fence, VK_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED);\n' |
Courtney Goeltzenleuchter | 97b7523 | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1334 | using_line += ' // TODO: Fix for updated memory reference mechanism\n' |
| 1335 | using_line += ' // validate_memory_mapping_status(pMemRefs, memRefCount);\n' |
| 1336 | using_line += ' // validate_mem_ref_count(memRefCount);\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1337 | mutex_unlock = True |
Mark Lobodzinski | 942b172 | 2015-05-11 17:21:15 -0500 | [diff] [blame] | 1338 | elif 'QueueBindSparse' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1339 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mike Stroyan | 1b5e91f | 2015-05-05 16:33:08 -0600 | [diff] [blame] | 1340 | using_line += ' validateQueueFlags(queue, "%s");\n' % (proto.name) |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1341 | mutex_unlock = True |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1342 | elif 'QueueBindObject' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1343 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1344 | using_line += ' validateObjectType("vk%s", objType, object);\n' % (proto.name) |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1345 | mutex_unlock = True |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1346 | elif 'GetObjectInfo' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1347 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1348 | using_line += ' validateObjectType("vk%s", objType, object);\n' % (proto.name) |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1349 | mutex_unlock = True |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1350 | elif 'GetFenceStatus' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1351 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1352 | using_line += ' // Warn if submitted_flag is not set\n' |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1353 | 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 | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1354 | mutex_unlock = True |
Mark Lobodzinski | 0d067d1 | 2015-04-22 15:06:12 -0600 | [diff] [blame] | 1355 | elif 'WaitForFences' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1356 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | 0d067d1 | 2015-04-22 15:06:12 -0600 | [diff] [blame] | 1357 | using_line += ' // Warn if waiting on unsubmitted fence\n' |
| 1358 | using_line += ' for (uint32_t i = 0; i < fenceCount; i++) {\n' |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1359 | 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 | 0d067d1 | 2015-04-22 15:06:12 -0600 | [diff] [blame] | 1360 | using_line += ' }\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1361 | mutex_unlock = True |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1362 | elif 'MapMemory' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1363 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1364 | using_line += ' set_status(mem, VK_OBJECT_TYPE_DEVICE_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1365 | mutex_unlock = True |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1366 | elif 'UnmapMemory' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1367 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1368 | using_line += ' reset_status(mem, VK_OBJECT_TYPE_DEVICE_MEMORY, OBJSTATUS_GPU_MEM_MAPPED);\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1369 | mutex_unlock = True |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1370 | elif 'AllocDescriptor' in proto.name: # Allocates array of DSs |
| 1371 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1372 | create_line += ' for (uint32_t i = 0; i < *pCount; i++) {\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1373 | create_line += ' create_obj(pDescriptorSets[i], VK_OBJECT_TYPE_DESCRIPTOR_SET);\n' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1374 | create_line += ' }\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1375 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1376 | elif 'Create' in proto.name or 'Alloc' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1377 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1378 | create_line += ' create_obj(*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').replace('const ', '')]) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1379 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1380 | if 'CreateDevice' in proto.name: |
| 1381 | create_line += ' if (result == VK_SUCCESS) {\n' |
| 1382 | create_line += ' enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);\n' |
| 1383 | create_line += ' }\n' |
| 1384 | |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1385 | if 'GetDeviceQueue' in proto.name: |
| 1386 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1387 | destroy_line += ' addQueueInfo(queueNodeIndex, *pQueue);\n' |
| 1388 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1389 | elif 'DestroyObject' in proto.name: |
| 1390 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | 03a7e98 | 2015-05-05 18:24:45 -0500 | [diff] [blame] | 1391 | destroy_line += ' validateObjectType("vk%s", objType, object);\n' % (proto.name) |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1392 | destroy_line += ' destroy_obj(%s);\n' % (proto.params[2].name) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1393 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1394 | elif 'DestroyDevice' in proto.name: |
Mark Lobodzinski | 00c4e64 | 2015-05-26 12:16:22 -0500 | [diff] [blame] | 1395 | using_line = ' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1396 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1397 | destroy_line += ' destroy_obj(device);\n' |
| 1398 | destroy_line += ' // Report any remaining objects\n' |
| 1399 | destroy_line += ' for (auto it = objMap.begin(); it != objMap.end(); ++it) {\n' |
| 1400 | destroy_line += ' OBJTRACK_NODE* pNode = it->second;' |
| 1401 | destroy_line += ' if ((pNode->objType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) || (pNode->objType == VK_OBJECT_TYPE_QUEUE)) {\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1402 | destroy_line += ' // Cannot destroy physical device so ignore\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1403 | destroy_line += ' } else {\n' |
| 1404 | destroy_line += ' char str[1024];\n' |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1405 | destroy_line += ' sprintf(str, "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkObjectType(pNode->objType), reinterpret_cast<VkUintPtrLeast64>(pNode->vkObj));\n' |
| 1406 | destroy_line += ' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1407 | destroy_line += ' }\n' |
| 1408 | destroy_line += ' }\n' |
| 1409 | destroy_line += ' // Clean up Queue\'s MemRef Linked Lists\n' |
| 1410 | destroy_line += ' destroyQueueMemRefLists();\n' |
| 1411 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1412 | elif 'DestroyInstance' in proto.name: |
Mark Lobodzinski | 00c4e64 | 2015-05-26 12:16:22 -0500 | [diff] [blame] | 1413 | using_line = ' VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1414 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1415 | destroy_line += ' destroy_obj(%s);\n' % (param0_name) |
| 1416 | destroy_line += ' // Report any remaining objects in LL\n' |
| 1417 | destroy_line += ' for (auto it = objMap.begin(); it != objMap.end(); ++it) {\n' |
| 1418 | destroy_line += ' OBJTRACK_NODE* pNode = it->second; if ((pNode->objType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) || (pNode->objType == VK_OBJECT_TYPE_QUEUE)) {\n' |
| 1419 | destroy_line += ' // Cannot destroy physical device so ignore\n' |
| 1420 | destroy_line += ' } else {\n' |
| 1421 | destroy_line += ' char str[1024];\n' |
| 1422 | destroy_line += ' sprintf(str, "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkObjectType(pNode->objType), reinterpret_cast<VkUintPtrLeast64>(pNode->vkObj));\n' |
| 1423 | destroy_line += ' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, pNode->objType, pNode->vkObj, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n' |
| 1424 | destroy_line += ' }\n' |
| 1425 | destroy_line += ' }\n' |
| 1426 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1427 | elif 'Free' in proto.name: |
| 1428 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1429 | destroy_line += ' destroy_obj(%s);\n' % (proto.params[1].name) |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1430 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Tobin Ehlis | 803cc49 | 2015-06-08 17:36:28 -0600 | [diff] [blame] | 1431 | elif 'Destroy' in proto.name: |
| 1432 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1433 | destroy_line += ' destroy_obj(%s);\n' % (param0_name) |
| 1434 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1435 | if len(object_params) > 0: |
| 1436 | if not mutex_unlock: |
| 1437 | using_line += ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1438 | mutex_unlock = True |
| 1439 | for opn in object_params: |
| 1440 | using_line += ' validate_object(%s);\n' % (opn) |
| 1441 | if mutex_unlock: |
| 1442 | using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1443 | ret_val = '' |
| 1444 | stmt = '' |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1445 | table = '' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1446 | if proto.ret != "void": |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1447 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1448 | stmt = " return result;\n" |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1449 | if proto_is_global(proto): |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1450 | table = 'Instance' |
| 1451 | |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1452 | if 'GetPhysicalDeviceInfo' in proto.name: |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1453 | gpu_state = ' if (infoType == VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES) {\n' |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1454 | gpu_state += ' if (pData != NULL) {\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1455 | gpu_state += ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | e2167aa | 2015-04-30 17:04:27 -0500 | [diff] [blame] | 1456 | gpu_state += ' setGpuQueueInfoState(pDataSize, pData);\n' |
Mark Lobodzinski | 48bd16d | 2015-05-08 09:12:28 -0500 | [diff] [blame] | 1457 | gpu_state += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1458 | gpu_state += ' }\n' |
| 1459 | gpu_state += ' }\n' |
| 1460 | funcs.append('%s%s\n' |
| 1461 | '{\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1462 | '%s' |
| 1463 | ' %sinstance_dispatch_table(gpu)->%s;\n' |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1464 | '%s%s' |
| 1465 | '%s' |
| 1466 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1467 | '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, gpu_state, stmt)) |
Jon Ashburn | 4d9f465 | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1468 | else: |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1469 | # CreateInstance needs to use the second parm instead of the first to set the correct dispatch table |
| 1470 | dispatch_param = param0_name |
| 1471 | # Must use 'instance' table for these APIs, 'device' table otherwise |
| 1472 | table_type = "" |
| 1473 | if proto_is_global(proto): |
| 1474 | table_type = "instance" |
| 1475 | else: |
| 1476 | table_type = "device" |
| 1477 | if 'CreateInstance' in proto.name: |
| 1478 | dispatch_param = '*' + proto.params[1].name |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1479 | funcs.append('%s%s\n' |
| 1480 | '{\n' |
| 1481 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1482 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1483 | '%s%s' |
| 1484 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1485 | '}' % (qual, decl, using_line, ret_val, table_type, dispatch_param, proto.c_call(), create_line, destroy_line, stmt)) |
Mike Stroyan | 00087e6 | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1486 | return "\n\n".join(funcs) |
| 1487 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1488 | def generate_body(self): |
Mike Stroyan | 3e3a1eb | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1489 | self.layer_name = "ObjectTracker" |
| 1490 | body = [self._generate_layer_initialization(True, lockname='obj'), |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1491 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Tobin Ehlis | ca91587 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1492 | self._generate_extensions(), |
Mark Lobodzinski | 7c75b85 | 2015-05-05 15:01:37 -0500 | [diff] [blame] | 1493 | self._generate_layer_gpa_function(extensions=['objTrackGetObjectsCount', 'objTrackGetObjects', 'objTrackGetObjectsOfTypeCount', 'objTrackGetObjectsOfType'])] |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1494 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | b412d21 | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1495 | |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1496 | class ThreadingSubcommand(Subcommand): |
| 1497 | def generate_header(self): |
| 1498 | header_txt = [] |
| 1499 | header_txt.append('#include <stdio.h>') |
| 1500 | header_txt.append('#include <stdlib.h>') |
| 1501 | header_txt.append('#include <string.h>') |
| 1502 | header_txt.append('#include <unordered_map>') |
| 1503 | header_txt.append('#include "loader_platform.h"') |
| 1504 | header_txt.append('#include "vkLayer.h"') |
| 1505 | header_txt.append('#include "threading.h"') |
| 1506 | header_txt.append('#include "layers_config.h"') |
| 1507 | header_txt.append('#include "vk_enum_validate_helper.h"') |
| 1508 | header_txt.append('#include "vk_struct_validate_helper.h"') |
| 1509 | header_txt.append('//The following is #included again to catch certain OS-specific functions being used:') |
| 1510 | header_txt.append('#include "loader_platform.h"\n') |
| 1511 | header_txt.append('#include "layers_msg.h"\n') |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1512 | header_txt.append('') |
| 1513 | header_txt.append('static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;') |
| 1514 | header_txt.append('static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;') |
| 1515 | header_txt.append('') |
| 1516 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);') |
| 1517 | header_txt.append('') |
| 1518 | header_txt.append('static inline VkLayerDispatchTable *device_dispatch_table(VkObject object) {') |
| 1519 | header_txt.append(' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) object;') |
| 1520 | header_txt.append(' VkLayerDispatchTable *pTable = tableMap[pDisp];') |
| 1521 | header_txt.append(' return pTable;') |
| 1522 | header_txt.append('}') |
| 1523 | header_txt.append('') |
| 1524 | header_txt.append('static inline VkLayerInstanceDispatchTable *instance_dispatch_table(VkObject object) {') |
| 1525 | header_txt.append(' VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) object;') |
| 1526 | header_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = tableInstanceMap[*ppDisp];') |
| 1527 | header_txt.append(' return pInstanceTable;') |
| 1528 | header_txt.append('}') |
| 1529 | header_txt.append('') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1530 | header_txt.append('using namespace std;') |
| 1531 | header_txt.append('static unordered_map<int, void*> proxy_objectsInUse;\n') |
| 1532 | header_txt.append('static unordered_map<VkObject, loader_platform_thread_id> objectsInUse;\n') |
| 1533 | header_txt.append('static int threadingLockInitialized = 0;') |
| 1534 | header_txt.append('static loader_platform_thread_mutex threadingLock;') |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1535 | header_txt.append('static loader_platform_thread_cond threadingCond;') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1536 | header_txt.append('static int printLockInitialized = 0;') |
| 1537 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
| 1538 | header_txt.append('') |
| 1539 | header_txt.append('static void useObject(VkObject object, const char* type)') |
| 1540 | header_txt.append('{') |
| 1541 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
| 1542 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1543 | header_txt.append(' if (objectsInUse.find(object) == objectsInUse.end()) {') |
| 1544 | header_txt.append(' objectsInUse[object] = tid;') |
| 1545 | header_txt.append(' } else {') |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1546 | header_txt.append(' if (objectsInUse[object] != tid) {') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1547 | header_txt.append(' char str[1024];') |
| 1548 | 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 | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1549 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, 0, 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING", str);') |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1550 | header_txt.append(' // Wait for thread-safe access to object') |
| 1551 | header_txt.append(' while (objectsInUse.find(object) != objectsInUse.end()) {') |
| 1552 | header_txt.append(' loader_platform_thread_cond_wait(&threadingCond, &threadingLock);') |
| 1553 | header_txt.append(' }') |
| 1554 | header_txt.append(' objectsInUse[object] = tid;') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1555 | header_txt.append(' } else {') |
| 1556 | header_txt.append(' char str[1024];') |
| 1557 | header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is recursively used in thread %ld", type, tid);') |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1558 | header_txt.append(' layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, 0, 0, THREADING_CHECKER_SINGLE_THREAD_REUSE, "THREADING", str);') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1559 | header_txt.append(' }') |
| 1560 | header_txt.append(' }') |
| 1561 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1562 | header_txt.append('}') |
| 1563 | header_txt.append('static void finishUsingObject(VkObject object)') |
| 1564 | header_txt.append('{') |
| 1565 | header_txt.append(' // Object is no longer in use') |
| 1566 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1567 | header_txt.append(' objectsInUse.erase(object);') |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1568 | header_txt.append(' loader_platform_thread_cond_broadcast(&threadingCond);') |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1569 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1570 | header_txt.append('}') |
| 1571 | return "\n".join(header_txt) |
| 1572 | |
| 1573 | def generate_intercept(self, proto, qual): |
Courtney Goeltzenleuchter | f579fa6 | 2015-06-10 17:39:03 -0600 | [diff] [blame] | 1574 | if proto.name in [ 'DbgCreateMsgCallback' ]: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1575 | # use default version |
| 1576 | return None |
| 1577 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1578 | thread_check_objects = [ |
| 1579 | "VkQueue", |
| 1580 | "VkDeviceMemory", |
| 1581 | "VkObject", |
| 1582 | "VkBuffer", |
| 1583 | "VkImage", |
| 1584 | "VkDescriptorSet", |
| 1585 | "VkDescriptorPool", |
| 1586 | "VkCmdBuffer", |
| 1587 | "VkSemaphore" |
| 1588 | ] |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1589 | ret_val = '' |
| 1590 | stmt = '' |
| 1591 | funcs = [] |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1592 | table = 'device' |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1593 | if proto.ret != "void": |
Jon Ashburn | b0fbe91 | 2015-05-06 10:15:07 -0600 | [diff] [blame] | 1594 | ret_val = "%s result = " % proto.ret |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1595 | stmt = " return result;\n" |
Jon Ashburn | 95a77ba | 2015-05-15 15:09:35 -0600 | [diff] [blame] | 1596 | if proto_is_global(proto): |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1597 | table = 'instance' |
Jon Ashburn | 71836d9 | 2015-05-12 17:23:55 -0600 | [diff] [blame] | 1598 | |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1599 | # Memory range calls are special in needed thread checking within structs |
| 1600 | if proto.name in ["FlushMappedMemoryRanges","InvalidateMappedMemoryRanges"]: |
| 1601 | funcs.append('%s%s\n' |
| 1602 | '{\n' |
| 1603 | ' for (int i=0; i<memRangeCount; i++) {\n' |
| 1604 | ' useObject((VkObject) pMemRanges[i].mem, "VkDeviceMemory");\n' |
| 1605 | ' }\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1606 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1607 | ' for (int i=0; i<memRangeCount; i++) {\n' |
| 1608 | ' finishUsingObject((VkObject) pMemRanges[i].mem);\n' |
| 1609 | ' }\n' |
| 1610 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1611 | '}' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call(), stmt)) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1612 | return "\n".join(funcs) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1613 | # All functions that do a Get are thread safe |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1614 | if 'Get' in proto.name: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1615 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1616 | # All WSI functions are thread safe |
| 1617 | if 'WSI' in proto.name: |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1618 | return None |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1619 | # Initialize in early calls |
| 1620 | if proto.params[0].ty == "VkPhysicalDevice": |
| 1621 | funcs.append('%s%s\n' |
| 1622 | '{\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1623 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1624 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1625 | '}' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call(), stmt)) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1626 | return "\n".join(funcs) |
| 1627 | # Functions changing command buffers need thread safe use of first parameter |
| 1628 | if proto.params[0].ty == "VkCmdBuffer": |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1629 | funcs.append('%s%s\n' |
| 1630 | '{\n' |
| 1631 | ' useObject((VkObject) %s, "%s");\n' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1632 | ' %s%s_dispatch_table(%s)->%s;\n' |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1633 | ' finishUsingObject((VkObject) %s);\n' |
| 1634 | '%s' |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1635 | '}' % (qual, decl, proto.params[0].name, proto.params[0].ty, ret_val, table, proto.params[0].name, proto.c_call(), proto.params[0].name, stmt)) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1636 | return "\n".join(funcs) |
| 1637 | # Non-Cmd functions that do a Wait are thread safe |
| 1638 | if 'Wait' in proto.name: |
| 1639 | return None |
| 1640 | # Watch use of certain types of objects passed as any parameter |
| 1641 | checked_params = [] |
| 1642 | for param in proto.params: |
| 1643 | if param.ty in thread_check_objects: |
| 1644 | checked_params.append(param) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1645 | if proto.name == "DestroyDevice": |
| 1646 | funcs.append('%s%s\n' |
| 1647 | '{\n' |
| 1648 | ' VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **) device;\n' |
| 1649 | ' %s%s_dispatch_table(%s)->%s;\n' |
| 1650 | ' tableMap.erase(pDisp);\n' |
| 1651 | ' return result;\n' |
| 1652 | '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) |
| 1653 | return "\n".join(funcs); |
| 1654 | elif proto.name == "DestroyInstance": |
| 1655 | funcs.append('%s%s\n' |
| 1656 | '{\n' |
| 1657 | ' VkLayerInstanceDispatchTable *pDisp = *(VkLayerInstanceDispatchTable **) instance;\n' |
| 1658 | ' %s%s_dispatch_table(%s)->%s;\n' |
| 1659 | ' tableInstanceMap.erase(pDisp);\n' |
| 1660 | ' return result;\n' |
| 1661 | '}\n' % (qual, decl, ret_val, table, proto.params[0].name, proto.c_call())) |
| 1662 | return "\n".join(funcs); |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1663 | if len(checked_params) == 0: |
| 1664 | return None |
| 1665 | # Surround call with useObject and finishUsingObject for each checked_param |
| 1666 | funcs.append('%s%s' % (qual, decl)) |
| 1667 | funcs.append('{') |
| 1668 | for param in checked_params: |
| 1669 | funcs.append(' useObject((VkObject) %s, "%s");' % (param.name, param.ty)) |
Mark Lobodzinski | fb5437a | 2015-05-22 14:15:36 -0500 | [diff] [blame] | 1670 | funcs.append(' %s%s_dispatch_table(%s)->%s;' % (ret_val, table, proto.params[0].name, proto.c_call())) |
Mike Stroyan | 6ea73e4 | 2015-05-11 17:18:14 -0600 | [diff] [blame] | 1671 | for param in checked_params: |
| 1672 | funcs.append(' finishUsingObject((VkObject) %s);' % param.name) |
| 1673 | funcs.append('%s' |
| 1674 | '}' % stmt) |
| 1675 | return "\n".join(funcs) |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1676 | |
| 1677 | def generate_body(self): |
| 1678 | self.layer_name = "Threading" |
Mike Stroyan | ed238bb | 2015-05-15 08:50:57 -0600 | [diff] [blame] | 1679 | body = [self._generate_layer_initialization(True, lockname='threading', condname='threading'), |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1680 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
| 1681 | self._generate_layer_gpa_function()] |
| 1682 | return "\n\n".join(body) |
| 1683 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1684 | def main(): |
| 1685 | subcommands = { |
| 1686 | "layer-funcs" : LayerFuncsSubcommand, |
| 1687 | "layer-dispatch" : LayerDispatchSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1688 | "Generic" : GenericLayerSubcommand, |
Tobin Ehlis | e78dbd8 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1689 | "APIDump" : APIDumpSubcommand, |
Tobin Ehlis | a363cfa | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1690 | "ObjectTracker" : ObjectTrackerSubcommand, |
Mike Stroyan | 3712d5c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1691 | "Threading" : ThreadingSubcommand, |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1692 | } |
| 1693 | |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1694 | if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]): |
| 1695 | print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1696 | print |
Tobin Ehlis | 7e65d75 | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1697 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1698 | exit(1) |
| 1699 | |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1700 | hfp = vk_helper.HeaderFileParser(sys.argv[2]) |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1701 | hfp.parse() |
Courtney Goeltzenleuchter | d8e229c | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1702 | vk_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1703 | vk_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1704 | vk_helper.struct_dict = hfp.get_struct_dict() |
| 1705 | vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1706 | vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1707 | vk_helper.types_dict = hfp.get_types_dict() |
Tobin Ehlis | 14ff085 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1708 | |
Tobin Ehlis | 12076fc | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1709 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1710 | subcmd.run() |
| 1711 | |
| 1712 | if __name__ == "__main__": |
| 1713 | main() |