| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 1 | #!/usr/bin/python3 -i |
| 2 | # |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 3 | # Copyright (c) 2015-2019 The Khronos Group Inc. |
| 4 | # Copyright (c) 2015-2019 Valve Corporation |
| 5 | # Copyright (c) 2015-2019 LunarG, Inc. |
| 6 | # Copyright (c) 2015-2019 Google Inc. |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 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> |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 21 | # Author: Dave Houlton <daveh@lunarg.com> |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 22 | |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 23 | import os,re,sys,string,json |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 24 | import xml.etree.ElementTree as etree |
| 25 | from generator import * |
| 26 | from collections import namedtuple |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 27 | from common_codegen import * |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 28 | |
| Jamie Madill | 8d4cda2 | 2017-11-08 13:40:09 -0500 | [diff] [blame] | 29 | # This is a workaround to use a Python 2.7 and 3.x compatible syntax. |
| 30 | from io import open |
| 31 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 32 | # 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 |
| 65 | class ObjectTrackerGeneratorOptions(GeneratorOptions): |
| 66 | def __init__(self, |
| Mike Schuchardt | 21638df | 2019-03-16 10:52:02 -0700 | [diff] [blame^] | 67 | conventions = None, |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 68 | filename = None, |
| 69 | directory = '.', |
| 70 | apiname = None, |
| 71 | profile = None, |
| 72 | versions = '.*', |
| 73 | emitversions = '.*', |
| 74 | defaultExtensions = None, |
| 75 | addExtensions = None, |
| 76 | removeExtensions = None, |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 77 | emitExtensions = None, |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 78 | sortProcedure = regSortFeatures, |
| 79 | prefixText = "", |
| 80 | genFuncPointers = True, |
| 81 | protectFile = True, |
| 82 | protectFeature = True, |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 83 | apicall = '', |
| 84 | apientry = '', |
| 85 | apientryp = '', |
| 86 | indentFuncProto = True, |
| 87 | indentFuncPointer = False, |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 88 | alignFuncParam = 0, |
| Mark Lobodzinski | 27a9e7c | 2018-05-31 16:01:57 -0600 | [diff] [blame] | 89 | expandEnumerants = True, |
| 90 | valid_usage_path = ''): |
| Mike Schuchardt | 21638df | 2019-03-16 10:52:02 -0700 | [diff] [blame^] | 91 | GeneratorOptions.__init__(self, conventions, filename, directory, apiname, profile, |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 92 | versions, emitversions, defaultExtensions, |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 93 | addExtensions, removeExtensions, emitExtensions, sortProcedure) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 94 | self.prefixText = prefixText |
| 95 | self.genFuncPointers = genFuncPointers |
| 96 | self.protectFile = protectFile |
| 97 | self.protectFeature = protectFeature |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 98 | self.apicall = apicall |
| 99 | self.apientry = apientry |
| 100 | self.apientryp = apientryp |
| 101 | self.indentFuncProto = indentFuncProto |
| 102 | self.indentFuncPointer = indentFuncPointer |
| 103 | self.alignFuncParam = alignFuncParam |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 104 | self.expandEnumerants = expandEnumerants |
| Mark Lobodzinski | 27a9e7c | 2018-05-31 16:01:57 -0600 | [diff] [blame] | 105 | self.valid_usage_path = valid_usage_path |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 106 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 107 | |
| 108 | # ObjectTrackerOutputGenerator - subclass of OutputGenerator. |
| 109 | # Generates object_tracker layer object validation code |
| 110 | # |
| 111 | # ---- methods ---- |
| 112 | # ObjectTrackerOutputGenerator(errFile, warnFile, diagFile) - args as for OutputGenerator. Defines additional internal state. |
| 113 | # ---- methods overriding base class ---- |
| 114 | # beginFile(genOpts) |
| 115 | # endFile() |
| 116 | # beginFeature(interface, emit) |
| 117 | # endFeature() |
| 118 | # genCmd(cmdinfo) |
| 119 | # genStruct() |
| 120 | # genType() |
| 121 | class ObjectTrackerOutputGenerator(OutputGenerator): |
| 122 | """Generate ObjectTracker code based on XML element attributes""" |
| 123 | # This is an ordered list of sections in the header file. |
| 124 | ALL_SECTIONS = ['command'] |
| 125 | def __init__(self, |
| 126 | errFile = sys.stderr, |
| 127 | warnFile = sys.stderr, |
| 128 | diagFile = sys.stdout): |
| 129 | OutputGenerator.__init__(self, errFile, warnFile, diagFile) |
| 130 | self.INDENT_SPACES = 4 |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 131 | self.prototypes = [] |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 132 | self.instance_extensions = [] |
| 133 | self.device_extensions = [] |
| 134 | # Commands which are not autogenerated but still intercepted |
| 135 | self.no_autogen_list = [ |
| 136 | 'vkDestroyInstance', |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 137 | 'vkCreateInstance', |
| 138 | 'vkEnumeratePhysicalDevices', |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 139 | 'vkGetPhysicalDeviceQueueFamilyProperties', |
| 140 | 'vkGetPhysicalDeviceQueueFamilyProperties2', |
| 141 | 'vkGetPhysicalDeviceQueueFamilyProperties2KHR', |
| 142 | 'vkGetDeviceQueue', |
| 143 | 'vkGetDeviceQueue2', |
| 144 | 'vkCreateDescriptorSetLayout', |
| 145 | 'vkDestroyDescriptorPool', |
| 146 | 'vkDestroyCommandPool', |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 147 | 'vkAllocateCommandBuffers', |
| 148 | 'vkAllocateDescriptorSets', |
| 149 | 'vkFreeDescriptorSets', |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 150 | 'vkFreeCommandBuffers', |
| 151 | 'vkUpdateDescriptorSets', |
| 152 | 'vkBeginCommandBuffer', |
| Mark Lobodzinski | 5a1c8d2 | 2018-07-02 10:28:12 -0600 | [diff] [blame] | 153 | 'vkGetDescriptorSetLayoutSupport', |
| 154 | 'vkGetDescriptorSetLayoutSupportKHR', |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 155 | 'vkDestroySwapchainKHR', |
| 156 | 'vkGetSwapchainImagesKHR', |
| 157 | 'vkCmdPushDescriptorSetKHR', |
| 158 | 'vkDestroyDevice', |
| 159 | 'vkResetDescriptorPool', |
| Shannon McPherson | 9d5167f | 2018-05-02 15:24:37 -0600 | [diff] [blame] | 160 | 'vkGetPhysicalDeviceDisplayPropertiesKHR', |
| Piers Daniell | 16c253f | 2018-05-30 14:34:05 -0600 | [diff] [blame] | 161 | 'vkGetPhysicalDeviceDisplayProperties2KHR', |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 162 | 'vkGetDisplayModePropertiesKHR', |
| Piers Daniell | 16c253f | 2018-05-30 14:34:05 -0600 | [diff] [blame] | 163 | 'vkGetDisplayModeProperties2KHR', |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 164 | ] |
| 165 | # These VUIDS are not implicit, but are best handled in this layer. Codegen for vkDestroy calls will generate a key |
| 166 | # which is translated here into a good VU. Saves ~40 checks. |
| 167 | self.manual_vuids = dict() |
| 168 | self.manual_vuids = { |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 169 | "fence-compatalloc": "\"VUID-vkDestroyFence-fence-01121\"", |
| 170 | "fence-nullalloc": "\"VUID-vkDestroyFence-fence-01122\"", |
| 171 | "event-compatalloc": "\"VUID-vkDestroyEvent-event-01146\"", |
| 172 | "event-nullalloc": "\"VUID-vkDestroyEvent-event-01147\"", |
| 173 | "buffer-compatalloc": "\"VUID-vkDestroyBuffer-buffer-00923\"", |
| 174 | "buffer-nullalloc": "\"VUID-vkDestroyBuffer-buffer-00924\"", |
| 175 | "image-compatalloc": "\"VUID-vkDestroyImage-image-01001\"", |
| 176 | "image-nullalloc": "\"VUID-vkDestroyImage-image-01002\"", |
| 177 | "shaderModule-compatalloc": "\"VUID-vkDestroyShaderModule-shaderModule-01092\"", |
| 178 | "shaderModule-nullalloc": "\"VUID-vkDestroyShaderModule-shaderModule-01093\"", |
| 179 | "pipeline-compatalloc": "\"VUID-vkDestroyPipeline-pipeline-00766\"", |
| 180 | "pipeline-nullalloc": "\"VUID-vkDestroyPipeline-pipeline-00767\"", |
| 181 | "sampler-compatalloc": "\"VUID-vkDestroySampler-sampler-01083\"", |
| 182 | "sampler-nullalloc": "\"VUID-vkDestroySampler-sampler-01084\"", |
| 183 | "renderPass-compatalloc": "\"VUID-vkDestroyRenderPass-renderPass-00874\"", |
| 184 | "renderPass-nullalloc": "\"VUID-vkDestroyRenderPass-renderPass-00875\"", |
| 185 | "descriptorUpdateTemplate-compatalloc": "\"VUID-vkDestroyDescriptorUpdateTemplate-descriptorSetLayout-00356\"", |
| 186 | "descriptorUpdateTemplate-nullalloc": "\"VUID-vkDestroyDescriptorUpdateTemplate-descriptorSetLayout-00357\"", |
| 187 | "imageView-compatalloc": "\"VUID-vkDestroyImageView-imageView-01027\"", |
| 188 | "imageView-nullalloc": "\"VUID-vkDestroyImageView-imageView-01028\"", |
| 189 | "pipelineCache-compatalloc": "\"VUID-vkDestroyPipelineCache-pipelineCache-00771\"", |
| 190 | "pipelineCache-nullalloc": "\"VUID-vkDestroyPipelineCache-pipelineCache-00772\"", |
| 191 | "pipelineLayout-compatalloc": "\"VUID-vkDestroyPipelineLayout-pipelineLayout-00299\"", |
| 192 | "pipelineLayout-nullalloc": "\"VUID-vkDestroyPipelineLayout-pipelineLayout-00300\"", |
| 193 | "descriptorSetLayout-compatalloc": "\"VUID-vkDestroyDescriptorSetLayout-descriptorSetLayout-00284\"", |
| 194 | "descriptorSetLayout-nullalloc": "\"VUID-vkDestroyDescriptorSetLayout-descriptorSetLayout-00285\"", |
| 195 | "semaphore-compatalloc": "\"VUID-vkDestroySemaphore-semaphore-01138\"", |
| 196 | "semaphore-nullalloc": "\"VUID-vkDestroySemaphore-semaphore-01139\"", |
| 197 | "queryPool-compatalloc": "\"VUID-vkDestroyQueryPool-queryPool-00794\"", |
| 198 | "queryPool-nullalloc": "\"VUID-vkDestroyQueryPool-queryPool-00795\"", |
| 199 | "bufferView-compatalloc": "\"VUID-vkDestroyBufferView-bufferView-00937\"", |
| 200 | "bufferView-nullalloc": "\"VUID-vkDestroyBufferView-bufferView-00938\"", |
| 201 | "surface-compatalloc": "\"VUID-vkDestroySurfaceKHR-surface-01267\"", |
| 202 | "surface-nullalloc": "\"VUID-vkDestroySurfaceKHR-surface-01268\"", |
| 203 | "framebuffer-compatalloc": "\"VUID-vkDestroyFramebuffer-framebuffer-00893\"", |
| 204 | "framebuffer-nullalloc": "\"VUID-vkDestroyFramebuffer-framebuffer-00894\"", |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | # Commands shadowed by interface functions and are not implemented |
| 208 | self.interface_functions = [ |
| 209 | ] |
| 210 | self.headerVersion = None |
| 211 | # Internal state - accumulators for different inner block text |
| 212 | self.sections = dict([(section, []) for section in self.ALL_SECTIONS]) |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 213 | self.cmd_list = [] # list of commands processed to maintain ordering |
| 214 | self.cmd_info_dict = {} # Per entry-point data for code generation and validation |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 215 | self.structMembers = [] # List of StructMemberData records for all Vulkan structs |
| 216 | self.extension_structs = [] # List of all structs or sister-structs containing handles |
| 217 | # A sister-struct may contain no handles but shares <validextensionstructs> with one that does |
| 218 | self.structTypes = dict() # Map of Vulkan struct typename to required VkStructureType |
| 219 | self.struct_member_dict = dict() |
| 220 | # Named tuples to store struct and command data |
| 221 | self.StructType = namedtuple('StructType', ['name', 'value']) |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 222 | self.CmdInfoData = namedtuple('CmdInfoData', ['name', 'cmdinfo', 'members', 'extra_protect', 'alias', 'iscreate', 'isdestroy', 'allocator']) |
| 223 | self.CommandParam = namedtuple('CommandParam', ['type', 'name', 'isconst', 'isoptional', 'iscount', 'iscreate', 'len', 'extstructs', 'cdecl', 'islocal']) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 224 | self.StructMemberData = namedtuple('StructMemberData', ['name', 'members']) |
| 225 | self.object_types = [] # List of all handle types |
| 226 | self.valid_vuids = set() # Set of all valid VUIDs |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 227 | self.vuid_dict = dict() # VUID dictionary (from JSON) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 228 | # |
| 229 | # Check if the parameter passed in is optional |
| 230 | def paramIsOptional(self, param): |
| 231 | # See if the handle is optional |
| 232 | isoptional = False |
| 233 | # Simple, if it's optional, return true |
| 234 | optString = param.attrib.get('optional') |
| 235 | if optString: |
| 236 | if optString == 'true': |
| 237 | isoptional = True |
| 238 | elif ',' in optString: |
| 239 | opts = [] |
| 240 | for opt in optString.split(','): |
| 241 | val = opt.strip() |
| 242 | if val == 'true': |
| 243 | opts.append(True) |
| 244 | elif val == 'false': |
| 245 | opts.append(False) |
| 246 | else: |
| 247 | print('Unrecognized len attribute value',val) |
| 248 | isoptional = opts |
| John Zulauf | 9f6788c | 2018-04-04 14:54:11 -0600 | [diff] [blame] | 249 | if not isoptional: |
| 250 | # Matching logic in parameter validation and ValidityOutputGenerator.isHandleOptional |
| 251 | optString = param.attrib.get('noautovalidity') |
| 252 | if optString and optString == 'true': |
| 253 | isoptional = True; |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 254 | return isoptional |
| 255 | # |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 256 | # Get VUID identifier from implicit VUID tag |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 257 | def GetVuid(self, parent, suffix): |
| 258 | vuid_string = 'VUID-%s-%s' % (parent, suffix) |
| 259 | vuid = "kVUIDUndefined" |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 260 | if '->' in vuid_string: |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 261 | return vuid |
| 262 | if vuid_string in self.valid_vuids: |
| 263 | vuid = "\"%s\"" % vuid_string |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 264 | else: |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 265 | alias = self.cmd_info_dict[parent].alias if parent in self.cmd_info_dict else None |
| 266 | if alias: |
| 267 | alias_string = 'VUID-%s-%s' % (alias, suffix) |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 268 | if alias_string in self.valid_vuids: |
| 269 | vuid = "\"%s\"" % vuid_string |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 270 | return vuid |
| 271 | # |
| 272 | # Increases indent by 4 spaces and tracks it globally |
| 273 | def incIndent(self, indent): |
| 274 | inc = ' ' * self.INDENT_SPACES |
| 275 | if indent: |
| 276 | return indent + inc |
| 277 | return inc |
| 278 | # |
| 279 | # Decreases indent by 4 spaces and tracks it globally |
| 280 | def decIndent(self, indent): |
| 281 | if indent and (len(indent) > self.INDENT_SPACES): |
| 282 | return indent[:-self.INDENT_SPACES] |
| 283 | return '' |
| 284 | # |
| 285 | # Override makeProtoName to drop the "vk" prefix |
| 286 | def makeProtoName(self, name, tail): |
| 287 | return self.genOpts.apientry + name[2:] + tail |
| 288 | # |
| 289 | # Check if the parameter passed in is a pointer to an array |
| 290 | def paramIsArray(self, param): |
| 291 | return param.attrib.get('len') is not None |
| Gabríel Arthúr Pétursson | fdcb540 | 2018-03-20 21:52:06 +0000 | [diff] [blame] | 292 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 293 | # |
| 294 | # Generate the object tracker undestroyed object validation function |
| 295 | def GenReportFunc(self): |
| 296 | output_func = '' |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 297 | output_func += 'bool ObjectLifetimes::ReportUndestroyedObjects(VkDevice device, const std::string& error_code) {\n' |
| Mark Lobodzinski | 5183a03 | 2018-09-13 14:44:28 -0600 | [diff] [blame] | 298 | output_func += ' bool skip = false;\n' |
| 299 | output_func += ' skip |= DeviceReportUndestroyedObjects(device, kVulkanObjectTypeCommandBuffer, error_code);\n' |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 300 | for handle in self.object_types: |
| 301 | if self.isHandleTypeNonDispatchable(handle): |
| Mark Lobodzinski | 5183a03 | 2018-09-13 14:44:28 -0600 | [diff] [blame] | 302 | output_func += ' skip |= DeviceReportUndestroyedObjects(device, %s, error_code);\n' % (self.GetVulkanObjType(handle)) |
| 303 | output_func += ' return skip;\n' |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 304 | output_func += '}\n' |
| 305 | return output_func |
| Gabríel Arthúr Pétursson | fdcb540 | 2018-03-20 21:52:06 +0000 | [diff] [blame] | 306 | |
| 307 | # |
| 308 | # Generate the object tracker undestroyed object destruction function |
| 309 | def GenDestroyFunc(self): |
| 310 | output_func = '' |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 311 | output_func += 'void ObjectLifetimes::DestroyUndestroyedObjects(VkDevice device) {\n' |
| Gabríel Arthúr Pétursson | fdcb540 | 2018-03-20 21:52:06 +0000 | [diff] [blame] | 312 | output_func += ' DeviceDestroyUndestroyedObjects(device, kVulkanObjectTypeCommandBuffer);\n' |
| 313 | for handle in self.object_types: |
| 314 | if self.isHandleTypeNonDispatchable(handle): |
| 315 | output_func += ' DeviceDestroyUndestroyedObjects(device, %s);\n' % (self.GetVulkanObjType(handle)) |
| 316 | output_func += '}\n' |
| 317 | return output_func |
| 318 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 319 | # |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 320 | # Walk the JSON-derived dict and find all "vuid" key values |
| 321 | def ExtractVUIDs(self, d): |
| 322 | if hasattr(d, 'items'): |
| 323 | for k, v in d.items(): |
| 324 | if k == "vuid": |
| 325 | yield v |
| 326 | elif isinstance(v, dict): |
| 327 | for s in self.ExtractVUIDs(v): |
| 328 | yield s |
| 329 | elif isinstance (v, list): |
| 330 | for l in v: |
| 331 | for s in self.ExtractVUIDs(l): |
| 332 | yield s |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 333 | # |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 334 | # Separate content for validation source and header files |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 335 | def otwrite(self, dest, formatstring): |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 336 | if 'object_tracker.h' in self.genOpts.filename and (dest == 'hdr' or dest == 'both'): |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 337 | write(formatstring, file=self.outFile) |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 338 | elif 'object_tracker.cpp' in self.genOpts.filename and (dest == 'cpp' or dest == 'both'): |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 339 | write(formatstring, file=self.outFile) |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 340 | |
| 341 | # |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 342 | # Called at beginning of processing as file is opened |
| 343 | def beginFile(self, genOpts): |
| 344 | OutputGenerator.beginFile(self, genOpts) |
| Mark Lobodzinski | 27a9e7c | 2018-05-31 16:01:57 -0600 | [diff] [blame] | 345 | |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 346 | header_file = (genOpts.filename == 'object_tracker.h') |
| 347 | source_file = (genOpts.filename == 'object_tracker.cpp') |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 348 | |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 349 | if not header_file and not source_file: |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 350 | print("Error: Output Filenames have changed, update generator source.\n") |
| 351 | sys.exit(1) |
| 352 | |
| Mark Lobodzinski | 27a9e7c | 2018-05-31 16:01:57 -0600 | [diff] [blame] | 353 | self.valid_usage_path = genOpts.valid_usage_path |
| 354 | vu_json_filename = os.path.join(self.valid_usage_path + os.sep, 'validusage.json') |
| 355 | if os.path.isfile(vu_json_filename): |
| 356 | json_file = open(vu_json_filename, 'r') |
| 357 | self.vuid_dict = json.load(json_file) |
| 358 | json_file.close() |
| 359 | if len(self.vuid_dict) == 0: |
| 360 | print("Error: Could not find, or error loading %s/validusage.json\n", vu_json_filename) |
| 361 | sys.exit(1) |
| 362 | |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 363 | # Build a set of all vuid text strings found in validusage.json |
| 364 | for json_vuid_string in self.ExtractVUIDs(self.vuid_dict): |
| 365 | self.valid_vuids.add(json_vuid_string) |
| 366 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 367 | # File Comment |
| 368 | file_comment = '// *** THIS FILE IS GENERATED - DO NOT EDIT ***\n' |
| 369 | file_comment += '// See object_tracker_generator.py for modifications\n' |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 370 | self.otwrite('both', file_comment) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 371 | # Copyright Statement |
| 372 | copyright = '' |
| 373 | copyright += '\n' |
| 374 | copyright += '/***************************************************************************\n' |
| 375 | copyright += ' *\n' |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 376 | copyright += ' * Copyright (c) 2015-2019 The Khronos Group Inc.\n' |
| 377 | copyright += ' * Copyright (c) 2015-2019 Valve Corporation\n' |
| 378 | copyright += ' * Copyright (c) 2015-2019 LunarG, Inc.\n' |
| 379 | copyright += ' * Copyright (c) 2015-2019 Google Inc.\n' |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 380 | copyright += ' *\n' |
| 381 | copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n' |
| 382 | copyright += ' * you may not use this file except in compliance with the License.\n' |
| 383 | copyright += ' * You may obtain a copy of the License at\n' |
| 384 | copyright += ' *\n' |
| 385 | copyright += ' * http://www.apache.org/licenses/LICENSE-2.0\n' |
| 386 | copyright += ' *\n' |
| 387 | copyright += ' * Unless required by applicable law or agreed to in writing, software\n' |
| 388 | copyright += ' * distributed under the License is distributed on an "AS IS" BASIS,\n' |
| 389 | copyright += ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' |
| 390 | copyright += ' * See the License for the specific language governing permissions and\n' |
| 391 | copyright += ' * limitations under the License.\n' |
| 392 | copyright += ' *\n' |
| 393 | copyright += ' * Author: Mark Lobodzinski <mark@lunarg.com>\n' |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 394 | copyright += ' * Author: Dave Houlton <daveh@lunarg.com>\n' |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 395 | copyright += ' *\n' |
| 396 | copyright += ' ****************************************************************************/\n' |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 397 | self.otwrite('both', copyright) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 398 | self.newline() |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 399 | self.otwrite('cpp', '#include "chassis.h"') |
| 400 | self.otwrite('cpp', '#include "object_lifetime_validation.h"') |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 401 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 402 | # |
| 403 | # Now that the data is all collected and complete, generate and output the object validation routines |
| 404 | def endFile(self): |
| 405 | self.struct_member_dict = dict(self.structMembers) |
| 406 | # Generate the list of APIs that might need to handle wrapped extension structs |
| 407 | # self.GenerateCommandWrapExtensionList() |
| 408 | self.WrapCommands() |
| 409 | # Build undestroyed objects reporting function |
| 410 | report_func = self.GenReportFunc() |
| 411 | self.newline() |
| Gabríel Arthúr Pétursson | fdcb540 | 2018-03-20 21:52:06 +0000 | [diff] [blame] | 412 | # Build undestroyed objects destruction function |
| 413 | destroy_func = self.GenDestroyFunc() |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 414 | self.otwrite('cpp', '\n') |
| 415 | self.otwrite('cpp', '// ObjectTracker undestroyed objects validation function') |
| 416 | self.otwrite('cpp', '%s' % report_func) |
| 417 | self.otwrite('cpp', '%s' % destroy_func) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 418 | # Actually write the interface to the output file. |
| 419 | if (self.emit): |
| 420 | self.newline() |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 421 | if self.featureExtraProtect is not None: |
| 422 | prot = '#ifdef %s' % self.featureExtraProtect |
| 423 | self.otwrite('both', '%s' % prot) |
| 424 | # Write the object_tracker code to the file |
| 425 | if self.sections['command']: |
| 426 | source = ('\n'.join(self.sections['command'])) |
| 427 | self.otwrite('both', '%s' % source) |
| Michał Janiszewski | 3c3ce9e | 2018-10-30 23:25:21 +0100 | [diff] [blame] | 428 | if (self.featureExtraProtect is not None): |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 429 | prot = '\n#endif // %s', self.featureExtraProtect |
| 430 | self.otwrite('both', prot) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 431 | else: |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 432 | self.otwrite('both', '\n') |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 433 | |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 434 | |
| 435 | self.otwrite('hdr', 'void PostCallRecordDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator);') |
| 436 | self.otwrite('hdr', 'void PreCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags);') |
| 437 | self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties *pQueueFamilyProperties);') |
| 438 | self.otwrite('hdr', 'void PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers);') |
| 439 | self.otwrite('hdr', 'void PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets);') |
| 440 | self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties);') |
| 441 | self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties);') |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 442 | self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPropertiesKHR *pProperties, VkResult result);') |
| 443 | self.otwrite('hdr', 'void PostCallRecordGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties, VkResult result);') |
| 444 | self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayProperties2KHR *pProperties, VkResult result);') |
| 445 | self.otwrite('hdr', 'void PostCallRecordGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t *pPropertyCount, VkDisplayModeProperties2KHR *pProperties, VkResult result);') |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 446 | OutputGenerator.endFile(self) |
| 447 | # |
| 448 | # Processing point at beginning of each extension definition |
| 449 | def beginFeature(self, interface, emit): |
| 450 | # Start processing in superclass |
| 451 | OutputGenerator.beginFeature(self, interface, emit) |
| 452 | self.headerVersion = None |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 453 | self.featureExtraProtect = GetFeatureProtect(interface) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 454 | |
| Mark Lobodzinski | 31964ca | 2017-09-18 14:15:09 -0600 | [diff] [blame] | 455 | if self.featureName != 'VK_VERSION_1_0' and self.featureName != 'VK_VERSION_1_1': |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 456 | white_list_entry = [] |
| Michał Janiszewski | 3c3ce9e | 2018-10-30 23:25:21 +0100 | [diff] [blame] | 457 | if (self.featureExtraProtect is not None): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 458 | white_list_entry += [ '#ifdef %s' % self.featureExtraProtect ] |
| 459 | white_list_entry += [ '"%s"' % self.featureName ] |
| Michał Janiszewski | 3c3ce9e | 2018-10-30 23:25:21 +0100 | [diff] [blame] | 460 | if (self.featureExtraProtect is not None): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 461 | white_list_entry += [ '#endif' ] |
| 462 | featureType = interface.get('type') |
| 463 | if featureType == 'instance': |
| 464 | self.instance_extensions += white_list_entry |
| 465 | elif featureType == 'device': |
| 466 | self.device_extensions += white_list_entry |
| 467 | # |
| 468 | # Processing point at end of each extension definition |
| 469 | def endFeature(self): |
| 470 | # Finish processing in superclass |
| 471 | OutputGenerator.endFeature(self) |
| 472 | # |
| 473 | # Process enums, structs, etc. |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 474 | def genType(self, typeinfo, name, alias): |
| 475 | OutputGenerator.genType(self, typeinfo, name, alias) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 476 | typeElem = typeinfo.elem |
| 477 | # If the type is a struct type, traverse the imbedded <member> tags generating a structure. |
| 478 | # Otherwise, emit the tag text. |
| 479 | category = typeElem.get('category') |
| 480 | if (category == 'struct' or category == 'union'): |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 481 | self.genStruct(typeinfo, name, alias) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 482 | if category == 'handle': |
| 483 | self.object_types.append(name) |
| 484 | # |
| 485 | # Append a definition to the specified section |
| 486 | def appendSection(self, section, text): |
| 487 | # self.sections[section].append('SECTION: ' + section + '\n') |
| 488 | self.sections[section].append(text) |
| 489 | # |
| 490 | # Check if the parameter passed in is a pointer |
| 491 | def paramIsPointer(self, param): |
| 492 | ispointer = False |
| 493 | for elem in param: |
| 494 | if ((elem.tag is not 'type') and (elem.tail is not None)) and '*' in elem.tail: |
| 495 | ispointer = True |
| 496 | return ispointer |
| 497 | # |
| 498 | # Get the category of a type |
| 499 | def getTypeCategory(self, typename): |
| 500 | types = self.registry.tree.findall("types/type") |
| 501 | for elem in types: |
| 502 | if (elem.find("name") is not None and elem.find('name').text == typename) or elem.attrib.get('name') == typename: |
| 503 | return elem.attrib.get('category') |
| 504 | # |
| 505 | # Check if a parent object is dispatchable or not |
| 506 | def isHandleTypeObject(self, handletype): |
| 507 | handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']") |
| 508 | if handle is not None: |
| 509 | return True |
| 510 | else: |
| 511 | return False |
| 512 | # |
| 513 | # Check if a parent object is dispatchable or not |
| 514 | def isHandleTypeNonDispatchable(self, handletype): |
| 515 | handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']") |
| 516 | if handle is not None and handle.find('type').text == 'VK_DEFINE_NON_DISPATCHABLE_HANDLE': |
| 517 | return True |
| 518 | else: |
| 519 | return False |
| 520 | # |
| 521 | # Retrieve the type and name for a parameter |
| 522 | def getTypeNameTuple(self, param): |
| 523 | type = '' |
| 524 | name = '' |
| 525 | for elem in param: |
| 526 | if elem.tag == 'type': |
| 527 | type = noneStr(elem.text) |
| 528 | elif elem.tag == 'name': |
| 529 | name = noneStr(elem.text) |
| 530 | return (type, name) |
| 531 | # |
| 532 | # Retrieve the value of the len tag |
| 533 | def getLen(self, param): |
| 534 | result = None |
| 535 | len = param.attrib.get('len') |
| 536 | if len and len != 'null-terminated': |
| 537 | # For string arrays, 'len' can look like 'count,null-terminated', indicating that we |
| 538 | # have a null terminated array of strings. We strip the null-terminated from the |
| 539 | # 'len' field and only return the parameter specifying the string count |
| 540 | if 'null-terminated' in len: |
| 541 | result = len.split(',')[0] |
| 542 | else: |
| 543 | result = len |
| 544 | # Spec has now notation for len attributes, using :: instead of platform specific pointer symbol |
| 545 | result = str(result).replace('::', '->') |
| 546 | return result |
| 547 | # |
| 548 | # Generate a VkStructureType based on a structure typename |
| 549 | def genVkStructureType(self, typename): |
| 550 | # Add underscore between lowercase then uppercase |
| 551 | value = re.sub('([a-z0-9])([A-Z])', r'\1_\2', typename) |
| 552 | # Change to uppercase |
| 553 | value = value.upper() |
| 554 | # Add STRUCTURE_TYPE_ |
| 555 | return re.sub('VK_', 'VK_STRUCTURE_TYPE_', value) |
| 556 | # |
| 557 | # Struct parameter check generation. |
| 558 | # This is a special case of the <type> tag where the contents are interpreted as a set of |
| 559 | # <member> tags instead of freeform C type declarations. The <member> tags are just like |
| 560 | # <param> tags - they are a declaration of a struct or union member. Only simple member |
| 561 | # declarations are supported (no nested structs etc.) |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 562 | def genStruct(self, typeinfo, typeName, alias): |
| 563 | OutputGenerator.genStruct(self, typeinfo, typeName, alias) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 564 | members = typeinfo.elem.findall('.//member') |
| 565 | # Iterate over members once to get length parameters for arrays |
| 566 | lens = set() |
| 567 | for member in members: |
| 568 | len = self.getLen(member) |
| 569 | if len: |
| 570 | lens.add(len) |
| 571 | # Generate member info |
| 572 | membersInfo = [] |
| 573 | for member in members: |
| 574 | # Get the member's type and name |
| 575 | info = self.getTypeNameTuple(member) |
| 576 | type = info[0] |
| 577 | name = info[1] |
| 578 | cdecl = self.makeCParamDecl(member, 0) |
| 579 | # Process VkStructureType |
| 580 | if type == 'VkStructureType': |
| 581 | # Extract the required struct type value from the comments |
| 582 | # embedded in the original text defining the 'typeinfo' element |
| 583 | rawXml = etree.tostring(typeinfo.elem).decode('ascii') |
| 584 | result = re.search(r'VK_STRUCTURE_TYPE_\w+', rawXml) |
| 585 | if result: |
| 586 | value = result.group(0) |
| 587 | else: |
| 588 | value = self.genVkStructureType(typeName) |
| 589 | # Store the required type value |
| 590 | self.structTypes[typeName] = self.StructType(name=name, value=value) |
| 591 | # Store pointer/array/string info |
| 592 | extstructs = member.attrib.get('validextensionstructs') if name == 'pNext' else None |
| 593 | membersInfo.append(self.CommandParam(type=type, |
| 594 | name=name, |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 595 | isconst=True if 'const' in cdecl else False, |
| 596 | isoptional=self.paramIsOptional(member), |
| 597 | iscount=True if name in lens else False, |
| 598 | len=self.getLen(member), |
| 599 | extstructs=extstructs, |
| 600 | cdecl=cdecl, |
| 601 | islocal=False, |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 602 | iscreate=False)) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 603 | self.structMembers.append(self.StructMemberData(name=typeName, members=membersInfo)) |
| 604 | # |
| 605 | # Insert a lock_guard line |
| 606 | def lock_guard(self, indent): |
| 607 | return '%sstd::lock_guard<std::mutex> lock(global_lock);\n' % indent |
| 608 | # |
| 609 | # Determine if a struct has an object as a member or an embedded member |
| 610 | def struct_contains_object(self, struct_item): |
| 611 | struct_member_dict = dict(self.structMembers) |
| 612 | struct_members = struct_member_dict[struct_item] |
| 613 | |
| 614 | for member in struct_members: |
| 615 | if self.isHandleTypeObject(member.type): |
| 616 | return True |
| Mike Schuchardt | cf2eda0 | 2018-08-11 20:34:07 -0700 | [diff] [blame] | 617 | # recurse for member structs, guard against infinite recursion |
| 618 | elif member.type in struct_member_dict and member.type != struct_item: |
| 619 | if self.struct_contains_object(member.type): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 620 | return True |
| 621 | return False |
| 622 | # |
| 623 | # Return list of struct members which contain, or whose sub-structures contain an obj in a given list of parameters or members |
| 624 | def getParmeterStructsWithObjects(self, item_list): |
| 625 | struct_list = set() |
| 626 | for item in item_list: |
| 627 | paramtype = item.find('type') |
| 628 | typecategory = self.getTypeCategory(paramtype.text) |
| 629 | if typecategory == 'struct': |
| 630 | if self.struct_contains_object(paramtype.text) == True: |
| 631 | struct_list.add(item) |
| 632 | return struct_list |
| 633 | # |
| 634 | # Return list of objects from a given list of parameters or members |
| 635 | def getObjectsInParameterList(self, item_list, create_func): |
| 636 | object_list = set() |
| 637 | if create_func == True: |
| 638 | member_list = item_list[0:-1] |
| 639 | else: |
| 640 | member_list = item_list |
| 641 | for item in member_list: |
| 642 | if self.isHandleTypeObject(paramtype.text): |
| 643 | object_list.add(item) |
| 644 | return object_list |
| 645 | # |
| 646 | # Construct list of extension structs containing handles, or extension structs that share a <validextensionstructs> |
| Shannon McPherson | 9d5167f | 2018-05-02 15:24:37 -0600 | [diff] [blame] | 647 | # tag WITH an extension struct containing handles. |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 648 | def GenerateCommandWrapExtensionList(self): |
| 649 | for struct in self.structMembers: |
| 650 | if (len(struct.members) > 1) and struct.members[1].extstructs is not None: |
| 651 | found = False; |
| 652 | for item in struct.members[1].extstructs.split(','): |
| 653 | if item != '' and self.struct_contains_object(item) == True: |
| 654 | found = True |
| 655 | if found == True: |
| 656 | for item in struct.members[1].extstructs.split(','): |
| 657 | if item != '' and item not in self.extension_structs: |
| 658 | self.extension_structs.append(item) |
| 659 | # |
| 660 | # Returns True if a struct may have a pNext chain containing an object |
| 661 | def StructWithExtensions(self, struct_type): |
| 662 | if struct_type in self.struct_member_dict: |
| 663 | param_info = self.struct_member_dict[struct_type] |
| 664 | if (len(param_info) > 1) and param_info[1].extstructs is not None: |
| 665 | for item in param_info[1].extstructs.split(','): |
| 666 | if item in self.extension_structs: |
| 667 | return True |
| 668 | return False |
| 669 | # |
| 670 | # Generate VulkanObjectType from object type |
| 671 | def GetVulkanObjType(self, type): |
| 672 | return 'kVulkanObjectType%s' % type[2:] |
| 673 | # |
| 674 | # Return correct dispatch table type -- instance or device |
| 675 | def GetDispType(self, type): |
| 676 | return 'instance' if type in ['VkInstance', 'VkPhysicalDevice'] else 'device' |
| 677 | # |
| 678 | # Generate source for creating a Vulkan object |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 679 | def generate_create_object_code(self, indent, proto, params, cmd_info, allocator): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 680 | create_obj_code = '' |
| 681 | handle_type = params[-1].find('type') |
| Mark Lobodzinski | dcf2bd2 | 2019-02-27 16:30:35 -0700 | [diff] [blame] | 682 | is_create_pipelines = False |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 683 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 684 | if self.isHandleTypeObject(handle_type.text): |
| 685 | # Check for special case where multiple handles are returned |
| 686 | object_array = False |
| 687 | if cmd_info[-1].len is not None: |
| 688 | object_array = True; |
| 689 | handle_name = params[-1].find('name') |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 690 | object_dest = '*%s' % handle_name.text |
| 691 | if object_array == True: |
| Mark Lobodzinski | dcf2bd2 | 2019-02-27 16:30:35 -0700 | [diff] [blame] | 692 | if 'CreateGraphicsPipelines' in proto.text or 'CreateComputePipelines' in proto.text or 'CreateRayTracingPipelines' in proto.text: |
| 693 | is_create_pipelines = True |
| 694 | create_obj_code += '%sif (VK_ERROR_VALIDATION_FAILED_EXT == result) return;\n' % indent |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 695 | countispointer = '' |
| 696 | if 'uint32_t*' in cmd_info[-2].cdecl: |
| 697 | countispointer = '*' |
| 698 | create_obj_code += '%sfor (uint32_t index = 0; index < %s%s; index++) {\n' % (indent, countispointer, cmd_info[-1].len) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 699 | indent = self.incIndent(indent) |
| 700 | object_dest = '%s[index]' % cmd_info[-1].name |
| Mark Lobodzinski | c3ff7a9 | 2018-09-20 11:05:57 -0600 | [diff] [blame] | 701 | |
| 702 | dispobj = params[0].find('type').text |
| Mark Lobodzinski | dcf2bd2 | 2019-02-27 16:30:35 -0700 | [diff] [blame] | 703 | if is_create_pipelines: |
| Mark Lobodzinski | fd2d0a4 | 2019-02-20 16:34:56 -0700 | [diff] [blame] | 704 | create_obj_code += '%sif (!pPipelines[index]) continue;\n' % indent |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 705 | create_obj_code += '%sCreateObject(%s, %s, %s, %s);\n' % (indent, params[0].find('name').text, object_dest, self.GetVulkanObjType(cmd_info[-1].type), allocator) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 706 | if object_array == True: |
| 707 | indent = self.decIndent(indent) |
| 708 | create_obj_code += '%s}\n' % indent |
| 709 | indent = self.decIndent(indent) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 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): |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 714 | validate_code = '' |
| 715 | record_code = '' |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 716 | object_array = False |
| 717 | if True in [destroy_txt in proto.text for destroy_txt in ['Destroy', 'Free']]: |
| 718 | # Check for special case where multiple handles are returned |
| 719 | if cmd_info[-1].len is not None: |
| 720 | object_array = True; |
| 721 | param = -1 |
| 722 | else: |
| 723 | param = -2 |
| 724 | compatalloc_vuid_string = '%s-compatalloc' % cmd_info[param].name |
| 725 | nullalloc_vuid_string = '%s-nullalloc' % cmd_info[param].name |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 726 | compatalloc_vuid = self.manual_vuids.get(compatalloc_vuid_string, "kVUIDUndefined") |
| 727 | nullalloc_vuid = self.manual_vuids.get(nullalloc_vuid_string, "kVUIDUndefined") |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 728 | if self.isHandleTypeObject(cmd_info[param].type) == True: |
| 729 | if object_array == True: |
| 730 | # This API is freeing an array of handles -- add loop control |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 731 | validate_code += 'HEY, NEED TO DESTROY AN ARRAY\n' |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 732 | else: |
| Mark Lobodzinski | c3ff7a9 | 2018-09-20 11:05:57 -0600 | [diff] [blame] | 733 | dispobj = cmd_info[0].type |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 734 | # Call Destroy a single time |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 735 | validate_code += '%sskip |= ValidateDestroyObject(%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) |
| 736 | record_code += '%sRecordDestroyObject(%s, %s, %s);\n' % (indent, cmd_info[0].name, cmd_info[param].name, self.GetVulkanObjType(cmd_info[param].type)) |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 737 | return object_array, validate_code, record_code |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 738 | # |
| 739 | # Output validation for a single object (obj_count is NULL) or a counted list of objects |
| Mark Lobodzinski | 8c0d3f9 | 2018-09-13 10:45:20 -0600 | [diff] [blame] | 740 | def outputObjects(self, obj_type, obj_name, obj_count, prefix, index, indent, disp_name, parent_name, null_allowed, top_level): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 741 | pre_call_code = '' |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 742 | param_suffix = '%s-parameter' % (obj_name) |
| 743 | parent_suffix = '%s-parent' % (obj_name) |
| 744 | param_vuid = self.GetVuid(parent_name, param_suffix) |
| 745 | parent_vuid = self.GetVuid(parent_name, parent_suffix) |
| 746 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 747 | # If no parent VUID for this member, look for a commonparent VUID |
| Dave Houlton | 57ae22f | 2018-05-18 16:20:52 -0600 | [diff] [blame] | 748 | if parent_vuid == 'kVUIDUndefined': |
| 749 | parent_vuid = self.GetVuid(parent_name, 'commonparent') |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 750 | if obj_count is not None: |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 751 | pre_call_code += '%sfor (uint32_t %s = 0; %s < %s; ++%s) {\n' % (indent, index, index, obj_count, index) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 752 | indent = self.incIndent(indent) |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 753 | pre_call_code += '%sskip |= 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) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 754 | indent = self.decIndent(indent) |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 755 | pre_call_code += '%s}\n' % indent |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 756 | else: |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 757 | pre_call_code += '%sskip |= 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) |
| Mark Lobodzinski | 8c0d3f9 | 2018-09-13 10:45:20 -0600 | [diff] [blame] | 758 | return pre_call_code |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 759 | # |
| 760 | # first_level_param indicates if elements are passed directly into the function else they're below a ptr/struct |
| Mark Lobodzinski | 8c0d3f9 | 2018-09-13 10:45:20 -0600 | [diff] [blame] | 761 | def validate_objects(self, members, indent, prefix, array_index, disp_name, parent_name, first_level_param): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 762 | pre_code = '' |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 763 | index = 'index%s' % str(array_index) |
| 764 | array_index += 1 |
| 765 | # Process any objects in this structure and recurse for any sub-structs in this struct |
| 766 | for member in members: |
| 767 | # Handle objects |
| 768 | if member.iscreate and first_level_param and member == members[-1]: |
| 769 | continue |
| 770 | if self.isHandleTypeObject(member.type) == True: |
| 771 | count_name = member.len |
| 772 | if (count_name is not None): |
| 773 | count_name = '%s%s' % (prefix, member.len) |
| 774 | null_allowed = member.isoptional |
| Mark Lobodzinski | 8c0d3f9 | 2018-09-13 10:45:20 -0600 | [diff] [blame] | 775 | tmp_pre = self.outputObjects(member.type, member.name, count_name, prefix, index, indent, disp_name, parent_name, str(null_allowed).lower(), first_level_param) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 776 | pre_code += tmp_pre |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 777 | # Handle Structs that contain objects at some level |
| 778 | elif member.type in self.struct_member_dict: |
| 779 | # Structs at first level will have an object |
| 780 | if self.struct_contains_object(member.type) == True: |
| 781 | struct_info = self.struct_member_dict[member.type] |
| Jeff Bolz | 38b3ce7 | 2018-09-19 12:53:38 -0500 | [diff] [blame] | 782 | # TODO (jbolz): Can this use paramIsPointer? |
| Jeff Bolz | ba74d97 | 2018-09-12 15:54:57 -0500 | [diff] [blame] | 783 | ispointer = '*' in member.cdecl; |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 784 | # Struct Array |
| 785 | if member.len is not None: |
| 786 | # Update struct prefix |
| 787 | new_prefix = '%s%s' % (prefix, member.name) |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 788 | pre_code += '%sif (%s%s) {\n' % (indent, prefix, member.name) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 789 | indent = self.incIndent(indent) |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 790 | pre_code += '%sfor (uint32_t %s = 0; %s < %s%s; ++%s) {\n' % (indent, index, index, prefix, member.len, index) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 791 | indent = self.incIndent(indent) |
| 792 | local_prefix = '%s[%s].' % (new_prefix, index) |
| 793 | # Process sub-structs in this struct |
| Mark Lobodzinski | 8c0d3f9 | 2018-09-13 10:45:20 -0600 | [diff] [blame] | 794 | tmp_pre = self.validate_objects(struct_info, indent, local_prefix, array_index, disp_name, member.type, False) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 795 | pre_code += tmp_pre |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 796 | indent = self.decIndent(indent) |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 797 | pre_code += '%s}\n' % indent |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 798 | indent = self.decIndent(indent) |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 799 | pre_code += '%s}\n' % indent |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 800 | # Single Struct |
| Jeff Bolz | ba74d97 | 2018-09-12 15:54:57 -0500 | [diff] [blame] | 801 | elif ispointer: |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 802 | # Update struct prefix |
| 803 | new_prefix = '%s%s->' % (prefix, member.name) |
| 804 | # Declare safe_VarType for struct |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 805 | pre_code += '%sif (%s%s) {\n' % (indent, prefix, member.name) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 806 | indent = self.incIndent(indent) |
| 807 | # Process sub-structs in this struct |
| Mark Lobodzinski | 8c0d3f9 | 2018-09-13 10:45:20 -0600 | [diff] [blame] | 808 | tmp_pre = self.validate_objects(struct_info, indent, new_prefix, array_index, disp_name, member.type, False) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 809 | pre_code += tmp_pre |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 810 | indent = self.decIndent(indent) |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 811 | pre_code += '%s}\n' % indent |
| Mark Lobodzinski | 8c0d3f9 | 2018-09-13 10:45:20 -0600 | [diff] [blame] | 812 | return pre_code |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 813 | # |
| 814 | # For a particular API, generate the object handling code |
| 815 | def generate_wrapping_code(self, cmd): |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 816 | indent = ' ' |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 817 | pre_call_validate = '' |
| 818 | pre_call_record = '' |
| 819 | post_call_record = '' |
| 820 | |
| 821 | destroy_array = False |
| 822 | validate_destroy_code = '' |
| 823 | record_destroy_code = '' |
| 824 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 825 | proto = cmd.find('proto/name') |
| 826 | params = cmd.findall('param') |
| 827 | if proto.text is not None: |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 828 | cmddata = self.cmd_info_dict[proto.text] |
| 829 | cmd_info = cmddata.members |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 830 | disp_name = cmd_info[0].name |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 831 | # Handle object create operations if last parameter is created by this call |
| 832 | if cmddata.iscreate: |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 833 | post_call_record += self.generate_create_object_code(indent, proto, params, cmd_info, cmddata.allocator) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 834 | # Handle object destroy operations |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 835 | if cmddata.isdestroy: |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 836 | (destroy_array, validate_destroy_code, record_destroy_code) = self.generate_destroy_object_code(indent, proto, cmd_info) |
| Mark Lobodzinski | 2a51e80 | 2018-09-12 16:07:01 -0600 | [diff] [blame] | 837 | |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 838 | pre_call_record += record_destroy_code |
| 839 | pre_call_validate += self.validate_objects(cmd_info, indent, '', 0, disp_name, proto.text, True) |
| 840 | pre_call_validate += validate_destroy_code |
| 841 | |
| 842 | return pre_call_validate, pre_call_record, post_call_record |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 843 | # |
| 844 | # Capture command parameter info needed to create, destroy, and validate objects |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 845 | def genCmd(self, cmdinfo, cmdname, alias): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 846 | |
| 847 | # Add struct-member type information to command parameter information |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 848 | OutputGenerator.genCmd(self, cmdinfo, cmdname, alias) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 849 | members = cmdinfo.elem.findall('.//param') |
| 850 | # Iterate over members once to get length parameters for arrays |
| 851 | lens = set() |
| 852 | for member in members: |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 853 | length = self.getLen(member) |
| 854 | if length: |
| 855 | lens.add(length) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 856 | struct_member_dict = dict(self.structMembers) |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 857 | |
| 858 | # Set command invariant information needed at a per member level in validate... |
| 859 | is_create_command = any(filter(lambda pat: pat in cmdname, ('Create', 'Allocate', 'Enumerate', 'RegisterDeviceEvent', 'RegisterDisplayEvent'))) |
| 860 | last_member_is_pointer = len(members) and self.paramIsPointer(members[-1]) |
| 861 | iscreate = is_create_command or ('vkGet' in cmdname and last_member_is_pointer) |
| 862 | isdestroy = any([destroy_txt in cmdname for destroy_txt in ['Destroy', 'Free']]) |
| 863 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 864 | # Generate member info |
| 865 | membersInfo = [] |
| 866 | constains_extension_structs = False |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 867 | allocator = 'nullptr' |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 868 | for member in members: |
| 869 | # Get type and name of member |
| 870 | info = self.getTypeNameTuple(member) |
| 871 | type = info[0] |
| 872 | name = info[1] |
| 873 | cdecl = self.makeCParamDecl(member, 0) |
| 874 | # Check for parameter name in lens set |
| 875 | iscount = True if name in lens else False |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 876 | length = self.getLen(member) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 877 | isconst = True if 'const' in cdecl else False |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 878 | # Mark param as local if it is an array of objects |
| 879 | islocal = False; |
| 880 | if self.isHandleTypeObject(type) == True: |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 881 | if (length is not None) and (isconst == True): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 882 | islocal = True |
| 883 | # Or if it's a struct that contains an object |
| 884 | elif type in struct_member_dict: |
| 885 | if self.struct_contains_object(type) == True: |
| 886 | islocal = True |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 887 | if type == 'VkAllocationCallbacks': |
| 888 | allocator = name |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 889 | extstructs = member.attrib.get('validextensionstructs') if name == 'pNext' else None |
| 890 | membersInfo.append(self.CommandParam(type=type, |
| 891 | name=name, |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 892 | isconst=isconst, |
| 893 | isoptional=self.paramIsOptional(member), |
| 894 | iscount=iscount, |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 895 | len=length, |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 896 | extstructs=extstructs, |
| 897 | cdecl=cdecl, |
| 898 | islocal=islocal, |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 899 | iscreate=iscreate)) |
| 900 | |
| 901 | self.cmd_list.append(cmdname) |
| 902 | self.cmd_info_dict[cmdname] =self.CmdInfoData(name=cmdname, cmdinfo=cmdinfo, members=membersInfo, iscreate=iscreate, isdestroy=isdestroy, allocator=allocator, extra_protect=self.featureExtraProtect, alias=alias) |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 903 | # |
| 904 | # Create code Create, Destroy, and validate Vulkan objects |
| 905 | def WrapCommands(self): |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 906 | for cmdname in self.cmd_list: |
| 907 | cmddata = self.cmd_info_dict[cmdname] |
| 908 | cmdinfo = cmddata.cmdinfo |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 909 | if cmdname in self.interface_functions: |
| 910 | continue |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 911 | manual = False |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 912 | if cmdname in self.no_autogen_list: |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 913 | manual = True |
| 914 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 915 | # Generate object handling code |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 916 | (pre_call_validate, pre_call_record, post_call_record) = self.generate_wrapping_code(cmdinfo.elem) |
| 917 | |
| John Zulauf | bb6e5e4 | 2018-08-06 16:00:07 -0600 | [diff] [blame] | 918 | feature_extra_protect = cmddata.extra_protect |
| Michał Janiszewski | 3c3ce9e | 2018-10-30 23:25:21 +0100 | [diff] [blame] | 919 | if (feature_extra_protect is not None): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 920 | self.appendSection('command', '') |
| 921 | self.appendSection('command', '#ifdef '+ feature_extra_protect) |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 922 | self.prototypes += [ '#ifdef %s' % feature_extra_protect ] |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 923 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 924 | # Add intercept to procmap |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 925 | self.prototypes += [ ' {"%s", (void*)%s},' % (cmdname,cmdname[2:]) ] |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 926 | |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 927 | decls = self.makeCDecls(cmdinfo.elem) |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 928 | |
| 929 | # Gather the parameter items |
| 930 | params = cmdinfo.elem.findall('param/name') |
| 931 | # Pull out the text for each of the parameters, separate them by commas in a list |
| 932 | paramstext = ', '.join([str(param.text) for param in params]) |
| 933 | # Generate the API call template |
| 934 | fcn_call = cmdinfo.elem.attrib.get('name').replace('vk', 'TOKEN', 1) + '(' + paramstext + ');' |
| 935 | |
| 936 | func_decl_template = decls[0][:-1].split('VKAPI_CALL ') |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 937 | func_decl_template = func_decl_template[1] |
| Mark Lobodzinski | a9e7e9c | 2018-09-13 13:29:49 -0600 | [diff] [blame] | 938 | |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 939 | result_type = cmdinfo.elem.find('proto/type') |
| 940 | |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 941 | if 'object_tracker.h' in self.genOpts.filename: |
| 942 | # Output PreCallValidateAPI prototype if necessary |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 943 | if pre_call_validate: |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 944 | pre_cv_func_decl = 'bool PreCallValidate' + func_decl_template + ';' |
| 945 | self.appendSection('command', pre_cv_func_decl) |
| 946 | |
| 947 | # Output PreCallRecordAPI prototype if necessary |
| 948 | if pre_call_record: |
| 949 | pre_cr_func_decl = 'void PreCallRecord' + func_decl_template + ';' |
| 950 | self.appendSection('command', pre_cr_func_decl) |
| 951 | |
| 952 | # Output PosCallRecordAPI prototype if necessary |
| 953 | if post_call_record: |
| 954 | post_cr_func_decl = 'void PostCallRecord' + func_decl_template + ';' |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 955 | if result_type.text == 'VkResult': |
| 956 | post_cr_func_decl = post_cr_func_decl.replace(')', ',\n VkResult result)') |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 957 | self.appendSection('command', post_cr_func_decl) |
| 958 | |
| 959 | if 'object_tracker.cpp' in self.genOpts.filename: |
| 960 | # Output PreCallValidateAPI function if necessary |
| 961 | if pre_call_validate and not manual: |
| 962 | pre_cv_func_decl = 'bool ObjectLifetimes::PreCallValidate' + func_decl_template + ' {' |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 963 | self.appendSection('command', '') |
| 964 | self.appendSection('command', pre_cv_func_decl) |
| 965 | self.appendSection('command', ' bool skip = false;') |
| 966 | self.appendSection('command', pre_call_validate) |
| 967 | self.appendSection('command', ' return skip;') |
| 968 | self.appendSection('command', '}') |
| 969 | |
| 970 | # Output PreCallRecordAPI function if necessary |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 971 | if pre_call_record and not manual: |
| 972 | pre_cr_func_decl = 'void ObjectLifetimes::PreCallRecord' + func_decl_template + ' {' |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 973 | self.appendSection('command', '') |
| 974 | self.appendSection('command', pre_cr_func_decl) |
| 975 | self.appendSection('command', pre_call_record) |
| 976 | self.appendSection('command', '}') |
| 977 | |
| 978 | # Output PosCallRecordAPI function if necessary |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 979 | if post_call_record and not manual: |
| 980 | post_cr_func_decl = 'void ObjectLifetimes::PostCallRecord' + func_decl_template + ' {' |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 981 | self.appendSection('command', '') |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 982 | |
| 983 | if result_type.text == 'VkResult': |
| 984 | post_cr_func_decl = post_cr_func_decl.replace(')', ',\n VkResult result)') |
| Mark Lobodzinski | fd2d0a4 | 2019-02-20 16:34:56 -0700 | [diff] [blame] | 985 | # The two createpipelines APIs may create on failure -- skip the success result check |
| 986 | if 'CreateGraphicsPipelines' not in cmdname and 'CreateComputePipelines' not in cmdname and 'CreateRayTracingPipelines' not in cmdname: |
| 987 | post_cr_func_decl = post_cr_func_decl.replace('{', '{\n if (result != VK_SUCCESS) return;') |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 988 | self.appendSection('command', post_cr_func_decl) |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 989 | |
| 990 | |
| Mark Lobodzinski | 63902f0 | 2018-09-21 10:36:44 -0600 | [diff] [blame] | 991 | self.appendSection('command', post_call_record) |
| 992 | self.appendSection('command', '}') |
| 993 | |
| Michał Janiszewski | 3c3ce9e | 2018-10-30 23:25:21 +0100 | [diff] [blame] | 994 | if (feature_extra_protect is not None): |
| Mark Lobodzinski | d146148 | 2017-07-18 13:56:09 -0600 | [diff] [blame] | 995 | self.appendSection('command', '#endif // '+ feature_extra_protect) |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 996 | self.prototypes += [ '#endif' ] |