diff options
| author | Mark Lobodzinski <mark@lunarg.com> | 2017-04-13 08:36:18 -0600 |
|---|---|---|
| committer | Mark Lobodzinski <mark@lunarg.com> | 2017-04-13 09:46:17 -0600 |
| commit | 32cd102c36c6fca2679904aa9e59fdffc64ded59 (patch) | |
| tree | 6bb3f6eb169d7758ebee1ba601f1d58183dd443f | |
| parent | 0b0be96ac2cf958866c0a26daf11b7ff86c6936b (diff) | |
| download | usermoji-32cd102c36c6fca2679904aa9e59fdffc64ded59.tar.xz | |
scripts: Convert ugly case statment to nice array
Since this was codegen'd, we can just create a static array for the
object type conversion and do away with all of the switch statement
mess.
Change-Id: I5fb20778d64f0675afa9c1563e2d44d22d5b4a02
| -rw-r--r-- | layers/object_tracker.cpp | 10 | ||||
| -rw-r--r-- | scripts/helper_file_generator.py | 19 |
2 files changed, 11 insertions, 18 deletions
diff --git a/layers/object_tracker.cpp b/layers/object_tracker.cpp index 9c9f74a4..967b87af 100644 --- a/layers/object_tracker.cpp +++ b/layers/object_tracker.cpp @@ -261,7 +261,7 @@ static void CreateObject(T1 dispatchable_object, T2 object, VulkanObjectType obj bool custom_allocator = pAllocator != nullptr; if (!instance_data->object_map[object_type].count(object_handle)) { - VkDebugReportObjectTypeEXT debug_object_type = GetDebugReportEnum(object_type); + VkDebugReportObjectTypeEXT debug_object_type = GetDebugReportEnum[object_type]; log_msg(instance_data->report_data, VK_DEBUG_REPORT_INFORMATION_BIT_EXT, debug_object_type, object_handle, __LINE__, OBJTRACK_NONE, LayerName, "OBJ[0x%" PRIxLEAST64 "] : CREATE %s object 0x%" PRIxLEAST64, object_track_index++, object_string[object_type], object_handle); @@ -285,7 +285,7 @@ static void DestroyObject(T1 dispatchable_object, T2 object, VulkanObjectType ob auto object_handle = handle_value(object); bool custom_allocator = pAllocator != nullptr; - VkDebugReportObjectTypeEXT debug_object_type = GetDebugReportEnum(object_type); + VkDebugReportObjectTypeEXT debug_object_type = GetDebugReportEnum[object_type]; if (object_handle != VK_NULL_HANDLE) { auto item = device_data->object_map[object_type].find(object_handle); @@ -337,7 +337,7 @@ static bool ValidateObject(T1 dispatchable_object, T2 object, VulkanObjectType o return false; } auto object_handle = handle_value(object); - VkDebugReportObjectTypeEXT debug_object_type = GetDebugReportEnum(object_type); + VkDebugReportObjectTypeEXT debug_object_type = GetDebugReportEnum[object_type]; layer_data *device_data = GetLayerDataPtr(get_dispatch_key(dispatchable_object), layer_data_map); // Look for object in device object map @@ -379,7 +379,7 @@ static void DeviceReportUndestroyedObjects(VkDevice device, VulkanObjectType obj layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map); for (auto item = device_data->object_map[object_type].begin(); item != device_data->object_map[object_type].end();) { OBJTRACK_NODE *object_info = item->second; - log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, GetDebugReportEnum(object_type), object_info->handle, + log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, GetDebugReportEnum[object_type], object_info->handle, __LINE__, error_code, LayerName, "OBJ ERROR : For device 0x%" PRIxLEAST64 ", %s object 0x%" PRIxLEAST64 " has not been destroyed. %s", reinterpret_cast<uint64_t>(device), object_string[object_type], object_info->handle, @@ -414,7 +414,7 @@ VKAPI_ATTR void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocati OBJTRACK_NODE *pNode = iit->second; VkDevice device = reinterpret_cast<VkDevice>(pNode->handle); - VkDebugReportObjectTypeEXT debug_object_type = GetDebugReportEnum(pNode->object_type); + VkDebugReportObjectTypeEXT debug_object_type = GetDebugReportEnum[pNode->object_type]; log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, debug_object_type, pNode->handle, __LINE__, OBJTRACK_OBJECT_LEAK, LayerName, "OBJ ERROR : %s object 0x%" PRIxLEAST64 " has not been destroyed.", diff --git a/scripts/helper_file_generator.py b/scripts/helper_file_generator.py index 2dcb7d9f..f4f555c0 100644 --- a/scripts/helper_file_generator.py +++ b/scripts/helper_file_generator.py @@ -560,32 +560,25 @@ class HelperFileOutputGenerator(OutputGenerator): # Output a conversion routine from the layer object definitions to the debug report definitions object_types_header += '\n' - object_types_header += '// Helper function to get Official Vulkan object type enum from the internal layers version\n' - object_types_header += 'VkDebugReportObjectTypeEXT GetDebugReportEnum(VulkanObjectType object_type) {\n\n' - object_types_header += ' switch (object_type) {\n' - object_types_header += ' case kVulkanObjectTypeUnknown:\n' - object_types_header += ' return VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;\n\n' + object_types_header += '// Helper array to get Official Vulkan object type enum from the internal layers version\n' + object_types_header += 'const VkDebugReportObjectTypeEXT GetDebugReportEnum[] = {\n' for object_type in type_list: done = False - object_types_header += ' case %s:\n' % object_type search_type = object_type.replace("kVulkanObjectType", "").lower() for vk_object_type in self.debug_report_object_types: target_type = vk_object_type.replace("VK_DEBUG_REPORT_OBJECT_TYPE_", "").lower() target_type = target_type[:-4] target_type = target_type.replace("_", "") if search_type == target_type: - object_types_header += ' return %s;\n\n' % vk_object_type + object_types_header += ' %s, // %s\n' % (vk_object_type, object_type) done = True break if done == False: if object_type == 'kVulkanObjectTypeDebugReportCallbackEXT': - object_types_header += ' return VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT;\n\n' + object_types_header += ' VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT, // kVulkanObjectTypeDebugReportCallbackEXT\n' else: - object_types_header += ' return VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;\n\n' - object_types_header += ' default:\n' - object_types_header += ' return VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;\n\n' - object_types_header += ' }\n' - object_types_header += '}\n' + object_types_header += ' VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT; // No Match\n' + object_types_header += '};\n' return object_types_header # # Determine if a structure needs a safe_struct helper function |
