@@ -924,13 +924,14 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
924924 out .append (f' std::vector<{ member .type } > { struct .name } _{ member .name } ;\n ' )
925925 out .append (self .AddGuardFooter (struct ))
926926 out .append (' void initialize_chain(' )
927+ args = []
927928 if chain_details .get ('type' ) in [EXTENSION_TYPE_INSTANCE , EXTENSION_TYPE_BOTH ]:
928- out .append ('AppInstance &inst, ' )
929+ args .append ('AppInstance &inst' )
929930 if chain_details .get ('type' ) in [EXTENSION_TYPE_DEVICE , EXTENSION_TYPE_BOTH ]:
930- out .append ('AppGpu &gpu ' )
931+ args .append ('AppGpu &gpu' )
931932 if chain_details .get ('can_show_promoted_structs' ):
932- out .append (', bool show_promoted_structs' )
933- out .append (') noexcept {\n ' )
933+ args .append ('bool show_promoted_structs' )
934+ out .append (f' { ", " . join ( args ) } ) noexcept { {\n ' )
934935 for s in structs_to_print :
935936 if s in STRUCT_BLACKLIST :
936937 continue
@@ -940,7 +941,6 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
940941 out .append (f' { struct .name [2 :]} .sType = { struct .sType } ;\n ' )
941942 out .append (self .AddGuardFooter (struct ))
942943
943-
944944 out .append (' std::vector<VkBaseOutStructure*> chain_members{};\n ' )
945945 for s in structs_to_print :
946946 if s in STRUCT_BLACKLIST :
@@ -1009,14 +1009,16 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
10091009''' )
10101010 if chain_details .get ('print_iterator' ):
10111011 out .append ('\n ' )
1012- out .append (f'void chain_iterator_{ listName } (Printer &p, ' )
1012+ out .append (f'void chain_iterator_{ listName } (' )
1013+ args = ['Printer &p' ]
10131014 if chain_details .get ('type' ) in [EXTENSION_TYPE_INSTANCE , EXTENSION_TYPE_BOTH ]:
1014- out .append ('AppInstance &inst, ' )
1015+ args .append ('AppInstance &inst' )
10151016 if chain_details .get ('type' ) in [EXTENSION_TYPE_DEVICE , EXTENSION_TYPE_BOTH ]:
1016- out .append ('AppGpu &gpu, ' )
1017+ args .append ('AppGpu &gpu' )
10171018 if chain_details .get ('can_show_promoted_structs' ):
1018- out .append ('bool show_promoted_structs, ' )
1019- out .append ('const void * place) {\n ' )
1019+ args .append ('bool show_promoted_structs' )
1020+ args .append ('const void * place' )
1021+ out .append (f'{ ", " .join (args )} ) {{\n ' )
10201022 out .append (' while (place) {\n ' )
10211023 out .append (' const VkBaseOutStructure *structure = (const VkBaseOutStructure *)place;\n ' )
10221024 out .append (' p.SetSubHeader();\n ' )
@@ -1030,16 +1032,9 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
10301032 out .append (f' if (structure->sType == { struct .sType } ' )
10311033 if struct .name in PORTABILITY_STRUCTS :
10321034 out .append (' && p.Type() != OutputType::json' )
1033- has_version = struct .version is not None
1034- has_extNameStr = len (struct .extensions ) > 0 or len (struct .aliases ) > 0
10351035 out .append (') {\n ' )
10361036 out .append (f' const { struct .name } * props = (const { struct .name } *)structure;\n ' )
1037- out .append (f' Dump{ struct .name } (p, ' )
1038- if len (struct .aliases ) > 0 and struct .version is not None :
1039- out .append (f'{ version_desc } >= { struct .version .nameApi } ?"{ struct .name } ":"{ struct .aliases [0 ]} "' )
1040- else :
1041- out .append (f'"{ struct .name } "' )
1042- out .append (', *props);\n ' )
1037+ out .extend (self .PrintStructNameDecisionLogic (struct , version_desc , chain_details .get ('can_show_promoted_structs' )))
10431038 out .append (' p.AddNewline();\n ' )
10441039 out .append (' }\n ' )
10451040 out .append (self .AddGuardFooter (struct ))
@@ -1073,6 +1068,56 @@ def PrintChainStruct(self, listName, structs_to_print, chain_details):
10731068
10741069 return out
10751070
1071+ def GetStructCheckStringForMatchingExtension (self , struct , structName ):
1072+ for ext_name in struct .extensions :
1073+ ext = self .vk .extensions [ext_name ]
1074+ vendor = ext .name .split ('_' )[1 ]
1075+ if structName .endswith (vendor ):
1076+ if ext .device :
1077+ return f'gpu.CheckPhysicalDeviceExtensionIncluded({ ext .nameString } )'
1078+ elif ext .instance :
1079+ return f'inst.CheckExtensionEnabled({ ext .nameString } )'
1080+ return None
1081+
1082+ # Function is complex because it has to do the following:
1083+ # Always print the struct with the most appropriate name given the gpu api version & enabled instance/device extensions
1084+ # Print struct aliases when --show-promoted-structs is set
1085+ # Not let alias printing duplicate the most appropriate name
1086+ def PrintStructNameDecisionLogic (self , struct , version_desc , can_show_promoted_structs ):
1087+ out = []
1088+ out .append (f'{ " " * 12 } const char* name = ' )
1089+ # Get a list of all the conditions to check and the type name to use
1090+ check_list = []
1091+ if struct .version is not None :
1092+ check_list .append ([f'{ version_desc } >= { struct .version .nameApi } ' , struct .name ])
1093+ else :
1094+ check_list .append ([f'{ self .GetStructCheckStringForMatchingExtension (struct , struct .name )} ' , struct .name ])
1095+
1096+ for alias in struct .aliases :
1097+ ext_str = self .GetStructCheckStringForMatchingExtension (struct , alias )
1098+ if ext_str is not None :
1099+ check_list .append ([f'{ self .GetStructCheckStringForMatchingExtension (struct , alias )} ' , alias ])
1100+ end_parens = ''
1101+ # Turn the conditions into a nested ternary condition -
1102+ for check in check_list :
1103+ if check == check_list [- 1 ]:
1104+ out .append ( f'"{ check [1 ]} "' )
1105+ else :
1106+ out .append ( f'{ check [0 ]} ? "{ check [1 ]} " : (' )
1107+ end_parens += ')'
1108+ out .append (f'{ end_parens } ;\n ' )
1109+ out .append (f'{ " " * 12 } Dump{ struct .name } (p, name, *props);\n ' )
1110+ if not can_show_promoted_structs :
1111+ return out
1112+ for alias in struct .aliases :
1113+ ext_str = self .GetStructCheckStringForMatchingExtension (struct , alias )
1114+ if ext_str is not None :
1115+ out .append (f'{ " " * 12 } if (show_promoted_structs && strcmp(name, "{ alias } ") != 0 && { ext_str } ) {{\n ' )
1116+ out .append (f'{ " " * 16 } p.AddNewline();\n ' )
1117+ out .append (f'{ " " * 16 } p.SetSubHeader();\n ' )
1118+ out .append (f'{ " " * 16 } Dump{ struct .name } (p, "{ alias } ", *props);\n ' )
1119+ out .append (f'{ " " * 12 } }}\n ' )
1120+ return out
10761121
10771122 def PrintStructComparisonForwardDecl (self ,structure ):
10781123 out = []
0 commit comments