blob: 4cb3288529fa84828da0f6692ecc6e03c1c3a0ad [file] [log] [blame]
Mark Lobodzinskiff910992016-10-11 14:29:52 -06001#!/usr/bin/python3 -i
2#
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -07003# 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 Lobodzinskiff910992016-10-11 14:29:52 -06007#
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 Lobodzinskid3b439e2017-06-07 13:08:41 -060021# Author: Mark Lobodzinski <mark@lunarg.com>
Mark Lobodzinskiff910992016-10-11 14:29:52 -060022
23import os,re,sys
24from generator import *
Mark Lobodzinski62f71562017-10-24 13:41:18 -060025from common_codegen import *
Mark Lobodzinskiff910992016-10-11 14:29:52 -060026
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
60class ThreadGeneratorOptions(GeneratorOptions):
61 def __init__(self,
62 filename = None,
63 directory = '.',
64 apiname = None,
65 profile = None,
66 versions = '.*',
67 emitversions = '.*',
68 defaultExtensions = None,
69 addExtensions = None,
70 removeExtensions = None,
Mark Lobodzinski62f71562017-10-24 13:41:18 -060071 emitExtensions = None,
Mark Lobodzinskiff910992016-10-11 14:29:52 -060072 sortProcedure = regSortFeatures,
73 prefixText = "",
74 genFuncPointers = True,
75 protectFile = True,
76 protectFeature = True,
Mark Lobodzinskiff910992016-10-11 14:29:52 -060077 apicall = '',
78 apientry = '',
79 apientryp = '',
80 indentFuncProto = True,
81 indentFuncPointer = False,
Mark Lobodzinski62f71562017-10-24 13:41:18 -060082 alignFuncParam = 0,
83 expandEnumerants = True):
Mark Lobodzinskiff910992016-10-11 14:29:52 -060084 GeneratorOptions.__init__(self, filename, directory, apiname, profile,
85 versions, emitversions, defaultExtensions,
Mark Lobodzinski62f71562017-10-24 13:41:18 -060086 addExtensions, removeExtensions, emitExtensions, sortProcedure)
Mark Lobodzinskiff910992016-10-11 14:29:52 -060087 self.prefixText = prefixText
88 self.genFuncPointers = genFuncPointers
89 self.protectFile = protectFile
90 self.protectFeature = protectFeature
Mark Lobodzinskiff910992016-10-11 14:29:52 -060091 self.apicall = apicall
92 self.apientry = apientry
93 self.apientryp = apientryp
94 self.indentFuncProto = indentFuncProto
95 self.indentFuncPointer = indentFuncPointer
96 self.alignFuncParam = alignFuncParam
Mark Lobodzinski62f71562017-10-24 13:41:18 -060097 self.expandEnumerants = expandEnumerants
98
Mark Lobodzinskiff910992016-10-11 14:29:52 -060099
100# ThreadOutputGenerator - subclass of OutputGenerator.
101# Generates Thread checking framework
102#
103# ---- methods ----
104# ThreadOutputGenerator(errFile, warnFile, diagFile) - args as for
105# OutputGenerator. Defines additional internal state.
106# ---- methods overriding base class ----
107# beginFile(genOpts)
108# endFile()
109# beginFeature(interface, emit)
110# endFeature()
111# genType(typeinfo,name)
112# genStruct(typeinfo,name)
113# genGroup(groupinfo,name)
114# genEnum(enuminfo, name)
115# genCmd(cmdinfo)
116class ThreadOutputGenerator(OutputGenerator):
117 """Generate specified API interfaces in a specific style, such as a C header"""
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700118
119 inline_copyright_message = """
120// This file is ***GENERATED***. Do Not Edit.
121// See layer_chassis_dispatch_generator.py for modifications.
122
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700123/* Copyright (c) 2015-2019 The Khronos Group Inc.
124 * Copyright (c) 2015-2019 Valve Corporation
125 * Copyright (c) 2015-2019 LunarG, Inc.
126 * Copyright (c) 2015-2019 Google Inc.
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700127 *
128 * Licensed under the Apache License, Version 2.0 (the "License");
129 * you may not use this file except in compliance with the License.
130 * You may obtain a copy of the License at
131 *
132 * http://www.apache.org/licenses/LICENSE-2.0
133 *
134 * Unless required by applicable law or agreed to in writing, software
135 * distributed under the License is distributed on an "AS IS" BASIS,
136 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137 * See the License for the specific language governing permissions and
138 * limitations under the License.
139 *
140 * Author: Mark Lobodzinski <mark@lunarg.com>
141 */"""
142
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700143 # Note that the inline_custom_header_preamble template below contains three embedded template expansion identifiers.
144 # These get replaced with generated code sections, and are labeled:
145 # o COUNTER_CLASS_DEFINITIONS_TEMPLATE
146 # o COUNTER_CLASS_INSTANCES_TEMPLATE
147 # o COUNTER_CLASS_BODIES_TEMPLATE
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700148 inline_custom_header_preamble = """
149#pragma once
150
151#include <condition_variable>
152#include <mutex>
153#include <vector>
154#include <unordered_set>
155#include <string>
156
157VK_DEFINE_NON_DISPATCHABLE_HANDLE(DISTINCT_NONDISPATCHABLE_PHONY_HANDLE)
158// The following line must match the vulkan_core.h condition guarding VK_DEFINE_NON_DISPATCHABLE_HANDLE
159#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
160 defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
161// If pointers are 64-bit, then there can be separate counters for each
162// NONDISPATCHABLE_HANDLE type. Otherwise they are all typedef uint64_t.
163#define DISTINCT_NONDISPATCHABLE_HANDLES
164// Make sure we catch any disagreement between us and the vulkan definition
165static_assert(std::is_pointer<DISTINCT_NONDISPATCHABLE_PHONY_HANDLE>::value,
166 "Mismatched non-dispatchable handle handle, expected pointer type.");
167#else
168// Make sure we catch any disagreement between us and the vulkan definition
169static_assert(std::is_same<uint64_t, DISTINCT_NONDISPATCHABLE_PHONY_HANDLE>::value,
170 "Mismatched non-dispatchable handle handle, expected uint64_t.");
171#endif
172
173// Suppress unused warning on Linux
174#if defined(__GNUC__)
175#define DECORATE_UNUSED __attribute__((unused))
176#else
177#define DECORATE_UNUSED
178#endif
179
180// clang-format off
181static const char DECORATE_UNUSED *kVUID_Threading_Info = "UNASSIGNED-Threading-Info";
182static const char DECORATE_UNUSED *kVUID_Threading_MultipleThreads = "UNASSIGNED-Threading-MultipleThreads";
183static const char DECORATE_UNUSED *kVUID_Threading_SingleThreadReuse = "UNASSIGNED-Threading-SingleThreadReuse";
184// clang-format on
185
186#undef DECORATE_UNUSED
187
188struct object_use_data {
189 loader_platform_thread_id thread;
190 int reader_count;
191 int writer_count;
192};
193
194template <typename T>
195class counter {
196public:
197 const char *typeName;
198 VkDebugReportObjectTypeEXT objectType;
199 debug_report_data **report_data;
200 std::unordered_map<T, object_use_data> uses;
201 std::mutex counter_lock;
202 std::condition_variable counter_condition;
203
204
205 void StartWrite(T object) {
206 if (object == VK_NULL_HANDLE) {
207 return;
208 }
209 bool skip = false;
210 loader_platform_thread_id tid = loader_platform_get_thread_id();
211 std::unique_lock<std::mutex> lock(counter_lock);
212 if (uses.find(object) == uses.end()) {
213 // There is no current use of the object. Record writer thread.
214 struct object_use_data *use_data = &uses[object];
215 use_data->reader_count = 0;
216 use_data->writer_count = 1;
217 use_data->thread = tid;
218 } else {
219 struct object_use_data *use_data = &uses[object];
220 if (use_data->reader_count == 0) {
221 // There are no readers. Two writers just collided.
222 if (use_data->thread != tid) {
223 skip |= log_msg(*report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object),
224 kVUID_Threading_MultipleThreads,
225 "THREADING ERROR : object of type %s is simultaneously used in "
226 "thread 0x%" PRIx64 " and thread 0x%" PRIx64,
227 typeName, (uint64_t)use_data->thread, (uint64_t)tid);
228 if (skip) {
229 // Wait for thread-safe access to object instead of skipping call.
230 while (uses.find(object) != uses.end()) {
231 counter_condition.wait(lock);
232 }
233 // There is now no current use of the object. Record writer thread.
234 struct object_use_data *new_use_data = &uses[object];
235 new_use_data->thread = tid;
236 new_use_data->reader_count = 0;
237 new_use_data->writer_count = 1;
238 } else {
239 // Continue with an unsafe use of the object.
240 use_data->thread = tid;
241 use_data->writer_count += 1;
242 }
243 } else {
244 // This is either safe multiple use in one call, or recursive use.
245 // There is no way to make recursion safe. Just forge ahead.
246 use_data->writer_count += 1;
247 }
248 } else {
249 // There are readers. This writer collided with them.
250 if (use_data->thread != tid) {
251 skip |= log_msg(*report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object),
252 kVUID_Threading_MultipleThreads,
253 "THREADING ERROR : object of type %s is simultaneously used in "
254 "thread 0x%" PRIx64 " and thread 0x%" PRIx64,
255 typeName, (uint64_t)use_data->thread, (uint64_t)tid);
256 if (skip) {
257 // Wait for thread-safe access to object instead of skipping call.
258 while (uses.find(object) != uses.end()) {
259 counter_condition.wait(lock);
260 }
261 // There is now no current use of the object. Record writer thread.
262 struct object_use_data *new_use_data = &uses[object];
263 new_use_data->thread = tid;
264 new_use_data->reader_count = 0;
265 new_use_data->writer_count = 1;
266 } else {
267 // Continue with an unsafe use of the object.
268 use_data->thread = tid;
269 use_data->writer_count += 1;
270 }
271 } else {
272 // This is either safe multiple use in one call, or recursive use.
273 // There is no way to make recursion safe. Just forge ahead.
274 use_data->writer_count += 1;
275 }
276 }
277 }
278 }
279
280 void FinishWrite(T object) {
281 if (object == VK_NULL_HANDLE) {
282 return;
283 }
284 // Object is no longer in use
285 std::unique_lock<std::mutex> lock(counter_lock);
286 uses[object].writer_count -= 1;
287 if ((uses[object].reader_count == 0) && (uses[object].writer_count == 0)) {
288 uses.erase(object);
289 }
290 // Notify any waiting threads that this object may be safe to use
291 lock.unlock();
292 counter_condition.notify_all();
293 }
294
295 void StartRead(T object) {
296 if (object == VK_NULL_HANDLE) {
297 return;
298 }
299 bool skip = false;
300 loader_platform_thread_id tid = loader_platform_get_thread_id();
301 std::unique_lock<std::mutex> lock(counter_lock);
302 if (uses.find(object) == uses.end()) {
303 // There is no current use of the object. Record reader count
304 struct object_use_data *use_data = &uses[object];
305 use_data->reader_count = 1;
306 use_data->writer_count = 0;
307 use_data->thread = tid;
308 } else if (uses[object].writer_count > 0 && uses[object].thread != tid) {
309 // There is a writer of the object.
310 skip |= false;
311 log_msg(*report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, objectType, (uint64_t)(object), kVUID_Threading_MultipleThreads,
312 "THREADING ERROR : object of type %s is simultaneously used in "
313 "thread 0x%" PRIx64 " and thread 0x%" PRIx64,
314 typeName, (uint64_t)uses[object].thread, (uint64_t)tid);
315 if (skip) {
316 // Wait for thread-safe access to object instead of skipping call.
317 while (uses.find(object) != uses.end()) {
318 counter_condition.wait(lock);
319 }
320 // There is no current use of the object. Record reader count
321 struct object_use_data *use_data = &uses[object];
322 use_data->reader_count = 1;
323 use_data->writer_count = 0;
324 use_data->thread = tid;
325 } else {
326 uses[object].reader_count += 1;
327 }
328 } else {
329 // There are other readers of the object. Increase reader count
330 uses[object].reader_count += 1;
331 }
332 }
333 void FinishRead(T object) {
334 if (object == VK_NULL_HANDLE) {
335 return;
336 }
337 std::unique_lock<std::mutex> lock(counter_lock);
338 uses[object].reader_count -= 1;
339 if ((uses[object].reader_count == 0) && (uses[object].writer_count == 0)) {
340 uses.erase(object);
341 }
342 // Notify any waiting threads that this object may be safe to use
343 lock.unlock();
344 counter_condition.notify_all();
345 }
346 counter(const char *name = "", VkDebugReportObjectTypeEXT type = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, debug_report_data **rep_data = nullptr) {
347 typeName = name;
348 objectType = type;
349 report_data = rep_data;
350 }
351};
352
353
354
355class ThreadSafety : public ValidationObject {
356public:
357
358 // Override chassis read/write locks for this validation object
Jeremy Hayesd4a3ec32019-01-29 14:42:08 -0700359 // This override takes a deferred lock. i.e. it is not acquired.
360 std::unique_lock<std::mutex> write_lock() {
361 return std::unique_lock<std::mutex>(validation_object_mutex, std::defer_lock);
362 }
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700363
364 std::mutex command_pool_lock;
365 std::unordered_map<VkCommandBuffer, VkCommandPool> command_pool_map;
366
367 counter<VkCommandBuffer> c_VkCommandBuffer;
368 counter<VkDevice> c_VkDevice;
369 counter<VkInstance> c_VkInstance;
370 counter<VkQueue> c_VkQueue;
371#ifdef DISTINCT_NONDISPATCHABLE_HANDLES
372
373 // Special entry to allow tracking of command pool Reset and Destroy
374 counter<VkCommandPool> c_VkCommandPoolContents;
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700375COUNTER_CLASS_DEFINITIONS_TEMPLATE
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700376
377#else // DISTINCT_NONDISPATCHABLE_HANDLES
378 // Special entry to allow tracking of command pool Reset and Destroy
379 counter<uint64_t> c_VkCommandPoolContents;
380
381 counter<uint64_t> c_uint64_t;
382#endif // DISTINCT_NONDISPATCHABLE_HANDLES
383
384 ThreadSafety()
385 : c_VkCommandBuffer("VkCommandBuffer", VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, &report_data),
386 c_VkDevice("VkDevice", VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, &report_data),
387 c_VkInstance("VkInstance", VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, &report_data),
388 c_VkQueue("VkQueue", VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, &report_data),
389 c_VkCommandPoolContents("VkCommandPool", VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, &report_data),
390
391#ifdef DISTINCT_NONDISPATCHABLE_HANDLES
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700392COUNTER_CLASS_INSTANCES_TEMPLATE
393
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700394
395#else // DISTINCT_NONDISPATCHABLE_HANDLES
396 c_uint64_t("NON_DISPATCHABLE_HANDLE", VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, &report_data)
397#endif // DISTINCT_NONDISPATCHABLE_HANDLES
398 {};
399
400#define WRAPPER(type) \
401 void StartWriteObject(type object) { \
402 c_##type.StartWrite(object); \
403 } \
404 void FinishWriteObject(type object) { \
405 c_##type.FinishWrite(object); \
406 } \
407 void StartReadObject(type object) { \
408 c_##type.StartRead(object); \
409 } \
410 void FinishReadObject(type object) { \
411 c_##type.FinishRead(object); \
412 }
413
414WRAPPER(VkDevice)
415WRAPPER(VkInstance)
416WRAPPER(VkQueue)
417#ifdef DISTINCT_NONDISPATCHABLE_HANDLES
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700418COUNTER_CLASS_BODIES_TEMPLATE
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700419
420#else // DISTINCT_NONDISPATCHABLE_HANDLES
421WRAPPER(uint64_t)
422#endif // DISTINCT_NONDISPATCHABLE_HANDLES
423
424 // VkCommandBuffer needs check for implicit use of command pool
425 void StartWriteObject(VkCommandBuffer object, bool lockPool = true) {
426 if (lockPool) {
427 std::unique_lock<std::mutex> lock(command_pool_lock);
428 VkCommandPool pool = command_pool_map[object];
429 lock.unlock();
430 StartWriteObject(pool);
431 }
432 c_VkCommandBuffer.StartWrite(object);
433 }
434 void FinishWriteObject(VkCommandBuffer object, bool lockPool = true) {
435 c_VkCommandBuffer.FinishWrite(object);
436 if (lockPool) {
437 std::unique_lock<std::mutex> lock(command_pool_lock);
438 VkCommandPool pool = command_pool_map[object];
439 lock.unlock();
440 FinishWriteObject(pool);
441 }
442 }
443 void StartReadObject(VkCommandBuffer object) {
444 std::unique_lock<std::mutex> lock(command_pool_lock);
445 VkCommandPool pool = command_pool_map[object];
446 lock.unlock();
447 // We set up a read guard against the "Contents" counter to catch conflict vs. vkResetCommandPool and vkDestroyCommandPool
448 // while *not* establishing a read guard against the command pool counter itself to avoid false postives for
449 // non-externally sync'd command buffers
450 c_VkCommandPoolContents.StartRead(pool);
451 c_VkCommandBuffer.StartRead(object);
452 }
453 void FinishReadObject(VkCommandBuffer object) {
454 c_VkCommandBuffer.FinishRead(object);
455 std::unique_lock<std::mutex> lock(command_pool_lock);
456 VkCommandPool pool = command_pool_map[object];
457 lock.unlock();
458 c_VkCommandPoolContents.FinishRead(pool);
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700459 } """
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700460
461
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700462 inline_custom_source_preamble = """
463void ThreadSafety::PreCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
464 VkCommandBuffer *pCommandBuffers) {
465 StartReadObject(device);
466 StartWriteObject(pAllocateInfo->commandPool);
467}
468
469void ThreadSafety::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700470 VkCommandBuffer *pCommandBuffers, VkResult result) {
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700471 FinishReadObject(device);
472 FinishWriteObject(pAllocateInfo->commandPool);
473
474 // Record mapping from command buffer to command pool
475 for (uint32_t index = 0; index < pAllocateInfo->commandBufferCount; index++) {
476 std::lock_guard<std::mutex> lock(command_pool_lock);
477 command_pool_map[pCommandBuffers[index]] = pAllocateInfo->commandPool;
478 }
479}
480
481void ThreadSafety::PreCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
482 VkDescriptorSet *pDescriptorSets) {
483 StartReadObject(device);
484 StartWriteObject(pAllocateInfo->descriptorPool);
485 // Host access to pAllocateInfo::descriptorPool must be externally synchronized
486}
487
488void ThreadSafety::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700489 VkDescriptorSet *pDescriptorSets, VkResult result) {
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700490 FinishReadObject(device);
491 FinishWriteObject(pAllocateInfo->descriptorPool);
492 // Host access to pAllocateInfo::descriptorPool must be externally synchronized
493}
494
495void ThreadSafety::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
496 const VkCommandBuffer *pCommandBuffers) {
497 const bool lockCommandPool = false; // pool is already directly locked
498 StartReadObject(device);
499 StartWriteObject(commandPool);
500 for (uint32_t index = 0; index < commandBufferCount; index++) {
501 StartWriteObject(pCommandBuffers[index], lockCommandPool);
502 }
503 // The driver may immediately reuse command buffers in another thread.
504 // These updates need to be done before calling down to the driver.
505 for (uint32_t index = 0; index < commandBufferCount; index++) {
506 FinishWriteObject(pCommandBuffers[index], lockCommandPool);
507 std::lock_guard<std::mutex> lock(command_pool_lock);
508 command_pool_map.erase(pCommandBuffers[index]);
509 }
510}
511
512void ThreadSafety::PostCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
513 const VkCommandBuffer *pCommandBuffers) {
514 FinishReadObject(device);
515 FinishWriteObject(commandPool);
516}
517
518void ThreadSafety::PreCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) {
519 StartReadObject(device);
520 StartWriteObject(commandPool);
521 // Check for any uses of non-externally sync'd command buffers (for example from vkCmdExecuteCommands)
522 c_VkCommandPoolContents.StartWrite(commandPool);
523 // Host access to commandPool must be externally synchronized
524}
525
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700526void ThreadSafety::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags, VkResult result) {
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700527 FinishReadObject(device);
528 FinishWriteObject(commandPool);
529 c_VkCommandPoolContents.FinishWrite(commandPool);
530 // Host access to commandPool must be externally synchronized
531}
532
533void ThreadSafety::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
534 StartReadObject(device);
535 StartWriteObject(commandPool);
536 // Check for any uses of non-externally sync'd command buffers (for example from vkCmdExecuteCommands)
537 c_VkCommandPoolContents.StartWrite(commandPool);
538 // Host access to commandPool must be externally synchronized
539}
540
541void ThreadSafety::PostCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
542 FinishReadObject(device);
543 FinishWriteObject(commandPool);
544 c_VkCommandPoolContents.FinishWrite(commandPool);
545}
546
Mark Lobodzinski8925c052018-12-18 12:41:15 -0700547// GetSwapchainImages can return a non-zero count with a NULL pSwapchainImages pointer. Let's avoid crashes by ignoring
548// pSwapchainImages.
549void ThreadSafety::PreCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
550 VkImage *pSwapchainImages) {
551 StartReadObject(device);
552 StartReadObject(swapchain);
553}
554
555void ThreadSafety::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700556 VkImage *pSwapchainImages, VkResult result) {
Mark Lobodzinski8925c052018-12-18 12:41:15 -0700557 FinishReadObject(device);
558 FinishReadObject(swapchain);
559}
560
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700561"""
562
563
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600564 # This is an ordered list of sections in the header file.
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700565 ALL_SECTIONS = ['command']
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600566 def __init__(self,
567 errFile = sys.stderr,
568 warnFile = sys.stderr,
569 diagFile = sys.stdout):
570 OutputGenerator.__init__(self, errFile, warnFile, diagFile)
571 # Internal state - accumulators for different inner block text
572 self.sections = dict([(section, []) for section in self.ALL_SECTIONS])
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700573 self.non_dispatchable_types = set()
574 self.object_to_debug_report_type = {
575 'VkInstance' : 'VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT',
576 'VkPhysicalDevice' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT',
577 'VkDevice' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT',
578 'VkQueue' : 'VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT',
579 'VkSemaphore' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT',
580 'VkCommandBuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT',
581 'VkFence' : 'VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT',
582 'VkDeviceMemory' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT',
583 'VkBuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT',
584 'VkImage' : 'VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT',
585 'VkEvent' : 'VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT',
586 'VkQueryPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT',
587 'VkBufferView' : 'VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT',
588 'VkImageView' : 'VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT',
589 'VkShaderModule' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT',
590 'VkPipelineCache' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT',
591 'VkPipelineLayout' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT',
592 'VkRenderPass' : 'VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT',
593 'VkPipeline' : 'VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT',
594 'VkDescriptorSetLayout' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT',
595 'VkSampler' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT',
596 'VkDescriptorPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT',
597 'VkDescriptorSet' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT',
598 'VkFramebuffer' : 'VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT',
599 'VkCommandPool' : 'VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT',
600 'VkSurfaceKHR' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT',
601 'VkSwapchainKHR' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT',
602 'VkDisplayKHR' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT',
603 'VkDisplayModeKHR' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT',
604 'VkObjectTableNVX' : 'VK_DEBUG_REPORT_OBJECT_TYPE_OBJECT_TABLE_NVX_EXT',
605 'VkIndirectCommandsLayoutNVX' : 'VK_DEBUG_REPORT_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX_EXT',
606 'VkSamplerYcbcrConversion' : 'VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION_EXT',
607 'VkDescriptorUpdateTemplate' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_EXT',
608 'VkAccelerationStructureNV' : 'VK_DEBUG_REPORT_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV_EXT',
609 'VkDebugReportCallbackEXT' : 'VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT',
610 'VkValidationCacheEXT' : 'VK_DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT' }
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600611
612 # Check if the parameter passed in is a pointer to an array
613 def paramIsArray(self, param):
614 return param.attrib.get('len') is not None
615
616 # Check if the parameter passed in is a pointer
617 def paramIsPointer(self, param):
618 ispointer = False
619 for elem in param:
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600620 if ((elem.tag is not 'type') and (elem.tail is not None)) and '*' in elem.tail:
621 ispointer = True
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600622 return ispointer
Mark Lobodzinski60b77b32017-02-14 09:16:56 -0700623
624 # Check if an object is a non-dispatchable handle
625 def isHandleTypeNonDispatchable(self, handletype):
626 handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']")
627 if handle is not None and handle.find('type').text == 'VK_DEFINE_NON_DISPATCHABLE_HANDLE':
628 return True
629 else:
630 return False
631
632 # Check if an object is a dispatchable handle
633 def isHandleTypeDispatchable(self, handletype):
634 handle = self.registry.tree.find("types/type/[name='" + handletype + "'][@category='handle']")
635 if handle is not None and handle.find('type').text == 'VK_DEFINE_HANDLE':
636 return True
637 else:
638 return False
639
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600640 def makeThreadUseBlock(self, cmd, functionprefix):
641 """Generate C function pointer typedef for <command> Element"""
642 paramdecl = ''
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600643 # Find and add any parameters that are thread unsafe
644 params = cmd.findall('param')
645 for param in params:
646 paramname = param.find('name')
647 if False: # self.paramIsPointer(param):
648 paramdecl += ' // not watching use of pointer ' + paramname.text + '\n'
649 else:
650 externsync = param.attrib.get('externsync')
651 if externsync == 'true':
652 if self.paramIsArray(param):
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700653 paramdecl += 'for (uint32_t index=0;index<' + param.attrib.get('len') + ';index++) {\n'
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700654 paramdecl += ' ' + functionprefix + 'WriteObject(' + paramname.text + '[index]);\n'
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700655 paramdecl += '}\n'
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600656 else:
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700657 paramdecl += functionprefix + 'WriteObject(' + paramname.text + ');\n'
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600658 elif (param.attrib.get('externsync')):
659 if self.paramIsArray(param):
660 # Externsync can list pointers to arrays of members to synchronize
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700661 paramdecl += 'for (uint32_t index=0;index<' + param.attrib.get('len') + ';index++) {\n'
662 second_indent = ''
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600663 for member in externsync.split(","):
664 # Replace first empty [] in member name with index
665 element = member.replace('[]','[index]',1)
666 if '[]' in element:
667 # Replace any second empty [] in element name with
668 # inner array index based on mapping array names like
669 # "pSomeThings[]" to "someThingCount" array size.
670 # This could be more robust by mapping a param member
671 # name to a struct type and "len" attribute.
672 limit = element[0:element.find('s[]')] + 'Count'
673 dotp = limit.rfind('.p')
674 limit = limit[0:dotp+1] + limit[dotp+2:dotp+3].lower() + limit[dotp+3:]
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700675 paramdecl += ' for(uint32_t index2=0;index2<'+limit+';index2++)\n'
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600676 element = element.replace('[]','[index2]')
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700677 second_indent = ' '
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700678 paramdecl += ' ' + second_indent + functionprefix + 'WriteObject(' + element + ');\n'
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700679 paramdecl += '}\n'
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600680 else:
681 # externsync can list members to synchronize
682 for member in externsync.split(","):
683 member = str(member).replace("::", "->")
Mark Lobodzinski9c147802017-02-10 08:34:54 -0700684 member = str(member).replace(".", "->")
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700685 paramdecl += ' ' + functionprefix + 'WriteObject(' + member + ');\n'
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600686 else:
687 paramtype = param.find('type')
688 if paramtype is not None:
689 paramtype = paramtype.text
690 else:
691 paramtype = 'None'
Mark Lobodzinski60b77b32017-02-14 09:16:56 -0700692 if (self.isHandleTypeDispatchable(paramtype) or self.isHandleTypeNonDispatchable(paramtype)) and paramtype != 'VkPhysicalDevice':
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600693 if self.paramIsArray(param) and ('pPipelines' != paramname.text):
Mark Lobodzinski9c147802017-02-10 08:34:54 -0700694 # Add pointer dereference for array counts that are pointer values
695 dereference = ''
696 for candidate in params:
697 if param.attrib.get('len') == candidate.find('name').text:
698 if self.paramIsPointer(candidate):
699 dereference = '*'
Mark Lobodzinski60b77b32017-02-14 09:16:56 -0700700 param_len = str(param.attrib.get('len')).replace("::", "->")
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700701 paramdecl += 'for (uint32_t index = 0; index < ' + dereference + param_len + '; index++) {\n'
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700702 paramdecl += ' ' + functionprefix + 'ReadObject(' + paramname.text + '[index]);\n'
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700703 paramdecl += '}\n'
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600704 elif not self.paramIsPointer(param):
705 # Pointer params are often being created.
706 # They are not being read from.
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700707 paramdecl += functionprefix + 'ReadObject(' + paramname.text + ');\n'
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600708 explicitexternsyncparams = cmd.findall("param[@externsync]")
709 if (explicitexternsyncparams is not None):
710 for param in explicitexternsyncparams:
711 externsyncattrib = param.attrib.get('externsync')
712 paramname = param.find('name')
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700713 paramdecl += '// Host access to '
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600714 if externsyncattrib == 'true':
715 if self.paramIsArray(param):
716 paramdecl += 'each member of ' + paramname.text
717 elif self.paramIsPointer(param):
718 paramdecl += 'the object referenced by ' + paramname.text
719 else:
720 paramdecl += paramname.text
721 else:
722 paramdecl += externsyncattrib
723 paramdecl += ' must be externally synchronized\n'
724
725 # Find and add any "implicit" parameters that are thread unsafe
726 implicitexternsyncparams = cmd.find('implicitexternsyncparams')
727 if (implicitexternsyncparams is not None):
728 for elem in implicitexternsyncparams:
Mark Lobodzinski716a4f92018-11-16 08:54:20 -0700729 paramdecl += '// '
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600730 paramdecl += elem.text
731 paramdecl += ' must be externally synchronized between host accesses\n'
732
733 if (paramdecl == ''):
734 return None
735 else:
736 return paramdecl
737 def beginFile(self, genOpts):
738 OutputGenerator.beginFile(self, genOpts)
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600739 #
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700740 # TODO: LUGMAL -- remove this and add our copyright
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600741 # User-supplied prefix text, if any (list of strings)
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700742 write(self.inline_copyright_message, file=self.outFile)
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700743
744 self.header_file = (genOpts.filename == 'thread_safety.h')
745 self.source_file = (genOpts.filename == 'thread_safety.cpp')
746
747 if not self.header_file and not self.source_file:
748 print("Error: Output Filenames have changed, update generator source.\n")
749 sys.exit(1)
750
751 if self.source_file:
752 write('#include "chassis.h"', file=self.outFile)
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700753 write('#include "thread_safety.h"', file=self.outFile)
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600754 self.newline()
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700755 write(self.inline_custom_source_preamble, file=self.outFile)
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700756
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700757
758 def endFile(self):
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700759
760 # Create class definitions
761 counter_class_defs = ''
762 counter_class_instances = ''
763 counter_class_bodies = ''
764
765 for obj in self.non_dispatchable_types:
766 counter_class_defs += ' counter<%s> c_%s;\n' % (obj, obj)
767 if obj in self.object_to_debug_report_type:
768 obj_type = self.object_to_debug_report_type[obj]
769 else:
770 obj_type = 'VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT'
771 counter_class_instances += ' c_%s("%s", %s, &report_data),\n' % (obj, obj, obj_type)
772 counter_class_bodies += 'WRAPPER(%s)\n' % obj
773 if self.header_file:
774 class_def = self.inline_custom_header_preamble.replace('COUNTER_CLASS_DEFINITIONS_TEMPLATE', counter_class_defs)
775 class_def = class_def.replace('COUNTER_CLASS_INSTANCES_TEMPLATE', counter_class_instances[:-2]) # Kill last comma
776 class_def = class_def.replace('COUNTER_CLASS_BODIES_TEMPLATE', counter_class_bodies)
777 write(class_def, file=self.outFile)
778 write('\n'.join(self.sections['command']), file=self.outFile)
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700779 if self.header_file:
780 write('};', file=self.outFile)
781
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600782 # Finish processing in superclass
783 OutputGenerator.endFile(self)
Mark Lobodzinski706e52b2018-12-11 13:21:52 -0700784
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600785 def beginFeature(self, interface, emit):
786 #write('// starting beginFeature', file=self.outFile)
787 # Start processing in superclass
788 OutputGenerator.beginFeature(self, interface, emit)
789 # C-specific
790 # Accumulate includes, defines, types, enums, function pointer typedefs,
791 # end function prototypes separately for this feature. They're only
792 # printed in endFeature().
Mark Lobodzinski62f71562017-10-24 13:41:18 -0600793 self.featureExtraProtect = GetFeatureProtect(interface)
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700794 if (self.featureExtraProtect is not None):
795 self.appendSection('command', '\n#ifdef %s' % self.featureExtraProtect)
796
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600797 #write('// ending beginFeature', file=self.outFile)
798 def endFeature(self):
799 # C-specific
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600800 if (self.emit):
MichaƂ Janiszewski3c3ce9e2018-10-30 23:25:21 +0100801 if (self.featureExtraProtect is not None):
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700802 self.appendSection('command', '#endif // %s' % self.featureExtraProtect)
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600803 # Finish processing in superclass
804 OutputGenerator.endFeature(self)
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600805 #
806 # Append a definition to the specified section
807 def appendSection(self, section, text):
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600808 self.sections[section].append(text)
809 #
810 # Type generation
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700811 def genType(self, typeinfo, name, alias):
Mark Lobodzinski796454c2018-12-11 16:10:55 -0700812 OutputGenerator.genType(self, typeinfo, name, alias)
813 type_elem = typeinfo.elem
814 category = type_elem.get('category')
815 if category == 'handle':
816 if self.isHandleTypeNonDispatchable(name):
817 self.non_dispatchable_types.add(name)
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600818 #
819 # Struct (e.g. C "struct" type) generation.
820 # This is a special case of the <type> tag where the contents are
821 # interpreted as a set of <member> tags instead of freeform C
822 # C type declarations. The <member> tags are just like <param>
823 # tags - they are a declaration of a struct or union member.
824 # Only simple member declarations are supported (no nested
825 # structs etc.)
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700826 def genStruct(self, typeinfo, typeName, alias):
827 OutputGenerator.genStruct(self, typeinfo, typeName, alias)
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600828 body = 'typedef ' + typeinfo.elem.get('category') + ' ' + typeName + ' {\n'
829 # paramdecl = self.makeCParamDecl(typeinfo.elem, self.genOpts.alignFuncParam)
830 for member in typeinfo.elem.findall('.//member'):
831 body += self.makeCParamDecl(member, self.genOpts.alignFuncParam)
832 body += ';\n'
833 body += '} ' + typeName + ';\n'
834 self.appendSection('struct', body)
835 #
836 # Group (e.g. C "enum" type) generation.
837 # These are concatenated together with other types.
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700838 def genGroup(self, groupinfo, groupName, alias):
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600839 pass
840 # Enumerant generation
841 # <enum> tags may specify their values in several ways, but are usually
842 # just integers.
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700843 def genEnum(self, enuminfo, name, alias):
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600844 pass
845 #
846 # Command generation
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700847 def genCmd(self, cmdinfo, name, alias):
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600848 # Commands shadowed by interface functions and are not implemented
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600849 special_functions = [
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600850 'vkCreateDevice',
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600851 'vkCreateInstance',
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600852 'vkAllocateCommandBuffers',
853 'vkFreeCommandBuffers',
John Zulaufe28aa342018-10-24 12:18:39 -0600854 'vkResetCommandPool',
855 'vkDestroyCommandPool',
Mark Lobodzinski3bd82ad2017-02-16 11:45:27 -0700856 'vkAllocateDescriptorSets',
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700857 'vkQueuePresentKHR',
Mark Lobodzinski8925c052018-12-18 12:41:15 -0700858 'vkGetSwapchainImagesKHR',
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600859 ]
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700860 if name == 'vkQueuePresentKHR' or (name in special_functions and self.source_file):
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600861 return
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700862
863 if (("DebugMarker" in name or "DebugUtilsObject" in name) and "EXT" in name):
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600864 self.appendSection('command', '// TODO - not wrapping EXT function ' + name)
865 return
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700866
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600867 # Determine first if this function needs to be intercepted
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700868 startthreadsafety = self.makeThreadUseBlock(cmdinfo.elem, 'Start')
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600869 if startthreadsafety is None:
870 return
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700871 finishthreadsafety = self.makeThreadUseBlock(cmdinfo.elem, 'Finish')
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600872
Mike Schuchardtf375c7c2017-12-28 11:23:48 -0700873 OutputGenerator.genCmd(self, cmdinfo, name, alias)
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700874
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600875 # setup common to call wrappers
876 # first parameter is always dispatchable
877 dispatchable_type = cmdinfo.elem.find('param/type').text
878 dispatchable_name = cmdinfo.elem.find('param/name').text
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700879
880 decls = self.makeCDecls(cmdinfo.elem)
881
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700882 result_type = cmdinfo.elem.find('proto/type')
883
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700884 if self.source_file:
885 pre_decl = decls[0][:-1]
886 pre_decl = pre_decl.split("VKAPI_CALL ")[1]
887 pre_decl = 'void ThreadSafety::PreCallRecord' + pre_decl + ' {'
888
889 # PreCallRecord
890 self.appendSection('command', '')
891 self.appendSection('command', pre_decl)
892 self.appendSection('command', " " + "\n ".join(str(startthreadsafety).rstrip().split("\n")))
893 self.appendSection('command', '}')
894
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700895 # PostCallRecord
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700896 post_decl = pre_decl.replace('PreCallRecord', 'PostCallRecord')
897 if result_type.text == 'VkResult':
898 post_decl = post_decl.replace(')', ',\n VkResult result)')
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700899 self.appendSection('command', '')
900 self.appendSection('command', post_decl)
901 self.appendSection('command', " " + "\n ".join(str(finishthreadsafety).rstrip().split("\n")))
902 self.appendSection('command', '}')
903
904 if self.header_file:
905 pre_decl = decls[0][:-1]
906 pre_decl = pre_decl.split("VKAPI_CALL ")[1]
907 pre_decl = 'void PreCallRecord' + pre_decl + ';'
908
909 # PreCallRecord
910 self.appendSection('command', '')
911 self.appendSection('command', pre_decl)
912
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700913 # PostCallRecord
Mark Lobodzinskicd05c1e2019-01-17 15:33:46 -0700914 post_decl = pre_decl.replace('PreCallRecord', 'PostCallRecord')
915 if result_type.text == 'VkResult':
916 post_decl = post_decl.replace(')', ',\n VkResult result)')
Mark Lobodzinski1f2ba262018-12-04 14:15:47 -0700917 self.appendSection('command', '')
918 self.appendSection('command', post_decl)
919
Mark Lobodzinskiff910992016-10-11 14:29:52 -0600920 #
921 # override makeProtoName to drop the "vk" prefix
922 def makeProtoName(self, name, tail):
923 return self.genOpts.apientry + name[2:] + tail