blob: 409c64959fe47469906c18f069ca722a69e7947a [file] [log] [blame]
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001#!/usr/bin/env python3
2#
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003# VK
Tobin Ehlis12076fc2014-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 Ehlis14ff0852014-12-17 17:44:50 -070029import os
Tobin Ehlis12076fc2014-10-22 09:06:33 -060030
Courtney Goeltzenleuchterf53c3cb2015-04-14 14:55:44 -060031import vulkan
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060032import vk_helper
Tobin Ehlis12076fc2014-10-22 09:06:33 -060033
Mike Stroyan938c2532015-04-03 13:58:35 -060034def generate_get_proc_addr_check(name):
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060035 return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \
36 " return NULL;" % ((name,) * 3)
Mike Stroyan938c2532015-04-03 13:58:35 -060037
Tobin Ehlis12076fc2014-10-22 09:06:33 -060038class Subcommand(object):
39 def __init__(self, argv):
40 self.argv = argv
Courtney Goeltzenleuchterf53c3cb2015-04-14 14:55:44 -060041 self.headers = vulkan.headers
42 self.protos = vulkan.protos
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -060043 self.no_addr = False
44 self.layer_name = ""
Tobin Ehlis12076fc2014-10-22 09:06:33 -060045
46 def run(self):
Tobin Ehlis12076fc2014-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060071 * Vulkan
Tobin Ehlis12076fc2014-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600104 def _get_printf_params(self, vk_type, name, output_param, cpp=False):
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600105 # TODO : Need ENUM and STRUCT checks here
Courtney Goeltzenleuchterd8e229c2015-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 Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600107 return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name))
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600108 if "char*" == vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600109 return ("%s", name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600110 if "uint64" in vk_type:
111 if '*' in vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600112 return ("%lu", "*%s" % name)
113 return ("%lu", name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600114 if "size" in vk_type:
115 if '*' in vk_type:
Chia-I Wu99ff89d2014-12-27 14:14:50 +0800116 return ("%zu", "*%s" % name)
117 return ("%zu", name)
Courtney Goeltzenleuchterd8e229c2015-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 Ehlis99f88672015-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 Ehlis12076fc2014-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 Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600124 if "bool" in vk_type or 'xcb_randr_crtc_t' in vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600125 return ("%u", name)
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600126 if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]:
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600127 if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis99f88672015-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 Ehlis12076fc2014-10-22 09:06:33 -0600130 return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600131 if '*' in vk_type:
Tobin Ehlisd2b88e82015-02-04 15:15:11 -0700132 if 'pUserData' == name:
133 return ("%i", "((pUserData == 0) ? 0 : *(pUserData))")
Tobin Ehlisc62cb892015-04-17 13:26:33 -0600134 if 'const' in vk_type.lower():
135 return ("%p", "(void*)(%s)" % name)
Jon Ashburn52f79b52014-12-12 16:10:45 -0700136 return ("%i", "*(%s)" % name)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600137 return ("%i", name)
Tobin Ehlis3a1cc8d2014-11-11 17:28:22 -0700138 # TODO : This is special-cased as there's only one "format" param currently and it's nice to expand it
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600139 if "VkFormat" == vk_type:
Tobin Ehlis99f88672015-01-10 12:42:41 -0700140 if cpp:
141 return ("%p", "&%s" % name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600142 return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_CHANNEL_FORMAT(%s.channelFormat), string_VK_NUM_FORMAT(%s.numericFormat)" % (name, name))
Tobin Ehlise7271572014-11-19 15:52:46 -0700143 if output_param:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600144 return ("%p", "(void*)*%s" % name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600145 if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type:
Courtney Goeltzenleuchterd462fba2015-04-03 16:35:32 -0600146 return ("%p", "(void*)(&%s)" % name)
Jon Ashburn52f79b52014-12-12 16:10:45 -0700147 return ("%p", "(void*)(%s)" % name)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600148
Tobin Ehlise8185062014-12-17 08:01:59 -0700149 def _gen_layer_dbg_callback_register(self):
150 r_body = []
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600151 r_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)')
Tobin Ehlise8185062014-12-17 08:01:59 -0700152 r_body.append('{')
153 r_body.append(' // This layer intercepts callbacks')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600154 r_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (VK_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(VK_LAYER_DBG_FUNCTION_NODE));')
Tobin Ehlise8185062014-12-17 08:01:59 -0700155 r_body.append(' if (!pNewDbgFuncNode)')
Tony Barbourd1c35722015-04-16 15:59:00 -0600156 r_body.append(' return VK_ERROR_OUT_OF_HOST_MEMORY;')
Tobin Ehlise8185062014-12-17 08:01:59 -0700157 r_body.append(' pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;')
158 r_body.append(' pNewDbgFuncNode->pUserData = pUserData;')
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700159 r_body.append(' pNewDbgFuncNode->pNext = g_pDbgFunctionHead;')
160 r_body.append(' g_pDbgFunctionHead = pNewDbgFuncNode;')
Jon Ashburna8aa8372015-03-03 15:07:15 -0700161 r_body.append(' // force callbacks if DebugAction hasn\'t been set already other than initial value')
Ian Elliott6d9e41e2015-03-05 12:28:53 -0700162 r_body.append(' if (g_actionIsDefault) {')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600163 r_body.append(' g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;')
Ian Elliott6d9e41e2015-03-05 12:28:53 -0700164 r_body.append(' }')
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600165 r_body.append(' VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);')
Tobin Ehlise8185062014-12-17 08:01:59 -0700166 r_body.append(' return result;')
167 r_body.append('}')
168 return "\n".join(r_body)
169
170 def _gen_layer_dbg_callback_unregister(self):
171 ur_body = []
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600172 ur_body.append('VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)')
Tobin Ehlise8185062014-12-17 08:01:59 -0700173 ur_body.append('{')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600174 ur_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pTrav = g_pDbgFunctionHead;')
175 ur_body.append(' VK_LAYER_DBG_FUNCTION_NODE *pPrev = pTrav;')
Tobin Ehlise8185062014-12-17 08:01:59 -0700176 ur_body.append(' while (pTrav) {')
177 ur_body.append(' if (pTrav->pfnMsgCallback == pfnMsgCallback) {')
178 ur_body.append(' pPrev->pNext = pTrav->pNext;')
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700179 ur_body.append(' if (g_pDbgFunctionHead == pTrav)')
180 ur_body.append(' g_pDbgFunctionHead = pTrav->pNext;')
Tobin Ehlise8185062014-12-17 08:01:59 -0700181 ur_body.append(' free(pTrav);')
182 ur_body.append(' break;')
183 ur_body.append(' }')
184 ur_body.append(' pPrev = pTrav;')
185 ur_body.append(' pTrav = pTrav->pNext;')
186 ur_body.append(' }')
Jon Ashburna8aa8372015-03-03 15:07:15 -0700187 ur_body.append(' if (g_pDbgFunctionHead == NULL)')
188 ur_body.append(' {')
189 ur_body.append(' if (g_actionIsDefault)')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600190 ur_body.append(' g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;')
Jon Ashburna8aa8372015-03-03 15:07:15 -0700191 ur_body.append(' else')
Mike Stroyan3712d5c2015-04-02 11:59:05 -0600192 ur_body.append(' g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));')
Jon Ashburna8aa8372015-03-03 15:07:15 -0700193 ur_body.append(' }')
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600194 ur_body.append(' VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);')
Tobin Ehlise8185062014-12-17 08:01:59 -0700195 ur_body.append(' return result;')
196 ur_body.append('}')
197 return "\n".join(ur_body)
198
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600199 def _gen_layer_get_global_extension_info(self, layer="Generic"):
200 ggei_body = []
201 ggei_body.append('struct extProps {')
202 ggei_body.append(' uint32_t version;')
203 ggei_body.append(' const char * const name;')
204 ggei_body.append('};')
Jon Ashburn120cfbe2015-04-14 14:12:59 -0600205 if layer == 'ObjectTracker':
206 ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 4')
207 ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {')
208 ggei_body.append(' // TODO what is the version?')
209 ggei_body.append(' {0x10, "%s"},' % layer)
210 ggei_body.append(' {0x10, "Validation"},')
211 ggei_body.append(' {0x10, "objTrackGetObjectCount"},')
212 ggei_body.append(' {0x10, "objTrackGetObjects"}')
213 ggei_body.append('};')
Tobin Ehlis3cc65722015-04-15 17:19:18 -0600214 elif layer == 'Threading':
215 ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 2')
216 ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {')
217 ggei_body.append(' // TODO what is the version?')
218 ggei_body.append(' {0x10, "%s"},' % layer)
219 ggei_body.append(' {0x10, "Validation"},')
220 ggei_body.append('};')
Jon Ashburn120cfbe2015-04-14 14:12:59 -0600221 else:
222 ggei_body.append('#define LAYER_EXT_ARRAY_SIZE 1')
223 ggei_body.append('static const struct extProps layerExts[LAYER_EXT_ARRAY_SIZE] = {')
224 ggei_body.append(' // TODO what is the version?')
225 ggei_body.append(' {0x10, "%s"}' % layer)
226 ggei_body.append('};')
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600227 ggei_body.append('')
Mark Lobodzinskia2727c92015-04-13 16:35:52 -0500228 ggei_body.append('VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(VkExtensionInfoType infoType, uint32_t extensionIndex, size_t* pDataSize, void* pData)')
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600229 ggei_body.append('{')
230 ggei_body.append(' VkExtensionProperties *ext_props;')
231 ggei_body.append(' uint32_t *count;')
232 ggei_body.append('')
233 ggei_body.append(' if (pDataSize == NULL)')
234 ggei_body.append(' return VK_ERROR_INVALID_POINTER;')
235 ggei_body.append('')
236 ggei_body.append(' switch (infoType) {')
237 ggei_body.append(' case VK_EXTENSION_INFO_TYPE_COUNT:')
238 ggei_body.append(' *pDataSize = sizeof(uint32_t);')
239 ggei_body.append(' if (pData == NULL)')
240 ggei_body.append(' return VK_SUCCESS;')
241 ggei_body.append(' count = (uint32_t *) pData;')
242 ggei_body.append(' *count = LAYER_EXT_ARRAY_SIZE;')
243 ggei_body.append(' break;')
244 ggei_body.append(' case VK_EXTENSION_INFO_TYPE_PROPERTIES:')
245 ggei_body.append(' *pDataSize = sizeof(VkExtensionProperties);')
246 ggei_body.append(' if (pData == NULL)')
247 ggei_body.append(' return VK_SUCCESS;')
248 ggei_body.append(' if (extensionIndex >= LAYER_EXT_ARRAY_SIZE)')
249 ggei_body.append(' return VK_ERROR_INVALID_VALUE;')
250 ggei_body.append(' ext_props = (VkExtensionProperties *) pData;')
251 ggei_body.append(' ext_props->version = layerExts[extensionIndex].version;')
252 ggei_body.append(' strncpy(ext_props->extName, layerExts[extensionIndex].name,')
253 ggei_body.append(' VK_MAX_EXTENSION_NAME);')
254 ggei_body.append(" ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\\0';")
255 ggei_body.append(' break;')
256 ggei_body.append(' default:')
257 ggei_body.append(' return VK_ERROR_INVALID_VALUE;')
258 ggei_body.append(' };')
259 ggei_body.append(' return VK_SUCCESS;')
260 ggei_body.append('}')
261 return "\n".join(ggei_body)
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600262
Tony Barbourd1c35722015-04-16 15:59:00 -0600263 def _gen_layer_get_extension_support(self, layer="Generic"):
264 ges_body = []
265 ges_body.append('VK_LAYER_EXPORT VkResult VKAPI xglGetExtensionSupport(VkPhysicalDevice gpu, const char* pExtName)')
266 ges_body.append('{')
267 ges_body.append(' VkResult result;')
268 ges_body.append(' VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;')
269 ges_body.append('')
270 ges_body.append(' /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */')
271 ges_body.append(' if (!strncmp(pExtName, "%s", strlen("%s")))' % (layer, layer))
272 ges_body.append(' {')
273 ges_body.append(' result = VK_SUCCESS;')
274 ges_body.append(' } else if (nextTable.GetExtensionSupport != NULL)')
275 ges_body.append(' {')
276 ges_body.append(' result = nextTable.GetExtensionSupport((VkPhysicalDevice)gpuw->nextObject, pExtName);')
277 ges_body.append(' } else')
278 ges_body.append(' {')
279 ges_body.append(' result = VK_ERROR_INVALID_EXTENSION;')
280 ges_body.append(' }')
281 ges_body.append(' return result;')
282 ges_body.append('}')
283 return "\n".join(ges_body)
284
Mike Stroyanbf237d72015-04-03 17:45:53 -0600285 def _generate_dispatch_entrypoints(self, qual=""):
Mike Stroyan938c2532015-04-03 13:58:35 -0600286 if qual:
287 qual += " "
288
Mike Stroyan938c2532015-04-03 13:58:35 -0600289 funcs = []
290 intercepted = []
291 for proto in self.protos:
Mike Stroyan70c05e82015-04-08 10:27:43 -0600292 if proto.name == "GetProcAddr":
293 intercepted.append(proto)
294 else:
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600295 intercept = self.generate_intercept(proto, qual)
Mike Stroyan938c2532015-04-03 13:58:35 -0600296 if intercept is None:
297 # fill in default intercept for certain entrypoints
298 if 'DbgRegisterMsgCallback' == proto.name:
299 intercept = self._gen_layer_dbg_callback_register()
Jon Ashburn5f3960e2015-04-02 12:06:28 -0600300 elif 'DbgUnregisterMsgCallback' == proto.name:
Mike Stroyan938c2532015-04-03 13:58:35 -0600301 intercept = self._gen_layer_dbg_callback_unregister()
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600302 elif 'GetGlobalExtensionInfo' == proto.name:
303 funcs.append(self._gen_layer_get_global_extension_info(self.layer_name))
Mike Stroyan938c2532015-04-03 13:58:35 -0600304 if intercept is not None:
305 funcs.append(intercept)
306 intercepted.append(proto)
307
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600308 prefix="vk"
Mike Stroyan938c2532015-04-03 13:58:35 -0600309 lookups = []
310 for proto in intercepted:
Mike Stroyan938c2532015-04-03 13:58:35 -0600311 lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
312 lookups.append(" return (void*) %s%s;" %
313 (prefix, proto.name))
Mike Stroyan938c2532015-04-03 13:58:35 -0600314
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600315 prefix="vk"
316 lookups = []
317 for proto in intercepted:
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600318 lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
319 lookups.append(" return (void*) %s%s;" %
320 (prefix, proto.name))
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600321
Mike Stroyan938c2532015-04-03 13:58:35 -0600322 # add customized layer_intercept_proc
323 body = []
324 body.append("static inline void* layer_intercept_proc(const char *name)")
325 body.append("{")
326 body.append(generate_get_proc_addr_check("name"))
327 body.append("")
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600328 body.append(" name += 2;")
Mike Stroyan938c2532015-04-03 13:58:35 -0600329 body.append(" %s" % "\n ".join(lookups))
330 body.append("")
331 body.append(" return NULL;")
332 body.append("}")
333 funcs.append("\n".join(body))
Mike Stroyan938c2532015-04-03 13:58:35 -0600334 return "\n\n".join(funcs)
335
336
Tobin Ehlisca915872014-11-18 11:28:33 -0700337 def _generate_extensions(self):
338 exts = []
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600339 exts.append('uint64_t objTrackGetObjectCount(VK_OBJECT_TYPE type)')
Tobin Ehlisca915872014-11-18 11:28:33 -0700340 exts.append('{')
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600341 exts.append(' return (type == VkObjectTypeAny) ? numTotalObjs : numObjs[type];')
Tobin Ehlisca915872014-11-18 11:28:33 -0700342 exts.append('}')
343 exts.append('')
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600344 exts.append('VkResult objTrackGetObjects(VK_OBJECT_TYPE type, uint64_t objCount, OBJTRACK_NODE* pObjNodeArray)')
Tobin Ehlisca915872014-11-18 11:28:33 -0700345 exts.append('{')
346 exts.append(" // This bool flags if we're pulling all objs or just a single class of objs")
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600347 exts.append(' bool32_t bAllObjs = (type == VkObjectTypeAny);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700348 exts.append(' // Check the count first thing')
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600349 exts.append(' uint64_t maxObjCount = (bAllObjs) ? numTotalObjs : numObjs[type];')
Tobin Ehlisca915872014-11-18 11:28:33 -0700350 exts.append(' if (objCount > maxObjCount) {')
351 exts.append(' char str[1024];')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600352 exts.append(' sprintf(str, "OBJ ERROR : Received objTrackGetObjects() request for %lu objs, but there are only %lu objs of type %s", objCount, maxObjCount, string_VK_OBJECT_TYPE(type));')
353 exts.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_OBJCOUNT_MAX_EXCEEDED, "OBJTRACK", str);')
354 exts.append(' return VK_ERROR_INVALID_VALUE;')
Tobin Ehlisca915872014-11-18 11:28:33 -0700355 exts.append(' }')
356 exts.append(' objNode* pTrav = (bAllObjs) ? pGlobalHead : pObjectHead[type];')
Mark Lobodzinski17caf572015-01-29 08:55:56 -0600357 exts.append(' for (uint64_t i = 0; i < objCount; i++) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700358 exts.append(' if (!pTrav) {')
359 exts.append(' char str[1024];')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600360 exts.append(' sprintf(str, "OBJ INTERNAL ERROR : Ran out of %s objs! Should have %lu, but only copied %lu and not the requested %lu.", string_VK_OBJECT_TYPE(type), maxObjCount, i, objCount);')
361 exts.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
362 exts.append(' return VK_ERROR_UNKNOWN;')
Tobin Ehlisca915872014-11-18 11:28:33 -0700363 exts.append(' }')
364 exts.append(' memcpy(&pObjNodeArray[i], pTrav, sizeof(OBJTRACK_NODE));')
365 exts.append(' pTrav = (bAllObjs) ? pTrav->pNextGlobal : pTrav->pNextObj;')
366 exts.append(' }')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600367 exts.append(' return VK_SUCCESS;')
Tobin Ehlisca915872014-11-18 11:28:33 -0700368 exts.append('}')
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600369 return "\n".join(exts)
370
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600371 def _generate_layer_gpa_function(self, extensions=[]):
372 func_body = []
Tony Barbourd1c35722015-04-16 15:59:00 -0600373 func_body.append("VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* funcName)\n"
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600374 "{\n"
375 " VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;\n"
376 " void* addr;\n"
Mike Stroyanb050c682015-04-17 12:36:38 -0600377 " if (gpu == VK_NULL_HANDLE)\n"
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600378 " return NULL;\n"
379 " pCurObj = gpuw;\n"
380 " loader_platform_thread_once(&tabOnce, init%s);\n\n"
381 " addr = layer_intercept_proc(funcName);\n"
382 " if (addr)\n"
383 " return addr;" % self.layer_name)
384
Tobin Ehlisca915872014-11-18 11:28:33 -0700385 if 0 != len(extensions):
386 for ext_name in extensions:
Chia-I Wuf1a5a742014-12-27 15:16:07 +0800387 func_body.append(' else if (!strncmp("%s", funcName, sizeof("%s")))\n'
Tobin Ehlisca915872014-11-18 11:28:33 -0700388 ' return %s;' % (ext_name, ext_name, ext_name))
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600389 func_body.append(" else {\n"
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600390 " if (gpuw->pGPA == NULL)\n"
391 " return NULL;\n"
Tony Barbourd1c35722015-04-16 15:59:00 -0600392 " return gpuw->pGPA((VkPhysicalDevice)gpuw->nextObject, funcName);\n"
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600393 " }\n"
394 "}\n")
395 return "\n".join(func_body)
396
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600397 def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None):
398 func_body = ["#include \"vk_dispatch_table_helper.h\""]
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700399 func_body.append('static void init%s(void)\n'
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600400 '{\n' % self.layer_name)
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700401 if init_opts:
402 func_body.append(' const char *strOpt;')
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600403 func_body.append(' // initialize %s options' % self.layer_name)
404 func_body.append(' getLayerOptionEnum("%sReportLevel", (uint32_t *) &g_reportingLevel);' % self.layer_name)
405 func_body.append(' g_actionIsDefault = getLayerOptionEnum("%sDebugAction", (uint32_t *) &g_debugAction);' % self.layer_name)
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700406 func_body.append('')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600407 func_body.append(' if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)')
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700408 func_body.append(' {')
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600409 func_body.append(' strOpt = getLayerOption("%sLogFilename");' % self.layer_name)
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700410 func_body.append(' if (strOpt)')
411 func_body.append(' {')
412 func_body.append(' g_logFile = fopen(strOpt, "w");')
413 func_body.append(' }')
414 func_body.append(' if (g_logFile == NULL)')
415 func_body.append(' g_logFile = stdout;')
416 func_body.append(' }')
417 func_body.append('')
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600418 func_body.append(' PFN_vkGetProcAddr fpNextGPA;\n'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600419 ' fpNextGPA = pCurObj->pGPA;\n'
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700420 ' assert(fpNextGPA);\n')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600421
Tony Barbourd1c35722015-04-16 15:59:00 -0600422 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);")
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700423 if lockname is not None:
424 func_body.append(" if (!%sLockInitialized)" % lockname)
425 func_body.append(" {")
426 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
427 func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname)
428 func_body.append(" %sLockInitialized = 1;" % lockname)
429 func_body.append(" }")
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600430 func_body.append("}\n")
431 return "\n".join(func_body)
432
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600433 def _generate_layer_initialization_with_lock(self, prefix='vk'):
434 func_body = ["#include \"vk_dispatch_table_helper.h\""]
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700435 func_body.append('static void init%s(void)\n'
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700436 '{\n'
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600437 ' PFN_vkGetProcAddr fpNextGPA;\n'
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700438 ' fpNextGPA = pCurObj->pGPA;\n'
Mike Stroyan3712d5c2015-04-02 11:59:05 -0600439 ' assert(fpNextGPA);\n' % self.layer_name)
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700440
Tony Barbourd1c35722015-04-16 15:59:00 -0600441 func_body.append(" layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);\n")
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700442 func_body.append(" if (!printLockInitialized)")
443 func_body.append(" {")
444 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
445 func_body.append(" loader_platform_thread_create_mutex(&printLock);")
446 func_body.append(" printLockInitialized = 1;")
447 func_body.append(" }")
448 func_body.append("}\n")
449 return "\n".join(func_body)
450
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600451class LayerFuncsSubcommand(Subcommand):
452 def generate_header(self):
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600453 return '#include <vkLayer.h>\n#include "loader.h"'
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600454
455 def generate_body(self):
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600456 return self._generate_dispatch_entrypoints("static")
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600457
458class LayerDispatchSubcommand(Subcommand):
459 def generate_header(self):
460 return '#include "layer_wrappers.h"'
461
462 def generate_body(self):
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700463 return self._generate_layer_initialization()
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600464
465class GenericLayerSubcommand(Subcommand):
466 def generate_header(self):
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600467 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 Ehlis12076fc2014-10-22 09:06:33 -0600468
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600469 def generate_intercept(self, proto, qual):
Tobin Ehlis7ad197f2015-04-16 11:17:12 -0600470 if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback' , 'GetGlobalExtensionInfo']:
Mike Stroyan00087e62015-04-03 14:39:16 -0600471 # use default version
472 return None
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600473 decl = proto.c_func(prefix="vk", attr="VKAPI")
Mike Stroyan938c2532015-04-03 13:58:35 -0600474 ret_val = ''
475 stmt = ''
476 funcs = []
477 if proto.ret != "void":
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600478 ret_val = "VkResult result = "
Mike Stroyan938c2532015-04-03 13:58:35 -0600479 stmt = " return result;\n"
Mike Stroyan938c2532015-04-03 13:58:35 -0600480 if proto.name == "EnumerateLayers":
Mike Stroyan938c2532015-04-03 13:58:35 -0600481 funcs.append('%s%s\n'
482 '{\n'
483 ' char str[1024];\n'
Mike Stroyanb050c682015-04-17 12:36:38 -0600484 ' if (gpu != VK_NULL_HANDLE) {\n'
Mike Stroyan938c2532015-04-03 13:58:35 -0600485 ' sprintf(str, "At start of layered %s\\n");\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600486 ' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600487 ' pCurObj = (VkBaseLayerObject *) gpu;\n'
Mike Stroyan938c2532015-04-03 13:58:35 -0600488 ' loader_platform_thread_once(&tabOnce, init%s);\n'
489 ' %snextTable.%s;\n'
490 ' sprintf(str, "Completed layered %s\\n");\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600491 ' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, gpu, 0, 0, (char *) "GENERIC", (char *) str);\n'
Mike Stroyan938c2532015-04-03 13:58:35 -0600492 ' fflush(stdout);\n'
493 ' %s'
494 ' } else {\n'
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600495 ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600496 ' return VK_ERROR_INVALID_POINTER;\n'
Mike Stroyan938c2532015-04-03 13:58:35 -0600497 ' // This layer compatible with all GPUs\n'
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600498 ' *pLayerCount = 1;\n'
Mike Stroyan938c2532015-04-03 13:58:35 -0600499 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600500 ' return VK_SUCCESS;\n'
Mike Stroyan938c2532015-04-03 13:58:35 -0600501 ' }\n'
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600502 '}' % (qual, decl, proto.name, self.layer_name, ret_val, proto.c_call(), proto.name, stmt, self.layer_name))
503 else:
Mike Stroyan938c2532015-04-03 13:58:35 -0600504 funcs.append('%s%s\n'
505 '{\n'
506 ' %snextTable.%s;\n'
507 '%s'
508 '}' % (qual, decl, ret_val, proto.c_call(), stmt))
Mike Stroyan938c2532015-04-03 13:58:35 -0600509 return "\n\n".join(funcs)
510
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600511 def generate_body(self):
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600512 self.layer_name = "Generic"
513 body = [self._generate_layer_initialization(True),
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600514 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
Mike Stroyanbf237d72015-04-03 17:45:53 -0600515 self._generate_layer_gpa_function()]
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600516
517 return "\n\n".join(body)
518
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600519class APIDumpSubcommand(Subcommand):
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600520 def generate_header(self):
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700521 header_txt = []
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600522 header_txt.append('#include <fstream>')
523 header_txt.append('#include <iostream>')
524 header_txt.append('#include <string>')
525 header_txt.append('')
526 header_txt.append('static std::ofstream fileStream;')
527 header_txt.append('static std::string fileName = "vk_apidump.txt";')
528 header_txt.append('std::ostream* outputStream = NULL;')
529 header_txt.append('void ConfigureOutputStream(bool writeToFile, bool flushAfterWrite)')
530 header_txt.append('{')
531 header_txt.append(' if(writeToFile)')
532 header_txt.append(' {')
533 header_txt.append(' fileStream.open(fileName);')
534 header_txt.append(' outputStream = &fileStream;')
535 header_txt.append(' }')
536 header_txt.append(' else')
537 header_txt.append(' {')
538 header_txt.append(' outputStream = &std::cout;')
539 header_txt.append(' }')
540 header_txt.append('')
541 header_txt.append(' if(flushAfterWrite)')
542 header_txt.append(' {')
543 header_txt.append(' outputStream->sync_with_stdio(true);')
544 header_txt.append(' }')
545 header_txt.append(' else')
546 header_txt.append(' {')
547 header_txt.append(' outputStream->sync_with_stdio(false);')
548 header_txt.append(' }')
549 header_txt.append('}')
550 header_txt.append('')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700551 header_txt.append('#include "loader_platform.h"')
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600552 header_txt.append('#include "vkLayer.h"')
553 header_txt.append('#include "vk_struct_string_helper_cpp.h"')
554 header_txt.append('')
Ian Elliott655cad72015-02-12 17:08:34 -0700555 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
556 header_txt.append('#include "loader_platform.h"')
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600557 header_txt.append('')
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600558 header_txt.append('static VkLayerDispatchTable nextTable;')
559 header_txt.append('static VkBaseLayerObject *pCurObj;')
Tobin Ehlisa2b199c2015-04-27 17:30:04 -0600560 header_txt.append('static bool g_APIDumpDetailed = true;')
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600561 header_txt.append('')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700562 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
563 header_txt.append('static int printLockInitialized = 0;')
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600564 header_txt.append('static loader_platform_thread_mutex printLock;')
565 header_txt.append('')
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700566 header_txt.append('#define MAX_TID 513')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700567 header_txt.append('static loader_platform_thread_id tidMapping[MAX_TID] = {0};')
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700568 header_txt.append('static uint32_t maxTID = 0;')
569 header_txt.append('// Map actual TID to an index value and return that index')
570 header_txt.append('// This keeps TIDs in range from 0-MAX_TID and simplifies compares between runs')
571 header_txt.append('static uint32_t getTIDIndex() {')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700572 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700573 header_txt.append(' for (uint32_t i = 0; i < maxTID; i++) {')
574 header_txt.append(' if (tid == tidMapping[i])')
575 header_txt.append(' return i;')
576 header_txt.append(' }')
577 header_txt.append(" // Don't yet have mapping, set it and return newly set index")
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700578 header_txt.append(' uint32_t retVal = (uint32_t) maxTID;')
Tobin Ehlisd009bae2014-11-24 15:46:55 -0700579 header_txt.append(' tidMapping[maxTID++] = tid;')
580 header_txt.append(' assert(maxTID < MAX_TID);')
581 header_txt.append(' return retVal;')
582 header_txt.append('}')
583 return "\n".join(header_txt)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600584
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600585 def generate_init(self):
586 func_body = []
587 func_body.append('#include "vk_dispatch_table_helper.h"')
588 func_body.append('#include "layers_config.h"')
589 func_body.append('')
590 func_body.append('static void init%s(void)' % self.layer_name)
591 func_body.append('{')
592 func_body.append(' using namespace StreamControl;')
593 func_body.append('')
Tobin Ehlisa2b199c2015-04-27 17:30:04 -0600594 func_body.append(' char const*const detailedStr = getLayerOption("APIDumpDetailed");')
595 func_body.append(' if(detailedStr != NULL)')
596 func_body.append(' {')
597 func_body.append(' if(strcmp(detailedStr, "TRUE") == 0)')
598 func_body.append(' {')
599 func_body.append(' g_APIDumpDetailed = true;')
600 func_body.append(' }')
601 func_body.append(' else if(strcmp(detailedStr, "FALSE") == 0)')
602 func_body.append(' {')
603 func_body.append(' g_APIDumpDetailed = false;')
604 func_body.append(' }')
605 func_body.append(' }')
606 func_body.append('')
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600607 func_body.append(' char const*const writeToFileStr = getLayerOption("APIDumpFile");')
608 func_body.append(' bool writeToFile = false;')
609 func_body.append(' if(writeToFileStr != NULL)')
610 func_body.append(' {')
611 func_body.append(' if(strcmp(writeToFileStr, "TRUE") == 0)')
612 func_body.append(' {')
613 func_body.append(' writeToFile = true;')
614 func_body.append(' }')
615 func_body.append(' else if(strcmp(writeToFileStr, "FALSE") == 0)')
616 func_body.append(' {')
617 func_body.append(' writeToFile = false;')
618 func_body.append(' }')
619 func_body.append(' }')
620 func_body.append('')
621 func_body.append(' char const*const noAddrStr = getLayerOption("APIDumpNoAddr");')
622 func_body.append(' if(noAddrStr != NULL)')
623 func_body.append(' {')
624 func_body.append(' if(strcmp(noAddrStr, "FALSE") == 0)')
625 func_body.append(' {')
626 func_body.append(' StreamControl::writeAddress = true;')
627 func_body.append(' }')
628 func_body.append(' else if(strcmp(noAddrStr, "TRUE") == 0)')
629 func_body.append(' {')
630 func_body.append(' StreamControl::writeAddress = false;')
631 func_body.append(' }')
632 func_body.append(' }')
633 func_body.append('')
634 func_body.append(' char const*const flushAfterWriteStr = getLayerOption("APIDumpFlush");')
635 func_body.append(' bool flushAfterWrite = false;')
636 func_body.append(' if(flushAfterWriteStr != NULL)')
637 func_body.append(' {')
638 func_body.append(' if(strcmp(flushAfterWriteStr, "TRUE") == 0)')
639 func_body.append(' {')
640 func_body.append(' flushAfterWrite = true;')
641 func_body.append(' }')
642 func_body.append(' else if(strcmp(flushAfterWriteStr, "FALSE") == 0)')
643 func_body.append(' {')
644 func_body.append(' flushAfterWrite = false;')
645 func_body.append(' }')
646 func_body.append(' }')
647 func_body.append('')
648 func_body.append(' ConfigureOutputStream(writeToFile, flushAfterWrite);')
649 func_body.append('')
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600650 func_body.append(' PFN_vkGetProcAddr fpNextGPA;')
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600651 func_body.append(' fpNextGPA = pCurObj->pGPA;')
652 func_body.append(' assert(fpNextGPA);')
Tony Barbourd1c35722015-04-16 15:59:00 -0600653 func_body.append(' layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalDevice) pCurObj->nextObject);')
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600654 func_body.append('')
655 func_body.append(' if (!printLockInitialized)')
656 func_body.append(' {')
657 func_body.append(' // TODO/TBD: Need to delete this mutex sometime. How???')
658 func_body.append(' loader_platform_thread_create_mutex(&printLock);')
659 func_body.append(' printLockInitialized = 1;')
660 func_body.append(' }')
661 func_body.append('}')
662 func_body.append('')
663 return "\n".join(func_body)
Tobin Ehlis99f88672015-01-10 12:42:41 -0700664
Mike Stroyanbf237d72015-04-03 17:45:53 -0600665 def generate_intercept(self, proto, qual):
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600666 if proto.name in [ 'GetGlobalExtensionInfo']:
667 return None
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600668 decl = proto.c_func(prefix="vk", attr="VKAPI")
Mike Stroyanbf237d72015-04-03 17:45:53 -0600669 ret_val = ''
670 stmt = ''
671 funcs = []
672 sp_param_dict = {} # Store 'index' for struct param to print, or an name of binding "Count" param for array to print
673 create_params = 0 # Num of params at end of function that are created and returned as output values
Chia-I Wuf8693382015-04-16 22:02:10 +0800674 if 'AllocDescriptorSets' in proto.name:
Mike Stroyanbf237d72015-04-03 17:45:53 -0600675 create_params = -2
676 elif 'Create' in proto.name or 'Alloc' in proto.name or 'MapMemory' in proto.name:
677 create_params = -1
678 if proto.ret != "void":
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600679 ret_val = "VkResult result = "
Mike Stroyanbf237d72015-04-03 17:45:53 -0600680 stmt = " return result;\n"
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600681 f_open = 'loader_platform_thread_lock_mutex(&printLock);\n '
682 log_func = ' if (StreamControl::writeAddress == true) {'
683 log_func += '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name
684 log_func_no_addr = '\n (*outputStream) << "t{" << getTIDIndex() << "} vk%s(' % proto.name
685 f_close = '\n loader_platform_thread_unlock_mutex(&printLock);'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600686 pindex = 0
687 prev_count_name = ''
688 for p in proto.params:
689 cp = False
690 if 0 != create_params:
691 # If this is any of the N last params of the func, treat as output
692 for y in range(-1, create_params-1, -1):
693 if p.name == proto.params[y].name:
694 cp = True
695 (pft, pfi) = self._get_printf_params(p.ty, p.name, cp, cpp=True)
Mike Stroyanbf237d72015-04-03 17:45:53 -0600696 log_func += '%s = " << %s << ", ' % (p.name, pfi)
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600697 if "%p" == pft:
698 log_func_no_addr += '%s = address, ' % (p.name)
699 else:
700 log_func_no_addr += '%s = " << %s << ", ' % (p.name, pfi)
Tobin Ehlis08541742015-04-16 15:56:11 -0600701 if prev_count_name != '' and (prev_count_name.replace('Count', '')[1:] in p.name):
Mike Stroyanbf237d72015-04-03 17:45:53 -0600702 sp_param_dict[pindex] = prev_count_name
Tobin Ehlis08541742015-04-16 15:56:11 -0600703 prev_count_name = ''
Mike Stroyanbf237d72015-04-03 17:45:53 -0600704 elif 'pDescriptorSets' == p.name and proto.params[-1].name == 'pCount':
705 sp_param_dict[pindex] = '*pCount'
Chia-I Wuf8693382015-04-16 22:02:10 +0800706 elif vk_helper.is_type(p.ty.strip('*').replace('const ', ''), 'struct'):
Mike Stroyanbf237d72015-04-03 17:45:53 -0600707 sp_param_dict[pindex] = 'index'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600708 if p.name.endswith('Count'):
709 if '*' in p.ty:
710 prev_count_name = "*%s" % p.name
711 else:
712 prev_count_name = p.name
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600713 pindex += 1
Mike Stroyanbf237d72015-04-03 17:45:53 -0600714 log_func = log_func.strip(', ')
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600715 log_func_no_addr = log_func_no_addr.strip(', ')
Mike Stroyanbf237d72015-04-03 17:45:53 -0600716 if proto.ret != "void":
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600717 log_func += ') = " << string_VkResult((VkResult)result) << endl'
718 log_func_no_addr += ') = " << string_VkResult((VkResult)result) << endl'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600719 else:
720 log_func += ')\\n"'
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600721 log_func_no_addr += ')\\n"'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600722 log_func += ';'
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600723 log_func_no_addr += ';'
724 log_func += '\n }\n else {%s;\n }' % log_func_no_addr;
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600725 #print("Proto %s has param_dict: %s" % (proto.name, sp_param_dict))
Mike Stroyanbf237d72015-04-03 17:45:53 -0600726 if len(sp_param_dict) > 0:
Tobin Ehlisa2b199c2015-04-27 17:30:04 -0600727 indent = ' '
728 log_func += '\n%sif (g_APIDumpDetailed) {' % indent
729 indent += ' '
Mike Stroyanbf237d72015-04-03 17:45:53 -0600730 i_decl = False
Tobin Ehlisa2b199c2015-04-27 17:30:04 -0600731 log_func += '\n%sstring tmp_str;' % indent
Mike Stroyanbf237d72015-04-03 17:45:53 -0600732 for sp_index in sp_param_dict:
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600733 #print("sp_index: %s" % str(sp_index))
Mike Stroyanbf237d72015-04-03 17:45:53 -0600734 if 'index' == sp_param_dict[sp_index]:
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600735 cis_print_func = 'vk_print_%s' % (proto.params[sp_index].ty.replace('const ', '').strip('*').lower())
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600736 local_name = proto.params[sp_index].name
737 if '*' not in proto.params[sp_index].ty:
738 local_name = '&%s' % proto.params[sp_index].name
Tobin Ehlisa2b199c2015-04-27 17:30:04 -0600739 log_func += '\n%sif (%s) {' % (indent, local_name)
740 indent += ' '
741 log_func += '\n%stmp_str = %s(%s, " ");' % (indent, cis_print_func, local_name)
742 log_func += '\n%s(*outputStream) << " %s (" << %s << ")" << endl << tmp_str << endl;' % (indent, local_name, local_name)
743 indent = indent[4:]
744 log_func += '\n%s}' % (indent)
Mike Stroyanbf237d72015-04-03 17:45:53 -0600745 else: # We have a count value stored to iterate over an array
746 print_cast = ''
747 print_func = ''
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600748 if vk_helper.is_type(proto.params[sp_index].ty.strip('*').replace('const ', ''), 'struct'):
Mike Stroyanbf237d72015-04-03 17:45:53 -0600749 print_cast = '&'
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600750 print_func = 'vk_print_%s' % proto.params[sp_index].ty.replace('const ', '').strip('*').lower()
Mike Stroyanbf237d72015-04-03 17:45:53 -0600751 else:
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600752 print_cast = ''
Mike Stroyanbf237d72015-04-03 17:45:53 -0600753 print_func = 'string_convert_helper'
754 #cis_print_func = 'tmp_str = string_convert_helper((void*)%s[i], " ");' % proto.params[sp_index].name
755 cis_print_func = 'tmp_str = %s(%s%s[i], " ");' % (print_func, print_cast, proto.params[sp_index].name)
Mike Stroyanbf237d72015-04-03 17:45:53 -0600756 if not i_decl:
Tobin Ehlisa2b199c2015-04-27 17:30:04 -0600757 log_func += '\n%suint32_t i;' % (indent)
Mike Stroyanbf237d72015-04-03 17:45:53 -0600758 i_decl = True
Tobin Ehlisa2b199c2015-04-27 17:30:04 -0600759 log_func += '\n%sfor (i = 0; i < %s; i++) {' % (indent, sp_param_dict[sp_index])
760 indent += ' '
761 log_func += '\n%s%s' % (indent, cis_print_func)
762 log_func += '\n%s(*outputStream) << " %s[" << i << "] (" << %s%s[i] << ")" << endl << tmp_str << endl;' % (indent, proto.params[sp_index].name, '&', proto.params[sp_index].name)
763 indent = indent[4:]
764 log_func += '\n%s}' % (indent)
765 indent = indent[4:]
766 log_func += '\n%s}' % (indent)
Mike Stroyanbf237d72015-04-03 17:45:53 -0600767 if proto.name == "EnumerateLayers":
Mike Stroyanbf237d72015-04-03 17:45:53 -0600768 funcs.append('%s%s\n'
769 '{\n'
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600770 ' using namespace StreamControl;\n'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600771 ' if (gpu != NULL) {\n'
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600772 ' pCurObj = (VkBaseLayerObject *) gpu;\n'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600773 ' loader_platform_thread_once(&tabOnce, init%s);\n'
774 ' %snextTable.%s;\n'
775 ' %s %s %s\n'
776 ' %s'
777 ' } else {\n'
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600778 ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600779 ' return VK_ERROR_INVALID_POINTER;\n'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600780 ' // This layer compatible with all GPUs\n'
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -0600781 ' *pLayerCount = 1;\n'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600782 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600783 ' return VK_SUCCESS;\n'
Mike Stroyanbf237d72015-04-03 17:45:53 -0600784 ' }\n'
Jon Ashburn4d9f4652015-04-08 21:33:34 -0600785 '}' % (qual, decl, self.layer_name, ret_val, proto.c_call(),f_open, log_func, f_close, stmt, self.layer_name))
Tony Barbourd1c35722015-04-16 15:59:00 -0600786 elif 'GetExtensionSupport' == proto.name:
787 funcs.append('%s%s\n'
788 '{\n'
789 ' VkResult result;\n'
790 ' /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */\n'
791 ' if (!strncmp(pExtName, "%s", strlen("%s")))\n'
792 ' {\n'
793 ' result = VK_SUCCESS;\n'
794 ' } else if (nextTable.GetExtensionSupport != NULL)\n'
795 ' {\n'
796 ' result = nextTable.%s;\n'
797 ' %s %s %s\n'
798 ' } else\n'
799 ' {\n'
800 ' result = VK_ERROR_INVALID_EXTENSION;\n'
801 ' }\n'
802 '%s'
803 '}' % (qual, decl, self.layer_name, self.layer_name, proto.c_call(), f_open, log_func, f_close, stmt))
Mike Stroyanbf237d72015-04-03 17:45:53 -0600804 else:
Mike Stroyanbf237d72015-04-03 17:45:53 -0600805 funcs.append('%s%s\n'
806 '{\n'
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600807 ' using namespace StreamControl;\n'
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600808 ' %snextTable.%s;\n'
809 ' %s%s%s\n'
810 '%s'
811 '}' % (qual, decl, ret_val, proto.c_call(), f_open, log_func, f_close, stmt))
Mike Stroyanbf237d72015-04-03 17:45:53 -0600812 return "\n\n".join(funcs)
813
Tobin Ehlis99f88672015-01-10 12:42:41 -0700814 def generate_body(self):
Tobin Ehlise78dbd82015-04-09 09:19:36 -0600815 self.layer_name = "APIDump"
816 body = [self.generate_init(),
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600817 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600818 self._generate_layer_gpa_function()]
Tobin Ehlis99f88672015-01-10 12:42:41 -0700819 return "\n\n".join(body)
820
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600821class ObjectTrackerSubcommand(Subcommand):
822 def generate_header(self):
823 header_txt = []
Tony Barbourfc15ff82015-04-20 16:28:46 -0600824 header_txt.append('#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <inttypes.h>\n#include "loader_platform.h"')
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600825 header_txt.append('#include "object_track.h"\n\nstatic VkLayerDispatchTable nextTable;\nstatic VkBaseLayerObject *pCurObj;')
Ian Elliott655cad72015-02-12 17:08:34 -0700826 header_txt.append('// The following is #included again to catch certain OS-specific functions being used:')
827 header_txt.append('#include "loader_platform.h"')
Jon Ashburn9a7f9a22015-02-17 11:03:12 -0700828 header_txt.append('#include "layers_config.h"')
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700829 header_txt.append('#include "layers_msg.h"')
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700830 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);')
831 header_txt.append('static long long unsigned int object_track_index = 0;')
Tobin Ehlis36f1b462015-02-23 14:09:16 -0700832 header_txt.append('static int objLockInitialized = 0;')
833 header_txt.append('static loader_platform_thread_mutex objLock;')
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700834 header_txt.append('')
Tobin Ehlisca915872014-11-18 11:28:33 -0700835 header_txt.append('// We maintain a "Global" list which links every object and a')
836 header_txt.append('// per-Object list which just links objects of a given type')
837 header_txt.append('// The object node has both pointers so the actual nodes are shared between the two lists')
838 header_txt.append('typedef struct _objNode {')
839 header_txt.append(' OBJTRACK_NODE obj;')
840 header_txt.append(' struct _objNode *pNextObj;')
841 header_txt.append(' struct _objNode *pNextGlobal;')
842 header_txt.append('} objNode;')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -0500843 header_txt.append('')
844 header_txt.append('static objNode *pObjectHead[VkNumObjectType] = {0};')
Tobin Ehlisca915872014-11-18 11:28:33 -0700845 header_txt.append('static objNode *pGlobalHead = NULL;')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -0500846 header_txt.append('static uint64_t numObjs[VkNumObjectType] = {0};')
Tobin Ehlisca915872014-11-18 11:28:33 -0700847 header_txt.append('static uint64_t numTotalObjs = 0;')
Courtney Goeltzenleuchterc951e742015-04-07 16:23:00 -0600848 header_txt.append('static uint32_t maxMemReferences = 0;')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -0500849 header_txt.append('')
850 header_txt.append('// For each Queue\'s doubly linked-list of mem refs')
851 header_txt.append('typedef struct _OT_MEM_INFO {')
Tony Barbourd1c35722015-04-16 15:59:00 -0600852 header_txt.append(' VkDeviceMemory mem;')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -0500853 header_txt.append(' struct _OT_MEM_INFO *pNextMI;')
854 header_txt.append(' struct _OT_MEM_INFO *pPrevMI;')
855 header_txt.append('')
856 header_txt.append('} OT_MEM_INFO;')
857 header_txt.append('')
858 header_txt.append('// Track Queue information')
859 header_txt.append('typedef struct _OT_QUEUE_INFO {')
860 header_txt.append(' OT_MEM_INFO *pMemRefList;')
861 header_txt.append(' struct _OT_QUEUE_INFO *pNextQI;')
862 header_txt.append(' VkQueue queue;')
863 header_txt.append(' uint32_t refCount;')
864 header_txt.append('} OT_QUEUE_INFO;')
865 header_txt.append('')
866 header_txt.append('// Global list of QueueInfo structures, one per queue')
867 header_txt.append('static OT_QUEUE_INFO *g_pQueueInfo;')
868 header_txt.append('')
869 header_txt.append('// Add new queue to head of global queue list')
870 header_txt.append('static void addQueueInfo(VkQueue queue)')
871 header_txt.append('{')
872 header_txt.append(' OT_QUEUE_INFO *pQueueInfo = malloc(sizeof(OT_QUEUE_INFO));')
873 header_txt.append(' memset(pQueueInfo, 0, sizeof(OT_QUEUE_INFO));')
874 header_txt.append(' pQueueInfo->queue = queue;')
875 header_txt.append('')
876 header_txt.append(' if (pQueueInfo != NULL) {')
877 header_txt.append(' pQueueInfo->pNextQI = g_pQueueInfo;')
878 header_txt.append(' g_pQueueInfo = pQueueInfo;')
879 header_txt.append(' }')
880 header_txt.append(' else {')
881 header_txt.append(' char str[1024];')
Tony Barbourd1c35722015-04-16 15:59:00 -0600882 header_txt.append(' sprintf(str, "ERROR: VK_ERROR_OUT_OF_HOST_MEMORY -- could not allocate memory for Queue Information");')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -0500883 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
884 header_txt.append(' }')
885 header_txt.append('}')
886 header_txt.append('')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -0500887 header_txt.append('// Destroy memRef lists and free all memory')
888 header_txt.append('static void destroyQueueMemRefLists()')
889 header_txt.append('{')
890 header_txt.append(' OT_QUEUE_INFO *pQueueInfo = g_pQueueInfo;')
891 header_txt.append(' OT_QUEUE_INFO *pDelQueueInfo = NULL;')
892 header_txt.append(' while (pQueueInfo != NULL) {')
893 header_txt.append(' OT_MEM_INFO *pMemInfo = pQueueInfo->pMemRefList;')
894 header_txt.append(' while (pMemInfo != NULL) {')
895 header_txt.append(' OT_MEM_INFO *pDelMemInfo = pMemInfo;')
896 header_txt.append(' pMemInfo = pMemInfo->pNextMI;')
897 header_txt.append(' free(pDelMemInfo);')
898 header_txt.append(' }')
899 header_txt.append(' pDelQueueInfo = pQueueInfo;')
900 header_txt.append(' pQueueInfo = pQueueInfo->pNextQI;')
901 header_txt.append(' free(pDelQueueInfo);')
902 header_txt.append(' }')
903 header_txt.append('}')
904 header_txt.append('')
Tobin Ehlisca915872014-11-18 11:28:33 -0700905 header_txt.append('// Debug function to print global list and each individual object list')
906 header_txt.append('static void ll_print_lists()')
907 header_txt.append('{')
908 header_txt.append(' objNode* pTrav = pGlobalHead;')
909 header_txt.append(' printf("=====GLOBAL OBJECT LIST (%lu total objs):\\n", numTotalObjs);')
910 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -0600911 header_txt.append(' printf(" ObjNode (%p) w/ %s obj 0x%" PRId64 " has pNextGlobal %p\\n", (void*)pTrav, string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.vkObj, (void*)pTrav->pNextGlobal);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700912 header_txt.append(' pTrav = pTrav->pNextGlobal;')
913 header_txt.append(' }')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -0500914 header_txt.append(' for (uint32_t i = 0; i < VkNumObjectType; i++) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700915 header_txt.append(' pTrav = pObjectHead[i];')
916 header_txt.append(' if (pTrav) {')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600917 header_txt.append(' printf("=====%s OBJECT LIST (%lu objs):\\n", string_VK_OBJECT_TYPE(pTrav->obj.objType), numObjs[i]);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700918 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -0600919 header_txt.append(' printf(" ObjNode (%p) w/ %s obj 0x%" PRId64 " has pNextObj %p\\n", (void*)pTrav, string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.vkObj, (void*)pTrav->pNextObj);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700920 header_txt.append(' pTrav = pTrav->pNextObj;')
921 header_txt.append(' }')
922 header_txt.append(' }')
923 header_txt.append(' }')
924 header_txt.append('}')
Tony Barbour96715312015-04-21 09:18:02 -0600925 header_txt.append('static void ll_insert_obj(VkObject vkObj, VK_OBJECT_TYPE objType) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700926 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -0600927 header_txt.append(' sprintf(str, "OBJ[%llu] : CREATE %s object 0x%" PRId64, object_track_index++, string_VK_OBJECT_TYPE(objType), vkObj);')
928 header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700929 header_txt.append(' objNode* pNewObjNode = (objNode*)malloc(sizeof(objNode));')
Tony Barbour96715312015-04-21 09:18:02 -0600930 header_txt.append(' pNewObjNode->obj.vkObj = vkObj;')
Tobin Ehlisca915872014-11-18 11:28:33 -0700931 header_txt.append(' pNewObjNode->obj.objType = objType;')
Mark Lobodzinski40370872015-02-03 10:06:31 -0600932 header_txt.append(' pNewObjNode->obj.status = OBJSTATUS_NONE;')
Tobin Ehlisca915872014-11-18 11:28:33 -0700933 header_txt.append(' pNewObjNode->obj.numUses = 0;')
934 header_txt.append(' // insert at front of global list')
935 header_txt.append(' pNewObjNode->pNextGlobal = pGlobalHead;')
936 header_txt.append(' pGlobalHead = pNewObjNode;')
937 header_txt.append(' // insert at front of object list')
938 header_txt.append(' pNewObjNode->pNextObj = pObjectHead[objType];')
939 header_txt.append(' pObjectHead[objType] = pNewObjNode;')
940 header_txt.append(' // increment obj counts')
941 header_txt.append(' numObjs[objType]++;')
942 header_txt.append(' numTotalObjs++;')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600943 header_txt.append(' //sprintf(str, "OBJ_STAT : %lu total objs & %lu %s objs.", numTotalObjs, numObjs[objType], string_VK_OBJECT_TYPE(objType));')
Chia-I Wu85763e52014-12-16 11:02:06 +0800944 header_txt.append(' if (0) ll_print_lists();')
Tobin Ehlisca915872014-11-18 11:28:33 -0700945 header_txt.append('}')
Tony Barbour96715312015-04-21 09:18:02 -0600946 header_txt.append('static void ll_increment_use_count(VkObject vkObj, VK_OBJECT_TYPE objType) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700947 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600948 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -0600949 header_txt.append(' if (pTrav->obj.vkObj == vkObj) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700950 header_txt.append(' pTrav->obj.numUses++;')
951 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -0600952 header_txt.append(' sprintf(str, "OBJ[%llu] : USING %s object 0x%" PRId64 " (%lu total uses)", object_track_index++, string_VK_OBJECT_TYPE(objType), vkObj, pTrav->obj.numUses);')
953 header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700954 header_txt.append(' return;')
955 header_txt.append(' }')
956 header_txt.append(' pTrav = pTrav->pNextObj;')
957 header_txt.append(' }')
958 header_txt.append(' // If we do not find obj, insert it and then increment count')
959 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -0600960 header_txt.append(' sprintf(str, "Unable to increment count for obj 0x%" PRId64 ", will add to list as %s type and increment count", vkObj, string_VK_OBJECT_TYPE(objType));')
961 header_txt.append(' layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700962 header_txt.append('')
Tony Barbour96715312015-04-21 09:18:02 -0600963 header_txt.append(' ll_insert_obj(vkObj, objType);')
964 header_txt.append(' ll_increment_use_count(vkObj, objType);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700965 header_txt.append('}')
966 header_txt.append('// We usually do not know Obj type when we destroy it so have to fetch')
967 header_txt.append('// Type from global list w/ ll_destroy_obj()')
968 header_txt.append('// and then do the full removal from both lists w/ ll_remove_obj_type()')
Tony Barbour96715312015-04-21 09:18:02 -0600969 header_txt.append('static void ll_remove_obj_type(VkObject vkObj, VK_OBJECT_TYPE objType) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700970 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
971 header_txt.append(' objNode *pPrev = pObjectHead[objType];')
972 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -0600973 header_txt.append(' if (pTrav->obj.vkObj == vkObj) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700974 header_txt.append(' pPrev->pNextObj = pTrav->pNextObj;')
975 header_txt.append(' // update HEAD of Obj list as needed')
976 header_txt.append(' if (pObjectHead[objType] == pTrav)')
977 header_txt.append(' pObjectHead[objType] = pTrav->pNextObj;')
978 header_txt.append(' assert(numObjs[objType] > 0);')
979 header_txt.append(' numObjs[objType]--;')
980 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -0600981 header_txt.append(' sprintf(str, "OBJ[%llu] : DESTROY %s object 0x%" PRId64, object_track_index++, string_VK_OBJECT_TYPE(objType), vkObj);')
982 header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600983 header_txt.append(' return;')
984 header_txt.append(' }')
985 header_txt.append(' pPrev = pTrav;')
Tobin Ehlisca915872014-11-18 11:28:33 -0700986 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600987 header_txt.append(' }')
Tobin Ehlisca915872014-11-18 11:28:33 -0700988 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -0600989 header_txt.append(' sprintf(str, "OBJ INTERNAL ERROR : Obj 0x%" PRId64 " was in global list but not in %s list", vkObj, string_VK_OBJECT_TYPE(objType));')
990 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_INTERNAL_ERROR, "OBJTRACK", str);')
Tobin Ehlisca915872014-11-18 11:28:33 -0700991 header_txt.append('}')
992 header_txt.append('// Parse global list to find obj type, then remove obj from obj type list, finally')
993 header_txt.append('// remove obj from global list')
Tony Barbour96715312015-04-21 09:18:02 -0600994 header_txt.append('static void ll_destroy_obj(VkObject vkObj) {')
Tobin Ehlisca915872014-11-18 11:28:33 -0700995 header_txt.append(' objNode *pTrav = pGlobalHead;')
996 header_txt.append(' objNode *pPrev = pGlobalHead;')
997 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -0600998 header_txt.append(' if (pTrav->obj.vkObj == vkObj) {')
999 header_txt.append(' ll_remove_obj_type(vkObj, pTrav->obj.objType);')
Tobin Ehlisca915872014-11-18 11:28:33 -07001000 header_txt.append(' pPrev->pNextGlobal = pTrav->pNextGlobal;')
1001 header_txt.append(' // update HEAD of global list if needed')
1002 header_txt.append(' if (pGlobalHead == pTrav)')
1003 header_txt.append(' pGlobalHead = pTrav->pNextGlobal;')
Tobin Ehlisca915872014-11-18 11:28:33 -07001004 header_txt.append(' assert(numTotalObjs > 0);')
1005 header_txt.append(' numTotalObjs--;')
1006 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -06001007 header_txt.append(' sprintf(str, "OBJ_STAT Removed %s obj 0x%" PRId64 " that was used %lu times (%lu total objs remain & %lu %s objs).", string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.vkObj, pTrav->obj.numUses, numTotalObjs, numObjs[pTrav->obj.objType], string_VK_OBJECT_TYPE(pTrav->obj.objType));')
1008 header_txt.append(' layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_NONE, "OBJTRACK", str);')
Tobin Ehlis36f1b462015-02-23 14:09:16 -07001009 header_txt.append(' free(pTrav);')
Tobin Ehlisca915872014-11-18 11:28:33 -07001010 header_txt.append(' return;')
1011 header_txt.append(' }')
1012 header_txt.append(' pPrev = pTrav;')
1013 header_txt.append(' pTrav = pTrav->pNextGlobal;')
1014 header_txt.append(' }')
1015 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -06001016 header_txt.append(' sprintf(str, "Unable to remove obj 0x%" PRId64 ". Was it created? Has it already been destroyed?", vkObj);')
1017 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_DESTROY_OBJECT_FAILED, "OBJTRACK", str);')
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001018 header_txt.append('}')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001019 header_txt.append('// Set selected flag state for an object node')
Tony Barbour96715312015-04-21 09:18:02 -06001020 header_txt.append('static void set_status(VkObject vkObj, VK_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
1021 header_txt.append(' if (vkObj != VK_NULL_HANDLE) {')
Mark Lobodzinski709e16d2015-02-09 10:16:20 -06001022 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1023 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -06001024 header_txt.append(' if (pTrav->obj.vkObj == vkObj) {')
Mark Lobodzinski709e16d2015-02-09 10:16:20 -06001025 header_txt.append(' pTrav->obj.status |= status_flag;')
1026 header_txt.append(' return;')
1027 header_txt.append(' }')
1028 header_txt.append(' pTrav = pTrav->pNextObj;')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001029 header_txt.append(' }')
Mark Lobodzinski709e16d2015-02-09 10:16:20 -06001030 header_txt.append(' // If we do not find it print an error')
1031 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -06001032 header_txt.append(' sprintf(str, "Unable to set status for non-existent object 0x%" PRId64 " of %s type", vkObj, string_VK_OBJECT_TYPE(objType));')
1033 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Mark Lobodzinski709e16d2015-02-09 10:16:20 -06001034 header_txt.append(' }');
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001035 header_txt.append('}')
1036 header_txt.append('')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001037 header_txt.append('// Track selected state for an object node')
Tony Barbour96715312015-04-21 09:18:02 -06001038 header_txt.append('static void track_object_status(VkObject vkObj, VkStateBindPoint stateBindPoint) {')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -05001039 header_txt.append(' objNode *pTrav = pObjectHead[VkObjectTypeCmdBuffer];')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001040 header_txt.append('')
1041 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -06001042 header_txt.append(' if (pTrav->obj.vkObj == vkObj) {')
Tony Barbourd1c35722015-04-16 15:59:00 -06001043 header_txt.append(' if (stateBindPoint == VK_STATE_BIND_POINT_VIEWPORT) {')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001044 header_txt.append(' pTrav->obj.status |= OBJSTATUS_VIEWPORT_BOUND;')
Tony Barbourd1c35722015-04-16 15:59:00 -06001045 header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_RASTER) {')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001046 header_txt.append(' pTrav->obj.status |= OBJSTATUS_RASTER_BOUND;')
Tony Barbourd1c35722015-04-16 15:59:00 -06001047 header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_COLOR_BLEND) {')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001048 header_txt.append(' pTrav->obj.status |= OBJSTATUS_COLOR_BLEND_BOUND;')
Tony Barbourd1c35722015-04-16 15:59:00 -06001049 header_txt.append(' } else if (stateBindPoint == VK_STATE_BIND_POINT_DEPTH_STENCIL) {')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001050 header_txt.append(' pTrav->obj.status |= OBJSTATUS_DEPTH_STENCIL_BOUND;')
1051 header_txt.append(' }')
1052 header_txt.append(' return;')
1053 header_txt.append(' }')
1054 header_txt.append(' pTrav = pTrav->pNextObj;')
1055 header_txt.append(' }')
1056 header_txt.append(' // If we do not find it print an error')
1057 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -06001058 header_txt.append(' sprintf(str, "Unable to track status for non-existent Command Buffer object 0x%" PRId64, vkObj);')
1059 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001060 header_txt.append('}')
1061 header_txt.append('')
1062 header_txt.append('// Reset selected flag state for an object node')
Tony Barbour96715312015-04-21 09:18:02 -06001063 header_txt.append('static void reset_status(VkObject vkObj, VK_OBJECT_TYPE objType, OBJECT_STATUS status_flag) {')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001064 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1065 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -06001066 header_txt.append(' if (pTrav->obj.vkObj == vkObj) {')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001067 header_txt.append(' pTrav->obj.status &= ~status_flag;')
1068 header_txt.append(' return;')
1069 header_txt.append(' }')
1070 header_txt.append(' pTrav = pTrav->pNextObj;')
1071 header_txt.append(' }')
1072 header_txt.append(' // If we do not find it print an error')
1073 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -06001074 header_txt.append(' sprintf(str, "Unable to reset status for non-existent object 0x%" PRId64 " of %s type", vkObj, string_VK_OBJECT_TYPE(objType));')
1075 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001076 header_txt.append('}')
1077 header_txt.append('')
1078 header_txt.append('// Check object status for selected flag state')
Tony Barbour96715312015-04-21 09:18:02 -06001079 header_txt.append('static bool32_t validate_status(VkObject vkObj, VK_OBJECT_TYPE objType, OBJECT_STATUS status_mask, OBJECT_STATUS status_flag, VK_DBG_MSG_TYPE error_level, OBJECT_TRACK_ERROR error_code, char* fail_msg) {')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001080 header_txt.append(' objNode *pTrav = pObjectHead[objType];')
1081 header_txt.append(' while (pTrav) {')
Tony Barbour96715312015-04-21 09:18:02 -06001082 header_txt.append(' if (pTrav->obj.vkObj == vkObj) {')
Mark Lobodzinski4988dea2015-02-03 11:52:26 -06001083 header_txt.append(' if ((pTrav->obj.status & status_mask) != status_flag) {')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001084 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -06001085 header_txt.append(' sprintf(str, "OBJECT VALIDATION WARNING: %s object 0x%" PRId64 ": %s", string_VK_OBJECT_TYPE(objType), vkObj, fail_msg);')
1086 header_txt.append(' layerCbMsg(error_level, VK_VALIDATION_LEVEL_0, vkObj, 0, error_code, "OBJTRACK", str);')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001087 header_txt.append(' return VK_FALSE;')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001088 header_txt.append(' }')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001089 header_txt.append(' return VK_TRUE;')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001090 header_txt.append(' }')
1091 header_txt.append(' pTrav = pTrav->pNextObj;')
1092 header_txt.append(' }')
Chia-I Wuf8693382015-04-16 22:02:10 +08001093 header_txt.append(' if (objType != VkObjectTypeSwapChainImageWSI &&')
1094 header_txt.append(' objType != VkObjectTypeSwapChainMemoryWSI) {')
Mark Lobodzinski78a21972015-03-05 12:39:33 -06001095 header_txt.append(' // If we do not find it print an error')
1096 header_txt.append(' char str[1024];')
Tony Barbour96715312015-04-21 09:18:02 -06001097 header_txt.append(' sprintf(str, "Unable to obtain status for non-existent object 0x%" PRId64 " of %s type", vkObj, string_VK_OBJECT_TYPE(objType));')
1098 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, vkObj, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);')
Mark Lobodzinski78a21972015-03-05 12:39:33 -06001099 header_txt.append(' }')
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001100 header_txt.append(' return VK_FALSE;')
Tobin Ehlis91ce77e2015-01-16 08:56:30 -07001101 header_txt.append('}')
Mark Lobodzinski40370872015-02-03 10:06:31 -06001102 header_txt.append('')
Tony Barbour96715312015-04-21 09:18:02 -06001103 header_txt.append('static void validate_draw_state_flags(VkObject vkObj) {')
1104 header_txt.append(' validate_status(vkObj, VkObjectTypeCmdBuffer, OBJSTATUS_VIEWPORT_BOUND, OBJSTATUS_VIEWPORT_BOUND, VK_DBG_MSG_ERROR, OBJTRACK_VIEWPORT_NOT_BOUND, "Viewport object not bound to this command buffer");')
1105 header_txt.append(' validate_status(vkObj, VkObjectTypeCmdBuffer, OBJSTATUS_RASTER_BOUND, OBJSTATUS_RASTER_BOUND, VK_DBG_MSG_ERROR, OBJTRACK_RASTER_NOT_BOUND, "Raster object not bound to this command buffer");')
1106 header_txt.append(' validate_status(vkObj, VkObjectTypeCmdBuffer, OBJSTATUS_COLOR_BLEND_BOUND, OBJSTATUS_COLOR_BLEND_BOUND, VK_DBG_MSG_UNKNOWN, OBJTRACK_COLOR_BLEND_NOT_BOUND, "Color-blend object not bound to this command buffer");')
1107 header_txt.append(' validate_status(vkObj, VkObjectTypeCmdBuffer, OBJSTATUS_DEPTH_STENCIL_BOUND, OBJSTATUS_DEPTH_STENCIL_BOUND, VK_DBG_MSG_UNKNOWN, OBJTRACK_DEPTH_STENCIL_NOT_BOUND, "Depth-stencil object not bound to this command buffer");')
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -05001108 header_txt.append('}')
1109 header_txt.append('')
Courtney Goeltzenleuchterc951e742015-04-07 16:23:00 -06001110 header_txt.append('static void setGpuQueueInfoState(void *pData) {')
Tony Barbourd1c35722015-04-16 15:59:00 -06001111 header_txt.append(' maxMemReferences = ((VkPhysicalDeviceQueueProperties *)pData)->maxMemReferences;')
Mark Lobodzinskiaae93e52015-02-09 10:20:53 -06001112 header_txt.append('}')
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001113 return "\n".join(header_txt)
1114
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -06001115 def generate_intercept(self, proto, qual):
Jon Ashburn9fd4cc42015-04-10 14:33:07 -06001116 if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback', 'GetGlobalExtensionInfo' ]:
Mike Stroyan00087e62015-04-03 14:39:16 -06001117 # use default version
1118 return None
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001119 obj_type_mapping = {base_t : base_t.replace("Vk", "VkObjectType") for base_t in vulkan.object_type_list}
Mike Stroyan00087e62015-04-03 14:39:16 -06001120 # For the various "super-types" we have to use function to distinguish sub type
Mike Stroyanb050c682015-04-17 12:36:38 -06001121 for obj_type in ["VK_BASE_OBJECT", "VK_OBJECT", "VK_DYNAMIC_STATE_OBJECT", "VkObject"]:
Mike Stroyan00087e62015-04-03 14:39:16 -06001122 obj_type_mapping[obj_type] = "ll_get_obj_type(object)"
1123
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001124 decl = proto.c_func(prefix="vk", attr="VKAPI")
Mike Stroyan00087e62015-04-03 14:39:16 -06001125 param0_name = proto.params[0].name
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -06001126 p0_type = proto.params[0].ty.strip('*').replace('const ', '')
Mike Stroyan00087e62015-04-03 14:39:16 -06001127 create_line = ''
1128 destroy_line = ''
1129 funcs = []
1130 # Special cases for API funcs that don't use an object as first arg
Chia-I Wuf8693382015-04-16 22:02:10 +08001131 if True in [no_use_proto in proto.name for no_use_proto in ['GlobalOption', 'CreateInstance', 'QueueSubmit', 'QueueAddMemReferences', 'QueueRemoveMemReferences', 'QueueWaitIdle', 'GetGlobalExtensionInfo', 'CreateDevice', 'GetGpuInfo', 'QueueSignalSemaphore', 'QueueWaitSemaphore']]:
Mike Stroyan00087e62015-04-03 14:39:16 -06001132 using_line = ''
1133 else:
1134 using_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Tony Barbourfc15ff82015-04-20 16:28:46 -06001135 using_line += ' ll_increment_use_count(%s, %s);\n' % (param0_name, obj_type_mapping[p0_type])
Mike Stroyan00087e62015-04-03 14:39:16 -06001136 using_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1137 if 'QueueSubmit' in proto.name:
Tony Barbourfc15ff82015-04-20 16:28:46 -06001138 using_line += ' set_status(fence, VkObjectTypeFence, OBJSTATUS_FENCE_IS_SUBMITTED);\n'
Courtney Goeltzenleuchter97b75232015-04-07 17:13:38 -06001139 using_line += ' // TODO: Fix for updated memory reference mechanism\n'
1140 using_line += ' // validate_memory_mapping_status(pMemRefs, memRefCount);\n'
1141 using_line += ' // validate_mem_ref_count(memRefCount);\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001142 elif 'GetFenceStatus' in proto.name:
1143 using_line += ' // Warn if submitted_flag is not set\n'
Tony Barbourfc15ff82015-04-20 16:28:46 -06001144 using_line += ' validate_status(fence, VkObjectTypeFence, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, VK_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
Mark Lobodzinski0d067d12015-04-22 15:06:12 -06001145 elif 'WaitForFences' in proto.name:
1146 using_line += ' // Warn if waiting on unsubmitted fence\n'
1147 using_line += ' for (uint32_t i = 0; i < fenceCount; i++) {\n'
1148 using_line += ' validate_status(pFences[i], VkObjectTypeFence, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, VK_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Waiting for Unsubmitted Fence");\n'
1149 using_line += ' }\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001150 elif 'EndCommandBuffer' in proto.name:
Tony Barbourfc15ff82015-04-20 16:28:46 -06001151 using_line += ' reset_status(cmdBuffer, VkObjectTypeCmdBuffer, (OBJSTATUS_VIEWPORT_BOUND |\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001152 using_line += ' OBJSTATUS_RASTER_BOUND |\n'
1153 using_line += ' OBJSTATUS_COLOR_BLEND_BOUND |\n'
1154 using_line += ' OBJSTATUS_DEPTH_STENCIL_BOUND));\n'
1155 elif 'CmdBindDynamicStateObject' in proto.name:
Tony Barbourfc15ff82015-04-20 16:28:46 -06001156 using_line += ' track_object_status(cmdBuffer, stateBindPoint);\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001157 elif 'CmdDraw' in proto.name:
Tony Barbourfc15ff82015-04-20 16:28:46 -06001158 using_line += ' validate_draw_state_flags(cmdBuffer);\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001159 elif 'MapMemory' in proto.name:
Tony Barbourfc15ff82015-04-20 16:28:46 -06001160 using_line += ' set_status(mem, VkObjectTypeDeviceMemory, OBJSTATUS_GPU_MEM_MAPPED);\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001161 elif 'UnmapMemory' in proto.name:
Tony Barbourfc15ff82015-04-20 16:28:46 -06001162 using_line += ' reset_status(mem, VkObjectTypeDeviceMemory, OBJSTATUS_GPU_MEM_MAPPED);\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001163 if 'AllocDescriptor' in proto.name: # Allocates array of DSs
1164 create_line = ' for (uint32_t i = 0; i < *pCount; i++) {\n'
1165 create_line += ' loader_platform_thread_lock_mutex(&objLock);\n'
Tony Barbourfc15ff82015-04-20 16:28:46 -06001166 create_line += ' ll_insert_obj(pDescriptorSets[i], VkObjectTypeDescriptorSet);\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001167 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1168 create_line += ' }\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001169 elif 'Create' in proto.name or 'Alloc' in proto.name:
1170 create_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Tony Barbourfc15ff82015-04-20 16:28:46 -06001171 create_line += ' ll_insert_obj(*%s, %s);\n' % (proto.params[-1].name, obj_type_mapping[proto.params[-1].ty.strip('*').replace('const ', '')])
Mike Stroyan00087e62015-04-03 14:39:16 -06001172 create_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1173 if 'DestroyObject' in proto.name:
1174 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Mark Lobodzinski85e80da2015-04-21 17:15:36 -06001175 destroy_line += ' ll_destroy_obj(%s);\n' % (proto.params[2].name)
Mike Stroyan00087e62015-04-03 14:39:16 -06001176 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1177 using_line = ''
1178 else:
Mark Lobodzinski85e80da2015-04-21 17:15:36 -06001179 if 'Destroy' in proto.name:
Mike Stroyan00087e62015-04-03 14:39:16 -06001180 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Tony Barbourfc15ff82015-04-20 16:28:46 -06001181 destroy_line += ' ll_destroy_obj(%s);\n' % (param0_name)
Mike Stroyan00087e62015-04-03 14:39:16 -06001182 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1183 using_line = ''
Mark Lobodzinski85e80da2015-04-21 17:15:36 -06001184 else:
1185 if 'Free' in proto.name:
1186 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
1187 destroy_line += ' ll_destroy_obj(%s);\n' % (proto.params[1].name)
1188 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
1189 using_line = ''
Mike Stroyan00087e62015-04-03 14:39:16 -06001190 if 'DestroyDevice' in proto.name:
1191 destroy_line += ' // Report any remaining objects in LL\n objNode *pTrav = pGlobalHead;\n while (pTrav) {\n'
Chia-I Wuf8693382015-04-16 22:02:10 +08001192 destroy_line += ' if (pTrav->obj.objType == VkObjectTypeSwapChainImageWSI ||\n'
1193 destroy_line += ' pTrav->obj.objType == VkObjectTypeSwapChainMemoryWSI) {\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001194 destroy_line += ' objNode *pDel = pTrav;\n'
1195 destroy_line += ' pTrav = pTrav->pNextGlobal;\n'
Tony Barbour96715312015-04-21 09:18:02 -06001196 destroy_line += ' ll_destroy_obj((pDel->obj.vkObj));\n'
Tobin Ehlis857156d2015-04-17 13:07:30 -06001197 destroy_line += ' } else if ((pTrav->obj.objType == VkObjectTypePhysicalDevice) || (pTrav->obj.objType == VkObjectTypeQueue)) {\n'
Tobin Ehlisdf45de52015-04-17 13:00:55 -06001198 destroy_line += ' // Cannot destroy physical device so ignore\n'
1199 destroy_line += ' pTrav = pTrav->pNextGlobal;\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001200 destroy_line += ' } else {\n'
1201 destroy_line += ' char str[1024];\n'
Tony Barbour96715312015-04-21 09:18:02 -06001202 destroy_line += ' sprintf(str, "OBJ ERROR : %s object 0x%" PRId64 " has not been destroyed (was used %lu times).", string_VK_OBJECT_TYPE(pTrav->obj.objType), pTrav->obj.vkObj, pTrav->obj.numUses);\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001203 destroy_line += ' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, OBJTRACK_OBJECT_LEAK, "OBJTRACK", str);\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001204 destroy_line += ' pTrav = pTrav->pNextGlobal;\n'
1205 destroy_line += ' }\n'
1206 destroy_line += ' }\n'
Mark Lobodzinskiebc5cb42015-04-09 12:09:45 -05001207 destroy_line += ' // Clean up Queue\'s MemRef Linked Lists\n'
1208 destroy_line += ' destroyQueueMemRefLists();\n'
1209 if 'GetDeviceQueue' in proto.name:
1210 destroy_line = ' addQueueInfo(*pQueue);\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001211 ret_val = ''
1212 stmt = ''
1213 if proto.ret != "void":
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001214 ret_val = "VkResult result = "
Mike Stroyan00087e62015-04-03 14:39:16 -06001215 stmt = " return result;\n"
Mike Stroyan00087e62015-04-03 14:39:16 -06001216 if proto.name == "EnumerateLayers":
Mike Stroyan00087e62015-04-03 14:39:16 -06001217 funcs.append('%s%s\n'
1218 '{\n'
Tony Barbourfc15ff82015-04-20 16:28:46 -06001219 ' if (gpu != VK_NULL_HANDLE) {\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001220 ' %s'
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001221 ' pCurObj = (VkBaseLayerObject *) gpu;\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001222 ' loader_platform_thread_once(&tabOnce, init%s);\n'
1223 ' %snextTable.%s;\n'
1224 ' %s%s'
1225 ' %s'
1226 ' } else {\n'
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001227 ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001228 ' return VK_ERROR_INVALID_POINTER;\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001229 ' // This layer compatible with all GPUs\n'
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001230 ' *pLayerCount = 1;\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001231 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001232 ' return VK_SUCCESS;\n'
Mike Stroyan00087e62015-04-03 14:39:16 -06001233 ' }\n'
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001234 '}' % (qual, decl, using_line, self.layer_name, ret_val, proto.c_call(), create_line, destroy_line, stmt, self.layer_name))
Tony Barbourd1c35722015-04-16 15:59:00 -06001235 elif 'GetExtensionSupport' == proto.name:
1236 funcs.append('%s%s\n'
1237 '{\n'
1238 ' VkResult result;\n'
1239 ' /* This entrypoint is NOT going to init its own dispatch table since loader calls this early */\n'
1240 ' if (!strncmp(pExtName, "%s", strlen("%s")) ||\n'
1241 ' !strncmp(pExtName, "objTrackGetObjectCount", strlen("objTrackGetObjectCount")) ||\n'
1242 ' !strncmp(pExtName, "objTrackGetObjects", strlen("objTrackGetObjects")))\n'
1243 ' {\n'
1244 ' result = VK_SUCCESS;\n'
1245 ' } else if (nextTable.GetExtensionSupport != NULL)\n'
1246 ' {\n'
1247 ' %s'
1248 ' result = nextTable.%s;\n'
1249 ' } else\n'
1250 ' {\n'
1251 ' result = VK_ERROR_INVALID_EXTENSION;\n'
1252 ' }\n'
1253 '%s'
1254 '}' % (qual, decl, self.layer_name, self.layer_name, using_line, proto.c_call(), stmt))
1255 elif 'GetPhysicalDeviceInfo' in proto.name:
1256 gpu_state = ' if (infoType == VK_PHYSICAL_DEVICE_INFO_TYPE_QUEUE_PROPERTIES) {\n'
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001257 gpu_state += ' if (pData != NULL) {\n'
1258 gpu_state += ' setGpuQueueInfoState(pData);\n'
1259 gpu_state += ' }\n'
1260 gpu_state += ' }\n'
1261 funcs.append('%s%s\n'
1262 '{\n'
1263 '%s'
1264 ' pCurObj = (VkBaseLayerObject *) gpu;\n'
1265 ' loader_platform_thread_once(&tabOnce, init%s);\n'
1266 ' %snextTable.%s;\n'
1267 '%s%s'
1268 '%s'
1269 '%s'
1270 '}' % (qual, decl, using_line, self.layer_name, ret_val, proto.c_call(), create_line, destroy_line, gpu_state, stmt))
1271 else:
Mike Stroyan00087e62015-04-03 14:39:16 -06001272 funcs.append('%s%s\n'
1273 '{\n'
1274 '%s'
1275 ' %snextTable.%s;\n'
1276 '%s%s'
1277 '%s'
1278 '}' % (qual, decl, using_line, ret_val, proto.c_call(), create_line, destroy_line, stmt))
Mike Stroyan00087e62015-04-03 14:39:16 -06001279 return "\n\n".join(funcs)
1280
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001281 def generate_body(self):
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -06001282 self.layer_name = "ObjectTracker"
1283 body = [self._generate_layer_initialization(True, lockname='obj'),
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001284 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
Tobin Ehlisca915872014-11-18 11:28:33 -07001285 self._generate_extensions(),
Mike Stroyanbf237d72015-04-03 17:45:53 -06001286 self._generate_layer_gpa_function(extensions=['objTrackGetObjectCount', 'objTrackGetObjects'])]
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001287
1288 return "\n\n".join(body)
Courtney Goeltzenleuchterb412d212014-11-18 10:40:29 -07001289
Mike Stroyan3712d5c2015-04-02 11:59:05 -06001290class ThreadingSubcommand(Subcommand):
1291 def generate_header(self):
1292 header_txt = []
1293 header_txt.append('#include <stdio.h>')
1294 header_txt.append('#include <stdlib.h>')
1295 header_txt.append('#include <string.h>')
1296 header_txt.append('#include <unordered_map>')
1297 header_txt.append('#include "loader_platform.h"')
1298 header_txt.append('#include "vkLayer.h"')
1299 header_txt.append('#include "threading.h"')
1300 header_txt.append('#include "layers_config.h"')
1301 header_txt.append('#include "vk_enum_validate_helper.h"')
1302 header_txt.append('#include "vk_struct_validate_helper.h"')
1303 header_txt.append('//The following is #included again to catch certain OS-specific functions being used:')
1304 header_txt.append('#include "loader_platform.h"\n')
1305 header_txt.append('#include "layers_msg.h"\n')
1306 header_txt.append('static VkLayerDispatchTable nextTable;')
1307 header_txt.append('static VkBaseLayerObject *pCurObj;')
1308 header_txt.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(tabOnce);\n')
1309 header_txt.append('using namespace std;')
1310 header_txt.append('static unordered_map<int, void*> proxy_objectsInUse;\n')
1311 header_txt.append('static unordered_map<VkObject, loader_platform_thread_id> objectsInUse;\n')
1312 header_txt.append('static int threadingLockInitialized = 0;')
1313 header_txt.append('static loader_platform_thread_mutex threadingLock;')
1314 header_txt.append('static int printLockInitialized = 0;')
1315 header_txt.append('static loader_platform_thread_mutex printLock;\n')
1316 header_txt.append('')
1317 header_txt.append('static void useObject(VkObject object, const char* type)')
1318 header_txt.append('{')
1319 header_txt.append(' loader_platform_thread_id tid = loader_platform_get_thread_id();')
1320 header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);')
1321 header_txt.append(' if (objectsInUse.find(object) == objectsInUse.end()) {')
1322 header_txt.append(' objectsInUse[object] = tid;')
1323 header_txt.append(' } else {')
1324 header_txt.append(' if (objectsInUse[object] == tid) {')
1325 header_txt.append(' char str[1024];')
1326 header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is simultaneously used in thread %ld and thread %ld", type, objectsInUse[object], tid);')
1327 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, THREADING_CHECKER_MULTIPLE_THREADS, "THREADING", str);')
1328 header_txt.append(' } else {')
1329 header_txt.append(' char str[1024];')
1330 header_txt.append(' sprintf(str, "THREADING ERROR : object of type %s is recursively used in thread %ld", type, tid);')
1331 header_txt.append(' layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, 0, 0, THREADING_CHECKER_SINGLE_THREAD_REUSE, "THREADING", str);')
1332 header_txt.append(' }')
1333 header_txt.append(' }')
1334 header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);')
1335 header_txt.append('}')
1336 header_txt.append('static void finishUsingObject(VkObject object)')
1337 header_txt.append('{')
1338 header_txt.append(' // Object is no longer in use')
1339 header_txt.append(' loader_platform_thread_lock_mutex(&threadingLock);')
1340 header_txt.append(' objectsInUse.erase(object);')
1341 header_txt.append(' loader_platform_thread_unlock_mutex(&threadingLock);')
1342 header_txt.append('}')
1343 return "\n".join(header_txt)
1344
1345 def generate_intercept(self, proto, qual):
1346 if proto.name in [ 'DbgRegisterMsgCallback', 'DbgUnregisterMsgCallback' ]:
1347 # use default version
1348 return None
1349 decl = proto.c_func(prefix="vk", attr="VKAPI")
1350 ret_val = ''
1351 stmt = ''
1352 funcs = []
1353 if proto.ret != "void":
1354 ret_val = "VkResult result = "
1355 stmt = " return result;\n"
1356 if proto.name == "EnumerateLayers":
1357 funcs.append('%s%s\n'
1358 '{\n'
Mike Stroyan3712d5c2015-04-02 11:59:05 -06001359 ' if (gpu != NULL) {\n'
1360 ' pCurObj = (VkBaseLayerObject *) %s;\n'
1361 ' loader_platform_thread_once(&tabOnce, init%s);\n'
1362 ' %snextTable.%s;\n'
1363 ' fflush(stdout);\n'
1364 ' %s'
1365 ' } else {\n'
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001366 ' if (pLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)\n'
Mike Stroyan3712d5c2015-04-02 11:59:05 -06001367 ' return VK_ERROR_INVALID_POINTER;\n'
1368 ' // This layer compatible with all GPUs\n'
Courtney Goeltzenleuchterd9dc0c72015-04-20 11:04:54 -06001369 ' *pLayerCount = 1;\n'
Mike Stroyan3712d5c2015-04-02 11:59:05 -06001370 ' strncpy((char *) pOutLayers[0], "%s", maxStringSize);\n'
1371 ' return VK_SUCCESS;\n'
1372 ' }\n'
1373 '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, proto.c_call(), stmt, self.layer_name))
1374 # All functions that do a Get are thread safe
1375 elif 'Get' in proto.name:
1376 return None
1377 # All Wsi functions are thread safe
1378 elif 'WsiX11' in proto.name:
1379 return None
1380 # All functions that start with a device parameter are thread safe
1381 elif proto.params[0].ty in { "VkDevice" }:
1382 return None
1383 # Only watch core objects passed as first parameter
1384 elif proto.params[0].ty not in vulkan.core.objects:
1385 return None
Tony Barbourd1c35722015-04-16 15:59:00 -06001386 elif proto.params[0].ty != "VkPhysicalDevice":
Mike Stroyan3712d5c2015-04-02 11:59:05 -06001387 funcs.append('%s%s\n'
1388 '{\n'
1389 ' useObject((VkObject) %s, "%s");\n'
1390 ' %snextTable.%s;\n'
1391 ' finishUsingObject((VkObject) %s);\n'
1392 '%s'
1393 '}' % (qual, decl, proto.params[0].name, proto.params[0].ty, ret_val, proto.c_call(), proto.params[0].name, stmt))
1394 else:
1395 funcs.append('%s%s\n'
1396 '{\n'
1397 ' pCurObj = (VkBaseLayerObject *) %s;\n'
1398 ' loader_platform_thread_once(&tabOnce, init%s);\n'
1399 ' %snextTable.%s;\n'
1400 '%s'
1401 '}' % (qual, decl, proto.params[0].name, self.layer_name, ret_val, proto.c_call(), stmt))
1402 return "\n\n".join(funcs)
1403
1404 def generate_body(self):
1405 self.layer_name = "Threading"
1406 body = [self._generate_layer_initialization(True, lockname='threading'),
1407 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
1408 self._generate_layer_gpa_function()]
1409 return "\n\n".join(body)
1410
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001411def main():
1412 subcommands = {
1413 "layer-funcs" : LayerFuncsSubcommand,
1414 "layer-dispatch" : LayerDispatchSubcommand,
Tobin Ehlisa363cfa2014-11-25 16:59:27 -07001415 "Generic" : GenericLayerSubcommand,
Tobin Ehlise78dbd82015-04-09 09:19:36 -06001416 "APIDump" : APIDumpSubcommand,
Tobin Ehlisa363cfa2014-11-25 16:59:27 -07001417 "ObjectTracker" : ObjectTrackerSubcommand,
Mike Stroyan3712d5c2015-04-02 11:59:05 -06001418 "Threading" : ThreadingSubcommand,
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001419 }
1420
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001421 if len(sys.argv) < 3 or sys.argv[1] not in subcommands or not os.path.exists(sys.argv[2]):
1422 print("Usage: %s <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001423 print
Tobin Ehlis7e65d752015-01-15 17:51:52 -07001424 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001425 exit(1)
1426
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001427 hfp = vk_helper.HeaderFileParser(sys.argv[2])
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001428 hfp.parse()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001429 vk_helper.enum_val_dict = hfp.get_enum_val_dict()
1430 vk_helper.enum_type_dict = hfp.get_enum_type_dict()
1431 vk_helper.struct_dict = hfp.get_struct_dict()
1432 vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1433 vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1434 vk_helper.types_dict = hfp.get_types_dict()
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001435
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001436 subcmd = subcommands[sys.argv[1]](sys.argv[2:])
1437 subcmd.run()
1438
1439if __name__ == "__main__":
1440 main()