[Mesa-dev] [PATCH 06/20] anv: Teach generator scripts how to parse mutliple XML files

Tapani Pälli tapani.palli at intel.com
Thu Sep 14 07:48:26 UTC 2017



On 09/14/2017 02:03 AM, Chad Versace wrote:
> From: Chad Versace <chadversary at chromium.org>
> 
> The taught scripts are anv_extensions.py and anv_entrypoints_gen.py.  To
> give a script multiple XML files, call it like so:
> 
>      anv_extensions.py --xml a.xml --xml b.xml --xml c.xml ...
> 
> The scripts parse the XML files in the given order.
> 
> This will allow us to feed the scripts XML files for extensions that are
> missing from the official vk.xml, such as VK_ANDROID_native_buffer.
> ---
>   src/intel/vulkan/anv_entrypoints_gen.py | 18 +++++++++++++-----
>   src/intel/vulkan/anv_extensions.py      | 15 ++++++++++-----
>   2 files changed, 23 insertions(+), 10 deletions(-)
> 
> diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
> index 3240704a0d8..983be09a39b 100644
> --- a/src/intel/vulkan/anv_entrypoints_gen.py
> +++ b/src/intel/vulkan/anv_entrypoints_gen.py
> @@ -253,7 +253,7 @@ def cal_hash(name):
>           lambda h, c: (h * PRIME_FACTOR + ord(c)) & U32_MASK, name, 0)
>   
>   
> -def get_entrypoints(doc, entrypoints_to_defines):
> +def get_entrypoints(doc, entrypoints_to_defines, start_index):
>       """Extract the entry points from the registry."""
>       entrypoints = []
>   
> @@ -275,7 +275,7 @@ def get_entrypoints(doc, entrypoints_to_defines):
>           for command in extension.findall('./require/command'):
>               enabled_commands.add(command.attrib['name'])
>   
> -    index = 0
> +    index = start_index
>       for command in doc.findall('./commands/command'):
>           type = command.find('./proto/type').text
>           fullname = command.find('./proto/name').text
> @@ -344,11 +344,19 @@ def main():
>       parser = argparse.ArgumentParser()
>       parser.add_argument('--outdir', help='Where to write the files.',
>                           required=True)
> -    parser.add_argument('--xml', help='Vulkan API XML file.', required=True)
> +    parser.add_argument('--xml',
> +                        help='Vulkan API XML file.',
> +                        required=True,
> +                        action='append',
> +                        dest='xml_files')
>       args = parser.parse_args()
>   
> -    doc = et.parse(args.xml)
> -    entrypoints = get_entrypoints(doc, get_entrypoints_defines(doc))
> +    entrypoints = []
> +
> +    for filename in args.xml_files:
> +        doc = et.parse(filename)
> +        entrypoints += get_entrypoints(doc, get_entrypoints_defines(doc),
> +                                       start_index=len(entrypoints))
>   
>       # Manually add CreateDmaBufImageINTEL for which we don't have an extension
>       # defined.
> diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py
> index acec785959b..d995f9f177c 100644
> --- a/src/intel/vulkan/anv_extensions.py
> +++ b/src/intel/vulkan/anv_extensions.py
> @@ -138,9 +138,6 @@ def _init_exts_from_xml(xml):
>   
>           ext.type = ext_elem.attrib['type']
>   
> -    for ext in EXTENSIONS:
> -        assert ext.type == 'instance' or ext.type == 'device'
> -
>   _TEMPLATE = Template(COPYRIGHT + """
>   #include "anv_private.h"
>   
> @@ -232,10 +229,18 @@ VkResult anv_EnumerateDeviceExtensionProperties(
>   if __name__ == '__main__':
>       parser = argparse.ArgumentParser()
>       parser.add_argument('--out', help='Output C file.', required=True)
> -    parser.add_argument('--xml', help='Vulkan API XML file.', required=True)
> +    parser.add_argument('--xml',
> +                        help='Vulkan API XML file.',
> +                        required=True,
> +                        action='append',
> +                        dest='xml_files')
>       args = parser.parse_args()
>   
> -    _init_exts_from_xml(args.xml)
> +    for filename in args.xml_files:
> +        _init_exts_from_xml(filename)
> +
> +    for ext in EXTENSIONS:
> +        assert ext.type == 'instance' or ext.type == 'device'

This assert will hold only and if only all the extensions not having 
'instance' or 'device' have implementation provided by other xml as with 
VK_ANDROID_native_buffer. So if you call only with vk.xml this will go 
boom. Not sure if that's a problem though, it would be only problem if 
someone comes along with yet another extension without type set.


>       template_env = {
>           'MAX_API_VERSION': MAX_API_VERSION,
> 


// Tapani


More information about the mesa-dev mailing list