zink/codegen: remember the fields in feats/props structs of extensions

this will be useful in the next commit, where we reapply fields from one struct
to another.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16265>
This commit is contained in:
Hoe Hao Cheng 2022-05-01 17:22:36 +08:00 committed by Marge Bot
parent b51e40ebde
commit 0d344e96c0
1 changed files with 64 additions and 6 deletions

View File

@ -67,9 +67,12 @@ class Extension:
core_since = None
# these are specific to zink_device_info.py:
has_properties = False
has_features = False
guard = False
has_properties = False
has_features = False
guard = False
features_promoted = False
properties_promoted = False
# these are specific to zink_instance.py:
platform_guard = None
@ -153,7 +156,11 @@ class ExtensionRegistryEntry:
instance_commands = None
constants = None
features_struct = None
features_fields = None
features_promoted = False
properties_struct = None
properties_fields = None
properties_promoted = False
# some instance extensions are locked behind certain platforms
platform_guard = ""
@ -165,8 +172,9 @@ class ExtensionRegistry:
vkxml = ElementTree.parse(vkxml_path)
commands_type = dict()
aliases = dict()
command_aliases = dict()
platform_guards = dict()
struct_aliases = dict()
for cmd in vkxml.findall("commands/command"):
name = cmd.find("./proto/name")
@ -174,9 +182,19 @@ class ExtensionRegistry:
if name is not None and name.text:
commands_type[name.text] = cmd.find("./param/type").text
elif cmd.get("name") is not None:
aliases[cmd.get("name")] = cmd.get("alias")
command_aliases[cmd.get("name")] = cmd.get("alias")
for (cmd, alias) in aliases.items():
for typ in vkxml.findall("types/type"):
if typ.get("category") != "struct":
continue
name = typ.get("name")
alias = typ.get("alias")
if name and alias:
struct_aliases[name] = alias
for (cmd, alias) in command_aliases.items():
commands_type[cmd] = commands_type[alias]
for platform in vkxml.findall("platforms/platform"):
@ -198,6 +216,8 @@ class ExtensionRegistry:
entry.device_commands = []
entry.pdevice_commands = []
entry.instance_commands = []
entry.features_fields = []
entry.properties_fields = []
for cmd in ext.findall("require/command"):
cmd_name = cmd.get("name")
@ -223,10 +243,48 @@ class ExtensionRegistry:
if (self.is_features_struct(ty_name) and
entry.features_struct is None):
entry.features_struct = ty_name
elif (self.is_properties_struct(ty_name) and
entry.properties_struct is None):
entry.properties_struct = ty_name
if entry.features_struct:
struct_name = entry.features_struct
if entry.features_struct in struct_aliases:
struct_name = struct_aliases[entry.features_struct]
entry.features_promoted = True
elif entry.promoted_in is not None:
# if the extension is promoted but a core-Vulkan alias is not
# available for the features, then consider the features struct
# non-core-promoted
entry.features_promoted = False
for field in vkxml.findall("./types/type[@name='{}']/member".format(struct_name)):
field_name = field.find("name").text
# we ignore sType and pNext since they are irrelevant
if field_name not in ["sType", "pNext"]:
entry.features_fields.append(field_name)
if entry.properties_struct:
struct_name = entry.properties_struct
if entry.properties_struct in struct_aliases:
struct_name = struct_aliases[entry.properties_struct]
entry.properties_promoted = True
elif entry.promoted_in is not None:
# if the extension is promoted but a core-Vulkan alias is not
# available for the properties, then it is not promoted to core
entry.properties_promoted = False
for field in vkxml.findall("./types/type[@name='{}']/member".format(struct_name)):
field_name = field.find("name").text
# we ignore sType and pNext since they are irrelevant
if field_name not in ["sType", "pNext"]:
entry.properties_fields.append(field_name)
if ext.get("platform") is not None:
entry.platform_guard = platform_guards[ext.get("platform")]