Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 3 | # VK |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 4 | # |
| 5 | # Copyright (C) 2014 LunarG, Inc. |
| 6 | # |
| 7 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | # copy of this software and associated documentation files (the "Software"), |
| 9 | # to deal in the Software without restriction, including without limitation |
| 10 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | # and/or sell copies of the Software, and to permit persons to whom the |
| 12 | # Software is furnished to do so, subject to the following conditions: |
| 13 | # |
| 14 | # The above copyright notice and this permission notice shall be included |
| 15 | # in all copies or substantial portions of the Software. |
| 16 | # |
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | # DEALINGS IN THE SOFTWARE. |
| 24 | # |
| 25 | # Authors: |
| 26 | # Chia-I Wu <olv@lunarg.com> |
| 27 | |
| 28 | import sys |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 29 | import os |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 30 | |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 31 | import vulkan |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 32 | import vk_helper |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 33 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 34 | def generate_get_proc_addr_check(name): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 35 | return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \ |
| 36 | " return NULL;" % ((name,) * 3) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 37 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 38 | class Subcommand(object): |
| 39 | def __init__(self, argv): |
| 40 | self.argv = argv |
Courtney Goeltzenleuchter | a8c0628 | 2015-04-14 14:55:44 -0600 | [diff] [blame] | 41 | self.headers = vulkan.headers |
| 42 | self.protos = vulkan.protos |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 43 | self.no_addr = False |
| 44 | self.layer_name = "" |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 45 | |
| 46 | def run(self): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 47 | print(self.generate()) |
| 48 | |
| 49 | def generate(self): |
| 50 | copyright = self.generate_copyright() |
| 51 | header = self.generate_header() |
| 52 | body = self.generate_body() |
| 53 | footer = self.generate_footer() |
| 54 | |
| 55 | contents = [] |
| 56 | if copyright: |
| 57 | contents.append(copyright) |
| 58 | if header: |
| 59 | contents.append(header) |
| 60 | if body: |
| 61 | contents.append(body) |
| 62 | if footer: |
| 63 | contents.append(footer) |
| 64 | |
| 65 | return "\n\n".join(contents) |
| 66 | |
| 67 | def generate_copyright(self): |
| 68 | return """/* THIS FILE IS GENERATED. DO NOT EDIT. */ |
| 69 | |
| 70 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 71 | * Vulkan |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 72 | * |
| 73 | * Copyright (C) 2014 LunarG, Inc. |
| 74 | * |
| 75 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 76 | * copy of this software and associated documentation files (the "Software"), |
| 77 | * to deal in the Software without restriction, including without limitation |
| 78 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 79 | * and/or sell copies of the Software, and to permit persons to whom the |
| 80 | * Software is furnished to do so, subject to the following conditions: |
| 81 | * |
| 82 | * The above copyright notice and this permission notice shall be included |
| 83 | * in all copies or substantial portions of the Software. |
| 84 | * |
| 85 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 86 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 87 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 88 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 89 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 90 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 91 | * DEALINGS IN THE SOFTWARE. |
| 92 | */""" |
| 93 | |
| 94 | def generate_header(self): |
| 95 | return "\n".join(["#include <" + h + ">" for h in self.headers]) |
| 96 | |
| 97 | def generate_body(self): |
| 98 | pass |
| 99 | |
| 100 | def generate_footer(self): |
| 101 | pass |
| 102 | |
| 103 | # Return set of printf '%' qualifier and input to that qualifier |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 104 | def _get_printf_params(self, vk_type, name, output_param, cpp=False): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 105 | # TODO : Need ENUM and STRUCT checks here |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 106 | if vk_helper.is_type(vk_type, 'enum'):#"_TYPE" in vk_type: # TODO : This should be generic ENUM check |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 107 | return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 108 | if "char*" == vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 109 | return ("%s", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 110 | if "uint64" in vk_type: |
| 111 | if '*' in vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 112 | return ("%lu", "*%s" % name) |
| 113 | return ("%lu", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 114 | if "size" in vk_type: |
| 115 | if '*' in vk_type: |
Chia-I Wu | 54ed079 | 2014-12-27 14:14:50 +0800 | [diff] [blame] | 116 | return ("%zu", "*%s" % name) |
| 117 | return ("%zu", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 118 | if "float" in vk_type: |
| 119 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 120 | if cpp: |
| 121 | return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 122 | return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
| 123 | return ("%f", name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 124 | if "bool" in vk_type or 'xcb_randr_crtc_t' in vk_type: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 125 | return ("%u", name) |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 126 | if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 127 | if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 128 | if cpp: |
| 129 | return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 130 | return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 131 | if '*' in vk_type: |
Tobin Ehlis | 1336c8d | 2015-02-04 15:15:11 -0700 | [diff] [blame] | 132 | if 'pUserData' == name: |
| 133 | return ("%i", "((pUserData == 0) ? 0 : *(pUserData))") |
Tobin Ehlis | a74d53a | 2015-04-17 13:26:33 -0600 | [diff] [blame] | 134 | if 'const' in vk_type.lower(): |
| 135 | return ("%p", "(void*)(%s)" % name) |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 136 | return ("%i", "*(%s)" % name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 137 | return ("%i", name) |
Tobin Ehlis | 0a1e06d | 2014-11-11 17:28:22 -0700 | [diff] [blame] | 138 | # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 139 | if "VkFormat" == vk_type: |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 140 | if cpp: |
| 141 | return ("%p", "&%s" % name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 142 | return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_CHANNEL_FORMAT(%s.channelFormat), string_VK_NUM_FORMAT(%s.numericFormat)" % (name, name)) |
Tobin Ehlis | a554dc3 | 2014-11-19 15:52:46 -0700 | [diff] [blame] | 143 | if output_param: |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 144 | return ("%p", "(void*)*%s" % name) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 145 | if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type: |
Courtney Goeltzenleuchter | 9a1ded8 | 2015-04-03 16:35:32 -0600 | [diff] [blame] | 146 | return ("%p", "(void*)(&%s)" % name) |
Jon Ashburn | 1f7e2d7 | 2014-12-12 16:10:45 -0700 | [diff] [blame] | 147 | return ("%p", "(void*)(%s)" % name) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 148 | |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 149 | def _gen_layer_dbg_callback_register(self): |
| 150 | r_body = [] |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 151 | r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 152 | r_body.append('{') |
| 153 | r_body.append(' // This layer intercepts callbacks') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 154 | r_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (VK_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(VK_LAYER_DBG_FUNCTION_NODE));') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 155 | r_body.append(' if (!pNewDbgFuncNode)') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 156 | r_body.append(' return VK_ERROR_OUT_OF_HOST_MEMORY;') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 157 | r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;') |
| 158 | r_body.append(' pNewDbgFuncNode->pUserData = pUserData;') |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 159 | r_body.append(' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;') |
| 160 | r_body.append(' g_pDbgFunctionHead = pNewDbgFuncNode;') |
Jon Ashburn | e472239 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 161 | r_body.append(' // force callbacks if DebugAction hasn\'t been set already other than initial value') |
Ian Elliott | c9473d9 | 2015-03-05 12:28:53 -0700 | [diff] [blame] | 162 | r_body.append(' if (g_actionIsDefault) {') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 163 | r_body.append(' g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;') |
Ian Elliott | c9473d9 | 2015-03-05 12:28:53 -0700 | [diff] [blame] | 164 | r_body.append(' }') |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 165 | r_body.append(' VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 166 | r_body.append(' return result;') |
| 167 | r_body.append('}') |
| 168 | return "\n".join(r_body) |
| 169 | |
| 170 | def _gen_layer_dbg_callback_unregister(self): |
| 171 | ur_body = [] |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 172 | ur_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 173 | ur_body.append('{') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 174 | ur_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;') |
| 175 | ur_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 176 | ur_body.append(' while (pTrav) {') |
| 177 | ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {') |
| 178 | ur_body.append(' pPrev->pNext = pTrav->pNext;') |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 179 | ur_body.append(' if (g_pDbgFunctionHead == pTrav)') |
| 180 | ur_body.append(' g_pDbgFunctionHead = pTrav->pNext;') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 181 | ur_body.append(' free(pTrav);') |
| 182 | ur_body.append(' break;') |
| 183 | ur_body.append(' }') |
| 184 | ur_body.append(' pPrev = pTrav;') |
| 185 | ur_body.append(' pTrav = pTrav->pNext;') |
| 186 | ur_body.append(' }') |
Jon Ashburn | e472239 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 187 | ur_body.append(' if (g_pDbgFunctionHead == NULL)') |
| 188 | ur_body.append(' {') |
| 189 | ur_body.append(' if (g_actionIsDefault)') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 190 | ur_body.append(' g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;') |
Jon Ashburn | e472239 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 191 | ur_body.append(' else') |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 192 | ur_body.append(' g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));') |
Jon Ashburn | e472239 | 2015-03-03 15:07:15 -0700 | [diff] [blame] | 193 | ur_body.append(' }') |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 194 | ur_body.append(' VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);') |
Tobin Ehlis | c54139f | 2014-12-17 08:01:59 -0700 | [diff] [blame] | 195 | ur_body.append(' return result;') |
| 196 | ur_body.append('}') |
| 197 | return "\n".join(ur_body) |
| 198 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 199 | def _gen_layer_get_global_extension_info(self, layer="Generic"): |
| 200 | ggei_body = [] |
| 201 | ggei_body.append('struct extProps {') |
| 202 | ggei_body.append(' uint32_t version;') |
| 203 | ggei_body.append(' const char * const name;') |
| 204 | ggei_body.append('};') |
Jon Ashburn | bdcd756 | 2015-04-14 14:12:59 -0600 | [diff] [blame] | 205 | if layer == 'ObjectTracker': |
| 206 | ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 4') |
| 207 | ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {') |
| 208 | ggei_body.append(' // TODO what is the version?') |
| 209 | ggei_body.append(' {0x10, "%s"},' % layer) |
| 210 | ggei_body.append(' {0x10, "Validation"},') |
| 211 | ggei_body.append(' {0x10, "objTrackGetObjectCount"},') |
| 212 | ggei_body.append(' {0x10, "objTrackGetObjects"}') |
| 213 | ggei_body.append('};') |
Tobin Ehlis | a53add0 | 2015-04-15 17:19:18 -0600 | [diff] [blame] | 214 | elif layer == 'Threading': |
| 215 | ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 2') |
| 216 | ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {') |
| 217 | ggei_body.append(' // TODO what is the version?') |
| 218 | ggei_body.append(' {0x10, "%s"},' % layer) |
| 219 | ggei_body.append(' {0x10, "Validation"},') |
| 220 | ggei_body.append('};') |
Jon Ashburn | bdcd756 | 2015-04-14 14:12:59 -0600 | [diff] [blame] | 221 | else: |
| 222 | ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 1') |
| 223 | ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {') |
| 224 | ggei_body.append(' // TODO what is the version?') |
| 225 | ggei_body.append(' {0x10, "%s"}' % layer) |
| 226 | ggei_body.append('};') |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 227 | ggei_body.append('') |
Mark Lobodzinski | 8bae7d4 | 2015-04-13 16:35:52 -0500 | [diff] [blame] | 228 | ggei_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(VkExtensionInfoType infoType, uint32_t extensionIndex, size_t* pDataSize, void* pData)') |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 229 | ggei_body.append('{') |
| 230 | ggei_body.append(' VkExtensionProperties *ext_props;') |
| 231 | ggei_body.append(' uint32_t *count;') |
| 232 | ggei_body.append('') |
| 233 | ggei_body.append(' if (pDataSize == NULL)') |
| 234 | ggei_body.append(' return VK_ERROR_INVALID_POINTER;') |
| 235 | ggei_body.append('') |
| 236 | ggei_body.append(' switch (infoType) {') |
| 237 | ggei_body.append(' case VK_EXTENSION_INFO_TYPE_COUNT:') |
| 238 | ggei_body.append(' *pDataSize = sizeof(uint32_t);') |
| 239 | ggei_body.append(' if (pData == NULL)') |
| 240 | ggei_body.append(' return VK_SUCCESS;') |
| 241 | ggei_body.append(' count = (uint32_t *) pData;') |
| 242 | ggei_body.append(' *count = LAYER_EXT_ARRAY_SIZE;') |
| 243 | ggei_body.append(' break;') |
| 244 | ggei_body.append(' case VK_EXTENSION_INFO_TYPE_PROPERTIES:') |
| 245 | ggei_body.append(' *pDataSize = sizeof(VkExtensionProperties);') |
| 246 | ggei_body.append(' if (pData == NULL)') |
| 247 | ggei_body.append(' return VK_SUCCESS;') |
| 248 | ggei_body.append(' if (extensionIndex >= LAYER_EXT_ARRAY_SIZE)') |
| 249 | ggei_body.append(' return VK_ERROR_INVALID_VALUE;') |
| 250 | ggei_body.append(' ext_props = (VkExtensionProperties *) pData;') |
| 251 | ggei_body.append(' ext_props->version = layerExts[extensionIndex].version;') |
| 252 | ggei_body.append(' strncpy(ext_props->extName, layerExts[extensionIndex].name,') |
| 253 | ggei_body.append(' VK_MAX_EXTENSION_NAME);') |
| 254 | ggei_body.append(" ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\\0';") |
| 255 | ggei_body.append(' break;') |
| 256 | ggei_body.append(' default:') |
| 257 | ggei_body.append(' return VK_ERROR_INVALID_VALUE;') |
| 258 | ggei_body.append(' };') |
| 259 | ggei_body.append(' return VK_SUCCESS;') |
| 260 | ggei_body.append('}') |
| 261 | return "\n".join(ggei_body) |
Jon Ashburn | 2556635 | 2015-04-02 12:06:28 -0600 | [diff] [blame] | 262 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 263 | def _gen_layer_get_extension_support(self, layer="Generic"): |
| 264 | ges_body = [] |
| 265 | ges_body.append('VK_LAYER_EXPORT VkResult VKAPI xglGetExtensionSupport(VkPhysicalDevice gpu, const char* pExtName)') |
| 266 | ges_body.append('{') |
| 267 | ges_body.append(' VkResult result;') |
| 268 | ges_body.append(' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;') |
| 269 | ges_body.append('') |
| 270 | ges_body.append(' /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */') |
| 271 | ges_body.append(' if (!strncmp(pExtName, "%s", strlen("%s")))' % (layer, layer)) |
| 272 | ges_body.append(' {') |
| 273 | ges_body.append(' result = VK_SUCCESS;') |
| 274 | ges_body.append(' } else if (nextTable.GetExtensionSupport != NULL)') |
| 275 | ges_body.append(' {') |
| 276 | ges_body.append(' result = nextTable.GetExtensionSupport((VkPhysicalDevice)gpuw->nextObject, pExtName);') |
| 277 | ges_body.append(' } else') |
| 278 | ges_body.append(' {') |
| 279 | ges_body.append(' result = VK_ERROR_INVALID_EXTENSION;') |
| 280 | ges_body.append(' }') |
| 281 | ges_body.append(' return result;') |
| 282 | ges_body.append('}') |
| 283 | return "\n".join(ges_body) |
| 284 | |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 285 | def _generate_dispatch_entrypoints(self, qual=""): |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 286 | if qual: |
| 287 | qual += " " |
| 288 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 289 | funcs = [] |
| 290 | intercepted = [] |
| 291 | for proto in self.protos: |
Mike Stroyan | 88f0ecf | 2015-04-08 10:27:43 -0600 | [diff] [blame] | 292 | if proto.name == "GetProcAddr": |
| 293 | intercepted.append(proto) |
| 294 | else: |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 295 | intercept = self.generate_intercept(proto, qual) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 296 | if intercept is None: |
| 297 | # fill in default intercept for certain entrypoints |
| 298 | if 'DbgRegisterMsgCallback' == proto.name: |
| 299 | intercept = self._gen_layer_dbg_callback_register() |
Jon Ashburn | 2556635 | 2015-04-02 12:06:28 -0600 | [diff] [blame] | 300 | elif 'DbgUnregisterMsgCallback' == proto.name: |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 301 | intercept = self._gen_layer_dbg_callback_unregister() |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 302 | elif 'GetGlobalExtensionInfo' == proto.name: |
| 303 | funcs.append(self._gen_layer_get_global_extension_info(self.layer_name)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 304 | if intercept is not None: |
| 305 | funcs.append(intercept) |
| 306 | intercepted.append(proto) |
| 307 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 308 | prefix="vk" |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 309 | lookups = [] |
| 310 | for proto in intercepted: |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 311 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
| 312 | lookups.append(" return (void*) %s%s;" % |
| 313 | (prefix, proto.name)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 314 | |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 315 | prefix="vk" |
| 316 | lookups = [] |
| 317 | for proto in intercepted: |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 318 | lookups.append("if (!strcmp(name, \"%s\"))" % proto.name) |
| 319 | lookups.append(" return (void*) %s%s;" % |
| 320 | (prefix, proto.name)) |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 321 | |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 322 | # add customized layer_intercept_proc |
| 323 | body = [] |
| 324 | body.append("static inline void* layer_intercept_proc(const char *name)") |
| 325 | body.append("{") |
| 326 | body.append(generate_get_proc_addr_check("name")) |
| 327 | body.append("") |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 328 | body.append(" name += 2;") |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 329 | body.append(" %s" % "\n ".join(lookups)) |
| 330 | body.append("") |
| 331 | body.append(" return NULL;") |
| 332 | body.append("}") |
| 333 | funcs.append("\n".join(body)) |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 334 | return "\n\n".join(funcs) |
| 335 | |
| 336 | |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 337 | def _generate_extensions(self): |
| 338 | exts = [] |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 339 | exts.append('uint64_t objTrackGetObjectCount(VK_OBJECT_TYPE type)') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 340 | exts.append('{') |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 341 | exts.append(' return (type == VkObjectTypeAny) ? numTotalObjs : numObjs[type];') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 342 | exts.append('}') |
| 343 | exts.append('') |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 344 | exts.append('VkResult objTrackGetObjects(VK_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 345 | exts.append('{') |
| 346 | exts.append(" // This bool flags if we're pulling all objs or just a single class of objs") |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 347 | exts.append(' bool32_t bAllObjs = (type == VkObjectTypeAny);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 348 | exts.append(' // Check the count first thing') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 349 | exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 350 | exts.append(' if (objCount > maxObjCount) {') |
| 351 | exts.append(' char str[1024];') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 352 | exts.append(' sprintf(str, "OBJ ERROR : Received objTrackGetObjects() request for %lu objs, but there are only %lu objs of type %s", objCount, maxObjCount, string_VK_OBJECT_TYPE(type));') |
| 353 | exts.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);') |
| 354 | exts.append(' return VK_ERROR_INVALID_VALUE;') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 355 | exts.append(' }') |
| 356 | exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];') |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 357 | exts.append(' for (uint64_t i = 0; i < objCount; i++) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 358 | exts.append(' if (!pTrav) {') |
| 359 | exts.append(' char str[1024];') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 360 | 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_VK_OBJECT_TYPE(type), maxObjCount, i, objCount);') |
| 361 | exts.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
| 362 | exts.append(' return VK_ERROR_UNKNOWN;') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 363 | exts.append(' }') |
| 364 | exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));') |
| 365 | exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;') |
| 366 | exts.append(' }') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 367 | exts.append(' return VK_SUCCESS;') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 368 | exts.append('}') |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 369 | return "\n".join(exts) |
| 370 | |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 371 | def _generate_layer_gpa_function(self, extensions=[]): |
| 372 | func_body = [] |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 373 | func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)\n" |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 374 | "{\n" |
| 375 | " VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;\n" |
| 376 | " void* addr;\n" |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 377 | " if (gpu == VK_NULL_HANDLE)\n" |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 378 | " return NULL;\n" |
| 379 | " pCurObj = gpuw;\n" |
| 380 | " loader_platform_thread_once(&tabOnce, init%s);\n\n" |
| 381 | " addr = layer_intercept_proc(funcName);\n" |
| 382 | " if (addr)\n" |
| 383 | " return addr;" % self.layer_name) |
| 384 | |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 385 | if 0 != len(extensions): |
| 386 | for ext_name in extensions: |
Chia-I Wu | 7461fcf | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 387 | func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n' |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 388 | ' return %s;' % (ext_name, ext_name, ext_name)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 389 | func_body.append(" else {\n" |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 390 | " if (gpuw->pGPA == NULL)\n" |
| 391 | " return NULL;\n" |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 392 | " return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);\n" |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 393 | " }\n" |
| 394 | "}\n") |
| 395 | return "\n".join(func_body) |
| 396 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 397 | def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None): |
| 398 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 399 | func_body.append('static void init%s(void)\n' |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 400 | '{\n' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 401 | if init_opts: |
| 402 | func_body.append(' const char *strOpt;') |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 403 | func_body.append(' // initialize %s options' % self.layer_name) |
| 404 | func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportingLevel);' % self.layer_name) |
| 405 | func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 406 | func_body.append('') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 407 | func_body.append(' if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)') |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 408 | func_body.append(' {') |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 409 | func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name) |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 410 | func_body.append(' if (strOpt)') |
| 411 | func_body.append(' {') |
| 412 | func_body.append(' g_logFile = fopen(strOpt, "w");') |
| 413 | func_body.append(' }') |
| 414 | func_body.append(' if (g_logFile == NULL)') |
| 415 | func_body.append(' g_logFile = stdout;') |
| 416 | func_body.append(' }') |
| 417 | func_body.append('') |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 418 | func_body.append(' PFN_vkGetProcAddr fpNextGPA;\n' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 419 | ' fpNextGPA = pCurObj->pGPA;\n' |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 420 | ' assert(fpNextGPA);\n') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 421 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 422 | func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);") |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 423 | if lockname is not None: |
| 424 | func_body.append(" if (!%sLockInitialized)" % lockname) |
| 425 | func_body.append(" {") |
| 426 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 427 | func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname) |
| 428 | func_body.append(" %sLockInitialized = 1;" % lockname) |
| 429 | func_body.append(" }") |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 430 | func_body.append("}\n") |
| 431 | return "\n".join(func_body) |
| 432 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 433 | def _generate_layer_initialization_with_lock(self, prefix='vk'): |
| 434 | func_body = ["#include \"vk_dispatch_table_helper.h\""] |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 435 | func_body.append('static void init%s(void)\n' |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 436 | '{\n' |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 437 | ' PFN_vkGetProcAddr fpNextGPA;\n' |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 438 | ' fpNextGPA = pCurObj->pGPA;\n' |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 439 | ' assert(fpNextGPA);\n' % self.layer_name) |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 440 | |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 441 | func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);\n") |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 442 | func_body.append(" if (!printLockInitialized)") |
| 443 | func_body.append(" {") |
| 444 | func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???") |
| 445 | func_body.append(" loader_platform_thread_create_mutex(&printLock);") |
| 446 | func_body.append(" printLockInitialized = 1;") |
| 447 | func_body.append(" }") |
| 448 | func_body.append("}\n") |
| 449 | return "\n".join(func_body) |
| 450 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 451 | class LayerFuncsSubcommand(Subcommand): |
| 452 | def generate_header(self): |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 453 | return '#include <vkLayer.h>\n#include "loader.h"' |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 454 | |
| 455 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 456 | return self._generate_dispatch_entrypoints("static") |
Tobin Ehlis | 92dbf80 | 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 | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 463 | return self._generate_layer_initialization() |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 464 | |
| 465 | class GenericLayerSubcommand(Subcommand): |
| 466 | def generate_header(self): |
Jon Ashburn | 301c5f0 | 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 | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 468 | |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 469 | def generate_intercept(self, proto, qual): |
Tobin Ehlis | 46c9665 | 2015-04-16 11:17:12 -0600 | [diff] [blame] | 470 | if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback' , 'GetGlobalExtensionInfo']: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 471 | # use default version |
| 472 | return None |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 473 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 474 | ret_val = '' |
| 475 | stmt = '' |
| 476 | funcs = [] |
| 477 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 478 | ret_val = "VkResult result = " |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 479 | stmt = " return result;\n" |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 480 | if proto.name == "EnumerateLayers": |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 481 | funcs.append('%s%s\n' |
| 482 | '{\n' |
| 483 | ' char str[1024];\n' |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 484 | ' if (gpu != VK_NULL_HANDLE) {\n' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 485 | ' sprintf(str, "At start of layered %s\\n");\n' |
Courtney Goeltzenleuchter | 9cc421e | 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 | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 487 | ' pCurObj = (VkBaseLayerObject *) gpu;\n' |
Mike Stroyan | 7c2efaa | 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 | 9cc421e | 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 | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 492 | ' fflush(stdout);\n' |
| 493 | ' %s' |
| 494 | ' } else {\n' |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame^] | 495 | ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 496 | ' return VK_ERROR_INVALID_POINTER;\n' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 497 | ' // This layer compatible with all GPUs\n' |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame^] | 498 | ' *pLayerCount = 1;\n' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 499 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 500 | ' return VK_SUCCESS;\n' |
Mike Stroyan | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 501 | ' }\n' |
Jon Ashburn | 630e44f | 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 | 7c2efaa | 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 | 7c2efaa | 2015-04-03 13:58:35 -0600 | [diff] [blame] | 509 | return "\n\n".join(funcs) |
| 510 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 511 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 512 | self.layer_name = "Generic" |
| 513 | body = [self._generate_layer_initialization(True), |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 514 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 515 | self._generate_layer_gpa_function()] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 516 | |
| 517 | return "\n\n".join(body) |
| 518 | |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 519 | class APIDumpSubcommand(Subcommand): |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 520 | def generate_header(self): |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 521 | header_txt = [] |
Tobin Ehlis | 4a636a1 | 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 | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 551 | header_txt.append('#include "loader_platform.h"') |
Tobin Ehlis | 4a636a1 | 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 | 20f0687 | 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 | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 557 | header_txt.append('') |
Jon Ashburn | 301c5f0 | 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 | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 560 | header_txt.append('') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 561 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') |
| 562 | header_txt.append('static int printLockInitialized = 0;') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 563 | header_txt.append('static loader_platform_thread_mutex printLock;') |
| 564 | header_txt.append('') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 565 | header_txt.append('#define MAX_TID 513') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 566 | header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 567 | header_txt.append('static uint32_t maxTID = 0;') |
| 568 | header_txt.append('// Map actual TID to an index value and return that index') |
| 569 | header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs') |
| 570 | header_txt.append('static uint32_t getTIDIndex() {') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 571 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 572 | header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {') |
| 573 | header_txt.append(' if (tid == tidMapping[i])') |
| 574 | header_txt.append(' return i;') |
| 575 | header_txt.append(' }') |
| 576 | header_txt.append(" // Don't yet have mapping, set it and return newly set index") |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 577 | header_txt.append(' uint32_t retVal = (uint32_t) maxTID;') |
Tobin Ehlis | 0c68c9c | 2014-11-24 15:46:55 -0700 | [diff] [blame] | 578 | header_txt.append(' tidMapping[maxTID++] = tid;') |
| 579 | header_txt.append(' assert(maxTID < MAX_TID);') |
| 580 | header_txt.append(' return retVal;') |
| 581 | header_txt.append('}') |
| 582 | return "\n".join(header_txt) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 583 | |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 584 | def generate_init(self): |
| 585 | func_body = [] |
| 586 | func_body.append('#include "vk_dispatch_table_helper.h"') |
| 587 | func_body.append('#include "layers_config.h"') |
| 588 | func_body.append('') |
| 589 | func_body.append('static void init%s(void)' % self.layer_name) |
| 590 | func_body.append('{') |
| 591 | func_body.append(' using namespace StreamControl;') |
| 592 | func_body.append('') |
| 593 | func_body.append(' char const*const writeToFileStr = getLayerOption("APIDumpFile");') |
| 594 | func_body.append(' bool writeToFile = false;') |
| 595 | func_body.append(' if(writeToFileStr != NULL)') |
| 596 | func_body.append(' {') |
| 597 | func_body.append(' if(strcmp(writeToFileStr, "TRUE") == 0)') |
| 598 | func_body.append(' {') |
| 599 | func_body.append(' writeToFile = true;') |
| 600 | func_body.append(' }') |
| 601 | func_body.append(' else if(strcmp(writeToFileStr, "FALSE") == 0)') |
| 602 | func_body.append(' {') |
| 603 | func_body.append(' writeToFile = false;') |
| 604 | func_body.append(' }') |
| 605 | func_body.append(' }') |
| 606 | func_body.append('') |
| 607 | func_body.append(' char const*const noAddrStr = getLayerOption("APIDumpNoAddr");') |
| 608 | func_body.append(' if(noAddrStr != NULL)') |
| 609 | func_body.append(' {') |
| 610 | func_body.append(' if(strcmp(noAddrStr, "FALSE") == 0)') |
| 611 | func_body.append(' {') |
| 612 | func_body.append(' StreamControl::writeAddress = true;') |
| 613 | func_body.append(' }') |
| 614 | func_body.append(' else if(strcmp(noAddrStr, "TRUE") == 0)') |
| 615 | func_body.append(' {') |
| 616 | func_body.append(' StreamControl::writeAddress = false;') |
| 617 | func_body.append(' }') |
| 618 | func_body.append(' }') |
| 619 | func_body.append('') |
| 620 | func_body.append(' char const*const flushAfterWriteStr = getLayerOption("APIDumpFlush");') |
| 621 | func_body.append(' bool flushAfterWrite = false;') |
| 622 | func_body.append(' if(flushAfterWriteStr != NULL)') |
| 623 | func_body.append(' {') |
| 624 | func_body.append(' if(strcmp(flushAfterWriteStr, "TRUE") == 0)') |
| 625 | func_body.append(' {') |
| 626 | func_body.append(' flushAfterWrite = true;') |
| 627 | func_body.append(' }') |
| 628 | func_body.append(' else if(strcmp(flushAfterWriteStr, "FALSE") == 0)') |
| 629 | func_body.append(' {') |
| 630 | func_body.append(' flushAfterWrite = false;') |
| 631 | func_body.append(' }') |
| 632 | func_body.append(' }') |
| 633 | func_body.append('') |
| 634 | func_body.append(' ConfigureOutputStream(writeToFile, flushAfterWrite);') |
| 635 | func_body.append('') |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 636 | func_body.append(' PFN_vkGetProcAddr fpNextGPA;') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 637 | func_body.append(' fpNextGPA = pCurObj->pGPA;') |
| 638 | func_body.append(' assert(fpNextGPA);') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 639 | func_body.append(' layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 640 | func_body.append('') |
| 641 | func_body.append(' if (!printLockInitialized)') |
| 642 | func_body.append(' {') |
| 643 | func_body.append(' // TODO/TBD: Need to delete this mutex sometime. How???') |
| 644 | func_body.append(' loader_platform_thread_create_mutex(&printLock);') |
| 645 | func_body.append(' printLockInitialized = 1;') |
| 646 | func_body.append(' }') |
| 647 | func_body.append('}') |
| 648 | func_body.append('') |
| 649 | return "\n".join(func_body) |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 650 | |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 651 | def generate_intercept(self, proto, qual): |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 652 | if proto.name in [ 'GetGlobalExtensionInfo']: |
| 653 | return None |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 654 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 655 | ret_val = '' |
| 656 | stmt = '' |
| 657 | funcs = [] |
| 658 | sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print |
| 659 | create_params = 0 # Num of params at end of function that are created and returned as output values |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 660 | if 'AllocDescriptorSets' in proto.name: |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 661 | create_params = -2 |
| 662 | elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name: |
| 663 | create_params = -1 |
| 664 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 665 | ret_val = "VkResult result = " |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 666 | stmt = " return result;\n" |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 667 | f_open = 'loader_platform_thread_lock_mutex(&printLock);\n ' |
| 668 | log_func = ' if (StreamControl::writeAddress == true) {' |
| 669 | log_func += '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 670 | log_func_no_addr = '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name |
| 671 | f_close = '\n loader_platform_thread_unlock_mutex(&printLock);' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 672 | pindex = 0 |
| 673 | prev_count_name = '' |
| 674 | for p in proto.params: |
| 675 | cp = False |
| 676 | if 0 != create_params: |
| 677 | # If this is any of the N last params of the func, treat as output |
| 678 | for y in range(-1, create_params-1, -1): |
| 679 | if p.name == proto.params[y].name: |
| 680 | cp = True |
| 681 | (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 682 | log_func += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 683 | if "%p" == pft: |
| 684 | log_func_no_addr += '%s = address, ' % (p.name) |
| 685 | else: |
| 686 | log_func_no_addr += '%s = " << %s << ", ' % (p.name, pfi) |
Tobin Ehlis | c99cb0d | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 687 | if prev_count_name != '' and (prev_count_name.replace('Count', '')[1:] in p.name): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 688 | sp_param_dict[pindex] = prev_count_name |
Tobin Ehlis | c99cb0d | 2015-04-16 15:56:11 -0600 | [diff] [blame] | 689 | prev_count_name = '' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 690 | elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount': |
| 691 | sp_param_dict[pindex] = '*pCount' |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 692 | elif vk_helper.is_type(p.ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 693 | sp_param_dict[pindex] = 'index' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 694 | if p.name.endswith('Count'): |
| 695 | if '*' in p.ty: |
| 696 | prev_count_name = "*%s" % p.name |
| 697 | else: |
| 698 | prev_count_name = p.name |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 699 | pindex += 1 |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 700 | log_func = log_func.strip(', ') |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 701 | log_func_no_addr = log_func_no_addr.strip(', ') |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 702 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 703 | log_func += ') = " << string_VkResult((VkResult)result) << endl' |
| 704 | log_func_no_addr += ') = " << string_VkResult((VkResult)result) << endl' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 705 | else: |
| 706 | log_func += ')\\n"' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 707 | log_func_no_addr += ')\\n"' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 708 | log_func += ';' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 709 | log_func_no_addr += ';' |
| 710 | log_func += '\n }\n else {%s;\n }' % log_func_no_addr; |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 711 | #print("Proto %s has param_dict: %s" % (proto.name, sp_param_dict)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 712 | if len(sp_param_dict) > 0: |
| 713 | i_decl = False |
| 714 | log_func += '\n string tmp_str;' |
| 715 | for sp_index in sp_param_dict: |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 716 | #print("sp_index: %s" % str(sp_index)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 717 | if 'index' == sp_param_dict[sp_index]: |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 718 | cis_print_func = 'vk_print_%s' % (proto.params[sp_index].ty.replace('const ', '').strip('*').lower()) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 719 | local_name = proto.params[sp_index].name |
| 720 | if '*' not in proto.params[sp_index].ty: |
| 721 | local_name = '&%s' % proto.params[sp_index].name |
| 722 | log_func += '\n if (%s) {' % (local_name) |
| 723 | log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, local_name) |
| 724 | log_func += '\n (*outputStream) << " %s (" << %s << ")" << endl << tmp_str << endl;' % (local_name, local_name) |
| 725 | log_func += '\n }' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 726 | else: # We have a count value stored to iterate over an array |
| 727 | print_cast = '' |
| 728 | print_func = '' |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 729 | if vk_helper.is_type(proto.params[sp_index].ty.strip('*').replace('const ', ''), 'struct'): |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 730 | print_cast = '&' |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 731 | print_func = 'vk_print_%s' % proto.params[sp_index].ty.replace('const ', '').strip('*').lower() |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 732 | else: |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 733 | print_cast = '' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 734 | print_func = 'string_convert_helper' |
| 735 | #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name |
| 736 | cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 737 | if not i_decl: |
| 738 | log_func += '\n uint32_t i;' |
| 739 | i_decl = True |
| 740 | log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index]) |
| 741 | log_func += '\n %s' % (cis_print_func) |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 742 | log_func += '\n (*outputStream) << " %s[" << i << "] (" << %s%s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, '&', proto.params[sp_index].name) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 743 | log_func += '\n }' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 744 | if proto.name == "EnumerateLayers": |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 745 | c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalDevice)gpuw->nextObject", 1) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 746 | funcs.append('%s%s\n' |
| 747 | '{\n' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 748 | ' using namespace StreamControl;\n' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 749 | ' if (gpu != NULL) {\n' |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 750 | ' pCurObj = (VkBaseLayerObject *) gpu;\n' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 751 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
| 752 | ' %snextTable.%s;\n' |
| 753 | ' %s %s %s\n' |
| 754 | ' %s' |
| 755 | ' } else {\n' |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame^] | 756 | ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 757 | ' return VK_ERROR_INVALID_POINTER;\n' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 758 | ' // This layer compatible with all GPUs\n' |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame^] | 759 | ' *pLayerCount = 1;\n' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 760 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 761 | ' return VK_SUCCESS;\n' |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 762 | ' }\n' |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 763 | '}' % (qual, decl, self.layer_name, ret_val, proto.c_call(),f_open, log_func, f_close, stmt, self.layer_name)) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 764 | elif 'GetExtensionSupport' == proto.name: |
| 765 | funcs.append('%s%s\n' |
| 766 | '{\n' |
| 767 | ' VkResult result;\n' |
| 768 | ' /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */\n' |
| 769 | ' if (!strncmp(pExtName, "%s", strlen("%s")))\n' |
| 770 | ' {\n' |
| 771 | ' result = VK_SUCCESS;\n' |
| 772 | ' } else if (nextTable.GetExtensionSupport != NULL)\n' |
| 773 | ' {\n' |
| 774 | ' result = nextTable.%s;\n' |
| 775 | ' %s %s %s\n' |
| 776 | ' } else\n' |
| 777 | ' {\n' |
| 778 | ' result = VK_ERROR_INVALID_EXTENSION;\n' |
| 779 | ' }\n' |
| 780 | '%s' |
| 781 | '}' % (qual, decl, self.layer_name, self.layer_name, proto.c_call(), f_open, log_func, f_close, stmt)) |
| 782 | # elif 'vkphysicalgpu' == proto.params[0].ty.lower(): |
| 783 | # c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalDevice)gpuw->nextObject", 1) |
| 784 | # funcs.append('%s%s\n' |
| 785 | # '{\n' |
| 786 | # ' using namespace StreamControl;\n' |
| 787 | # ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n' |
| 788 | # ' pCurObj = gpuw;\n' |
| 789 | # ' loader_platform_thread_once(&tabOnce, init%s);\n' |
| 790 | # ' %snextTable.%s;\n' |
| 791 | # ' %s%s%s\n' |
| 792 | # '%s' |
| 793 | # '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, c_call, f_open, log_func, f_close, stmt)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 794 | else: |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 795 | funcs.append('%s%s\n' |
| 796 | '{\n' |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 797 | ' using namespace StreamControl;\n' |
Jon Ashburn | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 798 | ' %snextTable.%s;\n' |
| 799 | ' %s%s%s\n' |
| 800 | '%s' |
| 801 | '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt)) |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 802 | return "\n\n".join(funcs) |
| 803 | |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 804 | def generate_body(self): |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 805 | self.layer_name = "APIDump" |
| 806 | body = [self.generate_init(), |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 807 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 808 | self._generate_layer_gpa_function()] |
Tobin Ehlis | 434db7c | 2015-01-10 12:42:41 -0700 | [diff] [blame] | 809 | return "\n\n".join(body) |
| 810 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 811 | class ObjectTrackerSubcommand(Subcommand): |
| 812 | def generate_header(self): |
| 813 | header_txt = [] |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 814 | 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 | 301c5f0 | 2015-04-06 10:58:22 -0600 | [diff] [blame] | 815 | header_txt.append('#include "object_track.h"\n\nstatic VkLayerDispatchTable nextTable;\nstatic VkBaseLayerObject *pCurObj;') |
Ian Elliott | 20f0687 | 2015-02-12 17:08:34 -0700 | [diff] [blame] | 816 | header_txt.append('// The following is #included again to catch certain OS-specific functions being used:') |
| 817 | header_txt.append('#include "loader_platform.h"') |
Jon Ashburn | 7a2da4f | 2015-02-17 11:03:12 -0700 | [diff] [blame] | 818 | header_txt.append('#include "layers_config.h"') |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 819 | header_txt.append('#include "layers_msg.h"') |
Ian Elliott | 81ac44c | 2015-01-13 17:52:38 -0700 | [diff] [blame] | 820 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);') |
| 821 | header_txt.append('static long long unsigned int object_track_index = 0;') |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 822 | header_txt.append('static int objLockInitialized = 0;') |
| 823 | header_txt.append('static loader_platform_thread_mutex objLock;') |
Jon Ashburn | 21001f6 | 2015-02-16 08:26:50 -0700 | [diff] [blame] | 824 | header_txt.append('') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 825 | header_txt.append('// We maintain a "Global" list which links every object and a') |
| 826 | header_txt.append('// per-Object list which just links objects of a given type') |
| 827 | header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists') |
| 828 | header_txt.append('typedef struct _objNode {') |
| 829 | header_txt.append(' OBJTRACK_NODE obj;') |
| 830 | header_txt.append(' struct _objNode *pNextObj;') |
| 831 | header_txt.append(' struct _objNode *pNextGlobal;') |
| 832 | header_txt.append('} objNode;') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 833 | header_txt.append('') |
| 834 | header_txt.append('static objNode *pObjectHead[VkNumObjectType] = {0};') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 835 | header_txt.append('static objNode *pGlobalHead = NULL;') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 836 | header_txt.append('static uint64_t numObjs[VkNumObjectType] = {0};') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 837 | header_txt.append('static uint64_t numTotalObjs = 0;') |
Courtney Goeltzenleuchter | 304a1f8 | 2015-04-07 16:23:00 -0600 | [diff] [blame] | 838 | header_txt.append('static uint32_t maxMemReferences = 0;') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 839 | header_txt.append('') |
| 840 | header_txt.append('// For each Queue\'s doubly linked-list of mem refs') |
| 841 | header_txt.append('typedef struct _OT_MEM_INFO {') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 842 | header_txt.append(' VkDeviceMemory mem;') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 843 | header_txt.append(' struct _OT_MEM_INFO *pNextMI;') |
| 844 | header_txt.append(' struct _OT_MEM_INFO *pPrevMI;') |
| 845 | header_txt.append('') |
| 846 | header_txt.append('} OT_MEM_INFO;') |
| 847 | header_txt.append('') |
| 848 | header_txt.append('// Track Queue information') |
| 849 | header_txt.append('typedef struct _OT_QUEUE_INFO {') |
| 850 | header_txt.append(' OT_MEM_INFO *pMemRefList;') |
| 851 | header_txt.append(' struct _OT_QUEUE_INFO *pNextQI;') |
| 852 | header_txt.append(' VkQueue queue;') |
| 853 | header_txt.append(' uint32_t refCount;') |
| 854 | header_txt.append('} OT_QUEUE_INFO;') |
| 855 | header_txt.append('') |
| 856 | header_txt.append('// Global list of QueueInfo structures, one per queue') |
| 857 | header_txt.append('static OT_QUEUE_INFO *g_pQueueInfo;') |
| 858 | header_txt.append('') |
| 859 | header_txt.append('// Add new queue to head of global queue list') |
| 860 | header_txt.append('static void addQueueInfo(VkQueue queue)') |
| 861 | header_txt.append('{') |
| 862 | header_txt.append(' OT_QUEUE_INFO *pQueueInfo = malloc(sizeof(OT_QUEUE_INFO));') |
| 863 | header_txt.append(' memset(pQueueInfo, 0, sizeof(OT_QUEUE_INFO));') |
| 864 | header_txt.append(' pQueueInfo->queue = queue;') |
| 865 | header_txt.append('') |
| 866 | header_txt.append(' if (pQueueInfo != NULL) {') |
| 867 | header_txt.append(' pQueueInfo->pNextQI = g_pQueueInfo;') |
| 868 | header_txt.append(' g_pQueueInfo = pQueueInfo;') |
| 869 | header_txt.append(' }') |
| 870 | header_txt.append(' else {') |
| 871 | header_txt.append(' char str[1024];') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 872 | header_txt.append(' sprintf(str, "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 873 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
| 874 | header_txt.append(' }') |
| 875 | header_txt.append('}') |
| 876 | header_txt.append('') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 877 | header_txt.append('// Destroy memRef lists and free all memory') |
| 878 | header_txt.append('static void destroyQueueMemRefLists()') |
| 879 | header_txt.append('{') |
| 880 | header_txt.append(' OT_QUEUE_INFO *pQueueInfo = g_pQueueInfo;') |
| 881 | header_txt.append(' OT_QUEUE_INFO *pDelQueueInfo = NULL;') |
| 882 | header_txt.append(' while (pQueueInfo != NULL) {') |
| 883 | header_txt.append(' OT_MEM_INFO *pMemInfo = pQueueInfo->pMemRefList;') |
| 884 | header_txt.append(' while (pMemInfo != NULL) {') |
| 885 | header_txt.append(' OT_MEM_INFO *pDelMemInfo = pMemInfo;') |
| 886 | header_txt.append(' pMemInfo = pMemInfo->pNextMI;') |
| 887 | header_txt.append(' free(pDelMemInfo);') |
| 888 | header_txt.append(' }') |
| 889 | header_txt.append(' pDelQueueInfo = pQueueInfo;') |
| 890 | header_txt.append(' pQueueInfo = pQueueInfo->pNextQI;') |
| 891 | header_txt.append(' free(pDelQueueInfo);') |
| 892 | header_txt.append(' }') |
| 893 | header_txt.append('}') |
| 894 | header_txt.append('') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 895 | header_txt.append('// Debug function to print global list and each individual object list') |
| 896 | header_txt.append('static void ll_print_lists()') |
| 897 | header_txt.append('{') |
| 898 | header_txt.append(' objNode* pTrav = pGlobalHead;') |
| 899 | header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);') |
| 900 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 901 | header_txt.append(' printf(" ObjNode (%p) w/ %s obj 0x%" PRId64 " has pNextGlobal %p\\n", (void*)pTrav, string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.vkObj, (void*)pTrav->pNextGlobal);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 902 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 903 | header_txt.append(' }') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 904 | header_txt.append(' for (uint32_t i = 0; i < VkNumObjectType; i++) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 905 | header_txt.append(' pTrav = pObjectHead[i];') |
| 906 | header_txt.append(' if (pTrav) {') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 907 | header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_VK_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 908 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 909 | header_txt.append(' printf(" ObjNode (%p) w/ %s obj 0x%" PRId64 " has pNextObj %p\\n", (void*)pTrav, string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.vkObj, (void*)pTrav->pNextObj);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 910 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 911 | header_txt.append(' }') |
| 912 | header_txt.append(' }') |
| 913 | header_txt.append(' }') |
| 914 | header_txt.append('}') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 915 | header_txt.append('static void ll_insert_obj(VkObject vkObj, VK_OBJECT_TYPE objType) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 916 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 917 | header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object 0x%" PRId64, object_track_index++, string_VK_OBJECT_TYPE(objType), vkObj);') |
| 918 | header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 919 | header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 920 | header_txt.append(' pNewObjNode->obj.vkObj = vkObj;') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 921 | header_txt.append(' pNewObjNode->obj.objType = objType;') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 922 | header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 923 | header_txt.append(' pNewObjNode->obj.numUses = 0;') |
| 924 | header_txt.append(' // insert at front of global list') |
| 925 | header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;') |
| 926 | header_txt.append(' pGlobalHead = pNewObjNode;') |
| 927 | header_txt.append(' // insert at front of object list') |
| 928 | header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];') |
| 929 | header_txt.append(' pObjectHead[objType] = pNewObjNode;') |
| 930 | header_txt.append(' // increment obj counts') |
| 931 | header_txt.append(' numObjs[objType]++;') |
| 932 | header_txt.append(' numTotalObjs++;') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 933 | header_txt.append(' //sprintf(str, "OBJ_STAT : %lu total objs & %lu %s objs.", numTotalObjs, numObjs[objType], string_VK_OBJECT_TYPE(objType));') |
Chia-I Wu | df142a3 | 2014-12-16 11:02:06 +0800 | [diff] [blame] | 934 | header_txt.append(' if (0) ll_print_lists();') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 935 | header_txt.append('}') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 936 | header_txt.append('static void ll_increment_use_count(VkObject vkObj, VK_OBJECT_TYPE objType) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 937 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 938 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 939 | header_txt.append(' if (pTrav->obj.vkObj == vkObj) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 940 | header_txt.append(' pTrav->obj.numUses++;') |
| 941 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 942 | header_txt.append(' sprintf(str, "OBJ[%llu] : USING %s object 0x%" PRId64 " (%lu total uses)", object_track_index++, string_VK_OBJECT_TYPE(objType), vkObj, pTrav->obj.numUses);') |
| 943 | header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 944 | header_txt.append(' return;') |
| 945 | header_txt.append(' }') |
| 946 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 947 | header_txt.append(' }') |
| 948 | header_txt.append(' // If we do not find obj, insert it and then increment count') |
| 949 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 950 | header_txt.append(' sprintf(str, "Unable to increment count for obj 0x%" PRId64 ", will add to list as %s type and increment count", vkObj, string_VK_OBJECT_TYPE(objType));') |
| 951 | header_txt.append(' layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 952 | header_txt.append('') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 953 | header_txt.append(' ll_insert_obj(vkObj, objType);') |
| 954 | header_txt.append(' ll_increment_use_count(vkObj, objType);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 955 | header_txt.append('}') |
| 956 | header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch') |
| 957 | header_txt.append('// Type from global list w/ ll_destroy_obj()') |
| 958 | header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 959 | header_txt.append('static void ll_remove_obj_type(VkObject vkObj, VK_OBJECT_TYPE objType) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 960 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 961 | header_txt.append(' objNode *pPrev = pObjectHead[objType];') |
| 962 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 963 | header_txt.append(' if (pTrav->obj.vkObj == vkObj) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 964 | header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;') |
| 965 | header_txt.append(' // update HEAD of Obj list as needed') |
| 966 | header_txt.append(' if (pObjectHead[objType] == pTrav)') |
| 967 | header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;') |
| 968 | header_txt.append(' assert(numObjs[objType] > 0);') |
| 969 | header_txt.append(' numObjs[objType]--;') |
| 970 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 971 | header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object 0x%" PRId64, object_track_index++, string_VK_OBJECT_TYPE(objType), vkObj);') |
| 972 | header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 973 | header_txt.append(' return;') |
| 974 | header_txt.append(' }') |
| 975 | header_txt.append(' pPrev = pTrav;') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 976 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 977 | header_txt.append(' }') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 978 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 979 | header_txt.append(' sprintf(str, "OBJ INTERNAL ERROR : Obj 0x%" PRId64 " was in global list but not in %s list", vkObj, string_VK_OBJECT_TYPE(objType));') |
| 980 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 981 | header_txt.append('}') |
| 982 | header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally') |
| 983 | header_txt.append('// remove obj from global list') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 984 | header_txt.append('static void ll_destroy_obj(VkObject vkObj) {') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 985 | header_txt.append(' objNode *pTrav = pGlobalHead;') |
| 986 | header_txt.append(' objNode *pPrev = pGlobalHead;') |
| 987 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 988 | header_txt.append(' if (pTrav->obj.vkObj == vkObj) {') |
| 989 | header_txt.append(' ll_remove_obj_type(vkObj, pTrav->obj.objType);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 990 | header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;') |
| 991 | header_txt.append(' // update HEAD of global list if needed') |
| 992 | header_txt.append(' if (pGlobalHead == pTrav)') |
| 993 | header_txt.append(' pGlobalHead = pTrav->pNextGlobal;') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 994 | header_txt.append(' assert(numTotalObjs > 0);') |
| 995 | header_txt.append(' numTotalObjs--;') |
| 996 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 997 | header_txt.append(' sprintf(str, "OBJ_STAT Removed %s obj 0x%" PRId64 " that was used %lu times (%lu total objs remain & %lu %s objs).", string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.vkObj, pTrav->obj.numUses, numTotalObjs, numObjs[pTrav->obj.objType], string_VK_OBJECT_TYPE(pTrav->obj.objType));') |
| 998 | header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);') |
Tobin Ehlis | 84a8a9b | 2015-02-23 14:09:16 -0700 | [diff] [blame] | 999 | header_txt.append(' free(pTrav);') |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1000 | header_txt.append(' return;') |
| 1001 | header_txt.append(' }') |
| 1002 | header_txt.append(' pPrev = pTrav;') |
| 1003 | header_txt.append(' pTrav = pTrav->pNextGlobal;') |
| 1004 | header_txt.append(' }') |
| 1005 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1006 | header_txt.append(' sprintf(str, "Unable to remove obj 0x%" PRId64 ". Was it created? Has it already been destroyed?", vkObj);') |
| 1007 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_DESTROY_OBJECT_FAILED, "OBJTRACK", str);') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1008 | header_txt.append('}') |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1009 | header_txt.append('// Set selected flag state for an object node') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1010 | header_txt.append('static void set_status(VkObject vkObj, VK_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {') |
| 1011 | header_txt.append(' if (vkObj != VK_NULL_HANDLE) {') |
Mark Lobodzinski | d11fcca | 2015-02-09 10:16:20 -0600 | [diff] [blame] | 1012 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1013 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1014 | header_txt.append(' if (pTrav->obj.vkObj == vkObj) {') |
Mark Lobodzinski | d11fcca | 2015-02-09 10:16:20 -0600 | [diff] [blame] | 1015 | header_txt.append(' pTrav->obj.status |= status_flag;') |
| 1016 | header_txt.append(' return;') |
| 1017 | header_txt.append(' }') |
| 1018 | header_txt.append(' pTrav = pTrav->pNextObj;') |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1019 | header_txt.append(' }') |
Mark Lobodzinski | d11fcca | 2015-02-09 10:16:20 -0600 | [diff] [blame] | 1020 | header_txt.append(' // If we do not find it print an error') |
| 1021 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1022 | header_txt.append(' sprintf(str, "Unable to set status for non-existent object 0x%" PRId64 " of %s type", vkObj, string_VK_OBJECT_TYPE(objType));') |
| 1023 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Mark Lobodzinski | d11fcca | 2015-02-09 10:16:20 -0600 | [diff] [blame] | 1024 | header_txt.append(' }'); |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1025 | header_txt.append('}') |
| 1026 | header_txt.append('') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1027 | header_txt.append('// Track selected state for an object node') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1028 | header_txt.append('static void track_object_status(VkObject vkObj, VkStateBindPoint stateBindPoint) {') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1029 | header_txt.append(' objNode *pTrav = pObjectHead[VkObjectTypeCmdBuffer];') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1030 | header_txt.append('') |
| 1031 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1032 | header_txt.append(' if (pTrav->obj.vkObj == vkObj) {') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1033 | header_txt.append(' if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1034 | header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1035 | header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1036 | header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1037 | header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1038 | header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1039 | header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1040 | header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;') |
| 1041 | header_txt.append(' }') |
| 1042 | header_txt.append(' return;') |
| 1043 | header_txt.append(' }') |
| 1044 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1045 | header_txt.append(' }') |
| 1046 | header_txt.append(' // If we do not find it print an error') |
| 1047 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1048 | header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object 0x%" PRId64, vkObj);') |
| 1049 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1050 | header_txt.append('}') |
| 1051 | header_txt.append('') |
| 1052 | header_txt.append('// Reset selected flag state for an object node') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1053 | header_txt.append('static void reset_status(VkObject vkObj, VK_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {') |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1054 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1055 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1056 | header_txt.append(' if (pTrav->obj.vkObj == vkObj) {') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1057 | header_txt.append(' pTrav->obj.status &= ~status_flag;') |
| 1058 | header_txt.append(' return;') |
| 1059 | header_txt.append(' }') |
| 1060 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1061 | header_txt.append(' }') |
| 1062 | header_txt.append(' // If we do not find it print an error') |
| 1063 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1064 | header_txt.append(' sprintf(str, "Unable to reset status for non-existent object 0x%" PRId64 " of %s type", vkObj, string_VK_OBJECT_TYPE(objType));') |
| 1065 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1066 | header_txt.append('}') |
| 1067 | header_txt.append('') |
| 1068 | header_txt.append('// Check object status for selected flag state') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1069 | header_txt.append('static bool32_t validate_status(VkObject vkObj, VK_OBJECT_TYPE objType, OBJECT_STATUS status_mask, OBJECT_STATUS status_flag, VK_DBG_MSG_TYPE error_level, OBJECT_TRACK_ERROR error_code, char* fail_msg) {') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1070 | header_txt.append(' objNode *pTrav = pObjectHead[objType];') |
| 1071 | header_txt.append(' while (pTrav) {') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1072 | header_txt.append(' if (pTrav->obj.vkObj == vkObj) {') |
Mark Lobodzinski | 4186e71 | 2015-02-03 11:52:26 -0600 | [diff] [blame] | 1073 | header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {') |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1074 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1075 | header_txt.append(' sprintf(str, "OBJECT VALIDATION WARNING: %s object 0x%" PRId64 ": %s", string_VK_OBJECT_TYPE(objType), vkObj, fail_msg);') |
| 1076 | header_txt.append(' layerCbMsg(error_level, VK_VALIDATION_LEVEL_0, vkObj, 0, error_code, "OBJTRACK", str);') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1077 | header_txt.append(' return VK_FALSE;') |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1078 | header_txt.append(' }') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1079 | header_txt.append(' return VK_TRUE;') |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1080 | header_txt.append(' }') |
| 1081 | header_txt.append(' pTrav = pTrav->pNextObj;') |
| 1082 | header_txt.append(' }') |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1083 | header_txt.append(' if (objType != VkObjectTypeSwapChainImageWSI &&') |
| 1084 | header_txt.append(' objType != VkObjectTypeSwapChainMemoryWSI) {') |
Mark Lobodzinski | acb9368 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 1085 | header_txt.append(' // If we do not find it print an error') |
| 1086 | header_txt.append(' char str[1024];') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1087 | header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object 0x%" PRId64 " of %s type", vkObj, string_VK_OBJECT_TYPE(objType));') |
| 1088 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);') |
Mark Lobodzinski | acb9368 | 2015-03-05 12:39:33 -0600 | [diff] [blame] | 1089 | header_txt.append(' }') |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1090 | header_txt.append(' return VK_FALSE;') |
Tobin Ehlis | 235c20e | 2015-01-16 08:56:30 -0700 | [diff] [blame] | 1091 | header_txt.append('}') |
Mark Lobodzinski | 0155270 | 2015-02-03 10:06:31 -0600 | [diff] [blame] | 1092 | header_txt.append('') |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1093 | header_txt.append('static void validate_draw_state_flags(VkObject vkObj) {') |
| 1094 | header_txt.append(' validate_status(vkObj, VkObjectTypeCmdBuffer, OBJSTATUS_VIEWPORT_BOUND, OBJSTATUS_VIEWPORT_BOUND, VK_DBG_MSG_ERROR, OBJTRACK_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");') |
| 1095 | header_txt.append(' validate_status(vkObj, VkObjectTypeCmdBuffer, OBJSTATUS_RASTER_BOUND, OBJSTATUS_RASTER_BOUND, VK_DBG_MSG_ERROR, OBJTRACK_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");') |
| 1096 | header_txt.append(' validate_status(vkObj, VkObjectTypeCmdBuffer, OBJSTATUS_COLOR_BLEND_BOUND, OBJSTATUS_COLOR_BLEND_BOUND, VK_DBG_MSG_UNKNOWN, OBJTRACK_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");') |
| 1097 | header_txt.append(' validate_status(vkObj, VkObjectTypeCmdBuffer, OBJSTATUS_DEPTH_STENCIL_BOUND, OBJSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_MSG_UNKNOWN, OBJTRACK_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");') |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1098 | header_txt.append('}') |
| 1099 | header_txt.append('') |
Courtney Goeltzenleuchter | 304a1f8 | 2015-04-07 16:23:00 -0600 | [diff] [blame] | 1100 | header_txt.append('static void setGpuQueueInfoState(void *pData) {') |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1101 | header_txt.append(' maxMemReferences = ((VkPhysicalDeviceQueueProperties *)pData)->maxMemReferences;') |
Mark Lobodzinski | e1d3f0c | 2015-02-09 10:20:53 -0600 | [diff] [blame] | 1102 | header_txt.append('}') |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1103 | return "\n".join(header_txt) |
| 1104 | |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1105 | def generate_intercept(self, proto, qual): |
Jon Ashburn | eb2728b | 2015-04-10 14:33:07 -0600 | [diff] [blame] | 1106 | if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback', 'GetGlobalExtensionInfo' ]: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1107 | # use default version |
| 1108 | return None |
Tobin Ehlis | f29da38 | 2015-04-15 07:46:12 -0600 | [diff] [blame] | 1109 | obj_type_mapping = {base_t : base_t.replace("Vk", "VkObjectType") for base_t in vulkan.object_type_list} |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1110 | # For the various "super-types" we have to use function to distinguish sub type |
Mike Stroyan | 230e625 | 2015-04-17 12:36:38 -0600 | [diff] [blame] | 1111 | for obj_type in ["VK_BASE_OBJECT", "VK_OBJECT", "VK_DYNAMIC_STATE_OBJECT", "VkObject"]: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1112 | obj_type_mapping[obj_type] = "ll_get_obj_type(object)" |
| 1113 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1114 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1115 | param0_name = proto.params[0].name |
Courtney Goeltzenleuchter | ddcb619 | 2015-04-14 18:48:46 -0600 | [diff] [blame] | 1116 | p0_type = proto.params[0].ty.strip('*').replace('const ', '') |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1117 | create_line = '' |
| 1118 | destroy_line = '' |
| 1119 | funcs = [] |
| 1120 | # Special cases for API funcs that don't use an object as first arg |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1121 | if True in [no_use_proto in proto.name for no_use_proto in ['GlobalOption', 'CreateInstance', 'QueueSubmit', 'QueueAddMemReferences', 'QueueRemoveMemReferences', 'QueueWaitIdle', 'GetGlobalExtensionInfo', 'CreateDevice', 'GetGpuInfo', 'QueueSignalSemaphore', 'QueueWaitSemaphore']]: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1122 | using_line = '' |
| 1123 | else: |
| 1124 | using_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1125 | using_line += ' ll_increment_use_count(%s, %s);\n' % (param0_name, obj_type_mapping[p0_type]) |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1126 | using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1127 | if 'QueueSubmit' in proto.name: |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1128 | using_line += ' set_status(fence, VkObjectTypeFence, OBJSTATUS_FENCE_IS_SUBMITTED);\n' |
Courtney Goeltzenleuchter | 8d49dbd | 2015-04-07 17:13:38 -0600 | [diff] [blame] | 1129 | using_line += ' // TODO: Fix for updated memory reference mechanism\n' |
| 1130 | using_line += ' // validate_memory_mapping_status(pMemRefs, memRefCount);\n' |
| 1131 | using_line += ' // validate_mem_ref_count(memRefCount);\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1132 | elif 'GetFenceStatus' in proto.name: |
| 1133 | using_line += ' // Warn if submitted_flag is not set\n' |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1134 | using_line += ' validate_status(fence, VkObjectTypeFence, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, VK_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1135 | elif 'EndCommandBuffer' in proto.name: |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1136 | using_line += ' reset_status(cmdBuffer, VkObjectTypeCmdBuffer, (OBJSTATUS_VIEWPORT_BOUND |\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1137 | using_line += ' OBJSTATUS_RASTER_BOUND |\n' |
| 1138 | using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n' |
| 1139 | using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n' |
| 1140 | elif 'CmdBindDynamicStateObject' in proto.name: |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1141 | using_line += ' track_object_status(cmdBuffer, stateBindPoint);\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1142 | elif 'CmdDraw' in proto.name: |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1143 | using_line += ' validate_draw_state_flags(cmdBuffer);\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1144 | elif 'MapMemory' in proto.name: |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1145 | using_line += ' set_status(mem, VkObjectTypeDeviceMemory, OBJSTATUS_GPU_MEM_MAPPED);\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1146 | elif 'UnmapMemory' in proto.name: |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1147 | using_line += ' reset_status(mem, VkObjectTypeDeviceMemory, OBJSTATUS_GPU_MEM_MAPPED);\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1148 | if 'AllocDescriptor' in proto.name: # Allocates array of DSs |
| 1149 | create_line = ' for (uint32_t i = 0; i < *pCount; i++) {\n' |
| 1150 | create_line += ' loader_platform_thread_lock_mutex(&objLock);\n' |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1151 | create_line += ' ll_insert_obj(pDescriptorSets[i], VkObjectTypeDescriptorSet);\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1152 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1153 | create_line += ' }\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1154 | elif 'Create' in proto.name or 'Alloc' in proto.name: |
| 1155 | create_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1156 | create_line += ' ll_insert_obj(*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').replace('const ', '')]) |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1157 | create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1158 | if 'DestroyObject' in proto.name: |
| 1159 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Mark Lobodzinski | 2df3afc | 2015-04-21 17:15:36 -0600 | [diff] [blame] | 1160 | destroy_line += ' ll_destroy_obj(%s);\n' % (proto.params[2].name) |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1161 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1162 | using_line = '' |
| 1163 | else: |
Mark Lobodzinski | 2df3afc | 2015-04-21 17:15:36 -0600 | [diff] [blame] | 1164 | if 'Destroy' in proto.name: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1165 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1166 | destroy_line += ' ll_destroy_obj(%s);\n' % (param0_name) |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1167 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1168 | using_line = '' |
Mark Lobodzinski | 2df3afc | 2015-04-21 17:15:36 -0600 | [diff] [blame] | 1169 | else: |
| 1170 | if 'Free' in proto.name: |
| 1171 | destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n' |
| 1172 | destroy_line += ' ll_destroy_obj(%s);\n' % (proto.params[1].name) |
| 1173 | destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n' |
| 1174 | using_line = '' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1175 | if 'DestroyDevice' in proto.name: |
| 1176 | destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n' |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 1177 | destroy_line += ' if (pTrav->obj.objType == VkObjectTypeSwapChainImageWSI ||\n' |
| 1178 | destroy_line += ' pTrav->obj.objType == VkObjectTypeSwapChainMemoryWSI) {\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1179 | destroy_line += ' objNode *pDel = pTrav;\n' |
| 1180 | destroy_line += ' pTrav = pTrav->pNextGlobal;\n' |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1181 | destroy_line += ' ll_destroy_obj((pDel->obj.vkObj));\n' |
Tobin Ehlis | fd79ddd | 2015-04-17 13:07:30 -0600 | [diff] [blame] | 1182 | destroy_line += ' } else if ((pTrav->obj.objType == VkObjectTypePhysicalDevice) || (pTrav->obj.objType == VkObjectTypeQueue)) {\n' |
Tobin Ehlis | d7bf5e0 | 2015-04-17 13:00:55 -0600 | [diff] [blame] | 1183 | destroy_line += ' // Cannot destroy physical device so ignore\n' |
| 1184 | destroy_line += ' pTrav = pTrav->pNextGlobal;\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1185 | destroy_line += ' } else {\n' |
| 1186 | destroy_line += ' char str[1024];\n' |
Tony Barbour | 83e6771 | 2015-04-21 09:18:02 -0600 | [diff] [blame] | 1187 | destroy_line += ' sprintf(str, "OBJ ERROR : %s object 0x%" PRId64 " has not been destroyed (was used %lu times).", string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.vkObj, pTrav->obj.numUses);\n' |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1188 | destroy_line += ' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1189 | destroy_line += ' pTrav = pTrav->pNextGlobal;\n' |
| 1190 | destroy_line += ' }\n' |
| 1191 | destroy_line += ' }\n' |
Mark Lobodzinski | 93fdbd2 | 2015-04-09 12:09:45 -0500 | [diff] [blame] | 1192 | destroy_line += ' // Clean up Queue\'s MemRef Linked Lists\n' |
| 1193 | destroy_line += ' destroyQueueMemRefLists();\n' |
| 1194 | if 'GetDeviceQueue' in proto.name: |
| 1195 | destroy_line = ' addQueueInfo(*pQueue);\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1196 | ret_val = '' |
| 1197 | stmt = '' |
| 1198 | if proto.ret != "void": |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 1199 | ret_val = "VkResult result = " |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1200 | stmt = " return result;\n" |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1201 | if proto.name == "EnumerateLayers": |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1202 | funcs.append('%s%s\n' |
| 1203 | '{\n' |
Tony Barbour | 11e76ac | 2015-04-20 16:28:46 -0600 | [diff] [blame] | 1204 | ' if (gpu != VK_NULL_HANDLE) {\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1205 | ' %s' |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1206 | ' pCurObj = (VkBaseLayerObject *) gpu;\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1207 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
| 1208 | ' %snextTable.%s;\n' |
| 1209 | ' %s%s' |
| 1210 | ' %s' |
| 1211 | ' } else {\n' |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame^] | 1212 | ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1213 | ' return VK_ERROR_INVALID_POINTER;\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1214 | ' // This layer compatible with all GPUs\n' |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame^] | 1215 | ' *pLayerCount = 1;\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1216 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1217 | ' return VK_SUCCESS;\n' |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1218 | ' }\n' |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1219 | '}' % (qual, decl, using_line, self.layer_name, ret_val, proto.c_call(), create_line, destroy_line, stmt, self.layer_name)) |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1220 | elif 'GetExtensionSupport' == proto.name: |
| 1221 | funcs.append('%s%s\n' |
| 1222 | '{\n' |
| 1223 | ' VkResult result;\n' |
| 1224 | ' /* This entrypoint is NOT going to init its own dispatch table since loader calls this early */\n' |
| 1225 | ' if (!strncmp(pExtName, "%s", strlen("%s")) ||\n' |
| 1226 | ' !strncmp(pExtName, "objTrackGetObjectCount", strlen("objTrackGetObjectCount")) ||\n' |
| 1227 | ' !strncmp(pExtName, "objTrackGetObjects", strlen("objTrackGetObjects")))\n' |
| 1228 | ' {\n' |
| 1229 | ' result = VK_SUCCESS;\n' |
| 1230 | ' } else if (nextTable.GetExtensionSupport != NULL)\n' |
| 1231 | ' {\n' |
| 1232 | ' %s' |
| 1233 | ' result = nextTable.%s;\n' |
| 1234 | ' } else\n' |
| 1235 | ' {\n' |
| 1236 | ' result = VK_ERROR_INVALID_EXTENSION;\n' |
| 1237 | ' }\n' |
| 1238 | '%s' |
| 1239 | '}' % (qual, decl, self.layer_name, self.layer_name, using_line, proto.c_call(), stmt)) |
| 1240 | elif 'GetPhysicalDeviceInfo' in proto.name: |
| 1241 | gpu_state = ' if (infoType == VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES) {\n' |
Jon Ashburn | 630e44f | 2015-04-08 21:33:34 -0600 | [diff] [blame] | 1242 | gpu_state += ' if (pData != NULL) {\n' |
| 1243 | gpu_state += ' setGpuQueueInfoState(pData);\n' |
| 1244 | gpu_state += ' }\n' |
| 1245 | gpu_state += ' }\n' |
| 1246 | funcs.append('%s%s\n' |
| 1247 | '{\n' |
| 1248 | '%s' |
| 1249 | ' pCurObj = (VkBaseLayerObject *) gpu;\n' |
| 1250 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
| 1251 | ' %snextTable.%s;\n' |
| 1252 | '%s%s' |
| 1253 | '%s' |
| 1254 | '%s' |
| 1255 | '}' % (qual, decl, using_line, self.layer_name, ret_val, proto.c_call(), create_line, destroy_line, gpu_state, stmt)) |
| 1256 | else: |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1257 | funcs.append('%s%s\n' |
| 1258 | '{\n' |
| 1259 | '%s' |
| 1260 | ' %snextTable.%s;\n' |
| 1261 | '%s%s' |
| 1262 | '%s' |
| 1263 | '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt)) |
Mike Stroyan | 723913e | 2015-04-03 14:39:16 -0600 | [diff] [blame] | 1264 | return "\n\n".join(funcs) |
| 1265 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1266 | def generate_body(self): |
Mike Stroyan | 3aecdb4 | 2015-04-03 17:13:23 -0600 | [diff] [blame] | 1267 | self.layer_name = "ObjectTracker" |
| 1268 | body = [self._generate_layer_initialization(True, lockname='obj'), |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1269 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
Tobin Ehlis | 3c26a54 | 2014-11-18 11:28:33 -0700 | [diff] [blame] | 1270 | self._generate_extensions(), |
Mike Stroyan | 2ad66f1 | 2015-04-03 17:45:53 -0600 | [diff] [blame] | 1271 | self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])] |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1272 | |
| 1273 | return "\n\n".join(body) |
Courtney Goeltzenleuchter | e6094fc | 2014-11-18 10:40:29 -0700 | [diff] [blame] | 1274 | |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1275 | class ThreadingSubcommand(Subcommand): |
| 1276 | def generate_header(self): |
| 1277 | header_txt = [] |
| 1278 | header_txt.append('#include <stdio.h>') |
| 1279 | header_txt.append('#include <stdlib.h>') |
| 1280 | header_txt.append('#include <string.h>') |
| 1281 | header_txt.append('#include <unordered_map>') |
| 1282 | header_txt.append('#include "loader_platform.h"') |
| 1283 | header_txt.append('#include "vkLayer.h"') |
| 1284 | header_txt.append('#include "threading.h"') |
| 1285 | header_txt.append('#include "layers_config.h"') |
| 1286 | header_txt.append('#include "vk_enum_validate_helper.h"') |
| 1287 | header_txt.append('#include "vk_struct_validate_helper.h"') |
| 1288 | header_txt.append('//The following is #included again to catch certain OS-specific functions being used:') |
| 1289 | header_txt.append('#include "loader_platform.h"\n') |
| 1290 | header_txt.append('#include "layers_msg.h"\n') |
| 1291 | header_txt.append('static VkLayerDispatchTable nextTable;') |
| 1292 | header_txt.append('static VkBaseLayerObject *pCurObj;') |
| 1293 | header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n') |
| 1294 | header_txt.append('using namespace std;') |
| 1295 | header_txt.append('static unordered_map<int, void*> proxy_objectsInUse;\n') |
| 1296 | header_txt.append('static unordered_map<VkObject, loader_platform_thread_id> objectsInUse;\n') |
| 1297 | header_txt.append('static int threadingLockInitialized = 0;') |
| 1298 | header_txt.append('static loader_platform_thread_mutex threadingLock;') |
| 1299 | header_txt.append('static int printLockInitialized = 0;') |
| 1300 | header_txt.append('static loader_platform_thread_mutex printLock;\n') |
| 1301 | header_txt.append('') |
| 1302 | header_txt.append('static void useObject(VkObject object, const char* type)') |
| 1303 | header_txt.append('{') |
| 1304 | header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();') |
| 1305 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1306 | header_txt.append(' if (objectsInUse.find(object) == objectsInUse.end()) {') |
| 1307 | header_txt.append(' objectsInUse[object] = tid;') |
| 1308 | header_txt.append(' } else {') |
| 1309 | header_txt.append(' if (objectsInUse[object] == tid) {') |
| 1310 | header_txt.append(' char str[1024];') |
| 1311 | header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is simultaneously used in thread %ld and thread %ld", type, objectsInUse[object], tid);') |
| 1312 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING", str);') |
| 1313 | header_txt.append(' } else {') |
| 1314 | header_txt.append(' char str[1024];') |
| 1315 | header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is recursively used in thread %ld", type, tid);') |
| 1316 | header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, THREADING_CHECKER_SINGLE_THREAD_REUSE, "THREADING", str);') |
| 1317 | header_txt.append(' }') |
| 1318 | header_txt.append(' }') |
| 1319 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1320 | header_txt.append('}') |
| 1321 | header_txt.append('static void finishUsingObject(VkObject object)') |
| 1322 | header_txt.append('{') |
| 1323 | header_txt.append(' // Object is no longer in use') |
| 1324 | header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);') |
| 1325 | header_txt.append(' objectsInUse.erase(object);') |
| 1326 | header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);') |
| 1327 | header_txt.append('}') |
| 1328 | return "\n".join(header_txt) |
| 1329 | |
| 1330 | def generate_intercept(self, proto, qual): |
| 1331 | if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback' ]: |
| 1332 | # use default version |
| 1333 | return None |
| 1334 | decl = proto.c_func(prefix="vk", attr="VKAPI") |
| 1335 | ret_val = '' |
| 1336 | stmt = '' |
| 1337 | funcs = [] |
| 1338 | if proto.ret != "void": |
| 1339 | ret_val = "VkResult result = " |
| 1340 | stmt = " return result;\n" |
| 1341 | if proto.name == "EnumerateLayers": |
| 1342 | funcs.append('%s%s\n' |
| 1343 | '{\n' |
| 1344 | ' char str[1024];\n' |
| 1345 | ' if (gpu != NULL) {\n' |
| 1346 | ' pCurObj = (VkBaseLayerObject *) %s;\n' |
| 1347 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
| 1348 | ' %snextTable.%s;\n' |
| 1349 | ' fflush(stdout);\n' |
| 1350 | ' %s' |
| 1351 | ' } else {\n' |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame^] | 1352 | ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n' |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1353 | ' return VK_ERROR_INVALID_POINTER;\n' |
| 1354 | ' // This layer compatible with all GPUs\n' |
Courtney Goeltzenleuchter | bb1f360 | 2015-04-20 11:04:54 -0600 | [diff] [blame^] | 1355 | ' *pLayerCount = 1;\n' |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1356 | ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n' |
| 1357 | ' return VK_SUCCESS;\n' |
| 1358 | ' }\n' |
| 1359 | '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, proto.c_call(), stmt, self.layer_name)) |
| 1360 | # All functions that do a Get are thread safe |
| 1361 | elif 'Get' in proto.name: |
| 1362 | return None |
| 1363 | # All Wsi functions are thread safe |
| 1364 | elif 'WsiX11' in proto.name: |
| 1365 | return None |
| 1366 | # All functions that start with a device parameter are thread safe |
| 1367 | elif proto.params[0].ty in { "VkDevice" }: |
| 1368 | return None |
| 1369 | # Only watch core objects passed as first parameter |
| 1370 | elif proto.params[0].ty not in vulkan.core.objects: |
| 1371 | return None |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 1372 | elif proto.params[0].ty != "VkPhysicalDevice": |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1373 | funcs.append('%s%s\n' |
| 1374 | '{\n' |
| 1375 | ' useObject((VkObject) %s, "%s");\n' |
| 1376 | ' %snextTable.%s;\n' |
| 1377 | ' finishUsingObject((VkObject) %s);\n' |
| 1378 | '%s' |
| 1379 | '}' % (qual, decl, proto.params[0].name, proto.params[0].ty, ret_val, proto.c_call(), proto.params[0].name, stmt)) |
| 1380 | else: |
| 1381 | funcs.append('%s%s\n' |
| 1382 | '{\n' |
| 1383 | ' pCurObj = (VkBaseLayerObject *) %s;\n' |
| 1384 | ' loader_platform_thread_once(&tabOnce, init%s);\n' |
| 1385 | ' %snextTable.%s;\n' |
| 1386 | '%s' |
| 1387 | '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, proto.c_call(), stmt)) |
| 1388 | return "\n\n".join(funcs) |
| 1389 | |
| 1390 | def generate_body(self): |
| 1391 | self.layer_name = "Threading" |
| 1392 | body = [self._generate_layer_initialization(True, lockname='threading'), |
| 1393 | self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"), |
| 1394 | self._generate_layer_gpa_function()] |
| 1395 | return "\n\n".join(body) |
| 1396 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1397 | def main(): |
| 1398 | subcommands = { |
| 1399 | "layer-funcs" : LayerFuncsSubcommand, |
| 1400 | "layer-dispatch" : LayerDispatchSubcommand, |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1401 | "Generic" : GenericLayerSubcommand, |
Tobin Ehlis | 4a636a1 | 2015-04-09 09:19:36 -0600 | [diff] [blame] | 1402 | "APIDump" : APIDumpSubcommand, |
Tobin Ehlis | 907a052 | 2014-11-25 16:59:27 -0700 | [diff] [blame] | 1403 | "ObjectTracker" : ObjectTrackerSubcommand, |
Mike Stroyan | b326d2c | 2015-04-02 11:59:05 -0600 | [diff] [blame] | 1404 | "Threading" : ThreadingSubcommand, |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1405 | } |
| 1406 | |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1407 | if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]): |
| 1408 | print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0]) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1409 | print |
Tobin Ehlis | 2f3726c | 2015-01-15 17:51:52 -0700 | [diff] [blame] | 1410 | print("Available subcommands are: %s" % " ".join(subcommands)) |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1411 | exit(1) |
| 1412 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1413 | hfp = vk_helper.HeaderFileParser(sys.argv[2]) |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1414 | hfp.parse() |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 1415 | vk_helper.enum_val_dict = hfp.get_enum_val_dict() |
| 1416 | vk_helper.enum_type_dict = hfp.get_enum_type_dict() |
| 1417 | vk_helper.struct_dict = hfp.get_struct_dict() |
| 1418 | vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict() |
| 1419 | vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict() |
| 1420 | vk_helper.types_dict = hfp.get_types_dict() |
Tobin Ehlis | 6cd0637 | 2014-12-17 17:44:50 -0700 | [diff] [blame] | 1421 | |
Tobin Ehlis | 92dbf80 | 2014-10-22 09:06:33 -0600 | [diff] [blame] | 1422 | subcmd = subcommands[sys.argv[1]](sys.argv[2:]) |
| 1423 | subcmd.run() |
| 1424 | |
| 1425 | if __name__ == "__main__": |
| 1426 | main() |