| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1 | #!/usr/bin/python3 -i |
| 2 | # |
| Mark Lobodzinski | d939fcb | 2019-01-10 15:49:12 -0700 | [diff] [blame] | 3 | # Copyright (c) 2015-2019 Valve Corporation |
| 4 | # Copyright (c) 2015-2019 LunarG, Inc. |
| 5 | # Copyright (c) 2015-2019 Google Inc. |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # |
| 19 | # Author: Tobin Ehlis <tobine@google.com> |
| 20 | # Author: Mark Lobodzinski <mark@lunarg.com> |
| 21 | # |
| 22 | # This script generates the dispatch portion of a factory layer which intercepts |
| 23 | # all Vulkan functions. The resultant factory layer allows rapid development of |
| 24 | # layers and interceptors. |
| 25 | |
| 26 | import os,re,sys |
| 27 | from generator import * |
| 28 | from common_codegen import * |
| 29 | |
| 30 | # LayerFactoryGeneratorOptions - subclass of GeneratorOptions. |
| 31 | # |
| 32 | # Adds options used by LayerFactoryOutputGenerator objects during factory |
| 33 | # layer generation. |
| 34 | # |
| 35 | # Additional members |
| 36 | # prefixText - list of strings to prefix generated header with |
| 37 | # (usually a copyright statement + calling convention macros). |
| 38 | # protectFile - True if multiple inclusion protection should be |
| 39 | # generated (based on the filename) around the entire header. |
| 40 | # protectFeature - True if #ifndef..#endif protection should be |
| 41 | # generated around a feature interface in the header file. |
| 42 | # genFuncPointers - True if function pointer typedefs should be |
| 43 | # generated |
| 44 | # protectProto - If conditional protection should be generated |
| 45 | # around prototype declarations, set to either '#ifdef' |
| 46 | # to require opt-in (#ifdef protectProtoStr) or '#ifndef' |
| 47 | # to require opt-out (#ifndef protectProtoStr). Otherwise |
| 48 | # set to None. |
| 49 | # protectProtoStr - #ifdef/#ifndef symbol to use around prototype |
| 50 | # declarations, if protectProto is set |
| 51 | # apicall - string to use for the function declaration prefix, |
| 52 | # such as APICALL on Windows. |
| 53 | # apientry - string to use for the calling convention macro, |
| 54 | # in typedefs, such as APIENTRY. |
| 55 | # apientryp - string to use for the calling convention macro |
| 56 | # in function pointer typedefs, such as APIENTRYP. |
| 57 | # indentFuncProto - True if prototype declarations should put each |
| 58 | # parameter on a separate line |
| 59 | # indentFuncPointer - True if typedefed function pointers should put each |
| 60 | # parameter on a separate line |
| 61 | # alignFuncParam - if nonzero and parameters are being put on a |
| 62 | # separate line, align parameter names at the specified column |
| 63 | class LayerChassisGeneratorOptions(GeneratorOptions): |
| 64 | def __init__(self, |
| 65 | filename = None, |
| 66 | directory = '.', |
| 67 | apiname = None, |
| 68 | profile = None, |
| 69 | versions = '.*', |
| 70 | emitversions = '.*', |
| 71 | defaultExtensions = None, |
| 72 | addExtensions = None, |
| 73 | removeExtensions = None, |
| 74 | emitExtensions = None, |
| 75 | sortProcedure = regSortFeatures, |
| 76 | prefixText = "", |
| 77 | genFuncPointers = True, |
| 78 | protectFile = True, |
| 79 | protectFeature = True, |
| 80 | apicall = '', |
| 81 | apientry = '', |
| 82 | apientryp = '', |
| 83 | indentFuncProto = True, |
| 84 | indentFuncPointer = False, |
| 85 | alignFuncParam = 0, |
| 86 | helper_file_type = '', |
| 87 | expandEnumerants = True): |
| 88 | GeneratorOptions.__init__(self, filename, directory, apiname, profile, |
| 89 | versions, emitversions, defaultExtensions, |
| 90 | addExtensions, removeExtensions, emitExtensions, sortProcedure) |
| 91 | self.prefixText = prefixText |
| 92 | self.genFuncPointers = genFuncPointers |
| 93 | self.protectFile = protectFile |
| 94 | self.protectFeature = protectFeature |
| 95 | self.apicall = apicall |
| 96 | self.apientry = apientry |
| 97 | self.apientryp = apientryp |
| 98 | self.indentFuncProto = indentFuncProto |
| 99 | self.indentFuncPointer = indentFuncPointer |
| 100 | self.alignFuncParam = alignFuncParam |
| 101 | |
| 102 | # LayerChassisOutputGenerator - subclass of OutputGenerator. |
| 103 | # Generates a LayerFactory layer that intercepts all API entrypoints |
| 104 | # This is intended to be used as a starting point for creating custom layers |
| 105 | # |
| 106 | # ---- methods ---- |
| 107 | # LayerChassisOutputGenerator(errFile, warnFile, diagFile) - args as for |
| 108 | # OutputGenerator. Defines additional internal state. |
| 109 | # ---- methods overriding base class ---- |
| 110 | # beginFile(genOpts) |
| 111 | # endFile() |
| 112 | # beginFeature(interface, emit) |
| 113 | # endFeature() |
| 114 | # genType(typeinfo,name) |
| 115 | # genStruct(typeinfo,name) |
| 116 | # genGroup(groupinfo,name) |
| 117 | # genEnum(enuminfo, name) |
| 118 | # genCmd(cmdinfo) |
| 119 | class LayerChassisOutputGenerator(OutputGenerator): |
| 120 | """Generate specified API interfaces in a specific style, such as a C header""" |
| 121 | # This is an ordered list of sections in the header file. |
| 122 | TYPE_SECTIONS = ['include', 'define', 'basetype', 'handle', 'enum', |
| 123 | 'group', 'bitmask', 'funcpointer', 'struct'] |
| 124 | ALL_SECTIONS = TYPE_SECTIONS + ['command'] |
| 125 | |
| Mark Lobodzinski | 09f8636 | 2018-12-13 14:07:20 -0700 | [diff] [blame] | 126 | manual_functions = [ |
| 127 | # Include functions here to be interecpted w/ manually implemented function bodies |
| 128 | 'vkGetDeviceProcAddr', |
| 129 | 'vkGetInstanceProcAddr', |
| 130 | 'vkGetPhysicalDeviceProcAddr', |
| 131 | 'vkCreateDevice', |
| 132 | 'vkDestroyDevice', |
| 133 | 'vkCreateInstance', |
| 134 | 'vkDestroyInstance', |
| 135 | 'vkCreateDebugReportCallbackEXT', |
| 136 | 'vkDestroyDebugReportCallbackEXT', |
| 137 | 'vkEnumerateInstanceLayerProperties', |
| 138 | 'vkEnumerateInstanceExtensionProperties', |
| 139 | 'vkEnumerateDeviceLayerProperties', |
| 140 | 'vkEnumerateDeviceExtensionProperties', |
| 141 | ] |
| 142 | |
| 143 | alt_ret_codes = [ |
| 144 | # Include functions here which must tolerate VK_INCOMPLETE as a return code |
| 145 | 'vkEnumeratePhysicalDevices', |
| 146 | 'vkEnumeratePhysicalDeviceGroupsKHR', |
| 147 | 'vkGetValidationCacheDataEXT', |
| 148 | 'vkGetPipelineCacheData', |
| 149 | 'vkGetShaderInfoAMD', |
| 150 | 'vkGetPhysicalDeviceDisplayPropertiesKHR', |
| 151 | 'vkGetPhysicalDeviceDisplayProperties2KHR', |
| 152 | 'vkGetPhysicalDeviceDisplayPlanePropertiesKHR', |
| 153 | 'vkGetDisplayPlaneSupportedDisplaysKHR', |
| 154 | 'vkGetDisplayModePropertiesKHR', |
| 155 | 'vkGetDisplayModeProperties2KHR', |
| 156 | 'vkGetPhysicalDeviceSurfaceFormatsKHR', |
| 157 | 'vkGetPhysicalDeviceSurfacePresentModesKHR', |
| 158 | 'vkGetPhysicalDevicePresentRectanglesKHR', |
| 159 | 'vkGetPastPresentationTimingGOOGLE', |
| 160 | 'vkGetSwapchainImagesKHR', |
| 161 | 'vkEnumerateInstanceLayerProperties', |
| 162 | 'vkEnumerateDeviceLayerProperties', |
| 163 | 'vkEnumerateInstanceExtensionProperties', |
| 164 | 'vkEnumerateDeviceExtensionProperties', |
| 165 | 'vkGetPhysicalDeviceCalibrateableTimeDomainsEXT', |
| 166 | ] |
| 167 | |
| Mark Lobodzinski | f57e828 | 2018-12-13 11:34:33 -0700 | [diff] [blame] | 168 | pre_dispatch_debug_utils_functions = { |
| 169 | 'vkSetDebugUtilsObjectNameEXT' : 'layer_data->report_data->debugUtilsObjectNameMap->insert(std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->objectHandle, pNameInfo->pObjectName));', |
| 170 | 'vkQueueBeginDebugUtilsLabelEXT' : 'BeginQueueDebugUtilsLabel(layer_data->report_data, queue, pLabelInfo);', |
| 171 | 'vkQueueInsertDebugUtilsLabelEXT' : 'InsertQueueDebugUtilsLabel(layer_data->report_data, queue, pLabelInfo);', |
| 172 | 'vkCmdBeginDebugUtilsLabelEXT' : 'BeginCmdDebugUtilsLabel(layer_data->report_data, commandBuffer, pLabelInfo);', |
| 173 | 'vkCmdInsertDebugUtilsLabelEXT' : 'InsertCmdDebugUtilsLabel(layer_data->report_data, commandBuffer, pLabelInfo);' |
| 174 | } |
| 175 | |
| 176 | post_dispatch_debug_utils_functions = { |
| 177 | 'vkQueueEndDebugUtilsLabelEXT' : 'EndQueueDebugUtilsLabel(layer_data->report_data, queue);', |
| 178 | 'vkCmdEndDebugUtilsLabelEXT' : 'EndCmdDebugUtilsLabel(layer_data->report_data, commandBuffer);', |
| 179 | 'vkCmdInsertDebugUtilsLabelEXT' : 'InsertCmdDebugUtilsLabel(layer_data->report_data, commandBuffer, pLabelInfo);' |
| 180 | } |
| 181 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 182 | precallvalidate_loop = "for (auto intercept : layer_data->object_dispatch) {" |
| 183 | precallrecord_loop = precallvalidate_loop |
| 184 | postcallrecord_loop = "for (auto intercept : layer_data->object_dispatch) {" |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 185 | |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 186 | inline_custom_header_preamble = """ |
| 187 | #define NOMINMAX |
| 188 | #include <mutex> |
| 189 | #include <cinttypes> |
| 190 | #include <stdio.h> |
| 191 | #include <stdlib.h> |
| 192 | #include <string.h> |
| 193 | #include <unordered_map> |
| 194 | #include <unordered_set> |
| 195 | #include <algorithm> |
| 196 | #include <memory> |
| 197 | |
| 198 | #include "vk_loader_platform.h" |
| 199 | #include "vulkan/vulkan.h" |
| 200 | #include "vk_layer_config.h" |
| 201 | #include "vk_layer_data.h" |
| 202 | #include "vk_layer_logging.h" |
| 203 | #include "vk_object_types.h" |
| 204 | #include "vulkan/vk_layer.h" |
| 205 | #include "vk_enum_string_helper.h" |
| 206 | #include "vk_layer_extension_utils.h" |
| 207 | #include "vk_layer_utils.h" |
| 208 | #include "vulkan/vk_layer.h" |
| 209 | #include "vk_dispatch_table_helper.h" |
| 210 | #include "vk_validation_error_messages.h" |
| 211 | #include "vk_extension_helper.h" |
| 212 | #include "vk_safe_struct.h" |
| 213 | |
| 214 | extern uint64_t global_unique_id; |
| 215 | extern std::unordered_map<uint64_t, uint64_t> unique_id_mapping; |
| 216 | """ |
| 217 | |
| 218 | inline_custom_header_class_definition = """ |
| 219 | |
| 220 | // Layer object type identifiers |
| 221 | enum LayerObjectTypeId { |
| 222 | LayerObjectTypeThreading, |
| 223 | LayerObjectTypeParameterValidation, |
| 224 | LayerObjectTypeObjectTracker, |
| 225 | LayerObjectTypeCoreValidation, |
| 226 | }; |
| 227 | |
| 228 | struct TEMPLATE_STATE { |
| 229 | VkDescriptorUpdateTemplateKHR desc_update_template; |
| 230 | safe_VkDescriptorUpdateTemplateCreateInfo create_info; |
| 231 | |
| 232 | TEMPLATE_STATE(VkDescriptorUpdateTemplateKHR update_template, safe_VkDescriptorUpdateTemplateCreateInfo *pCreateInfo) |
| 233 | : desc_update_template(update_template), create_info(*pCreateInfo) {} |
| 234 | }; |
| 235 | |
| Mark Lobodzinski | cc4e4a2 | 2018-12-18 16:16:21 -0700 | [diff] [blame] | 236 | class LAYER_PHYS_DEV_PROPERTIES { |
| 237 | public: |
| 238 | VkPhysicalDeviceProperties properties; |
| 239 | std::vector<VkQueueFamilyProperties> queue_family_properties; |
| 240 | }; |
| 241 | |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 242 | // Layer chassis validation object base class definition |
| 243 | class ValidationObject { |
| 244 | public: |
| 245 | uint32_t api_version; |
| 246 | debug_report_data* report_data = nullptr; |
| 247 | std::vector<VkDebugReportCallbackEXT> logging_callback; |
| 248 | std::vector<VkDebugUtilsMessengerEXT> logging_messenger; |
| 249 | |
| 250 | VkLayerInstanceDispatchTable instance_dispatch_table; |
| 251 | VkLayerDispatchTable device_dispatch_table; |
| 252 | |
| 253 | InstanceExtensions instance_extensions; |
| 254 | DeviceExtensions device_extensions = {}; |
| 255 | |
| 256 | VkInstance instance = VK_NULL_HANDLE; |
| 257 | VkPhysicalDevice physical_device = VK_NULL_HANDLE; |
| 258 | VkDevice device = VK_NULL_HANDLE; |
| Mark Lobodzinski | cc4e4a2 | 2018-12-18 16:16:21 -0700 | [diff] [blame] | 259 | LAYER_PHYS_DEV_PROPERTIES phys_dev_properties = {}; |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 260 | |
| 261 | std::vector<ValidationObject*> object_dispatch; |
| 262 | LayerObjectTypeId container_type; |
| 263 | |
| 264 | // Constructor |
| 265 | ValidationObject(){}; |
| 266 | // Destructor |
| 267 | virtual ~ValidationObject() {}; |
| 268 | |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 269 | std::mutex validation_object_mutex; |
| 270 | virtual void write_lock() { validation_object_mutex.lock(); } |
| 271 | virtual void write_unlock() { validation_object_mutex.unlock(); } |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 272 | |
| Mark Lobodzinski | 64b39c1 | 2018-12-25 10:01:48 -0700 | [diff] [blame] | 273 | ValidationObject* GetValidationObject(std::vector<ValidationObject*>& object_dispatch, LayerObjectTypeId object_type) { |
| 274 | for (auto validation_object : object_dispatch) { |
| 275 | if (validation_object->container_type == object_type) { |
| 276 | return validation_object; |
| 277 | } |
| 278 | } |
| 279 | return nullptr; |
| 280 | }; |
| 281 | |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 282 | std::string layer_name = "CHASSIS"; |
| 283 | |
| 284 | // Handle Wrapping Data |
| 285 | // Reverse map display handles |
| 286 | std::unordered_map<VkDisplayKHR, uint64_t> display_id_reverse_mapping; |
| 287 | std::unordered_map<uint64_t, std::unique_ptr<TEMPLATE_STATE>> desc_template_map; |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 288 | struct SubpassesUsageStates { |
| 289 | std::unordered_set<uint32_t> subpasses_using_color_attachment; |
| 290 | std::unordered_set<uint32_t> subpasses_using_depthstencil_attachment; |
| 291 | }; |
| 292 | // Uses unwrapped handles |
| 293 | std::unordered_map<VkRenderPass, SubpassesUsageStates> renderpasses_states; |
| 294 | // Map of wrapped swapchain handles to arrays of wrapped swapchain image IDs |
| 295 | // Each swapchain has an immutable list of wrapped swapchain image IDs -- always return these IDs if they exist |
| 296 | std::unordered_map<VkSwapchainKHR, std::vector<VkImage>> swapchain_wrapped_image_handle_map; |
| Mike Schuchardt | 1df790d | 2018-12-11 16:24:47 -0700 | [diff] [blame] | 297 | // Map of wrapped descriptor pools to set of wrapped descriptor sets allocated from each pool |
| 298 | std::unordered_map<VkDescriptorPool, std::unordered_set<VkDescriptorSet>> pool_descriptor_sets_map; |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 299 | |
| 300 | |
| 301 | // Unwrap a handle. Must hold lock. |
| 302 | template <typename HandleType> |
| 303 | HandleType Unwrap(HandleType wrappedHandle) { |
| 304 | // TODO: don't use operator[] here. |
| 305 | return (HandleType)unique_id_mapping[reinterpret_cast<uint64_t const &>(wrappedHandle)]; |
| 306 | } |
| 307 | |
| 308 | // Wrap a newly created handle with a new unique ID, and return the new ID -- must hold lock. |
| 309 | template <typename HandleType> |
| 310 | HandleType WrapNew(HandleType newlyCreatedHandle) { |
| 311 | auto unique_id = global_unique_id++; |
| 312 | unique_id_mapping[unique_id] = reinterpret_cast<uint64_t const &>(newlyCreatedHandle); |
| 313 | return (HandleType)unique_id; |
| 314 | } |
| 315 | |
| 316 | // Specialized handling for VkDisplayKHR. Adds an entry to enable reverse-lookup. Must hold lock. |
| 317 | VkDisplayKHR WrapDisplay(VkDisplayKHR newlyCreatedHandle, ValidationObject *map_data) { |
| 318 | auto unique_id = global_unique_id++; |
| 319 | unique_id_mapping[unique_id] = reinterpret_cast<uint64_t const &>(newlyCreatedHandle); |
| 320 | map_data->display_id_reverse_mapping[newlyCreatedHandle] = unique_id; |
| 321 | return (VkDisplayKHR)unique_id; |
| 322 | } |
| 323 | |
| 324 | // VkDisplayKHR objects don't have a single point of creation, so we need to see if one already exists in the map before |
| 325 | // creating another. Must hold lock. |
| 326 | VkDisplayKHR MaybeWrapDisplay(VkDisplayKHR handle, ValidationObject *map_data) { |
| 327 | // See if this display is already known |
| 328 | auto it = map_data->display_id_reverse_mapping.find(handle); |
| 329 | if (it != map_data->display_id_reverse_mapping.end()) return (VkDisplayKHR)it->second; |
| 330 | // Unknown, so wrap |
| 331 | return WrapDisplay(handle, map_data); |
| 332 | } |
| 333 | |
| 334 | // Pre/post hook point declarations |
| 335 | """ |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 336 | |
| Mark Lobodzinski | d03ed35 | 2018-11-09 09:34:24 -0700 | [diff] [blame] | 337 | inline_copyright_message = """ |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 338 | // This file is ***GENERATED***. Do Not Edit. |
| 339 | // See layer_chassis_generator.py for modifications. |
| 340 | |
| Shannon McPherson | 9a4ae98 | 2019-01-07 16:05:25 -0700 | [diff] [blame] | 341 | /* Copyright (c) 2015-2019 The Khronos Group Inc. |
| 342 | * Copyright (c) 2015-2019 Valve Corporation |
| 343 | * Copyright (c) 2015-2019 LunarG, Inc. |
| 344 | * Copyright (c) 2015-2019 Google Inc. |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 345 | * |
| 346 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 347 | * you may not use this file except in compliance with the License. |
| 348 | * You may obtain a copy of the License at |
| 349 | * |
| 350 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 351 | * |
| 352 | * Unless required by applicable law or agreed to in writing, software |
| 353 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 354 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 355 | * See the License for the specific language governing permissions and |
| 356 | * limitations under the License. |
| 357 | * |
| 358 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| Mark Lobodzinski | d03ed35 | 2018-11-09 09:34:24 -0700 | [diff] [blame] | 359 | */""" |
| 360 | |
| 361 | inline_custom_source_preamble = """ |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 362 | |
| 363 | #include <string.h> |
| 364 | #include <mutex> |
| 365 | |
| 366 | #define VALIDATION_ERROR_MAP_IMPL |
| 367 | |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 368 | #include "chassis.h" |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 369 | #include "layer_chassis_dispatch.h" |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 370 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 371 | std::unordered_map<void*, ValidationObject*> layer_data_map; |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 372 | |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 373 | // Global unique object identifier. All increments must be guarded by a lock. |
| 374 | uint64_t global_unique_id = 1; |
| 375 | // Map uniqueID to actual object handle |
| 376 | std::unordered_map<uint64_t, uint64_t> unique_id_mapping; |
| 377 | |
| 378 | // TODO: This variable controls handle wrapping -- in the future it should be hooked |
| 379 | // up to the new VALIDATION_FEATURES extension. Temporarily, control with a compile-time flag. |
| 380 | #if defined(LAYER_CHASSIS_CAN_WRAP_HANDLES) |
| 381 | bool wrap_handles = true; |
| 382 | #else |
| 383 | const bool wrap_handles = false; |
| 384 | #endif |
| 385 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 386 | // Include child object (layer) definitions |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 387 | #if BUILD_OBJECT_TRACKER |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 388 | #include "object_lifetime_validation.h" |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 389 | #define OBJECT_LAYER_NAME "VK_LAYER_LUNARG_object_tracker" |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 390 | #elif BUILD_THREAD_SAFETY |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 391 | #include "thread_safety.h" |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 392 | #define OBJECT_LAYER_NAME "VK_LAYER_GOOGLE_threading" |
| 393 | #elif BUILD_PARAMETER_VALIDATION |
| Mark Lobodzinski | af7c038 | 2018-12-18 11:55:55 -0700 | [diff] [blame] | 394 | #include "stateless_validation.h" |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 395 | #define OBJECT_LAYER_NAME "VK_LAYER_LUNARG_parameter_validation" |
| 396 | #elif BUILD_CORE_VALIDATION |
| 397 | #define OBJECT_LAYER_NAME "VK_LAYER_LUNARG_core_validation" |
| 398 | #else |
| 399 | #define OBJECT_LAYER_NAME "VK_LAYER_GOOGLE_unique_objects" |
| 400 | #endif |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 401 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 402 | namespace vulkan_layer_chassis { |
| 403 | |
| 404 | using std::unordered_map; |
| 405 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 406 | static const VkLayerProperties global_layer = { |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 407 | OBJECT_LAYER_NAME, VK_LAYER_API_VERSION, 1, "LunarG validation Layer", |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 408 | }; |
| 409 | |
| 410 | static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}}; |
| 411 | |
| 412 | extern const std::unordered_map<std::string, void*> name_to_funcptr_map; |
| 413 | |
| 414 | |
| 415 | // Manually written functions |
| 416 | |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 417 | // Check enabled instance extensions against supported instance extension whitelist |
| 418 | static void InstanceExtensionWhitelist(ValidationObject *layer_data, const VkInstanceCreateInfo *pCreateInfo, VkInstance instance) { |
| 419 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 420 | // Check for recognized instance extensions |
| 421 | if (!white_list(pCreateInfo->ppEnabledExtensionNames[i], kInstanceExtensionNames)) { |
| 422 | log_msg(layer_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 423 | kVUIDUndefined, |
| 424 | "Instance Extension %s is not supported by this layer. Using this extension may adversely affect validation " |
| 425 | "results and/or produce undefined behavior.", |
| 426 | pCreateInfo->ppEnabledExtensionNames[i]); |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | // Check enabled device extensions against supported device extension whitelist |
| 432 | static void DeviceExtensionWhitelist(ValidationObject *layer_data, const VkDeviceCreateInfo *pCreateInfo, VkDevice device) { |
| 433 | for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { |
| 434 | // Check for recognized device extensions |
| 435 | if (!white_list(pCreateInfo->ppEnabledExtensionNames[i], kDeviceExtensionNames)) { |
| 436 | log_msg(layer_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 437 | kVUIDUndefined, |
| 438 | "Device Extension %s is not supported by this layer. Using this extension may adversely affect validation " |
| 439 | "results and/or produce undefined behavior.", |
| 440 | pCreateInfo->ppEnabledExtensionNames[i]); |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 445 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) { |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 446 | auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); |
| Mark Lobodzinski | cc4e4a2 | 2018-12-18 16:16:21 -0700 | [diff] [blame] | 447 | if (!ApiParentExtensionEnabled(funcName, layer_data->device_extensions.device_extension_set)) { |
| Mark Lobodzinski | 2fc88fe | 2018-12-11 12:28:57 -0700 | [diff] [blame] | 448 | return nullptr; |
| 449 | } |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 450 | const auto &item = name_to_funcptr_map.find(funcName); |
| 451 | if (item != name_to_funcptr_map.end()) { |
| 452 | return reinterpret_cast<PFN_vkVoidFunction>(item->second); |
| 453 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 454 | auto &table = layer_data->device_dispatch_table; |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 455 | if (!table.GetDeviceProcAddr) return nullptr; |
| 456 | return table.GetDeviceProcAddr(device, funcName); |
| 457 | } |
| 458 | |
| 459 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char *funcName) { |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 460 | const auto &item = name_to_funcptr_map.find(funcName); |
| 461 | if (item != name_to_funcptr_map.end()) { |
| 462 | return reinterpret_cast<PFN_vkVoidFunction>(item->second); |
| 463 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 464 | auto layer_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
| 465 | auto &table = layer_data->instance_dispatch_table; |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 466 | if (!table.GetInstanceProcAddr) return nullptr; |
| 467 | return table.GetInstanceProcAddr(instance, funcName); |
| 468 | } |
| 469 | |
| 470 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 471 | auto layer_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
| 472 | auto &table = layer_data->instance_dispatch_table; |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 473 | if (!table.GetPhysicalDeviceProcAddr) return nullptr; |
| 474 | return table.GetPhysicalDeviceProcAddr(instance, funcName); |
| 475 | } |
| 476 | |
| 477 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) { |
| 478 | return util_GetLayerProperties(1, &global_layer, pCount, pProperties); |
| 479 | } |
| 480 | |
| 481 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 482 | VkLayerProperties *pProperties) { |
| 483 | return util_GetLayerProperties(1, &global_layer, pCount, pProperties); |
| 484 | } |
| 485 | |
| 486 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 487 | VkExtensionProperties *pProperties) { |
| 488 | if (pLayerName && !strcmp(pLayerName, global_layer.layerName)) |
| 489 | return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties); |
| 490 | |
| 491 | return VK_ERROR_LAYER_NOT_PRESENT; |
| 492 | } |
| 493 | |
| 494 | VKAPI_ATTR VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, |
| 495 | uint32_t *pCount, VkExtensionProperties *pProperties) { |
| 496 | if (pLayerName && !strcmp(pLayerName, global_layer.layerName)) return util_GetExtensionProperties(0, NULL, pCount, pProperties); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 497 | assert(physicalDevice); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 498 | auto layer_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), layer_data_map); |
| 499 | return layer_data->instance_dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | VKAPI_ATTR VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, |
| 503 | VkInstance *pInstance) { |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 504 | VkLayerInstanceCreateInfo* chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 505 | |
| 506 | assert(chain_info->u.pLayerInfo); |
| 507 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 508 | PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); |
| 509 | if (fpCreateInstance == NULL) return VK_ERROR_INITIALIZATION_FAILED; |
| 510 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 511 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 512 | // Create temporary dispatch vector for pre-calls until instance is created |
| 513 | std::vector<ValidationObject*> local_object_dispatch; |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 514 | #if BUILD_OBJECT_TRACKER |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 515 | auto object_tracker = new ObjectLifetimes; |
| 516 | local_object_dispatch.emplace_back(object_tracker); |
| 517 | object_tracker->container_type = LayerObjectTypeObjectTracker; |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 518 | #elif BUILD_THREAD_SAFETY |
| 519 | auto thread_checker = new ThreadSafety; |
| 520 | local_object_dispatch.emplace_back(thread_checker); |
| 521 | thread_checker->container_type = LayerObjectTypeThreading; |
| Mark Lobodzinski | af7c038 | 2018-12-18 11:55:55 -0700 | [diff] [blame] | 522 | #elif BUILD_PARAMETER_VALIDATION |
| 523 | auto parameter_validation = new StatelessValidation; |
| 524 | local_object_dispatch.emplace_back(parameter_validation); |
| 525 | parameter_validation->container_type = LayerObjectTypeParameterValidation; |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 526 | #endif |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 527 | |
| 528 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 529 | // Init dispatch array and call registration functions |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 530 | for (auto intercept : local_object_dispatch) { |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 531 | intercept->PreCallValidateCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 532 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 533 | for (auto intercept : local_object_dispatch) { |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 534 | intercept->PreCallRecordCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 535 | } |
| 536 | |
| 537 | VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 538 | if (result != VK_SUCCESS) return result; |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 539 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 540 | auto framework = GetLayerDataPtr(get_dispatch_key(*pInstance), layer_data_map); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 541 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 542 | framework->object_dispatch = local_object_dispatch; |
| 543 | |
| 544 | framework->instance = *pInstance; |
| 545 | layer_init_instance_dispatch_table(*pInstance, &framework->instance_dispatch_table, fpGetInstanceProcAddr); |
| 546 | framework->report_data = debug_utils_create_instance(&framework->instance_dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount, |
| 547 | pCreateInfo->ppEnabledExtensionNames); |
| 548 | framework->api_version = framework->instance_extensions.InitFromInstanceCreateInfo( |
| 549 | (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0), pCreateInfo); |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 550 | #if BUILD_OBJECT_TRACKER |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 551 | layer_debug_messenger_actions(framework->report_data, framework->logging_messenger, pAllocator, "lunarg_object_tracker"); |
| Mark Lobodzinski | af7c038 | 2018-12-18 11:55:55 -0700 | [diff] [blame] | 552 | object_tracker->report_data = framework->report_data; |
| 553 | object_tracker->api_version = framework->api_version; |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 554 | #elif BUILD_THREAD_SAFETY |
| 555 | layer_debug_messenger_actions(framework->report_data, framework->logging_messenger, pAllocator, "google_thread_checker"); |
| Mark Lobodzinski | af7c038 | 2018-12-18 11:55:55 -0700 | [diff] [blame] | 556 | thread_checker->report_data = framework->report_data; |
| 557 | thread_checker->api_version = framework->api_version; |
| 558 | #elif BUILD_PARAMETER_VALIDATION |
| 559 | layer_debug_messenger_actions(framework->report_data, framework->logging_messenger, pAllocator, "lunarg_parameter_validation"); |
| 560 | parameter_validation->report_data = framework->report_data; |
| 561 | parameter_validation->api_version = framework->api_version; |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 562 | #else |
| 563 | layer_debug_messenger_actions(framework->report_data, framework->logging_messenger, pAllocator, "lunarg_unique_objects"); |
| 564 | #endif |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 565 | |
| 566 | for (auto intercept : framework->object_dispatch) { |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 567 | intercept->PostCallRecordCreateInstance(pCreateInfo, pAllocator, pInstance); |
| 568 | } |
| 569 | |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 570 | InstanceExtensionWhitelist(framework, pCreateInfo, *pInstance); |
| 571 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 572 | return result; |
| 573 | } |
| 574 | |
| 575 | VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { |
| 576 | dispatch_key key = get_dispatch_key(instance); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 577 | auto layer_data = GetLayerDataPtr(key, layer_data_map); |
| 578 | """ + precallvalidate_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 579 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 580 | intercept->PreCallValidateDestroyInstance(instance, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 581 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 582 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 583 | """ + precallrecord_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 584 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 585 | intercept->PreCallRecordDestroyInstance(instance, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 586 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 587 | } |
| 588 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 589 | layer_data->instance_dispatch_table.DestroyInstance(instance, pAllocator); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 590 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 591 | """ + postcallrecord_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 592 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 593 | intercept->PostCallRecordDestroyInstance(instance, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 594 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 595 | } |
| 596 | // Clean up logging callback, if any |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 597 | while (layer_data->logging_messenger.size() > 0) { |
| 598 | VkDebugUtilsMessengerEXT messenger = layer_data->logging_messenger.back(); |
| 599 | layer_destroy_messenger_callback(layer_data->report_data, messenger, pAllocator); |
| 600 | layer_data->logging_messenger.pop_back(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 601 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 602 | while (layer_data->logging_callback.size() > 0) { |
| 603 | VkDebugReportCallbackEXT callback = layer_data->logging_callback.back(); |
| 604 | layer_destroy_report_callback(layer_data->report_data, callback, pAllocator); |
| 605 | layer_data->logging_callback.pop_back(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 606 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 607 | |
| 608 | layer_debug_utils_destroy_instance(layer_data->report_data); |
| 609 | |
| Mark Lobodzinski | c500337 | 2018-12-17 16:36:01 -0700 | [diff] [blame] | 610 | for (auto item = layer_data->object_dispatch.begin(); item != layer_data->object_dispatch.end(); item++) { |
| 611 | delete *item; |
| 612 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 613 | FreeLayerDataPtr(key, layer_data_map); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo, |
| 617 | const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 618 | VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 619 | |
| 620 | auto instance_interceptor = GetLayerDataPtr(get_dispatch_key(gpu), layer_data_map); |
| 621 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 622 | PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; |
| 623 | PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 624 | PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(instance_interceptor->instance, "vkCreateDevice"); |
| 625 | if (fpCreateDevice == NULL) { |
| 626 | return VK_ERROR_INITIALIZATION_FAILED; |
| 627 | } |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 628 | chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; |
| 629 | |
| Mark Lobodzinski | 0068bd8 | 2018-12-28 12:08:44 -0700 | [diff] [blame] | 630 | // Get physical device limits for device |
| 631 | VkPhysicalDeviceProperties device_properties = {}; |
| 632 | instance_interceptor->instance_dispatch_table.GetPhysicalDeviceProperties(gpu, &device_properties); |
| 633 | |
| 634 | // Setup the validation tables based on the application API version from the instance and the capabilities of the device driver |
| 635 | uint32_t effective_api_version = std::min(device_properties.apiVersion, instance_interceptor->api_version); |
| 636 | |
| 637 | DeviceExtensions device_extensions = {}; |
| 638 | device_extensions.InitFromDeviceCreateInfo(&instance_interceptor->instance_extensions, effective_api_version, pCreateInfo); |
| 639 | for (auto item : instance_interceptor->object_dispatch) { |
| 640 | item->device_extensions = device_extensions; |
| 641 | } |
| 642 | |
| 643 | bool skip = false; |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 644 | for (auto intercept : instance_interceptor->object_dispatch) { |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 645 | intercept->write_lock(); |
| Mark Lobodzinski | 0068bd8 | 2018-12-28 12:08:44 -0700 | [diff] [blame] | 646 | skip |= intercept->PreCallValidateCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 647 | intercept->write_unlock(); |
| Mark Lobodzinski | 0068bd8 | 2018-12-28 12:08:44 -0700 | [diff] [blame] | 648 | if (skip) return VK_ERROR_VALIDATION_FAILED_EXT; |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 649 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 650 | for (auto intercept : instance_interceptor->object_dispatch) { |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 651 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 652 | intercept->PreCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 653 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 654 | } |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 655 | |
| 656 | VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 657 | if (result != VK_SUCCESS) { |
| 658 | return result; |
| 659 | } |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 660 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 661 | auto device_interceptor = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map); |
| Mark Lobodzinski | cc4e4a2 | 2018-12-18 16:16:21 -0700 | [diff] [blame] | 662 | |
| Mark Lobodzinski | 0068bd8 | 2018-12-28 12:08:44 -0700 | [diff] [blame] | 663 | // Save local info in device object |
| 664 | device_interceptor->phys_dev_properties.properties = device_properties; |
| Mark Lobodzinski | cc4e4a2 | 2018-12-18 16:16:21 -0700 | [diff] [blame] | 665 | device_interceptor->api_version = device_interceptor->device_extensions.InitFromDeviceCreateInfo( |
| 666 | &instance_interceptor->instance_extensions, effective_api_version, pCreateInfo); |
| Mark Lobodzinski | 0068bd8 | 2018-12-28 12:08:44 -0700 | [diff] [blame] | 667 | device_interceptor->device_extensions = device_extensions; |
| Mark Lobodzinski | cc4e4a2 | 2018-12-18 16:16:21 -0700 | [diff] [blame] | 668 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 669 | layer_init_device_dispatch_table(*pDevice, &device_interceptor->device_dispatch_table, fpGetDeviceProcAddr); |
| Mark Lobodzinski | cc4e4a2 | 2018-12-18 16:16:21 -0700 | [diff] [blame] | 670 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 671 | device_interceptor->device = *pDevice; |
| 672 | device_interceptor->physical_device = gpu; |
| 673 | device_interceptor->instance = instance_interceptor->instance; |
| 674 | device_interceptor->report_data = layer_debug_utils_create_device(instance_interceptor->report_data, *pDevice); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 675 | |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 676 | #if BUILD_OBJECT_TRACKER |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 677 | // Create child layer objects for this key and add to dispatch vector |
| 678 | auto object_tracker = new ObjectLifetimes; |
| 679 | // TODO: Initialize child objects with parent info thru constuctor taking a parent object |
| 680 | object_tracker->container_type = LayerObjectTypeObjectTracker; |
| 681 | object_tracker->physical_device = gpu; |
| 682 | object_tracker->instance = instance_interceptor->instance; |
| 683 | object_tracker->report_data = device_interceptor->report_data; |
| 684 | object_tracker->device_dispatch_table = device_interceptor->device_dispatch_table; |
| Mark Lobodzinski | af7c038 | 2018-12-18 11:55:55 -0700 | [diff] [blame] | 685 | object_tracker->api_version = device_interceptor->api_version; |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 686 | device_interceptor->object_dispatch.emplace_back(object_tracker); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 687 | #elif BUILD_THREAD_SAFETY |
| 688 | auto thread_safety = new ThreadSafety; |
| 689 | // TODO: Initialize child objects with parent info thru constuctor taking a parent object |
| 690 | thread_safety->container_type = LayerObjectTypeThreading; |
| 691 | thread_safety->physical_device = gpu; |
| 692 | thread_safety->instance = instance_interceptor->instance; |
| 693 | thread_safety->report_data = device_interceptor->report_data; |
| 694 | thread_safety->device_dispatch_table = device_interceptor->device_dispatch_table; |
| Mark Lobodzinski | af7c038 | 2018-12-18 11:55:55 -0700 | [diff] [blame] | 695 | thread_safety->api_version = device_interceptor->api_version; |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 696 | device_interceptor->object_dispatch.emplace_back(thread_safety); |
| Mark Lobodzinski | af7c038 | 2018-12-18 11:55:55 -0700 | [diff] [blame] | 697 | #elif BUILD_PARAMETER_VALIDATION |
| 698 | auto stateless_validation = new StatelessValidation; |
| 699 | // TODO: Initialize child objects with parent info thru constuctor taking a parent object |
| 700 | stateless_validation->container_type = LayerObjectTypeParameterValidation; |
| 701 | stateless_validation->physical_device = gpu; |
| 702 | stateless_validation->instance = instance_interceptor->instance; |
| 703 | stateless_validation->report_data = device_interceptor->report_data; |
| 704 | stateless_validation->device_dispatch_table = device_interceptor->device_dispatch_table; |
| 705 | stateless_validation->api_version = device_interceptor->api_version; |
| 706 | device_interceptor->object_dispatch.emplace_back(stateless_validation); |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 707 | #endif |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 708 | |
| 709 | for (auto intercept : instance_interceptor->object_dispatch) { |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 710 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 711 | intercept->PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 712 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 713 | } |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 714 | |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 715 | DeviceExtensionWhitelist(device_interceptor, pCreateInfo, *pDevice); |
| 716 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 717 | return result; |
| 718 | } |
| 719 | |
| 720 | VKAPI_ATTR void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { |
| 721 | dispatch_key key = get_dispatch_key(device); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 722 | auto layer_data = GetLayerDataPtr(key, layer_data_map); |
| 723 | """ + precallvalidate_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 724 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 725 | intercept->PreCallValidateDestroyDevice(device, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 726 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 727 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 728 | """ + precallrecord_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 729 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 730 | intercept->PreCallRecordDestroyDevice(device, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 731 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 732 | } |
| 733 | layer_debug_utils_destroy_device(device); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 734 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 735 | layer_data->device_dispatch_table.DestroyDevice(device, pAllocator); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 736 | |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 737 | """ + postcallrecord_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 738 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 739 | intercept->PostCallRecordDestroyDevice(device, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 740 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 741 | } |
| 742 | |
| Mark Lobodzinski | c500337 | 2018-12-17 16:36:01 -0700 | [diff] [blame] | 743 | for (auto item = layer_data->object_dispatch.begin(); item != layer_data->object_dispatch.end(); item++) { |
| 744 | delete *item; |
| 745 | } |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 746 | FreeLayerDataPtr(key, layer_data_map); |
| 747 | } |
| 748 | |
| 749 | VKAPI_ATTR VkResult VKAPI_CALL CreateDebugReportCallbackEXT(VkInstance instance, |
| 750 | const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, |
| 751 | const VkAllocationCallbacks *pAllocator, |
| 752 | VkDebugReportCallbackEXT *pCallback) { |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 753 | auto layer_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
| 754 | """ + precallvalidate_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 755 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 756 | intercept->PreCallValidateCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 757 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 758 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 759 | """ + precallrecord_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 760 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 761 | intercept->PreCallRecordCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 762 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 763 | } |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 764 | VkResult result = DispatchCreateDebugReportCallbackEXT(layer_data, instance, pCreateInfo, pAllocator, pCallback); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 765 | result = layer_create_report_callback(layer_data->report_data, false, pCreateInfo, pAllocator, pCallback); |
| 766 | """ + postcallrecord_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 767 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 768 | intercept->PostCallRecordCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 769 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 770 | } |
| 771 | return result; |
| 772 | } |
| 773 | |
| 774 | VKAPI_ATTR void VKAPI_CALL DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, |
| 775 | const VkAllocationCallbacks *pAllocator) { |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 776 | auto layer_data = GetLayerDataPtr(get_dispatch_key(instance), layer_data_map); |
| 777 | """ + precallvalidate_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 778 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 779 | intercept->PreCallValidateDestroyDebugReportCallbackEXT(instance, callback, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 780 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 781 | } |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 782 | """ + precallrecord_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 783 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 784 | intercept->PreCallRecordDestroyDebugReportCallbackEXT(instance, callback, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 785 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 786 | } |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 787 | DispatchDestroyDebugReportCallbackEXT(layer_data, instance, callback, pAllocator); |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 788 | layer_destroy_report_callback(layer_data->report_data, callback, pAllocator); |
| 789 | """ + postcallrecord_loop + """ |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 790 | intercept->write_lock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 791 | intercept->PostCallRecordDestroyDebugReportCallbackEXT(instance, callback, pAllocator); |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 792 | intercept->write_unlock(); |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 793 | } |
| Mark Lobodzinski | f57e828 | 2018-12-13 11:34:33 -0700 | [diff] [blame] | 794 | }""" |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 795 | |
| 796 | inline_custom_source_postamble = """ |
| 797 | // loader-layer interface v0, just wrappers since there is only a layer |
| 798 | |
| 799 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, |
| 800 | VkExtensionProperties *pProperties) { |
| 801 | return vulkan_layer_chassis::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); |
| 802 | } |
| 803 | |
| 804 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, |
| 805 | VkLayerProperties *pProperties) { |
| 806 | return vulkan_layer_chassis::EnumerateInstanceLayerProperties(pCount, pProperties); |
| 807 | } |
| 808 | |
| 809 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, |
| 810 | VkLayerProperties *pProperties) { |
| 811 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 812 | assert(physicalDevice == VK_NULL_HANDLE); |
| 813 | return vulkan_layer_chassis::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties); |
| 814 | } |
| 815 | |
| 816 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, |
| 817 | const char *pLayerName, uint32_t *pCount, |
| 818 | VkExtensionProperties *pProperties) { |
| 819 | // the layer command handles VK_NULL_HANDLE just fine internally |
| 820 | assert(physicalDevice == VK_NULL_HANDLE); |
| 821 | return vulkan_layer_chassis::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); |
| 822 | } |
| 823 | |
| 824 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) { |
| 825 | return vulkan_layer_chassis::GetDeviceProcAddr(dev, funcName); |
| 826 | } |
| 827 | |
| 828 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { |
| 829 | return vulkan_layer_chassis::GetInstanceProcAddr(instance, funcName); |
| 830 | } |
| 831 | |
| 832 | VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance, |
| 833 | const char *funcName) { |
| 834 | return vulkan_layer_chassis::GetPhysicalDeviceProcAddr(instance, funcName); |
| 835 | } |
| 836 | |
| 837 | VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) { |
| 838 | assert(pVersionStruct != NULL); |
| 839 | assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT); |
| 840 | |
| 841 | // Fill in the function pointers if our version is at least capable of having the structure contain them. |
| 842 | if (pVersionStruct->loaderLayerInterfaceVersion >= 2) { |
| 843 | pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr; |
| 844 | pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr; |
| 845 | pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr; |
| 846 | } |
| 847 | |
| 848 | return VK_SUCCESS; |
| 849 | }""" |
| 850 | |
| 851 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 852 | def __init__(self, |
| 853 | errFile = sys.stderr, |
| 854 | warnFile = sys.stderr, |
| 855 | diagFile = sys.stdout): |
| 856 | OutputGenerator.__init__(self, errFile, warnFile, diagFile) |
| 857 | # Internal state - accumulators for different inner block text |
| 858 | self.sections = dict([(section, []) for section in self.ALL_SECTIONS]) |
| 859 | self.intercepts = [] |
| 860 | self.layer_factory = '' # String containing base layer factory class definition |
| 861 | |
| 862 | # Check if the parameter passed in is a pointer to an array |
| 863 | def paramIsArray(self, param): |
| 864 | return param.attrib.get('len') is not None |
| 865 | |
| 866 | # Check if the parameter passed in is a pointer |
| 867 | def paramIsPointer(self, param): |
| 868 | ispointer = False |
| 869 | for elem in param: |
| 870 | if ((elem.tag is not 'type') and (elem.tail is not None)) and '*' in elem.tail: |
| 871 | ispointer = True |
| 872 | return ispointer |
| 873 | |
| 874 | # Check if an object is a non-dispatchable handle |
| 875 | def isHandleTypeNonDispatchable(self, handletype): |
| 876 | handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']") |
| 877 | if handle is not None and handle.find('type').text == 'VK_DEFINE_NON_DISPATCHABLE_HANDLE': |
| 878 | return True |
| 879 | else: |
| 880 | return False |
| 881 | |
| 882 | # Check if an object is a dispatchable handle |
| 883 | def isHandleTypeDispatchable(self, handletype): |
| 884 | handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']") |
| 885 | if handle is not None and handle.find('type').text == 'VK_DEFINE_HANDLE': |
| 886 | return True |
| 887 | else: |
| 888 | return False |
| Mark Lobodzinski | d03ed35 | 2018-11-09 09:34:24 -0700 | [diff] [blame] | 889 | # |
| 890 | # |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 891 | def beginFile(self, genOpts): |
| 892 | OutputGenerator.beginFile(self, genOpts) |
| Mark Lobodzinski | d03ed35 | 2018-11-09 09:34:24 -0700 | [diff] [blame] | 893 | # Output Copyright |
| 894 | write(self.inline_copyright_message, file=self.outFile) |
| 895 | # Multiple inclusion protection |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 896 | self.header = False |
| 897 | if (self.genOpts.filename and 'h' == self.genOpts.filename[-1]): |
| 898 | self.header = True |
| 899 | write('#pragma once', file=self.outFile) |
| 900 | self.newline() |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 901 | if self.header: |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 902 | write(self.inline_custom_header_preamble, file=self.outFile) |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 903 | else: |
| 904 | write(self.inline_custom_source_preamble, file=self.outFile) |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 905 | self.layer_factory += self.inline_custom_header_class_definition |
| Mark Lobodzinski | d03ed35 | 2018-11-09 09:34:24 -0700 | [diff] [blame] | 906 | # |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 907 | # |
| 908 | def endFile(self): |
| 909 | # Finish C++ namespace and multiple inclusion protection |
| 910 | self.newline() |
| 911 | if not self.header: |
| 912 | # Record intercepted procedures |
| 913 | write('// Map of all APIs to be intercepted by this layer', file=self.outFile) |
| 914 | write('const std::unordered_map<std::string, void*> name_to_funcptr_map = {', file=self.outFile) |
| 915 | write('\n'.join(self.intercepts), file=self.outFile) |
| 916 | write('};\n', file=self.outFile) |
| 917 | self.newline() |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 918 | write('} // namespace vulkan_layer_chassis', file=self.outFile) |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 919 | if self.header: |
| 920 | self.newline() |
| 921 | # Output Layer Factory Class Definitions |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 922 | self.layer_factory += '};\n\n' |
| 923 | self.layer_factory += 'extern std::unordered_map<void*, ValidationObject*> layer_data_map;' |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 924 | write(self.layer_factory, file=self.outFile) |
| 925 | else: |
| 926 | write(self.inline_custom_source_postamble, file=self.outFile) |
| 927 | # Finish processing in superclass |
| 928 | OutputGenerator.endFile(self) |
| 929 | |
| 930 | def beginFeature(self, interface, emit): |
| 931 | # Start processing in superclass |
| 932 | OutputGenerator.beginFeature(self, interface, emit) |
| 933 | # Get feature extra protect |
| 934 | self.featureExtraProtect = GetFeatureProtect(interface) |
| 935 | # Accumulate includes, defines, types, enums, function pointer typedefs, end function prototypes separately for this |
| 936 | # feature. They're only printed in endFeature(). |
| 937 | self.sections = dict([(section, []) for section in self.ALL_SECTIONS]) |
| 938 | |
| 939 | def endFeature(self): |
| 940 | # Actually write the interface to the output file. |
| 941 | if (self.emit): |
| 942 | self.newline() |
| 943 | # If type declarations are needed by other features based on this one, it may be necessary to suppress the ExtraProtect, |
| 944 | # or move it below the 'for section...' loop. |
| 945 | if (self.featureExtraProtect != None): |
| 946 | write('#ifdef', self.featureExtraProtect, file=self.outFile) |
| 947 | for section in self.TYPE_SECTIONS: |
| 948 | contents = self.sections[section] |
| 949 | if contents: |
| 950 | write('\n'.join(contents), file=self.outFile) |
| 951 | self.newline() |
| 952 | if (self.sections['command']): |
| 953 | write('\n'.join(self.sections['command']), end=u'', file=self.outFile) |
| 954 | self.newline() |
| 955 | if (self.featureExtraProtect != None): |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 956 | write('#endif //', self.featureExtraProtect, file=self.outFile) |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 957 | # Finish processing in superclass |
| 958 | OutputGenerator.endFeature(self) |
| 959 | # |
| 960 | # Append a definition to the specified section |
| 961 | def appendSection(self, section, text): |
| 962 | self.sections[section].append(text) |
| 963 | # |
| 964 | # Type generation |
| 965 | def genType(self, typeinfo, name, alias): |
| 966 | pass |
| 967 | # |
| 968 | # Struct (e.g. C "struct" type) generation. This is a special case of the <type> tag where the contents are |
| 969 | # interpreted as a set of <member> tags instead of freeform C type declarations. The <member> tags are just like <param> |
| 970 | # tags - they are a declaration of a struct or union member. Only simple member declarations are supported (no nested |
| 971 | # structs etc.) |
| 972 | def genStruct(self, typeinfo, typeName): |
| 973 | OutputGenerator.genStruct(self, typeinfo, typeName) |
| 974 | body = 'typedef ' + typeinfo.elem.get('category') + ' ' + typeName + ' {\n' |
| 975 | # paramdecl = self.makeCParamDecl(typeinfo.elem, self.genOpts.alignFuncParam) |
| 976 | for member in typeinfo.elem.findall('.//member'): |
| 977 | body += self.makeCParamDecl(member, self.genOpts.alignFuncParam) |
| 978 | body += ';\n' |
| 979 | body += '} ' + typeName + ';\n' |
| 980 | self.appendSection('struct', body) |
| 981 | # |
| 982 | # Group (e.g. C "enum" type) generation. These are concatenated together with other types. |
| 983 | def genGroup(self, groupinfo, groupName, alias): |
| 984 | pass |
| 985 | # Enumerant generation |
| 986 | # <enum> tags may specify their values in several ways, but are usually just integers. |
| 987 | def genEnum(self, enuminfo, name, alias): |
| 988 | pass |
| 989 | # |
| 990 | # Customize Cdecl for layer factory base class |
| 991 | def BaseClassCdecl(self, elem, name): |
| 992 | raw = self.makeCDecls(elem)[1] |
| 993 | |
| 994 | # Toss everything before the undecorated name |
| 995 | prototype = raw.split("VKAPI_PTR *PFN_vk")[1] |
| 996 | prototype = prototype.replace(")", "", 1) |
| 997 | prototype = prototype.replace(";", " {};") |
| 998 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 999 | # Build up pre/post call virtual function declarations |
| 1000 | pre_call_validate = 'virtual bool PreCallValidate' + prototype |
| 1001 | pre_call_validate = pre_call_validate.replace("{}", " { return false; }") |
| 1002 | pre_call_record = 'virtual void PreCallRecord' + prototype |
| 1003 | post_call_record = 'virtual void PostCallRecord' + prototype |
| 1004 | return ' %s\n %s\n %s\n' % (pre_call_validate, pre_call_record, post_call_record) |
| 1005 | # |
| 1006 | # Command generation |
| 1007 | def genCmd(self, cmdinfo, name, alias): |
| 1008 | ignore_functions = [ |
| 1009 | 'vkEnumerateInstanceVersion' |
| 1010 | ] |
| 1011 | |
| 1012 | if name in ignore_functions: |
| 1013 | return |
| 1014 | |
| 1015 | if self.header: # In the header declare all intercepts |
| 1016 | self.appendSection('command', '') |
| 1017 | self.appendSection('command', self.makeCDecls(cmdinfo.elem)[0]) |
| 1018 | if (self.featureExtraProtect != None): |
| 1019 | self.intercepts += [ '#ifdef %s' % self.featureExtraProtect ] |
| 1020 | self.layer_factory += '#ifdef %s\n' % self.featureExtraProtect |
| 1021 | # Update base class with virtual function declarations |
| 1022 | self.layer_factory += self.BaseClassCdecl(cmdinfo.elem, name) |
| 1023 | # Update function intercepts |
| 1024 | self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ] |
| 1025 | if (self.featureExtraProtect != None): |
| 1026 | self.intercepts += [ '#endif' ] |
| 1027 | self.layer_factory += '#endif\n' |
| 1028 | return |
| 1029 | |
| Mark Lobodzinski | 09f8636 | 2018-12-13 14:07:20 -0700 | [diff] [blame] | 1030 | if name in self.manual_functions: |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1031 | self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ] |
| 1032 | return |
| 1033 | # Record that the function will be intercepted |
| 1034 | if (self.featureExtraProtect != None): |
| 1035 | self.intercepts += [ '#ifdef %s' % self.featureExtraProtect ] |
| 1036 | self.intercepts += [ ' {"%s", (void*)%s},' % (name,name[2:]) ] |
| 1037 | if (self.featureExtraProtect != None): |
| 1038 | self.intercepts += [ '#endif' ] |
| 1039 | OutputGenerator.genCmd(self, cmdinfo, name, alias) |
| 1040 | # |
| 1041 | decls = self.makeCDecls(cmdinfo.elem) |
| 1042 | self.appendSection('command', '') |
| 1043 | self.appendSection('command', '%s {' % decls[0][:-1]) |
| 1044 | # Setup common to call wrappers. First parameter is always dispatchable |
| 1045 | dispatchable_type = cmdinfo.elem.find('param/type').text |
| 1046 | dispatchable_name = cmdinfo.elem.find('param/name').text |
| 1047 | # Default to device |
| 1048 | device_or_instance = 'device' |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1049 | dispatch_table_name = 'VkLayerDispatchTable' |
| 1050 | # Set to instance as necessary |
| 1051 | if dispatchable_type in ["VkPhysicalDevice", "VkInstance"] or name == 'vkCreateInstance': |
| 1052 | device_or_instance = 'instance' |
| 1053 | dispatch_table_name = 'VkLayerInstanceDispatchTable' |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 1054 | self.appendSection('command', ' auto layer_data = GetLayerDataPtr(get_dispatch_key(%s), layer_data_map);' % (dispatchable_name)) |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1055 | api_function_name = cmdinfo.elem.attrib.get('name') |
| 1056 | params = cmdinfo.elem.findall('param/name') |
| 1057 | paramstext = ', '.join([str(param.text) for param in params]) |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 1058 | API = api_function_name.replace('vk','Dispatch') + '(layer_data, ' |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1059 | |
| 1060 | # Declare result variable, if any. |
| 1061 | return_map = { |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1062 | 'PFN_vkVoidFunction': 'return nullptr;', |
| 1063 | 'VkBool32': 'return VK_FALSE;', |
| Shannon McPherson | 9a4ae98 | 2019-01-07 16:05:25 -0700 | [diff] [blame] | 1064 | 'VkDeviceAddress': 'return 0;', |
| 1065 | 'VkResult': 'return VK_ERROR_VALIDATION_FAILED_EXT;', |
| 1066 | 'void': 'return;', |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1067 | } |
| 1068 | resulttype = cmdinfo.elem.find('proto/type') |
| 1069 | assignresult = '' |
| 1070 | if (resulttype.text != 'void'): |
| 1071 | assignresult = resulttype.text + ' result = ' |
| 1072 | |
| 1073 | # Set up skip and locking |
| Mark Lobodzinski | e37e2fc | 2018-11-26 16:31:17 -0700 | [diff] [blame] | 1074 | self.appendSection('command', ' bool skip = false;') |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1075 | |
| 1076 | # Generate pre-call validation source code |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 1077 | self.appendSection('command', ' %s' % self.precallvalidate_loop) |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 1078 | self.appendSection('command', ' intercept->write_lock();') |
| Mark Lobodzinski | e37e2fc | 2018-11-26 16:31:17 -0700 | [diff] [blame] | 1079 | self.appendSection('command', ' skip |= intercept->PreCallValidate%s(%s);' % (api_function_name[2:], paramstext)) |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 1080 | self.appendSection('command', ' intercept->write_unlock();') |
| Mark Lobodzinski | e37e2fc | 2018-11-26 16:31:17 -0700 | [diff] [blame] | 1081 | self.appendSection('command', ' if (skip) %s' % return_map[resulttype.text]) |
| 1082 | self.appendSection('command', ' }') |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1083 | |
| 1084 | # Generate pre-call state recording source code |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 1085 | self.appendSection('command', ' %s' % self.precallrecord_loop) |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 1086 | self.appendSection('command', ' intercept->write_lock();') |
| Mark Lobodzinski | e37e2fc | 2018-11-26 16:31:17 -0700 | [diff] [blame] | 1087 | self.appendSection('command', ' intercept->PreCallRecord%s(%s);' % (api_function_name[2:], paramstext)) |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 1088 | self.appendSection('command', ' intercept->write_unlock();') |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1089 | self.appendSection('command', ' }') |
| 1090 | |
| Mark Lobodzinski | f57e828 | 2018-12-13 11:34:33 -0700 | [diff] [blame] | 1091 | # Insert pre-dispatch debug utils function call |
| 1092 | if name in self.pre_dispatch_debug_utils_functions: |
| 1093 | self.appendSection('command', ' {') |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 1094 | self.appendSection('command', ' std::lock_guard<std::mutex> lock(layer_data->validation_object_mutex);') |
| Mark Lobodzinski | f57e828 | 2018-12-13 11:34:33 -0700 | [diff] [blame] | 1095 | self.appendSection('command', ' %s' % self.pre_dispatch_debug_utils_functions[name]) |
| 1096 | self.appendSection('command', ' }') |
| 1097 | |
| 1098 | # Output dispatch (down-chain) function call |
| Mark Lobodzinski | a5b163f | 2018-11-08 12:31:46 -0700 | [diff] [blame] | 1099 | self.appendSection('command', ' ' + assignresult + API + paramstext + ');') |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1100 | |
| Mark Lobodzinski | f57e828 | 2018-12-13 11:34:33 -0700 | [diff] [blame] | 1101 | # Insert post-dispatch debug utils function call |
| 1102 | if name in self.post_dispatch_debug_utils_functions: |
| 1103 | self.appendSection('command', ' {') |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 1104 | self.appendSection('command', ' std::lock_guard<std::mutex> lock(layer_data->validation_object_mutex);') |
| Mark Lobodzinski | f57e828 | 2018-12-13 11:34:33 -0700 | [diff] [blame] | 1105 | self.appendSection('command', ' %s' % self.post_dispatch_debug_utils_functions[name]) |
| 1106 | self.appendSection('command', ' }') |
| 1107 | |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1108 | # Generate post-call object processing source code |
| Mark Lobodzinski | e37e2fc | 2018-11-26 16:31:17 -0700 | [diff] [blame] | 1109 | return_type_indent = '' |
| Mark Lobodzinski | d939fcb | 2019-01-10 15:49:12 -0700 | [diff] [blame] | 1110 | |
| 1111 | self.appendSection('command', ' %s' % self.postcallrecord_loop) |
| Mark Lobodzinski | 0c66846 | 2018-09-27 10:13:19 -0600 | [diff] [blame] | 1112 | if (resulttype.text == 'VkResult'): |
| Mark Lobodzinski | e37e2fc | 2018-11-26 16:31:17 -0700 | [diff] [blame] | 1113 | return_type_indent = ' ' |
| Mark Lobodzinski | 09f8636 | 2018-12-13 14:07:20 -0700 | [diff] [blame] | 1114 | if name in self.alt_ret_codes: |
| Mark Lobodzinski | d939fcb | 2019-01-10 15:49:12 -0700 | [diff] [blame] | 1115 | self.appendSection('command', '%s if (((VK_SUCCESS == result) || (VK_INCOMPLETE == result)) || (intercept->container_type == LayerObjectTypeThreading)) {' % return_type_indent) |
| Mark Lobodzinski | b3c9484 | 2018-11-27 10:01:51 -0700 | [diff] [blame] | 1116 | else: |
| Mark Lobodzinski | d939fcb | 2019-01-10 15:49:12 -0700 | [diff] [blame] | 1117 | self.appendSection('command', '%s if ((VK_SUCCESS == result) || (intercept->container_type == LayerObjectTypeThreading)) {' % return_type_indent) |
| Mark Lobodzinski | add9323 | 2018-10-09 11:49:42 -0600 | [diff] [blame] | 1118 | |
| Mark Lobodzinski | d939fcb | 2019-01-10 15:49:12 -0700 | [diff] [blame] | 1119 | #self.appendSection('command', '%s %s' % (return_type_indent, self.postcallrecord_loop)) |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 1120 | self.appendSection('command', '%s intercept->write_lock();' % return_type_indent) |
| Mark Lobodzinski | e37e2fc | 2018-11-26 16:31:17 -0700 | [diff] [blame] | 1121 | self.appendSection('command', '%s intercept->PostCallRecord%s(%s);' % (return_type_indent,api_function_name[2:], paramstext)) |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 1122 | self.appendSection('command', '%s intercept->write_unlock();' % return_type_indent) |
| Mark Lobodzinski | e37e2fc | 2018-11-26 16:31:17 -0700 | [diff] [blame] | 1123 | self.appendSection('command', '%s }' % return_type_indent) |
| 1124 | if (resulttype.text == 'VkResult'): |
| 1125 | self.appendSection('command', ' }') |
| Mark Lobodzinski | 9b6522d | 2018-09-26 11:07:45 -0600 | [diff] [blame] | 1126 | |
| 1127 | # Return result variable, if any. |
| 1128 | if (resulttype.text != 'void'): |
| 1129 | self.appendSection('command', ' return result;') |
| 1130 | self.appendSection('command', '}') |
| 1131 | # |
| 1132 | # Override makeProtoName to drop the "vk" prefix |
| 1133 | def makeProtoName(self, name, tail): |
| 1134 | return self.genOpts.apientry + name[2:] + tail |