vulkan/cmd_queue: update generator to handle guarded types.

The latest includes/registry have some pNext structs that need
guarding spearately to their initial structs, so we have to track
the define guards better and use them in the generated code

For example:
VkVideoEncodeRateControlInfoKHR extends VkVideoCodingControlInfoKHR

However the first struct is protected by BETA, but the second isn't
the generator was always generating unguarded code for all structs

Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20384>
This commit is contained in:
Dave Airlie
2022-12-20 06:00:56 +10:00
parent c1968deec2
commit bfe1942e8a
+32 -5
View File
@@ -448,11 +448,18 @@ def get_pnext_member_copy(struct, src_type, member, types, level):
pnext_decl = "const VkBaseInStructure *pnext = %s;" % field_name
case_stmts = ""
for type in types[src_type].extended_by:
guard_pre_stmt = ""
guard_post_stmt = ""
if type.guard is not None:
guard_pre_stmt = "#ifdef %s" % type.guard
guard_post_stmt = "#endif"
case_stmts += """
%s
case %s:
%s
break;
""" % (type.enum, get_struct_copy(field_name, "pnext", type.name, "sizeof(%s)" % type.name, types, level))
%s
""" % (guard_pre_stmt, type.enum, get_struct_copy(field_name, "pnext", type.name, "sizeof(%s)" % type.name, types, level), guard_post_stmt)
return """
%s
if (pnext) {
@@ -498,9 +505,29 @@ def get_struct_free(command, param, types):
member_frees += "vk_free(queue->alloc, (%s)%s);\n" % (const_cast, member_name)
return "%s %s\n" % (member_frees, struct_free)
EntrypointType = namedtuple('EntrypointType', 'name enum members extended_by')
EntrypointType = namedtuple('EntrypointType', 'name enum members extended_by guard')
def get_types(doc):
def get_types_defines(doc):
"""Maps types to extension defines."""
types_to_defines = {}
platform_define = {}
for platform in doc.findall('./platforms/platform'):
name = platform.attrib['name']
define = platform.attrib['protect']
platform_define[name] = define
for extension in doc.findall('./extensions/extension[@platform]'):
platform = extension.attrib['platform']
define = platform_define[platform]
for types in extension.findall('./require/type'):
fullname = types.attrib['name']
types_to_defines[fullname] = define
return types_to_defines
def get_types(doc, types_to_defines):
"""Extract the types from the registry."""
types = {}
@@ -525,7 +552,7 @@ def get_types(doc):
if mem_name == 'sType':
type_enum = p.attrib.get('values')
types[_type.attrib['name']] = EntrypointType(name=_type.attrib['name'], enum=type_enum, members=members, extended_by=[])
types[_type.attrib['name']] = EntrypointType(name=_type.attrib['name'], enum=type_enum, members=members, extended_by=[], guard=types_to_defines.get(_type.attrib['name']))
for _type in doc.findall('./types/type'):
if _type.attrib.get('category') != 'struct':
@@ -542,7 +569,7 @@ def get_types_from_xml(xml_files):
for filename in xml_files:
doc = et.parse(filename)
types.update(get_types(doc))
types.update(get_types(doc, get_types_defines(doc)))
return types