blob: 749e6d56ca7e8c0234467b438134d25c974073bb [file] [log] [blame]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001#!/usr/bin/env python3
2#
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003# VK
Tobin Ehlis92dbf802014-10-22 09:06:33 -06004#
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
28import sys
Tobin Ehlis6cd06372014-12-17 17:44:50 -070029import os
Tobin Ehlis92dbf802014-10-22 09:06:33 -060030
Courtney Goeltzenleuchtera8c06282015-04-14 14:55:44 -060031import vulkan
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060032import vk_helper
Tobin Ehlis92dbf802014-10-22 09:06:33 -060033
Mike Stroyan7c2efaa2015-04-03 13:58:35 -060034def generate_get_proc_addr_check(name):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060035 return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \
36 " return NULL;" % ((name,) * 3)
Mike Stroyan7c2efaa2015-04-03 13:58:35 -060037
Tobin Ehlis92dbf802014-10-22 09:06:33 -060038class Subcommand(object):
39 def __init__(self, argv):
40 self.argv = argv
Courtney Goeltzenleuchtera8c06282015-04-14 14:55:44 -060041 self.headers = vulkan.headers
42 self.protos = vulkan.protos
Mike Stroyan3aecdb42015-04-03 17:13:23 -060043 self.no_addr = False
44 self.layer_name = ""
Tobin Ehlis92dbf802014-10-22 09:06:33 -060045
46 def run(self):
Tobin Ehlis92dbf802014-10-22 09:06:33 -060047 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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060071 * Vulkan
Tobin Ehlis92dbf802014-10-22 09:06:33 -060072 *
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 Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600104 def _get_printf_params(self, vk_type, name, output_param, cpp=False):
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600105 # TODO : Need ENUM and STRUCT checks here
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600106 if vk_helper.is_type(vk_type, 'enum'):#"_TYPE" in vk_type: # TODO : This should be generic ENUM check
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600107 return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600108 if "char*" == vk_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600109 return ("%s", name)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600110 if "uint64" in vk_type:
111 if '*' in vk_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600112 return ("%lu", "*%s" % name)
113 return ("%lu", name)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600114 if "size" in vk_type:
115 if '*' in vk_type:
Chia-I Wu54ed0792014-12-27 14:14:50 +0800116 return ("%zu", "*%s" % name)
117 return ("%zu", name)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600118 if "float" in vk_type:
119 if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700120 if cpp:
121 return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600122 return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
123 return ("%f", name)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600124 if "bool" in vk_type or 'xcb_randr_crtc_t' in vk_type:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600125 return ("%u", name)
Tobin Ehlisf29da382015-04-15 07:46:12 -0600126 if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600127 if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700128 if cpp:
129 return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600130 return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600131 if '*' in vk_type:
Tobin Ehlis1336c8d2015-02-04 15:15:11 -0700132 if 'pUserData' == name:
133 return ("%i", "((pUserData == 0) ? 0 : *(pUserData))")
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700134 return ("%i", "*(%s)" % name)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600135 return ("%i", name)
Tobin Ehlis0a1e06d2014-11-11 17:28:22 -0700136 # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600137 if "VkFormat" == vk_type:
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700138 if cpp:
139 return ("%p", "&%s" % name)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600140 return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_CHANNEL_FORMAT(%s.channelFormat), string_VK_NUM_FORMAT(%s.numericFormat)" % (name, name))
Tobin Ehlisa554dc32014-11-19 15:52:46 -0700141 if output_param:
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600142 return ("%p", "(void*)*%s" % name)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600143 if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type:
Courtney Goeltzenleuchter9a1ded82015-04-03 16:35:32 -0600144 return ("%p", "(void*)(&%s)" % name)
Jon Ashburn1f7e2d72014-12-12 16:10:45 -0700145 return ("%p", "(void*)(%s)" % name)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600146
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700147 def _gen_layer_dbg_callback_register(self):
148 r_body = []
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600149 r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700150 r_body.append('{')
151 r_body.append(' // This layer intercepts callbacks')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600152 r_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (VK_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(VK_LAYER_DBG_FUNCTION_NODE));')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700153 r_body.append(' if (!pNewDbgFuncNode)')
Tony Barbour8205d902015-04-16 15:59:00 -0600154 r_body.append(' return VK_ERROR_OUT_OF_HOST_MEMORY;')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700155 r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;')
156 r_body.append(' pNewDbgFuncNode->pUserData = pUserData;')
Jon Ashburn21001f62015-02-16 08:26:50 -0700157 r_body.append(' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;')
158 r_body.append(' g_pDbgFunctionHead = pNewDbgFuncNode;')
Jon Ashburne4722392015-03-03 15:07:15 -0700159 r_body.append(' // force callbacks if DebugAction hasn\'t been set already other than initial value')
Ian Elliottc9473d92015-03-05 12:28:53 -0700160 r_body.append(' if (g_actionIsDefault) {')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600161 r_body.append(' g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;')
Ian Elliottc9473d92015-03-05 12:28:53 -0700162 r_body.append(' }')
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600163 r_body.append(' VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700164 r_body.append(' return result;')
165 r_body.append('}')
166 return "\n".join(r_body)
167
168 def _gen_layer_dbg_callback_unregister(self):
169 ur_body = []
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600170 ur_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700171 ur_body.append('{')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600172 ur_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;')
173 ur_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700174 ur_body.append(' while (pTrav) {')
175 ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {')
176 ur_body.append(' pPrev->pNext = pTrav->pNext;')
Jon Ashburn21001f62015-02-16 08:26:50 -0700177 ur_body.append(' if (g_pDbgFunctionHead == pTrav)')
178 ur_body.append(' g_pDbgFunctionHead = pTrav->pNext;')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700179 ur_body.append(' free(pTrav);')
180 ur_body.append(' break;')
181 ur_body.append(' }')
182 ur_body.append(' pPrev = pTrav;')
183 ur_body.append(' pTrav = pTrav->pNext;')
184 ur_body.append(' }')
Jon Ashburne4722392015-03-03 15:07:15 -0700185 ur_body.append(' if (g_pDbgFunctionHead == NULL)')
186 ur_body.append(' {')
187 ur_body.append(' if (g_actionIsDefault)')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600188 ur_body.append(' g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;')
Jon Ashburne4722392015-03-03 15:07:15 -0700189 ur_body.append(' else')
Mike Stroyanb326d2c2015-04-02 11:59:05 -0600190 ur_body.append(' g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));')
Jon Ashburne4722392015-03-03 15:07:15 -0700191 ur_body.append(' }')
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600192 ur_body.append(' VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);')
Tobin Ehlisc54139f2014-12-17 08:01:59 -0700193 ur_body.append(' return result;')
194 ur_body.append('}')
195 return "\n".join(ur_body)
196
Jon Ashburneb2728b2015-04-10 14:33:07 -0600197 def _gen_layer_get_global_extension_info(self, layer="Generic"):
198 ggei_body = []
199 ggei_body.append('struct extProps {')
200 ggei_body.append(' uint32_t version;')
201 ggei_body.append(' const char * const name;')
202 ggei_body.append('};')
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600203 if layer == 'ObjectTracker':
204 ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 4')
205 ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {')
206 ggei_body.append(' // TODO what is the version?')
207 ggei_body.append(' {0x10, "%s"},' % layer)
208 ggei_body.append(' {0x10, "Validation"},')
209 ggei_body.append(' {0x10, "objTrackGetObjectCount"},')
210 ggei_body.append(' {0x10, "objTrackGetObjects"}')
211 ggei_body.append('};')
Tobin Ehlisa53add02015-04-15 17:19:18 -0600212 elif layer == 'Threading':
213 ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 2')
214 ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {')
215 ggei_body.append(' // TODO what is the version?')
216 ggei_body.append(' {0x10, "%s"},' % layer)
217 ggei_body.append(' {0x10, "Validation"},')
218 ggei_body.append('};')
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600219 else:
220 ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 1')
221 ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {')
222 ggei_body.append(' // TODO what is the version?')
223 ggei_body.append(' {0x10, "%s"}' % layer)
224 ggei_body.append('};')
Jon Ashburneb2728b2015-04-10 14:33:07 -0600225 ggei_body.append('')
Mark Lobodzinski8bae7d42015-04-13 16:35:52 -0500226 ggei_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(VkExtensionInfoType infoType, uint32_t extensionIndex, size_t* pDataSize, void* pData)')
Jon Ashburneb2728b2015-04-10 14:33:07 -0600227 ggei_body.append('{')
228 ggei_body.append(' VkExtensionProperties *ext_props;')
229 ggei_body.append(' uint32_t *count;')
230 ggei_body.append('')
231 ggei_body.append(' if (pDataSize == NULL)')
232 ggei_body.append(' return VK_ERROR_INVALID_POINTER;')
233 ggei_body.append('')
234 ggei_body.append(' switch (infoType) {')
235 ggei_body.append(' case VK_EXTENSION_INFO_TYPE_COUNT:')
236 ggei_body.append(' *pDataSize = sizeof(uint32_t);')
237 ggei_body.append(' if (pData == NULL)')
238 ggei_body.append(' return VK_SUCCESS;')
239 ggei_body.append(' count = (uint32_t *) pData;')
240 ggei_body.append(' *count = LAYER_EXT_ARRAY_SIZE;')
241 ggei_body.append(' break;')
242 ggei_body.append(' case VK_EXTENSION_INFO_TYPE_PROPERTIES:')
243 ggei_body.append(' *pDataSize = sizeof(VkExtensionProperties);')
244 ggei_body.append(' if (pData == NULL)')
245 ggei_body.append(' return VK_SUCCESS;')
246 ggei_body.append(' if (extensionIndex >= LAYER_EXT_ARRAY_SIZE)')
247 ggei_body.append(' return VK_ERROR_INVALID_VALUE;')
248 ggei_body.append(' ext_props = (VkExtensionProperties *) pData;')
249 ggei_body.append(' ext_props->version = layerExts[extensionIndex].version;')
250 ggei_body.append(' strncpy(ext_props->extName, layerExts[extensionIndex].name,')
251 ggei_body.append(' VK_MAX_EXTENSION_NAME);')
252 ggei_body.append(" ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\\0';")
253 ggei_body.append(' break;')
254 ggei_body.append(' default:')
255 ggei_body.append(' return VK_ERROR_INVALID_VALUE;')
256 ggei_body.append(' };')
257 ggei_body.append(' return VK_SUCCESS;')
258 ggei_body.append('}')
259 return "\n".join(ggei_body)
Jon Ashburn25566352015-04-02 12:06:28 -0600260
Tony Barbour8205d902015-04-16 15:59:00 -0600261 def _gen_layer_get_extension_support(self, layer="Generic"):
262 ges_body = []
263 ges_body.append('VK_LAYER_EXPORT VkResult VKAPI xglGetExtensionSupport(VkPhysicalDevice gpu, const char* pExtName)')
264 ges_body.append('{')
265 ges_body.append(' VkResult result;')
266 ges_body.append(' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;')
267 ges_body.append('')
268 ges_body.append(' /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */')
269 ges_body.append(' if (!strncmp(pExtName, "%s", strlen("%s")))' % (layer, layer))
270 ges_body.append(' {')
271 ges_body.append(' result = VK_SUCCESS;')
272 ges_body.append(' } else if (nextTable.GetExtensionSupport != NULL)')
273 ges_body.append(' {')
274 ges_body.append(' result = nextTable.GetExtensionSupport((VkPhysicalDevice)gpuw->nextObject, pExtName);')
275 ges_body.append(' } else')
276 ges_body.append(' {')
277 ges_body.append(' result = VK_ERROR_INVALID_EXTENSION;')
278 ges_body.append(' }')
279 ges_body.append(' return result;')
280 ges_body.append('}')
281 return "\n".join(ges_body)
282
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600283 def _generate_dispatch_entrypoints(self, qual=""):
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600284 if qual:
285 qual += " "
286
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600287 funcs = []
288 intercepted = []
289 for proto in self.protos:
Mike Stroyan88f0ecf2015-04-08 10:27:43 -0600290 if proto.name == "GetProcAddr":
291 intercepted.append(proto)
292 else:
Mike Stroyan3aecdb42015-04-03 17:13:23 -0600293 intercept = self.generate_intercept(proto, qual)
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600294 if intercept is None:
295 # fill in default intercept for certain entrypoints
296 if 'DbgRegisterMsgCallback' == proto.name:
297 intercept = self._gen_layer_dbg_callback_register()
Jon Ashburn25566352015-04-02 12:06:28 -0600298 elif 'DbgUnregisterMsgCallback' == proto.name:
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600299 intercept = self._gen_layer_dbg_callback_unregister()
Jon Ashburneb2728b2015-04-10 14:33:07 -0600300 elif 'GetGlobalExtensionInfo' == proto.name:
301 funcs.append(self._gen_layer_get_global_extension_info(self.layer_name))
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600302 if intercept is not None:
303 funcs.append(intercept)
304 intercepted.append(proto)
305
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600306 prefix="vk"
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600307 lookups = []
308 for proto in intercepted:
309 if 'WsiX11' in proto.name:
310 lookups.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
311 lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
312 lookups.append(" return (void*) %s%s;" %
313 (prefix, proto.name))
314 if 'WsiX11' in proto.name:
315 lookups.append("#endif")
316
Jon Ashburneb2728b2015-04-10 14:33:07 -0600317 prefix="vk"
318 lookups = []
319 for proto in intercepted:
320 if 'WsiX11' in proto.name:
321 lookups.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
322 lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
323 lookups.append(" return (void*) %s%s;" %
324 (prefix, proto.name))
325 if 'WsiX11' in proto.name:
326 lookups.append("#endif")
327
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600328 # add customized layer_intercept_proc
329 body = []
330 body.append("static inline void* layer_intercept_proc(const char *name)")
331 body.append("{")
332 body.append(generate_get_proc_addr_check("name"))
333 body.append("")
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600334 body.append(" name += 2;")
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600335 body.append(" %s" % "\n ".join(lookups))
336 body.append("")
337 body.append(" return NULL;")
338 body.append("}")
339 funcs.append("\n".join(body))
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600340 return "\n\n".join(funcs)
341
342
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700343 def _generate_extensions(self):
344 exts = []
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600345 exts.append('uint64_t objTrackGetObjectCount(VK_OBJECT_TYPE type)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700346 exts.append('{')
Tobin Ehlisf29da382015-04-15 07:46:12 -0600347 exts.append(' return (type == VkObjectTypeAny) ? numTotalObjs : numObjs[type];')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700348 exts.append('}')
349 exts.append('')
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600350 exts.append('VkResult objTrackGetObjects(VK_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700351 exts.append('{')
352 exts.append(" // This bool flags if we're pulling all objs or just a single class of objs")
Tobin Ehlisf29da382015-04-15 07:46:12 -0600353 exts.append(' bool32_t bAllObjs = (type == VkObjectTypeAny);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700354 exts.append(' // Check the count first thing')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600355 exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700356 exts.append(' if (objCount > maxObjCount) {')
357 exts.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600358 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));')
359 exts.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
360 exts.append(' return VK_ERROR_INVALID_VALUE;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700361 exts.append(' }')
362 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600363 exts.append(' for (uint64_t i = 0; i < objCount; i++) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700364 exts.append(' if (!pTrav) {')
365 exts.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600366 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);')
367 exts.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
368 exts.append(' return VK_ERROR_UNKNOWN;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700369 exts.append(' }')
370 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
371 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
372 exts.append(' }')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600373 exts.append(' return VK_SUCCESS;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700374 exts.append('}')
Tobin Ehlisf29da382015-04-15 07:46:12 -0600375 return "\n".join(exts)
376
Jon Ashburn301c5f02015-04-06 10:58:22 -0600377 def _generate_layer_gpa_function(self, extensions=[]):
378 func_body = []
Tony Barbour8205d902015-04-16 15:59:00 -0600379 func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)\n"
Jon Ashburn301c5f02015-04-06 10:58:22 -0600380 "{\n"
381 " VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;\n"
382 " void* addr;\n"
383 " if (gpu == NULL)\n"
384 " return NULL;\n"
385 " pCurObj = gpuw;\n"
386 " loader_platform_thread_once(&tabOnce, init%s);\n\n"
387 " addr = layer_intercept_proc(funcName);\n"
388 " if (addr)\n"
389 " return addr;" % self.layer_name)
390
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700391 if 0 != len(extensions):
392 for ext_name in extensions:
Chia-I Wu7461fcf2014-12-27 15:16:07 +0800393 func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n'
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700394 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600395 func_body.append(" else {\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600396 " if (gpuw->pGPA == NULL)\n"
397 " return NULL;\n"
Tony Barbour8205d902015-04-16 15:59:00 -0600398 " return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);\n"
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600399 " }\n"
400 "}\n")
401 return "\n".join(func_body)
402
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600403 def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None):
404 func_body = ["#include \"vk_dispatch_table_helper.h\""]
Jon Ashburn21001f62015-02-16 08:26:50 -0700405 func_body.append('static void init%s(void)\n'
Mike Stroyan3aecdb42015-04-03 17:13:23 -0600406 '{\n' % self.layer_name)
Jon Ashburn21001f62015-02-16 08:26:50 -0700407 if init_opts:
408 func_body.append(' const char *strOpt;')
Mike Stroyan3aecdb42015-04-03 17:13:23 -0600409 func_body.append(' // initialize %s options' % self.layer_name)
410 func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportingLevel);' % self.layer_name)
411 func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % self.layer_name)
Jon Ashburn21001f62015-02-16 08:26:50 -0700412 func_body.append('')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600413 func_body.append(' if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)')
Jon Ashburn21001f62015-02-16 08:26:50 -0700414 func_body.append(' {')
Mike Stroyan3aecdb42015-04-03 17:13:23 -0600415 func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name)
Jon Ashburn21001f62015-02-16 08:26:50 -0700416 func_body.append(' if (strOpt)')
417 func_body.append(' {')
418 func_body.append(' g_logFile = fopen(strOpt, "w");')
419 func_body.append(' }')
420 func_body.append(' if (g_logFile == NULL)')
421 func_body.append(' g_logFile = stdout;')
422 func_body.append(' }')
423 func_body.append('')
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600424 func_body.append(' PFN_vkGetProcAddr fpNextGPA;\n'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600425 ' fpNextGPA = pCurObj->pGPA;\n'
Jon Ashburn21001f62015-02-16 08:26:50 -0700426 ' assert(fpNextGPA);\n')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600427
Tony Barbour8205d902015-04-16 15:59:00 -0600428 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);")
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700429 if lockname is not None:
430 func_body.append(" if (!%sLockInitialized)" % lockname)
431 func_body.append(" {")
432 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
433 func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname)
434 func_body.append(" %sLockInitialized = 1;" % lockname)
435 func_body.append(" }")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600436 func_body.append("}\n")
437 return "\n".join(func_body)
438
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600439 def _generate_layer_initialization_with_lock(self, prefix='vk'):
440 func_body = ["#include \"vk_dispatch_table_helper.h\""]
Jon Ashburn21001f62015-02-16 08:26:50 -0700441 func_body.append('static void init%s(void)\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700442 '{\n'
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600443 ' PFN_vkGetProcAddr fpNextGPA;\n'
Ian Elliott81ac44c2015-01-13 17:52:38 -0700444 ' fpNextGPA = pCurObj->pGPA;\n'
Mike Stroyanb326d2c2015-04-02 11:59:05 -0600445 ' assert(fpNextGPA);\n' % self.layer_name)
Ian Elliott81ac44c2015-01-13 17:52:38 -0700446
Tony Barbour8205d902015-04-16 15:59:00 -0600447 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);\n")
Ian Elliott81ac44c2015-01-13 17:52:38 -0700448 func_body.append(" if (!printLockInitialized)")
449 func_body.append(" {")
450 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
451 func_body.append(" loader_platform_thread_create_mutex(&printLock);")
452 func_body.append(" printLockInitialized = 1;")
453 func_body.append(" }")
454 func_body.append("}\n")
455 return "\n".join(func_body)
456
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600457class LayerFuncsSubcommand(Subcommand):
458 def generate_header(self):
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600459 return '#include <vkLayer.h>\n#include "loader.h"'
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600460
461 def generate_body(self):
Mike Stroyan3aecdb42015-04-03 17:13:23 -0600462 return self._generate_dispatch_entrypoints("static")
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600463
464class LayerDispatchSubcommand(Subcommand):
465 def generate_header(self):
466 return '#include "layer_wrappers.h"'
467
468 def generate_body(self):
Jon Ashburn21001f62015-02-16 08:26:50 -0700469 return self._generate_layer_initialization()
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600470
471class GenericLayerSubcommand(Subcommand):
472 def generate_header(self):
Jon Ashburn301c5f02015-04-06 10:58:22 -0600473 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 Ehlis92dbf802014-10-22 09:06:33 -0600474
Mike Stroyan3aecdb42015-04-03 17:13:23 -0600475 def generate_intercept(self, proto, qual):
Tobin Ehlis46c96652015-04-16 11:17:12 -0600476 if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback' , 'GetGlobalExtensionInfo']:
Mike Stroyan723913e2015-04-03 14:39:16 -0600477 # use default version
478 return None
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600479 decl = proto.c_func(prefix="vk", attr="VKAPI")
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600480 ret_val = ''
481 stmt = ''
482 funcs = []
483 if proto.ret != "void":
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600484 ret_val = "VkResult result = "
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600485 stmt = " return result;\n"
486 if 'WsiX11AssociateConnection' == proto.name:
487 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
488 if proto.name == "EnumerateLayers":
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600489 funcs.append('%s%s\n'
490 '{\n'
491 ' char str[1024];\n'
492 ' if (gpu != NULL) {\n'
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600493 ' sprintf(str, "At start of layered %s\\n");\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600494 ' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn630e44f2015-04-08 21:33:34 -0600495 ' pCurObj = (VkBaseLayerObject *) gpu;\n'
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600496 ' loader_platform_thread_once(&tabOnce, init%s);\n'
497 ' %snextTable.%s;\n'
498 ' sprintf(str, "Completed layered %s\\n");\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600499 ' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600500 ' fflush(stdout);\n'
501 ' %s'
502 ' } else {\n'
503 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600504 ' return VK_ERROR_INVALID_POINTER;\n'
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600505 ' // This layer compatible with all GPUs\n'
506 ' *pOutLayerCount = 1;\n'
507 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600508 ' return VK_SUCCESS;\n'
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600509 ' }\n'
Jon Ashburn630e44f2015-04-08 21:33:34 -0600510 '}' % (qual, decl, proto.name, self.layer_name, ret_val, proto.c_call(), proto.name, stmt, self.layer_name))
511 else:
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600512 funcs.append('%s%s\n'
513 '{\n'
514 ' %snextTable.%s;\n'
515 '%s'
516 '}' % (qual, decl, ret_val, proto.c_call(), stmt))
Mike Stroyan7c2efaa2015-04-03 13:58:35 -0600517 if 'WsiX11QueuePresent' == proto.name:
518 funcs.append("#endif")
519 return "\n\n".join(funcs)
520
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600521 def generate_body(self):
Mike Stroyan3aecdb42015-04-03 17:13:23 -0600522 self.layer_name = "Generic"
523 body = [self._generate_layer_initialization(True),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600524 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600525 self._generate_layer_gpa_function()]
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600526
527 return "\n\n".join(body)
528
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600529class APIDumpSubcommand(Subcommand):
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600530 def generate_header(self):
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700531 header_txt = []
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600532 header_txt.append('#include <fstream>')
533 header_txt.append('#include <iostream>')
534 header_txt.append('#include <string>')
535 header_txt.append('')
536 header_txt.append('static std::ofstream fileStream;')
537 header_txt.append('static std::string fileName = "vk_apidump.txt";')
538 header_txt.append('std::ostream* outputStream = NULL;')
539 header_txt.append('void ConfigureOutputStream(bool writeToFile, bool flushAfterWrite)')
540 header_txt.append('{')
541 header_txt.append(' if(writeToFile)')
542 header_txt.append(' {')
543 header_txt.append(' fileStream.open(fileName);')
544 header_txt.append(' outputStream = &fileStream;')
545 header_txt.append(' }')
546 header_txt.append(' else')
547 header_txt.append(' {')
548 header_txt.append(' outputStream = &std::cout;')
549 header_txt.append(' }')
550 header_txt.append('')
551 header_txt.append(' if(flushAfterWrite)')
552 header_txt.append(' {')
553 header_txt.append(' outputStream->sync_with_stdio(true);')
554 header_txt.append(' }')
555 header_txt.append(' else')
556 header_txt.append(' {')
557 header_txt.append(' outputStream->sync_with_stdio(false);')
558 header_txt.append(' }')
559 header_txt.append('}')
560 header_txt.append('')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700561 header_txt.append('#include "loader_platform.h"')
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600562 header_txt.append('#include "vkLayer.h"')
563 header_txt.append('#include "vk_struct_string_helper_cpp.h"')
564 header_txt.append('')
Ian Elliott20f06872015-02-12 17:08:34 -0700565 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
566 header_txt.append('#include "loader_platform.h"')
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600567 header_txt.append('')
Jon Ashburn301c5f02015-04-06 10:58:22 -0600568 header_txt.append('static VkLayerDispatchTable nextTable;')
569 header_txt.append('static VkBaseLayerObject *pCurObj;')
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600570 header_txt.append('')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700571 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
572 header_txt.append('static int printLockInitialized = 0;')
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600573 header_txt.append('static loader_platform_thread_mutex printLock;')
574 header_txt.append('')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700575 header_txt.append('#define MAX_TID 513')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700576 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700577 header_txt.append('static uint32_t maxTID = 0;')
578 header_txt.append('// Map actual TID to an index value and return that index')
579 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
580 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700581 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700582 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
583 header_txt.append(' if (tid == tidMapping[i])')
584 header_txt.append(' return i;')
585 header_txt.append(' }')
586 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott81ac44c2015-01-13 17:52:38 -0700587 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlis0c68c9c2014-11-24 15:46:55 -0700588 header_txt.append(' tidMapping[maxTID++] = tid;')
589 header_txt.append(' assert(maxTID < MAX_TID);')
590 header_txt.append(' return retVal;')
591 header_txt.append('}')
592 return "\n".join(header_txt)
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600593
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600594 def generate_init(self):
595 func_body = []
596 func_body.append('#include "vk_dispatch_table_helper.h"')
597 func_body.append('#include "layers_config.h"')
598 func_body.append('')
599 func_body.append('static void init%s(void)' % self.layer_name)
600 func_body.append('{')
601 func_body.append(' using namespace StreamControl;')
602 func_body.append('')
603 func_body.append(' char const*const writeToFileStr = getLayerOption("APIDumpFile");')
604 func_body.append(' bool writeToFile = false;')
605 func_body.append(' if(writeToFileStr != NULL)')
606 func_body.append(' {')
607 func_body.append(' if(strcmp(writeToFileStr, "TRUE") == 0)')
608 func_body.append(' {')
609 func_body.append(' writeToFile = true;')
610 func_body.append(' }')
611 func_body.append(' else if(strcmp(writeToFileStr, "FALSE") == 0)')
612 func_body.append(' {')
613 func_body.append(' writeToFile = false;')
614 func_body.append(' }')
615 func_body.append(' }')
616 func_body.append('')
617 func_body.append(' char const*const noAddrStr = getLayerOption("APIDumpNoAddr");')
618 func_body.append(' if(noAddrStr != NULL)')
619 func_body.append(' {')
620 func_body.append(' if(strcmp(noAddrStr, "FALSE") == 0)')
621 func_body.append(' {')
622 func_body.append(' StreamControl::writeAddress = true;')
623 func_body.append(' }')
624 func_body.append(' else if(strcmp(noAddrStr, "TRUE") == 0)')
625 func_body.append(' {')
626 func_body.append(' StreamControl::writeAddress = false;')
627 func_body.append(' }')
628 func_body.append(' }')
629 func_body.append('')
630 func_body.append(' char const*const flushAfterWriteStr = getLayerOption("APIDumpFlush");')
631 func_body.append(' bool flushAfterWrite = false;')
632 func_body.append(' if(flushAfterWriteStr != NULL)')
633 func_body.append(' {')
634 func_body.append(' if(strcmp(flushAfterWriteStr, "TRUE") == 0)')
635 func_body.append(' {')
636 func_body.append(' flushAfterWrite = true;')
637 func_body.append(' }')
638 func_body.append(' else if(strcmp(flushAfterWriteStr, "FALSE") == 0)')
639 func_body.append(' {')
640 func_body.append(' flushAfterWrite = false;')
641 func_body.append(' }')
642 func_body.append(' }')
643 func_body.append('')
644 func_body.append(' ConfigureOutputStream(writeToFile, flushAfterWrite);')
645 func_body.append('')
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600646 func_body.append(' PFN_vkGetProcAddr fpNextGPA;')
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600647 func_body.append(' fpNextGPA = pCurObj->pGPA;')
648 func_body.append(' assert(fpNextGPA);')
Tony Barbour8205d902015-04-16 15:59:00 -0600649 func_body.append(' layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);')
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600650 func_body.append('')
651 func_body.append(' if (!printLockInitialized)')
652 func_body.append(' {')
653 func_body.append(' // TODO/TBD: Need to delete this mutex sometime. How???')
654 func_body.append(' loader_platform_thread_create_mutex(&printLock);')
655 func_body.append(' printLockInitialized = 1;')
656 func_body.append(' }')
657 func_body.append('}')
658 func_body.append('')
659 return "\n".join(func_body)
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700660
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600661 def generate_intercept(self, proto, qual):
Jon Ashburneb2728b2015-04-10 14:33:07 -0600662 if proto.name in [ 'GetGlobalExtensionInfo']:
663 return None
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600664 decl = proto.c_func(prefix="vk", attr="VKAPI")
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600665 ret_val = ''
666 stmt = ''
667 funcs = []
668 sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print
669 create_params = 0 # Num of params at end of function that are created and returned as output values
670 if 'WsiX11CreatePresentableImage' in proto.name or 'AllocDescriptorSets' in proto.name:
671 create_params = -2
672 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
673 create_params = -1
674 if proto.ret != "void":
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600675 ret_val = "VkResult result = "
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600676 stmt = " return result;\n"
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600677 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
678 log_func = ' if (StreamControl::writeAddress == true) {'
679 log_func += '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name
680 log_func_no_addr = '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name
681 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600682 pindex = 0
683 prev_count_name = ''
684 for p in proto.params:
685 cp = False
686 if 0 != create_params:
687 # If this is any of the N last params of the func, treat as output
688 for y in range(-1, create_params-1, -1):
689 if p.name == proto.params[y].name:
690 cp = True
691 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True)
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600692 log_func += '%s = " << %s << ", ' % (p.name, pfi)
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600693 if "%p" == pft:
694 log_func_no_addr += '%s = address, ' % (p.name)
695 else:
696 log_func_no_addr += '%s = " << %s << ", ' % (p.name, pfi)
Tobin Ehlisc99cb0d2015-04-16 15:56:11 -0600697 if prev_count_name != '' and (prev_count_name.replace('Count', '')[1:] in p.name):
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600698 sp_param_dict[pindex] = prev_count_name
Tobin Ehlisc99cb0d2015-04-16 15:56:11 -0600699 prev_count_name = ''
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600700 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
701 sp_param_dict[pindex] = '*pCount'
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600702 elif 'Wsi' not in proto.name and vk_helper.is_type(p.ty.strip('*').replace('const ', ''), 'struct'):
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600703 sp_param_dict[pindex] = 'index'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600704 if p.name.endswith('Count'):
705 if '*' in p.ty:
706 prev_count_name = "*%s" % p.name
707 else:
708 prev_count_name = p.name
Jon Ashburneb2728b2015-04-10 14:33:07 -0600709 pindex += 1
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600710 log_func = log_func.strip(', ')
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600711 log_func_no_addr = log_func_no_addr.strip(', ')
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600712 if proto.ret != "void":
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600713 log_func += ') = " << string_VkResult((VkResult)result) << endl'
714 log_func_no_addr += ') = " << string_VkResult((VkResult)result) << endl'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600715 else:
716 log_func += ')\\n"'
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600717 log_func_no_addr += ')\\n"'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600718 log_func += ';'
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600719 log_func_no_addr += ';'
720 log_func += '\n }\n else {%s;\n }' % log_func_no_addr;
Tobin Ehlisf29da382015-04-15 07:46:12 -0600721 #print("Proto %s has param_dict: %s" % (proto.name, sp_param_dict))
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600722 if len(sp_param_dict) > 0:
723 i_decl = False
724 log_func += '\n string tmp_str;'
725 for sp_index in sp_param_dict:
Tobin Ehlisf29da382015-04-15 07:46:12 -0600726 #print("sp_index: %s" % str(sp_index))
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600727 if 'index' == sp_param_dict[sp_index]:
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600728 cis_print_func = 'vk_print_%s' % (proto.params[sp_index].ty.replace('const ', '').strip('*').lower())
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600729 local_name = proto.params[sp_index].name
730 if '*' not in proto.params[sp_index].ty:
731 local_name = '&%s' % proto.params[sp_index].name
732 log_func += '\n if (%s) {' % (local_name)
733 log_func += '\n tmp_str = %s(%s, " ");' % (cis_print_func, local_name)
734 log_func += '\n (*outputStream) << " %s (" << %s << ")" << endl << tmp_str << endl;' % (local_name, local_name)
735 log_func += '\n }'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600736 else: # We have a count value stored to iterate over an array
737 print_cast = ''
738 print_func = ''
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600739 if vk_helper.is_type(proto.params[sp_index].ty.strip('*').replace('const ', ''), 'struct'):
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600740 print_cast = '&'
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600741 print_func = 'vk_print_%s' % proto.params[sp_index].ty.replace('const ', '').strip('*').lower()
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600742 else:
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600743 print_cast = ''
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600744 print_func = 'string_convert_helper'
745 #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name
746 cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name)
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600747 if not i_decl:
748 log_func += '\n uint32_t i;'
749 i_decl = True
750 log_func += '\n for (i = 0; i < %s; i++) {' % (sp_param_dict[sp_index])
751 log_func += '\n %s' % (cis_print_func)
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600752 log_func += '\n (*outputStream) << " %s[" << i << "] (" << %s%s[i] << ")" << endl << tmp_str << endl;' % (proto.params[sp_index].name, '&', proto.params[sp_index].name)
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600753 log_func += '\n }'
754 if 'WsiX11AssociateConnection' == proto.name:
755 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
756 if proto.name == "EnumerateLayers":
Tony Barbour8205d902015-04-16 15:59:00 -0600757 c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalDevice)gpuw->nextObject", 1)
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600758 funcs.append('%s%s\n'
759 '{\n'
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600760 ' using namespace StreamControl;\n'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600761 ' if (gpu != NULL) {\n'
Jon Ashburn630e44f2015-04-08 21:33:34 -0600762 ' pCurObj = (VkBaseLayerObject *) gpu;\n'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600763 ' loader_platform_thread_once(&tabOnce, init%s);\n'
764 ' %snextTable.%s;\n'
765 ' %s %s %s\n'
766 ' %s'
767 ' } else {\n'
768 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600769 ' return VK_ERROR_INVALID_POINTER;\n'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600770 ' // This layer compatible with all GPUs\n'
771 ' *pOutLayerCount = 1;\n'
772 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600773 ' return VK_SUCCESS;\n'
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600774 ' }\n'
Jon Ashburn630e44f2015-04-08 21:33:34 -0600775 '}' % (qual, decl, self.layer_name, ret_val, proto.c_call(),f_open, log_func, f_close, stmt, self.layer_name))
Tony Barbour8205d902015-04-16 15:59:00 -0600776 elif 'GetExtensionSupport' == proto.name:
777 funcs.append('%s%s\n'
778 '{\n'
779 ' VkResult result;\n'
780 ' /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */\n'
781 ' if (!strncmp(pExtName, "%s", strlen("%s")))\n'
782 ' {\n'
783 ' result = VK_SUCCESS;\n'
784 ' } else if (nextTable.GetExtensionSupport != NULL)\n'
785 ' {\n'
786 ' result = nextTable.%s;\n'
787 ' %s %s %s\n'
788 ' } else\n'
789 ' {\n'
790 ' result = VK_ERROR_INVALID_EXTENSION;\n'
791 ' }\n'
792 '%s'
793 '}' % (qual, decl, self.layer_name, self.layer_name, proto.c_call(), f_open, log_func, f_close, stmt))
794# elif 'vkphysicalgpu' == proto.params[0].ty.lower():
795# c_call = proto.c_call().replace("(" + proto.params[0].name, "((VkPhysicalDevice)gpuw->nextObject", 1)
796# funcs.append('%s%s\n'
797# '{\n'
798# ' using namespace StreamControl;\n'
799# ' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) %s;\n'
800# ' pCurObj = gpuw;\n'
801# ' loader_platform_thread_once(&tabOnce, init%s);\n'
802# ' %snextTable.%s;\n'
803# ' %s%s%s\n'
804# '%s'
805# '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, c_call, f_open, log_func, f_close, stmt))
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600806 else:
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600807 funcs.append('%s%s\n'
808 '{\n'
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600809 ' using namespace StreamControl;\n'
Jon Ashburn301c5f02015-04-06 10:58:22 -0600810 ' %snextTable.%s;\n'
811 ' %s%s%s\n'
812 '%s'
813 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
Mike Stroyan2ad66f12015-04-03 17:45:53 -0600814 if 'WsiX11QueuePresent' == proto.name:
815 funcs.append("#endif")
816 return "\n\n".join(funcs)
817
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700818 def generate_body(self):
Tobin Ehlis4a636a12015-04-09 09:19:36 -0600819 self.layer_name = "APIDump"
820 body = [self.generate_init(),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600821 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
Mike Stroyan3aecdb42015-04-03 17:13:23 -0600822 self._generate_layer_gpa_function()]
Tobin Ehlis434db7c2015-01-10 12:42:41 -0700823 return "\n\n".join(body)
824
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600825class ObjectTrackerSubcommand(Subcommand):
826 def generate_header(self):
827 header_txt = []
Ian Elliott81ac44c2015-01-13 17:52:38 -0700828 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include "loader_platform.h"')
Jon Ashburn301c5f02015-04-06 10:58:22 -0600829 header_txt.append('#include "object_track.h"\n\nstatic VkLayerDispatchTable nextTable;\nstatic VkBaseLayerObject *pCurObj;')
Ian Elliott20f06872015-02-12 17:08:34 -0700830 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
831 header_txt.append('#include "loader_platform.h"')
Jon Ashburn7a2da4f2015-02-17 11:03:12 -0700832 header_txt.append('#include "layers_config.h"')
Jon Ashburn21001f62015-02-16 08:26:50 -0700833 header_txt.append('#include "layers_msg.h"')
Ian Elliott81ac44c2015-01-13 17:52:38 -0700834 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
835 header_txt.append('static long long unsigned int object_track_index = 0;')
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -0700836 header_txt.append('static int objLockInitialized = 0;')
837 header_txt.append('static loader_platform_thread_mutex objLock;')
Jon Ashburn21001f62015-02-16 08:26:50 -0700838 header_txt.append('')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700839 header_txt.append('// We maintain a "Global" list which links every object and a')
840 header_txt.append('// per-Object list which just links objects of a given type')
841 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
842 header_txt.append('typedef struct _objNode {')
843 header_txt.append(' OBJTRACK_NODE obj;')
844 header_txt.append(' struct _objNode *pNextObj;')
845 header_txt.append(' struct _objNode *pNextGlobal;')
846 header_txt.append('} objNode;')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -0500847 header_txt.append('')
848 header_txt.append('static objNode *pObjectHead[VkNumObjectType] = {0};')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700849 header_txt.append('static objNode *pGlobalHead = NULL;')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -0500850 header_txt.append('static uint64_t numObjs[VkNumObjectType] = {0};')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700851 header_txt.append('static uint64_t numTotalObjs = 0;')
Courtney Goeltzenleuchter304a1f82015-04-07 16:23:00 -0600852 header_txt.append('static uint32_t maxMemReferences = 0;')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -0500853 header_txt.append('')
854 header_txt.append('// For each Queue\'s doubly linked-list of mem refs')
855 header_txt.append('typedef struct _OT_MEM_INFO {')
Tony Barbour8205d902015-04-16 15:59:00 -0600856 header_txt.append(' VkDeviceMemory mem;')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -0500857 header_txt.append(' struct _OT_MEM_INFO *pNextMI;')
858 header_txt.append(' struct _OT_MEM_INFO *pPrevMI;')
859 header_txt.append('')
860 header_txt.append('} OT_MEM_INFO;')
861 header_txt.append('')
862 header_txt.append('// Track Queue information')
863 header_txt.append('typedef struct _OT_QUEUE_INFO {')
864 header_txt.append(' OT_MEM_INFO *pMemRefList;')
865 header_txt.append(' struct _OT_QUEUE_INFO *pNextQI;')
866 header_txt.append(' VkQueue queue;')
867 header_txt.append(' uint32_t refCount;')
868 header_txt.append('} OT_QUEUE_INFO;')
869 header_txt.append('')
870 header_txt.append('// Global list of QueueInfo structures, one per queue')
871 header_txt.append('static OT_QUEUE_INFO *g_pQueueInfo;')
872 header_txt.append('')
873 header_txt.append('// Add new queue to head of global queue list')
874 header_txt.append('static void addQueueInfo(VkQueue queue)')
875 header_txt.append('{')
876 header_txt.append(' OT_QUEUE_INFO *pQueueInfo = malloc(sizeof(OT_QUEUE_INFO));')
877 header_txt.append(' memset(pQueueInfo, 0, sizeof(OT_QUEUE_INFO));')
878 header_txt.append(' pQueueInfo->queue = queue;')
879 header_txt.append('')
880 header_txt.append(' if (pQueueInfo != NULL) {')
881 header_txt.append(' pQueueInfo->pNextQI = g_pQueueInfo;')
882 header_txt.append(' g_pQueueInfo = pQueueInfo;')
883 header_txt.append(' }')
884 header_txt.append(' else {')
885 header_txt.append(' char str[1024];')
Tony Barbour8205d902015-04-16 15:59:00 -0600886 header_txt.append(' sprintf(str, "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -0500887 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
888 header_txt.append(' }')
889 header_txt.append('}')
890 header_txt.append('')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -0500891 header_txt.append('// Destroy memRef lists and free all memory')
892 header_txt.append('static void destroyQueueMemRefLists()')
893 header_txt.append('{')
894 header_txt.append(' OT_QUEUE_INFO *pQueueInfo = g_pQueueInfo;')
895 header_txt.append(' OT_QUEUE_INFO *pDelQueueInfo = NULL;')
896 header_txt.append(' while (pQueueInfo != NULL) {')
897 header_txt.append(' OT_MEM_INFO *pMemInfo = pQueueInfo->pMemRefList;')
898 header_txt.append(' while (pMemInfo != NULL) {')
899 header_txt.append(' OT_MEM_INFO *pDelMemInfo = pMemInfo;')
900 header_txt.append(' pMemInfo = pMemInfo->pNextMI;')
901 header_txt.append(' free(pDelMemInfo);')
902 header_txt.append(' }')
903 header_txt.append(' pDelQueueInfo = pQueueInfo;')
904 header_txt.append(' pQueueInfo = pQueueInfo->pNextQI;')
905 header_txt.append(' free(pDelQueueInfo);')
906 header_txt.append(' }')
907 header_txt.append('}')
908 header_txt.append('')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700909 header_txt.append('// Debug function to print global list and each individual object list')
910 header_txt.append('static void ll_print_lists()')
911 header_txt.append('{')
912 header_txt.append(' objNode* pTrav = pGlobalHead;')
913 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
914 header_txt.append(' while (pTrav) {')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600915 header_txt.append(' printf(" ObjNode (%p) w/ %s obj %p has pNextGlobal %p\\n", (void*)pTrav, string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, (void*)pTrav->pNextGlobal);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700916 header_txt.append(' pTrav = pTrav->pNextGlobal;')
917 header_txt.append(' }')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -0500918 header_txt.append(' for (uint32_t i = 0; i < VkNumObjectType; i++) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700919 header_txt.append(' pTrav = pObjectHead[i];')
920 header_txt.append(' if (pTrav) {')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600921 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_VK_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700922 header_txt.append(' while (pTrav) {')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600923 header_txt.append(' printf(" ObjNode (%p) w/ %s obj %p has pNextObj %p\\n", (void*)pTrav, string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, (void*)pTrav->pNextObj);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700924 header_txt.append(' pTrav = pTrav->pNextObj;')
925 header_txt.append(' }')
926 header_txt.append(' }')
927 header_txt.append(' }')
928 header_txt.append('}')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600929 header_txt.append('static void ll_insert_obj(void* pObj, VK_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700930 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600931 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object %p", object_track_index++, string_VK_OBJECT_TYPE(objType), (void*)pObj);')
932 header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700933 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
934 header_txt.append(' pNewObjNode->obj.pObj = pObj;')
935 header_txt.append(' pNewObjNode->obj.objType = objType;')
Mark Lobodzinski01552702015-02-03 10:06:31 -0600936 header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700937 header_txt.append(' pNewObjNode->obj.numUses = 0;')
938 header_txt.append(' // insert at front of global list')
939 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
940 header_txt.append(' pGlobalHead = pNewObjNode;')
941 header_txt.append(' // insert at front of object list')
942 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
943 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
944 header_txt.append(' // increment obj counts')
945 header_txt.append(' numObjs[objType]++;')
946 header_txt.append(' numTotalObjs++;')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600947 header_txt.append(' //sprintf(str, "OBJ_STAT : %lu total objs & %lu %s objs.", numTotalObjs, numObjs[objType], string_VK_OBJECT_TYPE(objType));')
Chia-I Wudf142a32014-12-16 11:02:06 +0800948 header_txt.append(' if (0) ll_print_lists();')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700949 header_txt.append('}')
950 header_txt.append('// Traverse global list and return type for given object')
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600951 header_txt.append('static VK_OBJECT_TYPE ll_get_obj_type(VkObject object) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700952 header_txt.append(' objNode *pTrav = pGlobalHead;')
953 header_txt.append(' while (pTrav) {')
954 header_txt.append(' if (pTrav->obj.pObj == object)')
955 header_txt.append(' return pTrav->obj.objType;')
956 header_txt.append(' pTrav = pTrav->pNextGlobal;')
957 header_txt.append(' }')
958 header_txt.append(' char str[1024];')
959 header_txt.append(' sprintf(str, "Attempting look-up on obj %p but it is NOT in the global list!", (void*)object);')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600960 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, OBJTRACK_MISSING_OBJECT, "OBJTRACK", str);')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -0500961 header_txt.append(' return VkObjectTypeUnknown;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700962 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +0800963 header_txt.append('#if 0')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600964 header_txt.append('static uint64_t ll_get_obj_uses(void* pObj, VK_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700965 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
966 header_txt.append(' while (pTrav) {')
967 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
968 header_txt.append(' return pTrav->obj.numUses;')
969 header_txt.append(' }')
970 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600971 header_txt.append(' }')
972 header_txt.append(' return 0;')
973 header_txt.append('}')
Chia-I Wudf142a32014-12-16 11:02:06 +0800974 header_txt.append('#endif')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600975 header_txt.append('static void ll_increment_use_count(void* pObj, VK_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700976 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis92dbf802014-10-22 09:06:33 -0600977 header_txt.append(' while (pTrav) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700978 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
979 header_txt.append(' pTrav->obj.numUses++;')
980 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600981 header_txt.append(' sprintf(str, "OBJ[%llu] : USING %s object %p (%lu total uses)", object_track_index++, string_VK_OBJECT_TYPE(objType), (void*)pObj, pTrav->obj.numUses);')
982 header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700983 header_txt.append(' return;')
984 header_txt.append(' }')
985 header_txt.append(' pTrav = pTrav->pNextObj;')
986 header_txt.append(' }')
987 header_txt.append(' // If we do not find obj, insert it and then increment count')
988 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600989 header_txt.append(' sprintf(str, "Unable to increment count for obj %p, will add to list as %s type and increment count", pObj, string_VK_OBJECT_TYPE(objType));')
990 header_txt.append(' layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700991 header_txt.append('')
992 header_txt.append(' ll_insert_obj(pObj, objType);')
993 header_txt.append(' ll_increment_use_count(pObj, objType);')
994 header_txt.append('}')
995 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
996 header_txt.append('// Type from global list w/ ll_destroy_obj()')
997 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600998 header_txt.append('static void ll_remove_obj_type(void* pObj, VK_OBJECT_TYPE objType) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -0700999 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1000 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
1001 header_txt.append(' while (pTrav) {')
1002 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1003 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
1004 header_txt.append(' // update HEAD of Obj list as needed')
1005 header_txt.append(' if (pObjectHead[objType] == pTrav)')
1006 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
1007 header_txt.append(' assert(numObjs[objType] > 0);')
1008 header_txt.append(' numObjs[objType]--;')
1009 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001010 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object %p", object_track_index++, string_VK_OBJECT_TYPE(objType), (void*)pObj);')
1011 header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001012 header_txt.append(' return;')
1013 header_txt.append(' }')
1014 header_txt.append(' pPrev = pTrav;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001015 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001016 header_txt.append(' }')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001017 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001018 header_txt.append(' sprintf(str, "OBJ INTERNAL ERROR : Obj %p was in global list but not in %s list", pObj, string_VK_OBJECT_TYPE(objType));')
1019 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001020 header_txt.append('}')
1021 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
1022 header_txt.append('// remove obj from global list')
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001023 header_txt.append('static void ll_destroy_obj(void* pObj) {')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001024 header_txt.append(' objNode *pTrav = pGlobalHead;')
1025 header_txt.append(' objNode *pPrev = pGlobalHead;')
1026 header_txt.append(' while (pTrav) {')
1027 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1028 header_txt.append(' ll_remove_obj_type(pObj, pTrav->obj.objType);')
1029 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
1030 header_txt.append(' // update HEAD of global list if needed')
1031 header_txt.append(' if (pGlobalHead == pTrav)')
1032 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001033 header_txt.append(' assert(numTotalObjs > 0);')
1034 header_txt.append(' numTotalObjs--;')
1035 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001036 header_txt.append(' sprintf(str, "OBJ_STAT Removed %s obj %p that was used %lu times (%lu total objs remain & %lu %s objs).", string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, pTrav->obj.numUses, numTotalObjs, numObjs[pTrav->obj.objType], string_VK_OBJECT_TYPE(pTrav->obj.objType));')
1037 header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis84a8a9b2015-02-23 14:09:16 -07001038 header_txt.append(' free(pTrav);')
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001039 header_txt.append(' return;')
1040 header_txt.append(' }')
1041 header_txt.append(' pPrev = pTrav;')
1042 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1043 header_txt.append(' }')
1044 header_txt.append(' char str[1024];')
1045 header_txt.append(' sprintf(str, "Unable to remove obj %p. Was it created? Has it already been destroyed?", pObj);')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001046 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_DESTROY_OBJECT_FAILED, "OBJTRACK", str);')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001047 header_txt.append('}')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001048 header_txt.append('// Set selected flag state for an object node')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001049 header_txt.append('static void set_status(void* pObj, VK_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001050 header_txt.append(' if (pObj != NULL) {')
1051 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1052 header_txt.append(' while (pTrav) {')
1053 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
1054 header_txt.append(' pTrav->obj.status |= status_flag;')
1055 header_txt.append(' return;')
1056 header_txt.append(' }')
1057 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001058 header_txt.append(' }')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001059 header_txt.append(' // If we do not find it print an error')
1060 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001061 header_txt.append(' sprintf(str, "Unable to set status for non-existent object %p of %s type", pObj, string_VK_OBJECT_TYPE(objType));')
1062 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Mark Lobodzinskid11fcca2015-02-09 10:16:20 -06001063 header_txt.append(' }');
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001064 header_txt.append('}')
1065 header_txt.append('')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001066 header_txt.append('// Track selected state for an object node')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -05001067 header_txt.append('static void track_object_status(void* pObj, VkStateBindPoint stateBindPoint) {')
1068 header_txt.append(' objNode *pTrav = pObjectHead[VkObjectTypeCmdBuffer];')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001069 header_txt.append('')
1070 header_txt.append(' while (pTrav) {')
1071 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Tony Barbour8205d902015-04-16 15:59:00 -06001072 header_txt.append(' if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001073 header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;')
Tony Barbour8205d902015-04-16 15:59:00 -06001074 header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001075 header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;')
Tony Barbour8205d902015-04-16 15:59:00 -06001076 header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001077 header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;')
Tony Barbour8205d902015-04-16 15:59:00 -06001078 header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001079 header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;')
1080 header_txt.append(' }')
1081 header_txt.append(' return;')
1082 header_txt.append(' }')
1083 header_txt.append(' pTrav = pTrav->pNextObj;')
1084 header_txt.append(' }')
1085 header_txt.append(' // If we do not find it print an error')
1086 header_txt.append(' char str[1024];')
1087 header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object %p", pObj);')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001088 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001089 header_txt.append('}')
1090 header_txt.append('')
1091 header_txt.append('// Reset selected flag state for an object node')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001092 header_txt.append('static void reset_status(void* pObj, VK_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001093 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1094 header_txt.append(' while (pTrav) {')
1095 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001096 header_txt.append(' pTrav->obj.status &= ~status_flag;')
1097 header_txt.append(' return;')
1098 header_txt.append(' }')
1099 header_txt.append(' pTrav = pTrav->pNextObj;')
1100 header_txt.append(' }')
1101 header_txt.append(' // If we do not find it print an error')
1102 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001103 header_txt.append(' sprintf(str, "Unable to reset status for non-existent object %p of %s type", pObj, string_VK_OBJECT_TYPE(objType));')
1104 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001105 header_txt.append('}')
1106 header_txt.append('')
1107 header_txt.append('// Check object status for selected flag state')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001108 header_txt.append('static bool32_t validate_status(void* pObj, 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 Lobodzinski01552702015-02-03 10:06:31 -06001109 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1110 header_txt.append(' while (pTrav) {')
1111 header_txt.append(' if (pTrav->obj.pObj == pObj) {')
Mark Lobodzinski4186e712015-02-03 11:52:26 -06001112 header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001113 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001114 header_txt.append(' sprintf(str, "OBJECT VALIDATION WARNING: %s object %p: %s", string_VK_OBJECT_TYPE(objType), (void*)pObj, fail_msg);')
1115 header_txt.append(' layerCbMsg(error_level, VK_VALIDATION_LEVEL_0, pObj, 0, error_code, "OBJTRACK", str);')
1116 header_txt.append(' return VK_FALSE;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001117 header_txt.append(' }')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001118 header_txt.append(' return VK_TRUE;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001119 header_txt.append(' }')
1120 header_txt.append(' pTrav = pTrav->pNextObj;')
1121 header_txt.append(' }')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -05001122 header_txt.append(' if (objType != VkObjectTypePresentableImageMemory) {')
Mark Lobodzinskiacb93682015-03-05 12:39:33 -06001123 header_txt.append(' // If we do not find it print an error')
1124 header_txt.append(' char str[1024];')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001125 header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object %p of %s type", pObj, string_VK_OBJECT_TYPE(objType));')
1126 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Mark Lobodzinskiacb93682015-03-05 12:39:33 -06001127 header_txt.append(' }')
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001128 header_txt.append(' return VK_FALSE;')
Tobin Ehlis235c20e2015-01-16 08:56:30 -07001129 header_txt.append('}')
Mark Lobodzinski01552702015-02-03 10:06:31 -06001130 header_txt.append('')
1131 header_txt.append('static void validate_draw_state_flags(void* pObj) {')
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -05001132 header_txt.append(' validate_status((void*)pObj, VkObjectTypeCmdBuffer, OBJSTATUS_VIEWPORT_BOUND, OBJSTATUS_VIEWPORT_BOUND, VK_DBG_MSG_ERROR, OBJTRACK_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");')
1133 header_txt.append(' validate_status((void*)pObj, VkObjectTypeCmdBuffer, OBJSTATUS_RASTER_BOUND, OBJSTATUS_RASTER_BOUND, VK_DBG_MSG_ERROR, OBJTRACK_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");')
1134 header_txt.append(' validate_status((void*)pObj, 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");')
1135 header_txt.append(' validate_status((void*)pObj, 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");')
1136 header_txt.append('}')
1137 header_txt.append('')
Courtney Goeltzenleuchter304a1f82015-04-07 16:23:00 -06001138 header_txt.append('static void setGpuQueueInfoState(void *pData) {')
Tony Barbour8205d902015-04-16 15:59:00 -06001139 header_txt.append(' maxMemReferences = ((VkPhysicalDeviceQueueProperties *)pData)->maxMemReferences;')
Mark Lobodzinskie1d3f0c2015-02-09 10:20:53 -06001140 header_txt.append('}')
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001141 return "\n".join(header_txt)
1142
Mike Stroyan3aecdb42015-04-03 17:13:23 -06001143 def generate_intercept(self, proto, qual):
Jon Ashburneb2728b2015-04-10 14:33:07 -06001144 if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback', 'GetGlobalExtensionInfo' ]:
Mike Stroyan723913e2015-04-03 14:39:16 -06001145 # use default version
1146 return None
Tobin Ehlisf29da382015-04-15 07:46:12 -06001147 obj_type_mapping = {base_t : base_t.replace("Vk", "VkObjectType") for base_t in vulkan.object_type_list}
Mike Stroyan723913e2015-04-03 14:39:16 -06001148 # For the various "super-types" we have to use function to distinguish sub type
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001149 for obj_type in ["VK_BASE_OBJECT", "VK_OBJECT", "VK_DYNAMIC_STATE_OBJECT", "VkObject", "VkBaseObject"]:
Mike Stroyan723913e2015-04-03 14:39:16 -06001150 obj_type_mapping[obj_type] = "ll_get_obj_type(object)"
1151
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001152 decl = proto.c_func(prefix="vk", attr="VKAPI")
Mike Stroyan723913e2015-04-03 14:39:16 -06001153 param0_name = proto.params[0].name
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001154 p0_type = proto.params[0].ty.strip('*').replace('const ', '')
Mike Stroyan723913e2015-04-03 14:39:16 -06001155 create_line = ''
1156 destroy_line = ''
1157 funcs = []
1158 # Special cases for API funcs that don't use an object as first arg
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06001159 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', 'WsiX11QueuePresent']]:
Mike Stroyan723913e2015-04-03 14:39:16 -06001160 using_line = ''
1161 else:
1162 using_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
1163 using_line += ' ll_increment_use_count((void*)%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
1164 using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1165 if 'QueueSubmit' in proto.name:
Tobin Ehlisf29da382015-04-15 07:46:12 -06001166 using_line += ' set_status((void*)fence, VkObjectTypeFence, OBJSTATUS_FENCE_IS_SUBMITTED);\n'
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -06001167 using_line += ' // TODO: Fix for updated memory reference mechanism\n'
1168 using_line += ' // validate_memory_mapping_status(pMemRefs, memRefCount);\n'
1169 using_line += ' // validate_mem_ref_count(memRefCount);\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001170 elif 'GetFenceStatus' in proto.name:
1171 using_line += ' // Warn if submitted_flag is not set\n'
Tobin Ehlisf29da382015-04-15 07:46:12 -06001172 using_line += ' validate_status((void*)fence, VkObjectTypeFence, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, VK_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001173 elif 'EndCommandBuffer' in proto.name:
Tobin Ehlisf29da382015-04-15 07:46:12 -06001174 using_line += ' reset_status((void*)cmdBuffer, VkObjectTypeCmdBuffer, (OBJSTATUS_VIEWPORT_BOUND |\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001175 using_line += ' OBJSTATUS_RASTER_BOUND |\n'
1176 using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n'
1177 using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n'
1178 elif 'CmdBindDynamicStateObject' in proto.name:
1179 using_line += ' track_object_status((void*)cmdBuffer, stateBindPoint);\n'
1180 elif 'CmdDraw' in proto.name:
1181 using_line += ' validate_draw_state_flags((void *)cmdBuffer);\n'
1182 elif 'MapMemory' in proto.name:
Tony Barbour8205d902015-04-16 15:59:00 -06001183 using_line += ' set_status((void*)mem, VkObjectTypeDeviceMemory, OBJSTATUS_GPU_MEM_MAPPED);\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001184 elif 'UnmapMemory' in proto.name:
Tony Barbour8205d902015-04-16 15:59:00 -06001185 using_line += ' reset_status((void*)mem, VkObjectTypeDeviceMemory, OBJSTATUS_GPU_MEM_MAPPED);\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001186 if 'AllocDescriptor' in proto.name: # Allocates array of DSs
1187 create_line = ' for (uint32_t i = 0; i < *pCount; i++) {\n'
1188 create_line += ' loader_platform_thread_lock_mutex(&objLock);\n'
Tobin Ehlisf29da382015-04-15 07:46:12 -06001189 create_line += ' ll_insert_obj((void*)pDescriptorSets[i], VkObjectTypeDescriptorSet);\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001190 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1191 create_line += ' }\n'
1192 elif 'CreatePresentableImage' in proto.name:
1193 create_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001194 create_line += ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-2].name, obj_type_mapping[proto.params[-2].ty.strip('*').replace('const ', '')])
Tobin Ehlisf29da382015-04-15 07:46:12 -06001195 create_line += ' ll_insert_obj((void*)*pMem, VkObjectTypePresentableImageMemory);\n'
Tobin Ehlis293ff632015-04-15 13:20:56 -06001196
Mike Stroyan723913e2015-04-03 14:39:16 -06001197 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1198 elif 'Create' in proto.name or 'Alloc' in proto.name:
1199 create_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001200 create_line += ' ll_insert_obj((void*)*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').replace('const ', '')])
Mike Stroyan723913e2015-04-03 14:39:16 -06001201 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1202 if 'DestroyObject' in proto.name:
1203 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
1204 destroy_line += ' ll_destroy_obj((void*)%s);\n' % (param0_name)
1205 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1206 using_line = ''
1207 else:
1208 if 'Destroy' in proto.name or 'Free' in proto.name:
1209 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
1210 destroy_line += ' ll_destroy_obj((void*)%s);\n' % (param0_name)
1211 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1212 using_line = ''
1213 if 'DestroyDevice' in proto.name:
1214 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
Tobin Ehlisf29da382015-04-15 07:46:12 -06001215 destroy_line += ' if (pTrav->obj.objType == VkObjectTypePresentableImageMemory) {\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001216 destroy_line += ' objNode *pDel = pTrav;\n'
1217 destroy_line += ' pTrav = pTrav->pNextGlobal;\n'
1218 destroy_line += ' ll_destroy_obj((void*)(pDel->obj.pObj));\n'
1219 destroy_line += ' } else {\n'
1220 destroy_line += ' char str[1024];\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001221 destroy_line += ' sprintf(str, "OBJ ERROR : %s object %p has not been destroyed (was used %lu times).", string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.pObj, pTrav->obj.numUses);\n'
1222 destroy_line += ' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001223 destroy_line += ' pTrav = pTrav->pNextGlobal;\n'
1224 destroy_line += ' }\n'
1225 destroy_line += ' }\n'
Mark Lobodzinski93fdbd22015-04-09 12:09:45 -05001226 destroy_line += ' // Clean up Queue\'s MemRef Linked Lists\n'
1227 destroy_line += ' destroyQueueMemRefLists();\n'
1228 if 'GetDeviceQueue' in proto.name:
1229 destroy_line = ' addQueueInfo(*pQueue);\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001230 ret_val = ''
1231 stmt = ''
1232 if proto.ret != "void":
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001233 ret_val = "VkResult result = "
Mike Stroyan723913e2015-04-03 14:39:16 -06001234 stmt = " return result;\n"
1235 if 'WsiX11AssociateConnection' == proto.name:
1236 funcs.append("#if defined(__linux__) || defined(XCB_NVIDIA)")
1237 if proto.name == "EnumerateLayers":
Mike Stroyan723913e2015-04-03 14:39:16 -06001238 funcs.append('%s%s\n'
1239 '{\n'
1240 ' if (gpu != NULL) {\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001241 ' %s'
Jon Ashburn630e44f2015-04-08 21:33:34 -06001242 ' pCurObj = (VkBaseLayerObject *) gpu;\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001243 ' loader_platform_thread_once(&tabOnce, init%s);\n'
1244 ' %snextTable.%s;\n'
1245 ' %s%s'
1246 ' %s'
1247 ' } else {\n'
1248 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001249 ' return VK_ERROR_INVALID_POINTER;\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001250 ' // This layer compatible with all GPUs\n'
1251 ' *pOutLayerCount = 1;\n'
1252 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001253 ' return VK_SUCCESS;\n'
Mike Stroyan723913e2015-04-03 14:39:16 -06001254 ' }\n'
Jon Ashburn630e44f2015-04-08 21:33:34 -06001255 '}' % (qual, decl, using_line, self.layer_name, ret_val, proto.c_call(), create_line, destroy_line, stmt, self.layer_name))
Tony Barbour8205d902015-04-16 15:59:00 -06001256 elif 'GetExtensionSupport' == proto.name:
1257 funcs.append('%s%s\n'
1258 '{\n'
1259 ' VkResult result;\n'
1260 ' /* This entrypoint is NOT going to init its own dispatch table since loader calls this early */\n'
1261 ' if (!strncmp(pExtName, "%s", strlen("%s")) ||\n'
1262 ' !strncmp(pExtName, "objTrackGetObjectCount", strlen("objTrackGetObjectCount")) ||\n'
1263 ' !strncmp(pExtName, "objTrackGetObjects", strlen("objTrackGetObjects")))\n'
1264 ' {\n'
1265 ' result = VK_SUCCESS;\n'
1266 ' } else if (nextTable.GetExtensionSupport != NULL)\n'
1267 ' {\n'
1268 ' %s'
1269 ' result = nextTable.%s;\n'
1270 ' } else\n'
1271 ' {\n'
1272 ' result = VK_ERROR_INVALID_EXTENSION;\n'
1273 ' }\n'
1274 '%s'
1275 '}' % (qual, decl, self.layer_name, self.layer_name, using_line, proto.c_call(), stmt))
1276 elif 'GetPhysicalDeviceInfo' in proto.name:
1277 gpu_state = ' if (infoType == VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES) {\n'
Jon Ashburn630e44f2015-04-08 21:33:34 -06001278 gpu_state += ' if (pData != NULL) {\n'
1279 gpu_state += ' setGpuQueueInfoState(pData);\n'
1280 gpu_state += ' }\n'
1281 gpu_state += ' }\n'
1282 funcs.append('%s%s\n'
1283 '{\n'
1284 '%s'
1285 ' pCurObj = (VkBaseLayerObject *) gpu;\n'
1286 ' loader_platform_thread_once(&tabOnce, init%s);\n'
1287 ' %snextTable.%s;\n'
1288 '%s%s'
1289 '%s'
1290 '%s'
1291 '}' % (qual, decl, using_line, self.layer_name, ret_val, proto.c_call(), create_line, destroy_line, gpu_state, stmt))
1292 else:
Mike Stroyan723913e2015-04-03 14:39:16 -06001293 funcs.append('%s%s\n'
1294 '{\n'
1295 '%s'
1296 ' %snextTable.%s;\n'
1297 '%s%s'
1298 '%s'
1299 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
Mike Stroyan723913e2015-04-03 14:39:16 -06001300 if 'WsiX11QueuePresent' == proto.name:
1301 funcs.append("#endif")
1302 return "\n\n".join(funcs)
1303
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001304 def generate_body(self):
Mike Stroyan3aecdb42015-04-03 17:13:23 -06001305 self.layer_name = "ObjectTracker"
1306 body = [self._generate_layer_initialization(True, lockname='obj'),
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001307 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
Tobin Ehlis3c26a542014-11-18 11:28:33 -07001308 self._generate_extensions(),
Mike Stroyan2ad66f12015-04-03 17:45:53 -06001309 self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001310
1311 return "\n\n".join(body)
Courtney Goeltzenleuchtere6094fc2014-11-18 10:40:29 -07001312
Mike Stroyanb326d2c2015-04-02 11:59:05 -06001313class ThreadingSubcommand(Subcommand):
1314 def generate_header(self):
1315 header_txt = []
1316 header_txt.append('#include <stdio.h>')
1317 header_txt.append('#include <stdlib.h>')
1318 header_txt.append('#include <string.h>')
1319 header_txt.append('#include <unordered_map>')
1320 header_txt.append('#include "loader_platform.h"')
1321 header_txt.append('#include "vkLayer.h"')
1322 header_txt.append('#include "threading.h"')
1323 header_txt.append('#include "layers_config.h"')
1324 header_txt.append('#include "vk_enum_validate_helper.h"')
1325 header_txt.append('#include "vk_struct_validate_helper.h"')
1326 header_txt.append('//The following is #included again to catch certain OS-specific functions being used:')
1327 header_txt.append('#include "loader_platform.h"\n')
1328 header_txt.append('#include "layers_msg.h"\n')
1329 header_txt.append('static VkLayerDispatchTable nextTable;')
1330 header_txt.append('static VkBaseLayerObject *pCurObj;')
1331 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n')
1332 header_txt.append('using namespace std;')
1333 header_txt.append('static unordered_map<int, void*> proxy_objectsInUse;\n')
1334 header_txt.append('static unordered_map<VkObject, loader_platform_thread_id> objectsInUse;\n')
1335 header_txt.append('static int threadingLockInitialized = 0;')
1336 header_txt.append('static loader_platform_thread_mutex threadingLock;')
1337 header_txt.append('static int printLockInitialized = 0;')
1338 header_txt.append('static loader_platform_thread_mutex printLock;\n')
1339 header_txt.append('')
1340 header_txt.append('static void useObject(VkObject object, const char* type)')
1341 header_txt.append('{')
1342 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
1343 header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);')
1344 header_txt.append(' if (objectsInUse.find(object) == objectsInUse.end()) {')
1345 header_txt.append(' objectsInUse[object] = tid;')
1346 header_txt.append(' } else {')
1347 header_txt.append(' if (objectsInUse[object] == tid) {')
1348 header_txt.append(' char str[1024];')
1349 header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is simultaneously used in thread %ld and thread %ld", type, objectsInUse[object], tid);')
1350 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING", str);')
1351 header_txt.append(' } else {')
1352 header_txt.append(' char str[1024];')
1353 header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is recursively used in thread %ld", type, tid);')
1354 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, THREADING_CHECKER_SINGLE_THREAD_REUSE, "THREADING", str);')
1355 header_txt.append(' }')
1356 header_txt.append(' }')
1357 header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);')
1358 header_txt.append('}')
1359 header_txt.append('static void finishUsingObject(VkObject object)')
1360 header_txt.append('{')
1361 header_txt.append(' // Object is no longer in use')
1362 header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);')
1363 header_txt.append(' objectsInUse.erase(object);')
1364 header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);')
1365 header_txt.append('}')
1366 return "\n".join(header_txt)
1367
1368 def generate_intercept(self, proto, qual):
1369 if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback' ]:
1370 # use default version
1371 return None
1372 decl = proto.c_func(prefix="vk", attr="VKAPI")
1373 ret_val = ''
1374 stmt = ''
1375 funcs = []
1376 if proto.ret != "void":
1377 ret_val = "VkResult result = "
1378 stmt = " return result;\n"
1379 if proto.name == "EnumerateLayers":
1380 funcs.append('%s%s\n'
1381 '{\n'
1382 ' char str[1024];\n'
1383 ' if (gpu != NULL) {\n'
1384 ' pCurObj = (VkBaseLayerObject *) %s;\n'
1385 ' loader_platform_thread_once(&tabOnce, init%s);\n'
1386 ' %snextTable.%s;\n'
1387 ' fflush(stdout);\n'
1388 ' %s'
1389 ' } else {\n'
1390 ' if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
1391 ' return VK_ERROR_INVALID_POINTER;\n'
1392 ' // This layer compatible with all GPUs\n'
1393 ' *pOutLayerCount = 1;\n'
1394 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
1395 ' return VK_SUCCESS;\n'
1396 ' }\n'
1397 '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, proto.c_call(), stmt, self.layer_name))
1398 # All functions that do a Get are thread safe
1399 elif 'Get' in proto.name:
1400 return None
1401 # All Wsi functions are thread safe
1402 elif 'WsiX11' in proto.name:
1403 return None
1404 # All functions that start with a device parameter are thread safe
1405 elif proto.params[0].ty in { "VkDevice" }:
1406 return None
1407 # Only watch core objects passed as first parameter
1408 elif proto.params[0].ty not in vulkan.core.objects:
1409 return None
Tony Barbour8205d902015-04-16 15:59:00 -06001410 elif proto.params[0].ty != "VkPhysicalDevice":
Mike Stroyanb326d2c2015-04-02 11:59:05 -06001411 funcs.append('%s%s\n'
1412 '{\n'
1413 ' useObject((VkObject) %s, "%s");\n'
1414 ' %snextTable.%s;\n'
1415 ' finishUsingObject((VkObject) %s);\n'
1416 '%s'
1417 '}' % (qual, decl, proto.params[0].name, proto.params[0].ty, ret_val, proto.c_call(), proto.params[0].name, stmt))
1418 else:
1419 funcs.append('%s%s\n'
1420 '{\n'
1421 ' pCurObj = (VkBaseLayerObject *) %s;\n'
1422 ' loader_platform_thread_once(&tabOnce, init%s);\n'
1423 ' %snextTable.%s;\n'
1424 '%s'
1425 '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, proto.c_call(), stmt))
1426 return "\n\n".join(funcs)
1427
1428 def generate_body(self):
1429 self.layer_name = "Threading"
1430 body = [self._generate_layer_initialization(True, lockname='threading'),
1431 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
1432 self._generate_layer_gpa_function()]
1433 return "\n\n".join(body)
1434
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001435def main():
1436 subcommands = {
1437 "layer-funcs" : LayerFuncsSubcommand,
1438 "layer-dispatch" : LayerDispatchSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001439 "Generic" : GenericLayerSubcommand,
Tobin Ehlis4a636a12015-04-09 09:19:36 -06001440 "APIDump" : APIDumpSubcommand,
Tobin Ehlis907a0522014-11-25 16:59:27 -07001441 "ObjectTracker" : ObjectTrackerSubcommand,
Mike Stroyanb326d2c2015-04-02 11:59:05 -06001442 "Threading" : ThreadingSubcommand,
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001443 }
1444
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001445 if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]):
1446 print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001447 print
Tobin Ehlis2f3726c2015-01-15 17:51:52 -07001448 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001449 exit(1)
1450
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001451 hfp = vk_helper.HeaderFileParser(sys.argv[2])
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001452 hfp.parse()
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001453 vk_helper.enum_val_dict = hfp.get_enum_val_dict()
1454 vk_helper.enum_type_dict = hfp.get_enum_type_dict()
1455 vk_helper.struct_dict = hfp.get_struct_dict()
1456 vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1457 vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1458 vk_helper.types_dict = hfp.get_types_dict()
Tobin Ehlis6cd06372014-12-17 17:44:50 -07001459
Tobin Ehlis92dbf802014-10-22 09:06:33 -06001460 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
1461 subcmd.run()
1462
1463if __name__ == "__main__":
1464 main()