blob: 9e0a3750940ccb3befb483de061a23fcd46a3548 [file] [log] [blame]
Mark Lobodzinskid1461482017-07-18 13:56:09 -06001#!/usr/bin/python3 -i
2#
3# Copyright (c) 2015-2017 The Khronos Group Inc.
4# Copyright (c) 2015-2017 Valve Corporation
5# Copyright (c) 2015-2017 LunarG, Inc.
6# Copyright (c) 2015-2017 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: Mark Lobodzinski <mark@lunarg.com>
21
22import os,re,sys,string
23import xml.etree.ElementTree as etree
24from generator import *
25from collections import namedtuple
26from vuid_mapping import *
Mark Lobodzinski62f71562017-10-24 13:41:18 -060027from common_codegen import *
Mark Lobodzinskid1461482017-07-18 13:56:09 -060028
Jamie Madill8d4cda22017-11-08 13:40:09 -050029# This is a workaround to use a Python 2.7 and 3.x compatible syntax.
30from io import open
31
Mark Lobodzinskid1461482017-07-18 13:56:09 -060032# ObjectTrackerGeneratorOptions - subclass of GeneratorOptions.
33#
34# Adds options used by ObjectTrackerOutputGenerator objects during
35# object_tracker layer generation.
36#
37# Additional members
38# prefixText - list of strings to prefix generated header with
39# (usually a copyright statement + calling convention macros).
40# protectFile - True if multiple inclusion protection should be
41# generated (based on the filename) around the entire header.
42# protectFeature - True if #ifndef..#endif protection should be
43# generated around a feature interface in the header file.
44# genFuncPointers - True if function pointer typedefs should be
45# generated
46# protectProto - If conditional protection should be generated
47# around prototype declarations, set to either '#ifdef'
48# to require opt-in (#ifdef protectProtoStr) or '#ifndef'
49# to require opt-out (#ifndef protectProtoStr). Otherwise
50# set to None.
51# protectProtoStr - #ifdef/#ifndef symbol to use around prototype
52# declarations, if protectProto is set
53# apicall - string to use for the function declaration prefix,
54# such as APICALL on Windows.
55# apientry - string to use for the calling convention macro,
56# in typedefs, such as APIENTRY.
57# apientryp - string to use for the calling convention macro
58# in function pointer typedefs, such as APIENTRYP.
59# indentFuncProto - True if prototype declarations should put each
60# parameter on a separate line
61# indentFuncPointer - True if typedefed function pointers should put each
62# parameter on a separate line
63# alignFuncParam - if nonzero and parameters are being put on a
64# separate line, align parameter names at the specified column
65class ObjectTrackerGeneratorOptions(GeneratorOptions):
66 def __init__(self,
67 filename = None,
68 directory = '.',
69 apiname = None,
70 profile = None,
71 versions = '.*',
72 emitversions = '.*',
73 defaultExtensions = None,
74 addExtensions = None,
75 removeExtensions = None,
Mark Lobodzinski62f71562017-10-24 13:41:18 -060076 emitExtensions = None,
Mark Lobodzinskid1461482017-07-18 13:56:09 -060077 sortProcedure = regSortFeatures,
78 prefixText = "",
79 genFuncPointers = True,
80 protectFile = True,
81 protectFeature = True,
Mark Lobodzinskid1461482017-07-18 13:56:09 -060082 apicall = '',
83 apientry = '',
84 apientryp = '',
85 indentFuncProto = True,
86 indentFuncPointer = False,
Mark Lobodzinski62f71562017-10-24 13:41:18 -060087 alignFuncParam = 0,
88 expandEnumerants = True):
Mark Lobodzinskid1461482017-07-18 13:56:09 -060089 GeneratorOptions.__init__(self, filename, directory, apiname, profile,
90 versions, emitversions, defaultExtensions,
Mark Lobodzinski62f71562017-10-24 13:41:18 -060091 addExtensions, removeExtensions, emitExtensions, sortProcedure)
Mark Lobodzinskid1461482017-07-18 13:56:09 -060092 self.prefixText = prefixText
93 self.genFuncPointers = genFuncPointers
94 self.protectFile = protectFile
95 self.protectFeature = protectFeature
Mark Lobodzinskid1461482017-07-18 13:56:09 -060096 self.apicall = apicall
97 self.apientry = apientry
98 self.apientryp = apientryp
99 self.indentFuncProto = indentFuncProto
100 self.indentFuncPointer = indentFuncPointer
101 self.alignFuncParam = alignFuncParam
Mark Lobodzinski62f71562017-10-24 13:41:18 -0600102 self.expandEnumerants = expandEnumerants
103
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600104
105# ObjectTrackerOutputGenerator - subclass of OutputGenerator.
106# Generates object_tracker layer object validation code
107#
108# ---- methods ----
109# ObjectTrackerOutputGenerator(errFile, warnFile, diagFile) - args as for OutputGenerator. Defines additional internal state.
110# ---- methods overriding base class ----
111# beginFile(genOpts)
112# endFile()
113# beginFeature(interface, emit)
114# endFeature()
115# genCmd(cmdinfo)
116# genStruct()
117# genType()
118class ObjectTrackerOutputGenerator(OutputGenerator):
119 """Generate ObjectTracker code based on XML element attributes"""
120 # This is an ordered list of sections in the header file.
121 ALL_SECTIONS = ['command']
122 def __init__(self,
123 errFile = sys.stderr,
124 warnFile = sys.stderr,
125 diagFile = sys.stdout):
126 OutputGenerator.__init__(self, errFile, warnFile, diagFile)
127 self.INDENT_SPACES = 4
128 self.intercepts = []
129 self.instance_extensions = []
130 self.device_extensions = []
131 # Commands which are not autogenerated but still intercepted
132 self.no_autogen_list = [
133 'vkDestroyInstance',
134 'vkDestroyDevice',
135 'vkUpdateDescriptorSets',
136 'vkDestroyDebugReportCallbackEXT',
137 'vkDebugReportMessageEXT',
138 'vkGetPhysicalDeviceQueueFamilyProperties',
139 'vkFreeCommandBuffers',
140 'vkDestroySwapchainKHR',
141 'vkDestroyDescriptorPool',
142 'vkDestroyCommandPool',
Mark Lobodzinski14ddc192017-10-25 16:57:04 -0600143 'vkGetPhysicalDeviceQueueFamilyProperties2',
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600144 'vkGetPhysicalDeviceQueueFamilyProperties2KHR',
145 'vkResetDescriptorPool',
146 'vkBeginCommandBuffer',
147 'vkCreateDebugReportCallbackEXT',
148 'vkEnumerateInstanceLayerProperties',
149 'vkEnumerateDeviceLayerProperties',
150 'vkEnumerateInstanceExtensionProperties',
151 'vkEnumerateDeviceExtensionProperties',
152 'vkCreateDevice',
153 'vkCreateInstance',
154 'vkEnumeratePhysicalDevices',
155 'vkAllocateCommandBuffers',
156 'vkAllocateDescriptorSets',
157 'vkFreeDescriptorSets',
Tony Barbour2fd0c2c2017-08-08 12:51:33 -0600158 'vkCmdPushDescriptorSetKHR',
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600159 'vkDebugMarkerSetObjectNameEXT',
160 'vkGetPhysicalDeviceProcAddr',
161 'vkGetDeviceProcAddr',
162 'vkGetInstanceProcAddr',
163 'vkEnumerateInstanceExtensionProperties',
164 'vkEnumerateInstanceLayerProperties',
165 'vkEnumerateDeviceLayerProperties',
166 'vkGetDeviceProcAddr',
167 'vkGetInstanceProcAddr',
168 'vkEnumerateDeviceExtensionProperties',
169 'vk_layerGetPhysicalDeviceProcAddr',
170 'vkNegotiateLoaderLayerInterfaceVersion',
171 'vkCreateComputePipelines',
172 'vkGetDeviceQueue',
Yiwei Zhang991d88d2018-02-14 14:39:46 -0800173 'vkGetDeviceQueue2',
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600174 'vkGetSwapchainImagesKHR',
Petr Kraus42f6f8d2017-12-17 17:37:33 +0100175 'vkCreateDescriptorSetLayout',
Mark Young6ba8abe2017-11-09 10:37:04 -0700176 'vkCreateDebugUtilsMessengerEXT',
177 'vkDestroyDebugUtilsMessengerEXT',
178 'vkSubmitDebugUtilsMessageEXT',
179 'vkSetDebugUtilsObjectNameEXT',
180 'vkSetDebugUtilsObjectTagEXT',
181 'vkQueueBeginDebugUtilsLabelEXT',
182 'vkQueueEndDebugUtilsLabelEXT',
183 'vkQueueInsertDebugUtilsLabelEXT',
184 'vkCmdBeginDebugUtilsLabelEXT',
185 'vkCmdEndDebugUtilsLabelEXT',
186 'vkCmdInsertDebugUtilsLabelEXT',
Shannon McPherson9d5167f2018-05-02 15:24:37 -0600187 'vkGetDisplayModePropertiesKHR',
188 'vkGetPhysicalDeviceDisplayPropertiesKHR',
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600189 ]
190 # These VUIDS are not implicit, but are best handled in this layer. Codegen for vkDestroy calls will generate a key
191 # which is translated here into a good VU. Saves ~40 checks.
192 self.manual_vuids = dict()
193 self.manual_vuids = {
194 "fence-compatalloc": "VALIDATION_ERROR_24e008c2",
195 "fence-nullalloc": "VALIDATION_ERROR_24e008c4",
196 "event-compatalloc": "VALIDATION_ERROR_24c008f4",
197 "event-nullalloc": "VALIDATION_ERROR_24c008f6",
198 "buffer-compatalloc": "VALIDATION_ERROR_23c00736",
199 "buffer-nullalloc": "VALIDATION_ERROR_23c00738",
200 "image-compatalloc": "VALIDATION_ERROR_252007d2",
201 "image-nullalloc": "VALIDATION_ERROR_252007d4",
202 "shaderModule-compatalloc": "VALIDATION_ERROR_26a00888",
203 "shaderModule-nullalloc": "VALIDATION_ERROR_26a0088a",
204 "pipeline-compatalloc": "VALIDATION_ERROR_25c005fc",
205 "pipeline-nullalloc": "VALIDATION_ERROR_25c005fe",
206 "sampler-compatalloc": "VALIDATION_ERROR_26600876",
207 "sampler-nullalloc": "VALIDATION_ERROR_26600878",
208 "renderPass-compatalloc": "VALIDATION_ERROR_264006d4",
209 "renderPass-nullalloc": "VALIDATION_ERROR_264006d6",
210 "descriptorUpdateTemplate-compatalloc": "VALIDATION_ERROR_248002c8",
211 "descriptorUpdateTemplate-nullalloc": "VALIDATION_ERROR_248002ca",
212 "imageView-compatalloc": "VALIDATION_ERROR_25400806",
213 "imageView-nullalloc": "VALIDATION_ERROR_25400808",
214 "pipelineCache-compatalloc": "VALIDATION_ERROR_25e00606",
215 "pipelineCache-nullalloc": "VALIDATION_ERROR_25e00608",
216 "pipelineLayout-compatalloc": "VALIDATION_ERROR_26000256",
217 "pipelineLayout-nullalloc": "VALIDATION_ERROR_26000258",
218 "descriptorSetLayout-compatalloc": "VALIDATION_ERROR_24600238",
219 "descriptorSetLayout-nullalloc": "VALIDATION_ERROR_2460023a",
220 "semaphore-compatalloc": "VALIDATION_ERROR_268008e4",
221 "semaphore-nullalloc": "VALIDATION_ERROR_268008e6",
222 "queryPool-compatalloc": "VALIDATION_ERROR_26200634",
223 "queryPool-nullalloc": "VALIDATION_ERROR_26200636",
224 "bufferView-compatalloc": "VALIDATION_ERROR_23e00752",
225 "bufferView-nullalloc": "VALIDATION_ERROR_23e00754",
226 "surface-compatalloc": "VALIDATION_ERROR_26c009e6",
227 "surface-nullalloc": "VALIDATION_ERROR_26c009e8",
228 "framebuffer-compatalloc": "VALIDATION_ERROR_250006fa",
229 "framebuffer-nullalloc": "VALIDATION_ERROR_250006fc",
230 }
231
232 # Commands shadowed by interface functions and are not implemented
233 self.interface_functions = [
234 ]
235 self.headerVersion = None
236 # Internal state - accumulators for different inner block text
237 self.sections = dict([(section, []) for section in self.ALL_SECTIONS])
238 self.cmdMembers = []
239 self.cmd_feature_protect = [] # Save ifdef's for each command
240 self.cmd_info_data = [] # Save the cmdinfo data for validating the handles when processing is complete
241 self.structMembers = [] # List of StructMemberData records for all Vulkan structs
242 self.extension_structs = [] # List of all structs or sister-structs containing handles
243 # A sister-struct may contain no handles but shares <validextensionstructs> with one that does
244 self.structTypes = dict() # Map of Vulkan struct typename to required VkStructureType
245 self.struct_member_dict = dict()
246 # Named tuples to store struct and command data
247 self.StructType = namedtuple('StructType', ['name', 'value'])
248 self.CmdMemberData = namedtuple('CmdMemberData', ['name', 'members'])
249 self.CmdInfoData = namedtuple('CmdInfoData', ['name', 'cmdinfo'])
250 self.CmdExtraProtect = namedtuple('CmdExtraProtect', ['name', 'extra_protect'])
251 self.CommandParam = namedtuple('CommandParam', ['type', 'name', 'ispointer', 'isconst', 'isoptional', 'iscount', 'len', 'extstructs', 'cdecl', 'islocal', 'iscreate', 'isdestroy', 'feature_protect'])
252 self.StructMemberData = namedtuple('StructMemberData', ['name', 'members'])
253 self.object_types = [] # List of all handle types
254 self.valid_vuids = set() # Set of all valid VUIDs
255 self.vuid_file = None
256 # Cover cases where file is built from scripts directory, Lin/Win, or Android build structure
Jamie Madillc47ddf92017-12-20 14:45:11 -0500257 # Set cwd to the script directory to more easily locate the header.
258 previous_dir = os.getcwd()
259 os.chdir(os.path.dirname(sys.argv[0]))
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600260 vuid_filename_locations = [
261 './vk_validation_error_messages.h',
262 '../layers/vk_validation_error_messages.h',
263 '../../layers/vk_validation_error_messages.h',
264 '../../../layers/vk_validation_error_messages.h',
265 ]
266 for vuid_filename in vuid_filename_locations:
267 if os.path.isfile(vuid_filename):
Lenny Komowb79f04a2017-09-18 17:07:00 -0600268 self.vuid_file = open(vuid_filename, "r", encoding="utf8")
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600269 break
270 if self.vuid_file == None:
271 print("Error: Could not find vk_validation_error_messages.h")
Jamie Madill3935f7c2017-11-08 13:50:14 -0500272 sys.exit(1)
Jamie Madillc47ddf92017-12-20 14:45:11 -0500273 os.chdir(previous_dir)
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600274 #
275 # Check if the parameter passed in is optional
276 def paramIsOptional(self, param):
277 # See if the handle is optional
278 isoptional = False
279 # Simple, if it's optional, return true
280 optString = param.attrib.get('optional')
281 if optString:
282 if optString == 'true':
283 isoptional = True
284 elif ',' in optString:
285 opts = []
286 for opt in optString.split(','):
287 val = opt.strip()
288 if val == 'true':
289 opts.append(True)
290 elif val == 'false':
291 opts.append(False)
292 else:
293 print('Unrecognized len attribute value',val)
294 isoptional = opts
John Zulauf9f6788c2018-04-04 14:54:11 -0600295 if not isoptional:
296 # Matching logic in parameter validation and ValidityOutputGenerator.isHandleOptional
297 optString = param.attrib.get('noautovalidity')
298 if optString and optString == 'true':
299 isoptional = True;
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600300 return isoptional
301 #
302 # Convert decimal number to 8 digit hexadecimal lower-case representation
303 def IdToHex(self, dec_num):
304 if dec_num > 4294967295:
305 print ("ERROR: Decimal # %d can't be represented in 8 hex digits" % (dec_num))
306 sys.exit()
307 hex_num = hex(dec_num)
308 return hex_num[2:].zfill(8)
309 #
310 # Get VUID identifier from implicit VUID tag
311 def GetVuid(self, vuid_string):
312 if '->' in vuid_string:
313 return "VALIDATION_ERROR_UNDEFINED"
314 vuid_num = self.IdToHex(convertVUID(vuid_string))
315 if vuid_num in self.valid_vuids:
316 vuid = "VALIDATION_ERROR_%s" % vuid_num
317 else:
318 vuid = "VALIDATION_ERROR_UNDEFINED"
319 return vuid
320 #
321 # Increases indent by 4 spaces and tracks it globally
322 def incIndent(self, indent):
323 inc = ' ' * self.INDENT_SPACES
324 if indent:
325 return indent + inc
326 return inc
327 #
328 # Decreases indent by 4 spaces and tracks it globally
329 def decIndent(self, indent):
330 if indent and (len(indent) > self.INDENT_SPACES):
331 return indent[:-self.INDENT_SPACES]
332 return ''
333 #
334 # Override makeProtoName to drop the "vk" prefix
335 def makeProtoName(self, name, tail):
336 return self.genOpts.apientry + name[2:] + tail
337 #
338 # Check if the parameter passed in is a pointer to an array
339 def paramIsArray(self, param):
340 return param.attrib.get('len') is not None
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000341
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600342 #
343 # Generate the object tracker undestroyed object validation function
344 def GenReportFunc(self):
345 output_func = ''
346 output_func += 'void ReportUndestroyedObjects(VkDevice device, enum UNIQUE_VALIDATION_ERROR_CODE error_code) {\n'
347 output_func += ' DeviceReportUndestroyedObjects(device, kVulkanObjectTypeCommandBuffer, error_code);\n'
348 for handle in self.object_types:
349 if self.isHandleTypeNonDispatchable(handle):
350 output_func += ' DeviceReportUndestroyedObjects(device, %s, error_code);\n' % (self.GetVulkanObjType(handle))
351 output_func += '}\n'
352 return output_func
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000353
354 #
355 # Generate the object tracker undestroyed object destruction function
356 def GenDestroyFunc(self):
357 output_func = ''
358 output_func += 'void DestroyUndestroyedObjects(VkDevice device) {\n'
359 output_func += ' DeviceDestroyUndestroyedObjects(device, kVulkanObjectTypeCommandBuffer);\n'
360 for handle in self.object_types:
361 if self.isHandleTypeNonDispatchable(handle):
362 output_func += ' DeviceDestroyUndestroyedObjects(device, %s);\n' % (self.GetVulkanObjType(handle))
363 output_func += '}\n'
364 return output_func
365
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600366 #
367 # Called at beginning of processing as file is opened
368 def beginFile(self, genOpts):
369 OutputGenerator.beginFile(self, genOpts)
370 # Open vk_validation_error_messages.h file to verify computed VUIDs
371 for line in self.vuid_file:
372 # Grab hex number from enum definition
373 vuid_list = line.split('0x')
374 # If this is a valid enumeration line, remove trailing comma and CR
375 if len(vuid_list) == 2:
376 vuid_num = vuid_list[1][:-2]
377 # Make sure this is a good hex number before adding to set
378 if len(vuid_num) == 8 and all(c in string.hexdigits for c in vuid_num):
379 self.valid_vuids.add(vuid_num)
380 # File Comment
381 file_comment = '// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n'
382 file_comment += '// See object_tracker_generator.py for modifications\n'
383 write(file_comment, file=self.outFile)
384 # Copyright Statement
385 copyright = ''
386 copyright += '\n'
387 copyright += '/***************************************************************************\n'
388 copyright += ' *\n'
389 copyright += ' * Copyright (c) 2015-2017 The Khronos Group Inc.\n'
390 copyright += ' * Copyright (c) 2015-2017 Valve Corporation\n'
391 copyright += ' * Copyright (c) 2015-2017 LunarG, Inc.\n'
392 copyright += ' * Copyright (c) 2015-2017 Google Inc.\n'
393 copyright += ' *\n'
394 copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n'
395 copyright += ' * you may not use this file except in compliance with the License.\n'
396 copyright += ' * You may obtain a copy of the License at\n'
397 copyright += ' *\n'
398 copyright += ' * http://www.apache.org/licenses/LICENSE-2.0\n'
399 copyright += ' *\n'
400 copyright += ' * Unless required by applicable law or agreed to in writing, software\n'
401 copyright += ' * distributed under the License is distributed on an "AS IS" BASIS,\n'
402 copyright += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
403 copyright += ' * See the License for the specific language governing permissions and\n'
404 copyright += ' * limitations under the License.\n'
405 copyright += ' *\n'
406 copyright += ' * Author: Mark Lobodzinski <mark@lunarg.com>\n'
407 copyright += ' *\n'
408 copyright += ' ****************************************************************************/\n'
409 write(copyright, file=self.outFile)
410 # Namespace
411 self.newline()
412 write('#include "object_tracker.h"', file = self.outFile)
413 self.newline()
414 write('namespace object_tracker {', file = self.outFile)
415 #
416 # Now that the data is all collected and complete, generate and output the object validation routines
417 def endFile(self):
418 self.struct_member_dict = dict(self.structMembers)
419 # Generate the list of APIs that might need to handle wrapped extension structs
420 # self.GenerateCommandWrapExtensionList()
421 self.WrapCommands()
422 # Build undestroyed objects reporting function
423 report_func = self.GenReportFunc()
424 self.newline()
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000425 # Build undestroyed objects destruction function
426 destroy_func = self.GenDestroyFunc()
427 self.newline()
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600428 write('// ObjectTracker undestroyed objects validation function', file=self.outFile)
429 write('%s' % report_func, file=self.outFile)
Gabríel Arthúr Péturssonfdcb5402018-03-20 21:52:06 +0000430 write('%s' % destroy_func, file=self.outFile)
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600431 # Actually write the interface to the output file.
432 if (self.emit):
433 self.newline()
434 if (self.featureExtraProtect != None):
435 write('#ifdef', self.featureExtraProtect, file=self.outFile)
436 # Write the object_tracker code to the file
437 if (self.sections['command']):
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600438 write('\n'.join(self.sections['command']), end=u'', file=self.outFile)
439 if (self.featureExtraProtect != None):
440 write('\n#endif //', self.featureExtraProtect, file=self.outFile)
441 else:
442 self.newline()
443
444 # Record intercepted procedures
445 write('// Map of all APIs to be intercepted by this layer', file=self.outFile)
446 write('const std::unordered_map<std::string, void*> name_to_funcptr_map = {', file=self.outFile)
447 write('\n'.join(self.intercepts), file=self.outFile)
448 write('};\n', file=self.outFile)
449 self.newline()
450 write('} // namespace object_tracker', file=self.outFile)
451 # Finish processing in superclass
452 OutputGenerator.endFile(self)
453 #
454 # Processing point at beginning of each extension definition
455 def beginFeature(self, interface, emit):
456 # Start processing in superclass
457 OutputGenerator.beginFeature(self, interface, emit)
458 self.headerVersion = None
Mark Lobodzinski62f71562017-10-24 13:41:18 -0600459 self.featureExtraProtect = GetFeatureProtect(interface)
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600460
Mark Lobodzinski31964ca2017-09-18 14:15:09 -0600461 if self.featureName != 'VK_VERSION_1_0' and self.featureName != 'VK_VERSION_1_1':
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600462 white_list_entry = []
463 if (self.featureExtraProtect != None):
464 white_list_entry += [ '#ifdef %s' % self.featureExtraProtect ]
465 white_list_entry += [ '"%s"' % self.featureName ]
466 if (self.featureExtraProtect != None):
467 white_list_entry += [ '#endif' ]
468 featureType = interface.get('type')
469 if featureType == 'instance':
470 self.instance_extensions += white_list_entry
471 elif featureType == 'device':
472 self.device_extensions += white_list_entry
473 #
474 # Processing point at end of each extension definition
475 def endFeature(self):
476 # Finish processing in superclass
477 OutputGenerator.endFeature(self)
478 #
479 # Process enums, structs, etc.
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700480 def genType(self, typeinfo, name, alias):
481 OutputGenerator.genType(self, typeinfo, name, alias)
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600482 typeElem = typeinfo.elem
483 # If the type is a struct type, traverse the imbedded <member> tags generating a structure.
484 # Otherwise, emit the tag text.
485 category = typeElem.get('category')
486 if (category == 'struct' or category == 'union'):
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700487 self.genStruct(typeinfo, name, alias)
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600488 if category == 'handle':
489 self.object_types.append(name)
490 #
491 # Append a definition to the specified section
492 def appendSection(self, section, text):
493 # self.sections[section].append('SECTION: ' + section + '\n')
494 self.sections[section].append(text)
495 #
496 # Check if the parameter passed in is a pointer
497 def paramIsPointer(self, param):
498 ispointer = False
499 for elem in param:
500 if ((elem.tag is not 'type') and (elem.tail is not None)) and '*' in elem.tail:
501 ispointer = True
502 return ispointer
503 #
504 # Get the category of a type
505 def getTypeCategory(self, typename):
506 types = self.registry.tree.findall("types/type")
507 for elem in types:
508 if (elem.find("name") is not None and elem.find('name').text == typename) or elem.attrib.get('name') == typename:
509 return elem.attrib.get('category')
510 #
511 # Check if a parent object is dispatchable or not
512 def isHandleTypeObject(self, handletype):
513 handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']")
514 if handle is not None:
515 return True
516 else:
517 return False
518 #
519 # Check if a parent object is dispatchable or not
520 def isHandleTypeNonDispatchable(self, handletype):
521 handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']")
522 if handle is not None and handle.find('type').text == 'VK_DEFINE_NON_DISPATCHABLE_HANDLE':
523 return True
524 else:
525 return False
526 #
527 # Retrieve the type and name for a parameter
528 def getTypeNameTuple(self, param):
529 type = ''
530 name = ''
531 for elem in param:
532 if elem.tag == 'type':
533 type = noneStr(elem.text)
534 elif elem.tag == 'name':
535 name = noneStr(elem.text)
536 return (type, name)
537 #
538 # Retrieve the value of the len tag
539 def getLen(self, param):
540 result = None
541 len = param.attrib.get('len')
542 if len and len != 'null-terminated':
543 # For string arrays, 'len' can look like 'count,null-terminated', indicating that we
544 # have a null terminated array of strings. We strip the null-terminated from the
545 # 'len' field and only return the parameter specifying the string count
546 if 'null-terminated' in len:
547 result = len.split(',')[0]
548 else:
549 result = len
550 # Spec has now notation for len attributes, using :: instead of platform specific pointer symbol
551 result = str(result).replace('::', '->')
552 return result
553 #
554 # Generate a VkStructureType based on a structure typename
555 def genVkStructureType(self, typename):
556 # Add underscore between lowercase then uppercase
557 value = re.sub('([a-z0-9])([A-Z])', r'\1_\2', typename)
558 # Change to uppercase
559 value = value.upper()
560 # Add STRUCTURE_TYPE_
561 return re.sub('VK_', 'VK_STRUCTURE_TYPE_', value)
562 #
563 # Struct parameter check generation.
564 # This is a special case of the <type> tag where the contents are interpreted as a set of
565 # <member> tags instead of freeform C type declarations. The <member> tags are just like
566 # <param> tags - they are a declaration of a struct or union member. Only simple member
567 # declarations are supported (no nested structs etc.)
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700568 def genStruct(self, typeinfo, typeName, alias):
569 OutputGenerator.genStruct(self, typeinfo, typeName, alias)
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600570 members = typeinfo.elem.findall('.//member')
571 # Iterate over members once to get length parameters for arrays
572 lens = set()
573 for member in members:
574 len = self.getLen(member)
575 if len:
576 lens.add(len)
577 # Generate member info
578 membersInfo = []
579 for member in members:
580 # Get the member's type and name
581 info = self.getTypeNameTuple(member)
582 type = info[0]
583 name = info[1]
584 cdecl = self.makeCParamDecl(member, 0)
585 # Process VkStructureType
586 if type == 'VkStructureType':
587 # Extract the required struct type value from the comments
588 # embedded in the original text defining the 'typeinfo' element
589 rawXml = etree.tostring(typeinfo.elem).decode('ascii')
590 result = re.search(r'VK_STRUCTURE_TYPE_\w+', rawXml)
591 if result:
592 value = result.group(0)
593 else:
594 value = self.genVkStructureType(typeName)
595 # Store the required type value
596 self.structTypes[typeName] = self.StructType(name=name, value=value)
597 # Store pointer/array/string info
598 extstructs = member.attrib.get('validextensionstructs') if name == 'pNext' else None
599 membersInfo.append(self.CommandParam(type=type,
600 name=name,
601 ispointer=self.paramIsPointer(member),
602 isconst=True if 'const' in cdecl else False,
603 isoptional=self.paramIsOptional(member),
604 iscount=True if name in lens else False,
605 len=self.getLen(member),
606 extstructs=extstructs,
607 cdecl=cdecl,
608 islocal=False,
609 iscreate=False,
610 isdestroy=False,
611 feature_protect=self.featureExtraProtect))
612 self.structMembers.append(self.StructMemberData(name=typeName, members=membersInfo))
613 #
614 # Insert a lock_guard line
615 def lock_guard(self, indent):
616 return '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % indent
617 #
618 # Determine if a struct has an object as a member or an embedded member
619 def struct_contains_object(self, struct_item):
620 struct_member_dict = dict(self.structMembers)
621 struct_members = struct_member_dict[struct_item]
622
623 for member in struct_members:
624 if self.isHandleTypeObject(member.type):
625 return True
626 elif member.type in struct_member_dict:
627 if self.struct_contains_object(member.type) == True:
628 return True
629 return False
630 #
631 # Return list of struct members which contain, or whose sub-structures contain an obj in a given list of parameters or members
632 def getParmeterStructsWithObjects(self, item_list):
633 struct_list = set()
634 for item in item_list:
635 paramtype = item.find('type')
636 typecategory = self.getTypeCategory(paramtype.text)
637 if typecategory == 'struct':
638 if self.struct_contains_object(paramtype.text) == True:
639 struct_list.add(item)
640 return struct_list
641 #
642 # Return list of objects from a given list of parameters or members
643 def getObjectsInParameterList(self, item_list, create_func):
644 object_list = set()
645 if create_func == True:
646 member_list = item_list[0:-1]
647 else:
648 member_list = item_list
649 for item in member_list:
650 if self.isHandleTypeObject(paramtype.text):
651 object_list.add(item)
652 return object_list
653 #
654 # Construct list of extension structs containing handles, or extension structs that share a <validextensionstructs>
Shannon McPherson9d5167f2018-05-02 15:24:37 -0600655 # tag WITH an extension struct containing handles.
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600656 def GenerateCommandWrapExtensionList(self):
657 for struct in self.structMembers:
658 if (len(struct.members) > 1) and struct.members[1].extstructs is not None:
659 found = False;
660 for item in struct.members[1].extstructs.split(','):
661 if item != '' and self.struct_contains_object(item) == True:
662 found = True
663 if found == True:
664 for item in struct.members[1].extstructs.split(','):
665 if item != '' and item not in self.extension_structs:
666 self.extension_structs.append(item)
667 #
668 # Returns True if a struct may have a pNext chain containing an object
669 def StructWithExtensions(self, struct_type):
670 if struct_type in self.struct_member_dict:
671 param_info = self.struct_member_dict[struct_type]
672 if (len(param_info) > 1) and param_info[1].extstructs is not None:
673 for item in param_info[1].extstructs.split(','):
674 if item in self.extension_structs:
675 return True
676 return False
677 #
678 # Generate VulkanObjectType from object type
679 def GetVulkanObjType(self, type):
680 return 'kVulkanObjectType%s' % type[2:]
681 #
682 # Return correct dispatch table type -- instance or device
683 def GetDispType(self, type):
684 return 'instance' if type in ['VkInstance', 'VkPhysicalDevice'] else 'device'
685 #
686 # Generate source for creating a Vulkan object
687 def generate_create_object_code(self, indent, proto, params, cmd_info):
688 create_obj_code = ''
689 handle_type = params[-1].find('type')
690 if self.isHandleTypeObject(handle_type.text):
691 # Check for special case where multiple handles are returned
692 object_array = False
693 if cmd_info[-1].len is not None:
694 object_array = True;
695 handle_name = params[-1].find('name')
696 create_obj_code += '%sif (VK_SUCCESS == result) {\n' % (indent)
697 indent = self.incIndent(indent)
698 create_obj_code += '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % (indent)
699 object_dest = '*%s' % handle_name.text
700 if object_array == True:
701 create_obj_code += '%sfor (uint32_t index = 0; index < %s; index++) {\n' % (indent, cmd_info[-1].len)
702 indent = self.incIndent(indent)
703 object_dest = '%s[index]' % cmd_info[-1].name
704 create_obj_code += '%sCreateObject(%s, %s, %s, pAllocator);\n' % (indent, params[0].find('name').text, object_dest, self.GetVulkanObjType(cmd_info[-1].type))
705 if object_array == True:
706 indent = self.decIndent(indent)
707 create_obj_code += '%s}\n' % indent
708 indent = self.decIndent(indent)
709 create_obj_code += '%s}\n' % (indent)
710 return create_obj_code
711 #
712 # Generate source for destroying a non-dispatchable object
713 def generate_destroy_object_code(self, indent, proto, cmd_info):
714 destroy_obj_code = ''
715 object_array = False
716 if True in [destroy_txt in proto.text for destroy_txt in ['Destroy', 'Free']]:
717 # Check for special case where multiple handles are returned
718 if cmd_info[-1].len is not None:
719 object_array = True;
720 param = -1
721 else:
722 param = -2
723 compatalloc_vuid_string = '%s-compatalloc' % cmd_info[param].name
724 nullalloc_vuid_string = '%s-nullalloc' % cmd_info[param].name
725 compatalloc_vuid = self.manual_vuids.get(compatalloc_vuid_string, "VALIDATION_ERROR_UNDEFINED")
726 nullalloc_vuid = self.manual_vuids.get(nullalloc_vuid_string, "VALIDATION_ERROR_UNDEFINED")
727 if self.isHandleTypeObject(cmd_info[param].type) == True:
728 if object_array == True:
729 # This API is freeing an array of handles -- add loop control
730 destroy_obj_code += 'HEY, NEED TO DESTROY AN ARRAY\n'
731 else:
732 # Call Destroy a single time
733 destroy_obj_code += '%sif (skip) return;\n' % indent
734 destroy_obj_code += '%s{\n' % indent
735 destroy_obj_code += '%s std::lock_guard<std::mutex> lock(global_lock);\n' % indent
736 destroy_obj_code += '%s DestroyObject(%s, %s, %s, pAllocator, %s, %s);\n' % (indent, cmd_info[0].name, cmd_info[param].name, self.GetVulkanObjType(cmd_info[param].type), compatalloc_vuid, nullalloc_vuid)
737 destroy_obj_code += '%s}\n' % indent
738 return object_array, destroy_obj_code
739 #
740 # Output validation for a single object (obj_count is NULL) or a counted list of objects
741 def outputObjects(self, obj_type, obj_name, obj_count, prefix, index, indent, destroy_func, destroy_array, disp_name, parent_name, null_allowed, top_level):
742 decl_code = ''
743 pre_call_code = ''
744 post_call_code = ''
745 param_vuid_string = 'VUID-%s-%s-parameter' % (parent_name, obj_name)
746 parent_vuid_string = 'VUID-%s-%s-parent' % (parent_name, obj_name)
747 param_vuid = self.GetVuid(param_vuid_string)
748 parent_vuid = self.GetVuid(parent_vuid_string)
749 # If no parent VUID for this member, look for a commonparent VUID
750 if parent_vuid == 'VALIDATION_ERROR_UNDEFINED':
751 commonparent_vuid_string = 'VUID-%s-commonparent' % parent_name
752 parent_vuid = self.GetVuid(commonparent_vuid_string)
753 if obj_count is not None:
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600754 pre_call_code += '%s for (uint32_t %s = 0; %s < %s; ++%s) {\n' % (indent, index, index, obj_count, index)
755 indent = self.incIndent(indent)
756 pre_call_code += '%s skip |= ValidateObject(%s, %s%s[%s], %s, %s, %s, %s);\n' % (indent, disp_name, prefix, obj_name, index, self.GetVulkanObjType(obj_type), null_allowed, param_vuid, parent_vuid)
757 indent = self.decIndent(indent)
758 pre_call_code += '%s }\n' % indent
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600759 else:
760 pre_call_code += '%s skip |= ValidateObject(%s, %s%s, %s, %s, %s, %s);\n' % (indent, disp_name, prefix, obj_name, self.GetVulkanObjType(obj_type), null_allowed, param_vuid, parent_vuid)
761 return decl_code, pre_call_code, post_call_code
762 #
763 # first_level_param indicates if elements are passed directly into the function else they're below a ptr/struct
764 # create_func means that this is API creates or allocates objects
765 # destroy_func indicates that this API destroys or frees objects
766 # destroy_array means that the destroy_func operated on an array of objects
767 def validate_objects(self, members, indent, prefix, array_index, create_func, destroy_func, destroy_array, disp_name, parent_name, first_level_param):
768 decls = ''
769 pre_code = ''
770 post_code = ''
771 index = 'index%s' % str(array_index)
772 array_index += 1
773 # Process any objects in this structure and recurse for any sub-structs in this struct
774 for member in members:
775 # Handle objects
776 if member.iscreate and first_level_param and member == members[-1]:
777 continue
778 if self.isHandleTypeObject(member.type) == True:
779 count_name = member.len
780 if (count_name is not None):
781 count_name = '%s%s' % (prefix, member.len)
782 null_allowed = member.isoptional
783 (tmp_decl, tmp_pre, tmp_post) = self.outputObjects(member.type, member.name, count_name, prefix, index, indent, destroy_func, destroy_array, disp_name, parent_name, str(null_allowed).lower(), first_level_param)
784 decls += tmp_decl
785 pre_code += tmp_pre
786 post_code += tmp_post
787 # Handle Structs that contain objects at some level
788 elif member.type in self.struct_member_dict:
789 # Structs at first level will have an object
790 if self.struct_contains_object(member.type) == True:
791 struct_info = self.struct_member_dict[member.type]
792 # Struct Array
793 if member.len is not None:
794 # Update struct prefix
795 new_prefix = '%s%s' % (prefix, member.name)
796 pre_code += '%s if (%s%s) {\n' % (indent, prefix, member.name)
797 indent = self.incIndent(indent)
798 pre_code += '%s for (uint32_t %s = 0; %s < %s%s; ++%s) {\n' % (indent, index, index, prefix, member.len, index)
799 indent = self.incIndent(indent)
800 local_prefix = '%s[%s].' % (new_prefix, index)
801 # Process sub-structs in this struct
802 (tmp_decl, tmp_pre, tmp_post) = self.validate_objects(struct_info, indent, local_prefix, array_index, create_func, destroy_func, destroy_array, disp_name, member.type, False)
803 decls += tmp_decl
804 pre_code += tmp_pre
805 post_code += tmp_post
806 indent = self.decIndent(indent)
807 pre_code += '%s }\n' % indent
808 indent = self.decIndent(indent)
809 pre_code += '%s }\n' % indent
810 # Single Struct
811 else:
812 # Update struct prefix
813 new_prefix = '%s%s->' % (prefix, member.name)
814 # Declare safe_VarType for struct
815 pre_code += '%s if (%s%s) {\n' % (indent, prefix, member.name)
816 indent = self.incIndent(indent)
817 # Process sub-structs in this struct
818 (tmp_decl, tmp_pre, tmp_post) = self.validate_objects(struct_info, indent, new_prefix, array_index, create_func, destroy_func, destroy_array, disp_name, member.type, False)
819 decls += tmp_decl
820 pre_code += tmp_pre
821 post_code += tmp_post
822 indent = self.decIndent(indent)
823 pre_code += '%s }\n' % indent
824 return decls, pre_code, post_code
825 #
826 # For a particular API, generate the object handling code
827 def generate_wrapping_code(self, cmd):
828 indent = ' '
829 proto = cmd.find('proto/name')
830 params = cmd.findall('param')
831 if proto.text is not None:
832 cmd_member_dict = dict(self.cmdMembers)
833 cmd_info = cmd_member_dict[proto.text]
834 disp_name = cmd_info[0].name
835 # Handle object create operations
836 if cmd_info[0].iscreate:
837 create_obj_code = self.generate_create_object_code(indent, proto, params, cmd_info)
838 else:
839 create_obj_code = ''
840 # Handle object destroy operations
841 if cmd_info[0].isdestroy:
842 (destroy_array, destroy_object_code) = self.generate_destroy_object_code(indent, proto, cmd_info)
843 else:
844 destroy_array = False
845 destroy_object_code = ''
846 paramdecl = ''
847 param_pre_code = ''
848 param_post_code = ''
849 create_func = True if create_obj_code else False
850 destroy_func = True if destroy_object_code else False
851 (paramdecl, param_pre_code, param_post_code) = self.validate_objects(cmd_info, indent, '', 0, create_func, destroy_func, destroy_array, disp_name, proto.text, True)
852 param_post_code += create_obj_code
853 if destroy_object_code:
854 if destroy_array == True:
855 param_post_code += destroy_object_code
856 else:
857 param_pre_code += destroy_object_code
858 if param_pre_code:
859 if (not destroy_func) or (destroy_array):
860 param_pre_code = '%s{\n%s%s%s%s}\n' % (' ', indent, self.lock_guard(indent), param_pre_code, indent)
861 return paramdecl, param_pre_code, param_post_code
862 #
863 # Capture command parameter info needed to create, destroy, and validate objects
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700864 def genCmd(self, cmdinfo, cmdname, alias):
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600865
866 # Add struct-member type information to command parameter information
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700867 OutputGenerator.genCmd(self, cmdinfo, cmdname, alias)
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600868 members = cmdinfo.elem.findall('.//param')
869 # Iterate over members once to get length parameters for arrays
870 lens = set()
871 for member in members:
872 len = self.getLen(member)
873 if len:
874 lens.add(len)
875 struct_member_dict = dict(self.structMembers)
876 # Generate member info
877 membersInfo = []
878 constains_extension_structs = False
879 for member in members:
880 # Get type and name of member
881 info = self.getTypeNameTuple(member)
882 type = info[0]
883 name = info[1]
884 cdecl = self.makeCParamDecl(member, 0)
885 # Check for parameter name in lens set
886 iscount = True if name in lens else False
887 len = self.getLen(member)
888 isconst = True if 'const' in cdecl else False
889 ispointer = self.paramIsPointer(member)
890 # Mark param as local if it is an array of objects
891 islocal = False;
892 if self.isHandleTypeObject(type) == True:
893 if (len is not None) and (isconst == True):
894 islocal = True
895 # Or if it's a struct that contains an object
896 elif type in struct_member_dict:
897 if self.struct_contains_object(type) == True:
898 islocal = True
899 isdestroy = True if True in [destroy_txt in cmdname for destroy_txt in ['Destroy', 'Free']] else False
900 iscreate = True if True in [create_txt in cmdname for create_txt in ['Create', 'Allocate', 'Enumerate', 'RegisterDeviceEvent', 'RegisterDisplayEvent']] or ('vkGet' in cmdname and member == members[-1] and ispointer == True) else False
901 extstructs = member.attrib.get('validextensionstructs') if name == 'pNext' else None
902 membersInfo.append(self.CommandParam(type=type,
903 name=name,
904 ispointer=ispointer,
905 isconst=isconst,
906 isoptional=self.paramIsOptional(member),
907 iscount=iscount,
908 len=len,
909 extstructs=extstructs,
910 cdecl=cdecl,
911 islocal=islocal,
912 iscreate=iscreate,
913 isdestroy=isdestroy,
914 feature_protect=self.featureExtraProtect))
915 self.cmdMembers.append(self.CmdMemberData(name=cmdname, members=membersInfo))
916 self.cmd_info_data.append(self.CmdInfoData(name=cmdname, cmdinfo=cmdinfo))
917 self.cmd_feature_protect.append(self.CmdExtraProtect(name=cmdname, extra_protect=self.featureExtraProtect))
918 #
919 # Create code Create, Destroy, and validate Vulkan objects
920 def WrapCommands(self):
921 cmd_member_dict = dict(self.cmdMembers)
922 cmd_info_dict = dict(self.cmd_info_data)
923 cmd_protect_dict = dict(self.cmd_feature_protect)
924 for api_call in self.cmdMembers:
925 cmdname = api_call.name
926 cmdinfo = cmd_info_dict[api_call.name]
927 if cmdname in self.interface_functions:
928 continue
929 if cmdname in self.no_autogen_list:
930 decls = self.makeCDecls(cmdinfo.elem)
931 self.appendSection('command', '')
932 self.appendSection('command', '// Declare only')
933 self.appendSection('command', decls[0])
934 self.intercepts += [ ' {"%s", (void *)%s},' % (cmdname,cmdname[2:]) ]
935 continue
936 # Generate object handling code
937 (api_decls, api_pre, api_post) = self.generate_wrapping_code(cmdinfo.elem)
938 # If API doesn't contain any object handles, don't fool with it
939 if not api_decls and not api_pre and not api_post:
940 continue
941 feature_extra_protect = cmd_protect_dict[api_call.name]
942 if (feature_extra_protect != None):
943 self.appendSection('command', '')
944 self.appendSection('command', '#ifdef '+ feature_extra_protect)
945 self.intercepts += [ '#ifdef %s' % feature_extra_protect ]
946 # Add intercept to procmap
947 self.intercepts += [ ' {"%s", (void*)%s},' % (cmdname,cmdname[2:]) ]
948 decls = self.makeCDecls(cmdinfo.elem)
949 self.appendSection('command', '')
950 self.appendSection('command', decls[0][:-1])
951 self.appendSection('command', '{')
952 self.appendSection('command', ' bool skip = false;')
953 # Handle return values, if any
954 resulttype = cmdinfo.elem.find('proto/type')
955 if (resulttype != None and resulttype.text == 'void'):
956 resulttype = None
957 if (resulttype != None):
958 assignresult = resulttype.text + ' result = '
959 else:
960 assignresult = ''
961 # Pre-pend declarations and pre-api-call codegen
962 if api_decls:
963 self.appendSection('command', "\n".join(str(api_decls).rstrip().split("\n")))
964 if api_pre:
965 self.appendSection('command', "\n".join(str(api_pre).rstrip().split("\n")))
966 # Generate the API call itself
967 # Gather the parameter items
968 params = cmdinfo.elem.findall('param/name')
969 # Pull out the text for each of the parameters, separate them by commas in a list
970 paramstext = ', '.join([str(param.text) for param in params])
971 # Use correct dispatch table
972 disp_type = cmdinfo.elem.find('param/type').text
973 disp_name = cmdinfo.elem.find('param/name').text
974 dispatch_table = 'get_dispatch_table(ot_%s_table_map, %s)->' % (self.GetDispType(disp_type), disp_name)
975 API = cmdinfo.elem.attrib.get('name').replace('vk', dispatch_table, 1)
976 # Put all this together for the final down-chain call
977 if assignresult != '':
Jamie Madillfc315192017-11-08 14:11:26 -0500978 if resulttype.text == 'VkResult':
979 self.appendSection('command', ' if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;')
980 elif resulttype.text == 'VkBool32':
981 self.appendSection('command', ' if (skip) return VK_FALSE;')
982 else:
983 raise Exception('Unknown result type ' + resulttype.text)
Mark Lobodzinskid1461482017-07-18 13:56:09 -0600984 else:
985 self.appendSection('command', ' if (skip) return;')
986 self.appendSection('command', ' ' + assignresult + API + '(' + paramstext + ');')
987 # And add the post-API-call codegen
988 self.appendSection('command', "\n".join(str(api_post).rstrip().split("\n")))
989 # Handle the return result variable, if any
990 if (resulttype != None):
991 self.appendSection('command', ' return result;')
992 self.appendSection('command', '}')
993 if (feature_extra_protect != None):
994 self.appendSection('command', '#endif // '+ feature_extra_protect)
995 self.intercepts += [ '#endif' ]