blob: e48c0ad2227eddb17fa5011c53288f678b4b5c8b [file] [log] [blame]
Mark Lobodzinskia509c292016-10-11 14:33:07 -06001#!/usr/bin/python3 -i
2#
3# Copyright (c) 2015-2016 The Khronos Group Inc.
4# Copyright (c) 2015-2016 Valve Corporation
5# Copyright (c) 2015-2016 LunarG, Inc.
6# Copyright (c) 2015-2016 Google Inc.
7#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20# Author: Tobin Ehlis <tobine@google.com>
21# Author: Mark Lobodzinski <mark@lunarg.com>
22
23import os,re,sys
24import xml.etree.ElementTree as etree
25from generator import *
26from collections import namedtuple
27
28# UniqueObjectsGeneratorOptions - subclass of GeneratorOptions.
29#
30# Adds options used by UniqueObjectsOutputGenerator objects during
31# unique objects layer generation.
32#
33# Additional members
34# prefixText - list of strings to prefix generated header with
35# (usually a copyright statement + calling convention macros).
36# protectFile - True if multiple inclusion protection should be
37# generated (based on the filename) around the entire header.
38# protectFeature - True if #ifndef..#endif protection should be
39# generated around a feature interface in the header file.
40# genFuncPointers - True if function pointer typedefs should be
41# generated
42# protectProto - If conditional protection should be generated
43# around prototype declarations, set to either '#ifdef'
44# to require opt-in (#ifdef protectProtoStr) or '#ifndef'
45# to require opt-out (#ifndef protectProtoStr). Otherwise
46# set to None.
47# protectProtoStr - #ifdef/#ifndef symbol to use around prototype
48# declarations, if protectProto is set
49# apicall - string to use for the function declaration prefix,
50# such as APICALL on Windows.
51# apientry - string to use for the calling convention macro,
52# in typedefs, such as APIENTRY.
53# apientryp - string to use for the calling convention macro
54# in function pointer typedefs, such as APIENTRYP.
55# indentFuncProto - True if prototype declarations should put each
56# parameter on a separate line
57# indentFuncPointer - True if typedefed function pointers should put each
58# parameter on a separate line
59# alignFuncParam - if nonzero and parameters are being put on a
60# separate line, align parameter names at the specified column
61class UniqueObjectsGeneratorOptions(GeneratorOptions):
62 def __init__(self,
63 filename = None,
64 directory = '.',
65 apiname = None,
66 profile = None,
67 versions = '.*',
68 emitversions = '.*',
69 defaultExtensions = None,
70 addExtensions = None,
71 removeExtensions = None,
72 sortProcedure = regSortFeatures,
73 prefixText = "",
74 genFuncPointers = True,
75 protectFile = True,
76 protectFeature = True,
77 protectProto = None,
78 protectProtoStr = None,
79 apicall = '',
80 apientry = '',
81 apientryp = '',
82 indentFuncProto = True,
83 indentFuncPointer = False,
84 alignFuncParam = 0):
85 GeneratorOptions.__init__(self, filename, directory, apiname, profile,
86 versions, emitversions, defaultExtensions,
87 addExtensions, removeExtensions, sortProcedure)
88 self.prefixText = prefixText
89 self.genFuncPointers = genFuncPointers
90 self.protectFile = protectFile
91 self.protectFeature = protectFeature
92 self.protectProto = protectProto
93 self.protectProtoStr = protectProtoStr
94 self.apicall = apicall
95 self.apientry = apientry
96 self.apientryp = apientryp
97 self.indentFuncProto = indentFuncProto
98 self.indentFuncPointer = indentFuncPointer
99 self.alignFuncParam = alignFuncParam
100
101# UniqueObjectsOutputGenerator - subclass of OutputGenerator.
102# Generates unique objects layer non-dispatchable handle-wrapping code.
103#
104# ---- methods ----
105# UniqueObjectsOutputGenerator(errFile, warnFile, diagFile) - args as for OutputGenerator. Defines additional internal state.
106# ---- methods overriding base class ----
107# beginFile(genOpts)
108# endFile()
109# beginFeature(interface, emit)
110# endFeature()
111# genCmd(cmdinfo)
112# genStruct()
113# genType()
114class UniqueObjectsOutputGenerator(OutputGenerator):
115 """Generate UniqueObjects code based on XML element attributes"""
116 # This is an ordered list of sections in the header file.
117 ALL_SECTIONS = ['command']
118 def __init__(self,
119 errFile = sys.stderr,
120 warnFile = sys.stderr,
121 diagFile = sys.stdout):
122 OutputGenerator.__init__(self, errFile, warnFile, diagFile)
123 self.INDENT_SPACES = 4
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600124 self.intercepts = []
Mark Lobodzinski8c375832017-02-09 15:58:14 -0700125 self.instance_extensions = []
126 self.device_extensions = []
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600127 # Commands which are not autogenerated but still intercepted
128 self.no_autogen_list = [
Jamie Madill24aa9742016-12-13 17:02:57 -0500129 'vkGetDeviceProcAddr',
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600130 'vkGetInstanceProcAddr',
131 'vkCreateInstance',
132 'vkDestroyInstance',
133 'vkCreateDevice',
134 'vkDestroyDevice',
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600135 'vkCreateComputePipelines',
136 'vkCreateGraphicsPipelines',
137 'vkCreateSwapchainKHR',
Dustin Graves9a6eb052017-03-28 14:18:54 -0600138 'vkCreateSharedSwapchainsKHR',
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600139 'vkGetSwapchainImagesKHR',
Chris Forbes0f507f22017-04-16 13:13:17 +1200140 'vkQueuePresentKHR',
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600141 'vkEnumerateInstanceLayerProperties',
142 'vkEnumerateDeviceLayerProperties',
143 'vkEnumerateInstanceExtensionProperties',
Mark Lobodzinski71703a52017-03-03 08:40:16 -0700144 'vkCreateDescriptorUpdateTemplateKHR',
145 'vkDestroyDescriptorUpdateTemplateKHR',
146 'vkUpdateDescriptorSetWithTemplateKHR',
147 'vkCmdPushDescriptorSetWithTemplateKHR',
Mark Lobodzinskia096c122017-03-16 11:54:35 -0600148 'vkDebugMarkerSetObjectTagEXT',
149 'vkDebugMarkerSetObjectNameEXT',
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600150 ]
151 # Commands shadowed by interface functions and are not implemented
152 self.interface_functions = [
153 'vkGetPhysicalDeviceDisplayPropertiesKHR',
154 'vkGetPhysicalDeviceDisplayPlanePropertiesKHR',
155 'vkGetDisplayPlaneSupportedDisplaysKHR',
156 'vkGetDisplayModePropertiesKHR',
Norbert Nopper1dec9a52016-11-25 07:55:13 +0100157 'vkGetDisplayPlaneCapabilitiesKHR',
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600158 # DebugReport APIs are hooked, but handled separately in the source file
159 'vkCreateDebugReportCallbackEXT',
160 'vkDestroyDebugReportCallbackEXT',
161 'vkDebugReportMessageEXT',
162 ]
163 self.headerVersion = None
164 # Internal state - accumulators for different inner block text
165 self.sections = dict([(section, []) for section in self.ALL_SECTIONS])
Mark Lobodzinski85904632017-04-06 10:07:42 -0600166
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600167 self.cmdMembers = []
168 self.cmd_feature_protect = [] # Save ifdef's for each command
Mark Lobodzinski85904632017-04-06 10:07:42 -0600169 self.cmd_info_data = [] # Save the cmdinfo data for wrapping the handles when processing is complete
170 self.structMembers = [] # List of StructMemberData records for all Vulkan structs
171 self.extension_structs = [] # List of all structs or sister-structs containing handles
172 # A sister-struct may contain no handles but shares <validextensionstructs> with one that does
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600173 self.structTypes = dict() # Map of Vulkan struct typename to required VkStructureType
174 self.struct_member_dict = dict()
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600175 # Named tuples to store struct and command data
Mark Lobodzinski85904632017-04-06 10:07:42 -0600176 self.StructType = namedtuple('StructType', ['name', 'value'])
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600177 self.CmdMemberData = namedtuple('CmdMemberData', ['name', 'members'])
178 self.CmdInfoData = namedtuple('CmdInfoData', ['name', 'cmdinfo'])
179 self.CmdExtraProtect = namedtuple('CmdExtraProtect', ['name', 'extra_protect'])
Mark Lobodzinski85904632017-04-06 10:07:42 -0600180
181 self.CommandParam = namedtuple('CommandParam', ['type', 'name', 'ispointer', 'isconst', 'iscount', 'len', 'extstructs', 'cdecl', 'islocal', 'iscreate', 'isdestroy', 'feature_protect'])
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600182 self.StructMemberData = namedtuple('StructMemberData', ['name', 'members'])
183 #
184 def incIndent(self, indent):
185 inc = ' ' * self.INDENT_SPACES
186 if indent:
187 return indent + inc
188 return inc
189 #
190 def decIndent(self, indent):
191 if indent and (len(indent) > self.INDENT_SPACES):
192 return indent[:-self.INDENT_SPACES]
193 return ''
194 #
195 # Override makeProtoName to drop the "vk" prefix
196 def makeProtoName(self, name, tail):
197 return self.genOpts.apientry + name[2:] + tail
198 #
199 # Check if the parameter passed in is a pointer to an array
200 def paramIsArray(self, param):
201 return param.attrib.get('len') is not None
202 #
203 def beginFile(self, genOpts):
204 OutputGenerator.beginFile(self, genOpts)
205 # User-supplied prefix text, if any (list of strings)
206 if (genOpts.prefixText):
207 for s in genOpts.prefixText:
208 write(s, file=self.outFile)
209 # Namespace
210 self.newline()
211 write('namespace unique_objects {', file = self.outFile)
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600212 # Now that the data is all collected and complete, generate and output the wrapping/unwrapping routines
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600213 def endFile(self):
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600214
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600215 self.struct_member_dict = dict(self.structMembers)
216
217 # Generate the list of APIs that might need to handle wrapped extension structs
218 self.GenerateCommandWrapExtensionList()
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600219 # Write out wrapping/unwrapping functions
220 self.WrapCommands()
Mark Lobodzinski85904632017-04-06 10:07:42 -0600221 # Build and write out pNext processing function
222 extension_proc = self.build_extension_processing_func()
223 self.newline()
224 write('// Unique Objects pNext extension handling function', file=self.outFile)
225 write('%s' % extension_proc, file=self.outFile)
226
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600227 # Actually write the interface to the output file.
228 if (self.emit):
229 self.newline()
230 if (self.featureExtraProtect != None):
231 write('#ifdef', self.featureExtraProtect, file=self.outFile)
232 # Write the unique_objects code to the file
233 if (self.sections['command']):
234 if (self.genOpts.protectProto):
235 write(self.genOpts.protectProto,
236 self.genOpts.protectProtoStr, file=self.outFile)
237 write('\n'.join(self.sections['command']), end=u'', file=self.outFile)
238 if (self.featureExtraProtect != None):
239 write('\n#endif //', self.featureExtraProtect, file=self.outFile)
240 else:
241 self.newline()
242
Mark Lobodzinski8c375832017-02-09 15:58:14 -0700243 # Write out device extension white list
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600244 self.newline()
Mark Lobodzinski8c375832017-02-09 15:58:14 -0700245 write('// Layer Device Extension Whitelist', file=self.outFile)
246 write('static const char *kUniqueObjectsSupportedDeviceExtensions =', file=self.outFile)
247 for line in self.device_extensions:
248 write('%s' % line, file=self.outFile)
249 write(';\n', file=self.outFile)
250
251 # Write out instance extension white list
252 self.newline()
253 write('// Layer Instance Extension Whitelist', file=self.outFile)
254 write('static const char *kUniqueObjectsSupportedInstanceExtensions =', file=self.outFile)
255 for line in self.instance_extensions:
256 write('%s' % line, file=self.outFile)
257 write(';\n', file=self.outFile)
258 self.newline()
259
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600260 # Record intercepted procedures
261 write('// intercepts', file=self.outFile)
262 write('struct { const char* name; PFN_vkVoidFunction pFunc;} procmap[] = {', file=self.outFile)
263 write('\n'.join(self.intercepts), file=self.outFile)
264 write('};\n', file=self.outFile)
265 self.newline()
266 write('} // namespace unique_objects', file=self.outFile)
267 # Finish processing in superclass
268 OutputGenerator.endFile(self)
269 #
270 def beginFeature(self, interface, emit):
271 # Start processing in superclass
272 OutputGenerator.beginFeature(self, interface, emit)
273 self.headerVersion = None
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600274
Mark Lobodzinski8c375832017-02-09 15:58:14 -0700275 if self.featureName != 'VK_VERSION_1_0':
276 white_list_entry = []
277 if (self.featureExtraProtect != None):
278 white_list_entry += [ '#ifdef %s' % self.featureExtraProtect ]
279 white_list_entry += [ '"%s"' % self.featureName ]
280 if (self.featureExtraProtect != None):
281 white_list_entry += [ '#endif' ]
282 featureType = interface.get('type')
283 if featureType == 'instance':
284 self.instance_extensions += white_list_entry
285 elif featureType == 'device':
286 self.device_extensions += white_list_entry
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600287 #
288 def endFeature(self):
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600289 # Finish processing in superclass
290 OutputGenerator.endFeature(self)
291 #
292 def genType(self, typeinfo, name):
293 OutputGenerator.genType(self, typeinfo, name)
294 typeElem = typeinfo.elem
295 # If the type is a struct type, traverse the imbedded <member> tags generating a structure.
296 # Otherwise, emit the tag text.
297 category = typeElem.get('category')
298 if (category == 'struct' or category == 'union'):
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600299 self.genStruct(typeinfo, name)
300 #
301 # Append a definition to the specified section
302 def appendSection(self, section, text):
303 # self.sections[section].append('SECTION: ' + section + '\n')
304 self.sections[section].append(text)
305 #
306 # Check if the parameter passed in is a pointer
307 def paramIsPointer(self, param):
308 ispointer = False
309 for elem in param:
310 if ((elem.tag is not 'type') and (elem.tail is not None)) and '*' in elem.tail:
311 ispointer = True
312 return ispointer
313 #
314 # Get the category of a type
315 def getTypeCategory(self, typename):
316 types = self.registry.tree.findall("types/type")
317 for elem in types:
318 if (elem.find("name") is not None and elem.find('name').text == typename) or elem.attrib.get('name') == typename:
319 return elem.attrib.get('category')
320 #
321 # Check if a parent object is dispatchable or not
322 def isHandleTypeNonDispatchable(self, handletype):
323 handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']")
324 if handle is not None and handle.find('type').text == 'VK_DEFINE_NON_DISPATCHABLE_HANDLE':
325 return True
326 else:
327 return False
328 #
329 # Retrieve the type and name for a parameter
330 def getTypeNameTuple(self, param):
331 type = ''
332 name = ''
333 for elem in param:
334 if elem.tag == 'type':
335 type = noneStr(elem.text)
336 elif elem.tag == 'name':
337 name = noneStr(elem.text)
338 return (type, name)
339 #
340 # Retrieve the value of the len tag
341 def getLen(self, param):
342 result = None
343 len = param.attrib.get('len')
344 if len and len != 'null-terminated':
345 # For string arrays, 'len' can look like 'count,null-terminated', indicating that we
346 # have a null terminated array of strings. We strip the null-terminated from the
347 # 'len' field and only return the parameter specifying the string count
348 if 'null-terminated' in len:
349 result = len.split(',')[0]
350 else:
351 result = len
352 # Spec has now notation for len attributes, using :: instead of platform specific pointer symbol
353 result = str(result).replace('::', '->')
354 return result
355 #
356 # Generate a VkStructureType based on a structure typename
357 def genVkStructureType(self, typename):
358 # Add underscore between lowercase then uppercase
359 value = re.sub('([a-z0-9])([A-Z])', r'\1_\2', typename)
360 # Change to uppercase
361 value = value.upper()
362 # Add STRUCTURE_TYPE_
363 return re.sub('VK_', 'VK_STRUCTURE_TYPE_', value)
364 #
365 # Struct parameter check generation.
366 # This is a special case of the <type> tag where the contents are interpreted as a set of
367 # <member> tags instead of freeform C type declarations. The <member> tags are just like
368 # <param> tags - they are a declaration of a struct or union member. Only simple member
369 # declarations are supported (no nested structs etc.)
370 def genStruct(self, typeinfo, typeName):
371 OutputGenerator.genStruct(self, typeinfo, typeName)
372 members = typeinfo.elem.findall('.//member')
373 # Iterate over members once to get length parameters for arrays
374 lens = set()
375 for member in members:
376 len = self.getLen(member)
377 if len:
378 lens.add(len)
379 # Generate member info
380 membersInfo = []
381 for member in members:
382 # Get the member's type and name
383 info = self.getTypeNameTuple(member)
384 type = info[0]
385 name = info[1]
386 cdecl = self.makeCParamDecl(member, 0)
387 # Process VkStructureType
388 if type == 'VkStructureType':
389 # Extract the required struct type value from the comments
390 # embedded in the original text defining the 'typeinfo' element
391 rawXml = etree.tostring(typeinfo.elem).decode('ascii')
392 result = re.search(r'VK_STRUCTURE_TYPE_\w+', rawXml)
393 if result:
394 value = result.group(0)
395 else:
396 value = self.genVkStructureType(typeName)
Mark Lobodzinski85904632017-04-06 10:07:42 -0600397 # Store the required type value
398 self.structTypes[typeName] = self.StructType(name=name, value=value)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600399 # Store pointer/array/string info
Mark Lobodzinski85904632017-04-06 10:07:42 -0600400 extstructs = member.attrib.get('validextensionstructs') if name == 'pNext' else None
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600401 membersInfo.append(self.CommandParam(type=type,
402 name=name,
403 ispointer=self.paramIsPointer(member),
404 isconst=True if 'const' in cdecl else False,
405 iscount=True if name in lens else False,
406 len=self.getLen(member),
Mark Lobodzinski85904632017-04-06 10:07:42 -0600407 extstructs=extstructs,
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600408 cdecl=cdecl,
409 islocal=False,
410 iscreate=False,
Mark Lobodzinski85904632017-04-06 10:07:42 -0600411 isdestroy=False,
412 feature_protect=self.featureExtraProtect))
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600413 self.structMembers.append(self.StructMemberData(name=typeName, members=membersInfo))
Mark Lobodzinski85904632017-04-06 10:07:42 -0600414
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600415 #
416 # Insert a lock_guard line
417 def lock_guard(self, indent):
418 return '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % indent
419 #
420 # Determine if a struct has an NDO as a member or an embedded member
421 def struct_contains_ndo(self, struct_item):
422 struct_member_dict = dict(self.structMembers)
423 struct_members = struct_member_dict[struct_item]
424
425 for member in struct_members:
426 if self.isHandleTypeNonDispatchable(member.type):
427 return True
428 elif member.type in struct_member_dict:
429 if self.struct_contains_ndo(member.type) == True:
430 return True
431 return False
432 #
433 # Return list of struct members which contain, or which sub-structures contain
434 # an NDO in a given list of parameters or members
435 def getParmeterStructsWithNdos(self, item_list):
436 struct_list = set()
437 for item in item_list:
438 paramtype = item.find('type')
439 typecategory = self.getTypeCategory(paramtype.text)
440 if typecategory == 'struct':
441 if self.struct_contains_ndo(paramtype.text) == True:
442 struct_list.add(item)
443 return struct_list
444 #
445 # Return list of non-dispatchable objects from a given list of parameters or members
446 def getNdosInParameterList(self, item_list, create_func):
447 ndo_list = set()
448 if create_func == True:
449 member_list = item_list[0:-1]
450 else:
451 member_list = item_list
452 for item in member_list:
453 if self.isHandleTypeNonDispatchable(paramtype.text):
454 ndo_list.add(item)
455 return ndo_list
456 #
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600457 # Construct list of extension structs containing handles, or extension structs that share a <validextensionstructs>
458 # tag WITH an extension struct containing handles. All extension structs in any pNext chain will have to be copied.
459 # TODO: make this recursive -- structs buried three or more levels deep are not searched for extensions
460 def GenerateCommandWrapExtensionList(self):
Mark Lobodzinski85904632017-04-06 10:07:42 -0600461 for struct in self.structMembers:
462 if (len(struct.members) > 1) and struct.members[1].extstructs is not None:
463 found = False;
464 for item in struct.members[1].extstructs.split(','):
465 if item != '' and self.struct_contains_ndo(item) == True:
466 found = True
467 if found == True:
468 for item in struct.members[1].extstructs.split(','):
469 if item != '' and item not in self.extension_structs:
470 self.extension_structs.append(item)
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600471 #
472 # Returns True if a struct may have a pNext chain containing an NDO
473 def StructWithExtensions(self, struct_type):
474 if struct_type in self.struct_member_dict:
475 param_info = self.struct_member_dict[struct_type]
476 if (len(param_info) > 1) and param_info[1].extstructs is not None:
477 for item in param_info[1].extstructs.split(','):
478 if item in self.extension_structs:
479 return True
480 return False
481 #
482 # Generate pNext handling function
483 def build_extension_processing_func(self):
Mark Lobodzinski85904632017-04-06 10:07:42 -0600484 # Construct helper functions to build and free pNext extension chains
485 pnext_proc = ''
486 pnext_proc += 'void *CreateUnwrappedExtensionStructs(layer_data *dev_data, const void *pNext) {\n'
487 pnext_proc += ' void *cur_pnext = const_cast<void *>(pNext);\n'
488 pnext_proc += ' void *head_pnext = NULL;\n'
489 pnext_proc += ' void *prev_ext_struct = NULL;\n'
490 pnext_proc += ' void *cur_ext_struct = NULL;\n\n'
491 pnext_proc += ' while (cur_pnext != NULL) {\n'
492 pnext_proc += ' GenericHeader *header = reinterpret_cast<GenericHeader *>(cur_pnext);\n\n'
493 pnext_proc += ' switch (header->sType) {\n'
494 for item in self.extension_structs:
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600495 struct_info = self.struct_member_dict[item]
Mark Lobodzinski85904632017-04-06 10:07:42 -0600496 if struct_info[0].feature_protect is not None:
497 pnext_proc += '#ifdef %s \n' % struct_info[0].feature_protect
498 pnext_proc += ' case %s: {\n' % self.structTypes[item].value
499 pnext_proc += ' safe_%s *safe_struct = reinterpret_cast<safe_%s *>(new safe_%s);\n' % (item, item, item)
500 pnext_proc += ' safe_struct->initialize(reinterpret_cast<const %s *>(cur_pnext));\n' % item
501 # Generate code to unwrap the handles
502 indent = ' '
503 (tmp_decl, tmp_pre, tmp_post) = self.uniquify_members(struct_info, indent, 'safe_struct->', 0, False, False, False, False)
504 pnext_proc += tmp_pre
505 pnext_proc += ' cur_ext_struct = reinterpret_cast<void *>(safe_struct);\n'
506 pnext_proc += ' } break;\n'
507 if struct_info[0].feature_protect is not None:
508 pnext_proc += '#endif // %s \n' % struct_info[0].feature_protect
509 pnext_proc += '\n'
510 pnext_proc += ' default:\n'
511 pnext_proc += ' break;\n'
512 pnext_proc += ' }\n\n'
513 pnext_proc += ' // Save pointer to the first structure in the pNext chain\n'
514 pnext_proc += ' head_pnext = (head_pnext ? head_pnext : cur_ext_struct);\n\n'
515 pnext_proc += ' // For any extension structure but the first, link the last struct\'s pNext to the current ext struct\n'
516 pnext_proc += ' if (prev_ext_struct) {\n'
517 pnext_proc += ' (reinterpret_cast<GenericHeader *>(prev_ext_struct))->pNext = cur_ext_struct;\n'
518 pnext_proc += ' }\n'
519 pnext_proc += ' prev_ext_struct = cur_ext_struct;\n\n'
520 pnext_proc += ' // Process the next structure in the chain\n'
521 pnext_proc += ' cur_pnext = const_cast<void *>(header->pNext);\n'
522 pnext_proc += ' }\n'
523 pnext_proc += ' return head_pnext;\n'
524 pnext_proc += '}\n\n'
525 pnext_proc += '// Free a pNext extension chain\n'
526 pnext_proc += 'void FreeUnwrappedExtensionStructs(void *head) {\n'
527 pnext_proc += ' void * curr_ptr = head;\n'
528 pnext_proc += ' while (curr_ptr) {\n'
529 pnext_proc += ' GenericHeader *header = reinterpret_cast<GenericHeader *>(curr_ptr);\n'
530 pnext_proc += ' void *temp = curr_ptr;\n'
531 pnext_proc += ' curr_ptr = header->pNext;\n'
532 pnext_proc += ' free(temp);\n'
533 pnext_proc += ' }\n'
534 pnext_proc += '}\n'
535 return pnext_proc
536
537 #
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600538 # Generate source for creating a non-dispatchable object
539 def generate_create_ndo_code(self, indent, proto, params, cmd_info):
540 create_ndo_code = ''
Mark Young39389872017-01-19 21:10:49 -0700541 handle_type = params[-1].find('type')
542 if self.isHandleTypeNonDispatchable(handle_type.text):
543 # Check for special case where multiple handles are returned
544 ndo_array = False
545 if cmd_info[-1].len is not None:
546 ndo_array = True;
547 handle_name = params[-1].find('name')
548 create_ndo_code += '%sif (VK_SUCCESS == result) {\n' % (indent)
549 indent = self.incIndent(indent)
550 create_ndo_code += '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % (indent)
551 ndo_dest = '*%s' % handle_name.text
552 if ndo_array == True:
553 create_ndo_code += '%sfor (uint32_t index0 = 0; index0 < %s; index0++) {\n' % (indent, cmd_info[-1].len)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600554 indent = self.incIndent(indent)
Mark Young39389872017-01-19 21:10:49 -0700555 ndo_dest = '%s[index0]' % cmd_info[-1].name
Chris Forbesd73a1a02017-05-02 18:25:30 -0700556 create_ndo_code += '%s%s = WrapNew(dev_data, %s);\n' % (indent, ndo_dest, ndo_dest)
Mark Young39389872017-01-19 21:10:49 -0700557 if ndo_array == True:
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600558 indent = self.decIndent(indent)
Mark Young39389872017-01-19 21:10:49 -0700559 create_ndo_code += '%s}\n' % indent
560 indent = self.decIndent(indent)
561 create_ndo_code += '%s}\n' % (indent)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600562 return create_ndo_code
563 #
564 # Generate source for destroying a non-dispatchable object
565 def generate_destroy_ndo_code(self, indent, proto, cmd_info):
566 destroy_ndo_code = ''
567 ndo_array = False
568 if True in [destroy_txt in proto.text for destroy_txt in ['Destroy', 'Free']]:
569 # Check for special case where multiple handles are returned
570 if cmd_info[-1].len is not None:
571 ndo_array = True;
572 param = -1
573 else:
574 param = -2
575 if self.isHandleTypeNonDispatchable(cmd_info[param].type) == True:
576 if ndo_array == True:
577 # This API is freeing an array of handles. Remove them from the unique_id map.
578 destroy_ndo_code += '%sif ((VK_SUCCESS == result) && (%s)) {\n' % (indent, cmd_info[param].name)
579 indent = self.incIndent(indent)
580 destroy_ndo_code += '%sstd::unique_lock<std::mutex> lock(global_lock);\n' % (indent)
581 destroy_ndo_code += '%sfor (uint32_t index0 = 0; index0 < %s; index0++) {\n' % (indent, cmd_info[param].len)
582 indent = self.incIndent(indent)
583 destroy_ndo_code += '%s%s handle = %s[index0];\n' % (indent, cmd_info[param].type, cmd_info[param].name)
584 destroy_ndo_code += '%suint64_t unique_id = reinterpret_cast<uint64_t &>(handle);\n' % (indent)
585 destroy_ndo_code += '%sdev_data->unique_id_mapping.erase(unique_id);\n' % (indent)
586 indent = self.decIndent(indent);
587 destroy_ndo_code += '%s}\n' % indent
588 indent = self.decIndent(indent);
589 destroy_ndo_code += '%s}\n' % indent
590 else:
591 # Remove a single handle from the map
592 destroy_ndo_code += '%sstd::unique_lock<std::mutex> lock(global_lock);\n' % (indent)
593 destroy_ndo_code += '%suint64_t %s_id = reinterpret_cast<uint64_t &>(%s);\n' % (indent, cmd_info[param].name, cmd_info[param].name)
594 destroy_ndo_code += '%s%s = (%s)dev_data->unique_id_mapping[%s_id];\n' % (indent, cmd_info[param].name, cmd_info[param].type, cmd_info[param].name)
595 destroy_ndo_code += '%sdev_data->unique_id_mapping.erase(%s_id);\n' % (indent, cmd_info[param].name)
596 destroy_ndo_code += '%slock.unlock();\n' % (indent)
597 return ndo_array, destroy_ndo_code
598
599 #
600 # Clean up local declarations
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600601 def cleanUpLocalDeclarations(self, indent, prefix, name, len, index, process_pnext):
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600602 cleanup = '%sif (local_%s%s)\n' % (indent, prefix, name)
603 if len is not None:
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600604 if process_pnext:
605 cleanup += '%s for (uint32_t %s = 0; %s < %s%s; ++%s) {\n' % (indent, index, index, prefix, len, index)
606 cleanup += '%s FreeUnwrappedExtensionStructs(const_cast<void *>(local_%s%s[%s].pNext));\n' % (indent, prefix, name, index)
607 cleanup += '%s }\n' % indent
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600608 cleanup += '%s delete[] local_%s%s;\n' % (indent, prefix, name)
609 else:
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600610 if process_pnext:
611 cleanup += '%s FreeUnwrappedExtensionStructs(const_cast<void *>(local_%s%s->pNext));\n' % (indent, prefix, name)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600612 cleanup += '%s delete local_%s%s;\n' % (indent, prefix, name)
613 return cleanup
614 #
615 # Output UO code for a single NDO (ndo_count is NULL) or a counted list of NDOs
616 def outputNDOs(self, ndo_type, ndo_name, ndo_count, prefix, index, indent, destroy_func, destroy_array, top_level):
617 decl_code = ''
618 pre_call_code = ''
619 post_call_code = ''
620 if ndo_count is not None:
621 if top_level == True:
622 decl_code += '%s%s *local_%s%s = NULL;\n' % (indent, ndo_type, prefix, ndo_name)
623 pre_call_code += '%s if (%s%s) {\n' % (indent, prefix, ndo_name)
624 indent = self.incIndent(indent)
625 if top_level == True:
626 pre_call_code += '%s local_%s%s = new %s[%s];\n' % (indent, prefix, ndo_name, ndo_type, ndo_count)
627 pre_call_code += '%s for (uint32_t %s = 0; %s < %s; ++%s) {\n' % (indent, index, index, ndo_count, index)
628 indent = self.incIndent(indent)
Chris Forbesb9889702017-05-02 18:35:12 -0700629 pre_call_code += '%s local_%s%s[%s] = Unwrap(dev_data, %s[%s]);\n' % (indent, prefix, ndo_name, index, ndo_name, index)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600630 else:
631 pre_call_code += '%s for (uint32_t %s = 0; %s < %s; ++%s) {\n' % (indent, index, index, ndo_count, index)
632 indent = self.incIndent(indent)
Chris Forbesb9889702017-05-02 18:35:12 -0700633 pre_call_code += '%s %s%s[%s] = Unwrap(dev_data, %s%s[%s]);\n' % (indent, prefix, ndo_name, index, prefix, ndo_name, index)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600634 indent = self.decIndent(indent)
635 pre_call_code += '%s }\n' % indent
636 indent = self.decIndent(indent)
637 pre_call_code += '%s }\n' % indent
638 if top_level == True:
639 post_call_code += '%sif (local_%s%s)\n' % (indent, prefix, ndo_name)
640 indent = self.incIndent(indent)
641 post_call_code += '%sdelete[] local_%s;\n' % (indent, ndo_name)
642 else:
643 if top_level == True:
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600644 if (destroy_func == False) or (destroy_array == True):
Chris Forbesb9889702017-05-02 18:35:12 -0700645 pre_call_code += '%s %s = Unwrap(dev_data, %s);\n' % (indent, ndo_name, ndo_name)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600646 else:
647 # Make temp copy of this var with the 'local' removed. It may be better to not pass in 'local_'
648 # as part of the string and explicitly print it
649 fix = str(prefix).strip('local_');
650 pre_call_code += '%s if (%s%s) {\n' % (indent, fix, ndo_name)
651 indent = self.incIndent(indent)
Chris Forbesb9889702017-05-02 18:35:12 -0700652 pre_call_code += '%s %s%s = Unwrap(dev_data, %s%s);\n' % (indent, prefix, ndo_name, fix, ndo_name)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600653 indent = self.decIndent(indent)
654 pre_call_code += '%s }\n' % indent
655 return decl_code, pre_call_code, post_call_code
656 #
657 # first_level_param indicates if elements are passed directly into the function else they're below a ptr/struct
658 # create_func means that this is API creates or allocates NDOs
659 # destroy_func indicates that this API destroys or frees NDOs
660 # destroy_array means that the destroy_func operated on an array of NDOs
661 def uniquify_members(self, members, indent, prefix, array_index, create_func, destroy_func, destroy_array, first_level_param):
662 decls = ''
663 pre_code = ''
664 post_code = ''
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600665 index = 'index%s' % str(array_index)
666 array_index += 1
667 # Process any NDOs in this structure and recurse for any sub-structs in this struct
668 for member in members:
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600669 process_pnext = self.StructWithExtensions(member.type)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600670 # Handle NDOs
671 if self.isHandleTypeNonDispatchable(member.type) == True:
Jamie Madill24aa9742016-12-13 17:02:57 -0500672 count_name = member.len
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600673 if (count_name is not None):
674 if first_level_param == False:
675 count_name = '%s%s' % (prefix, member.len)
676
677 if (first_level_param == False) or (create_func == False):
678 (tmp_decl, tmp_pre, tmp_post) = self.outputNDOs(member.type, member.name, count_name, prefix, index, indent, destroy_func, destroy_array, first_level_param)
679 decls += tmp_decl
680 pre_code += tmp_pre
681 post_code += tmp_post
682 # Handle Structs that contain NDOs at some level
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600683 elif member.type in self.struct_member_dict:
684 # Structs at first level will have an NDO, OR, we need a safe_struct for the pnext chain
685 if self.struct_contains_ndo(member.type) == True or process_pnext:
686 struct_info = self.struct_member_dict[member.type]
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600687 # Struct Array
688 if member.len is not None:
689 # Update struct prefix
690 if first_level_param == True:
691 new_prefix = 'local_%s' % member.name
692 # Declare safe_VarType for struct
693 decls += '%ssafe_%s *%s = NULL;\n' % (indent, member.type, new_prefix)
694 else:
695 new_prefix = '%s%s' % (prefix, member.name)
696 pre_code += '%s if (%s%s) {\n' % (indent, prefix, member.name)
697 indent = self.incIndent(indent)
698 if first_level_param == True:
699 pre_code += '%s %s = new safe_%s[%s];\n' % (indent, new_prefix, member.type, member.len)
700 pre_code += '%s for (uint32_t %s = 0; %s < %s%s; ++%s) {\n' % (indent, index, index, prefix, member.len, index)
701 indent = self.incIndent(indent)
702 if first_level_param == True:
703 pre_code += '%s %s[%s].initialize(&%s[%s]);\n' % (indent, new_prefix, index, member.name, index)
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600704 if process_pnext:
705 pre_code += '%s %s[%s].pNext = CreateUnwrappedExtensionStructs(dev_data, %s[%s].pNext);\n' % (indent, new_prefix, index, new_prefix, index)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600706 local_prefix = '%s[%s].' % (new_prefix, index)
707 # Process sub-structs in this struct
708 (tmp_decl, tmp_pre, tmp_post) = self.uniquify_members(struct_info, indent, local_prefix, array_index, create_func, destroy_func, destroy_array, False)
709 decls += tmp_decl
710 pre_code += tmp_pre
711 post_code += tmp_post
712 indent = self.decIndent(indent)
713 pre_code += '%s }\n' % indent
714 indent = self.decIndent(indent)
715 pre_code += '%s }\n' % indent
716 if first_level_param == True:
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600717 post_code += self.cleanUpLocalDeclarations(indent, prefix, member.name, member.len, index, process_pnext)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600718 # Single Struct
719 else:
720 # Update struct prefix
721 if first_level_param == True:
722 new_prefix = 'local_%s->' % member.name
723 decls += '%ssafe_%s *local_%s%s = NULL;\n' % (indent, member.type, prefix, member.name)
724 else:
725 new_prefix = '%s%s->' % (prefix, member.name)
726 # Declare safe_VarType for struct
727 pre_code += '%s if (%s%s) {\n' % (indent, prefix, member.name)
728 indent = self.incIndent(indent)
729 if first_level_param == True:
730 pre_code += '%s local_%s%s = new safe_%s(%s);\n' % (indent, prefix, member.name, member.type, member.name)
731 # Process sub-structs in this struct
732 (tmp_decl, tmp_pre, tmp_post) = self.uniquify_members(struct_info, indent, new_prefix, array_index, create_func, destroy_func, destroy_array, False)
733 decls += tmp_decl
734 pre_code += tmp_pre
735 post_code += tmp_post
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600736 if process_pnext:
737 pre_code += '%s local_%s%s->pNext = CreateUnwrappedExtensionStructs(dev_data, local_%s%s->pNext);\n' % (indent, prefix, member.name, prefix, member.name)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600738 indent = self.decIndent(indent)
739 pre_code += '%s }\n' % indent
740 if first_level_param == True:
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600741 post_code += self.cleanUpLocalDeclarations(indent, prefix, member.name, member.len, index, process_pnext)
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600742 return decls, pre_code, post_code
743 #
744 # For a particular API, generate the non-dispatchable-object wrapping/unwrapping code
745 def generate_wrapping_code(self, cmd):
746 indent = ' '
747 proto = cmd.find('proto/name')
748 params = cmd.findall('param')
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600749
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600750 if proto.text is not None:
751 cmd_member_dict = dict(self.cmdMembers)
752 cmd_info = cmd_member_dict[proto.text]
753 # Handle ndo create/allocate operations
754 if cmd_info[0].iscreate:
755 create_ndo_code = self.generate_create_ndo_code(indent, proto, params, cmd_info)
756 else:
757 create_ndo_code = ''
758 # Handle ndo destroy/free operations
759 if cmd_info[0].isdestroy:
760 (destroy_array, destroy_ndo_code) = self.generate_destroy_ndo_code(indent, proto, cmd_info)
761 else:
762 destroy_array = False
763 destroy_ndo_code = ''
764 paramdecl = ''
765 param_pre_code = ''
766 param_post_code = ''
767 create_func = True if create_ndo_code else False
768 destroy_func = True if destroy_ndo_code else False
769 (paramdecl, param_pre_code, param_post_code) = self.uniquify_members(cmd_info, indent, '', 0, create_func, destroy_func, destroy_array, True)
770 param_post_code += create_ndo_code
771 if destroy_ndo_code:
772 if destroy_array == True:
773 param_post_code += destroy_ndo_code
774 else:
775 param_pre_code += destroy_ndo_code
776 if param_pre_code:
777 if (not destroy_func) or (destroy_array):
778 param_pre_code = '%s{\n%s%s%s%s}\n' % (' ', indent, self.lock_guard(indent), param_pre_code, indent)
779 return paramdecl, param_pre_code, param_post_code
780 #
781 # Capture command parameter info needed to wrap NDOs as well as handling some boilerplate code
782 def genCmd(self, cmdinfo, cmdname):
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600783
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600784 # Add struct-member type information to command parameter information
785 OutputGenerator.genCmd(self, cmdinfo, cmdname)
786 members = cmdinfo.elem.findall('.//param')
787 # Iterate over members once to get length parameters for arrays
788 lens = set()
789 for member in members:
790 len = self.getLen(member)
791 if len:
792 lens.add(len)
793 struct_member_dict = dict(self.structMembers)
794 # Generate member info
795 membersInfo = []
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600796 constains_extension_structs = False
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600797 for member in members:
798 # Get type and name of member
799 info = self.getTypeNameTuple(member)
800 type = info[0]
801 name = info[1]
802 cdecl = self.makeCParamDecl(member, 0)
803 # Check for parameter name in lens set
804 iscount = True if name in lens else False
805 len = self.getLen(member)
806 isconst = True if 'const' in cdecl else False
807 ispointer = self.paramIsPointer(member)
808 # Mark param as local if it is an array of NDOs
809 islocal = False;
810 if self.isHandleTypeNonDispatchable(type) == True:
811 if (len is not None) and (isconst == True):
812 islocal = True
813 # Or if it's a struct that contains an NDO
814 elif type in struct_member_dict:
815 if self.struct_contains_ndo(type) == True:
816 islocal = True
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600817 isdestroy = True if True in [destroy_txt in cmdname for destroy_txt in ['Destroy', 'Free']] else False
Mark Young39389872017-01-19 21:10:49 -0700818 iscreate = True if True in [create_txt in cmdname for create_txt in ['Create', 'Allocate', 'GetRandROutputDisplayEXT', 'RegisterDeviceEvent', 'RegisterDisplayEvent']] else False
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600819 extstructs = member.attrib.get('validextensionstructs') if name == 'pNext' else None
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600820 membersInfo.append(self.CommandParam(type=type,
821 name=name,
822 ispointer=ispointer,
823 isconst=isconst,
824 iscount=iscount,
825 len=len,
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600826 extstructs=extstructs,
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600827 cdecl=cdecl,
828 islocal=islocal,
829 iscreate=iscreate,
Mark Lobodzinski85904632017-04-06 10:07:42 -0600830 isdestroy=isdestroy,
831 feature_protect=self.featureExtraProtect))
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600832 self.cmdMembers.append(self.CmdMemberData(name=cmdname, members=membersInfo))
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600833 self.cmd_info_data.append(self.CmdInfoData(name=cmdname, cmdinfo=cmdinfo))
834 self.cmd_feature_protect.append(self.CmdExtraProtect(name=cmdname, extra_protect=self.featureExtraProtect))
835 #
836 # Create code to wrap NDOs as well as handling some boilerplate code
837 def WrapCommands(self):
Mark Lobodzinskia509c292016-10-11 14:33:07 -0600838 cmd_member_dict = dict(self.cmdMembers)
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600839 cmd_info_dict = dict(self.cmd_info_data)
840 cmd_protect_dict = dict(self.cmd_feature_protect)
841
842 for api_call in self.cmdMembers:
843 cmdname = api_call.name
844 cmdinfo = cmd_info_dict[api_call.name]
845 if cmdname in self.interface_functions:
846 continue
847 if cmdname in self.no_autogen_list:
848 decls = self.makeCDecls(cmdinfo.elem)
849 self.appendSection('command', '')
850 self.appendSection('command', '// Declare only')
851 self.appendSection('command', decls[0])
852 self.intercepts += [ ' {"%s", reinterpret_cast<PFN_vkVoidFunction>(%s)},' % (cmdname,cmdname[2:]) ]
853 continue
854 # Generate NDO wrapping/unwrapping code for all parameters
855 (api_decls, api_pre, api_post) = self.generate_wrapping_code(cmdinfo.elem)
856 # If API doesn't contain an NDO's, don't fool with it
857 if not api_decls and not api_pre and not api_post:
858 continue
859 feature_extra_protect = cmd_protect_dict[api_call.name]
860 if (feature_extra_protect != None):
861 self.appendSection('command', '')
862 self.appendSection('command', '#ifdef '+ feature_extra_protect)
863 self.intercepts += [ '#ifdef %s' % feature_extra_protect ]
864 # Add intercept to procmap
865 self.intercepts += [ ' {"%s", reinterpret_cast<PFN_vkVoidFunction>(%s)},' % (cmdname,cmdname[2:]) ]
866 decls = self.makeCDecls(cmdinfo.elem)
867 self.appendSection('command', '')
868 self.appendSection('command', decls[0][:-1])
869 self.appendSection('command', '{')
870 # Setup common to call wrappers, first parameter is always dispatchable
871 dispatchable_type = cmdinfo.elem.find('param/type').text
872 dispatchable_name = cmdinfo.elem.find('param/name').text
873 # Generate local instance/pdev/device data lookup
Chris Forbes5279a8c2017-05-02 16:26:23 -0700874 if dispatchable_type in ["VkPhysicalDevice", "VkInstance"]:
875 self.appendSection('command', ' instance_layer_data *dev_data = GetLayerDataPtr(get_dispatch_key('+dispatchable_name+'), instance_layer_data_map);')
876 else:
877 self.appendSection('command', ' layer_data *dev_data = GetLayerDataPtr(get_dispatch_key('+dispatchable_name+'), layer_data_map);')
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600878 # Handle return values, if any
879 resulttype = cmdinfo.elem.find('proto/type')
880 if (resulttype != None and resulttype.text == 'void'):
881 resulttype = None
882 if (resulttype != None):
883 assignresult = resulttype.text + ' result = '
884 else:
885 assignresult = ''
886 # Pre-pend declarations and pre-api-call codegen
887 if api_decls:
888 self.appendSection('command', "\n".join(str(api_decls).rstrip().split("\n")))
889 if api_pre:
890 self.appendSection('command', "\n".join(str(api_pre).rstrip().split("\n")))
891 # Generate the API call itself
892 # Gather the parameter items
893 params = cmdinfo.elem.findall('param/name')
894 # Pull out the text for each of the parameters, separate them by commas in a list
895 paramstext = ', '.join([str(param.text) for param in params])
896 # If any of these paramters has been replaced by a local var, fix up the list
897 params = cmd_member_dict[cmdname]
898 for param in params:
Mark Lobodzinskifbd4d182017-04-07 15:31:35 -0600899 if param.islocal == True or self.StructWithExtensions(param.type):
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600900 if param.ispointer == True:
901 paramstext = paramstext.replace(param.name, '(%s %s*)local_%s' % ('const', param.type, param.name))
902 else:
903 paramstext = paramstext.replace(param.name, '(%s %s)local_%s' % ('const', param.type, param.name))
904 # Use correct dispatch table
Chris Forbes44c05302017-05-02 16:42:55 -0700905 API = cmdinfo.elem.attrib.get('name').replace('vk','dev_data->dispatch_table.',1)
Mark Lobodzinski65c6cfa2017-04-06 15:22:07 -0600906 # Put all this together for the final down-chain call
907 self.appendSection('command', ' ' + assignresult + API + '(' + paramstext + ');')
908 # And add the post-API-call codegen
909 self.appendSection('command', "\n".join(str(api_post).rstrip().split("\n")))
910 # Handle the return result variable, if any
911 if (resulttype != None):
912 self.appendSection('command', ' return result;')
913 self.appendSection('command', '}')
914 if (feature_extra_protect != None):
915 self.appendSection('command', '#endif // '+ feature_extra_protect)
916 self.intercepts += [ '#endif' ]