KhronosGroup / Vulkan-Docs

The Vulkan API Specification and related tools
Other
2.77k stars 465 forks source link

Merge equivalent require blocks #2406

Closed Waffl3x closed 1 month ago

Waffl3x commented 1 month ago

Addresses #2404 Merges extension require blocks that have identical children, extending the depends attribute with a logical or.

CLAassistant commented 1 month ago

CLA assistant check
All committers have signed the CLA.

Waffl3x commented 1 month ago

Here is a script I made in python that finds these cases, I'm not really sure how to handle license stuff, and I'm not sure where it should go so I didn't add it with this pull request. I'm also not very familiar with python so it has some flaws, namely that it just looks for a vk.xml in the same directory as the script, so I don't feel like it's good enough to be included as-is.

import xml.etree.ElementTree as etree
import itertools

tree = etree.parse('vk.xml')
doc = tree.getroot()

extensions = doc.find('extensions')

def check_if_children_equal(req1, req2):
    if len(req1) != len(req2):
        return False
    for child1, child2 in zip(req1, req2):
        if child1.tag != child2.tag:
            return False
        if child1.attrib != child2.attrib:
            return False
    return True
# def check_if_children_equal

for ext in extensions:
    req_with_depends = []
    # put all candidates into a list
    for req, count in zip(ext, itertools.count()):
        if 'depends' in req.attrib:
            req_with_depends.append((req, count))

    # compare candidates in a pairwise manner
    for tup1, it2_start in zip(req_with_depends[:-1], range(1, len(req_with_depends))):
        for tup2 in req_with_depends[it2_start:]:
            req1, req_count1 = tup1
            req2, req_count2 = tup2
            all_match = check_if_children_equal(req1, req2)
            if all_match:
                print('Found matching require block in extension {}:'.format(ext.attrib['name']))
                print('blocks {} and {} are equal'.format(req_count1, req_count2))
                print('require block {} attributes: {}'.format(req_count1, req1.attrib))
                print('require block {} attributes: {}'.format(req_count2, req2.attrib))
                print('  block children:')
                for child1, child2 in zip(req1, req2):
                    print('    ', req_count1, ': ', child1.attrib)
                    print('    ', req_count2, ': ', child2.attrib)
oddhack commented 1 month ago

Thanks! If you are comfortable putting this at the start:

#!/usr/bin/env python3
#
# Copyright 2024 <your actual name, or other organization holding copyright>
# SPDX-License-Identifier: Apache-2.0

in the header, that will place it under Apache 2.0 on the same terms as other scripts in the repo and allow us to redistribute it while still giving you credit. It should go in the "scripts/" directory.

Waffl3x commented 1 month ago

Should be good now I think