zink/codegen: support platform tags

Some extensions are locked behind certain platforms, don't include them
if the extension is unsupported.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14434>
This commit is contained in:
Hoe Hao Cheng 2022-01-07 12:36:41 +08:00 committed by Marge Bot
parent 1d40d53e03
commit 029e871239
2 changed files with 29 additions and 0 deletions

View file

@ -71,6 +71,9 @@ class Extension:
has_features = False
guard = False
# these are specific to zink_instance.py:
platform_guard = None
def __init__(self, name, alias="", required=False, nonstandard=False,
properties=False, features=False, conditions=None, guard=False,
core_since=None):
@ -153,6 +156,8 @@ class ExtensionRegistryEntry:
constants = None
features_struct = None
properties_struct = None
# some instance extensions are locked behind certain platforms
platform_guard = ""
class ExtensionRegistry:
# key = extension name, value = registry entry
@ -163,6 +168,7 @@ class ExtensionRegistry:
commands_type = dict()
aliases = dict()
platform_guards = dict()
for cmd in vkxml.findall("commands/command"):
name = cmd.find("./proto/name")
@ -175,6 +181,11 @@ class ExtensionRegistry:
for (cmd, alias) in aliases.items():
commands_type[cmd] = commands_type[alias]
for platform in vkxml.findall("platforms/platform"):
name = platform.get("name")
guard = platform.get("protect")
platform_guards[name] = guard
for ext in vkxml.findall("extensions/extension"):
# Reserved extensions are marked with `supported="disabled"`
if ext.get("supported") == "disabled":
@ -218,6 +229,9 @@ class ExtensionRegistry:
entry.properties_struct is None):
entry.properties_struct = ty_name
if ext.get("platform") is not None:
entry.platform_guard = platform_guards[ext.get("platform")]
self.registry[name] = entry
def in_registry(self, ext_name: str):

View file

@ -236,6 +236,9 @@ zink_verify_instance_extensions(struct zink_screen *screen)
{
%for ext in extensions:
%if registry.in_registry(ext.name):
%if ext.platform_guard:
#ifdef ${ext.platform_guard}
%endif
if (screen->instance_info.have_${ext.name_with_vendor()}) {
%for cmd in registry.get_registry_entry(ext.name).instance_commands:
if (!screen->vk.${cmd.lstrip("vk")}) {
@ -257,6 +260,9 @@ zink_verify_instance_extensions(struct zink_screen *screen)
%endfor
}
%endif
%if ext.platform_guard:
#endif
%endif
%endfor
}
@ -273,12 +279,18 @@ zink_verify_instance_extensions(struct zink_screen *screen)
%else:
<% generated_funcs.add(cmd) %>
%endif
%if ext.platform_guard:
#ifdef ${ext.platform_guard}
%endif
void
zink_stub_${cmd.lstrip("vk")}()
{
mesa_loge("ZINK: ${cmd} is not loaded properly!");
abort();
}
%if ext.platform_guard:
#endif
%endif
%endfor
%endif
%endfor
@ -335,6 +347,9 @@ if __name__ == "__main__":
if entry.promoted_in:
ext.core_since = Version((*entry.promoted_in, 0))
if entry.platform_guard:
ext.platform_guard = entry.platform_guard
if error_count > 0:
print("zink_instance.py: Found {} error(s) in total. Quitting.".format(error_count))
exit(1)