layers: Pass VkResults to PostCallRecord functions
In several cases, PostCallRecordApi functions need to do different
things depending upon the return code. The most flexible way to handle
this is to allow each validation object's PCR routines to decide this
for themselves.
All PostCallRecord functions returning a VkResult will now have a
VkResult as an additional, final parameter.
Change-Id: Ibd9d7c25f8c290dd228409e793f065bf0cd253fb
diff --git a/scripts/layer_chassis_generator.py b/scripts/layer_chassis_generator.py
index b204c0a..4bc84c9 100644
--- a/scripts/layer_chassis_generator.py
+++ b/scripts/layer_chassis_generator.py
@@ -568,7 +568,7 @@
#endif
for (auto intercept : framework->object_dispatch) {
- intercept->PostCallRecordCreateInstance(pCreateInfo, pAllocator, pInstance);
+ intercept->PostCallRecordCreateInstance(pCreateInfo, pAllocator, pInstance, result);
}
InstanceExtensionWhitelist(framework, pCreateInfo, *pInstance);
@@ -712,7 +712,7 @@
for (auto intercept : instance_interceptor->object_dispatch) {
intercept->write_lock();
- intercept->PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
+ intercept->PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, result);
intercept->write_unlock();
}
@@ -769,7 +769,7 @@
result = layer_create_report_callback(layer_data->report_data, false, pCreateInfo, pAllocator, pCallback);
""" + postcallrecord_loop + """
intercept->write_lock();
- intercept->PostCallRecordCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback);
+ intercept->PostCallRecordCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pCallback, result);
intercept->write_unlock();
}
return result;
@@ -1005,6 +1005,9 @@
pre_call_validate = pre_call_validate.replace("{}", " { return false; }")
pre_call_record = 'virtual void PreCallRecord' + prototype
post_call_record = 'virtual void PostCallRecord' + prototype
+ resulttype = elem.find('proto/type')
+ if resulttype.text == 'VkResult':
+ post_call_record = post_call_record.replace(')', ', VkResult result)')
return ' %s\n %s\n %s\n' % (pre_call_validate, pre_call_record, post_call_record)
#
# Command generation
@@ -1110,24 +1113,14 @@
self.appendSection('command', ' }')
# Generate post-call object processing source code
- return_type_indent = ''
-
self.appendSection('command', ' %s' % self.postcallrecord_loop)
+ returnparam = ''
if (resulttype.text == 'VkResult'):
- return_type_indent = ' '
- if name in self.alt_ret_codes:
- self.appendSection('command', '%s if (((VK_SUCCESS == result) || (VK_INCOMPLETE == result)) || (intercept->container_type == LayerObjectTypeThreading)) {' % return_type_indent)
- else:
- self.appendSection('command', '%s if ((VK_SUCCESS == result) || (intercept->container_type == LayerObjectTypeThreading)) {' % return_type_indent)
-
- #self.appendSection('command', '%s %s' % (return_type_indent, self.postcallrecord_loop))
- self.appendSection('command', '%s intercept->write_lock();' % return_type_indent)
- self.appendSection('command', '%s intercept->PostCallRecord%s(%s);' % (return_type_indent,api_function_name[2:], paramstext))
- self.appendSection('command', '%s intercept->write_unlock();' % return_type_indent)
- self.appendSection('command', '%s }' % return_type_indent)
- if (resulttype.text == 'VkResult'):
- self.appendSection('command', ' }')
-
+ returnparam = ', result'
+ self.appendSection('command', ' intercept->write_lock();')
+ self.appendSection('command', ' intercept->PostCallRecord%s(%s%s);' % (api_function_name[2:], paramstext, returnparam))
+ self.appendSection('command', ' intercept->write_unlock();')
+ self.appendSection('command', ' }')
# Return result variable, if any.
if (resulttype.text != 'void'):
self.appendSection('command', ' return result;')
diff --git a/scripts/object_tracker_generator.py b/scripts/object_tracker_generator.py
index 974f9a7..6f8757a 100644
--- a/scripts/object_tracker_generator.py
+++ b/scripts/object_tracker_generator.py
@@ -1,9 +1,9 @@
#!/usr/bin/python3 -i
#
-# Copyright (c) 2015-2018 The Khronos Group Inc.
-# Copyright (c) 2015-2018 Valve Corporation
-# Copyright (c) 2015-2018 LunarG, Inc.
-# Copyright (c) 2015-2018 Google Inc.
+# Copyright (c) 2015-2019 The Khronos Group Inc.
+# Copyright (c) 2015-2019 Valve Corporation
+# Copyright (c) 2015-2019 LunarG, Inc.
+# Copyright (c) 2015-2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -372,10 +372,10 @@
copyright += '\n'
copyright += '/***************************************************************************\n'
copyright += ' *\n'
- copyright += ' * Copyright (c) 2015-2018 The Khronos Group Inc.\n'
- copyright += ' * Copyright (c) 2015-2018 Valve Corporation\n'
- copyright += ' * Copyright (c) 2015-2018 LunarG, Inc.\n'
- copyright += ' * Copyright (c) 2015-2018 Google Inc.\n'
+ copyright += ' * Copyright (c) 2015-2019 The Khronos Group Inc.\n'
+ copyright += ' * Copyright (c) 2015-2019 Valve Corporation\n'
+ copyright += ' * Copyright (c) 2015-2019 LunarG, Inc.\n'
+ copyright += ' * Copyright (c) 2015-2019 Google Inc.\n'
copyright += ' *\n'
copyright += ' * Licensed under the Apache License, Version 2.0 (the "License");\n'
copyright += ' * you may not use this file except in compliance with the License.\n'
@@ -438,10 +438,10 @@
self.otwrite('hdr', 'void PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets);')
self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties);')
self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR *pQueueFamilyProperties);')
- self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPropertiesKHR *pProperties);')
- self.otwrite('hdr', 'void PostCallRecordGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties);')
- self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayProperties2KHR *pProperties);')
- self.otwrite('hdr', 'void PostCallRecordGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t *pPropertyCount, VkDisplayModeProperties2KHR *pProperties);')
+ self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayPropertiesKHR *pProperties, VkResult result);')
+ self.otwrite('hdr', 'void PostCallRecordGetDisplayModePropertiesKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t *pPropertyCount, VkDisplayModePropertiesKHR *pProperties, VkResult result);')
+ self.otwrite('hdr', 'void PostCallRecordGetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount, VkDisplayProperties2KHR *pProperties, VkResult result);')
+ self.otwrite('hdr', 'void PostCallRecordGetDisplayModeProperties2KHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t *pPropertyCount, VkDisplayModeProperties2KHR *pProperties, VkResult result);')
OutputGenerator.endFile(self)
#
# Processing point at beginning of each extension definition
@@ -929,6 +929,8 @@
func_decl_template = decls[0][:-1].split('VKAPI_CALL ')
func_decl_template = func_decl_template[1]
+ result_type = cmdinfo.elem.find('proto/type')
+
if 'object_tracker.h' in self.genOpts.filename:
# Output PreCallValidateAPI prototype if necessary
if pre_call_validate:
@@ -943,6 +945,8 @@
# Output PosCallRecordAPI prototype if necessary
if post_call_record:
post_cr_func_decl = 'void PostCallRecord' + func_decl_template + ';'
+ if result_type.text == 'VkResult':
+ post_cr_func_decl = post_cr_func_decl.replace(')', ',\n VkResult result)')
self.appendSection('command', post_cr_func_decl)
if 'object_tracker.cpp' in self.genOpts.filename:
@@ -968,7 +972,13 @@
if post_call_record and not manual:
post_cr_func_decl = 'void ObjectLifetimes::PostCallRecord' + func_decl_template + ' {'
self.appendSection('command', '')
+
+ if result_type.text == 'VkResult':
+ post_cr_func_decl = post_cr_func_decl.replace(')', ',\n VkResult result)')
+ post_cr_func_decl = post_cr_func_decl.replace('{', '{\n if (result != VK_SUCCESS) return;')
self.appendSection('command', post_cr_func_decl)
+
+
self.appendSection('command', post_call_record)
self.appendSection('command', '}')
diff --git a/scripts/thread_safety_generator.py b/scripts/thread_safety_generator.py
index 9d682d9..cfc8ddc 100644
--- a/scripts/thread_safety_generator.py
+++ b/scripts/thread_safety_generator.py
@@ -1,9 +1,9 @@
#!/usr/bin/python3 -i
#
-# Copyright (c) 2015-2016 The Khronos Group Inc.
-# Copyright (c) 2015-2016 Valve Corporation
-# Copyright (c) 2015-2016 LunarG, Inc.
-# Copyright (c) 2015-2016 Google Inc.
+# Copyright (c) 2015-2019 The Khronos Group Inc.
+# Copyright (c) 2015-2019 Valve Corporation
+# Copyright (c) 2015-2019 LunarG, Inc.
+# Copyright (c) 2015-2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -120,10 +120,10 @@
// This file is ***GENERATED***. Do Not Edit.
// See layer_chassis_dispatch_generator.py for modifications.
-/* Copyright (c) 2015-2018 The Khronos Group Inc.
- * Copyright (c) 2015-2018 Valve Corporation
- * Copyright (c) 2015-2018 LunarG, Inc.
- * Copyright (c) 2015-2018 Google Inc.
+/* Copyright (c) 2015-2019 The Khronos Group Inc.
+ * Copyright (c) 2015-2019 Valve Corporation
+ * Copyright (c) 2015-2019 LunarG, Inc.
+ * Copyright (c) 2015-2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -465,7 +465,7 @@
}
void ThreadSafety::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo,
- VkCommandBuffer *pCommandBuffers) {
+ VkCommandBuffer *pCommandBuffers, VkResult result) {
FinishReadObject(device);
FinishWriteObject(pAllocateInfo->commandPool);
@@ -484,7 +484,7 @@
}
void ThreadSafety::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
- VkDescriptorSet *pDescriptorSets) {
+ VkDescriptorSet *pDescriptorSets, VkResult result) {
FinishReadObject(device);
FinishWriteObject(pAllocateInfo->descriptorPool);
// Host access to pAllocateInfo::descriptorPool must be externally synchronized
@@ -521,7 +521,7 @@
// Host access to commandPool must be externally synchronized
}
-void ThreadSafety::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) {
+void ThreadSafety::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags, VkResult result) {
FinishReadObject(device);
FinishWriteObject(commandPool);
c_VkCommandPoolContents.FinishWrite(commandPool);
@@ -551,7 +551,7 @@
}
void ThreadSafety::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain, uint32_t *pSwapchainImageCount,
- VkImage *pSwapchainImages) {
+ VkImage *pSwapchainImages, VkResult result) {
FinishReadObject(device);
FinishReadObject(swapchain);
}
@@ -877,6 +877,8 @@
decls = self.makeCDecls(cmdinfo.elem)
+ result_type = cmdinfo.elem.find('proto/type')
+
if self.source_file:
pre_decl = decls[0][:-1]
pre_decl = pre_decl.split("VKAPI_CALL ")[1]
@@ -888,9 +890,10 @@
self.appendSection('command', " " + "\n ".join(str(startthreadsafety).rstrip().split("\n")))
self.appendSection('command', '}')
- post_decl = pre_decl.replace('PreCallRecord', 'PostCallRecord')
-
# PostCallRecord
+ post_decl = pre_decl.replace('PreCallRecord', 'PostCallRecord')
+ if result_type.text == 'VkResult':
+ post_decl = post_decl.replace(')', ',\n VkResult result)')
self.appendSection('command', '')
self.appendSection('command', post_decl)
self.appendSection('command', " " + "\n ".join(str(finishthreadsafety).rstrip().split("\n")))
@@ -905,9 +908,10 @@
self.appendSection('command', '')
self.appendSection('command', pre_decl)
- post_decl = pre_decl.replace('PreCallRecord', 'PostCallRecord')
-
# PostCallRecord
+ post_decl = pre_decl.replace('PreCallRecord', 'PostCallRecord')
+ if result_type.text == 'VkResult':
+ post_decl = post_decl.replace(')', ',\n VkResult result)')
self.appendSection('command', '')
self.appendSection('command', post_decl)