blob: 3a07ce957b4c86705169220645462515aaa4a7e7 [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):
167 def __init__(self, argv):
168 self.argv = argv
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):
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600177 print(self.generate())
178
179 def generate(self):
180 copyright = self.generate_copyright()
181 header = self.generate_header()
182 body = self.generate_body()
183 footer = self.generate_footer()
184
185 contents = []
186 if copyright:
187 contents.append(copyright)
188 if header:
189 contents.append(header)
190 if body:
191 contents.append(body)
192 if footer:
193 contents.append(footer)
194
195 return "\n\n".join(contents)
196
197 def generate_copyright(self):
198 return """/* THIS FILE IS GENERATED. DO NOT EDIT. */
199
200/*
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -0700201 * Copyright (c) 2015-2016 The Khronos Group Inc.
202 * Copyright (c) 2015-2016 Valve Corporation
203 * Copyright (c) 2015-2016 LunarG, Inc.
Tobin Ehlis10ba1de2016-04-13 12:59:43 -0600204 * Copyright (c) 2015-2016 Google, Inc.
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600205 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -0600206 * Licensed under the Apache License, Version 2.0 (the "License");
207 * you may not use this file except in compliance with the License.
208 * You may obtain a copy of the License at
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600209 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -0600210 * http://www.apache.org/licenses/LICENSE-2.0
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600211 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -0600212 * Unless required by applicable law or agreed to in writing, software
213 * distributed under the License is distributed on an "AS IS" BASIS,
214 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
215 * See the License for the specific language governing permissions and
216 * limitations under the License.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -0600217 *
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700218 * Author: Tobin Ehlis <tobine@google.com>
219 * Author: Courtney Goeltzenleuchter <courtneygo@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -0600220 * Author: Jon Ashburn <jon@lunarg.com>
221 * Author: Mark Lobodzinski <mark@lunarg.com>
Tobin Ehlisd34a4c52015-12-08 10:50:10 -0700222 * Author: Mike Stroyan <stroyan@google.com>
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -0600223 * Author: Tony Barbour <tony@LunarG.com>
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600224 */"""
225
226 def generate_header(self):
227 return "\n".join(["#include <" + h + ">" for h in self.headers])
228
229 def generate_body(self):
230 pass
231
232 def generate_footer(self):
233 pass
234
235 # Return set of printf '%' qualifier and input to that qualifier
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600236 def _get_printf_params(self, vk_type, name, output_param, cpp=False):
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600237 # TODO : Need ENUM and STRUCT checks here
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600238 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 -0600239 return ("%s", "string_%s(%s)" % (vk_type.replace('const ', '').strip('*'), name))
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600240 if "char*" == vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600241 return ("%s", name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600242 if "uint64" in vk_type:
243 if '*' in vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600244 return ("%lu", "*%s" % name)
245 return ("%lu", name)
Tobin Ehlisa30e7e52015-07-06 14:02:36 -0600246 if vk_type.strip('*') in vulkan.object_non_dispatch_list:
247 if '*' in vk_type:
Chia-I Wue2fc5522015-10-26 20:04:44 +0800248 return ("%lu", "%s" % name)
249 return ("%lu", "%s" % name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600250 if "size" in vk_type:
251 if '*' in vk_type:
Mark Lobodzinskia1456492015-10-06 09:57:52 -0600252 return ("%lu", "(unsigned long)*%s" % name)
253 return ("%lu", "(unsigned long)%s" % name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600254 if "float" in vk_type:
255 if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis99f88672015-01-10 12:42:41 -0700256 if cpp:
257 return ("[%i, %i, %i, %i]", '"[" << %s[0] << "," << %s[1] << "," << %s[2] << "," << %s[3] << "]"' % (name, name, name, name))
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600258 return ("[%f, %f, %f, %f]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
259 return ("%f", name)
Courtney Goeltzenleuchtercd2a0992015-07-09 11:44:38 -0600260 if "bool" in vk_type.lower() or 'xcb_randr_crtc_t' in vk_type:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600261 return ("%u", name)
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600262 if True in [t in vk_type.lower() for t in ["int", "flags", "mask", "xcb_window_t"]]:
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600263 if '[' in vk_type: # handle array, current hard-coded to 4 (TODO: Make this dynamic)
Tobin Ehlis99f88672015-01-10 12:42:41 -0700264 if cpp:
265 return ("[%i, %i, %i, %i]", "%s[0] << %s[1] << %s[2] << %s[3]" % (name, name, name, name))
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600266 return ("[%i, %i, %i, %i]", "%s[0], %s[1], %s[2], %s[3]" % (name, name, name, name))
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600267 if '*' in vk_type:
Tobin Ehlisd2b88e82015-02-04 15:15:11 -0700268 if 'pUserData' == name:
269 return ("%i", "((pUserData == 0) ? 0 : *(pUserData))")
Tobin Ehlisc62cb892015-04-17 13:26:33 -0600270 if 'const' in vk_type.lower():
271 return ("%p", "(void*)(%s)" % name)
Jon Ashburn52f79b52014-12-12 16:10:45 -0700272 return ("%i", "*(%s)" % name)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600273 return ("%i", name)
Tobin Ehlis3a1cc8d2014-11-11 17:28:22 -0700274 # 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 -0600275 if "VkFormat" == vk_type:
Tobin Ehlis99f88672015-01-10 12:42:41 -0700276 if cpp:
277 return ("%p", "&%s" % name)
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800278 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 -0700279 if output_param:
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600280 return ("%p", "(void*)*%s" % name)
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600281 if vk_helper.is_type(vk_type, 'struct') and '*' not in vk_type:
Courtney Goeltzenleuchterd462fba2015-04-03 16:35:32 -0600282 return ("%p", "(void*)(&%s)" % name)
Jon Ashburn52f79b52014-12-12 16:10:45 -0700283 return ("%p", "(void*)(%s)" % name)
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600284
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600285 def _gen_create_msg_callback(self):
Tobin Ehlise8185062014-12-17 08:01:59 -0700286 r_body = []
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600287 r_body.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700288 r_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(')
289 r_body.append(' VkInstance instance,')
290 r_body.append(' const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,')
291 r_body.append(' const VkAllocationCallbacks* pAllocator,')
292 r_body.append(' VkDebugReportCallbackEXT* pCallback)')
Tobin Ehlise8185062014-12-17 08:01:59 -0700293 r_body.append('{')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600294 # Switch to this code section for the new per-instance storage and debug callbacks
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600295 if self.layer_name in ['object_tracker', 'unique_objects']:
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600296 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700297 r_body.append(' VkResult result = pInstanceTable->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600298 r_body.append(' if (VK_SUCCESS == result) {')
299 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 -0700300 r_body.append(' result = layer_create_msg_callback(my_data->report_data,')
301 r_body.append(' pCreateInfo,')
302 r_body.append(' pAllocator,')
303 r_body.append(' pCallback);')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600304 r_body.append(' }')
305 r_body.append(' return result;')
306 else:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700307 r_body.append(' VkResult result = instance_dispatch_table(instance)->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);')
Jon Ashburn3a278b72015-10-06 17:05:21 -0600308 r_body.append(' if (VK_SUCCESS == result) {')
309 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 -0700310 r_body.append(' result = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pCallback);')
Jon Ashburn3a278b72015-10-06 17:05:21 -0600311 r_body.append(' }')
312 r_body.append(' return result;')
Tobin Ehlise8185062014-12-17 08:01:59 -0700313 r_body.append('}')
314 return "\n".join(r_body)
315
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600316 def _gen_destroy_msg_callback(self):
317 r_body = []
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600318 r_body.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700319 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 -0600320 r_body.append('{')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600321 # Switch to this code section for the new per-instance storage and debug callbacks
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600322 if self.layer_name in ['object_tracker', 'unique_objects']:
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600323 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600324 else:
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700325 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700326 r_body.append(' pInstanceTable->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);')
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700327 r_body.append(' layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);')
328 r_body.append(' layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);')
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600329 r_body.append('}')
330 return "\n".join(r_body)
Tobin Ehlise8185062014-12-17 08:01:59 -0700331
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700332 def _gen_debug_report_msg(self):
333 r_body = []
334 r_body.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700335 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 -0700336 r_body.append('{')
337 # Switch to this code section for the new per-instance storage and debug callbacks
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600338 if self.layer_name == 'object_tracker':
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700339 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(%s_instance_table_map, instance);' % self.layer_name )
340 else:
341 r_body.append(' VkLayerInstanceDispatchTable *pInstanceTable = instance_dispatch_table(instance);')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700342 r_body.append(' pInstanceTable->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);')
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700343 r_body.append('}')
344 return "\n".join(r_body)
345
Jon Ashburn1f32a442016-02-02 13:13:01 -0700346 def _gen_layer_get_global_extension_props(self, layer="object_tracker"):
Tony Barbour59a47322015-06-24 16:06:58 -0600347 ggep_body = []
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600348 # generated layers do not provide any global extensions
349 ggep_body.append('%s' % self.lineinfo.get())
350
351 ggep_body.append('')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600352 if self.layer_name == 'object_tracker':
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700353 ggep_body.append('static const VkExtensionProperties instance_extensions[] = {')
354 ggep_body.append(' {')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700355 ggep_body.append(' VK_EXT_DEBUG_REPORT_EXTENSION_NAME,')
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -0700356 ggep_body.append(' VK_EXT_DEBUG_REPORT_SPEC_VERSION')
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700357 ggep_body.append(' }')
358 ggep_body.append('};')
Chia-I Wu9ab61502015-11-06 06:42:02 +0800359 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 -0600360 ggep_body.append('{')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600361 if self.layer_name == 'object_tracker':
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700362 ggep_body.append(' return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);')
363 else:
364 ggep_body.append(' return util_GetExtensionProperties(0, NULL, pCount, pProperties);')
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600365 ggep_body.append('}')
366 return "\n".join(ggep_body)
367
Jon Ashburn1f32a442016-02-02 13:13:01 -0700368 def _gen_layer_get_global_layer_props(self, layer="object_tracker"):
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600369 ggep_body = []
Jon Ashburn1f32a442016-02-02 13:13:01 -0700370 layer_name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', layer)
371 layer_name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', layer_name).lower()
372 ggep_body.append('%s' % self.lineinfo.get())
373 ggep_body.append('static const VkLayerProperties globalLayerProps[] = {')
374 ggep_body.append(' {')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600375 if self.layer_name in ['unique_objects']:
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700376 ggep_body.append(' "VK_LAYER_GOOGLE_%s",' % layer)
Jon Ashburndc9111c2016-03-22 12:57:13 -0600377 ggep_body.append(' VK_LAYER_API_VERSION, // specVersion')
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700378 ggep_body.append(' 1, // implementationVersion')
379 ggep_body.append(' "Google Validation Layer"')
380 else:
381 ggep_body.append(' "VK_LAYER_LUNARG_%s",' % layer)
Jon Ashburndc9111c2016-03-22 12:57:13 -0600382 ggep_body.append(' VK_LAYER_API_VERSION, // specVersion')
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700383 ggep_body.append(' 1, // implementationVersion')
384 ggep_body.append(' "LunarG Validation Layer"')
Jon Ashburn1f32a442016-02-02 13:13:01 -0700385 ggep_body.append(' }')
386 ggep_body.append('};')
Tony Barbour59a47322015-06-24 16:06:58 -0600387 ggep_body.append('')
388 ggep_body.append('%s' % self.lineinfo.get())
Tony Barbour59a47322015-06-24 16:06:58 -0600389 ggep_body.append('')
Chia-I Wu9ab61502015-11-06 06:42:02 +0800390 ggep_body.append('VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties* pProperties)')
Tony Barbour59a47322015-06-24 16:06:58 -0600391 ggep_body.append('{')
Courtney Goeltzenleuchter79a5a962015-07-07 17:51:45 -0600392 ggep_body.append(' return util_GetLayerProperties(ARRAY_SIZE(globalLayerProps), globalLayerProps, pCount, pProperties);')
Tony Barbour59a47322015-06-24 16:06:58 -0600393 ggep_body.append('}')
394 return "\n".join(ggep_body)
395
Jon Ashburn1f32a442016-02-02 13:13:01 -0700396 def _gen_layer_get_physical_device_layer_props(self, layer="object_tracker"):
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600397 gpdlp_body = []
Jon Ashburn1f32a442016-02-02 13:13:01 -0700398 gpdlp_body.append('%s' % self.lineinfo.get())
399 gpdlp_body.append('static const VkLayerProperties deviceLayerProps[] = {')
400 gpdlp_body.append(' {')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600401 if self.layer_name in ['unique_objects']:
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700402 gpdlp_body.append(' "VK_LAYER_GOOGLE_%s",' % layer)
Jon Ashburndc9111c2016-03-22 12:57:13 -0600403 gpdlp_body.append(' VK_LAYER_API_VERSION, // specVersion')
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700404 gpdlp_body.append(' 1, // implementationVersion')
405 gpdlp_body.append(' "Google Validation Layer"')
406 else:
407 gpdlp_body.append(' "VK_LAYER_LUNARG_%s",' % layer)
Jon Ashburndc9111c2016-03-22 12:57:13 -0600408 gpdlp_body.append(' VK_LAYER_API_VERSION, // specVersion')
Courtney Goeltzenleuchterfb4c1c32016-02-08 11:16:21 -0700409 gpdlp_body.append(' 1, // implementationVersion')
410 gpdlp_body.append(' "LunarG Validation Layer"')
Jon Ashburn1f32a442016-02-02 13:13:01 -0700411 gpdlp_body.append(' }')
412 gpdlp_body.append('};')
Chia-I Wu9ab61502015-11-06 06:42:02 +0800413 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 -0600414 gpdlp_body.append('{')
Courtney Goeltzenleuchter79a5a962015-07-07 17:51:45 -0600415 gpdlp_body.append(' return util_GetLayerProperties(ARRAY_SIZE(deviceLayerProps), deviceLayerProps, pCount, pProperties);')
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600416 gpdlp_body.append('}')
417 gpdlp_body.append('')
418 return "\n".join(gpdlp_body)
419
Mike Stroyanbf237d72015-04-03 17:45:53 -0600420 def _generate_dispatch_entrypoints(self, qual=""):
Mike Stroyan938c2532015-04-03 13:58:35 -0600421 if qual:
422 qual += " "
423
Mike Stroyan938c2532015-04-03 13:58:35 -0600424 funcs = []
425 intercepted = []
426 for proto in self.protos:
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600427 if proto.name == "GetDeviceProcAddr" or proto.name == "GetInstanceProcAddr":
Jon Ashburn8fd08252015-05-28 16:25:02 -0600428 continue
Mike Stroyan70c05e82015-04-08 10:27:43 -0600429 else:
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600430 intercept = self.generate_intercept(proto, qual)
Mike Stroyan938c2532015-04-03 13:58:35 -0600431 if intercept is None:
432 # fill in default intercept for certain entrypoints
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700433 if 'CreateDebugReportCallbackEXT' == proto.name:
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600434 intercept = self._gen_layer_dbg_create_msg_callback()
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700435 elif 'DestroyDebugReportCallbackEXT' == proto.name:
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600436 intercept = self._gen_layer_dbg_destroy_msg_callback()
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700437 elif 'DebugReportMessageEXT' == proto.name:
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700438 intercept = self._gen_debug_report_msg()
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600439 elif 'CreateDevice' == proto.name:
440 funcs.append('/* CreateDevice HERE */')
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600441 elif 'EnumerateInstanceExtensionProperties' == proto.name:
Tony Barbour59a47322015-06-24 16:06:58 -0600442 intercept = self._gen_layer_get_global_extension_props(self.layer_name)
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600443 elif 'EnumerateInstanceLayerProperties' == proto.name:
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600444 intercept = self._gen_layer_get_global_layer_props(self.layer_name)
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600445 elif 'EnumerateDeviceLayerProperties' == proto.name:
Courtney Goeltzenleuchter110fdf92015-06-29 15:39:26 -0600446 intercept = self._gen_layer_get_physical_device_layer_props(self.layer_name)
Tony Barbour59a47322015-06-24 16:06:58 -0600447
Mike Stroyan938c2532015-04-03 13:58:35 -0600448 if intercept is not None:
449 funcs.append(intercept)
Ian Elliott7e40db92015-08-21 15:09:33 -0600450 if not "KHR" in proto.name:
Jon Ashburn747f2b62015-06-18 15:02:58 -0600451 intercepted.append(proto)
Mike Stroyan938c2532015-04-03 13:58:35 -0600452
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600453 prefix="vk"
Mike Stroyan938c2532015-04-03 13:58:35 -0600454 lookups = []
455 for proto in intercepted:
Mike Stroyan938c2532015-04-03 13:58:35 -0600456 lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600457 lookups.append(" return (PFN_vkVoidFunction) %s%s;" %
Mike Stroyan938c2532015-04-03 13:58:35 -0600458 (prefix, proto.name))
Mike Stroyan938c2532015-04-03 13:58:35 -0600459
460 # add customized layer_intercept_proc
461 body = []
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600462 body.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600463 body.append("static inline PFN_vkVoidFunction layer_intercept_proc(const char *name)")
Mike Stroyan938c2532015-04-03 13:58:35 -0600464 body.append("{")
465 body.append(generate_get_proc_addr_check("name"))
466 body.append("")
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600467 body.append(" name += 2;")
Mike Stroyan938c2532015-04-03 13:58:35 -0600468 body.append(" %s" % "\n ".join(lookups))
469 body.append("")
470 body.append(" return NULL;")
471 body.append("}")
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600472 # add layer_intercept_instance_proc
473 lookups = []
474 for proto in self.protos:
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600475 if not proto_is_global(proto):
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600476 continue
477
478 if not proto in intercepted:
479 continue
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700480 if proto.name == "CreateInstance":
481 continue
Courtney Goeltzenleuchterca173b82015-06-25 18:01:43 -0600482 if proto.name == "CreateDevice":
483 continue
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600484 lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600485 lookups.append(" return (PFN_vkVoidFunction) %s%s;" % (prefix, proto.name))
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600486
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600487 body.append("static inline PFN_vkVoidFunction layer_intercept_instance_proc(const char *name)")
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600488 body.append("{")
489 body.append(generate_get_proc_addr_check("name"))
490 body.append("")
491 body.append(" name += 2;")
492 body.append(" %s" % "\n ".join(lookups))
493 body.append("")
494 body.append(" return NULL;")
495 body.append("}")
496
Mike Stroyan938c2532015-04-03 13:58:35 -0600497 funcs.append("\n".join(body))
Mike Stroyan938c2532015-04-03 13:58:35 -0600498 return "\n\n".join(funcs)
499
Tobin Ehlisca915872014-11-18 11:28:33 -0700500 def _generate_extensions(self):
501 exts = []
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600502 exts.append('%s' % self.lineinfo.get())
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600503 exts.append(self._gen_create_msg_callback())
504 exts.append(self._gen_destroy_msg_callback())
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700505 exts.append(self._gen_debug_report_msg())
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600506 return "\n".join(exts)
507
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600508 def _generate_layer_gpa_function(self, extensions=[], instance_extensions=[]):
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600509 func_body = []
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600510#
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600511# New style of GPA Functions for the new layer_data/layer_logging changes
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600512#
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600513 if self.layer_name in ['object_tracker', 'unique_objects']:
Chia-I Wu9ab61502015-11-06 06:42:02 +0800514 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 -0600515 "{\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600516 " PFN_vkVoidFunction addr;\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600517 " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600518 " return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600519 " }\n\n"
520 " addr = layer_intercept_proc(funcName);\n"
521 " if (addr)\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700522 " return addr;\n"
523 " if (device == VK_NULL_HANDLE) {\n"
524 " return NULL;\n"
525 " }\n")
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600526 if 0 != len(extensions):
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600527 func_body.append('%s' % self.lineinfo.get())
528 func_body.append(' layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600529 for (ext_enable, ext_list) in extensions:
530 extra_space = ""
531 if 0 != len(ext_enable):
Courtney Goeltzenleuchter3f9f7c42015-07-06 09:11:12 -0600532 func_body.append(' if (my_device_data->%s) {' % ext_enable)
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600533 extra_space = " "
534 for ext_name in ext_list:
535 func_body.append(' %sif (!strcmp("%s", funcName))\n'
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600536 ' %sreturn reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, extra_space, ext_name))
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600537 if 0 != len(ext_enable):
538 func_body.append(' }\n')
539 func_body.append("\n if (get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr == NULL)\n"
540 " return NULL;\n"
541 " return get_dispatch_table(%s_device_table_map, device)->GetDeviceProcAddr(device, funcName);\n"
542 "}\n" % (self.layer_name, self.layer_name))
Chia-I Wu9ab61502015-11-06 06:42:02 +0800543 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 -0600544 "{\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600545 " PFN_vkVoidFunction addr;\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700546 " if (!strcmp(funcName, \"vkGetInstanceProcAddr\"))\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600547 " return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700548 " if (!strcmp(funcName, \"vkCreateInstance\"))\n"
549 " return (PFN_vkVoidFunction) vkCreateInstance;\n"
550 " if (!strcmp(funcName, \"vkCreateDevice\"))\n"
551 " return (PFN_vkVoidFunction) vkCreateDevice;\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600552 " addr = layer_intercept_instance_proc(funcName);\n"
553 " if (addr) {\n"
554 " return addr;"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700555 " }\n"
556 " if (instance == VK_NULL_HANDLE) {\n"
557 " return NULL;\n"
558 " }\n"
559 )
Jon Ashburnbacb0f52015-04-06 10:58:22 -0600560
Jon Ashburn3dc39382015-09-17 10:00:32 -0600561 table_declared = False
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600562 if 0 != len(instance_extensions):
Jon Ashburn3dc39382015-09-17 10:00:32 -0600563 for (ext_enable, ext_list) in instance_extensions:
564 extra_space = ""
565 if 0 != len(ext_enable):
566 if ext_enable == 'msg_callback_get_proc_addr':
567 func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600568 " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n"
569 " if (addr) {\n"
570 " return addr;\n"
Jon Ashburn3dc39382015-09-17 10:00:32 -0600571 " }\n")
572 else:
573 if table_declared == False:
574 func_body.append(" VkLayerInstanceDispatchTable* pTable = get_dispatch_table(%s_instance_table_map, instance);" % self.layer_name)
575 table_declared = True
576 func_body.append(' if (instanceExtMap.size() != 0 && instanceExtMap[pTable].%s)' % ext_enable)
577 func_body.append(' {')
578 extra_space = " "
579 for ext_name in ext_list:
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700580 if wsi_name(ext_name):
581 func_body.append('%s' % wsi_ifdef(ext_name))
Jon Ashburn3dc39382015-09-17 10:00:32 -0600582 func_body.append(' %sif (!strcmp("%s", funcName))\n'
583 ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name))
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700584 if wsi_name(ext_name):
585 func_body.append('%s' % wsi_endif(ext_name))
Jon Ashburn3dc39382015-09-17 10:00:32 -0600586 if 0 != len(ext_enable):
587 func_body.append(' }\n')
588
589 func_body.append(" if (get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr == NULL) {\n"
590 " return NULL;\n"
591 " }\n"
592 " return get_dispatch_table(%s_instance_table_map, instance)->GetInstanceProcAddr(instance, funcName);\n"
593 "}\n" % (self.layer_name, self.layer_name))
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600594 return "\n".join(func_body)
595 else:
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600596 func_body.append('%s' % self.lineinfo.get())
Chia-I Wu9ab61502015-11-06 06:42:02 +0800597 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 -0600598 "{\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700599 " PFN_vkVoidFunction addr;\n")
Jon Ashburn1f32a442016-02-02 13:13:01 -0700600 func_body.append("\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600601 " loader_platform_thread_once(&initOnce, init%s);\n\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600602 " if (!strcmp(\"vkGetDeviceProcAddr\", funcName)) {\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600603 " return (PFN_vkVoidFunction) vkGetDeviceProcAddr;\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600604 " }\n\n"
605 " addr = layer_intercept_proc(funcName);\n"
606 " if (addr)\n"
607 " return addr;" % self.layer_name)
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700608 func_body.append(" if (device == VK_NULL_HANDLE) {\n"
609 " return NULL;\n"
610 " }\n")
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600611 func_body.append('')
612 func_body.append(' VkLayerDispatchTable *pDisp = device_dispatch_table(device);')
613 if 0 != len(extensions):
614 extra_space = ""
615 for (ext_enable, ext_list) in extensions:
616 if 0 != len(ext_enable):
Jon Ashburn8acd2332015-09-16 18:08:32 -0600617 func_body.append(' if (deviceExtMap.size() != 0 && deviceExtMap[pDisp].%s)' % ext_enable)
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600618 func_body.append(' {')
619 extra_space = " "
620 for ext_name in ext_list:
621 func_body.append(' %sif (!strcmp("%s", funcName))\n'
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600622 ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name))
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600623 if 0 != len(ext_enable):
624 func_body.append(' }')
625 func_body.append('%s' % self.lineinfo.get())
626 func_body.append(" {\n"
627 " if (pDisp->GetDeviceProcAddr == NULL)\n"
628 " return NULL;\n"
629 " return pDisp->GetDeviceProcAddr(device, funcName);\n"
630 " }\n"
631 "}\n")
Jon Ashburn3dc39382015-09-17 10:00:32 -0600632 func_body.append('%s' % self.lineinfo.get())
Chia-I Wu9ab61502015-11-06 06:42:02 +0800633 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 -0600634 "{\n"
Courtney Goeltzenleuchter2d3ba632015-07-12 14:35:22 -0600635 " PFN_vkVoidFunction addr;\n"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700636 " if (!strcmp(funcName, \"vkGetInstanceProcAddr\"))\n"
637 " return (PFN_vkVoidFunction) vkGetInstanceProcAddr;\n"
638 " if (!strcmp(funcName, \"vkCreateInstance\"))\n"
639 " return (PFN_vkVoidFunction) vkCreateInstance;\n"
640 " if (!strcmp(funcName, \"vkCreateDevice\"))\n"
641 " return (PFN_vkVoidFunction) vkCreateDevice;\n"
642 )
Jon Ashburn1f32a442016-02-02 13:13:01 -0700643 func_body.append(
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600644 " loader_platform_thread_once(&initOnce, init%s);\n\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600645 " addr = layer_intercept_instance_proc(funcName);\n"
646 " if (addr)\n"
647 " return addr;" % self.layer_name)
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700648 func_body.append(" if (instance == VK_NULL_HANDLE) {\n"
649 " return NULL;\n"
650 " }\n")
Jon Ashburn3dc39382015-09-17 10:00:32 -0600651 func_body.append("")
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700652 func_body.append(" VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);\n")
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600653 if 0 != len(instance_extensions):
Jon Ashburn3dc39382015-09-17 10:00:32 -0600654 extra_space = ""
655 for (ext_enable, ext_list) in instance_extensions:
656 if 0 != len(ext_enable):
Jon Ashburn3a278b72015-10-06 17:05:21 -0600657 if ext_enable == 'msg_callback_get_proc_addr':
658 func_body.append(" layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);\n"
659 " addr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);\n"
660 " if (addr) {\n"
661 " return addr;\n"
662 " }\n")
663 else:
664 func_body.append(' if (instanceExtMap.size() != 0 && instanceExtMap[pTable].%s)' % ext_enable)
665 func_body.append(' {')
666 extra_space = " "
667 for ext_name in ext_list:
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700668 if wsi_name(ext_name):
669 func_body.append('%s' % wsi_ifdef(ext_name))
Jon Ashburn3a278b72015-10-06 17:05:21 -0600670 func_body.append(' %sif (!strcmp("%s", funcName))\n'
Jon Ashburn3dc39382015-09-17 10:00:32 -0600671 ' return reinterpret_cast<PFN_vkVoidFunction>(%s);' % (extra_space, ext_name, ext_name))
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -0700672 if wsi_name(ext_name):
673 func_body.append('%s' % wsi_endif(ext_name))
Jon Ashburn3a278b72015-10-06 17:05:21 -0600674 if 0 != len(ext_enable):
675 func_body.append(' }\n')
Jon Ashburn3dc39382015-09-17 10:00:32 -0600676
677 func_body.append(" if (pTable->GetInstanceProcAddr == NULL)\n"
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600678 " return NULL;\n"
679 " return pTable->GetInstanceProcAddr(instance, funcName);\n"
680 "}\n")
681 return "\n".join(func_body)
Jon Ashburnf6b33db2015-05-05 14:22:52 -0600682
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600683
Mike Stroyaned238bb2015-05-15 08:50:57 -0600684 def _generate_layer_initialization(self, init_opts=False, prefix='vk', lockname=None, condname=None):
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600685 func_body = ["#include \"vk_dispatch_table_helper.h\""]
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600686 func_body.append('%s' % self.lineinfo.get())
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700687 func_body.append('static void init_%s(layer_data *my_data, const VkAllocationCallbacks *pAllocator)\n'
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -0600688 '{\n' % self.layer_name)
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700689 if init_opts:
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600690 func_body.append('%s' % self.lineinfo.get())
Jon Ashburnd6badbc2015-02-16 08:26:50 -0700691 func_body.append('')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600692 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 -0600693 func_body.append('')
694 if lockname is not None:
695 func_body.append('%s' % self.lineinfo.get())
696 func_body.append(" if (!%sLockInitialized)" % lockname)
697 func_body.append(" {")
698 func_body.append(" // TODO/TBD: Need to delete this mutex sometime. How???")
699 func_body.append(" loader_platform_thread_create_mutex(&%sLock);" % lockname)
700 if condname is not None:
701 func_body.append(" loader_platform_thread_init_cond(&%sCond);" % condname)
702 func_body.append(" %sLockInitialized = 1;" % lockname)
703 func_body.append(" }")
704 func_body.append("}\n")
705 func_body.append('')
706 return "\n".join(func_body)
707
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600708class ObjectTrackerSubcommand(Subcommand):
709 def generate_header(self):
710 header_txt = []
Tobin Ehlis08fafd02015-06-12 12:49:01 -0600711 header_txt.append('%s' % self.lineinfo.get())
Jamie Madilldf5d5732016-04-04 11:54:43 -0400712 header_txt.append('#include "vk_loader_platform.h"')
713 header_txt.append('#include "vulkan/vulkan.h"')
714 header_txt.append('')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600715 header_txt.append('#include <stdio.h>')
716 header_txt.append('#include <stdlib.h>')
717 header_txt.append('#include <string.h>')
718 header_txt.append('#include <inttypes.h>')
719 header_txt.append('')
Tobin Ehlis803cc492015-06-08 17:36:28 -0600720 header_txt.append('#include <unordered_map>')
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600721 header_txt.append('')
David Pinedo9316d3b2015-11-06 12:54:48 -0700722 header_txt.append('#include "vulkan/vk_layer.h"')
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -0600723 header_txt.append('#include "vk_layer_config.h"')
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -0600724 header_txt.append('#include "vk_layer_table.h"')
725 header_txt.append('#include "vk_layer_data.h"')
726 header_txt.append('#include "vk_layer_logging.h"')
Mark Lobodzinskifae78852015-06-23 11:35:12 -0600727 header_txt.append('')
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700728# NOTE: The non-autoGenerated code is in the object_tracker.h header file
729 header_txt.append('#include "object_tracker.h"')
Mark Lobodzinskifb5437a2015-05-22 14:15:36 -0500730 header_txt.append('')
Tobin Ehlis12076fc2014-10-22 09:06:33 -0600731 return "\n".join(header_txt)
732
Tony Barboura05dbaa2015-07-09 17:31:46 -0600733 def generate_maps(self):
734 maps_txt = []
Tobin Ehlis86684f92016-01-05 10:33:58 -0700735 for o in vulkan.object_type_list:
Mark Lobodzinskif93272b2016-05-02 12:08:24 -0600736 maps_txt.append('std::unordered_map<uint64_t, OBJTRACK_NODE*> %sMap;' % (o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600737 return "\n".join(maps_txt)
738
Tobin Ehlis86684f92016-01-05 10:33:58 -0700739 def _gather_object_uses(self, obj_list, struct_type, obj_set):
740 # for each member of struct_type
741 # add objs in obj_list to obj_set
742 # call self for structs
Mike Stroyan04be7832016-04-07 12:14:30 -0600743 for m in sorted(vk_helper.struct_dict[struct_type]):
Tobin Ehlis86684f92016-01-05 10:33:58 -0700744 if vk_helper.struct_dict[struct_type][m]['type'] in obj_list:
745 obj_set.add(vk_helper.struct_dict[struct_type][m]['type'])
746 elif vk_helper.is_type(vk_helper.struct_dict[struct_type][m]['type'], 'struct'):
747 obj_set = obj_set.union(self._gather_object_uses(obj_list, vk_helper.struct_dict[struct_type][m]['type'], obj_set))
748 return obj_set
749
Tony Barboura05dbaa2015-07-09 17:31:46 -0600750 def generate_procs(self):
751 procs_txt = []
Tobin Ehlis86684f92016-01-05 10:33:58 -0700752 # First parse through funcs and gather dict of all objects seen by each call
753 obj_use_dict = {}
754 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
755 for proto in proto_list:
756 disp_obj = proto.params[0].ty.strip('*').replace('const ', '')
757 if disp_obj in vulkan.object_dispatch_list:
758 if disp_obj not in obj_use_dict:
759 obj_use_dict[disp_obj] = set()
760 for p in proto.params[1:]:
761 base_type = p.ty.strip('*').replace('const ', '')
762 if base_type in vulkan.object_type_list:
763 obj_use_dict[disp_obj].add(base_type)
764 if vk_helper.is_type(base_type, 'struct'):
765 obj_use_dict[disp_obj] = self._gather_object_uses(vulkan.object_type_list, base_type, obj_use_dict[disp_obj])
766 #for do in obj_use_dict:
767 # print "Disp obj %s has uses for objs: %s" % (do, ', '.join(obj_use_dict[do]))
768
769 for o in vulkan.object_type_list:# vulkan.core.objects:
Tony Barboura05dbaa2015-07-09 17:31:46 -0600770 procs_txt.append('%s' % self.lineinfo.get())
Michael Lentine13803dc2015-11-04 14:35:12 -0800771 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o)
772 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
Tobin Ehlis154e0462015-08-26 11:22:09 -0600773 if o in vulkan.object_dispatch_list:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700774 procs_txt.append('static void create_%s(%s dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o, o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600775 else:
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700776 procs_txt.append('static void create_%s(VkDevice dispatchable_object, %s vkObj, VkDebugReportObjectTypeEXT objType)' % (name, o))
Chia-I Wue2fc5522015-10-26 20:04:44 +0800777 procs_txt.append('{')
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700778 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 -0700779 procs_txt.append(' "OBJ[%llu] : CREATE %s object 0x%" PRIxLEAST64 , object_track_index++, string_VkDebugReportObjectTypeEXT(objType),')
Mark Young93ecb1d2016-01-13 13:47:16 -0700780 procs_txt.append(' (uint64_t)(vkObj));')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600781 procs_txt.append('')
782 procs_txt.append(' OBJTRACK_NODE* pNewObjNode = new OBJTRACK_NODE;')
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700783 procs_txt.append(' pNewObjNode->belongsTo = (uint64_t)dispatchable_object;')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600784 procs_txt.append(' pNewObjNode->objType = objType;')
785 procs_txt.append(' pNewObjNode->status = OBJSTATUS_NONE;')
Mark Young93ecb1d2016-01-13 13:47:16 -0700786 procs_txt.append(' pNewObjNode->vkObj = (uint64_t)(vkObj);')
Michael Lentine13803dc2015-11-04 14:35:12 -0800787 procs_txt.append(' %sMap[(uint64_t)vkObj] = pNewObjNode;' % (o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600788 procs_txt.append(' uint32_t objIndex = objTypeToIndex(objType);')
789 procs_txt.append(' numObjs[objIndex]++;')
790 procs_txt.append(' numTotalObjs++;')
791 procs_txt.append('}')
792 procs_txt.append('')
793 procs_txt.append('%s' % self.lineinfo.get())
Tobin Ehlis154e0462015-08-26 11:22:09 -0600794 if o in vulkan.object_dispatch_list:
Michael Lentine13803dc2015-11-04 14:35:12 -0800795 procs_txt.append('static void destroy_%s(%s dispatchable_object, %s object)' % (name, o, o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600796 else:
Michael Lentine13803dc2015-11-04 14:35:12 -0800797 procs_txt.append('static void destroy_%s(VkDevice dispatchable_object, %s object)' % (name, o))
Tony Barboura05dbaa2015-07-09 17:31:46 -0600798 procs_txt.append('{')
Mark Young93ecb1d2016-01-13 13:47:16 -0700799 procs_txt.append(' uint64_t object_handle = (uint64_t)(object);')
Chris Forbesbdbc1132016-03-09 12:06:45 +1300800 procs_txt.append(' auto it = %sMap.find(object_handle);' % o)
801 procs_txt.append(' if (it != %sMap.end()) {' % o)
802 procs_txt.append(' OBJTRACK_NODE* pNode = it->second;')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600803 procs_txt.append(' uint32_t objIndex = objTypeToIndex(pNode->objType);')
804 procs_txt.append(' assert(numTotalObjs > 0);')
805 procs_txt.append(' numTotalObjs--;')
806 procs_txt.append(' assert(numObjs[objIndex] > 0);')
807 procs_txt.append(' numObjs[objIndex]--;')
Mark Lobodzinski510e20d2016-02-11 09:26:16 -0700808 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 -0800809 procs_txt.append(' "OBJ_STAT Destroy %s obj 0x%" PRIxLEAST64 " (%" PRIu64 " total objs remain & %" PRIu64 " %s objs).",')
Mark Young93ecb1d2016-01-13 13:47:16 -0700810 procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType), (uint64_t)(object), numTotalObjs, numObjs[objIndex],')
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700811 procs_txt.append(' string_VkDebugReportObjectTypeEXT(pNode->objType));')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600812 procs_txt.append(' delete pNode;')
Chris Forbesbdbc1132016-03-09 12:06:45 +1300813 procs_txt.append(' %sMap.erase(it);' % (o))
Chia-I Wue2fc5522015-10-26 20:04:44 +0800814 procs_txt.append(' } else {')
Mark Lobodzinski6085c2b2016-01-04 15:48:11 -0700815 procs_txt.append(' log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT ) 0, object_handle, __LINE__, OBJTRACK_NONE, "OBJTRACK",')
Chia-I Wue2fc5522015-10-26 20:04:44 +0800816 procs_txt.append(' "Unable to remove obj 0x%" PRIxLEAST64 ". Was it created? Has it already been destroyed?",')
Michael Lentine13803dc2015-11-04 14:35:12 -0800817 procs_txt.append(' object_handle);')
Chia-I Wue2fc5522015-10-26 20:04:44 +0800818 procs_txt.append(' }')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600819 procs_txt.append('}')
820 procs_txt.append('')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700821 # Generate the permutations of validate_* functions where for each
822 # dispatchable object type, we have a corresponding validate_* function
823 # for that object and all non-dispatchable objects that are used in API
824 # calls with that dispatchable object.
Mike Stroyan04be7832016-04-07 12:14:30 -0600825 procs_txt.append('//%s' % str(sorted(obj_use_dict)))
826 for do in sorted(obj_use_dict):
Tobin Ehlis86684f92016-01-05 10:33:58 -0700827 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', do)
828 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
829 # First create validate_* func for disp obj
830 procs_txt.append('%s' % self.lineinfo.get())
831 procs_txt.append('static VkBool32 validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, do))
832 procs_txt.append('{')
833 procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))')
834 procs_txt.append(' return VK_FALSE;')
835 procs_txt.append(' if (%sMap.find((uint64_t)object) == %sMap.end()) {' % (do, do))
Mark Young93ecb1d2016-01-13 13:47:16 -0700836 procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",')
837 procs_txt.append(' "Invalid %s Object 0x%%" PRIx64 ,(uint64_t)(object));' % do)
Tobin Ehlis86684f92016-01-05 10:33:58 -0700838 procs_txt.append(' }')
839 procs_txt.append(' return VK_FALSE;')
840 procs_txt.append('}')
841 procs_txt.append('')
Mike Stroyan04be7832016-04-07 12:14:30 -0600842 for o in sorted(obj_use_dict[do]):
Tobin Ehlis86684f92016-01-05 10:33:58 -0700843 if o == do: # We already generated this case above so skip here
844 continue
845 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', o)
846 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
847 procs_txt.append('%s' % self.lineinfo.get())
848 procs_txt.append('static VkBool32 validate_%s(%s dispatchable_object, %s object, VkDebugReportObjectTypeEXT objType, bool null_allowed)' % (name, do, o))
849 procs_txt.append('{')
850 procs_txt.append(' if (null_allowed && (object == VK_NULL_HANDLE))')
851 procs_txt.append(' return VK_FALSE;')
852 if o == "VkImage":
853 procs_txt.append(' // We need to validate normal image objects and those from the swapchain')
854 procs_txt.append(' if ((%sMap.find((uint64_t)object) == %sMap.end()) &&' % (o, o))
855 procs_txt.append(' (swapchainImageMap.find((uint64_t)object) == swapchainImageMap.end())) {')
856 else:
857 procs_txt.append(' if (%sMap.find((uint64_t)object) == %sMap.end()) {' % (o, o))
Mark Young93ecb1d2016-01-13 13:47:16 -0700858 procs_txt.append(' return log_msg(mdd(dispatchable_object), VK_DEBUG_REPORT_ERROR_BIT_EXT, objType, (uint64_t)(object), __LINE__, OBJTRACK_INVALID_OBJECT, "OBJTRACK",')
859 procs_txt.append(' "Invalid %s Object 0x%%" PRIx64, (uint64_t)(object));' % o)
Tobin Ehlis86684f92016-01-05 10:33:58 -0700860 procs_txt.append(' }')
861 procs_txt.append(' return VK_FALSE;')
862 procs_txt.append('}')
863 procs_txt.append('')
864 procs_txt.append('')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600865 return "\n".join(procs_txt)
866
Mark Lobodzinski64d57752015-07-17 11:51:24 -0600867 def generate_destroy_instance(self):
Tony Barboura05dbaa2015-07-09 17:31:46 -0600868 gedi_txt = []
869 gedi_txt.append('%s' % self.lineinfo.get())
Mark Young93ecb1d2016-01-13 13:47:16 -0700870 gedi_txt.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(')
Chia-I Wuf7458c52015-10-26 21:10:41 +0800871 gedi_txt.append('VkInstance instance,')
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800872 gedi_txt.append('const VkAllocationCallbacks* pAllocator)')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600873 gedi_txt.append('{')
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600874 gedi_txt.append(' std::unique_lock<std::mutex> lock(global_lock);')
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600875 gedi_txt.append('')
876 gedi_txt.append(' dispatch_key key = get_dispatch_key(instance);')
877 gedi_txt.append(' layer_data *my_data = get_my_data_ptr(key, layer_data_map);')
878 gedi_txt.append('')
879 gedi_txt.append(' // Enable the temporary callback(s) here to catch cleanup issues:')
880 gedi_txt.append(' bool callback_setup = false;')
881 gedi_txt.append(' if (my_data->num_tmp_callbacks > 0) {')
882 gedi_txt.append(' if (!layer_enable_tmp_callbacks(my_data->report_data,')
883 gedi_txt.append(' my_data->num_tmp_callbacks,')
884 gedi_txt.append(' my_data->tmp_dbg_create_infos,')
885 gedi_txt.append(' my_data->tmp_callbacks)) {')
886 gedi_txt.append(' callback_setup = true;')
887 gedi_txt.append(' }')
888 gedi_txt.append(' }')
889 gedi_txt.append('')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700890 gedi_txt.append(' validate_instance(instance, instance, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, false);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600891 gedi_txt.append('')
Michael Lentine13803dc2015-11-04 14:35:12 -0800892 gedi_txt.append(' destroy_instance(instance, instance);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600893 gedi_txt.append(' // Report any remaining objects in LL')
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700894 gedi_txt.append('')
895 gedi_txt.append(' for (auto iit = VkDeviceMap.begin(); iit != VkDeviceMap.end();) {')
896 gedi_txt.append(' OBJTRACK_NODE* pNode = iit->second;')
897 gedi_txt.append(' if (pNode->belongsTo == (uint64_t)instance) {')
898 gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",')
899 gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),')
900 gedi_txt.append(' pNode->vkObj);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600901 for o in vulkan.core.objects:
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700902 if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue', 'VkDevice']:
Tony Barboura05dbaa2015-07-09 17:31:46 -0600903 continue
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700904 gedi_txt.append(' for (auto idt = %sMap.begin(); idt != %sMap.end();) {' % (o, o))
905 gedi_txt.append(' OBJTRACK_NODE* pNode = idt->second;')
906 gedi_txt.append(' if (pNode->belongsTo == iit->first) {')
907 gedi_txt.append(' log_msg(mid(instance), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",')
908 gedi_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),')
909 gedi_txt.append(' pNode->vkObj);')
910 gedi_txt.append(' %sMap.erase(idt++);' % o )
911 gedi_txt.append(' } else {')
912 gedi_txt.append(' ++idt;')
913 gedi_txt.append(' }')
914 gedi_txt.append(' }')
915 gedi_txt.append(' VkDeviceMap.erase(iit++);')
916 gedi_txt.append(' } else {')
917 gedi_txt.append(' ++iit;')
918 gedi_txt.append(' }')
919 gedi_txt.append(' }')
920 gedi_txt.append('')
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700921 gedi_txt.append(' VkLayerInstanceDispatchTable *pInstanceTable = get_dispatch_table(object_tracker_instance_table_map, instance);')
Chia-I Wuf7458c52015-10-26 21:10:41 +0800922 gedi_txt.append(' pInstanceTable->DestroyInstance(instance, pAllocator);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600923 gedi_txt.append('')
Ian Elliotted6b5ac2016-04-28 09:08:13 -0600924 gedi_txt.append(' // Disable and cleanup the temporary callback(s):')
925 gedi_txt.append(' if (callback_setup) {')
926 gedi_txt.append(' layer_disable_tmp_callbacks(my_data->report_data,')
927 gedi_txt.append(' my_data->num_tmp_callbacks,')
928 gedi_txt.append(' my_data->tmp_callbacks);')
929 gedi_txt.append(' }')
930 gedi_txt.append(' if (my_data->num_tmp_callbacks > 0) {')
931 gedi_txt.append(' layer_free_tmp_callbacks(my_data->tmp_dbg_create_infos,')
932 gedi_txt.append(' my_data->tmp_callbacks);')
933 gedi_txt.append(' my_data->num_tmp_callbacks = 0;')
934 gedi_txt.append(' }')
935 gedi_txt.append('')
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -0600936 gedi_txt.append(' // Clean up logging callback, if any')
937 gedi_txt.append(' while (my_data->logging_callback.size() > 0) {')
938 gedi_txt.append(' VkDebugReportCallbackEXT callback = my_data->logging_callback.back();')
939 gedi_txt.append(' layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);')
940 gedi_txt.append(' my_data->logging_callback.pop_back();')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600941 gedi_txt.append(' }')
942 gedi_txt.append('')
943 gedi_txt.append(' layer_debug_report_destroy_instance(mid(instance));')
Tobin Ehlis4192fdf2016-04-18 15:40:59 -0600944 gedi_txt.append(' layer_data_map.erase(key);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600945 gedi_txt.append('')
Jon Ashburn3dc39382015-09-17 10:00:32 -0600946 gedi_txt.append(' instanceExtMap.erase(pInstanceTable);')
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600947 gedi_txt.append(' lock.unlock();')
Mike Stroyan0699a792015-08-18 14:48:34 -0600948 # The loader holds a mutex that protects this from other threads
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700949 gedi_txt.append(' object_tracker_instance_table_map.erase(key);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600950 gedi_txt.append('}')
951 gedi_txt.append('')
952 return "\n".join(gedi_txt)
953
Mark Lobodzinski64d57752015-07-17 11:51:24 -0600954 def generate_destroy_device(self):
Tony Barboura05dbaa2015-07-09 17:31:46 -0600955 gedd_txt = []
956 gedd_txt.append('%s' % self.lineinfo.get())
Mark Young93ecb1d2016-01-13 13:47:16 -0700957 gedd_txt.append('VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(')
Chia-I Wuf7458c52015-10-26 21:10:41 +0800958 gedd_txt.append('VkDevice device,')
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800959 gedd_txt.append('const VkAllocationCallbacks* pAllocator)')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600960 gedd_txt.append('{')
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600961 gedd_txt.append(' std::unique_lock<std::mutex> lock(global_lock);')
Tobin Ehlis86684f92016-01-05 10:33:58 -0700962 gedd_txt.append(' validate_device(device, device, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, false);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600963 gedd_txt.append('')
Michael Lentine13803dc2015-11-04 14:35:12 -0800964 gedd_txt.append(' destroy_device(device, device);')
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700965 gedd_txt.append(' // Report any remaining objects associated with this VkDevice object in LL')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600966 for o in vulkan.core.objects:
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700967 # DescriptorSets and Command Buffers are destroyed through their pools, not explicitly
968 if o in ['VkInstance', 'VkPhysicalDevice', 'VkQueue', 'VkDevice', 'VkDescriptorSet', 'VkCommandBuffer']:
Tony Barboura05dbaa2015-07-09 17:31:46 -0600969 continue
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700970 gedd_txt.append(' for (auto it = %sMap.begin(); it != %sMap.end();) {' % (o, o))
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700971 gedd_txt.append(' OBJTRACK_NODE* pNode = it->second;')
Mark Lobodzinskic857fb32016-03-08 15:10:00 -0700972 gedd_txt.append(' if (pNode->belongsTo == (uint64_t)device) {')
973 gedd_txt.append(' log_msg(mdd(device), VK_DEBUG_REPORT_ERROR_BIT_EXT, pNode->objType, pNode->vkObj, __LINE__, OBJTRACK_OBJECT_LEAK, "OBJTRACK",')
974 gedd_txt.append(' "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", string_VkDebugReportObjectTypeEXT(pNode->objType),')
975 gedd_txt.append(' pNode->vkObj);')
976 gedd_txt.append(' %sMap.erase(it++);' % o )
977 gedd_txt.append(' } else {')
978 gedd_txt.append(' ++it;')
979 gedd_txt.append(' }')
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -0700980 gedd_txt.append(' }')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600981 gedd_txt.append('')
982 gedd_txt.append(" // Clean up Queue's MemRef Linked Lists")
983 gedd_txt.append(' destroyQueueMemRefLists();')
984 gedd_txt.append('')
Jeremy Hayes2f065b12016-04-13 10:54:17 -0600985 gedd_txt.append(' lock.unlock();')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600986 gedd_txt.append('')
987 gedd_txt.append(' dispatch_key key = get_dispatch_key(device);')
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700988 gedd_txt.append(' VkLayerDispatchTable *pDisp = get_dispatch_table(object_tracker_device_table_map, device);')
Chia-I Wuf7458c52015-10-26 21:10:41 +0800989 gedd_txt.append(' pDisp->DestroyDevice(device, pAllocator);')
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -0700990 gedd_txt.append(' object_tracker_device_table_map.erase(key);')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600991 gedd_txt.append('')
Tony Barboura05dbaa2015-07-09 17:31:46 -0600992 gedd_txt.append('}')
993 gedd_txt.append('')
994 return "\n".join(gedd_txt)
995
Mark Lobodzinski2fba0322016-01-23 18:31:23 -0700996 # Special-case validating some objects -- they may be non-NULL but should
997 # only be validated upon meeting some condition specified below.
998 def _dereference_conditionally(self, indent, prefix, type_name, name):
Mark Lobodzinski9fde6392016-01-19 09:57:24 -0700999 s_code = ''
1000 if type_name == 'pBufferInfo':
1001 s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||\n' % (indent, prefix)
1002 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||\n' % (indent, prefix)
1003 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||\n' % (indent, prefix)
1004 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) ) {\n' % (indent, prefix)
1005 elif type_name == 'pImageInfo':
1006 s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||\n' % (indent, prefix)
1007 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||\n' % (indent, prefix)
1008 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) ||\n' % (indent, prefix)
1009 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||\n' % (indent, prefix)
1010 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ) {\n' % (indent, prefix)
1011 elif type_name == 'pTexelBufferView':
Mark Lobodzinski2fba0322016-01-23 18:31:23 -07001012 s_code += '%sif ((%sdescriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||\n' % (indent, prefix)
1013 s_code += '%s (%sdescriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) ) {\n' % (indent, prefix)
1014 elif name == 'pBeginInfo->pInheritanceInfo':
1015 s_code += '%sOBJTRACK_NODE* pNode = VkCommandBufferMap[(uint64_t)commandBuffer];\n' % (indent)
1016 s_code += '%sif ((%s) && (pNode->status & OBJSTATUS_COMMAND_BUFFER_SECONDARY)) {\n' % (indent, name)
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001017 else:
1018 s_code += '%sif (%s) {\n' % (indent, name)
1019 return s_code
1020
Tobin Ehlis86684f92016-01-05 10:33:58 -07001021 def _gen_obj_validate_code(self, struct_uses, obj_type_mapping, func_name, valid_null_dict, param0_name, indent, prefix, array_index):
1022 pre_code = ''
1023 for obj in sorted(struct_uses):
1024 name = obj
1025 array = ''
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001026 type_name = ''
Tobin Ehlis86684f92016-01-05 10:33:58 -07001027 if '[' in obj:
1028 (name, array) = obj.split('[')
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001029 type_name = name
Tobin Ehlis86684f92016-01-05 10:33:58 -07001030 array = array.strip(']')
1031 if isinstance(struct_uses[obj], dict):
1032 local_prefix = ''
1033 name = '%s%s' % (prefix, name)
1034 ptr_type = False
1035 if 'p' == obj[0]:
1036 ptr_type = True
Mark Lobodzinski2fba0322016-01-23 18:31:23 -07001037 tmp_pre = self._dereference_conditionally(indent, prefix, type_name, name)
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001038 pre_code += tmp_pre
Tobin Ehlis86684f92016-01-05 10:33:58 -07001039 indent += ' '
1040 if array != '':
1041 idx = 'idx%s' % str(array_index)
1042 array_index += 1
1043 pre_code += '%s\n' % self.lineinfo.get()
1044 pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx)
1045 indent += ' '
1046 local_prefix = '%s[%s].' % (name, idx)
1047 elif ptr_type:
1048 local_prefix = '%s->' % (name)
1049 else:
1050 local_prefix = '%s.' % (name)
1051 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)
1052 pre_code += tmp_pre
1053 if array != '':
1054 indent = indent[4:]
1055 pre_code += '%s}\n' % (indent)
1056 if ptr_type:
1057 indent = indent[4:]
1058 pre_code += '%s}\n' % (indent)
1059 else:
1060 ptype = struct_uses[obj]
1061 dbg_obj_type = obj_type_mapping[ptype]
1062 fname = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', ptype)
1063 fname = re.sub('([a-z0-9])([A-Z])', r'\1_\2', fname).lower()[3:]
1064 full_name = '%s%s' % (prefix, name)
1065 null_obj_ok = 'false'
1066 # If a valid null param is defined for this func and we have a match, allow NULL
Mike Stroyan04be7832016-04-07 12:14:30 -06001067 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 -07001068 null_obj_ok = 'true'
1069 if (array_index > 0) or '' != array:
Mark Lobodzinski2fba0322016-01-23 18:31:23 -07001070 tmp_pre = self._dereference_conditionally(indent, prefix, type_name, full_name)
Mark Lobodzinski9fde6392016-01-19 09:57:24 -07001071 pre_code += tmp_pre
Tobin Ehlis86684f92016-01-05 10:33:58 -07001072 indent += ' '
1073 if array != '':
1074 idx = 'idx%s' % str(array_index)
1075 array_index += 1
1076 pre_code += '%sfor (uint32_t %s=0; %s<%s%s; ++%s) {\n' % (indent, idx, idx, prefix, array, idx)
1077 indent += ' '
1078 full_name = '%s[%s]' % (full_name, idx)
1079 pre_code += '%s\n' % self.lineinfo.get()
1080 pre_code += '%sskipCall |= validate_%s(%s, %s, %s, %s);\n' %(indent, fname, param0_name, full_name, dbg_obj_type, null_obj_ok)
1081 if array != '':
1082 indent = indent[4:]
1083 pre_code += '%s}\n' % (indent)
1084 indent = indent[4:]
1085 pre_code += '%s}\n' % (indent)
1086 else:
1087 pre_code += '%s\n' % self.lineinfo.get()
1088 pre_code += '%sskipCall |= validate_%s(%s, %s, %s, %s);\n' %(indent, fname, param0_name, full_name, dbg_obj_type, null_obj_ok)
1089 return pre_code
Tony Barboura05dbaa2015-07-09 17:31:46 -06001090
Mike Stroyan3e3a1eb2015-04-03 17:13:23 -06001091 def generate_intercept(self, proto, qual):
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001092 if proto.name in [ 'CreateDebugReportCallbackEXT', 'EnumerateInstanceLayerProperties', 'EnumerateInstanceExtensionProperties','EnumerateDeviceLayerProperties', 'EnumerateDeviceExtensionProperties' ]:
Mike Stroyan00087e62015-04-03 14:39:16 -06001093 # use default version
1094 return None
Mark Lobodzinski7c75b852015-05-05 15:01:37 -05001095
Tony Barboura05dbaa2015-07-09 17:31:46 -06001096 # Create map of object names to object type enums of the form VkName : VkObjectTypeName
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001097 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 -05001098 # Convert object type enum names from UpperCamelCase to UPPER_CASE_WITH_UNDERSCORES
1099 for objectName, objectTypeEnum in obj_type_mapping.items():
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001100 obj_type_mapping[objectName] = ucc_to_U_C_C(objectTypeEnum) + '_EXT';
Mark Lobodzinski7c75b852015-05-05 15:01:37 -05001101 # Command Buffer Object doesn't follow the rule.
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07001102 obj_type_mapping['VkCommandBuffer'] = "VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT"
1103 obj_type_mapping['VkShaderModule'] = "VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT"
Mike Stroyan00087e62015-04-03 14:39:16 -06001104
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001105 explicit_object_tracker_functions = [
1106 "CreateInstance",
Tobin Ehlisec598302015-09-15 15:02:17 -06001107 "EnumeratePhysicalDevices",
Cody Northropd0802882015-08-03 17:04:53 -06001108 "GetPhysicalDeviceQueueFamilyProperties",
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001109 "CreateDevice",
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001110 "GetDeviceQueue",
Chia-I Wu1ff4c3d2015-10-26 16:55:27 +08001111 "QueueBindSparse",
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001112 "AllocateDescriptorSets",
Tony Barbour770f80d2015-07-20 10:52:13 -06001113 "FreeDescriptorSets",
Mark Lobodzinski154329b2016-01-26 09:55:28 -07001114 "CreateGraphicsPipelines",
1115 "CreateComputePipelines",
Mark Lobodzinski5f5c0e12015-11-12 16:02:35 -07001116 "AllocateCommandBuffers",
1117 "FreeCommandBuffers",
1118 "DestroyDescriptorPool",
1119 "DestroyCommandPool",
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001120 "MapMemory",
1121 "UnmapMemory",
1122 "FreeMemory",
Mark Lobodzinskie6d3f2c2015-10-14 13:16:33 -06001123 "DestroySwapchainKHR",
1124 "GetSwapchainImagesKHR"
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001125 ]
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001126 decl = proto.c_func(prefix="vk", attr="VKAPI")
Mike Stroyan00087e62015-04-03 14:39:16 -06001127 param0_name = proto.params[0].name
Mark Lobodzinski48bd16d2015-05-08 09:12:28 -05001128 using_line = ''
Mike Stroyan00087e62015-04-03 14:39:16 -06001129 create_line = ''
Mark Lobodzinski64d57752015-07-17 11:51:24 -06001130 destroy_line = ''
Tobin Ehlis154e0462015-08-26 11:22:09 -06001131 # 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 -07001132 # TODO : Should integrate slightly better code for this purpose from unique_objects layer
Tobin Ehlis154e0462015-08-26 11:22:09 -06001133 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 -08001134 loop_types = defaultdict(list)
Tobin Ehlis2717d132015-07-10 18:25:07 -06001135 # 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 -06001136 # or better yet, these should be encoded into an API json definition and we generate checks from there
1137 # 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)
1138 # param names may be directly passed to the function, or may be a field in a struct param
1139 valid_null_object_names = {'CreateGraphicsPipelines' : ['basePipelineHandle'],
1140 'CreateComputePipelines' : ['basePipelineHandle'],
1141 'BeginCommandBuffer' : ['renderPass', 'framebuffer'],
Tobin Ehlisec598302015-09-15 15:02:17 -06001142 'QueueSubmit' : ['fence'],
Jon Ashburn9216ae42016-01-14 15:11:55 -07001143 'AcquireNextImageKHR' : ['fence', 'semaphore' ],
Tobin Ehlisba31cab2015-11-02 15:24:32 -07001144 'UpdateDescriptorSets' : ['pTexelBufferView'],
Tobin Ehlis86684f92016-01-05 10:33:58 -07001145 'CreateSwapchainKHR' : ['oldSwapchain'],
Tobin Ehlis154e0462015-08-26 11:22:09 -06001146 }
Tobin Ehlis154e0462015-08-26 11:22:09 -06001147 param_count = 'NONE' # keep track of arrays passed directly into API functions
Tobin Ehlis803cc492015-06-08 17:36:28 -06001148 for p in proto.params:
Tobin Ehlisec598302015-09-15 15:02:17 -06001149 base_type = p.ty.replace('const ', '').strip('*')
Tobin Ehlis154e0462015-08-26 11:22:09 -06001150 if 'count' in p.name.lower():
1151 param_count = p.name
Tobin Ehlisec598302015-09-15 15:02:17 -06001152 if base_type in vulkan.core.objects:
1153 # This is an object to potentially check for validity. First see if it's an array
1154 if '*' in p.ty and 'const' in p.ty and param_count != 'NONE':
1155 loop_params[param_count].append(p.name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001156 loop_types[param_count].append(str(p.ty[6:-1]))
Tobin Ehlisec598302015-09-15 15:02:17 -06001157 # Not an array, check for just a base Object that's not in exceptions
1158 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 -06001159 loop_params[0].append(p.name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001160 loop_types[0].append(str(p.ty))
Tobin Ehlisec598302015-09-15 15:02:17 -06001161 elif vk_helper.is_type(base_type, 'struct'):
1162 struct_type = base_type
Tobin Ehlis9d675942015-06-30 14:32:16 -06001163 if vk_helper.typedef_rev_dict[struct_type] in vk_helper.struct_dict:
1164 struct_type = vk_helper.typedef_rev_dict[struct_type]
Tobin Ehlis82b3db52015-10-23 17:52:53 -06001165 # Parse elements of this struct param to identify objects and/or arrays of objects
Tobin Ehlis9d675942015-06-30 14:32:16 -06001166 for m in sorted(vk_helper.struct_dict[struct_type]):
1167 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 -06001168 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 -06001169 # This is not great, but gets the job done for now, but If we have a count and this param is a ptr w/
1170 # last letter 's' OR non-'count' string of count is in the param name, then this is a dynamically sized array param
1171 param_array = False
1172 if param_count != 'NONE':
1173 if '*' in p.ty:
1174 if 's' == p.name[-1] or param_count.lower().replace('count', '') in p.name.lower():
1175 param_array = True
1176 if param_array:
Tobin Ehlis154e0462015-08-26 11:22:09 -06001177 param_name = '%s[i].%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name'])
Tobin Ehlis46d53622015-07-10 11:10:21 -06001178 else:
Tobin Ehlis154e0462015-08-26 11:22:09 -06001179 param_name = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['name'])
1180 if vk_helper.struct_dict[struct_type][m]['dyn_array']:
Tobin Ehlis82b3db52015-10-23 17:52:53 -06001181 if param_count != 'NONE': # this will be a double-embedded loop, use comma delineated 'count,name' for param_name
1182 loop_count = '%s[i].%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size'])
1183 loop_params[param_count].append('%s,%s' % (loop_count, param_name))
Michael Lentine13803dc2015-11-04 14:35:12 -08001184 loop_types[param_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type']))
Tobin Ehlis82b3db52015-10-23 17:52:53 -06001185 else:
1186 loop_count = '%s->%s' % (p.name, vk_helper.struct_dict[struct_type][m]['array_size'])
1187 loop_params[loop_count].append(param_name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001188 loop_types[loop_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type']))
Tobin Ehlis154e0462015-08-26 11:22:09 -06001189 else:
1190 if '[' in param_name: # dynamic array param, set size
1191 loop_params[param_count].append(param_name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001192 loop_types[param_count].append('%s' % (vk_helper.struct_dict[struct_type][m]['type']))
Tobin Ehlis154e0462015-08-26 11:22:09 -06001193 else:
1194 loop_params[0].append(param_name)
Michael Lentine13803dc2015-11-04 14:35:12 -08001195 loop_types[0].append('%s' % (vk_helper.struct_dict[struct_type][m]['type']))
Tobin Ehlis86684f92016-01-05 10:33:58 -07001196 last_param_index = None
1197 create_func = False
1198 if True in [create_txt in proto.name for create_txt in ['Create', 'Allocate']]:
1199 create_func = True
1200 last_param_index = -1 # For create funcs don't validate last object
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001201 (struct_uses, local_decls) = get_object_uses(vulkan.object_type_list, proto.params[:last_param_index])
Mike Stroyan00087e62015-04-03 14:39:16 -06001202 funcs = []
Tobin Ehlis803cc492015-06-08 17:36:28 -06001203 mutex_unlock = False
Tobin Ehlis154e0462015-08-26 11:22:09 -06001204 funcs.append('%s\n' % self.lineinfo.get())
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001205 if proto.name in explicit_object_tracker_functions:
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001206 funcs.append('%s%s\n'
1207 '{\n'
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001208 ' return explicit_%s;\n'
1209 '}' % (qual, decl, proto.c_call()))
1210 return "".join(funcs)
Mark Lobodzinski308d7792015-11-24 10:28:31 -07001211 # Temporarily prevent DestroySurface call from being generated until WSI layer support is fleshed out
Mark Lobodzinski882655d2016-01-05 11:32:53 -07001212 elif 'DestroyInstance' in proto.name or 'DestroyDevice' in proto.name:
Mark Lobodzinski64d57752015-07-17 11:51:24 -06001213 return ""
Jon Ashburn4d9f4652015-04-08 21:33:34 -06001214 else:
Tobin Ehlis86684f92016-01-05 10:33:58 -07001215 if create_func:
Michael Lentine13803dc2015-11-04 14:35:12 -08001216 typ = proto.params[-1].ty.strip('*').replace('const ', '');
1217 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ)
1218 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001219 create_line = ' {\n'
1220 create_line += ' std::lock_guard<std::mutex> lock(global_lock);\n'
1221 create_line += ' if (result == VK_SUCCESS) {\n'
1222 create_line += ' create_%s(%s, *%s, %s);\n' % (name, param0_name, proto.params[-1].name, obj_type_mapping[typ])
1223 create_line += ' }\n'
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001224 create_line += ' }\n'
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001225 if 'FreeCommandBuffers' in proto.name:
Michael Lentine13803dc2015-11-04 14:35:12 -08001226 typ = proto.params[-1].ty.strip('*').replace('const ', '');
1227 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ)
1228 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001229 funcs.append('%s\n' % self.lineinfo.get())
1230 destroy_line = ' loader_platform_thread_lock_mutex(&objLock);\n'
Chia-I Wud50a7d72015-10-26 20:48:51 +08001231 destroy_line += ' for (uint32_t i = 0; i < commandBufferCount; i++) {\n'
Michael Lentine13803dc2015-11-04 14:35:12 -08001232 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 -06001233 destroy_line += ' }\n'
1234 destroy_line += ' loader_platform_thread_unlock_mutex(&objLock);\n'
Mark Lobodzinski64d57752015-07-17 11:51:24 -06001235 if 'Destroy' in proto.name:
Michael Lentine13803dc2015-11-04 14:35:12 -08001236 typ = proto.params[-2].ty.strip('*').replace('const ', '');
1237 name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', typ)
1238 name = re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()[3:]
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06001239 funcs.append('%s\n' % self.lineinfo.get())
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001240 destroy_line = ' {\n'
1241 destroy_line += ' std::lock_guard<std::mutex> lock(global_lock);\n'
1242 destroy_line += ' destroy_%s(%s, %s);\n' % (name, param0_name, proto.params[-2].name)
1243 destroy_line += ' }\n'
Tobin Ehlis86684f92016-01-05 10:33:58 -07001244 indent = ' '
1245 if len(struct_uses) > 0:
1246 using_line += '%sVkBool32 skipCall = VK_FALSE;\n' % (indent)
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001247 if not mutex_unlock:
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001248 using_line += '%s{\n' % (indent)
1249 indent += ' '
1250 using_line += '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % (indent)
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001251 mutex_unlock = True
Mike Stroyan04be7832016-04-07 12:14:30 -06001252 using_line += '// objects to validate: %s\n' % str(sorted(struct_uses))
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001253 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 -06001254 if mutex_unlock:
Jeremy Hayes2f065b12016-04-13 10:54:17 -06001255 indent = indent[4:]
1256 using_line += '%s}\n' % (indent)
Tobin Ehlis86684f92016-01-05 10:33:58 -07001257 if len(struct_uses) > 0:
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001258 using_line += ' if (skipCall)\n'
Jamie Madill2bf385b2016-04-04 12:15:39 -04001259 if proto.ret == "VkBool32":
1260 using_line += ' return VK_FALSE;\n'
1261 elif proto.ret != "void":
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -07001262 using_line += ' return VK_ERROR_VALIDATION_FAILED_EXT;\n'
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06001263 else:
1264 using_line += ' return;\n'
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001265 ret_val = ''
1266 stmt = ''
Mark Lobodzinskifae78852015-06-23 11:35:12 -06001267 if proto.ret != "void":
1268 ret_val = "%s result = " % proto.ret
1269 stmt = " return result;\n"
1270
1271 dispatch_param = proto.params[0].name
1272 if 'CreateInstance' in proto.name:
1273 dispatch_param = '*' + proto.params[1].name
1274
Mark Lobodzinskifb5437a2015-05-22 14:15:36 -05001275 # Must use 'instance' table for these APIs, 'device' table otherwise
1276 table_type = ""
1277 if proto_is_global(proto):
1278 table_type = "instance"
1279 else:
1280 table_type = "device"
Mark Lobodzinskia8a5f852015-12-10 16:25:21 -07001281 if wsi_name(proto.name):
1282 funcs.append('%s' % wsi_ifdef(proto.name))
Mike Stroyan00087e62015-04-03 14:39:16 -06001283 funcs.append('%s%s\n'
1284 '{\n'
1285 '%s'
Mike Stroyan00087e62015-04-03 14:39:16 -06001286 '%s'
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07001287 ' %sget_dispatch_table(object_tracker_%s_table_map, %s)->%s;\n'
Mike Stroyan38820b32015-09-28 13:47:29 -06001288 '%s'
1289 '%s'
1290 '}' % (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 -07001291 if wsi_name(proto.name):
1292 funcs.append('%s' % wsi_endif(proto.name))
Mike Stroyan00087e62015-04-03 14:39:16 -06001293 return "\n\n".join(funcs)
1294
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001295 def generate_body(self):
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07001296 self.layer_name = "object_tracker"
Ian Elliott1064fe32015-07-06 14:31:32 -06001297 extensions=[('wsi_enabled',
Ian Elliott05846062015-11-20 14:13:17 -07001298 ['vkCreateSwapchainKHR',
Jon Ashburn8acd2332015-09-16 18:08:32 -06001299 'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR',
1300 'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])]
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001301 if self.wsi == 'Win32':
Michael Lentine64e2ebd2015-12-03 14:33:09 -08001302 instance_extensions=[('msg_callback_get_proc_addr', []),
1303 ('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001304 ['vkDestroySurfaceKHR',
1305 'vkGetPhysicalDeviceSurfaceSupportKHR',
Michael Lentine64e2ebd2015-12-03 14:33:09 -08001306 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1307 'vkGetPhysicalDeviceSurfaceFormatsKHR',
1308 'vkGetPhysicalDeviceSurfacePresentModesKHR',
1309 'vkCreateWin32SurfaceKHR',
1310 'vkGetPhysicalDeviceWin32PresentationSupportKHR'])]
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001311 elif self.wsi == 'Android':
1312 instance_extensions=[('msg_callback_get_proc_addr', []),
1313 ('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001314 ['vkDestroySurfaceKHR',
1315 'vkGetPhysicalDeviceSurfaceSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001316 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1317 'vkGetPhysicalDeviceSurfaceFormatsKHR',
Michael Lentine56512bb2016-03-02 17:28:55 -06001318 'vkGetPhysicalDeviceSurfacePresentModesKHR',
1319 'vkCreateAndroidSurfaceKHR'])]
Karl Schultz9daf7a32016-03-08 15:14:11 -07001320 elif self.wsi == 'Xcb' or self.wsi == 'Xlib' or self.wsi == 'Wayland' or self.wsi == 'Mir':
Michael Lentine64e2ebd2015-12-03 14:33:09 -08001321 instance_extensions=[('msg_callback_get_proc_addr', []),
1322 ('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001323 ['vkDestroySurfaceKHR',
1324 'vkGetPhysicalDeviceSurfaceSupportKHR',
Michael Lentine64e2ebd2015-12-03 14:33:09 -08001325 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1326 'vkGetPhysicalDeviceSurfaceFormatsKHR',
1327 'vkGetPhysicalDeviceSurfacePresentModesKHR',
1328 'vkCreateXcbSurfaceKHR',
Karl Schultz9daf7a32016-03-08 15:14:11 -07001329 'vkGetPhysicalDeviceXcbPresentationSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001330 'vkCreateXlibSurfaceKHR',
Karl Schultz9daf7a32016-03-08 15:14:11 -07001331 'vkGetPhysicalDeviceXlibPresentationSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001332 'vkCreateWaylandSurfaceKHR',
Karl Schultz9daf7a32016-03-08 15:14:11 -07001333 'vkGetPhysicalDeviceWaylandPresentationSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001334 'vkCreateMirSurfaceKHR',
1335 'vkGetPhysicalDeviceMirPresentationSupportKHR'])]
Mark Lobodzinskid53098f2016-02-25 18:14:56 -07001336 else:
1337 print('Error: Undefined DisplayServer')
1338 instance_extensions=[]
1339
Tony Barboura05dbaa2015-07-09 17:31:46 -06001340 body = [self.generate_maps(),
1341 self.generate_procs(),
Mark Lobodzinski64d57752015-07-17 11:51:24 -06001342 self.generate_destroy_instance(),
1343 self.generate_destroy_device(),
Tony Barboura05dbaa2015-07-09 17:31:46 -06001344 self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
Tobin Ehlisca915872014-11-18 11:28:33 -07001345 self._generate_extensions(),
Jon Ashburn747f2b62015-06-18 15:02:58 -06001346 self._generate_layer_gpa_function(extensions,
Jon Ashburn3dc39382015-09-17 10:00:32 -06001347 instance_extensions)]
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001348 return "\n\n".join(body)
Courtney Goeltzenleuchterb412d212014-11-18 10:40:29 -07001349
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001350class UniqueObjectsSubcommand(Subcommand):
1351 def generate_header(self):
1352 header_txt = []
1353 header_txt.append('%s' % self.lineinfo.get())
1354 header_txt.append('#include "unique_objects.h"')
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001355 return "\n".join(header_txt)
1356
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001357 # Generate UniqueObjects code for given struct_uses dict of objects that need to be unwrapped
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001358 # vector_name_set is used to make sure we don't replicate vector names
1359 # 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 -07001360 # TODO : Comment this code
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001361 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 -07001362 decls = ''
1363 pre_code = ''
1364 post_code = ''
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001365 for obj in sorted(struct_uses):
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001366 name = obj
1367 array = ''
1368 if '[' in obj:
1369 (name, array) = obj.split('[')
1370 array = array.strip(']')
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001371 ptr_type = False
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001372 if 'p' == obj[0] and obj[1] != obj[1].lower(): # TODO : Not ideal way to determine ptr
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001373 ptr_type = True
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001374 if isinstance(struct_uses[obj], dict):
1375 local_prefix = ''
1376 name = '%s%s' % (prefix, name)
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001377 if ptr_type:
Tobin Ehlis6dd0fc32016-02-12 14:37:09 -07001378 if first_level_param and name in param_type:
1379 pre_code += '%sif (%s) {\n' % (indent, name)
1380 else: # shadow ptr will have been initialized at this point so check it vs. source ptr
1381 pre_code += '%sif (local_%s) {\n' % (indent, name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001382 indent += ' '
1383 if array != '':
1384 idx = 'idx%s' % str(array_index)
1385 array_index += 1
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001386 if first_level_param and name in param_type:
1387 pre_code += '%slocal_%s = new safe_%s[%s];\n' % (indent, name, param_type[name].strip('*'), array)
1388 post_code += ' if (local_%s)\n' % (name)
1389 post_code += ' delete[] local_%s;\n' % (name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001390 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 -07001391 indent += ' '
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001392 if first_level_param:
1393 pre_code += '%slocal_%s[%s].initialize(&%s[%s]);\n' % (indent, name, idx, name, idx)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001394 local_prefix = '%s[%s].' % (name, idx)
1395 elif ptr_type:
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001396 if first_level_param and name in param_type:
1397 pre_code += '%slocal_%s = new safe_%s(%s);\n' % (indent, name, param_type[name].strip('*'), name)
1398 post_code += ' if (local_%s)\n' % (name)
1399 post_code += ' delete local_%s;\n' % (name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001400 local_prefix = '%s->' % (name)
1401 else:
1402 local_prefix = '%s.' % (name)
1403 assert isinstance(decls, object)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001404 (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 -07001405 decls += tmp_decl
1406 pre_code += tmp_pre
1407 post_code += tmp_post
1408 if array != '':
1409 indent = indent[4:]
1410 pre_code += '%s}\n' % (indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001411 if ptr_type:
1412 indent = indent[4:]
1413 pre_code += '%s}\n' % (indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001414 else:
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001415 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 -07001416 if first_level_param:
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001417 decls += '%s%s* local_%s = NULL;\n' % (indent, struct_uses[obj], name)
Tobin Ehlis6dd0fc32016-02-12 14:37:09 -07001418 if array != '' and not first_level_param: # ptrs under structs will have been initialized so use local_*
1419 pre_code += '%sif (local_%s%s) {\n' %(indent, prefix, name)
1420 else:
1421 pre_code += '%sif (%s%s) {\n' %(indent, prefix, name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001422 indent += ' '
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001423 if array != '':
1424 idx = 'idx%s' % str(array_index)
1425 array_index += 1
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001426 if first_level_param:
1427 pre_code += '%slocal_%s = new %s[%s];\n' % (indent, name, struct_uses[obj], array)
1428 post_code += ' if (local_%s)\n' % (name)
1429 post_code += ' delete[] local_%s;\n' % (name)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001430 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 -07001431 indent += ' '
1432 name = '%s[%s]' % (name, idx)
1433 pName = 'p%s' % (struct_uses[obj][2:])
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001434 if name not in vector_name_set:
1435 vector_name_set.add(name)
Dustin Gravesa7622d82016-04-14 17:29:20 -06001436 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 -07001437 if array != '':
1438 indent = indent[4:]
1439 pre_code += '%s}\n' % (indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001440 indent = indent[4:]
1441 pre_code += '%s}\n' % (indent)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001442 else:
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001443 pre_code += '%s\n' % (self.lineinfo.get())
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001444 deref_txt = '&'
1445 if ptr_type:
1446 deref_txt = ''
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001447 if '->' in prefix: # need to update local struct
Dustin Gravesa7622d82016-04-14 17:29:20 -06001448 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 -07001449 else:
Dustin Gravesa7622d82016-04-14 17:29:20 -06001450 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 -07001451 return decls, pre_code, post_code
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001452
1453 def generate_intercept(self, proto, qual):
1454 create_func = False
1455 destroy_func = False
1456 last_param_index = None #typcially we look at all params for ndos
1457 pre_call_txt = '' # code prior to calling down chain such as unwrap uses of ndos
1458 post_call_txt = '' # code following call down chain such to wrap newly created ndos, or destroy local wrap struct
1459 funcs = []
1460 indent = ' ' # indent level for generated code
1461 decl = proto.c_func(prefix="vk", attr="VKAPI")
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001462 # A few API cases that are manual code
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001463 # TODO : Special case Create*Pipelines funcs to handle creating multiple unique objects
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001464 explicit_object_tracker_functions = ['GetSwapchainImagesKHR',
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001465 'CreateSwapchainKHR',
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001466 'CreateInstance',
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001467 'DestroyInstance',
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001468 'CreateDevice',
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001469 'DestroyDevice',
Tobin Ehlisa39c26a2016-01-05 16:34:59 -07001470 'CreateComputePipelines',
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001471 'CreateGraphicsPipelines'
1472 ]
Tobin Ehlis453e91f2016-01-29 14:24:42 -07001473 # TODO : This is hacky, need to make this a more general-purpose solution for all layers
Cody Northrop0a179fe2016-02-24 12:28:41 -07001474 ifdef_dict = {'CreateXcbSurfaceKHR': 'VK_USE_PLATFORM_XCB_KHR',
1475 'CreateAndroidSurfaceKHR': 'VK_USE_PLATFORM_ANDROID_KHR',
Tony Barboure66d4e42016-04-12 13:35:51 -06001476 'CreateWin32SurfaceKHR': 'VK_USE_PLATFORM_WIN32_KHR',
1477 'CreateXlibSurfaceKHR': 'VK_USE_PLATFORM_XLIB_KHR',
1478 'CreateWaylandSurfaceKHR': 'VK_USE_PLATFORM_WAYLAND_KHR',
1479 'CreateMirSurfaceKHR': 'VK_USE_PLATFORM_MIR_KHR'}
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001480 # Give special treatment to create functions that return multiple new objects
1481 # This dict stores array name and size of array
Jon Ashburnf19916e2016-01-11 13:12:43 -07001482 custom_create_dict = {'pDescriptorSets' : 'pAllocateInfo->descriptorSetCount'}
Courtney Goeltzenleuchter5a0f2832016-02-11 11:44:04 -07001483 pre_call_txt += '%s\n' % (self.lineinfo.get())
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001484 if proto.name in explicit_object_tracker_functions:
1485 funcs.append('%s%s\n'
1486 '{\n'
1487 ' return explicit_%s;\n'
1488 '}' % (qual, decl, proto.c_call()))
1489 return "".join(funcs)
1490 if True in [create_txt in proto.name for create_txt in ['Create', 'Allocate']]:
1491 create_func = True
1492 last_param_index = -1 # For create funcs don't care if last param is ndo
1493 if True in [destroy_txt in proto.name for destroy_txt in ['Destroy', 'Free']]:
1494 destroy_obj_type = proto.params[-2].ty
1495 if destroy_obj_type in vulkan.object_non_dispatch_list:
1496 destroy_func = True
1497
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001498 # First thing we need to do is gather uses of non-dispatchable-objects (ndos)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001499 (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 -07001500
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001501 dispatch_param = proto.params[0].name
1502 if 'CreateInstance' in proto.name:
1503 dispatch_param = '*' + proto.params[1].name
1504 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 -07001505 if len(struct_uses) > 0:
Mike Stroyan04be7832016-04-07 12:14:30 -06001506 pre_call_txt += '// STRUCT USES:%s\n' % sorted(struct_uses)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001507 if len(local_decls) > 0:
Mike Stroyan04be7832016-04-07 12:14:30 -06001508 pre_call_txt += '//LOCAL DECLS:%s\n' % sorted(local_decls)
Tobin Ehlis65f44e42016-01-05 09:46:03 -07001509 if destroy_func: # only one object
Karl Schultz2d6c90e2016-04-29 17:22:50 -06001510 pre_call_txt += '%sstd::unique_lock<std::mutex> lock(global_lock);\n' % (indent)
Mike Stroyan04be7832016-04-07 12:14:30 -06001511 for del_obj in sorted(struct_uses):
Dustin Gravesa7622d82016-04-14 17:29:20 -06001512 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 -06001513 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 -06001514 pre_call_txt += '%slock.unlock();\n' % (indent)
1515 (pre_decl, pre_code, post_code) = ('', '', '')
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001516 else:
1517 (pre_decl, pre_code, post_code) = self._gen_obj_code(struct_uses, local_decls, ' ', '', 0, set(), True)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001518 # 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 -06001519 for ld in sorted(local_decls):
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001520 init_null_txt = 'NULL';
1521 if '*' not in local_decls[ld]:
1522 init_null_txt = '{}';
1523 if local_decls[ld].strip('*') not in vulkan.object_non_dispatch_list:
1524 pre_decl += ' safe_%s local_%s = %s;\n' % (local_decls[ld], ld, init_null_txt)
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001525 if pre_code != '': # lock around map uses
1526 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 -07001527 pre_call_txt += '%s%s' % (pre_decl, pre_code)
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001528 post_call_txt += '%s' % (post_code)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001529 elif create_func:
1530 base_type = proto.params[-1].ty.replace('const ', '').strip('*')
1531 if base_type not in vulkan.object_non_dispatch_list:
1532 return None
1533 else:
1534 return None
1535
1536 ret_val = ''
1537 ret_stmt = ''
1538 if proto.ret != "void":
1539 ret_val = "%s result = " % proto.ret
1540 ret_stmt = " return result;\n"
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001541 if create_func:
1542 obj_type = proto.params[-1].ty.strip('*')
1543 obj_name = proto.params[-1].name
1544 if obj_type in vulkan.object_non_dispatch_list:
1545 local_name = "unique%s" % obj_type[2:]
1546 post_call_txt += '%sif (VK_SUCCESS == result) {\n' % (indent)
1547 indent += ' '
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001548 post_call_txt += '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % (indent)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001549 if obj_name in custom_create_dict:
1550 post_call_txt += '%s\n' % (self.lineinfo.get())
1551 local_name = '%ss' % (local_name) # add 's' to end for vector of many
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001552 post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, custom_create_dict[obj_name])
1553 indent += ' '
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -06001554 post_call_txt += '%suint64_t unique_id = global_unique_id++;\n' % (indent)
Dustin Gravesa7622d82016-04-14 17:29:20 -06001555 post_call_txt += '%smy_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(%s[i]);\n' % (indent, obj_name)
1556 post_call_txt += '%s%s[i] = reinterpret_cast<%s&>(unique_id);\n' % (indent, obj_name, obj_type)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001557 indent = indent[4:]
1558 post_call_txt += '%s}\n' % (indent)
1559 else:
1560 post_call_txt += '%s\n' % (self.lineinfo.get())
Mark Lobodzinskifdf8f472016-04-28 16:36:58 -06001561 post_call_txt += '%suint64_t unique_id = global_unique_id++;\n' % (indent)
Dustin Gravesa7622d82016-04-14 17:29:20 -06001562 post_call_txt += '%smy_map_data->unique_id_mapping[unique_id] = reinterpret_cast<uint64_t &>(*%s);\n' % (indent, obj_name)
1563 post_call_txt += '%s*%s = reinterpret_cast<%s&>(unique_id);\n' % (indent, obj_name, obj_type)
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001564 indent = indent[4:]
1565 post_call_txt += '%s}\n' % (indent)
1566 elif destroy_func:
1567 del_obj = proto.params[-2].name
1568 if 'count' in del_obj.lower():
1569 post_call_txt += '%s\n' % (self.lineinfo.get())
1570 post_call_txt += '%sfor (uint32_t i=0; i<%s; ++i) {\n' % (indent, del_obj)
1571 del_obj = proto.params[-1].name
1572 indent += ' '
1573 post_call_txt += '%sdelete (VkUniqueObject*)%s[i];\n' % (indent, del_obj)
1574 indent = indent[4:]
1575 post_call_txt += '%s}\n' % (indent)
1576 else:
1577 post_call_txt += '%s\n' % (self.lineinfo.get())
Karl Schultz2d6c90e2016-04-29 17:22:50 -06001578 post_call_txt += '%slock.lock();\n' % (indent)
Tobin Ehlis10ba1de2016-04-13 12:59:43 -06001579 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 -07001580
1581 call_sig = proto.c_call()
Tobin Ehlis8bb7c2f2016-02-10 15:38:45 -07001582 # Replace default params with any custom local params
1583 for ld in local_decls:
1584 call_sig = call_sig.replace(ld, '(const %s)local_%s' % (local_decls[ld], ld))
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001585 if proto_is_global(proto):
1586 table_type = "instance"
1587 else:
1588 table_type = "device"
1589 pre_call_txt += '%s\n' % (self.lineinfo.get())
Tobin Ehlis453e91f2016-01-29 14:24:42 -07001590 open_ifdef = ''
1591 close_ifdef = ''
1592 if proto.name in ifdef_dict:
1593 open_ifdef = '#ifdef %s\n' % (ifdef_dict[proto.name])
1594 close_ifdef = '#endif\n'
1595 funcs.append('%s'
1596 '%s%s\n'
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001597 '{\n'
1598 '%s'
1599 ' %sget_dispatch_table(unique_objects_%s_table_map, %s)->%s;\n'
1600 '%s'
1601 '%s'
Tobin Ehlis453e91f2016-01-29 14:24:42 -07001602 '}\n'
1603 '%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 -07001604 return "\n\n".join(funcs)
1605
1606 def generate_body(self):
1607 self.layer_name = "unique_objects"
1608 extensions=[('wsi_enabled',
1609 ['vkCreateSwapchainKHR',
1610 'vkDestroySwapchainKHR', 'vkGetSwapchainImagesKHR',
1611 'vkAcquireNextImageKHR', 'vkQueuePresentKHR'])]
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001612 if self.wsi == 'Win32':
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001613 instance_extensions=[('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001614 ['vkDestroySurfaceKHR',
1615 'vkGetPhysicalDeviceSurfaceSupportKHR',
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001616 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1617 'vkGetPhysicalDeviceSurfaceFormatsKHR',
1618 'vkGetPhysicalDeviceSurfacePresentModesKHR',
Jon Ashburn00dc7412016-01-07 16:13:06 -07001619 'vkCreateWin32SurfaceKHR'
1620 ])]
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001621 elif self.wsi == 'Android':
1622 instance_extensions=[('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001623 ['vkDestroySurfaceKHR',
1624 'vkGetPhysicalDeviceSurfaceSupportKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001625 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1626 'vkGetPhysicalDeviceSurfaceFormatsKHR',
Michael Lentine56512bb2016-03-02 17:28:55 -06001627 'vkGetPhysicalDeviceSurfacePresentModesKHR',
1628 'vkCreateAndroidSurfaceKHR'])]
Karl Schultz9daf7a32016-03-08 15:14:11 -07001629 elif self.wsi == 'Xcb' or self.wsi == 'Xlib' or self.wsi == 'Wayland' or self.wsi == 'Mir':
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001630 instance_extensions=[('wsi_enabled',
Michael Lentine56512bb2016-03-02 17:28:55 -06001631 ['vkDestroySurfaceKHR',
1632 'vkGetPhysicalDeviceSurfaceSupportKHR',
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001633 'vkGetPhysicalDeviceSurfaceCapabilitiesKHR',
1634 'vkGetPhysicalDeviceSurfaceFormatsKHR',
1635 'vkGetPhysicalDeviceSurfacePresentModesKHR',
Courtney Goeltzenleuchter5a0f2832016-02-11 11:44:04 -07001636 'vkCreateXcbSurfaceKHR',
Karl Schultz9daf7a32016-03-08 15:14:11 -07001637 'vkCreateXlibSurfaceKHR',
1638 'vkCreateWaylandSurfaceKHR',
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001639 'vkCreateMirSurfaceKHR'
1640 ])]
Karl Schultz9daf7a32016-03-08 15:14:11 -07001641 else:
1642 print('Error: Undefined DisplayServer')
1643 instance_extensions=[]
1644
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001645 body = [self._generate_dispatch_entrypoints("VK_LAYER_EXPORT"),
1646 self._generate_layer_gpa_function(extensions,
1647 instance_extensions)]
1648 return "\n\n".join(body)
1649
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001650def main():
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001651 wsi = {
1652 "Win32",
1653 "Android",
1654 "Xcb",
1655 "Xlib",
1656 "Wayland",
1657 "Mir",
1658 }
1659
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001660 subcommands = {
Mark Lobodzinski0d054fe2015-12-30 08:16:12 -07001661 "object_tracker" : ObjectTrackerSubcommand,
Tobin Ehlisd34a4c52015-12-08 10:50:10 -07001662 "unique_objects" : UniqueObjectsSubcommand,
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001663 }
1664
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001665 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]):
1666 print("Usage: %s <wsi> <subcommand> <input_header> [options]" % sys.argv[0])
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001667 print
Tobin Ehlis7e65d752015-01-15 17:51:52 -07001668 print("Available subcommands are: %s" % " ".join(subcommands))
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001669 exit(1)
1670
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001671 hfp = vk_helper.HeaderFileParser(sys.argv[3])
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001672 hfp.parse()
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001673 vk_helper.enum_val_dict = hfp.get_enum_val_dict()
1674 vk_helper.enum_type_dict = hfp.get_enum_type_dict()
1675 vk_helper.struct_dict = hfp.get_struct_dict()
1676 vk_helper.typedef_fwd_dict = hfp.get_typedef_fwd_dict()
1677 vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
1678 vk_helper.types_dict = hfp.get_types_dict()
Tobin Ehlis14ff0852014-12-17 17:44:50 -07001679
Mun, Gwan-gyeongbd4dd592016-02-22 09:43:09 +09001680 subcmd = subcommands[sys.argv[2]](sys.argv[3:])
Tobin Ehlis12076fc2014-10-22 09:06:33 -06001681 subcmd.run()
1682
1683if __name__ == "__main__":
1684 main()