blob: 6d0e70fa29e611afd74b3f85c1553125765db521 [file] [log] [blame]
Mark Lobodzinskib13c4ea2016-05-02 13:11:50 -06001#!/usr/bin/env python3
Tobin Ehlis12076fc2014-10-22 09:06:33 -06002#
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06003# VK
Tobin Ehlis12076fc2014-10-22 09:06:33 -06004#
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07005# Copyright (c) 2015-2016 The Khronos Group Inc.
6# Copyright (c) 2015-2016 Valve Corporation
7# Copyright (c) 2015-2016 LunarG, Inc.
8# Copyright (c) 2015-2016 Google Inc.
Tobin Ehlis12076fc2014-10-22 09:06:33 -06009#
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010# Licensed under the Apache License, Version 2.0 (the "License");
11# you may not use this file except in compliance with the License.
12# You may obtain a copy of the License at
Tobin Ehlis12076fc2014-10-22 09:06:33 -060013#
Jon Ashburn3ebf1252016-04-19 11:30:31 -060014# http://www.apache.org/licenses/LICENSE-2.0
Tobin Ehlis12076fc2014-10-22 09:06:33 -060015#
Jon Ashburn3ebf1252016-04-19 11:30:31 -060016# Unless required by applicable law or agreed to in writing, software
17# distributed under the License is distributed on an "AS IS" BASIS,
18# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19# See the License for the specific language governing permissions and
20# limitations under the License.
Tobin Ehlis12076fc2014-10-22 09:06:33 -060021#
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070022# Author: Tobin Ehlis <tobine@google.com>
23# Author: Courtney Goeltzenleuchter <courtneygo@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060024# Author: Jon Ashburn <jon@lunarg.com>
25# Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070026# Author: Mike Stroyan <stroyan@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060027# Author: Tony Barbour <tony@LunarG.com>
Tobin Ehlisd34a4c52015-12-08 10:50:10 -070028# Author: Chia-I Wu <olv@google.com>
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +090029# Author: Gwan-gyeong Mun <kk.moon@samsung.com>
Tobin Ehlis12076fc2014-10-22 09:06:33 -060030
31import sys
Tobin Ehlis14ff0852014-12-17 17:44:50 -070032import os
Mark Lobodzinski7c75b852015-05-05 15:01:37 -050033import re
Tobin Ehlis12076fc2014-10-22 09:06:33 -060034
Courtney Goeltzenleuchterf53c3cb2015-04-14 14:55:44 -060035import vulkan
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036import vk_helper
Tobin Ehlis08fafd02015-06-12 12:49:01 -060037from source_line_info import sourcelineinfo
Tobin Ehlis154e0462015-08-26 11:22:09 -060038from collections import defaultdict
Tobin Ehlis12076fc2014-10-22 09:06:33 -060039
Jon Ashburn95a77ba2015-05-15 15:09:35 -060040def proto_is_global(proto):
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070041 global_function_names = [
42 "CreateInstance",
43 "EnumerateInstanceLayerProperties",
44 "EnumerateInstanceExtensionProperties",
45 "EnumerateDeviceLayerProperties",
46 "EnumerateDeviceExtensionProperties",
47 "CreateXcbSurfaceKHR",
Jon Ashburn00dc7412016-01-07 16:13:06 -070048 "GetPhysicalDeviceXcbPresentationSupportKHR",
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070049 "CreateXlibSurfaceKHR",
Jon Ashburn00dc7412016-01-07 16:13:06 -070050 "GetPhysicalDeviceXlibPresentationSupportKHR",
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070051 "CreateWaylandSurfaceKHR",
Jon Ashburn00dc7412016-01-07 16:13:06 -070052 "GetPhysicalDeviceWaylandPresentationSupportKHR",
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070053 "CreateMirSurfaceKHR",
Jon Ashburn00dc7412016-01-07 16:13:06 -070054 "GetPhysicalDeviceMirPresentationSupportKHR",
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070055 "CreateAndroidSurfaceKHR",
56 "CreateWin32SurfaceKHR",
Jon Ashburn00dc7412016-01-07 16:13:06 -070057 "GetPhysicalDeviceWin32PresentationSupportKHR"
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070058 ]
59 if proto.params[0].ty == "VkInstance" or proto.params[0].ty == "VkPhysicalDevice" or proto.name in global_function_names:
Jon Ashburn95a77ba2015-05-15 15:09:35 -060060 return True
61 else:
62 return False
63
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -070064def wsi_name(ext_name):
65 wsi_prefix = ""
66 if 'Xcb' in ext_name:
67 wsi_prefix = 'XCB'
68 elif 'Xlib' in ext_name:
69 wsi_prefix = 'XLIB'
70 elif 'Win32' in ext_name:
71 wsi_prefix = 'WIN32'
72 elif 'Mir' in ext_name:
73 wsi_prefix = 'MIR'
74 elif 'Wayland' in ext_name:
75 wsi_prefix = 'WAYLAND'
76 elif 'Android' in ext_name:
77 wsi_prefix = 'ANDROID'
78 else:
79 wsi_prefix = ''
80 return wsi_prefix
81
82def wsi_ifdef(ext_name):
83 wsi_prefix = wsi_name(ext_name)
84 if not wsi_prefix:
85 return ''
86 else:
87 return "#ifdef VK_USE_PLATFORM_%s_KHR" % wsi_prefix
88
89def wsi_endif(ext_name):
90 wsi_prefix = wsi_name(ext_name)
91 if not wsi_prefix:
92 return ''
93 else:
94 return "#endif // VK_USE_PLATFORM_%s_KHR" % wsi_prefix
95
Mike Stroyan938c2532015-04-03 13:58:35 -060096def generate_get_proc_addr_check(name):
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060097 return " if (!%s || %s[0] != 'v' || %s[1] != 'k')\n" \
98 " return NULL;" % ((name,) * 3)
Mike Stroyan938c2532015-04-03 13:58:35 -060099
Mark Lobodzinski7c75b852015-05-05 15:01:37 -0500100def ucc_to_U_C_C(CamelCase):
101 temp = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', CamelCase)
102 return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).upper()
103
Tobin Ehlis65f44e42016-01-05 09:46:03 -0700104# Parse complete struct chain and add any new ndo_uses to the dict
105def gather_object_uses_in_struct(obj_list, struct_type):
106 struct_uses = {}
107 if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict:
108 struct_type = vk_helper.typedef_rev_dict[struct_type]
109 # Parse elements of this struct param to identify objects and/or arrays of objects
110 for m in sorted(vk_helper.struct_dict[struct_type]):
111 array_len = "%s" % (str(vk_helper.struct_dict[struct_type][m]['array_size']))
112 base_type = vk_helper.struct_dict[struct_type][m]['type']
113 mem_name = vk_helper.struct_dict[struct_type][m]['name']
114 if array_len != '0':
115 mem_name = "%s[%s]" % (mem_name, array_len)
116 if base_type in obj_list:
117 #if array_len not in ndo_uses:
118 # struct_uses[array_len] = []
119 #struct_uses[array_len].append("%s%s,%s" % (name_prefix, struct_name, base_type))
120 struct_uses[mem_name] = base_type
121 elif vk_helper.is_type(base_type, 'struct'):
122 sub_uses = gather_object_uses_in_struct(obj_list, base_type)
123 if len(sub_uses) > 0:
124 struct_uses[mem_name] = sub_uses
125 return struct_uses
126
127# For the given list of object types, Parse the given list of params
128# and return dict of params that use one of the obj_list types
129# Format of the dict is that terminal elements have <name>,<type>
130# non-terminal elements will have <name>[<array_size>]
131# TODO : This analysis could be done up-front at vk_helper time
132def get_object_uses(obj_list, params):
133 obj_uses = {}
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -0700134 local_decls = {}
Tobin Ehlis65f44e42016-01-05 09:46:03 -0700135 param_count = 'NONE' # track params that give array sizes
136 for p in params:
137 base_type = p.ty.replace('const ', '').strip('*')
138 array_len = ''
139 is_ptr = False
140 if 'count' in p.name.lower():
141 param_count = p.name
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -0700142 ptr_txt = ''
Tobin Ehlis65f44e42016-01-05 09:46:03 -0700143 if '*' in p.ty:
144 is_ptr = True
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -0700145 ptr_txt = '*'
Tobin Ehlis65f44e42016-01-05 09:46:03 -0700146 if base_type in obj_list:
147 if is_ptr and 'const' in p.ty and param_count != 'NONE':
148 array_len = "[%s]" % param_count
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -0700149 # Non-arrays we can overwrite in place, but need local decl for arrays
150 local_decls[p.name] = '%s%s' % (base_type, ptr_txt)
Tobin Ehlis65f44e42016-01-05 09:46:03 -0700151 #if array_len not in obj_uses:
152 # obj_uses[array_len] = {}
153 # obj_uses[array_len][p.name] = base_type
154 obj_uses["%s%s" % (p.name, array_len)] = base_type
155 elif vk_helper.is_type(base_type, 'struct'):
156 struct_name = p.name
157 if 'NONE' != param_count:
158 struct_name = "%s[%s]" % (struct_name, param_count)
159 struct_uses = gather_object_uses_in_struct(obj_list, base_type)
160 if len(struct_uses) > 0:
161 obj_uses[struct_name] = struct_uses
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -0700162 # This is a top-level struct w/ uses below it, so need local decl
163 local_decls['%s' % (p.name)] = '%s%s' % (base_type, ptr_txt)
164 return (obj_uses, local_decls)
Tobin Ehlis65f44e42016-01-05 09:46:03 -0700165
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600166class Subcommand(object):
Jamie Madilldbda66b2016-05-10 07:36:20 -0700167 def __init__(self, outfile):
168 self.outfile = outfile
Courtney Goeltzenleuchterf53c3cb2015-04-14 14:55:44 -0600169 self.headers = vulkan.headers
170 self.protos = vulkan.protos
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600171 self.no_addr = False
172 self.layer_name = ""
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600173 self.lineinfo = sourcelineinfo()
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +0900174 self.wsi = sys.argv[1]
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600175
176 def run(self):
Jamie Madilldbda66b2016-05-10 07:36:20 -0700177 if self.outfile:
178 with open(self.outfile, "w") as outfile:
179 outfile.write(self.generate())
180 else:
181 print(self.generate())
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600182
183 def generate(self):
184 copyright = self.generate_copyright()
185 header = self.generate_header()
186 body = self.generate_body()
187 footer = self.generate_footer()
188
189 contents = []
190 if copyright:
191 contents.append(copyright)
192 if header:
193 contents.append(header)
194 if body:
195 contents.append(body)
196 if footer:
197 contents.append(footer)
198
199 return "\n\n".join(contents)
200
201 def generate_copyright(self):
202 return """/* THIS FILE IS GENERATED. DO NOT EDIT. */
203
204/*
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -0700205 * Copyright (c) 2015-2016 The Khronos Group Inc.
206 * Copyright (c) 2015-2016 Valve Corporation
207 * Copyright (c) 2015-2016 LunarG, Inc.
Tobin Ehlis10ba1de2016-04-13 12:59:43 -0600208 * Copyright (c) 2015-2016 Google, Inc.
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600209 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -0600210 * Licensed under the Apache License, Version 2.0 (the "License");
211 * you may not use this file except in compliance with the License.
212 * You may obtain a copy of the License at
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600213 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -0600214 * http://www.apache.org/licenses/LICENSE-2.0
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600215 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -0600216 * Unless required by applicable law or agreed to in writing, software
217 * distributed under the License is distributed on an "AS IS" BASIS,
218 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
219 * See the License for the specific language governing permissions and
220 * limitations under the License.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -0600221 *
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700222 * Author: Tobin Ehlis <tobine@google.com>
223 * Author: Courtney Goeltzenleuchter <courtneygo@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -0600224 * Author: Jon Ashburn <jon@lunarg.com>
225 * Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700226 * Author: Mike Stroyan <stroyan@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -0600227 * Author: Tony Barbour <tony@LunarG.com>
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600228 */"""
229
230 def generate_header(self):
231 return "\n".join(["#include <" + h + ">" for h in self.headers])
232
233 def generate_body(self):
234 pass
235
236 def generate_footer(self):
237 pass
238
239 # Return set of printf '%' qualifier and input to that qualifier
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600240 def _get_printf_params(self, vk_type, name, output_param, cpp=False):
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600241 # TODO : Need ENUM and STRUCT checks here
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600242 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 -0600243 return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name))
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600244 if "char*" == vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600245 return ("%s", name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600246 if "uint64" in vk_type:
247 if '*' in vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600248 return ("%lu", "*%s" % name)
249 return ("%lu", name)
Tobin Ehlisa30e7e52015-07-06 14:02:36 -0600250 if vk_type.strip('*') in vulkan.object_non_dispatch_list:
251 if '*' in vk_type:
Chia-I Wue2fc5522015-10-26 20:04:44 +0800252 return ("%lu", "%s" % name)
253 return ("%lu", "%s" % name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600254 if "size" in vk_type:
255 if '*' in vk_type:
Mark Lobodzinskia1456492015-10-06 09:57:52 -0600256 return ("%lu", "(unsigned long)*%s" % name)
257 return ("%lu", "(unsigned long)%s" % name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600258 if "float" in vk_type:
259 if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis99f88672015-01-10 12:42:41 -0700260 if cpp:
261 return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name))
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600262 return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
263 return ("%f", name)
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600264 if "bool" in vk_type.lower() or 'xcb_randr_crtc_t' in vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600265 return ("%u", name)
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600266 if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]:
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600267 if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis99f88672015-01-10 12:42:41 -0700268 if cpp:
269 return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name))
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600270 return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600271 if '*' in vk_type:
Tobin Ehlisd2b88e82015-02-04 15:15:11 -0700272 if 'pUserData' == name:
273 return ("%i", "((pUserData == 0) ? 0 : *(pUserData))")
Tobin Ehlisc62cb892015-04-17 13:26:33 -0600274 if 'const' in vk_type.lower():
Mark Muelleraab36502016-05-03 13:17:29 -0600275 return ("0x%p", "(void*)(%s)" % name)
Jon Ashburn52f79b52014-12-12 16:10:45 -0700276 return ("%i", "*(%s)" % name)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600277 return ("%i", name)
Tobin Ehlis3a1cc8d2014-11-11 17:28:22 -0700278 # 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 -0600279 if "VkFormat" == vk_type:
Tobin Ehlis99f88672015-01-10 12:42:41 -0700280 if cpp:
Mark Muelleraab36502016-05-03 13:17:29 -0600281 return ("0x%p", "&%s" % name)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800282 return ("{%s.channelFormat = %%s, %s.numericFormat = %%s}" % (name, name), "string_VK_COLOR_COMPONENT_FORMAT(%s.channelFormat), string_VK_FORMAT_RANGE_SIZE(%s.numericFormat)" % (name, name))
Tobin Ehlise7271572014-11-19 15:52:46 -0700283 if output_param:
Mark Muelleraab36502016-05-03 13:17:29 -0600284 return ("0x%p", "(void*)*%s" % name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600285 if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type:
Mark Muelleraab36502016-05-03 13:17:29 -0600286 return ("0x%p", "(void*)(&%s)" % name)
287 return ("0x%p", "(void*)(%s)" % name)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600288
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600289 def _gen_create_msg_callback(self):
Tobin Ehlise8185062014-12-17 08:01:59 -0700290 r_body = []
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600291 r_body.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700292 r_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(')
293 r_body.append(' VkInstance instance,')
294 r_body.append(' const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,')
295 r_body.append(' const VkAllocationCallbacks* pAllocator,')
296 r_body.append(' VkDebugReportCallbackEXT* pCallback)')
Tobin Ehlise8185062014-12-17 08:01:59 -0700297 r_body.append('{')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600298 # Switch to this code section for the new per-instance storage and debug callbacks
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600299 if self.layer_name in ['object_tracker', 'unique_objects']:
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600300 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700301 r_body.append(' VkResult result = pInstanceTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600302 r_body.append(' if (VK_SUCCESS == result) {')
303 r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);')
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700304 r_body.append(' result = layer_create_msg_callback(my_data->report_data,')
305 r_body.append(' pCreateInfo,')
306 r_body.append(' pAllocator,')
307 r_body.append(' pCallback);')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600308 r_body.append(' }')
309 r_body.append(' return result;')
310 else:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700311 r_body.append(' VkResult result = instance_dispatch_table(instance)->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);')
Jon Ashburn3a278b72015-10-06 17:05:21 -0600312 r_body.append(' if (VK_SUCCESS == result) {')
313 r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);')
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700314 r_body.append(' result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pCallback);')
Jon Ashburn3a278b72015-10-06 17:05:21 -0600315 r_body.append(' }')
316 r_body.append(' return result;')
Tobin Ehlise8185062014-12-17 08:01:59 -0700317 r_body.append('}')
318 return "\n".join(r_body)
319
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600320 def _gen_destroy_msg_callback(self):
321 r_body = []
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600322 r_body.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700323 r_body.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback, const VkAllocationCallbacks *pAllocator)')
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600324 r_body.append('{')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600325 # Switch to this code section for the new per-instance storage and debug callbacks
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600326 if self.layer_name in ['object_tracker', 'unique_objects']:
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600327 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600328 else:
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700329 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700330 r_body.append(' pInstanceTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);')
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700331 r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);')
332 r_body.append(' layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);')
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600333 r_body.append('}')
334 return "\n".join(r_body)
Tobin Ehlise8185062014-12-17 08:01:59 -0700335
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700336 def _gen_debug_report_msg(self):
337 r_body = []
338 r_body.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700339 r_body.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object, size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg)')
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700340 r_body.append('{')
341 # Switch to this code section for the new per-instance storage and debug callbacks
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600342 if self.layer_name == 'object_tracker':
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700343 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
344 else:
345 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700346 r_body.append(' pInstanceTable->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);')
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700347 r_body.append('}')
348 return "\n".join(r_body)
349
Jon Ashburn1f32a442016-02-02 13:13:01 -0700350 def _gen_layer_get_global_extension_props(self, layer="object_tracker"):
Tony Barbour59a47322015-06-24 16:06:58 -0600351 ggep_body = []
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600352 # generated layers do not provide any global extensions
353 ggep_body.append('%s' % self.lineinfo.get())
354
355 ggep_body.append('')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600356 if self.layer_name == 'object_tracker':
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700357 ggep_body.append('static const VkExtensionProperties instance_extensions[] = {')
358 ggep_body.append(' {')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700359 ggep_body.append(' VK_EXT_DEBUG_REPORT_EXTENSION_NAME,')
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -0700360 ggep_body.append(' VK_EXT_DEBUG_REPORT_SPEC_VERSION')
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700361 ggep_body.append(' }')
362 ggep_body.append('};')
Chia-I Wu9ab61502015-11-06 06:42:02 +0800363 ggep_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties* pProperties)')
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600364 ggep_body.append('{')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600365 if self.layer_name == 'object_tracker':
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700366 ggep_body.append(' return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);')
367 else:
368 ggep_body.append(' return util_GetExtensionProperties(0, NULL, pCount, pProperties);')
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600369 ggep_body.append('}')
370 return "\n".join(ggep_body)
371
Jon Ashburn1f32a442016-02-02 13:13:01 -0700372 def _gen_layer_get_global_layer_props(self, layer="object_tracker"):
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600373 ggep_body = []
Jon Ashburn1f32a442016-02-02 13:13:01 -0700374 layer_name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', layer)
375 layer_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', layer_name).lower()
376 ggep_body.append('%s' % self.lineinfo.get())
377 ggep_body.append('static const VkLayerProperties globalLayerProps[] = {')
378 ggep_body.append(' {')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600379 if self.layer_name in ['unique_objects']:
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700380 ggep_body.append(' "VK_LAYER_GOOGLE_%s",' % layer)
Jon Ashburndc9111c2016-03-22 12:57:13 -0600381 ggep_body.append(' VK_LAYER_API_VERSION, // specVersion')
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700382 ggep_body.append(' 1, // implementationVersion')
383 ggep_body.append(' "Google Validation Layer"')
384 else:
385 ggep_body.append(' "VK_LAYER_LUNARG_%s",' % layer)
Jon Ashburndc9111c2016-03-22 12:57:13 -0600386 ggep_body.append(' VK_LAYER_API_VERSION, // specVersion')
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700387 ggep_body.append(' 1, // implementationVersion')
388 ggep_body.append(' "LunarG Validation Layer"')
Jon Ashburn1f32a442016-02-02 13:13:01 -0700389 ggep_body.append(' }')
390 ggep_body.append('};')
Tony Barbour59a47322015-06-24 16:06:58 -0600391 ggep_body.append('')
392 ggep_body.append('%s' % self.lineinfo.get())
Tony Barbour59a47322015-06-24 16:06:58 -0600393 ggep_body.append('')
Chia-I Wu9ab61502015-11-06 06:42:02 +0800394 ggep_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)')
Tony Barbour59a47322015-06-24 16:06:58 -0600395 ggep_body.append('{')
Courtney Goeltzenleuchter79a5a962015-07-07 17:51:45 -0600396 ggep_body.append(' return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);')
Tony Barbour59a47322015-06-24 16:06:58 -0600397 ggep_body.append('}')
398 return "\n".join(ggep_body)
399
Jon Ashburn1f32a442016-02-02 13:13:01 -0700400 def _gen_layer_get_physical_device_layer_props(self, layer="object_tracker"):
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600401 gpdlp_body = []
Jon Ashburn1f32a442016-02-02 13:13:01 -0700402 gpdlp_body.append('%s' % self.lineinfo.get())
403 gpdlp_body.append('static const VkLayerProperties deviceLayerProps[] = {')
404 gpdlp_body.append(' {')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600405 if self.layer_name in ['unique_objects']:
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700406 gpdlp_body.append(' "VK_LAYER_GOOGLE_%s",' % layer)
Jon Ashburndc9111c2016-03-22 12:57:13 -0600407 gpdlp_body.append(' VK_LAYER_API_VERSION, // specVersion')
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700408 gpdlp_body.append(' 1, // implementationVersion')
409 gpdlp_body.append(' "Google Validation Layer"')
410 else:
411 gpdlp_body.append(' "VK_LAYER_LUNARG_%s",' % layer)
Jon Ashburndc9111c2016-03-22 12:57:13 -0600412 gpdlp_body.append(' VK_LAYER_API_VERSION, // specVersion')
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700413 gpdlp_body.append(' 1, // implementationVersion')
414 gpdlp_body.append(' "LunarG Validation Layer"')
Jon Ashburn1f32a442016-02-02 13:13:01 -0700415 gpdlp_body.append(' }')
416 gpdlp_body.append('};')
Chia-I Wu9ab61502015-11-06 06:42:02 +0800417 gpdlp_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties* pProperties)')
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600418 gpdlp_body.append('{')
Courtney Goeltzenleuchter79a5a962015-07-07 17:51:45 -0600419 gpdlp_body.append(' return util_GetLayerProperties(ARRAY_SIZE(deviceLayerProps), deviceLayerProps, pCount, pProperties);')
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600420 gpdlp_body.append('}')
421 gpdlp_body.append('')
422 return "\n".join(gpdlp_body)
423
Mike Stroyanbf237d72015-04-03 17:45:53 -0600424 def _generate_dispatch_entrypoints(self, qual=""):
Mike Stroyan938c2532015-04-03 13:58:35 -0600425 if qual:
426 qual += " "
427
Mike Stroyan938c2532015-04-03 13:58:35 -0600428 funcs = []
429 intercepted = []
430 for proto in self.protos:
Chia-I Wu2985b142016-05-16 12:27:03 +0800431 if proto.name in ["GetDeviceProcAddr",
432 "GetInstanceProcAddr"]:
433 intercepted.append(proto)
Mike Stroyan70c05e82015-04-08 10:27:43 -0600434 else:
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600435 intercept = self.generate_intercept(proto, qual)
Mike Stroyan938c2532015-04-03 13:58:35 -0600436 if intercept is None:
437 # fill in default intercept for certain entrypoints
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700438 if 'CreateDebugReportCallbackEXT' == proto.name:
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600439 intercept = self._gen_layer_dbg_create_msg_callback()
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700440 elif 'DestroyDebugReportCallbackEXT' == proto.name:
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600441 intercept = self._gen_layer_dbg_destroy_msg_callback()
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700442 elif 'DebugReportMessageEXT' == proto.name:
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700443 intercept = self._gen_debug_report_msg()
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600444 elif 'CreateDevice' == proto.name:
445 funcs.append('/* CreateDevice HERE */')
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600446 elif 'EnumerateInstanceExtensionProperties' == proto.name:
Tony Barbour59a47322015-06-24 16:06:58 -0600447 intercept = self._gen_layer_get_global_extension_props(self.layer_name)
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600448 elif 'EnumerateInstanceLayerProperties' == proto.name:
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600449 intercept = self._gen_layer_get_global_layer_props(self.layer_name)
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600450 elif 'EnumerateDeviceLayerProperties' == proto.name:
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600451 intercept = self._gen_layer_get_physical_device_layer_props(self.layer_name)
Tony Barbour59a47322015-06-24 16:06:58 -0600452
Mike Stroyan938c2532015-04-03 13:58:35 -0600453 if intercept is not None:
454 funcs.append(intercept)
Ian Elliott7e40db92015-08-21 15:09:33 -0600455 if not "KHR" in proto.name:
Jon Ashburn747f2b62015-06-18 15:02:58 -0600456 intercepted.append(proto)
Mike Stroyan938c2532015-04-03 13:58:35 -0600457
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600458 prefix="vk"
Chia-I Wu2985b142016-05-16 12:27:03 +0800459 instance_lookups = []
460 device_lookups = []
Mike Stroyan938c2532015-04-03 13:58:35 -0600461 for proto in intercepted:
Chia-I Wu2985b142016-05-16 12:27:03 +0800462 if proto_is_global(proto):
463 instance_lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
464 instance_lookups.append(" return (PFN_vkVoidFunction) %s%s;" % (prefix, proto.name))
465 else:
466 device_lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
467 device_lookups.append(" return (PFN_vkVoidFunction) %s%s;" % (prefix, proto.name))
Mike Stroyan938c2532015-04-03 13:58:35 -0600468
Chia-I Wu2985b142016-05-16 12:27:03 +0800469 # add customized intercept_core_device_command
Mike Stroyan938c2532015-04-03 13:58:35 -0600470 body = []
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600471 body.append('%s' % self.lineinfo.get())
Chia-I Wu2985b142016-05-16 12:27:03 +0800472 body.append("static inline PFN_vkVoidFunction intercept_core_device_command(const char *name)")
Mike Stroyan938c2532015-04-03 13:58:35 -0600473 body.append("{")
474 body.append(generate_get_proc_addr_check("name"))
475 body.append("")
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600476 body.append(" name += 2;")
Chia-I Wu2985b142016-05-16 12:27:03 +0800477 body.append(" %s" % "\n ".join(device_lookups))
Mike Stroyan938c2532015-04-03 13:58:35 -0600478 body.append("")
479 body.append(" return NULL;")
480 body.append("}")
Chia-I Wu2985b142016-05-16 12:27:03 +0800481 # add intercept_core_instance_command
482 body.append("static inline PFN_vkVoidFunction intercept_core_instance_command(const char *name)")
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600483 body.append("{")
484 body.append(generate_get_proc_addr_check("name"))
485 body.append("")
486 body.append(" name += 2;")
Chia-I Wu2985b142016-05-16 12:27:03 +0800487 body.append(" %s" % "\n ".join(instance_lookups))
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600488 body.append("")
489 body.append(" return NULL;")
490 body.append("}")
491
Mike Stroyan938c2532015-04-03 13:58:35 -0600492 funcs.append("\n".join(body))
Mike Stroyan938c2532015-04-03 13:58:35 -0600493 return "\n\n".join(funcs)
494
Tobin Ehlisca915872014-11-18 11:28:33 -0700495 def _generate_extensions(self):
496 exts = []
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600497 exts.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600498 exts.append(self._gen_create_msg_callback())
499 exts.append(self._gen_destroy_msg_callback())
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700500 exts.append(self._gen_debug_report_msg())
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600501 return "\n".join(exts)
502
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600503 def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]):
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600504 func_body = []
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600505#
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600506# New style of GPA Functions for the new layer_data/layer_logging changes
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600507#
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600508 if self.layer_name in ['object_tracker', 'unique_objects']:
Chia-I Wufcf7eb92016-05-16 13:01:39 +0800509 for ext_enable, ext_list in extensions:
510 func_body.append('%s' % self.lineinfo.get())
511 func_body.append('static inline PFN_vkVoidFunction intercept_%s_command(const char *name, VkDevice dev)' % ext_enable)
512 func_body.append('{')
513 func_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);')
514 func_body.append(' if (!my_data->%s)' % ext_enable)
515 func_body.append(' return nullptr;\n')
516
517 for ext_name in ext_list:
518 func_body.append(' if (!strcmp("%s", name))\n'
519 ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (ext_name, ext_name))
520 func_body.append('\n return nullptr;')
521 func_body.append('}\n')
522
Chia-I Wu9ab61502015-11-06 06:42:02 +0800523 func_body.append("VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600524 "{\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600525 " PFN_vkVoidFunction addr;\n"
Chia-I Wu2985b142016-05-16 12:27:03 +0800526 " addr = intercept_core_device_command(funcName);\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600527 " if (addr)\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700528 " return addr;\n"
529 " if (device == VK_NULL_HANDLE) {\n"
530 " return NULL;\n"
531 " }\n")
Chia-I Wufcf7eb92016-05-16 13:01:39 +0800532 for ext_enable, _ in extensions:
533 func_body.append(' addr = intercept_%s_command(funcName, device);' % ext_enable)
534 func_body.append(' if (addr)\n'
535 ' return addr;')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600536 func_body.append("\n if (get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr == NULL)\n"
537 " return NULL;\n"
538 " return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n"
539 "}\n" % (self.layer_name, self.layer_name))
Chia-I Wufcf7eb92016-05-16 13:01:39 +0800540
541 for ext_enable, ext_list in instance_extensions:
542 func_body.append('%s' % self.lineinfo.get())
543 func_body.append('static inline PFN_vkVoidFunction intercept_%s_command(const char *name, VkInstance instance)' % ext_enable)
544 func_body.append('{')
545 if ext_enable == 'msg_callback_get_proc_addr':
546 func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n"
547 " return debug_report_get_instance_proc_addr(my_data->report_data, name);")
548 else:
549 func_body.append(" VkLayerInstanceDispatchTable* pTable = get_dispatch_table(%s_instance_table_map, instance);" % self.layer_name)
550 func_body.append(' if (instanceExtMap.size() == 0 || !instanceExtMap[pTable].%s)' % ext_enable)
551 func_body.append(' return nullptr;\n')
552
553 for ext_name in ext_list:
554 if wsi_name(ext_name):
555 func_body.append('%s' % wsi_ifdef(ext_name))
556 func_body.append(' if (!strcmp("%s", name))\n'
557 ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (ext_name, ext_name))
558 if wsi_name(ext_name):
559 func_body.append('%s' % wsi_endif(ext_name))
560
561 func_body.append('\n return nullptr;')
562 func_body.append('}\n')
563
Chia-I Wu9ab61502015-11-06 06:42:02 +0800564 func_body.append("VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600565 "{\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600566 " PFN_vkVoidFunction addr;\n"
Chia-I Wu2985b142016-05-16 12:27:03 +0800567 " addr = intercept_core_instance_command(funcName);\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600568 " if (addr) {\n"
Chia-I Wufcf7eb92016-05-16 13:01:39 +0800569 " return addr;\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700570 " }\n"
571 " if (instance == VK_NULL_HANDLE) {\n"
572 " return NULL;\n"
573 " }\n"
574 )
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600575
Chia-I Wufcf7eb92016-05-16 13:01:39 +0800576 for ext_enable, _ in instance_extensions:
577 func_body.append(' addr = intercept_%s_command(funcName, instance);' % ext_enable)
578 func_body.append(' if (addr)\n'
579 ' return addr;\n')
Jon Ashburn3dc39382015-09-17 10:00:32 -0600580
581 func_body.append(" if (get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr == NULL) {\n"
582 " return NULL;\n"
583 " }\n"
584 " return get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);\n"
585 "}\n" % (self.layer_name, self.layer_name))
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600586 return "\n".join(func_body)
587 else:
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600588 func_body.append('%s' % self.lineinfo.get())
Chia-I Wu9ab61502015-11-06 06:42:02 +0800589 func_body.append("VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* funcName)\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600590 "{\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700591 " PFN_vkVoidFunction addr;\n")
Jon Ashburn1f32a442016-02-02 13:13:01 -0700592 func_body.append("\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600593 " loader_platform_thread_once(&initOnce, init%s);\n\n"
Chia-I Wu2985b142016-05-16 12:27:03 +0800594 " addr = intercept_core_device_command(funcName);\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600595 " if (addr)\n"
596 " return addr;" % self.layer_name)
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700597 func_body.append(" if (device == VK_NULL_HANDLE) {\n"
598 " return NULL;\n"
599 " }\n")
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600600 func_body.append('')
601 func_body.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);')
602 if 0 != len(extensions):
603 extra_space = ""
604 for (ext_enable, ext_list) in extensions:
605 if 0 != len(ext_enable):
Jon Ashburn8acd2332015-09-16 18:08:32 -0600606 func_body.append(' if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].%s)' % ext_enable)
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600607 func_body.append(' {')
608 extra_space = " "
609 for ext_name in ext_list:
610 func_body.append(' %sif (!strcmp("%s", funcName))\n'
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600611 ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name))
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600612 if 0 != len(ext_enable):
613 func_body.append(' }')
614 func_body.append('%s' % self.lineinfo.get())
615 func_body.append(" {\n"
616 " if (pDisp->GetDeviceProcAddr == NULL)\n"
617 " return NULL;\n"
618 " return pDisp->GetDeviceProcAddr(device, funcName);\n"
619 " }\n"
620 "}\n")
Jon Ashburn3dc39382015-09-17 10:00:32 -0600621 func_body.append('%s' % self.lineinfo.get())
Chia-I Wu9ab61502015-11-06 06:42:02 +0800622 func_body.append("VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600623 "{\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600624 " PFN_vkVoidFunction addr;\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700625 )
Jon Ashburn1f32a442016-02-02 13:13:01 -0700626 func_body.append(
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600627 " loader_platform_thread_once(&initOnce, init%s);\n\n"
Chia-I Wu2985b142016-05-16 12:27:03 +0800628 " addr = intercept_core_instance_command(funcName);\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600629 " if (addr)\n"
630 " return addr;" % self.layer_name)
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700631 func_body.append(" if (instance == VK_NULL_HANDLE) {\n"
632 " return NULL;\n"
633 " }\n")
Jon Ashburn3dc39382015-09-17 10:00:32 -0600634 func_body.append("")
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700635 func_body.append(" VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);\n")
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600636 if 0 != len(instance_extensions):
Jon Ashburn3dc39382015-09-17 10:00:32 -0600637 extra_space = ""
638 for (ext_enable, ext_list) in instance_extensions:
639 if 0 != len(ext_enable):
Jon Ashburn3a278b72015-10-06 17:05:21 -0600640 if ext_enable == 'msg_callback_get_proc_addr':
641 func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n"
642 " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n"
643 " if (addr) {\n"
644 " return addr;\n"
645 " }\n")
646 else:
647 func_body.append(' if (instanceExtMap.size() != 0 && instanceExtMap[pTable].%s)' % ext_enable)
648 func_body.append(' {')
649 extra_space = " "
650 for ext_name in ext_list:
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700651 if wsi_name(ext_name):
652 func_body.append('%s' % wsi_ifdef(ext_name))
Jon Ashburn3a278b72015-10-06 17:05:21 -0600653 func_body.append(' %sif (!strcmp("%s", funcName))\n'
Jon Ashburn3dc39382015-09-17 10:00:32 -0600654 ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name))
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700655 if wsi_name(ext_name):
656 func_body.append('%s' % wsi_endif(ext_name))
Jon Ashburn3a278b72015-10-06 17:05:21 -0600657 if 0 != len(ext_enable):
658 func_body.append(' }\n')
Jon Ashburn3dc39382015-09-17 10:00:32 -0600659
660 func_body.append(" if (pTable->GetInstanceProcAddr == NULL)\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600661 " return NULL;\n"
662 " return pTable->GetInstanceProcAddr(instance, funcName);\n"
663 "}\n")
664 return "\n".join(func_body)
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600665
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600666
Mike Stroyaned238bb2015-05-15 08:50:57 -0600667 def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None):
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600668 func_body = ["#include \"vk_dispatch_table_helper.h\""]
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600669 func_body.append('%s' % self.lineinfo.get())
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700670 func_body.append('static void init_%s(layer_data *my_data, const VkAllocationCallbacks *pAllocator)\n'
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600671 '{\n' % self.layer_name)
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700672 if init_opts:
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600673 func_body.append('%s' % self.lineinfo.get())
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700674 func_body.append('')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600675 func_body.append(' layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_%s");' % self.layer_name)
Mike Stroyan313f7e62015-08-10 16:42:53 -0600676 func_body.append('')
677 if lockname is not None:
678 func_body.append('%s' % self.lineinfo.get())
679 func_body.append(" if (!%sLockInitialized)" % lockname)
680 func_body.append(" {")
681 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
682 func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname)
683 if condname is not None:
684 func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname)
685 func_body.append(" %sLockInitialized = 1;" % lockname)
686 func_body.append(" }")
687 func_body.append("}\n")
688 func_body.append('')
689 return "\n".join(func_body)
690
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600691class ObjectTrackerSubcommand(Subcommand):
692 def generate_header(self):
693 header_txt = []
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600694 header_txt.append('%s' % self.lineinfo.get())
Jamie Madilldf5d5732016-04-04 11:54:43 -0400695 header_txt.append('#include "vk_loader_platform.h"')
696 header_txt.append('#include "vulkan/vulkan.h"')
697 header_txt.append('')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600698 header_txt.append('#include <stdio.h>')
699 header_txt.append('#include <stdlib.h>')
700 header_txt.append('#include <string.h>')
Karl Schultzd7f37542016-05-10 11:36:08 -0600701 header_txt.append('#include <cinttypes>')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600702 header_txt.append('')
Tobin Ehlis803cc492015-06-08 17:36:28 -0600703 header_txt.append('#include <unordered_map>')
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600704 header_txt.append('')
David Pinedo9316d3b2015-11-06 12:54:48 -0700705 header_txt.append('#include "vulkan/vk_layer.h"')
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -0600706 header_txt.append('#include "vk_layer_config.h"')
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -0600707 header_txt.append('#include "vk_layer_table.h"')
708 header_txt.append('#include "vk_layer_data.h"')
709 header_txt.append('#include "vk_layer_logging.h"')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600710 header_txt.append('')
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700711# NOTE: The non-autoGenerated code is in the object_tracker.h header file
712 header_txt.append('#include "object_tracker.h"')
Mark Lobodzinskifb5437a2015-05-22 14:15:36 -0500713 header_txt.append('')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600714 return "\n".join(header_txt)
715
Tony Barboura05dbaa2015-07-09 17:31:46 -0600716 def generate_maps(self):
717 maps_txt = []
Tobin Ehlis86684f92016-01-05 10:33:58 -0700718 for o in vulkan.object_type_list:
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600719 maps_txt.append('std::unordered_map<uint64_t, OBJTRACK_NODE*> %sMap;' % (o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600720 return "\n".join(maps_txt)
721
Tobin Ehlis86684f92016-01-05 10:33:58 -0700722 def _gather_object_uses(self, obj_list, struct_type, obj_set):
723 # for each member of struct_type
724 # add objs in obj_list to obj_set
725 # call self for structs
Mike Stroyan04be7832016-04-07 12:14:30 -0600726 for m in sorted(vk_helper.struct_dict[struct_type]):
Tobin Ehlis86684f92016-01-05 10:33:58 -0700727 if vk_helper.struct_dict[struct_type][m]['type'] in obj_list:
728 obj_set.add(vk_helper.struct_dict[struct_type][m]['type'])
729 elif vk_helper.is_type(vk_helper.struct_dict[struct_type][m]['type'], 'struct'):
730 obj_set = obj_set.union(self._gather_object_uses(obj_list, vk_helper.struct_dict[struct_type][m]['type'], obj_set))
731 return obj_set
732
Tony Barboura05dbaa2015-07-09 17:31:46 -0600733 def generate_procs(self):
734 procs_txt = []
Tobin Ehlis86684f92016-01-05 10:33:58 -0700735 # First parse through funcs and gather dict of all objects seen by each call
736 obj_use_dict = {}
737 proto_list = vulkan.core.protos + vulkan.ext_khr_surface.protos + vulkan.ext_khr_surface.protos + vulkan.ext_khr_win32_surface.protos + vulkan.ext_khr_device_swapchain.protos
738 for proto in proto_list:
739 disp_obj = proto.params[0].ty.strip('*').replace('const ', '')
740 if disp_obj in vulkan.object_dispatch_list:
741 if disp_obj not in obj_use_dict:
742 obj_use_dict[disp_obj] = set()
743 for p in proto.params[1:]:
744 base_type = p.ty.strip('*').replace('const ', '')
745 if base_type in vulkan.object_type_list:
746 obj_use_dict[disp_obj].add(base_type)
747 if vk_helper.is_type(base_type, 'struct'):
748 obj_use_dict[disp_obj] = self._gather_object_uses(vulkan.object_type_list, base_type, obj_use_dict[disp_obj])
749 #for do in obj_use_dict:
750 # print "Disp obj %s has uses for objs: %s" % (do, ', '.join(obj_use_dict[do]))
751
752 for o in vulkan.object_type_list:# vulkan.core.objects:
Tony Barboura05dbaa2015-07-09 17:31:46 -0600753 procs_txt.append('%s' % self.lineinfo.get())
Michael Lentine13803dc2015-11-04 14:35:12 -0800754 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o)
755 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
Tobin Ehlis154e0462015-08-26 11:22:09 -0600756 if o in vulkan.object_dispatch_list:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700757 procs_txt.append('static void create_%s(%s dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o, o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600758 else:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700759 procs_txt.append('static void create_%s(VkDevice dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o))
Chia-I Wue2fc5522015-10-26 20:04:44 +0800760 procs_txt.append('{')
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700761 procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, objType,(uint64_t)(vkObj), __LINE__, OBJTRACK_NONE, "OBJTRACK",')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700762 procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDebugReportObjectTypeEXT(objType),')
Mark Young93ecb1d2016-01-13 13:47:16 -0700763 procs_txt.append(' (uint64_t)(vkObj));')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600764 procs_txt.append('')
765 procs_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;')
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700766 procs_txt.append(' pNewObjNode->belongsTo = (uint64_t)dispatchable_object;')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600767 procs_txt.append(' pNewObjNode->objType = objType;')
768 procs_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;')
Mark Young93ecb1d2016-01-13 13:47:16 -0700769 procs_txt.append(' pNewObjNode->vkObj = (uint64_t)(vkObj);')
Michael Lentine13803dc2015-11-04 14:35:12 -0800770 procs_txt.append(' %sMap[(uint64_t)vkObj] = pNewObjNode;' % (o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600771 procs_txt.append(' uint32_t objIndex = objTypeToIndex(objType);')
772 procs_txt.append(' numObjs[objIndex]++;')
773 procs_txt.append(' numTotalObjs++;')
774 procs_txt.append('}')
775 procs_txt.append('')
776 procs_txt.append('%s' % self.lineinfo.get())
Tobin Ehlis154e0462015-08-26 11:22:09 -0600777 if o in vulkan.object_dispatch_list:
Michael Lentine13803dc2015-11-04 14:35:12 -0800778 procs_txt.append('static void destroy_%s(%s dispatchable_object, %s object)' % (name, o, o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600779 else:
Michael Lentine13803dc2015-11-04 14:35:12 -0800780 procs_txt.append('static void destroy_%s(VkDevice dispatchable_object, %s object)' % (name, o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600781 procs_txt.append('{')
Mark Young93ecb1d2016-01-13 13:47:16 -0700782 procs_txt.append(' uint64_t object_handle = (uint64_t)(object);')
Chris Forbesbdbc1132016-03-09 12:06:45 +1300783 procs_txt.append(' auto it = %sMap.find(object_handle);' % o)
784 procs_txt.append(' if (it != %sMap.end()) {' % o)
785 procs_txt.append(' OBJTRACK_NODE* pNode = it->second;')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600786 procs_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);')
787 procs_txt.append(' assert(numTotalObjs > 0);')
788 procs_txt.append(' numTotalObjs--;')
789 procs_txt.append(' assert(numObjs[objIndex] > 0);')
790 procs_txt.append(' numObjs[objIndex]--;')
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700791 procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_INFORMATION_BIT_EXT, pNode->objType, object_handle, __LINE__, OBJTRACK_NONE, "OBJTRACK",')
Michael Lentine010f4692015-11-03 16:19:46 -0800792 procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",')
Mark Young93ecb1d2016-01-13 13:47:16 -0700793 procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType), (uint64_t)(object), numTotalObjs, numObjs[objIndex],')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700794 procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType));')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600795 procs_txt.append(' delete pNode;')
Chris Forbesbdbc1132016-03-09 12:06:45 +1300796 procs_txt.append(' %sMap.erase(it);' % (o))
Chia-I Wue2fc5522015-10-26 20:04:44 +0800797 procs_txt.append(' } else {')
Mark Lobodzinskia1bf5db2016-05-02 13:19:15 -0600798 procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT ) 0,')
799 procs_txt.append(' object_handle, __LINE__, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK",')
Chia-I Wue2fc5522015-10-26 20:04:44 +0800800 procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",')
Mark Lobodzinskia1bf5db2016-05-02 13:19:15 -0600801 procs_txt.append(' object_handle);')
Chia-I Wue2fc5522015-10-26 20:04:44 +0800802 procs_txt.append(' }')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600803 procs_txt.append('}')
804 procs_txt.append('')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700805 # Generate the permutations of validate_* functions where for each
806 # dispatchable object type, we have a corresponding validate_* function
807 # for that object and all non-dispatchable objects that are used in API
808 # calls with that dispatchable object.
Mike Stroyan04be7832016-04-07 12:14:30 -0600809 procs_txt.append('//%s' % str(sorted(obj_use_dict)))
810 for do in sorted(obj_use_dict):
Tobin Ehlis86684f92016-01-05 10:33:58 -0700811 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', do)
812 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
813 # First create validate_* func for disp obj
814 procs_txt.append('%s' % self.lineinfo.get())
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600815 procs_txt.append('static bool validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, do))
Tobin Ehlis86684f92016-01-05 10:33:58 -0700816 procs_txt.append('{')
817 procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))')
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600818 procs_txt.append(' return false;')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700819 procs_txt.append(' if (%sMap.find((uint64_t)object) == %sMap.end()) {' % (do, do))
Mark Young93ecb1d2016-01-13 13:47:16 -0700820 procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",')
821 procs_txt.append(' "Invalid %s Object 0x%%" PRIx64 ,(uint64_t)(object));' % do)
Tobin Ehlis86684f92016-01-05 10:33:58 -0700822 procs_txt.append(' }')
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600823 procs_txt.append(' return false;')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700824 procs_txt.append('}')
825 procs_txt.append('')
Mike Stroyan04be7832016-04-07 12:14:30 -0600826 for o in sorted(obj_use_dict[do]):
Tobin Ehlis86684f92016-01-05 10:33:58 -0700827 if o == do: # We already generated this case above so skip here
828 continue
829 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o)
830 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
831 procs_txt.append('%s' % self.lineinfo.get())
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600832 procs_txt.append('static bool validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, o))
Tobin Ehlis86684f92016-01-05 10:33:58 -0700833 procs_txt.append('{')
834 procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))')
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600835 procs_txt.append(' return false;')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700836 if o == "VkImage":
837 procs_txt.append(' // We need to validate normal image objects and those from the swapchain')
838 procs_txt.append(' if ((%sMap.find((uint64_t)object) == %sMap.end()) &&' % (o, o))
839 procs_txt.append(' (swapchainImageMap.find((uint64_t)object) == swapchainImageMap.end())) {')
840 else:
841 procs_txt.append(' if (%sMap.find((uint64_t)object) == %sMap.end()) {' % (o, o))
Mark Young93ecb1d2016-01-13 13:47:16 -0700842 procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",')
843 procs_txt.append(' "Invalid %s Object 0x%%" PRIx64, (uint64_t)(object));' % o)
Tobin Ehlis86684f92016-01-05 10:33:58 -0700844 procs_txt.append(' }')
Mark Lobodzinski2abefa92016-05-05 11:45:57 -0600845 procs_txt.append(' return false;')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700846 procs_txt.append('}')
847 procs_txt.append('')
848 procs_txt.append('')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600849 return "\n".join(procs_txt)
850
Mark Lobodzinski64d57752015-07-17 11:51:24 -0600851 def generate_destroy_instance(self):
Tony Barboura05dbaa2015-07-09 17:31:46 -0600852 gedi_txt = []
853 gedi_txt.append('%s' % self.lineinfo.get())
Mark Young93ecb1d2016-01-13 13:47:16 -0700854 gedi_txt.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(')
Chia-I Wuf7458c52015-10-26 21:10:41 +0800855 gedi_txt.append('VkInstance instance,')
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800856 gedi_txt.append('const VkAllocationCallbacks* pAllocator)')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600857 gedi_txt.append('{')
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600858 gedi_txt.append(' std::unique_lock<std::mutex> lock(global_lock);')
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600859 gedi_txt.append('')
860 gedi_txt.append(' dispatch_key key = get_dispatch_key(instance);')
861 gedi_txt.append(' layer_data *my_data = get_my_data_ptr(key, layer_data_map);')
862 gedi_txt.append('')
863 gedi_txt.append(' // Enable the temporary callback(s) here to catch cleanup issues:')
864 gedi_txt.append(' bool callback_setup = false;')
865 gedi_txt.append(' if (my_data->num_tmp_callbacks > 0) {')
866 gedi_txt.append(' if (!layer_enable_tmp_callbacks(my_data->report_data,')
867 gedi_txt.append(' my_data->num_tmp_callbacks,')
868 gedi_txt.append(' my_data->tmp_dbg_create_infos,')
869 gedi_txt.append(' my_data->tmp_callbacks)) {')
870 gedi_txt.append(' callback_setup = true;')
871 gedi_txt.append(' }')
872 gedi_txt.append(' }')
873 gedi_txt.append('')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700874 gedi_txt.append(' validate_instance(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, false);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600875 gedi_txt.append('')
Michael Lentine13803dc2015-11-04 14:35:12 -0800876 gedi_txt.append(' destroy_instance(instance, instance);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600877 gedi_txt.append(' // Report any remaining objects in LL')
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700878 gedi_txt.append('')
879 gedi_txt.append(' for (auto iit = VkDeviceMap.begin(); iit != VkDeviceMap.end();) {')
880 gedi_txt.append(' OBJTRACK_NODE* pNode = iit->second;')
881 gedi_txt.append(' if (pNode->belongsTo == (uint64_t)instance) {')
882 gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",')
883 gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),')
884 gedi_txt.append(' pNode->vkObj);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600885 for o in vulkan.core.objects:
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700886 if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue', 'VkDevice']:
Tony Barboura05dbaa2015-07-09 17:31:46 -0600887 continue
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700888 gedi_txt.append(' for (auto idt = %sMap.begin(); idt != %sMap.end();) {' % (o, o))
889 gedi_txt.append(' OBJTRACK_NODE* pNode = idt->second;')
890 gedi_txt.append(' if (pNode->belongsTo == iit->first) {')
891 gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",')
892 gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),')
893 gedi_txt.append(' pNode->vkObj);')
894 gedi_txt.append(' %sMap.erase(idt++);' % o )
895 gedi_txt.append(' } else {')
896 gedi_txt.append(' ++idt;')
897 gedi_txt.append(' }')
898 gedi_txt.append(' }')
899 gedi_txt.append(' VkDeviceMap.erase(iit++);')
900 gedi_txt.append(' } else {')
901 gedi_txt.append(' ++iit;')
902 gedi_txt.append(' }')
903 gedi_txt.append(' }')
904 gedi_txt.append('')
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700905 gedi_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, instance);')
Chia-I Wuf7458c52015-10-26 21:10:41 +0800906 gedi_txt.append(' pInstanceTable->DestroyInstance(instance, pAllocator);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600907 gedi_txt.append('')
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600908 gedi_txt.append(' // Disable and cleanup the temporary callback(s):')
909 gedi_txt.append(' if (callback_setup) {')
910 gedi_txt.append(' layer_disable_tmp_callbacks(my_data->report_data,')
911 gedi_txt.append(' my_data->num_tmp_callbacks,')
912 gedi_txt.append(' my_data->tmp_callbacks);')
913 gedi_txt.append(' }')
914 gedi_txt.append(' if (my_data->num_tmp_callbacks > 0) {')
915 gedi_txt.append(' layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos,')
916 gedi_txt.append(' my_data->tmp_callbacks);')
917 gedi_txt.append(' my_data->num_tmp_callbacks = 0;')
918 gedi_txt.append(' }')
919 gedi_txt.append('')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600920 gedi_txt.append(' // Clean up logging callback, if any')
921 gedi_txt.append(' while (my_data->logging_callback.size() > 0) {')
922 gedi_txt.append(' VkDebugReportCallbackEXT callback = my_data->logging_callback.back();')
923 gedi_txt.append(' layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);')
924 gedi_txt.append(' my_data->logging_callback.pop_back();')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600925 gedi_txt.append(' }')
926 gedi_txt.append('')
927 gedi_txt.append(' layer_debug_report_destroy_instance(mid(instance));')
Tobin Ehlis4192fdf2016-04-18 15:40:59 -0600928 gedi_txt.append(' layer_data_map.erase(key);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600929 gedi_txt.append('')
Jon Ashburn3dc39382015-09-17 10:00:32 -0600930 gedi_txt.append(' instanceExtMap.erase(pInstanceTable);')
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600931 gedi_txt.append(' lock.unlock();')
Mike Stroyan0699a792015-08-18 14:48:34 -0600932 # The loader holds a mutex that protects this from other threads
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700933 gedi_txt.append(' object_tracker_instance_table_map.erase(key);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600934 gedi_txt.append('}')
935 gedi_txt.append('')
936 return "\n".join(gedi_txt)
937
Mark Lobodzinski64d57752015-07-17 11:51:24 -0600938 def generate_destroy_device(self):
Tony Barboura05dbaa2015-07-09 17:31:46 -0600939 gedd_txt = []
940 gedd_txt.append('%s' % self.lineinfo.get())
Mark Young93ecb1d2016-01-13 13:47:16 -0700941 gedd_txt.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(')
Chia-I Wuf7458c52015-10-26 21:10:41 +0800942 gedd_txt.append('VkDevice device,')
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800943 gedd_txt.append('const VkAllocationCallbacks* pAllocator)')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600944 gedd_txt.append('{')
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600945 gedd_txt.append(' std::unique_lock<std::mutex> lock(global_lock);')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700946 gedd_txt.append(' validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600947 gedd_txt.append('')
Michael Lentine13803dc2015-11-04 14:35:12 -0800948 gedd_txt.append(' destroy_device(device, device);')
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700949 gedd_txt.append(' // Report any remaining objects associated with this VkDevice object in LL')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600950 for o in vulkan.core.objects:
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700951 # DescriptorSets and Command Buffers are destroyed through their pools, not explicitly
952 if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue', 'VkDevice', 'VkDescriptorSet', 'VkCommandBuffer']:
Tony Barboura05dbaa2015-07-09 17:31:46 -0600953 continue
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700954 gedd_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end();) {' % (o, o))
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700955 gedd_txt.append(' OBJTRACK_NODE* pNode = it->second;')
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700956 gedd_txt.append(' if (pNode->belongsTo == (uint64_t)device) {')
957 gedd_txt.append(' log_msg(mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",')
958 gedd_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),')
959 gedd_txt.append(' pNode->vkObj);')
960 gedd_txt.append(' %sMap.erase(it++);' % o )
961 gedd_txt.append(' } else {')
962 gedd_txt.append(' ++it;')
963 gedd_txt.append(' }')
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700964 gedd_txt.append(' }')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600965 gedd_txt.append('')
966 gedd_txt.append(" // Clean up Queue's MemRef Linked Lists")
967 gedd_txt.append(' destroyQueueMemRefLists();')
968 gedd_txt.append('')
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600969 gedd_txt.append(' lock.unlock();')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600970 gedd_txt.append('')
971 gedd_txt.append(' dispatch_key key = get_dispatch_key(device);')
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700972 gedd_txt.append(' VkLayerDispatchTable *pDisp = get_dispatch_table(object_tracker_device_table_map, device);')
Chia-I Wuf7458c52015-10-26 21:10:41 +0800973 gedd_txt.append(' pDisp->DestroyDevice(device, pAllocator);')
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700974 gedd_txt.append(' object_tracker_device_table_map.erase(key);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600975 gedd_txt.append('')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600976 gedd_txt.append('}')
977 gedd_txt.append('')
978 return "\n".join(gedd_txt)
979
Mark Lobodzinski2fba0322016-01-23 18:31:23 -0700980 # Special-case validating some objects -- they may be non-NULL but should
981 # only be validated upon meeting some condition specified below.
982 def _dereference_conditionally(self, indent, prefix, type_name, name):
Mark Lobodzinski9fde6392016-01-19 09:57:24 -0700983 s_code = ''
984 if type_name == 'pBufferInfo':
985 s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||\n' % (indent, prefix)
986 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||\n' % (indent, prefix)
987 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||\n' % (indent, prefix)
988 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) ) {\n' % (indent, prefix)
989 elif type_name == 'pImageInfo':
990 s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||\n' % (indent, prefix)
991 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||\n' % (indent, prefix)
992 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) ||\n' % (indent, prefix)
993 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||\n' % (indent, prefix)
994 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ) {\n' % (indent, prefix)
995 elif type_name == 'pTexelBufferView':
Mark Lobodzinski2fba0322016-01-23 18:31:23 -0700996 s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||\n' % (indent, prefix)
997 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) ) {\n' % (indent, prefix)
998 elif name == 'pBeginInfo->pInheritanceInfo':
999 s_code += '%sOBJTRACK_NODE* pNode = VkCommandBufferMap[(uint64_t)commandBuffer];\n' % (indent)
1000 s_code += '%sif ((%s) && (pNode->status & OBJSTATUS_COMMAND_BUFFER_SECONDARY)) {\n' % (indent, name)
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001001 else:
1002 s_code += '%sif (%s) {\n' % (indent, name)
1003 return s_code
1004
Tobin Ehlis86684f92016-01-05 10:33:58 -07001005 def _gen_obj_validate_code(self, struct_uses, obj_type_mapping, func_name, valid_null_dict, param0_name, indent, prefix, array_index):
1006 pre_code = ''
1007 for obj in sorted(struct_uses):
1008 name = obj
1009 array = ''
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001010 type_name = ''
Tobin Ehlis86684f92016-01-05 10:33:58 -07001011 if '[' in obj:
1012 (name, array) = obj.split('[')
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001013 type_name = name
Tobin Ehlis86684f92016-01-05 10:33:58 -07001014 array = array.strip(']')
1015 if isinstance(struct_uses[obj], dict):
1016 local_prefix = ''
1017 name = '%s%s' % (prefix, name)
1018 ptr_type = False
1019 if 'p' == obj[0]:
1020 ptr_type = True
Mark Lobodzinski2fba0322016-01-23 18:31:23 -07001021 tmp_pre = self._dereference_conditionally(indent, prefix, type_name, name)
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001022 pre_code += tmp_pre
Tobin Ehlis86684f92016-01-05 10:33:58 -07001023 indent += ' '
1024 if array != '':
1025 idx = 'idx%s' % str(array_index)
1026 array_index += 1
1027 pre_code += '%s\n' % self.lineinfo.get()
1028 pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx)
1029 indent += ' '
1030 local_prefix = '%s[%s].' % (name, idx)
1031 elif ptr_type:
1032 local_prefix = '%s->' % (name)
1033 else:
1034 local_prefix = '%s.' % (name)
1035 tmp_pre = self._gen_obj_validate_code(struct_uses[obj], obj_type_mapping, func_name, valid_null_dict, param0_name, indent, local_prefix, array_index)
1036 pre_code += tmp_pre
1037 if array != '':
1038 indent = indent[4:]
1039 pre_code += '%s}\n' % (indent)
1040 if ptr_type:
1041 indent = indent[4:]
1042 pre_code += '%s}\n' % (indent)
1043 else:
1044 ptype = struct_uses[obj]
1045 dbg_obj_type = obj_type_mapping[ptype]
1046 fname = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', ptype)
1047 fname = re.sub('([a-z0-9])([A-Z])', r'\1_\2', fname).lower()[3:]
1048 full_name = '%s%s' % (prefix, name)
1049 null_obj_ok = 'false'
1050 # If a valid null param is defined for this func and we have a match, allow NULL
Mike Stroyan04be7832016-04-07 12:14:30 -06001051 if func_name in valid_null_dict and True in [name in pn for pn in sorted(valid_null_dict[func_name])]:
Tobin Ehlis86684f92016-01-05 10:33:58 -07001052 null_obj_ok = 'true'
1053 if (array_index > 0) or '' != array:
Mark Lobodzinski2fba0322016-01-23 18:31:23 -07001054 tmp_pre = self._dereference_conditionally(indent, prefix, type_name, full_name)
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001055 pre_code += tmp_pre
Tobin Ehlis86684f92016-01-05 10:33:58 -07001056 indent += ' '
1057 if array != '':
1058 idx = 'idx%s' % str(array_index)
1059 array_index += 1
1060 pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx)
1061 indent += ' '
1062 full_name = '%s[%s]' % (full_name, idx)
1063 pre_code += '%s\n' % self.lineinfo.get()
1064 pre_code += '%sskipCall |= validate_%s(%s, %s, %s, %s);\n' %(indent, fname, param0_name, full_name, dbg_obj_type, null_obj_ok)
1065 if array != '':
1066 indent = indent[4:]
1067 pre_code += '%s}\n' % (indent)
1068 indent = indent[4:]
1069 pre_code += '%s}\n' % (indent)
1070 else:
1071 pre_code += '%s\n' % self.lineinfo.get()
1072 pre_code += '%sskipCall |= validate_%s(%s, %s, %s, %s);\n' %(indent, fname, param0_name, full_name, dbg_obj_type, null_obj_ok)
1073 return pre_code
Tony Barboura05dbaa2015-07-09 17:31:46 -06001074
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -06001075 def generate_intercept(self, proto, qual):
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001076 if proto.name in [ 'CreateDebugReportCallbackEXT', 'EnumerateInstanceLayerProperties', 'EnumerateInstanceExtensionProperties','EnumerateDeviceLayerProperties', 'EnumerateDeviceExtensionProperties' ]:
Mike Stroyan00087e62015-04-03 14:39:16 -06001077 # use default version
1078 return None
Mark Lobodzinski7c75b852015-05-05 15:01:37 -05001079
Tony Barboura05dbaa2015-07-09 17:31:46 -06001080 # Create map of object names to object type enums of the form VkName : VkObjectTypeName
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001081 obj_type_mapping = {base_t : base_t.replace("Vk", "VkDebugReportObjectType") for base_t in vulkan.object_type_list}
Mark Lobodzinski7c75b852015-05-05 15:01:37 -05001082 # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES
1083 for objectName, objectTypeEnum in obj_type_mapping.items():
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001084 obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum) + '_EXT';
Mark Lobodzinski7c75b852015-05-05 15:01:37 -05001085 # Command Buffer Object doesn't follow the rule.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001086 obj_type_mapping['VkCommandBuffer'] = "VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT"
1087 obj_type_mapping['VkShaderModule'] = "VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT"
Mike Stroyan00087e62015-04-03 14:39:16 -06001088
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001089 explicit_object_tracker_functions = [
1090 "CreateInstance",
Tobin Ehlisec598302015-09-15 15:02:17 -06001091 "EnumeratePhysicalDevices",
Cody Northropd0802882015-08-03 17:04:53 -06001092 "GetPhysicalDeviceQueueFamilyProperties",
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001093 "CreateDevice",
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001094 "GetDeviceQueue",
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +08001095 "QueueBindSparse",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001096 "AllocateDescriptorSets",
Tony Barbour770f80d2015-07-20 10:52:13 -06001097 "FreeDescriptorSets",
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001098 "CreateGraphicsPipelines",
1099 "CreateComputePipelines",
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -07001100 "AllocateCommandBuffers",
1101 "FreeCommandBuffers",
1102 "DestroyDescriptorPool",
1103 "DestroyCommandPool",
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001104 "MapMemory",
1105 "UnmapMemory",
1106 "FreeMemory",
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -06001107 "DestroySwapchainKHR",
1108 "GetSwapchainImagesKHR"
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001109 ]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001110 decl = proto.c_func(prefix="vk", attr="VKAPI")
Mike Stroyan00087e62015-04-03 14:39:16 -06001111 param0_name = proto.params[0].name
Mark Lobodzinski48bd16d2015-05-08 09:12:28 -05001112 using_line = ''
Mike Stroyan00087e62015-04-03 14:39:16 -06001113 create_line = ''
Mark Lobodzinski64d57752015-07-17 11:51:24 -06001114 destroy_line = ''
Tobin Ehlis154e0462015-08-26 11:22:09 -06001115 # Dict below tracks params that are vk objects. Dict is "loop count"->["params w/ that loop count"] where '0' is params that aren't in an array
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001116 # TODO : Should integrate slightly better code for this purpose from unique_objects layer
Tobin Ehlis154e0462015-08-26 11:22:09 -06001117 loop_params = defaultdict(list) # Dict uses loop count as key to make final code generation cleaner so params shared in single loop where needed
Michael Lentine13803dc2015-11-04 14:35:12 -08001118 loop_types = defaultdict(list)
Tobin Ehlis2717d132015-07-10 18:25:07 -06001119 # TODO : For now skipping objs that can be NULL. Really should check these and have special case that allows them to be NULL
Tobin Ehlis154e0462015-08-26 11:22:09 -06001120 # or better yet, these should be encoded into an API json definition and we generate checks from there
1121 # Until then, this is a dict where each func name is a list of object params that can be null (so don't need to be validated)
1122 # param names may be directly passed to the function, or may be a field in a struct param
1123 valid_null_object_names = {'CreateGraphicsPipelines' : ['basePipelineHandle'],
1124 'CreateComputePipelines' : ['basePipelineHandle'],
1125 'BeginCommandBuffer' : ['renderPass', 'framebuffer'],
Tobin Ehlisec598302015-09-15 15:02:17 -06001126 'QueueSubmit' : ['fence'],
Jon Ashburn9216ae42016-01-14 15:11:55 -07001127 'AcquireNextImageKHR' : ['fence', 'semaphore' ],
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001128 'UpdateDescriptorSets' : ['pTexelBufferView'],
Tobin Ehlis86684f92016-01-05 10:33:58 -07001129 'CreateSwapchainKHR' : ['oldSwapchain'],
Tobin Ehlis154e0462015-08-26 11:22:09 -06001130 }
Tobin Ehlis154e0462015-08-26 11:22:09 -06001131 param_count = 'NONE' # keep track of arrays passed directly into API functions
Tobin Ehlis803cc492015-06-08 17:36:28 -06001132 for p in proto.params:
Tobin Ehlisec598302015-09-15 15:02:17 -06001133 base_type = p.ty.replace('const ', '').strip('*')
Tobin Ehlis154e0462015-08-26 11:22:09 -06001134 if 'count' in p.name.lower():
1135 param_count = p.name
Tobin Ehlisec598302015-09-15 15:02:17 -06001136 if base_type in vulkan.core.objects:
1137 # This is an object to potentially check for validity. First see if it's an array
1138 if '*' in p.ty and 'const' in p.ty and param_count != 'NONE':
1139 loop_params[param_count].append(p.name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001140 loop_types[param_count].append(str(p.ty[6:-1]))
Tobin Ehlisec598302015-09-15 15:02:17 -06001141 # Not an array, check for just a base Object that's not in exceptions
1142 elif '*' not in p.ty and (proto.name not in valid_null_object_names or p.name not in valid_null_object_names[proto.name]):
Tobin Ehlis154e0462015-08-26 11:22:09 -06001143 loop_params[0].append(p.name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001144 loop_types[0].append(str(p.ty))
Tobin Ehlisec598302015-09-15 15:02:17 -06001145 elif vk_helper.is_type(base_type, 'struct'):
1146 struct_type = base_type
Tobin Ehlis9d675942015-06-30 14:32:16 -06001147 if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict:
1148 struct_type = vk_helper.typedef_rev_dict[struct_type]
Tobin Ehlis82b3db52015-10-23 17:52:53 -06001149 # Parse elements of this struct param to identify objects and/or arrays of objects
Tobin Ehlis9d675942015-06-30 14:32:16 -06001150 for m in sorted(vk_helper.struct_dict[struct_type]):
1151 if vk_helper.struct_dict[struct_type][m]['type'] in vulkan.core.objects and vk_helper.struct_dict[struct_type][m]['type'] not in ['VkPhysicalDevice', 'VkQueue', 'VkFence', 'VkImage', 'VkDeviceMemory']:
Tobin Ehlis154e0462015-08-26 11:22:09 -06001152 if proto.name not in valid_null_object_names or vk_helper.struct_dict[struct_type][m]['name'] not in valid_null_object_names[proto.name]:
Tobin Ehlis82b3db52015-10-23 17:52:53 -06001153 # This is not great, but gets the job done for now, but If we have a count and this param is a ptr w/
1154 # last letter 's' OR non-'count' string of count is in the param name, then this is a dynamically sized array param
1155 param_array = False
1156 if param_count != 'NONE':
1157 if '*' in p.ty:
1158 if 's' == p.name[-1] or param_count.lower().replace('count', '') in p.name.lower():
1159 param_array = True
1160 if param_array:
Tobin Ehlis154e0462015-08-26 11:22:09 -06001161 param_name = '%s[i].%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name'])
Tobin Ehlis46d53622015-07-10 11:10:21 -06001162 else:
Tobin Ehlis154e0462015-08-26 11:22:09 -06001163 param_name = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name'])
1164 if vk_helper.struct_dict[struct_type][m]['dyn_array']:
Tobin Ehlis82b3db52015-10-23 17:52:53 -06001165 if param_count != 'NONE': # this will be a double-embedded loop, use comma delineated 'count,name' for param_name
1166 loop_count = '%s[i].%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size'])
1167 loop_params[param_count].append('%s,%s' % (loop_count, param_name))
Michael Lentine13803dc2015-11-04 14:35:12 -08001168 loop_types[param_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type']))
Tobin Ehlis82b3db52015-10-23 17:52:53 -06001169 else:
1170 loop_count = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size'])
1171 loop_params[loop_count].append(param_name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001172 loop_types[loop_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type']))
Tobin Ehlis154e0462015-08-26 11:22:09 -06001173 else:
1174 if '[' in param_name: # dynamic array param, set size
1175 loop_params[param_count].append(param_name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001176 loop_types[param_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type']))
Tobin Ehlis154e0462015-08-26 11:22:09 -06001177 else:
1178 loop_params[0].append(param_name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001179 loop_types[0].append('%s' % (vk_helper.struct_dict[struct_type][m]['type']))
Tobin Ehlis86684f92016-01-05 10:33:58 -07001180 last_param_index = None
1181 create_func = False
1182 if True in [create_txt in proto.name for create_txt in ['Create', 'Allocate']]:
1183 create_func = True
1184 last_param_index = -1 # For create funcs don't validate last object
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001185 (struct_uses, local_decls) = get_object_uses(vulkan.object_type_list, proto.params[:last_param_index])
Mike Stroyan00087e62015-04-03 14:39:16 -06001186 funcs = []
Tobin Ehlis803cc492015-06-08 17:36:28 -06001187 mutex_unlock = False
Tobin Ehlis154e0462015-08-26 11:22:09 -06001188 funcs.append('%s\n' % self.lineinfo.get())
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001189 if proto.name in explicit_object_tracker_functions:
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001190 funcs.append('%s%s\n'
1191 '{\n'
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001192 ' return explicit_%s;\n'
1193 '}' % (qual, decl, proto.c_call()))
1194 return "".join(funcs)
Mark Lobodzinski308d7792015-11-24 10:28:31 -07001195 # Temporarily prevent DestroySurface call from being generated until WSI layer support is fleshed out
Mark Lobodzinski882655d2016-01-05 11:32:53 -07001196 elif 'DestroyInstance' in proto.name or 'DestroyDevice' in proto.name:
Mark Lobodzinski64d57752015-07-17 11:51:24 -06001197 return ""
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001198 else:
Tobin Ehlis86684f92016-01-05 10:33:58 -07001199 if create_func:
Michael Lentine13803dc2015-11-04 14:35:12 -08001200 typ = proto.params[-1].ty.strip('*').replace('const ', '');
1201 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ)
1202 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001203 create_line = ' {\n'
1204 create_line += ' std::lock_guard<std::mutex> lock(global_lock);\n'
1205 create_line += ' if (result == VK_SUCCESS) {\n'
1206 create_line += ' create_%s(%s, *%s, %s);\n' % (name, param0_name, proto.params[-1].name, obj_type_mapping[typ])
1207 create_line += ' }\n'
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001208 create_line += ' }\n'
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001209 if 'FreeCommandBuffers' in proto.name:
Michael Lentine13803dc2015-11-04 14:35:12 -08001210 typ = proto.params[-1].ty.strip('*').replace('const ', '');
1211 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ)
1212 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001213 funcs.append('%s\n' % self.lineinfo.get())
1214 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Chia-I Wud50a7d72015-10-26 20:48:51 +08001215 destroy_line += ' for (uint32_t i = 0; i < commandBufferCount; i++) {\n'
Michael Lentine13803dc2015-11-04 14:35:12 -08001216 destroy_line += ' destroy_%s(%s[i], %s[i]);\n' % (name, proto.params[-1].name, proto.params[-1].name)
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001217 destroy_line += ' }\n'
1218 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Mark Lobodzinski64d57752015-07-17 11:51:24 -06001219 if 'Destroy' in proto.name:
Michael Lentine13803dc2015-11-04 14:35:12 -08001220 typ = proto.params[-2].ty.strip('*').replace('const ', '');
1221 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ)
1222 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001223 funcs.append('%s\n' % self.lineinfo.get())
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001224 destroy_line = ' {\n'
1225 destroy_line += ' std::lock_guard<std::mutex> lock(global_lock);\n'
1226 destroy_line += ' destroy_%s(%s, %s);\n' % (name, param0_name, proto.params[-2].name)
1227 destroy_line += ' }\n'
Tobin Ehlis86684f92016-01-05 10:33:58 -07001228 indent = ' '
1229 if len(struct_uses) > 0:
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001230 using_line += '%sbool skipCall = false;\n' % (indent)
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001231 if not mutex_unlock:
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001232 using_line += '%s{\n' % (indent)
1233 indent += ' '
1234 using_line += '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % (indent)
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001235 mutex_unlock = True
Mike Stroyan04be7832016-04-07 12:14:30 -06001236 using_line += '// objects to validate: %s\n' % str(sorted(struct_uses))
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001237 using_line += self._gen_obj_validate_code(struct_uses, obj_type_mapping, proto.name, valid_null_object_names, param0_name, indent, '', 0)
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001238 if mutex_unlock:
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001239 indent = indent[4:]
1240 using_line += '%s}\n' % (indent)
Tobin Ehlis86684f92016-01-05 10:33:58 -07001241 if len(struct_uses) > 0:
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001242 using_line += ' if (skipCall)\n'
Mark Lobodzinski2abefa92016-05-05 11:45:57 -06001243 if proto.ret == "bool":
1244 using_line += ' return false;\n'
Jamie Madill940c4bd2016-05-11 16:11:47 -04001245 elif proto.ret == "VkBool32":
1246 using_line += ' return VK_FALSE;\n'
Jamie Madill2bf385b2016-04-04 12:15:39 -04001247 elif proto.ret != "void":
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001248 using_line += ' return VK_ERROR_VALIDATION_FAILED_EXT;\n'
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001249 else:
1250 using_line += ' return;\n'
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001251 ret_val = ''
1252 stmt = ''
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001253 if proto.ret != "void":
1254 ret_val = "%s result = " % proto.ret
1255 stmt = " return result;\n"
1256
1257 dispatch_param = proto.params[0].name
1258 if 'CreateInstance' in proto.name:
1259 dispatch_param = '*' + proto.params[1].name
1260
Mark Lobodzinskifb5437a2015-05-22 14:15:36 -05001261 # Must use 'instance' table for these APIs, 'device' table otherwise
1262 table_type = ""
1263 if proto_is_global(proto):
1264 table_type = "instance"
1265 else:
1266 table_type = "device"
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001267 if wsi_name(proto.name):
1268 funcs.append('%s' % wsi_ifdef(proto.name))
Mike Stroyan00087e62015-04-03 14:39:16 -06001269 funcs.append('%s%s\n'
1270 '{\n'
1271 '%s'
Mike Stroyan00087e62015-04-03 14:39:16 -06001272 '%s'
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07001273 ' %sget_dispatch_table(object_tracker_%s_table_map, %s)->%s;\n'
Mike Stroyan38820b32015-09-28 13:47:29 -06001274 '%s'
1275 '%s'
1276 '}' % (qual, decl, using_line, destroy_line, ret_val, table_type, dispatch_param, proto.c_call(), create_line, stmt))
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001277 if wsi_name(proto.name):
1278 funcs.append('%s' % wsi_endif(proto.name))
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):
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07001282 self.layer_name = "object_tracker"
Ian Elliott1064fe32015-07-06 14:31:32 -06001283 extensions=[('wsi_enabled',
Ian Elliott05846062015-11-20 14:13:17 -07001284 ['vkCreateSwapchainKHR',
Jon Ashburn8acd2332015-09-16 18:08:32 -06001285 'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR',
1286 'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])]
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001287 if self.wsi == 'Win32':
Michael Lentine64e2ebd2015-12-03 14:33:09 -08001288 instance_extensions=[('msg_callback_get_proc_addr', []),
1289 ('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001290 ['vkDestroySurfaceKHR',
1291 'vkGetPhysicalDeviceSurfaceSupportKHR',
Michael Lentine64e2ebd2015-12-03 14:33:09 -08001292 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1293 'vkGetPhysicalDeviceSurfaceFormatsKHR',
1294 'vkGetPhysicalDeviceSurfacePresentModesKHR',
1295 'vkCreateWin32SurfaceKHR',
1296 'vkGetPhysicalDeviceWin32PresentationSupportKHR'])]
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001297 elif self.wsi == 'Android':
1298 instance_extensions=[('msg_callback_get_proc_addr', []),
1299 ('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001300 ['vkDestroySurfaceKHR',
1301 'vkGetPhysicalDeviceSurfaceSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001302 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1303 'vkGetPhysicalDeviceSurfaceFormatsKHR',
Michael Lentine56512bb2016-03-02 17:28:55 -06001304 'vkGetPhysicalDeviceSurfacePresentModesKHR',
1305 'vkCreateAndroidSurfaceKHR'])]
Karl Schultz9daf7a32016-03-08 15:14:11 -07001306 elif self.wsi == 'Xcb' or self.wsi == 'Xlib' or self.wsi == 'Wayland' or self.wsi == 'Mir':
Michael Lentine64e2ebd2015-12-03 14:33:09 -08001307 instance_extensions=[('msg_callback_get_proc_addr', []),
1308 ('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001309 ['vkDestroySurfaceKHR',
1310 'vkGetPhysicalDeviceSurfaceSupportKHR',
Michael Lentine64e2ebd2015-12-03 14:33:09 -08001311 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1312 'vkGetPhysicalDeviceSurfaceFormatsKHR',
1313 'vkGetPhysicalDeviceSurfacePresentModesKHR',
1314 'vkCreateXcbSurfaceKHR',
Karl Schultz9daf7a32016-03-08 15:14:11 -07001315 'vkGetPhysicalDeviceXcbPresentationSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001316 'vkCreateXlibSurfaceKHR',
Karl Schultz9daf7a32016-03-08 15:14:11 -07001317 'vkGetPhysicalDeviceXlibPresentationSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001318 'vkCreateWaylandSurfaceKHR',
Karl Schultz9daf7a32016-03-08 15:14:11 -07001319 'vkGetPhysicalDeviceWaylandPresentationSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001320 'vkCreateMirSurfaceKHR',
1321 'vkGetPhysicalDeviceMirPresentationSupportKHR'])]
Mark Lobodzinskid53098f2016-02-25 18:14:56 -07001322 else:
1323 print('Error: Undefined DisplayServer')
1324 instance_extensions=[]
1325
Tony Barboura05dbaa2015-07-09 17:31:46 -06001326 body = [self.generate_maps(),
1327 self.generate_procs(),
Mark Lobodzinski64d57752015-07-17 11:51:24 -06001328 self.generate_destroy_instance(),
1329 self.generate_destroy_device(),
Tony Barboura05dbaa2015-07-09 17:31:46 -06001330 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
Tobin Ehlisca915872014-11-18 11:28:33 -07001331 self._generate_extensions(),
Jon Ashburn747f2b62015-06-18 15:02:58 -06001332 self._generate_layer_gpa_function(extensions,
Jon Ashburn3dc39382015-09-17 10:00:32 -06001333 instance_extensions)]
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001334 return "\n\n".join(body)
Courtney Goeltzenleuchterb412d212014-11-18 10:40:29 -07001335
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001336class UniqueObjectsSubcommand(Subcommand):
1337 def generate_header(self):
1338 header_txt = []
1339 header_txt.append('%s' % self.lineinfo.get())
1340 header_txt.append('#include "unique_objects.h"')
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001341 return "\n".join(header_txt)
1342
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001343 # Generate UniqueObjects code for given struct_uses dict of objects that need to be unwrapped
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001344 # vector_name_set is used to make sure we don't replicate vector names
1345 # first_level_param indicates if elements are passed directly into the function else they're below a ptr/struct
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001346 # TODO : Comment this code
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001347 def _gen_obj_code(self, struct_uses, param_type, indent, prefix, array_index, vector_name_set, first_level_param):
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001348 decls = ''
1349 pre_code = ''
1350 post_code = ''
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001351 for obj in sorted(struct_uses):
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001352 name = obj
1353 array = ''
1354 if '[' in obj:
1355 (name, array) = obj.split('[')
1356 array = array.strip(']')
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001357 ptr_type = False
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001358 if 'p' == obj[0] and obj[1] != obj[1].lower(): # TODO : Not ideal way to determine ptr
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001359 ptr_type = True
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001360 if isinstance(struct_uses[obj], dict):
1361 local_prefix = ''
1362 name = '%s%s' % (prefix, name)
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001363 if ptr_type:
Tobin Ehlis6dd0fc32016-02-12 14:37:09 -07001364 if first_level_param and name in param_type:
1365 pre_code += '%sif (%s) {\n' % (indent, name)
1366 else: # shadow ptr will have been initialized at this point so check it vs. source ptr
1367 pre_code += '%sif (local_%s) {\n' % (indent, name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001368 indent += ' '
1369 if array != '':
1370 idx = 'idx%s' % str(array_index)
1371 array_index += 1
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001372 if first_level_param and name in param_type:
1373 pre_code += '%slocal_%s = new safe_%s[%s];\n' % (indent, name, param_type[name].strip('*'), array)
1374 post_code += ' if (local_%s)\n' % (name)
1375 post_code += ' delete[] local_%s;\n' % (name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001376 pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001377 indent += ' '
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001378 if first_level_param:
1379 pre_code += '%slocal_%s[%s].initialize(&%s[%s]);\n' % (indent, name, idx, name, idx)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001380 local_prefix = '%s[%s].' % (name, idx)
1381 elif ptr_type:
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001382 if first_level_param and name in param_type:
1383 pre_code += '%slocal_%s = new safe_%s(%s);\n' % (indent, name, param_type[name].strip('*'), name)
1384 post_code += ' if (local_%s)\n' % (name)
1385 post_code += ' delete local_%s;\n' % (name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001386 local_prefix = '%s->' % (name)
1387 else:
1388 local_prefix = '%s.' % (name)
1389 assert isinstance(decls, object)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001390 (tmp_decl, tmp_pre, tmp_post) = self._gen_obj_code(struct_uses[obj], param_type, indent, local_prefix, array_index, vector_name_set, False)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001391 decls += tmp_decl
1392 pre_code += tmp_pre
1393 post_code += tmp_post
1394 if array != '':
1395 indent = indent[4:]
1396 pre_code += '%s}\n' % (indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001397 if ptr_type:
1398 indent = indent[4:]
1399 pre_code += '%s}\n' % (indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001400 else:
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001401 if (array_index > 0) or array != '': # TODO : This is not ideal, really want to know if we're anywhere under an array
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001402 if first_level_param:
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001403 decls += '%s%s* local_%s = NULL;\n' % (indent, struct_uses[obj], name)
Tobin Ehlis6dd0fc32016-02-12 14:37:09 -07001404 if array != '' and not first_level_param: # ptrs under structs will have been initialized so use local_*
1405 pre_code += '%sif (local_%s%s) {\n' %(indent, prefix, name)
1406 else:
1407 pre_code += '%sif (%s%s) {\n' %(indent, prefix, name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001408 indent += ' '
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001409 if array != '':
1410 idx = 'idx%s' % str(array_index)
1411 array_index += 1
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001412 if first_level_param:
1413 pre_code += '%slocal_%s = new %s[%s];\n' % (indent, name, struct_uses[obj], array)
1414 post_code += ' if (local_%s)\n' % (name)
1415 post_code += ' delete[] local_%s;\n' % (name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001416 pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001417 indent += ' '
1418 name = '%s[%s]' % (name, idx)
1419 pName = 'p%s' % (struct_uses[obj][2:])
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001420 if name not in vector_name_set:
1421 vector_name_set.add(name)
Dustin Gravesa7622d82016-04-14 17:29:20 -06001422 pre_code += '%slocal_%s%s = (%s)my_map_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(%s%s)];\n' % (indent, prefix, name, struct_uses[obj], prefix, name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001423 if array != '':
1424 indent = indent[4:]
1425 pre_code += '%s}\n' % (indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001426 indent = indent[4:]
1427 pre_code += '%s}\n' % (indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001428 else:
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001429 pre_code += '%s\n' % (self.lineinfo.get())
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001430 deref_txt = '&'
1431 if ptr_type:
1432 deref_txt = ''
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001433 if '->' in prefix: # need to update local struct
Dustin Gravesa7622d82016-04-14 17:29:20 -06001434 pre_code += '%slocal_%s%s = (%s)my_map_data->unique_id_mapping[reinterpret_cast<const uint64_t &>(%s%s)];\n' % (indent, prefix, name, struct_uses[obj], prefix, name)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001435 else:
Dustin Gravesa7622d82016-04-14 17:29:20 -06001436 pre_code += '%s%s = (%s)my_map_data->unique_id_mapping[reinterpret_cast<uint64_t &>(%s)];\n' % (indent, name, struct_uses[obj], name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001437 return decls, pre_code, post_code
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001438
1439 def generate_intercept(self, proto, qual):
1440 create_func = False
1441 destroy_func = False
1442 last_param_index = None #typcially we look at all params for ndos
1443 pre_call_txt = '' # code prior to calling down chain such as unwrap uses of ndos
1444 post_call_txt = '' # code following call down chain such to wrap newly created ndos, or destroy local wrap struct
1445 funcs = []
1446 indent = ' ' # indent level for generated code
1447 decl = proto.c_func(prefix="vk", attr="VKAPI")
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001448 # A few API cases that are manual code
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001449 # TODO : Special case Create*Pipelines funcs to handle creating multiple unique objects
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001450 explicit_object_tracker_functions = ['GetSwapchainImagesKHR',
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001451 'CreateSwapchainKHR',
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001452 'CreateInstance',
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001453 'DestroyInstance',
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001454 'CreateDevice',
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001455 'DestroyDevice',
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001456 'CreateComputePipelines',
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001457 'CreateGraphicsPipelines'
1458 ]
Tobin Ehlis453e91f2016-01-29 14:24:42 -07001459 # TODO : This is hacky, need to make this a more general-purpose solution for all layers
Cody Northrop0a179fe2016-02-24 12:28:41 -07001460 ifdef_dict = {'CreateXcbSurfaceKHR': 'VK_USE_PLATFORM_XCB_KHR',
1461 'CreateAndroidSurfaceKHR': 'VK_USE_PLATFORM_ANDROID_KHR',
Tony Barboure66d4e42016-04-12 13:35:51 -06001462 'CreateWin32SurfaceKHR': 'VK_USE_PLATFORM_WIN32_KHR',
1463 'CreateXlibSurfaceKHR': 'VK_USE_PLATFORM_XLIB_KHR',
1464 'CreateWaylandSurfaceKHR': 'VK_USE_PLATFORM_WAYLAND_KHR',
1465 'CreateMirSurfaceKHR': 'VK_USE_PLATFORM_MIR_KHR'}
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001466 # Give special treatment to create functions that return multiple new objects
1467 # This dict stores array name and size of array
Jon Ashburnf19916e2016-01-11 13:12:43 -07001468 custom_create_dict = {'pDescriptorSets' : 'pAllocateInfo->descriptorSetCount'}
Courtney Goeltzenleuchter5a0f2832016-02-11 11:44:04 -07001469 pre_call_txt += '%s\n' % (self.lineinfo.get())
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001470 if proto.name in explicit_object_tracker_functions:
1471 funcs.append('%s%s\n'
1472 '{\n'
1473 ' return explicit_%s;\n'
1474 '}' % (qual, decl, proto.c_call()))
1475 return "".join(funcs)
1476 if True in [create_txt in proto.name for create_txt in ['Create', 'Allocate']]:
1477 create_func = True
1478 last_param_index = -1 # For create funcs don't care if last param is ndo
1479 if True in [destroy_txt in proto.name for destroy_txt in ['Destroy', 'Free']]:
1480 destroy_obj_type = proto.params[-2].ty
1481 if destroy_obj_type in vulkan.object_non_dispatch_list:
1482 destroy_func = True
1483
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001484 # First thing we need to do is gather uses of non-dispatchable-objects (ndos)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001485 (struct_uses, local_decls) = get_object_uses(vulkan.object_non_dispatch_list, proto.params[1:last_param_index])
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001486
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001487 dispatch_param = proto.params[0].name
1488 if 'CreateInstance' in proto.name:
1489 dispatch_param = '*' + proto.params[1].name
1490 pre_call_txt += '%slayer_data *my_map_data = get_my_data_ptr(get_dispatch_key(%s), layer_data_map);\n' % (indent, dispatch_param)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001491 if len(struct_uses) > 0:
Mike Stroyan04be7832016-04-07 12:14:30 -06001492 pre_call_txt += '// STRUCT USES:%s\n' % sorted(struct_uses)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001493 if len(local_decls) > 0:
Mike Stroyan04be7832016-04-07 12:14:30 -06001494 pre_call_txt += '//LOCAL DECLS:%s\n' % sorted(local_decls)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001495 if destroy_func: # only one object
Karl Schultz2d6c90e2016-04-29 17:22:50 -06001496 pre_call_txt += '%sstd::unique_lock<std::mutex> lock(global_lock);\n' % (indent)
Mike Stroyan04be7832016-04-07 12:14:30 -06001497 for del_obj in sorted(struct_uses):
Dustin Gravesa7622d82016-04-14 17:29:20 -06001498 pre_call_txt += '%suint64_t local_%s = reinterpret_cast<uint64_t &>(%s);\n' % (indent, del_obj, del_obj)
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001499 pre_call_txt += '%s%s = (%s)my_map_data->unique_id_mapping[local_%s];\n' % (indent, del_obj, struct_uses[del_obj], del_obj)
Karl Schultz2d6c90e2016-04-29 17:22:50 -06001500 pre_call_txt += '%slock.unlock();\n' % (indent)
1501 (pre_decl, pre_code, post_code) = ('', '', '')
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001502 else:
1503 (pre_decl, pre_code, post_code) = self._gen_obj_code(struct_uses, local_decls, ' ', '', 0, set(), True)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001504 # This is a bit hacky but works for now. Need to decl local versions of top-level structs
Mike Stroyan04be7832016-04-07 12:14:30 -06001505 for ld in sorted(local_decls):
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001506 init_null_txt = 'NULL';
1507 if '*' not in local_decls[ld]:
1508 init_null_txt = '{}';
1509 if local_decls[ld].strip('*') not in vulkan.object_non_dispatch_list:
1510 pre_decl += ' safe_%s local_%s = %s;\n' % (local_decls[ld], ld, init_null_txt)
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001511 if pre_code != '': # lock around map uses
1512 pre_code = '%s{\n%sstd::lock_guard<std::mutex> lock(global_lock);\n%s%s}\n' % (indent, indent, pre_code, indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001513 pre_call_txt += '%s%s' % (pre_decl, pre_code)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001514 post_call_txt += '%s' % (post_code)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001515 elif create_func:
1516 base_type = proto.params[-1].ty.replace('const ', '').strip('*')
1517 if base_type not in vulkan.object_non_dispatch_list:
1518 return None
1519 else:
1520 return None
1521
1522 ret_val = ''
1523 ret_stmt = ''
1524 if proto.ret != "void":
1525 ret_val = "%s result = " % proto.ret
1526 ret_stmt = " return result;\n"
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001527 if create_func:
1528 obj_type = proto.params[-1].ty.strip('*')
1529 obj_name = proto.params[-1].name
1530 if obj_type in vulkan.object_non_dispatch_list:
1531 local_name = "unique%s" % obj_type[2:]
1532 post_call_txt += '%sif (VK_SUCCESS == result) {\n' % (indent)
1533 indent += ' '
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001534 post_call_txt += '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % (indent)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001535 if obj_name in custom_create_dict:
1536 post_call_txt += '%s\n' % (self.lineinfo.get())
1537 local_name = '%ss' % (local_name) # add 's' to end for vector of many
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001538 post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, custom_create_dict[obj_name])
1539 indent += ' '
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -06001540 post_call_txt += '%suint64_t unique_id = global_unique_id++;\n' % (indent)
Dustin Gravesa7622d82016-04-14 17:29:20 -06001541 post_call_txt += '%smy_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(%s[i]);\n' % (indent, obj_name)
1542 post_call_txt += '%s%s[i] = reinterpret_cast<%s&>(unique_id);\n' % (indent, obj_name, obj_type)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001543 indent = indent[4:]
1544 post_call_txt += '%s}\n' % (indent)
1545 else:
1546 post_call_txt += '%s\n' % (self.lineinfo.get())
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -06001547 post_call_txt += '%suint64_t unique_id = global_unique_id++;\n' % (indent)
Dustin Gravesa7622d82016-04-14 17:29:20 -06001548 post_call_txt += '%smy_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*%s);\n' % (indent, obj_name)
1549 post_call_txt += '%s*%s = reinterpret_cast<%s&>(unique_id);\n' % (indent, obj_name, obj_type)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001550 indent = indent[4:]
1551 post_call_txt += '%s}\n' % (indent)
1552 elif destroy_func:
1553 del_obj = proto.params[-2].name
1554 if 'count' in del_obj.lower():
1555 post_call_txt += '%s\n' % (self.lineinfo.get())
1556 post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, del_obj)
1557 del_obj = proto.params[-1].name
1558 indent += ' '
1559 post_call_txt += '%sdelete (VkUniqueObject*)%s[i];\n' % (indent, del_obj)
1560 indent = indent[4:]
1561 post_call_txt += '%s}\n' % (indent)
1562 else:
1563 post_call_txt += '%s\n' % (self.lineinfo.get())
Karl Schultz2d6c90e2016-04-29 17:22:50 -06001564 post_call_txt += '%slock.lock();\n' % (indent)
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001565 post_call_txt += '%smy_map_data->unique_id_mapping.erase(local_%s);\n' % (indent, proto.params[-2].name)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001566
1567 call_sig = proto.c_call()
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001568 # Replace default params with any custom local params
1569 for ld in local_decls:
1570 call_sig = call_sig.replace(ld, '(const %s)local_%s' % (local_decls[ld], ld))
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001571 if proto_is_global(proto):
1572 table_type = "instance"
1573 else:
1574 table_type = "device"
1575 pre_call_txt += '%s\n' % (self.lineinfo.get())
Tobin Ehlis453e91f2016-01-29 14:24:42 -07001576 open_ifdef = ''
1577 close_ifdef = ''
1578 if proto.name in ifdef_dict:
1579 open_ifdef = '#ifdef %s\n' % (ifdef_dict[proto.name])
1580 close_ifdef = '#endif\n'
1581 funcs.append('%s'
1582 '%s%s\n'
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001583 '{\n'
1584 '%s'
1585 ' %sget_dispatch_table(unique_objects_%s_table_map, %s)->%s;\n'
1586 '%s'
1587 '%s'
Tobin Ehlis453e91f2016-01-29 14:24:42 -07001588 '}\n'
1589 '%s' % (open_ifdef, qual, decl, pre_call_txt, ret_val, table_type, dispatch_param, call_sig, post_call_txt, ret_stmt, close_ifdef))
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001590 return "\n\n".join(funcs)
1591
1592 def generate_body(self):
1593 self.layer_name = "unique_objects"
1594 extensions=[('wsi_enabled',
1595 ['vkCreateSwapchainKHR',
1596 'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR',
1597 'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])]
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001598 if self.wsi == 'Win32':
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001599 instance_extensions=[('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001600 ['vkDestroySurfaceKHR',
1601 'vkGetPhysicalDeviceSurfaceSupportKHR',
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001602 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1603 'vkGetPhysicalDeviceSurfaceFormatsKHR',
1604 'vkGetPhysicalDeviceSurfacePresentModesKHR',
Jon Ashburn00dc7412016-01-07 16:13:06 -07001605 'vkCreateWin32SurfaceKHR'
1606 ])]
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001607 elif self.wsi == 'Android':
1608 instance_extensions=[('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001609 ['vkDestroySurfaceKHR',
1610 'vkGetPhysicalDeviceSurfaceSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001611 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1612 'vkGetPhysicalDeviceSurfaceFormatsKHR',
Michael Lentine56512bb2016-03-02 17:28:55 -06001613 'vkGetPhysicalDeviceSurfacePresentModesKHR',
1614 'vkCreateAndroidSurfaceKHR'])]
Karl Schultz9daf7a32016-03-08 15:14:11 -07001615 elif self.wsi == 'Xcb' or self.wsi == 'Xlib' or self.wsi == 'Wayland' or self.wsi == 'Mir':
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001616 instance_extensions=[('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001617 ['vkDestroySurfaceKHR',
1618 'vkGetPhysicalDeviceSurfaceSupportKHR',
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001619 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1620 'vkGetPhysicalDeviceSurfaceFormatsKHR',
1621 'vkGetPhysicalDeviceSurfacePresentModesKHR',
Courtney Goeltzenleuchter5a0f2832016-02-11 11:44:04 -07001622 'vkCreateXcbSurfaceKHR',
Karl Schultz9daf7a32016-03-08 15:14:11 -07001623 'vkCreateXlibSurfaceKHR',
1624 'vkCreateWaylandSurfaceKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001625 'vkCreateMirSurfaceKHR'
1626 ])]
Karl Schultz9daf7a32016-03-08 15:14:11 -07001627 else:
1628 print('Error: Undefined DisplayServer')
1629 instance_extensions=[]
1630
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001631 body = [self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
1632 self._generate_layer_gpa_function(extensions,
1633 instance_extensions)]
1634 return "\n\n".join(body)
1635
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001636def main():
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001637 wsi = {
1638 "Win32",
1639 "Android",
1640 "Xcb",
1641 "Xlib",
1642 "Wayland",
1643 "Mir",
1644 }
1645
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001646 subcommands = {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07001647 "object_tracker" : ObjectTrackerSubcommand,
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001648 "unique_objects" : UniqueObjectsSubcommand,
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001649 }
1650
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001651 if len(sys.argv) < 4 or sys.argv[1] not in wsi or sys.argv[2] not in subcommands or not os.path.exists(sys.argv[3]):
Jamie Madilldbda66b2016-05-10 07:36:20 -07001652 print("Usage: %s <wsi> <subcommand> <input_header> [outdir]" % sys.argv[0])
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001653 print
Tobin Ehlis7e65d752015-01-15 17:51:52 -07001654 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001655 exit(1)
1656
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001657 hfp = vk_helper.HeaderFileParser(sys.argv[3])
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001658 hfp.parse()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001659 vk_helper.enum_val_dict = hfp.get_enum_val_dict()
1660 vk_helper.enum_type_dict = hfp.get_enum_type_dict()
1661 vk_helper.struct_dict = hfp.get_struct_dict()
1662 vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1663 vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1664 vk_helper.types_dict = hfp.get_types_dict()
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001665
Jamie Madilldbda66b2016-05-10 07:36:20 -07001666 outfile = None
1667 if len(sys.argv) >= 5:
1668 outfile = sys.argv[4]
1669
1670 subcmd = subcommands[sys.argv[2]](outfile)
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001671 subcmd.run()
1672
1673if __name__ == "__main__":
1674 main()