@@ -929,13 +929,14 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
929929 out .append (f' std::vector<{ member .type } > { struct .name } _{ member .name } ;\n ' )
930930 out .append (self .AddGuardFooter (struct ))
931931 out .append (' void initialize_chain(' )
932+ args = []
932933 if chain_details .get ('type' ) in [EXTENSION_TYPE_INSTANCE , EXTENSION_TYPE_BOTH ]:
933- out .append ('AppInstance &inst, ' )
934+ args .append ('AppInstance &inst' )
934935 if chain_details .get ('type' ) in [EXTENSION_TYPE_DEVICE , EXTENSION_TYPE_BOTH ]:
935- out .append ('AppGpu &gpu ' )
936+ args .append ('AppGpu &gpu' )
936937 if chain_details .get ('can_show_promoted_structs' ):
937- out .append (', bool show_promoted_structs' )
938- out .append (') noexcept {\n ' )
938+ args .append ('bool show_promoted_structs' )
939+ out .append (f' { ", " . join ( args ) } ) noexcept { {\n ' )
939940 for s in structs_to_print :
940941 if s in STRUCT_BLACKLIST :
941942 continue
@@ -945,7 +946,6 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
945946 out .append (f' { struct .name [2 :]} .sType = { struct .sType } ;\n ' )
946947 out .append (self .AddGuardFooter (struct ))
947948
948-
949949 out .append (' std::vector<VkBaseOutStructure*> chain_members{};\n ' )
950950 for s in structs_to_print :
951951 if s in STRUCT_BLACKLIST :
@@ -1014,14 +1014,16 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
10141014''' )
10151015 if chain_details .get ('print_iterator' ):
10161016 out .append ('\n ' )
1017- out .append (f'void chain_iterator_{ listName } (Printer &p, ' )
1017+ out .append (f'void chain_iterator_{ listName } (' )
1018+ args = ['Printer &p' ]
10181019 if chain_details .get ('type' ) in [EXTENSION_TYPE_INSTANCE , EXTENSION_TYPE_BOTH ]:
1019- out .append ('AppInstance &inst, ' )
1020+ args .append ('AppInstance &inst' )
10201021 if chain_details .get ('type' ) in [EXTENSION_TYPE_DEVICE , EXTENSION_TYPE_BOTH ]:
1021- out .append ('AppGpu &gpu, ' )
1022+ args .append ('AppGpu &gpu' )
10221023 if chain_details .get ('can_show_promoted_structs' ):
1023- out .append ('bool show_promoted_structs, ' )
1024- out .append ('const void * place) {\n ' )
1024+ args .append ('bool show_promoted_structs' )
1025+ args .append ('const void * place' )
1026+ out .append (f'{ ", " .join (args )} ) {{\n ' )
10251027 out .append (' while (place) {\n ' )
10261028 out .append (' const VkBaseOutStructure *structure = (const VkBaseOutStructure *)place;\n ' )
10271029 out .append (' p.SetSubHeader();\n ' )
@@ -1035,16 +1037,9 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
10351037 out .append (f' if (structure->sType == { struct .sType } ' )
10361038 if struct .name in PORTABILITY_STRUCTS :
10371039 out .append (' && p.Type() != OutputType::json' )
1038- has_version = struct .version is not None
1039- has_extNameStr = len (struct .extensions ) > 0 or len (struct .aliases ) > 0
10401040 out .append (') {\n ' )
10411041 out .append (f' const { struct .name } * props = (const { struct .name } *)structure;\n ' )
1042- out .append (f' Dump{ struct .name } (p, ' )
1043- if len (struct .aliases ) > 0 and struct .version is not None :
1044- out .append (f'{ version_desc } >= { struct .version .nameApi } ?"{ struct .name } ":"{ struct .aliases [0 ]} "' )
1045- else :
1046- out .append (f'"{ struct .name } "' )
1047- out .append (', *props);\n ' )
1042+ out .extend (self .PrintStructNameDecisionLogic (struct , version_desc , chain_details .get ('can_show_promoted_structs' )))
10481043 out .append (' p.AddNewline();\n ' )
10491044 out .append (' }\n ' )
10501045 out .append (self .AddGuardFooter (struct ))
@@ -1078,6 +1073,56 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
10781073
10791074 return out
10801075
1076+ def GetStructCheckStringForMatchingExtension (self , struct , structName ):
1077+ for ext_name in struct .extensions :
1078+ ext = self .vk .extensions [ext_name ]
1079+ vendor = ext .name .split ('_' )[1 ]
1080+ if structName .endswith (vendor ):
1081+ if ext .device :
1082+ return f'gpu.CheckPhysicalDeviceExtensionIncluded({ ext .nameString } )'
1083+ elif ext .instance :
1084+ return f'inst.CheckExtensionEnabled({ ext .nameString } )'
1085+ return None
1086+
1087+ # Function is complex because it has to do the following:
1088+ # Always print the struct with the most appropriate name given the gpu api version & enabled instance/device extensions
1089+ # Print struct aliases when --show-promoted-structs is set
1090+ # Not let alias printing duplicate the most appropriate name
1091+ def PrintStructNameDecisionLogic (self , struct , version_desc , can_show_promoted_structs ):
1092+ out = []
1093+ out .append (f'{ " " * 12 } const char* name = ' )
1094+ # Get a list of all the conditions to check and the type name to use
1095+ check_list = []
1096+ if struct .version is not None :
1097+ check_list .append ([f'{ version_desc } >= { struct .version .nameApi } ' , struct .name ])
1098+ else :
1099+ check_list .append ([f'{ self .GetStructCheckStringForMatchingExtension (struct , struct .name )} ' , struct .name ])
1100+
1101+ for alias in struct .aliases :
1102+ ext_str = self .GetStructCheckStringForMatchingExtension (struct , alias )
1103+ if ext_str is not None :
1104+ check_list .append ([f'{ self .GetStructCheckStringForMatchingExtension (struct , alias )} ' , alias ])
1105+ end_parens = ''
1106+ # Turn the conditions into a nested ternary condition -
1107+ for check in check_list :
1108+ if check == check_list [- 1 ]:
1109+ out .append ( f'"{ check [1 ]} "' )
1110+ else :
1111+ out .append ( f'{ check [0 ]} ? "{ check [1 ]} " : (' )
1112+ end_parens += ')'
1113+ out .append (f'{ end_parens } ;\n ' )
1114+ out .append (f'{ " " * 12 } Dump{ struct .name } (p, name, *props);\n ' )
1115+ if not can_show_promoted_structs :
1116+ return out
1117+ for alias in struct .aliases :
1118+ ext_str = self .GetStructCheckStringForMatchingExtension (struct , alias )
1119+ if ext_str is not None :
1120+ out .append (f'{ " " * 12 } if (show_promoted_structs && strcmp(name, "{ alias } ") != 0 && { ext_str } ) {{\n ' )
1121+ out .append (f'{ " " * 16 } p.AddNewline();\n ' )
1122+ out .append (f'{ " " * 16 } p.SetSubHeader();\n ' )
1123+ out .append (f'{ " " * 16 } Dump{ struct .name } (p, "{ alias } ", *props);\n ' )
1124+ out .append (f'{ " " * 12 } }}\n ' )
1125+ return out
10811126
10821127 def PrintStructComparisonForwardDecl (self ,structure ):
10831128 out = []
0 commit comments