vulkan/properties: support Android in the property generator

get_property_structs() now checks if a property struct is
in ANDROID_PROPERTIES and marks it as such.

The header file now includes vk_android_native_buffer.h and the
Android properties in vk_properties..
For the C file, also generate case statements for respective Android
property structs.
All of the Android-specific code is #ifdeffed behind ANDROID.

That being said, we only support PresentationPropertiesANDROID for now.

Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Tested-by: Roman Stratiienko <r.stratiienko@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26386>
This commit is contained in:
Oskar Viljasaar 2023-11-27 00:15:13 +02:00 committed by Marge Bot
parent 610a7c84c3
commit 1afbf0ba4a

View file

@ -62,14 +62,21 @@ SPECIALIZED_PROPERTY_STRUCTS = [
"HostImageCopyPropertiesEXT", "HostImageCopyPropertiesEXT",
] ]
# Properties not extending VkPhysicalDeviceProperties2 in the XML,
# but which might still be present (in Android for instance)
ANDROID_PROPERTIES = [
"VkPhysicalDevicePresentationPropertiesANDROID",
]
@dataclass @dataclass
class Property: class Property:
decl: str decl: str
name: str name: str
actual_name: str actual_name: str
length: str length: str
is_android: bool
def __init__(self, p, property_struct_name): def __init__(self, p, property_struct_name, is_android=False):
self.decl = "" self.decl = ""
for element in p: for element in p:
if element.tag != "comment": if element.tag != "comment":
@ -85,11 +92,14 @@ class Property:
self.decl = self.decl.replace(self.name, self.actual_name) self.decl = self.decl.replace(self.name, self.actual_name)
self.is_android = is_android
@dataclass @dataclass
class PropertyStruct: class PropertyStruct:
c_type: str c_type: str
s_type: str s_type: str
name: str name: str
is_android: bool
properties: typing.List[Property] properties: typing.List[Property]
def copy_property(dst, src, decl, length="1"): def copy_property(dst, src, decl, length="1"):
@ -105,13 +115,23 @@ TEMPLATE_H = Template(COPYRIGHT + """
#ifndef VK_PROPERTIES_H #ifndef VK_PROPERTIES_H
#define VK_PROPERTIES_H #define VK_PROPERTIES_H
#if DETECT_OS_ANDROID
#include "vulkan/vk_android_native_buffer.h"
#endif /* DETECT_OS_ANDROID */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
struct vk_properties { struct vk_properties {
% for prop in all_properties: % for prop in all_properties:
% if prop.is_android:
#if DETECT_OS_ANDROID
% endif
${prop.decl}; ${prop.decl};
% if prop.is_android:
#endif /* DETECT_OS_ANDROID */
% endif
% endfor % endfor
}; };
@ -144,6 +164,9 @@ vk_common_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
vk_foreach_struct(ext, pProperties->pNext) { vk_foreach_struct(ext, pProperties->pNext) {
switch (ext->sType) { switch (ext->sType) {
% for property_struct in property_structs: % for property_struct in property_structs:
% if property_struct.is_android:
#ifdef ANDROID
% endif
% if property_struct.name not in SPECIALIZED_PROPERTY_STRUCTS: % if property_struct.name not in SPECIALIZED_PROPERTY_STRUCTS:
case ${property_struct.s_type}: { case ${property_struct.s_type}: {
${property_struct.c_type} *properties = (void *)ext; ${property_struct.c_type} *properties = (void *)ext;
@ -152,6 +175,9 @@ vk_common_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
% endfor % endfor
break; break;
} }
% if property_struct.is_android:
#endif /* ANDROID */
% endif
% endif % endif
% endfor % endfor
@ -214,16 +240,23 @@ def get_property_structs(doc, api, beta):
# parse all struct types where structextends VkPhysicalDeviceProperties2 # parse all struct types where structextends VkPhysicalDeviceProperties2
for _type in doc.findall("./types/type[@category=\"struct\"]"): for _type in doc.findall("./types/type[@category=\"struct\"]"):
full_name = _type.attrib.get("name")
if _type.attrib.get("structextends") != "VkPhysicalDeviceProperties2": if _type.attrib.get("structextends") != "VkPhysicalDeviceProperties2":
if full_name not in ANDROID_PROPERTIES:
continue continue
full_name = _type.attrib["name"]
if full_name not in required: if full_name not in required:
continue continue
# Skip extensions with a define for now
guard = required[full_name].guard guard = required[full_name].guard
if guard is not None and (guard != "VK_ENABLE_BETA_EXTENSIONS" or beta != "true"): is_android = full_name in ANDROID_PROPERTIES
if (guard is not None
# Skip beta extensions if not enabled
and (guard != "VK_ENABLE_BETA_EXTENSIONS" or beta != "true")
# Include android properties if included in ANDROID_PROPERTIES
and not is_android):
continue continue
# find Vulkan structure type # find Vulkan structure type
@ -246,9 +279,10 @@ def get_property_structs(doc, api, beta):
elif m_name == "sType": elif m_name == "sType":
s_type = p.attrib.get("values") s_type = p.attrib.get("values")
else: else:
properties.append(Property(p, name)) properties.append(Property(p, name, is_android))
property_struct = PropertyStruct(c_type=full_name, s_type=s_type, name=name, properties=properties) property_struct = PropertyStruct(c_type=full_name, s_type=s_type,
name=name, properties=properties, is_android=is_android)
property_structs[property_struct.c_type] = property_struct property_structs[property_struct.c_type] = property_struct
return property_structs.values() return property_structs.values()