| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -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 | ff91099 | 2016-10-11 14:29:52 -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: Mike Stroyan <stroyan@google.com> |
| Mark Lobodzinski | d3b439e | 2017-06-07 13:08:41 -0600 | [diff] [blame] | 21 | # Author: Mark Lobodzinski <mark@lunarg.com> |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 22 | |
| 23 | import os,re,sys |
| 24 | from generator import * |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 25 | from common_codegen import * |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 26 | |
| 27 | # ThreadGeneratorOptions - subclass of GeneratorOptions. |
| 28 | # |
| 29 | # Adds options used by ThreadOutputGenerator objects during threading |
| 30 | # layer generation. |
| 31 | # |
| 32 | # Additional members |
| 33 | # prefixText - list of strings to prefix generated header with |
| 34 | # (usually a copyright statement + calling convention macros). |
| 35 | # protectFile - True if multiple inclusion protection should be |
| 36 | # generated (based on the filename) around the entire header. |
| 37 | # protectFeature - True if #ifndef..#endif protection should be |
| 38 | # generated around a feature interface in the header file. |
| 39 | # genFuncPointers - True if function pointer typedefs should be |
| 40 | # generated |
| 41 | # protectProto - If conditional protection should be generated |
| 42 | # around prototype declarations, set to either '#ifdef' |
| 43 | # to require opt-in (#ifdef protectProtoStr) or '#ifndef' |
| 44 | # to require opt-out (#ifndef protectProtoStr). Otherwise |
| 45 | # set to None. |
| 46 | # protectProtoStr - #ifdef/#ifndef symbol to use around prototype |
| 47 | # declarations, if protectProto is set |
| 48 | # apicall - string to use for the function declaration prefix, |
| 49 | # such as APICALL on Windows. |
| 50 | # apientry - string to use for the calling convention macro, |
| 51 | # in typedefs, such as APIENTRY. |
| 52 | # apientryp - string to use for the calling convention macro |
| 53 | # in function pointer typedefs, such as APIENTRYP. |
| 54 | # indentFuncProto - True if prototype declarations should put each |
| 55 | # parameter on a separate line |
| 56 | # indentFuncPointer - True if typedefed function pointers should put each |
| 57 | # parameter on a separate line |
| 58 | # alignFuncParam - if nonzero and parameters are being put on a |
| 59 | # separate line, align parameter names at the specified column |
| 60 | class ThreadGeneratorOptions(GeneratorOptions): |
| 61 | def __init__(self, |
| Mike Schuchardt | 21638df | 2019-03-16 10:52:02 -0700 | [diff] [blame] | 62 | conventions = None, |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 63 | filename = None, |
| 64 | directory = '.', |
| 65 | apiname = None, |
| 66 | profile = None, |
| 67 | versions = '.*', |
| 68 | emitversions = '.*', |
| 69 | defaultExtensions = None, |
| 70 | addExtensions = None, |
| 71 | removeExtensions = None, |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 72 | emitExtensions = None, |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 73 | sortProcedure = regSortFeatures, |
| 74 | prefixText = "", |
| 75 | genFuncPointers = True, |
| 76 | protectFile = True, |
| 77 | protectFeature = True, |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 78 | apicall = '', |
| 79 | apientry = '', |
| 80 | apientryp = '', |
| 81 | indentFuncProto = True, |
| 82 | indentFuncPointer = False, |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 83 | alignFuncParam = 0, |
| 84 | expandEnumerants = True): |
| Mike Schuchardt | 21638df | 2019-03-16 10:52:02 -0700 | [diff] [blame] | 85 | GeneratorOptions.__init__(self, conventions, filename, directory, apiname, profile, |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 86 | versions, emitversions, defaultExtensions, |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 87 | addExtensions, removeExtensions, emitExtensions, sortProcedure) |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 88 | self.prefixText = prefixText |
| 89 | self.genFuncPointers = genFuncPointers |
| 90 | self.protectFile = protectFile |
| 91 | self.protectFeature = protectFeature |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 92 | self.apicall = apicall |
| 93 | self.apientry = apientry |
| 94 | self.apientryp = apientryp |
| 95 | self.indentFuncProto = indentFuncProto |
| 96 | self.indentFuncPointer = indentFuncPointer |
| 97 | self.alignFuncParam = alignFuncParam |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 98 | self.expandEnumerants = expandEnumerants |
| 99 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 100 | |
| 101 | # ThreadOutputGenerator - subclass of OutputGenerator. |
| 102 | # Generates Thread checking framework |
| 103 | # |
| 104 | # ---- methods ---- |
| 105 | # ThreadOutputGenerator(errFile, warnFile, diagFile) - args as for |
| 106 | # OutputGenerator. Defines additional internal state. |
| 107 | # ---- methods overriding base class ---- |
| 108 | # beginFile(genOpts) |
| 109 | # endFile() |
| 110 | # beginFeature(interface, emit) |
| 111 | # endFeature() |
| 112 | # genType(typeinfo,name) |
| 113 | # genStruct(typeinfo,name) |
| 114 | # genGroup(groupinfo,name) |
| 115 | # genEnum(enuminfo, name) |
| 116 | # genCmd(cmdinfo) |
| 117 | class ThreadOutputGenerator(OutputGenerator): |
| 118 | """Generate specified API interfaces in a specific style, such as a C header""" |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 119 | |
| 120 | inline_copyright_message = """ |
| 121 | // This file is ***GENERATED***. Do Not Edit. |
| 122 | // See layer_chassis_dispatch_generator.py for modifications. |
| 123 | |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 124 | /* Copyright (c) 2015-2019 The Khronos Group Inc. |
| 125 | * Copyright (c) 2015-2019 Valve Corporation |
| 126 | * Copyright (c) 2015-2019 LunarG, Inc. |
| 127 | * Copyright (c) 2015-2019 Google Inc. |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 128 | * |
| 129 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 130 | * you may not use this file except in compliance with the License. |
| 131 | * You may obtain a copy of the License at |
| 132 | * |
| 133 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 134 | * |
| 135 | * Unless required by applicable law or agreed to in writing, software |
| 136 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 137 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 138 | * See the License for the specific language governing permissions and |
| 139 | * limitations under the License. |
| 140 | * |
| 141 | * Author: Mark Lobodzinski <mark@lunarg.com> |
| 142 | */""" |
| 143 | |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 144 | # Note that the inline_custom_header_preamble template below contains three embedded template expansion identifiers. |
| 145 | # These get replaced with generated code sections, and are labeled: |
| 146 | # o COUNTER_CLASS_DEFINITIONS_TEMPLATE |
| 147 | # o COUNTER_CLASS_INSTANCES_TEMPLATE |
| 148 | # o COUNTER_CLASS_BODIES_TEMPLATE |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 149 | inline_custom_header_preamble = """ |
| 150 | #pragma once |
| 151 | |
| 152 | #include <condition_variable> |
| 153 | #include <mutex> |
| 154 | #include <vector> |
| 155 | #include <unordered_set> |
| 156 | #include <string> |
| 157 | |
| 158 | VK_DEFINE_NON_DISPATCHABLE_HANDLE(DISTINCT_NONDISPATCHABLE_PHONY_HANDLE) |
| 159 | // The following line must match the vulkan_core.h condition guarding VK_DEFINE_NON_DISPATCHABLE_HANDLE |
| 160 | #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \ |
| 161 | defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) |
| 162 | // If pointers are 64-bit, then there can be separate counters for each |
| 163 | // NONDISPATCHABLE_HANDLE type. Otherwise they are all typedef uint64_t. |
| 164 | #define DISTINCT_NONDISPATCHABLE_HANDLES |
| 165 | // Make sure we catch any disagreement between us and the vulkan definition |
| 166 | static_assert(std::is_pointer<DISTINCT_NONDISPATCHABLE_PHONY_HANDLE>::value, |
| 167 | "Mismatched non-dispatchable handle handle, expected pointer type."); |
| 168 | #else |
| 169 | // Make sure we catch any disagreement between us and the vulkan definition |
| 170 | static_assert(std::is_same<uint64_t, DISTINCT_NONDISPATCHABLE_PHONY_HANDLE>::value, |
| 171 | "Mismatched non-dispatchable handle handle, expected uint64_t."); |
| 172 | #endif |
| 173 | |
| 174 | // Suppress unused warning on Linux |
| 175 | #if defined(__GNUC__) |
| 176 | #define DECORATE_UNUSED __attribute__((unused)) |
| 177 | #else |
| 178 | #define DECORATE_UNUSED |
| 179 | #endif |
| 180 | |
| 181 | // clang-format off |
| 182 | static const char DECORATE_UNUSED *kVUID_Threading_Info = "UNASSIGNED-Threading-Info"; |
| 183 | static const char DECORATE_UNUSED *kVUID_Threading_MultipleThreads = "UNASSIGNED-Threading-MultipleThreads"; |
| 184 | static const char DECORATE_UNUSED *kVUID_Threading_SingleThreadReuse = "UNASSIGNED-Threading-SingleThreadReuse"; |
| 185 | // clang-format on |
| 186 | |
| 187 | #undef DECORATE_UNUSED |
| 188 | |
| 189 | struct object_use_data { |
| 190 | loader_platform_thread_id thread; |
| 191 | int reader_count; |
| 192 | int writer_count; |
| 193 | }; |
| 194 | |
| Jeff Bolz | 1cb6fd6f | 2019-02-03 21:58:14 -0600 | [diff] [blame] | 195 | // This is a wrapper around unordered_map that optimizes for the common case |
| 196 | // of only containing a single element. The "first" element's use is stored |
| 197 | // inline in the class and doesn't require hashing or memory (de)allocation. |
| 198 | // TODO: Consider generalizing this from one element to N elements (where N |
| 199 | // is a template parameter). |
| 200 | template <typename Key, typename T> |
| 201 | class small_unordered_map { |
| 202 | |
| 203 | bool first_data_allocated; |
| 204 | Key first_data_key; |
| 205 | T first_data; |
| 206 | |
| 207 | std::unordered_map<Key, T> uses; |
| 208 | |
| 209 | public: |
| 210 | small_unordered_map() : first_data_allocated(false) {} |
| 211 | |
| 212 | bool contains(const Key& object) const { |
| 213 | if (first_data_allocated && object == first_data_key) { |
| 214 | return true; |
| 215 | // check size() first to avoid hashing object unnecessarily. |
| 216 | } else if (uses.size() == 0) { |
| 217 | return false; |
| 218 | } else { |
| 219 | return uses.find(object) != uses.end(); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | T& operator[](const Key& object) { |
| 224 | if (first_data_allocated && first_data_key == object) { |
| 225 | return first_data; |
| 226 | } else if (!first_data_allocated && uses.size() == 0) { |
| 227 | first_data_allocated = true; |
| 228 | first_data_key = object; |
| 229 | return first_data; |
| 230 | } else { |
| 231 | return uses[object]; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | typename std::unordered_map<Key, T>::size_type erase(const Key& object) { |
| 236 | if (first_data_allocated && first_data_key == object) { |
| 237 | first_data_allocated = false; |
| 238 | return 1; |
| 239 | } else { |
| 240 | return uses.erase(object); |
| 241 | } |
| 242 | } |
| 243 | }; |
| 244 | |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 245 | template <typename T> |
| 246 | class counter { |
| 247 | public: |
| 248 | const char *typeName; |
| 249 | VkDebugReportObjectTypeEXT objectType; |
| 250 | debug_report_data **report_data; |
| Jeff Bolz | 1cb6fd6f | 2019-02-03 21:58:14 -0600 | [diff] [blame] | 251 | small_unordered_map<T, object_use_data> uses; |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 252 | std::mutex counter_lock; |
| 253 | std::condition_variable counter_condition; |
| 254 | |
| 255 | |
| 256 | void StartWrite(T object) { |
| 257 | if (object == VK_NULL_HANDLE) { |
| 258 | return; |
| 259 | } |
| 260 | bool skip = false; |
| 261 | loader_platform_thread_id tid = loader_platform_get_thread_id(); |
| 262 | std::unique_lock<std::mutex> lock(counter_lock); |
| Jeff Bolz | 1cb6fd6f | 2019-02-03 21:58:14 -0600 | [diff] [blame] | 263 | if (!uses.contains(object)) { |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 264 | // There is no current use of the object. Record writer thread. |
| 265 | struct object_use_data *use_data = &uses[object]; |
| 266 | use_data->reader_count = 0; |
| 267 | use_data->writer_count = 1; |
| 268 | use_data->thread = tid; |
| 269 | } else { |
| 270 | struct object_use_data *use_data = &uses[object]; |
| 271 | if (use_data->reader_count == 0) { |
| 272 | // There are no readers. Two writers just collided. |
| 273 | if (use_data->thread != tid) { |
| 274 | skip |= log_msg(*report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object), |
| 275 | kVUID_Threading_MultipleThreads, |
| 276 | "THREADING ERROR : object of type %s is simultaneously used in " |
| 277 | "thread 0x%" PRIx64 " and thread 0x%" PRIx64, |
| 278 | typeName, (uint64_t)use_data->thread, (uint64_t)tid); |
| 279 | if (skip) { |
| 280 | // Wait for thread-safe access to object instead of skipping call. |
| Jeff Bolz | 1cb6fd6f | 2019-02-03 21:58:14 -0600 | [diff] [blame] | 281 | while (uses.contains(object)) { |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 282 | counter_condition.wait(lock); |
| 283 | } |
| 284 | // There is now no current use of the object. Record writer thread. |
| 285 | struct object_use_data *new_use_data = &uses[object]; |
| 286 | new_use_data->thread = tid; |
| 287 | new_use_data->reader_count = 0; |
| 288 | new_use_data->writer_count = 1; |
| 289 | } else { |
| 290 | // Continue with an unsafe use of the object. |
| 291 | use_data->thread = tid; |
| 292 | use_data->writer_count += 1; |
| 293 | } |
| 294 | } else { |
| 295 | // This is either safe multiple use in one call, or recursive use. |
| 296 | // There is no way to make recursion safe. Just forge ahead. |
| 297 | use_data->writer_count += 1; |
| 298 | } |
| 299 | } else { |
| 300 | // There are readers. This writer collided with them. |
| 301 | if (use_data->thread != tid) { |
| 302 | skip |= log_msg(*report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object), |
| 303 | kVUID_Threading_MultipleThreads, |
| 304 | "THREADING ERROR : object of type %s is simultaneously used in " |
| 305 | "thread 0x%" PRIx64 " and thread 0x%" PRIx64, |
| 306 | typeName, (uint64_t)use_data->thread, (uint64_t)tid); |
| 307 | if (skip) { |
| 308 | // Wait for thread-safe access to object instead of skipping call. |
| Jeff Bolz | 1cb6fd6f | 2019-02-03 21:58:14 -0600 | [diff] [blame] | 309 | while (uses.contains(object)) { |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 310 | counter_condition.wait(lock); |
| 311 | } |
| 312 | // There is now no current use of the object. Record writer thread. |
| 313 | struct object_use_data *new_use_data = &uses[object]; |
| 314 | new_use_data->thread = tid; |
| 315 | new_use_data->reader_count = 0; |
| 316 | new_use_data->writer_count = 1; |
| 317 | } else { |
| 318 | // Continue with an unsafe use of the object. |
| 319 | use_data->thread = tid; |
| 320 | use_data->writer_count += 1; |
| 321 | } |
| 322 | } else { |
| 323 | // This is either safe multiple use in one call, or recursive use. |
| 324 | // There is no way to make recursion safe. Just forge ahead. |
| 325 | use_data->writer_count += 1; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | void FinishWrite(T object) { |
| 332 | if (object == VK_NULL_HANDLE) { |
| 333 | return; |
| 334 | } |
| 335 | // Object is no longer in use |
| 336 | std::unique_lock<std::mutex> lock(counter_lock); |
| 337 | uses[object].writer_count -= 1; |
| 338 | if ((uses[object].reader_count == 0) && (uses[object].writer_count == 0)) { |
| 339 | uses.erase(object); |
| 340 | } |
| 341 | // Notify any waiting threads that this object may be safe to use |
| 342 | lock.unlock(); |
| 343 | counter_condition.notify_all(); |
| 344 | } |
| 345 | |
| 346 | void StartRead(T object) { |
| 347 | if (object == VK_NULL_HANDLE) { |
| 348 | return; |
| 349 | } |
| 350 | bool skip = false; |
| 351 | loader_platform_thread_id tid = loader_platform_get_thread_id(); |
| 352 | std::unique_lock<std::mutex> lock(counter_lock); |
| Jeff Bolz | 1cb6fd6f | 2019-02-03 21:58:14 -0600 | [diff] [blame] | 353 | if (!uses.contains(object)) { |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 354 | // There is no current use of the object. Record reader count |
| 355 | struct object_use_data *use_data = &uses[object]; |
| 356 | use_data->reader_count = 1; |
| 357 | use_data->writer_count = 0; |
| 358 | use_data->thread = tid; |
| 359 | } else if (uses[object].writer_count > 0 && uses[object].thread != tid) { |
| 360 | // There is a writer of the object. |
| 361 | skip |= false; |
| 362 | log_msg(*report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object), kVUID_Threading_MultipleThreads, |
| 363 | "THREADING ERROR : object of type %s is simultaneously used in " |
| 364 | "thread 0x%" PRIx64 " and thread 0x%" PRIx64, |
| 365 | typeName, (uint64_t)uses[object].thread, (uint64_t)tid); |
| 366 | if (skip) { |
| 367 | // Wait for thread-safe access to object instead of skipping call. |
| Jeff Bolz | 1cb6fd6f | 2019-02-03 21:58:14 -0600 | [diff] [blame] | 368 | while (uses.contains(object)) { |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 369 | counter_condition.wait(lock); |
| 370 | } |
| 371 | // There is no current use of the object. Record reader count |
| 372 | struct object_use_data *use_data = &uses[object]; |
| 373 | use_data->reader_count = 1; |
| 374 | use_data->writer_count = 0; |
| 375 | use_data->thread = tid; |
| 376 | } else { |
| 377 | uses[object].reader_count += 1; |
| 378 | } |
| 379 | } else { |
| 380 | // There are other readers of the object. Increase reader count |
| 381 | uses[object].reader_count += 1; |
| 382 | } |
| 383 | } |
| 384 | void FinishRead(T object) { |
| 385 | if (object == VK_NULL_HANDLE) { |
| 386 | return; |
| 387 | } |
| 388 | std::unique_lock<std::mutex> lock(counter_lock); |
| 389 | uses[object].reader_count -= 1; |
| 390 | if ((uses[object].reader_count == 0) && (uses[object].writer_count == 0)) { |
| 391 | uses.erase(object); |
| 392 | } |
| 393 | // Notify any waiting threads that this object may be safe to use |
| 394 | lock.unlock(); |
| 395 | counter_condition.notify_all(); |
| 396 | } |
| 397 | counter(const char *name = "", VkDebugReportObjectTypeEXT type = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, debug_report_data **rep_data = nullptr) { |
| 398 | typeName = name; |
| 399 | objectType = type; |
| 400 | report_data = rep_data; |
| 401 | } |
| 402 | }; |
| 403 | |
| 404 | |
| 405 | |
| 406 | class ThreadSafety : public ValidationObject { |
| 407 | public: |
| 408 | |
| 409 | // Override chassis read/write locks for this validation object |
| Jeremy Hayes | d4a3ec3 | 2019-01-29 14:42:08 -0700 | [diff] [blame] | 410 | // This override takes a deferred lock. i.e. it is not acquired. |
| 411 | std::unique_lock<std::mutex> write_lock() { |
| 412 | return std::unique_lock<std::mutex>(validation_object_mutex, std::defer_lock); |
| 413 | } |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 414 | |
| 415 | std::mutex command_pool_lock; |
| 416 | std::unordered_map<VkCommandBuffer, VkCommandPool> command_pool_map; |
| 417 | |
| 418 | counter<VkCommandBuffer> c_VkCommandBuffer; |
| 419 | counter<VkDevice> c_VkDevice; |
| 420 | counter<VkInstance> c_VkInstance; |
| 421 | counter<VkQueue> c_VkQueue; |
| 422 | #ifdef DISTINCT_NONDISPATCHABLE_HANDLES |
| 423 | |
| 424 | // Special entry to allow tracking of command pool Reset and Destroy |
| 425 | counter<VkCommandPool> c_VkCommandPoolContents; |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 426 | COUNTER_CLASS_DEFINITIONS_TEMPLATE |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 427 | |
| 428 | #else // DISTINCT_NONDISPATCHABLE_HANDLES |
| 429 | // Special entry to allow tracking of command pool Reset and Destroy |
| 430 | counter<uint64_t> c_VkCommandPoolContents; |
| 431 | |
| 432 | counter<uint64_t> c_uint64_t; |
| 433 | #endif // DISTINCT_NONDISPATCHABLE_HANDLES |
| 434 | |
| 435 | ThreadSafety() |
| 436 | : c_VkCommandBuffer("VkCommandBuffer", VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, &report_data), |
| 437 | c_VkDevice("VkDevice", VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, &report_data), |
| 438 | c_VkInstance("VkInstance", VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, &report_data), |
| 439 | c_VkQueue("VkQueue", VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, &report_data), |
| 440 | c_VkCommandPoolContents("VkCommandPool", VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, &report_data), |
| 441 | |
| 442 | #ifdef DISTINCT_NONDISPATCHABLE_HANDLES |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 443 | COUNTER_CLASS_INSTANCES_TEMPLATE |
| 444 | |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 445 | |
| 446 | #else // DISTINCT_NONDISPATCHABLE_HANDLES |
| 447 | c_uint64_t("NON_DISPATCHABLE_HANDLE", VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, &report_data) |
| 448 | #endif // DISTINCT_NONDISPATCHABLE_HANDLES |
| 449 | {}; |
| 450 | |
| 451 | #define WRAPPER(type) \ |
| 452 | void StartWriteObject(type object) { \ |
| 453 | c_##type.StartWrite(object); \ |
| 454 | } \ |
| 455 | void FinishWriteObject(type object) { \ |
| 456 | c_##type.FinishWrite(object); \ |
| 457 | } \ |
| 458 | void StartReadObject(type object) { \ |
| 459 | c_##type.StartRead(object); \ |
| 460 | } \ |
| 461 | void FinishReadObject(type object) { \ |
| 462 | c_##type.FinishRead(object); \ |
| 463 | } |
| 464 | |
| 465 | WRAPPER(VkDevice) |
| 466 | WRAPPER(VkInstance) |
| 467 | WRAPPER(VkQueue) |
| 468 | #ifdef DISTINCT_NONDISPATCHABLE_HANDLES |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 469 | COUNTER_CLASS_BODIES_TEMPLATE |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 470 | |
| 471 | #else // DISTINCT_NONDISPATCHABLE_HANDLES |
| 472 | WRAPPER(uint64_t) |
| 473 | #endif // DISTINCT_NONDISPATCHABLE_HANDLES |
| 474 | |
| 475 | // VkCommandBuffer needs check for implicit use of command pool |
| 476 | void StartWriteObject(VkCommandBuffer object, bool lockPool = true) { |
| 477 | if (lockPool) { |
| 478 | std::unique_lock<std::mutex> lock(command_pool_lock); |
| 479 | VkCommandPool pool = command_pool_map[object]; |
| 480 | lock.unlock(); |
| 481 | StartWriteObject(pool); |
| 482 | } |
| 483 | c_VkCommandBuffer.StartWrite(object); |
| 484 | } |
| 485 | void FinishWriteObject(VkCommandBuffer object, bool lockPool = true) { |
| 486 | c_VkCommandBuffer.FinishWrite(object); |
| 487 | if (lockPool) { |
| 488 | std::unique_lock<std::mutex> lock(command_pool_lock); |
| 489 | VkCommandPool pool = command_pool_map[object]; |
| 490 | lock.unlock(); |
| 491 | FinishWriteObject(pool); |
| 492 | } |
| 493 | } |
| 494 | void StartReadObject(VkCommandBuffer object) { |
| 495 | std::unique_lock<std::mutex> lock(command_pool_lock); |
| 496 | VkCommandPool pool = command_pool_map[object]; |
| 497 | lock.unlock(); |
| 498 | // We set up a read guard against the "Contents" counter to catch conflict vs. vkResetCommandPool and vkDestroyCommandPool |
| 499 | // while *not* establishing a read guard against the command pool counter itself to avoid false postives for |
| 500 | // non-externally sync'd command buffers |
| 501 | c_VkCommandPoolContents.StartRead(pool); |
| 502 | c_VkCommandBuffer.StartRead(object); |
| 503 | } |
| 504 | void FinishReadObject(VkCommandBuffer object) { |
| 505 | c_VkCommandBuffer.FinishRead(object); |
| 506 | std::unique_lock<std::mutex> lock(command_pool_lock); |
| 507 | VkCommandPool pool = command_pool_map[object]; |
| 508 | lock.unlock(); |
| 509 | c_VkCommandPoolContents.FinishRead(pool); |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 510 | } """ |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 511 | |
| 512 | |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 513 | inline_custom_source_preamble = """ |
| 514 | void ThreadSafety::PreCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, |
| 515 | VkCommandBuffer *pCommandBuffers) { |
| 516 | StartReadObject(device); |
| 517 | StartWriteObject(pAllocateInfo->commandPool); |
| 518 | } |
| 519 | |
| 520 | void ThreadSafety::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 521 | VkCommandBuffer *pCommandBuffers, VkResult result) { |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 522 | FinishReadObject(device); |
| 523 | FinishWriteObject(pAllocateInfo->commandPool); |
| 524 | |
| 525 | // Record mapping from command buffer to command pool |
| John Zulauf | c9f979e | 2019-04-29 08:51:15 -0600 | [diff] [blame] | 526 | if(pCommandBuffers) { |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 527 | std::lock_guard<std::mutex> lock(command_pool_lock); |
| John Zulauf | c9f979e | 2019-04-29 08:51:15 -0600 | [diff] [blame] | 528 | for (uint32_t index = 0; index < pAllocateInfo->commandBufferCount; index++) { |
| 529 | command_pool_map[pCommandBuffers[index]] = pAllocateInfo->commandPool; |
| 530 | } |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
| 534 | void ThreadSafety::PreCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| 535 | VkDescriptorSet *pDescriptorSets) { |
| 536 | StartReadObject(device); |
| 537 | StartWriteObject(pAllocateInfo->descriptorPool); |
| 538 | // Host access to pAllocateInfo::descriptorPool must be externally synchronized |
| 539 | } |
| 540 | |
| 541 | void ThreadSafety::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo, |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 542 | VkDescriptorSet *pDescriptorSets, VkResult result) { |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 543 | FinishReadObject(device); |
| 544 | FinishWriteObject(pAllocateInfo->descriptorPool); |
| 545 | // Host access to pAllocateInfo::descriptorPool must be externally synchronized |
| 546 | } |
| 547 | |
| 548 | void ThreadSafety::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, |
| 549 | const VkCommandBuffer *pCommandBuffers) { |
| 550 | const bool lockCommandPool = false; // pool is already directly locked |
| 551 | StartReadObject(device); |
| 552 | StartWriteObject(commandPool); |
| John Zulauf | c9f979e | 2019-04-29 08:51:15 -0600 | [diff] [blame] | 553 | if(pCommandBuffers) { |
| 554 | // Even though we're immediately "finishing" below, we still are testing for concurrency with any call in process |
| 555 | // so this isn't a no-op |
| 556 | for (uint32_t index = 0; index < commandBufferCount; index++) { |
| 557 | StartWriteObject(pCommandBuffers[index], lockCommandPool); |
| 558 | } |
| 559 | // The driver may immediately reuse command buffers in another thread. |
| 560 | // These updates need to be done before calling down to the driver. |
| 561 | for (uint32_t index = 0; index < commandBufferCount; index++) { |
| 562 | FinishWriteObject(pCommandBuffers[index], lockCommandPool); |
| 563 | } |
| 564 | // Holding the lock for the shortest time while we update the map |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 565 | std::lock_guard<std::mutex> lock(command_pool_lock); |
| John Zulauf | c9f979e | 2019-04-29 08:51:15 -0600 | [diff] [blame] | 566 | for (uint32_t index = 0; index < commandBufferCount; index++) { |
| 567 | command_pool_map.erase(pCommandBuffers[index]); |
| 568 | } |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
| 572 | void ThreadSafety::PostCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, |
| 573 | const VkCommandBuffer *pCommandBuffers) { |
| 574 | FinishReadObject(device); |
| 575 | FinishWriteObject(commandPool); |
| 576 | } |
| 577 | |
| 578 | void ThreadSafety::PreCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) { |
| 579 | StartReadObject(device); |
| 580 | StartWriteObject(commandPool); |
| 581 | // Check for any uses of non-externally sync'd command buffers (for example from vkCmdExecuteCommands) |
| 582 | c_VkCommandPoolContents.StartWrite(commandPool); |
| 583 | // Host access to commandPool must be externally synchronized |
| 584 | } |
| 585 | |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 586 | void ThreadSafety::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags, VkResult result) { |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 587 | FinishReadObject(device); |
| 588 | FinishWriteObject(commandPool); |
| 589 | c_VkCommandPoolContents.FinishWrite(commandPool); |
| 590 | // Host access to commandPool must be externally synchronized |
| 591 | } |
| 592 | |
| 593 | void ThreadSafety::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) { |
| 594 | StartReadObject(device); |
| 595 | StartWriteObject(commandPool); |
| 596 | // Check for any uses of non-externally sync'd command buffers (for example from vkCmdExecuteCommands) |
| 597 | c_VkCommandPoolContents.StartWrite(commandPool); |
| 598 | // Host access to commandPool must be externally synchronized |
| 599 | } |
| 600 | |
| 601 | void ThreadSafety::PostCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) { |
| 602 | FinishReadObject(device); |
| 603 | FinishWriteObject(commandPool); |
| 604 | c_VkCommandPoolContents.FinishWrite(commandPool); |
| 605 | } |
| 606 | |
| Mark Lobodzinski | 8925c05 | 2018-12-18 12:41:15 -0700 | [diff] [blame] | 607 | // GetSwapchainImages can return a non-zero count with a NULL pSwapchainImages pointer. Let's avoid crashes by ignoring |
| 608 | // pSwapchainImages. |
| 609 | void ThreadSafety::PreCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, |
| 610 | VkImage *pSwapchainImages) { |
| 611 | StartReadObject(device); |
| 612 | StartReadObject(swapchain); |
| 613 | } |
| 614 | |
| 615 | void ThreadSafety::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount, |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 616 | VkImage *pSwapchainImages, VkResult result) { |
| Mark Lobodzinski | 8925c05 | 2018-12-18 12:41:15 -0700 | [diff] [blame] | 617 | FinishReadObject(device); |
| 618 | FinishReadObject(swapchain); |
| 619 | } |
| 620 | |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 621 | """ |
| 622 | |
| 623 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 624 | # This is an ordered list of sections in the header file. |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 625 | ALL_SECTIONS = ['command'] |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 626 | def __init__(self, |
| 627 | errFile = sys.stderr, |
| 628 | warnFile = sys.stderr, |
| 629 | diagFile = sys.stdout): |
| 630 | OutputGenerator.__init__(self, errFile, warnFile, diagFile) |
| 631 | # Internal state - accumulators for different inner block text |
| 632 | self.sections = dict([(section, []) for section in self.ALL_SECTIONS]) |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 633 | self.non_dispatchable_types = set() |
| 634 | self.object_to_debug_report_type = { |
| 635 | 'VkInstance' : 'VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT', |
| 636 | 'VkPhysicalDevice' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT', |
| 637 | 'VkDevice' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT', |
| 638 | 'VkQueue' : 'VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT', |
| 639 | 'VkSemaphore' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT', |
| 640 | 'VkCommandBuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT', |
| 641 | 'VkFence' : 'VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT', |
| 642 | 'VkDeviceMemory' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT', |
| 643 | 'VkBuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT', |
| 644 | 'VkImage' : 'VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT', |
| 645 | 'VkEvent' : 'VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT', |
| 646 | 'VkQueryPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT', |
| 647 | 'VkBufferView' : 'VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT', |
| 648 | 'VkImageView' : 'VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT', |
| 649 | 'VkShaderModule' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT', |
| 650 | 'VkPipelineCache' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT', |
| 651 | 'VkPipelineLayout' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT', |
| 652 | 'VkRenderPass' : 'VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT', |
| 653 | 'VkPipeline' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT', |
| 654 | 'VkDescriptorSetLayout' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT', |
| 655 | 'VkSampler' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT', |
| 656 | 'VkDescriptorPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT', |
| 657 | 'VkDescriptorSet' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT', |
| 658 | 'VkFramebuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT', |
| 659 | 'VkCommandPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT', |
| 660 | 'VkSurfaceKHR' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT', |
| 661 | 'VkSwapchainKHR' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT', |
| 662 | 'VkDisplayKHR' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT', |
| 663 | 'VkDisplayModeKHR' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT', |
| 664 | 'VkObjectTableNVX' : 'VK_DEBUG_REPORT_OBJECT_TYPE_OBJECT_TABLE_NVX_EXT', |
| 665 | 'VkIndirectCommandsLayoutNVX' : 'VK_DEBUG_REPORT_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX_EXT', |
| 666 | 'VkSamplerYcbcrConversion' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION_EXT', |
| 667 | 'VkDescriptorUpdateTemplate' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_EXT', |
| 668 | 'VkAccelerationStructureNV' : 'VK_DEBUG_REPORT_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV_EXT', |
| 669 | 'VkDebugReportCallbackEXT' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT', |
| 670 | 'VkValidationCacheEXT' : 'VK_DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT' } |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 671 | |
| 672 | # Check if the parameter passed in is a pointer to an array |
| 673 | def paramIsArray(self, param): |
| 674 | return param.attrib.get('len') is not None |
| 675 | |
| 676 | # Check if the parameter passed in is a pointer |
| 677 | def paramIsPointer(self, param): |
| 678 | ispointer = False |
| 679 | for elem in param: |
| Raul Tambre | 7b30018 | 2019-05-04 11:25:14 +0300 | [diff] [blame^] | 680 | if elem.tag == 'type' and elem.tail is not None and '*' in elem.tail: |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 681 | ispointer = True |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 682 | return ispointer |
| Mark Lobodzinski | 60b77b3 | 2017-02-14 09:16:56 -0700 | [diff] [blame] | 683 | |
| 684 | # Check if an object is a non-dispatchable handle |
| 685 | def isHandleTypeNonDispatchable(self, handletype): |
| 686 | handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']") |
| 687 | if handle is not None and handle.find('type').text == 'VK_DEFINE_NON_DISPATCHABLE_HANDLE': |
| 688 | return True |
| 689 | else: |
| 690 | return False |
| 691 | |
| 692 | # Check if an object is a dispatchable handle |
| 693 | def isHandleTypeDispatchable(self, handletype): |
| 694 | handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']") |
| 695 | if handle is not None and handle.find('type').text == 'VK_DEFINE_HANDLE': |
| 696 | return True |
| 697 | else: |
| 698 | return False |
| 699 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 700 | def makeThreadUseBlock(self, cmd, functionprefix): |
| 701 | """Generate C function pointer typedef for <command> Element""" |
| 702 | paramdecl = '' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 703 | # Find and add any parameters that are thread unsafe |
| 704 | params = cmd.findall('param') |
| 705 | for param in params: |
| 706 | paramname = param.find('name') |
| 707 | if False: # self.paramIsPointer(param): |
| 708 | paramdecl += ' // not watching use of pointer ' + paramname.text + '\n' |
| 709 | else: |
| 710 | externsync = param.attrib.get('externsync') |
| 711 | if externsync == 'true': |
| 712 | if self.paramIsArray(param): |
| John Zulauf | 0320864 | 2019-04-24 14:40:41 -0600 | [diff] [blame] | 713 | paramdecl += 'if (' + paramname.text + ') {\n' |
| 714 | paramdecl += ' for (uint32_t index=0; index < ' + param.attrib.get('len') + '; index++) {\n' |
| 715 | paramdecl += ' ' + functionprefix + 'WriteObject(' + paramname.text + '[index]);\n' |
| 716 | paramdecl += ' }\n' |
| Mark Lobodzinski | 716a4f9 | 2018-11-16 08:54:20 -0700 | [diff] [blame] | 717 | paramdecl += '}\n' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 718 | else: |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 719 | paramdecl += functionprefix + 'WriteObject(' + paramname.text + ');\n' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 720 | elif (param.attrib.get('externsync')): |
| 721 | if self.paramIsArray(param): |
| 722 | # Externsync can list pointers to arrays of members to synchronize |
| John Zulauf | 0320864 | 2019-04-24 14:40:41 -0600 | [diff] [blame] | 723 | paramdecl += 'if (' + paramname.text + ') {\n' |
| 724 | paramdecl += ' for (uint32_t index=0; index < ' + param.attrib.get('len') + '; index++) {\n' |
| 725 | second_indent = ' ' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 726 | for member in externsync.split(","): |
| 727 | # Replace first empty [] in member name with index |
| 728 | element = member.replace('[]','[index]',1) |
| 729 | if '[]' in element: |
| Mark Lobodzinski | 6d49566 | 2019-02-15 11:54:53 -0700 | [diff] [blame] | 730 | # TODO: These null checks can be removed if threading ends up behind parameter |
| 731 | # validation in layer order |
| 732 | element_ptr = element.split('[]')[0] |
| John Zulauf | 0320864 | 2019-04-24 14:40:41 -0600 | [diff] [blame] | 733 | paramdecl += ' if (' + element_ptr + ') {\n' |
| Mark Lobodzinski | 6d49566 | 2019-02-15 11:54:53 -0700 | [diff] [blame] | 734 | # Replace any second empty [] in element name with inner array index based on mapping array |
| 735 | # names like "pSomeThings[]" to "someThingCount" array size. This could be more robust by |
| 736 | # mapping a param member name to a struct type and "len" attribute. |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 737 | limit = element[0:element.find('s[]')] + 'Count' |
| 738 | dotp = limit.rfind('.p') |
| 739 | limit = limit[0:dotp+1] + limit[dotp+2:dotp+3].lower() + limit[dotp+3:] |
| John Zulauf | 0320864 | 2019-04-24 14:40:41 -0600 | [diff] [blame] | 740 | paramdecl += ' for (uint32_t index2=0; index2 < '+limit+'; index2++) {\n' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 741 | element = element.replace('[]','[index2]') |
| John Zulauf | 0320864 | 2019-04-24 14:40:41 -0600 | [diff] [blame] | 742 | second_indent = ' ' |
| Mark Lobodzinski | 6d49566 | 2019-02-15 11:54:53 -0700 | [diff] [blame] | 743 | paramdecl += ' ' + second_indent + functionprefix + 'WriteObject(' + element + ');\n' |
| John Zulauf | 0320864 | 2019-04-24 14:40:41 -0600 | [diff] [blame] | 744 | paramdecl += ' }\n' |
| Mark Lobodzinski | 6d49566 | 2019-02-15 11:54:53 -0700 | [diff] [blame] | 745 | paramdecl += ' }\n' |
| Mark Lobodzinski | 6d49566 | 2019-02-15 11:54:53 -0700 | [diff] [blame] | 746 | else: |
| 747 | paramdecl += ' ' + second_indent + functionprefix + 'WriteObject(' + element + ');\n' |
| John Zulauf | 0320864 | 2019-04-24 14:40:41 -0600 | [diff] [blame] | 748 | paramdecl += ' }\n' |
| Mark Lobodzinski | 716a4f9 | 2018-11-16 08:54:20 -0700 | [diff] [blame] | 749 | paramdecl += '}\n' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 750 | else: |
| 751 | # externsync can list members to synchronize |
| 752 | for member in externsync.split(","): |
| 753 | member = str(member).replace("::", "->") |
| Mark Lobodzinski | 9c14780 | 2017-02-10 08:34:54 -0700 | [diff] [blame] | 754 | member = str(member).replace(".", "->") |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 755 | paramdecl += ' ' + functionprefix + 'WriteObject(' + member + ');\n' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 756 | else: |
| 757 | paramtype = param.find('type') |
| 758 | if paramtype is not None: |
| 759 | paramtype = paramtype.text |
| 760 | else: |
| 761 | paramtype = 'None' |
| Mark Lobodzinski | 60b77b3 | 2017-02-14 09:16:56 -0700 | [diff] [blame] | 762 | if (self.isHandleTypeDispatchable(paramtype) or self.isHandleTypeNonDispatchable(paramtype)) and paramtype != 'VkPhysicalDevice': |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 763 | if self.paramIsArray(param) and ('pPipelines' != paramname.text): |
| Mark Lobodzinski | 9c14780 | 2017-02-10 08:34:54 -0700 | [diff] [blame] | 764 | # Add pointer dereference for array counts that are pointer values |
| 765 | dereference = '' |
| 766 | for candidate in params: |
| 767 | if param.attrib.get('len') == candidate.find('name').text: |
| 768 | if self.paramIsPointer(candidate): |
| 769 | dereference = '*' |
| Mark Lobodzinski | 60b77b3 | 2017-02-14 09:16:56 -0700 | [diff] [blame] | 770 | param_len = str(param.attrib.get('len')).replace("::", "->") |
| John Zulauf | 0320864 | 2019-04-24 14:40:41 -0600 | [diff] [blame] | 771 | paramdecl += 'if (' + paramname.text + ') {\n' |
| 772 | paramdecl += ' for (uint32_t index = 0; index < ' + dereference + param_len + '; index++) {\n' |
| 773 | paramdecl += ' ' + functionprefix + 'ReadObject(' + paramname.text + '[index]);\n' |
| 774 | paramdecl += ' }\n' |
| Mark Lobodzinski | 716a4f9 | 2018-11-16 08:54:20 -0700 | [diff] [blame] | 775 | paramdecl += '}\n' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 776 | elif not self.paramIsPointer(param): |
| 777 | # Pointer params are often being created. |
| 778 | # They are not being read from. |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 779 | paramdecl += functionprefix + 'ReadObject(' + paramname.text + ');\n' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 780 | explicitexternsyncparams = cmd.findall("param[@externsync]") |
| 781 | if (explicitexternsyncparams is not None): |
| 782 | for param in explicitexternsyncparams: |
| 783 | externsyncattrib = param.attrib.get('externsync') |
| 784 | paramname = param.find('name') |
| Mark Lobodzinski | 716a4f9 | 2018-11-16 08:54:20 -0700 | [diff] [blame] | 785 | paramdecl += '// Host access to ' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 786 | if externsyncattrib == 'true': |
| 787 | if self.paramIsArray(param): |
| 788 | paramdecl += 'each member of ' + paramname.text |
| 789 | elif self.paramIsPointer(param): |
| 790 | paramdecl += 'the object referenced by ' + paramname.text |
| 791 | else: |
| 792 | paramdecl += paramname.text |
| 793 | else: |
| 794 | paramdecl += externsyncattrib |
| 795 | paramdecl += ' must be externally synchronized\n' |
| 796 | |
| 797 | # Find and add any "implicit" parameters that are thread unsafe |
| 798 | implicitexternsyncparams = cmd.find('implicitexternsyncparams') |
| 799 | if (implicitexternsyncparams is not None): |
| 800 | for elem in implicitexternsyncparams: |
| Mark Lobodzinski | 716a4f9 | 2018-11-16 08:54:20 -0700 | [diff] [blame] | 801 | paramdecl += '// ' |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 802 | paramdecl += elem.text |
| 803 | paramdecl += ' must be externally synchronized between host accesses\n' |
| 804 | |
| 805 | if (paramdecl == ''): |
| 806 | return None |
| 807 | else: |
| 808 | return paramdecl |
| 809 | def beginFile(self, genOpts): |
| 810 | OutputGenerator.beginFile(self, genOpts) |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 811 | # |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 812 | # TODO: LUGMAL -- remove this and add our copyright |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 813 | # User-supplied prefix text, if any (list of strings) |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 814 | write(self.inline_copyright_message, file=self.outFile) |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 815 | |
| 816 | self.header_file = (genOpts.filename == 'thread_safety.h') |
| 817 | self.source_file = (genOpts.filename == 'thread_safety.cpp') |
| 818 | |
| 819 | if not self.header_file and not self.source_file: |
| 820 | print("Error: Output Filenames have changed, update generator source.\n") |
| 821 | sys.exit(1) |
| 822 | |
| 823 | if self.source_file: |
| 824 | write('#include "chassis.h"', file=self.outFile) |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 825 | write('#include "thread_safety.h"', file=self.outFile) |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 826 | self.newline() |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 827 | write(self.inline_custom_source_preamble, file=self.outFile) |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 828 | |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 829 | |
| 830 | def endFile(self): |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 831 | |
| 832 | # Create class definitions |
| 833 | counter_class_defs = '' |
| 834 | counter_class_instances = '' |
| 835 | counter_class_bodies = '' |
| 836 | |
| 837 | for obj in self.non_dispatchable_types: |
| 838 | counter_class_defs += ' counter<%s> c_%s;\n' % (obj, obj) |
| 839 | if obj in self.object_to_debug_report_type: |
| 840 | obj_type = self.object_to_debug_report_type[obj] |
| 841 | else: |
| 842 | obj_type = 'VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT' |
| 843 | counter_class_instances += ' c_%s("%s", %s, &report_data),\n' % (obj, obj, obj_type) |
| 844 | counter_class_bodies += 'WRAPPER(%s)\n' % obj |
| 845 | if self.header_file: |
| 846 | class_def = self.inline_custom_header_preamble.replace('COUNTER_CLASS_DEFINITIONS_TEMPLATE', counter_class_defs) |
| 847 | class_def = class_def.replace('COUNTER_CLASS_INSTANCES_TEMPLATE', counter_class_instances[:-2]) # Kill last comma |
| 848 | class_def = class_def.replace('COUNTER_CLASS_BODIES_TEMPLATE', counter_class_bodies) |
| 849 | write(class_def, file=self.outFile) |
| 850 | write('\n'.join(self.sections['command']), file=self.outFile) |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 851 | if self.header_file: |
| 852 | write('};', file=self.outFile) |
| 853 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 854 | # Finish processing in superclass |
| 855 | OutputGenerator.endFile(self) |
| Mark Lobodzinski | 706e52b | 2018-12-11 13:21:52 -0700 | [diff] [blame] | 856 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 857 | def beginFeature(self, interface, emit): |
| 858 | #write('// starting beginFeature', file=self.outFile) |
| 859 | # Start processing in superclass |
| 860 | OutputGenerator.beginFeature(self, interface, emit) |
| 861 | # C-specific |
| 862 | # Accumulate includes, defines, types, enums, function pointer typedefs, |
| 863 | # end function prototypes separately for this feature. They're only |
| 864 | # printed in endFeature(). |
| Mark Lobodzinski | 62f7156 | 2017-10-24 13:41:18 -0600 | [diff] [blame] | 865 | self.featureExtraProtect = GetFeatureProtect(interface) |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 866 | if (self.featureExtraProtect is not None): |
| 867 | self.appendSection('command', '\n#ifdef %s' % self.featureExtraProtect) |
| 868 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 869 | #write('// ending beginFeature', file=self.outFile) |
| 870 | def endFeature(self): |
| 871 | # C-specific |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 872 | if (self.emit): |
| MichaĆ Janiszewski | 3c3ce9e | 2018-10-30 23:25:21 +0100 | [diff] [blame] | 873 | if (self.featureExtraProtect is not None): |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 874 | self.appendSection('command', '#endif // %s' % self.featureExtraProtect) |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 875 | # Finish processing in superclass |
| 876 | OutputGenerator.endFeature(self) |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 877 | # |
| 878 | # Append a definition to the specified section |
| 879 | def appendSection(self, section, text): |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 880 | self.sections[section].append(text) |
| 881 | # |
| 882 | # Type generation |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 883 | def genType(self, typeinfo, name, alias): |
| Mark Lobodzinski | 796454c | 2018-12-11 16:10:55 -0700 | [diff] [blame] | 884 | OutputGenerator.genType(self, typeinfo, name, alias) |
| 885 | type_elem = typeinfo.elem |
| 886 | category = type_elem.get('category') |
| 887 | if category == 'handle': |
| 888 | if self.isHandleTypeNonDispatchable(name): |
| 889 | self.non_dispatchable_types.add(name) |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 890 | # |
| 891 | # Struct (e.g. C "struct" type) generation. |
| 892 | # This is a special case of the <type> tag where the contents are |
| 893 | # interpreted as a set of <member> tags instead of freeform C |
| 894 | # C type declarations. The <member> tags are just like <param> |
| 895 | # tags - they are a declaration of a struct or union member. |
| 896 | # Only simple member declarations are supported (no nested |
| 897 | # structs etc.) |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 898 | def genStruct(self, typeinfo, typeName, alias): |
| 899 | OutputGenerator.genStruct(self, typeinfo, typeName, alias) |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 900 | body = 'typedef ' + typeinfo.elem.get('category') + ' ' + typeName + ' {\n' |
| 901 | # paramdecl = self.makeCParamDecl(typeinfo.elem, self.genOpts.alignFuncParam) |
| 902 | for member in typeinfo.elem.findall('.//member'): |
| 903 | body += self.makeCParamDecl(member, self.genOpts.alignFuncParam) |
| 904 | body += ';\n' |
| 905 | body += '} ' + typeName + ';\n' |
| 906 | self.appendSection('struct', body) |
| 907 | # |
| 908 | # Group (e.g. C "enum" type) generation. |
| 909 | # These are concatenated together with other types. |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 910 | def genGroup(self, groupinfo, groupName, alias): |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 911 | pass |
| 912 | # Enumerant generation |
| 913 | # <enum> tags may specify their values in several ways, but are usually |
| 914 | # just integers. |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 915 | def genEnum(self, enuminfo, name, alias): |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 916 | pass |
| 917 | # |
| 918 | # Command generation |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 919 | def genCmd(self, cmdinfo, name, alias): |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 920 | # Commands shadowed by interface functions and are not implemented |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 921 | special_functions = [ |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 922 | 'vkCreateDevice', |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 923 | 'vkCreateInstance', |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 924 | 'vkAllocateCommandBuffers', |
| 925 | 'vkFreeCommandBuffers', |
| John Zulauf | e28aa34 | 2018-10-24 12:18:39 -0600 | [diff] [blame] | 926 | 'vkResetCommandPool', |
| 927 | 'vkDestroyCommandPool', |
| Mark Lobodzinski | 3bd82ad | 2017-02-16 11:45:27 -0700 | [diff] [blame] | 928 | 'vkAllocateDescriptorSets', |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 929 | 'vkQueuePresentKHR', |
| Mark Lobodzinski | 8925c05 | 2018-12-18 12:41:15 -0700 | [diff] [blame] | 930 | 'vkGetSwapchainImagesKHR', |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 931 | ] |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 932 | if name == 'vkQueuePresentKHR' or (name in special_functions and self.source_file): |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 933 | return |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 934 | |
| 935 | if (("DebugMarker" in name or "DebugUtilsObject" in name) and "EXT" in name): |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 936 | self.appendSection('command', '// TODO - not wrapping EXT function ' + name) |
| 937 | return |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 938 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 939 | # Determine first if this function needs to be intercepted |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 940 | startthreadsafety = self.makeThreadUseBlock(cmdinfo.elem, 'Start') |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 941 | if startthreadsafety is None: |
| 942 | return |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 943 | finishthreadsafety = self.makeThreadUseBlock(cmdinfo.elem, 'Finish') |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 944 | |
| Mike Schuchardt | f375c7c | 2017-12-28 11:23:48 -0700 | [diff] [blame] | 945 | OutputGenerator.genCmd(self, cmdinfo, name, alias) |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 946 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 947 | # setup common to call wrappers |
| 948 | # first parameter is always dispatchable |
| 949 | dispatchable_type = cmdinfo.elem.find('param/type').text |
| 950 | dispatchable_name = cmdinfo.elem.find('param/name').text |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 951 | |
| 952 | decls = self.makeCDecls(cmdinfo.elem) |
| 953 | |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 954 | result_type = cmdinfo.elem.find('proto/type') |
| 955 | |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 956 | if self.source_file: |
| 957 | pre_decl = decls[0][:-1] |
| 958 | pre_decl = pre_decl.split("VKAPI_CALL ")[1] |
| 959 | pre_decl = 'void ThreadSafety::PreCallRecord' + pre_decl + ' {' |
| 960 | |
| 961 | # PreCallRecord |
| 962 | self.appendSection('command', '') |
| 963 | self.appendSection('command', pre_decl) |
| 964 | self.appendSection('command', " " + "\n ".join(str(startthreadsafety).rstrip().split("\n"))) |
| 965 | self.appendSection('command', '}') |
| 966 | |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 967 | # PostCallRecord |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 968 | post_decl = pre_decl.replace('PreCallRecord', 'PostCallRecord') |
| 969 | if result_type.text == 'VkResult': |
| 970 | post_decl = post_decl.replace(')', ',\n VkResult result)') |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 971 | self.appendSection('command', '') |
| 972 | self.appendSection('command', post_decl) |
| 973 | self.appendSection('command', " " + "\n ".join(str(finishthreadsafety).rstrip().split("\n"))) |
| 974 | self.appendSection('command', '}') |
| 975 | |
| 976 | if self.header_file: |
| 977 | pre_decl = decls[0][:-1] |
| 978 | pre_decl = pre_decl.split("VKAPI_CALL ")[1] |
| 979 | pre_decl = 'void PreCallRecord' + pre_decl + ';' |
| 980 | |
| 981 | # PreCallRecord |
| 982 | self.appendSection('command', '') |
| 983 | self.appendSection('command', pre_decl) |
| 984 | |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 985 | # PostCallRecord |
| Mark Lobodzinski | cd05c1e | 2019-01-17 15:33:46 -0700 | [diff] [blame] | 986 | post_decl = pre_decl.replace('PreCallRecord', 'PostCallRecord') |
| 987 | if result_type.text == 'VkResult': |
| 988 | post_decl = post_decl.replace(')', ',\n VkResult result)') |
| Mark Lobodzinski | 1f2ba26 | 2018-12-04 14:15:47 -0700 | [diff] [blame] | 989 | self.appendSection('command', '') |
| 990 | self.appendSection('command', post_decl) |
| 991 | |
| Mark Lobodzinski | ff91099 | 2016-10-11 14:29:52 -0600 | [diff] [blame] | 992 | # |
| 993 | # override makeProtoName to drop the "vk" prefix |
| 994 | def makeProtoName(self, name, tail): |
| 995 | return self.genOpts.apientry + name[2:] + tail |