From cde128728af6983a49692051b1cf73ce8723dd9b Mon Sep 17 00:00:00 2001 From: Mike Schuchardt Date: Tue, 28 Sep 2021 09:45:09 -0700 Subject: scripts: Fix codegen with hard-coded enum indices Currently some of the generators use a fixed child index to locate extension enums, which will break if comment blocks are added near the top of an extension definition. This change makes the enum lookup more robust by searching for the expected enum name instead of using a hard-coded offset. --- scripts/mock_icd_generator.py | 25 +++++++++++++++---------- scripts/vulkan_tools_helper_file_generator.py | 18 +++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/mock_icd_generator.py b/scripts/mock_icd_generator.py index 64ea7dc6..d8b0739c 100644 --- a/scripts/mock_icd_generator.py +++ b/scripts/mock_icd_generator.py @@ -1,9 +1,9 @@ #!/usr/bin/python3 -i # -# Copyright (c) 2015-2017 The Khronos Group Inc. -# Copyright (c) 2015-2017 Valve Corporation -# Copyright (c) 2015-2017 LunarG, Inc. -# Copyright (c) 2015-2017 Google Inc. +# Copyright (c) 2015-2021 The Khronos Group Inc. +# Copyright (c) 2015-2021 Valve Corporation +# Copyright (c) 2015-2021 LunarG, Inc. +# Copyright (c) 2015-2021 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -1202,12 +1202,17 @@ class MockICDOutputGenerator(OutputGenerator): ignore_exts = ['VK_EXT_validation_cache', 'VK_KHR_portability_subset'] for ext in self.registry.tree.findall("extensions/extension"): if ext.attrib['supported'] != 'disabled': # Only include enabled extensions - if (ext.attrib['name'] in ignore_exts): - pass - elif (ext.attrib.get('type') and 'instance' == ext.attrib['type']): - instance_exts.append(' {"%s", %s},' % (ext.attrib['name'], ext[0][0].attrib['value'])) - else: - device_exts.append(' {"%s", %s},' % (ext.attrib['name'], ext[0][0].attrib['value'])) + if (ext.attrib['name'] not in ignore_exts): + # Search for extension version enum + for enum in ext.findall('require/enum'): + if enum.get('name', '').endswith('_SPEC_VERSION'): + ext_version = enum.get('value') + if (ext.attrib.get('type') == 'instance'): + instance_exts.append(' {"%s", %s},' % (ext.attrib['name'], ext_version)) + else: + device_exts.append(' {"%s", %s},' % (ext.attrib['name'], ext_version)) + break + write('// Map of instance extension name to version', file=self.outFile) write('static const std::unordered_map instance_extension_map = {', file=self.outFile) write('\n'.join(instance_exts), file=self.outFile) diff --git a/scripts/vulkan_tools_helper_file_generator.py b/scripts/vulkan_tools_helper_file_generator.py index 1b24a5e4..42ce0199 100644 --- a/scripts/vulkan_tools_helper_file_generator.py +++ b/scripts/vulkan_tools_helper_file_generator.py @@ -1,9 +1,9 @@ #!/usr/bin/python3 -i # -# Copyright (c) 2015-2017 The Khronos Group Inc. -# Copyright (c) 2015-2017 Valve Corporation -# Copyright (c) 2015-2017 LunarG, Inc. -# Copyright (c) 2015-2017 Google Inc. +# Copyright (c) 2015-2021 The Khronos Group Inc. +# Copyright (c) 2015-2021 Valve Corporation +# Copyright (c) 2015-2021 LunarG, Inc. +# Copyright (c) 2015-2021 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -176,10 +176,10 @@ class HelperFileOutputGenerator(OutputGenerator): if interface.tag != 'extension': return name = self.featureName - nameElem = interface[0][1] - name_define = nameElem.get('name') - if 'EXTENSION_NAME' not in name_define: - print("Error in vk.xml file -- extension name is not available") + for enum in interface.findall('require/enum'): + if enum.get('name', '').endswith('EXTENSION_NAME'): + name_define = enum.get('name') + break requires = interface.get('requires') if requires is not None: required_extensions = requires.split(',') @@ -241,7 +241,7 @@ class HelperFileOutputGenerator(OutputGenerator): def paramIsPointer(self, param): ispointer = False for elem in param: - if ((elem.tag is not 'type') and (elem.tail is not None)) and '*' in elem.tail: + if ((elem.tag != 'type') and (elem.tail is not None)) and '*' in elem.tail: ispointer = True return ispointer # -- cgit v1.2.3