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