diff --git a/scripts/loader_extension_generator.py b/scripts/loader_extension_generator.py index 6dbdf1fda..a0b9f69b5 100644 --- a/scripts/loader_extension_generator.py +++ b/scripts/loader_extension_generator.py @@ -22,10 +22,10 @@ # Author: Mark Young # Author: Mark Lobodzinski -import os,re,sys -import xml.etree.ElementTree as etree -from generator import * +import re +import sys from collections import namedtuple +from generator import * from common_codegen import * @@ -192,7 +192,7 @@ def beginFile(self, genOpts): OutputGenerator.beginFile(self, genOpts) # User-supplied prefix text, if any (list of strings) - if (genOpts.prefixText): + if genOpts.prefixText: for s in genOpts.prefixText: write(s, file=self.outFile) @@ -294,7 +294,7 @@ def endFile(self): file_data += '// clang-format on' - write(file_data, file=self.outFile); + write(file_data, file=self.outFile) # Finish processing in superclass OutputGenerator.endFile(self) @@ -348,16 +348,16 @@ def endFeature(self): # Retrieve the value of the len tag def getLen(self, param): result = None - len = param.attrib.get('len') - if len and len != 'null-terminated': + length = param.attrib.get('len') + if length and length != 'null-terminated': # For string arrays, 'len' can look like 'count,null-terminated', # indicating that we have a null terminated array of strings. We # strip the null-terminated from the 'len' field and only return # the parameter specifying the string count - if 'null-terminated' in len: - result = len.split(',')[0] + if 'null-terminated' in length: + result = length.split(',')[0] else: - result = len + result = length result = str(result).replace('::', '->') return result @@ -388,11 +388,11 @@ def AddCommandToDispatchList(self, extension_name, extension_type, name, cmdinfo return_type = cmdinfo.elem.find('proto/type') if (return_type is not None and return_type.text == 'void'): - return_type = None + return_type = None require = None if name == 'vkGetDeviceGroupSurfacePresentModes2EXT': - require_node = self.registry.tree.find("./extensions/extension[@name='{}']/require/command[@name='{}']/..".format(extension_name, name)) + require_node = self.registry.tree.find(f"./extensions/extension[@name='{extension_name}']/require/command[@name='{name}']/..") if 'depends' in require_node.attrib: require = require_node.attrib['depends'] @@ -403,10 +403,10 @@ def AddCommandToDispatchList(self, extension_name, extension_type, name, cmdinfo params = cmdinfo.elem.findall('param') lens = set() for param in params: - len = self.getLen(param) - if len: - lens.add(len) - paramsInfo = [] + length = self.getLen(param) + if length: + lens.add(length) + for param in params: paramInfo = self.getTypeNameTuple(param) param_type = paramInfo[0] @@ -473,14 +473,14 @@ def AddCommandToDispatchList(self, extension_name, extension_type, name, cmdinfo # # Retrieve the type and name for a parameter def getTypeNameTuple(self, param): - type = '' - name = '' + t = '' + n = '' for elem in param: if elem.tag == 'type': - type = noneStr(elem.text) + t = noneStr(elem.text) elif elem.tag == 'name': - name = noneStr(elem.text) - return (type, name) + n = noneStr(elem.text) + return (t, n) # Convert an XML dependency expression to a C expression, taking a callback to replace extension names # See https://registry.khronos.org/vulkan/specs/1.3/registry.html#depends-expressions @@ -598,21 +598,21 @@ def OutputLayerInstanceDispatchTable(self): if cur_cmd.ext_name != cur_extension_name: if version: - table += '\n // ---- Core %s commands\n' % version.name + table += f'\n // ---- Core {version.name} commands\n' else: - table += '\n // ---- %s extension commands\n' % cur_cmd.ext_name + table += f'\n // ---- {cur_cmd.ext_name} extension commands\n' cur_extension_name = cur_cmd.ext_name # Remove 'vk' from proto name base_name = cur_cmd.name[2:] if cur_cmd.protect is not None: - table += '#if defined(%s)\n' % cur_cmd.protect + table += f'#if defined({cur_cmd.protect})\n' - table += ' PFN_%s %s;\n' % (cur_cmd.name, base_name) + table += f' PFN_{cur_cmd.name} {base_name};\n' if cur_cmd.protect is not None: - table += '#endif // %s\n' % cur_cmd.protect + table += f'#endif // {cur_cmd.protect}\n' table += '} VkLayerInstanceDispatchTable;\n\n' return table @@ -642,21 +642,20 @@ def OutputLayerDeviceDispatchTable(self): if cur_cmd.ext_name != cur_extension_name: if version: - table += '\n // ---- Core %s commands\n' % version.name + table += f'\n // ---- Core {version.name} commands\n' else: - table += '\n // ---- %s extension commands\n' % cur_cmd.ext_name + table += f'\n // ---- {cur_cmd.ext_name} extension commands\n' cur_extension_name = cur_cmd.ext_name # Remove 'vk' from proto name base_name = cur_cmd.name[2:] if cur_cmd.protect is not None: - table += '#if defined(%s)\n' % cur_cmd.protect - - table += ' PFN_%s %s;\n' % (cur_cmd.name, base_name) + table += f'#if defined({cur_cmd.protect})\n' + table += f' PFN_{cur_cmd.name} {base_name};\n' if cur_cmd.protect is not None: - table += '#endif // %s\n' % cur_cmd.protect + table += f'#endif // {cur_cmd.protect}\n' table += '} VkLayerDispatchTable;\n\n' return table @@ -689,24 +688,24 @@ def OutputIcdDispatchTable(self): for cur_cmd in commands: version = self.getAPIVersion(cur_cmd.ext_name) - if (self.ShouldPrintInIcdDispatchTable(cur_cmd, skip_commands)): + if self.ShouldPrintInIcdDispatchTable(cur_cmd, skip_commands): if cur_cmd.ext_name != cur_extension_name: if version: - table += '\n // ---- Core %s commands\n' % version.name + table += f'\n // ---- Core {version.name} commands\n' else: - table += '\n // ---- %s extension commands\n' % cur_cmd.ext_name + table += f'\n // ---- {cur_cmd.ext_name} extension commands\n' cur_extension_name = cur_cmd.ext_name # Remove 'vk' from proto name base_name = cur_cmd.name[2:] if cur_cmd.protect is not None: - table += '#if defined(%s)\n' % cur_cmd.protect + table += f'#if defined({cur_cmd.protect})\n' - table += ' PFN_%s %s;\n' % (cur_cmd.name, base_name) + table += f' PFN_{cur_cmd.name} {base_name};\n' if cur_cmd.protect is not None: - table += '#endif // %s\n' % cur_cmd.protect + table += f'#endif // {cur_cmd.protect}\n' table += '};\n\n' return table @@ -752,14 +751,14 @@ def OutputIcdDispatchTableInit(self): required = False for cur_cmd in commands: version = self.getAPIVersion(cur_cmd.ext_name) - if (self.ShouldPrintInIcdDispatchTable(cur_cmd, skip_gipa_commands)): + if self.ShouldPrintInIcdDispatchTable(cur_cmd, skip_gipa_commands): if cur_cmd.ext_name != cur_extension_name: if version: - table += '\n // ---- Core %s\n' % version.name + table += f'\n // ---- Core {version.name}\n' required = version.number == '1.0' else: - table += '\n // ---- %s extension commands\n' % cur_cmd.ext_name + table += f'\n // ---- {cur_cmd.ext_name} extension commands\n' required = False cur_extension_name = cur_cmd.ext_name @@ -767,7 +766,7 @@ def OutputIcdDispatchTableInit(self): base_name = cur_cmd.name[2:] if cur_cmd.protect is not None: - table += '#if defined(%s)\n' % cur_cmd.protect + table += f'#if defined({cur_cmd.protect})\n' if required: # The Core Vulkan code will be wrapped in a feature called VK_VERSION_#_# @@ -776,7 +775,7 @@ def OutputIcdDispatchTableInit(self): else: table += f' LOOKUP_GIPA({base_name});\n' if cur_cmd.protect is not None: - table += '#endif // %s\n' % cur_cmd.protect + table += f'#endif // {cur_cmd.protect}\n' table += '\n' table += '#undef LOOKUP_REQUIRED_GIPA\n' @@ -798,7 +797,7 @@ def OutputIcdExtensionEnableUnion(self): ext.type == 'device' or ext.num_commands == 0): continue - union += ' uint8_t %s;\n' % ext.name[3:].lower() + union += f' uint8_t {ext.name[3:].lower()};\n' union += '};\n\n' return union @@ -822,7 +821,7 @@ def OutputLoaderTerminators(self): mod_string = mod_string.replace(cur_cmd.name[2:] + '(\n', cur_cmd.name[2:] + '(\n const Vk' + cur_cmd.name[2:] + 'Chain* chain,\n') if cur_cmd.protect is not None: - terminators += '#if defined(%s)\n' % cur_cmd.protect + terminators += f'#if defined({cur_cmd.protect})\n' if cur_cmd.name in PRE_INSTANCE_FUNCTIONS: terminators += pre_instance_basic_version @@ -832,7 +831,7 @@ def OutputLoaderTerminators(self): terminators += '\n' if cur_cmd.protect is not None: - terminators += '#endif // %s\n' % cur_cmd.protect + terminators += f'#endif // {cur_cmd.protect}\n' terminators += '\n' return terminators @@ -897,9 +896,9 @@ def OutputLoaderDispatchTables(self): if ((cur_type == 'instance' and is_inst_handle_type) or (cur_type == 'device' and not is_inst_handle_type)): if cur_cmd.ext_name != cur_extension_name: if version: - tables += '\n // ---- Core %s commands\n' % version.name + tables += f'\n // ---- Core {version.name} commands\n' else: - tables += '\n // ---- %s extension commands\n' % cur_cmd.ext_name + tables += f'\n // ---- {cur_cmd.ext_name} extension commands\n' cur_extension_name = cur_cmd.ext_name # Remove 'vk' from proto name @@ -913,7 +912,7 @@ def OutputLoaderDispatchTables(self): continue if cur_cmd.protect is not None: - tables += '#if defined(%s)\n' % cur_cmd.protect + tables += f'#if defined({cur_cmd.protect})\n' # If we're looking for the proc we are passing in, just point the table to it. This fixes the issue where # a layer overrides the function name for the loader. @@ -921,18 +920,18 @@ def OutputLoaderDispatchTables(self): if base_name == 'GetDeviceProcAddr': tables += ' table->GetDeviceProcAddr = gdpa;\n' elif cur_cmd.ext_type == 'instance': - tables += ' table->%s = (PFN_%s)gipa(inst, "%s");\n' % (base_name, cur_cmd.name, cur_cmd.name) + tables += f' table->{base_name} = (PFN_{cur_cmd.name})gipa(inst, "{cur_cmd.name}");\n' else: - tables += ' table->%s = (PFN_%s)gdpa(dev, "%s");\n' % (base_name, cur_cmd.name, cur_cmd.name) + tables += f' table->{base_name} = (PFN_{cur_cmd.name})gdpa(dev, "{cur_cmd.name}");\n' elif (x < 1 and base_name == 'GetDeviceProcAddr'): tables += ' table->GetDeviceProcAddr = gpa;\n' elif (x > 1 and base_name == 'GetInstanceProcAddr'): tables += ' table->GetInstanceProcAddr = gpa;\n' else: - tables += ' table->%s = (PFN_%s)gpa(%s, "%s");\n' % (base_name, cur_cmd.name, gpa_param, cur_cmd.name) + tables += f' table->{base_name} = (PFN_{cur_cmd.name})gpa({gpa_param}, "{cur_cmd.name}");\n' if cur_cmd.protect is not None: - tables += '#endif // %s\n' % cur_cmd.protect + tables += f'#endif // {cur_cmd.protect}\n' tables += '}\n\n' return tables @@ -990,12 +989,12 @@ def OutputLoaderLookupFunc(self): if ((cur_type == 'instance' and is_inst_handle_type) or (cur_type == 'device' and not is_inst_handle_type)): if cur_cmd.ext_name != cur_extension_name: if version: - tables += '\n // ---- Core %s commands\n' % version.name + tables += f'\n // ---- Core {version.name} commands\n' if cur_type == 'device': version_check = f' if (dev->should_ignore_device_commands_from_newer_version && api_version < {version.constant}) return NULL;\n' else: - tables += '\n // ---- %s extension commands\n' % cur_cmd.ext_name + tables += f'\n // ---- {cur_cmd.ext_name} extension commands\n' version_check = '' cur_extension_name = cur_cmd.ext_name @@ -1009,7 +1008,7 @@ def OutputLoaderLookupFunc(self): continue if cur_cmd.protect is not None: - tables += '#if defined(%s)\n' % cur_cmd.protect + tables += f'#if defined({cur_cmd.protect})\n' tables += f' if (!strcmp(name, "{base_name}")) ' if cur_cmd.name in DEVICE_CMDS_MUST_USE_TRAMP: @@ -1025,7 +1024,7 @@ def OutputLoaderLookupFunc(self): tables += f'return (void *)table->{base_name};\n' if cur_cmd.protect is not None: - tables += '#endif // %s\n' % cur_cmd.protect + tables += f'#endif // {cur_cmd.protect}\n' tables += '\n' tables += ' *found_name = false;\n' @@ -1036,7 +1035,6 @@ def OutputLoaderLookupFunc(self): # # Create the appropriate trampoline (and possibly terminator) functions def CreateTrampTermFuncs(self): - entries = [] funcs = '' cur_extension_name = '' @@ -1078,13 +1076,13 @@ def CreateTrampTermFuncs(self): version = self.getAPIVersion(ext_cmd.ext_name) if ext_cmd.ext_name != cur_extension_name: if version: - funcs += '\n// ---- Core %s trampoline/terminators\n\n' % version.name + funcs += f'\n// ---- Core {version.name} trampoline/terminators\n\n' else: - funcs += '\n// ---- %s extension trampoline/terminators\n\n' % ext_cmd.ext_name + funcs += f'\n// ---- {ext_cmd.ext_name} extension trampoline/terminators\n\n' cur_extension_name = ext_cmd.ext_name if ext_cmd.protect is not None: - funcs += '#if defined(%s)\n' % ext_cmd.protect + funcs += f'#if defined({ext_cmd.protect})\n' func_header = ext_cmd.cdecl.replace(";", " {\n") tramp_header = func_header.replace("VKAPI_CALL vk", "VKAPI_CALL ") @@ -1132,7 +1130,7 @@ def CreateTrampTermFuncs(self): requires_terminator = 1 instance_var_name = param.name - if (ext_cmd.return_type is not None): + if ext_cmd.return_type is not None: return_prefix += 'return ' has_return_type = True @@ -1148,20 +1146,20 @@ def CreateTrampTermFuncs(self): if ext_cmd.handle_type == 'VkPhysicalDevice': funcs += ' const VkLayerInstanceDispatchTable *disp;\n' - funcs += ' VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device(%s);\n' % (phys_dev_var_name) + funcs += f' VkPhysicalDevice unwrapped_phys_dev = loader_unwrap_physical_device({phys_dev_var_name});\n' funcs += ' if (VK_NULL_HANDLE == unwrapped_phys_dev) {\n' funcs += ' loader_log(NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,\n' - funcs += ' "%s: Invalid %s "\n' % (ext_cmd.name, phys_dev_var_name) - funcs += ' "[VUID-%s-%s-parameter]");\n' % (ext_cmd.name, phys_dev_var_name) + funcs += f' "{ext_cmd.name}: Invalid {phys_dev_var_name} "\n' + funcs += f' "[VUID-{ext_cmd.name}-{phys_dev_var_name}-parameter]");\n' funcs += ' abort(); /* Intentionally fail so user can correct issue. */\n' funcs += ' }\n' - funcs += ' disp = loader_get_instance_layer_dispatch(%s);\n' % (phys_dev_var_name) + funcs += f' disp = loader_get_instance_layer_dispatch({phys_dev_var_name});\n' elif ext_cmd.handle_type == 'VkInstance': - funcs += ' struct loader_instance *inst = loader_get_instance(%s);\n' % (instance_var_name) + funcs += f' struct loader_instance *inst = loader_get_instance({instance_var_name});\n' funcs += ' if (NULL == inst) {\n' funcs += ' loader_log(\n' funcs += ' NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,\n' - funcs += ' "%s: Invalid instance [VUID-%s-%s-parameter]");\n' % (ext_cmd.name, ext_cmd.name, instance_var_name) + funcs += f' "{ext_cmd.name}: Invalid instance [VUID-{ext_cmd.name}-{instance_var_name}-parameter]");\n' funcs += ' abort(); /* Intentionally fail so user can correct issue. */\n' funcs += ' }\n' funcs += '#error("Not implemented. Likely needs to be manually generated!");\n' @@ -1171,8 +1169,8 @@ def CreateTrampTermFuncs(self): funcs += ');\n' funcs += ' if (NULL == disp) {\n' funcs += ' loader_log(NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,\n' - funcs += ' "%s: Invalid %s "\n' % (ext_cmd.name, ext_cmd.params[0].name) - funcs += ' "[VUID-%s-%s-parameter]");\n' % (ext_cmd.name, ext_cmd.params[0].name) + funcs += f' "{ext_cmd.name}: Invalid {ext_cmd.params[0].name} "\n' + funcs += f' "[VUID-{ext_cmd.name}-{ext_cmd.params[0].name}-parameter]");\n' funcs += ' abort(); /* Intentionally fail so user can correct issue. */\n' funcs += ' }\n' @@ -1242,9 +1240,9 @@ def CreateTrampTermFuncs(self): if param.type == 'VkPhysicalDevice': funcs += 'unwrapped_phys_dev' elif ('DebugMarkerSetObject' in ext_cmd.name or 'SetDebugUtilsObject' in ext_cmd.name) and param.name == 'pNameInfo': - funcs += '&local_name_info' + funcs += '&local_name_info' elif ('DebugMarkerSetObject' in ext_cmd.name or 'SetDebugUtilsObject' in ext_cmd.name) and param.name == 'pTagInfo': - funcs += '&local_tag_info' + funcs += '&local_tag_info' else: funcs += param.name @@ -1259,7 +1257,7 @@ def CreateTrampTermFuncs(self): funcs += term_header if ext_cmd.handle_type == 'VkPhysicalDevice': - funcs += ' struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)%s;\n' % (phys_dev_var_name) + funcs += f' struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *){phys_dev_var_name};\n' funcs += ' struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;\n' funcs += ' if (NULL == icd_term->dispatch.' funcs += base_name @@ -1279,7 +1277,7 @@ def CreateTrampTermFuncs(self): funcs += ' }\n' if has_surface == 1: - funcs += ' VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)(%s);\n' % (surface_var_name) + funcs += f' VkIcdSurface *icd_surface = (VkIcdSurface *)(uintptr_t)({surface_var_name});\n' funcs += ' if (NULL != icd_term->surface_list.list && icd_term->surface_list.capacity > icd_surface->surface_index * sizeof(VkSurfaceKHR) && icd_term->surface_list[icd_surface->surface_index]) {\n' # If there's a structure with a surface, we need to update its internals with the correct surface for the ICD @@ -1329,11 +1327,11 @@ def CreateTrampTermFuncs(self): elif ext_cmd.handle_type == 'VkInstance': - funcs += ' struct loader_instance *inst = loader_get_instance(%s);\n' % (instance_var_name) + funcs += f' struct loader_instance *inst = loader_get_instance({instance_var_name});\n' funcs += ' if (NULL == inst) {\n' funcs += ' loader_log(\n' funcs += ' NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,\n' - funcs += ' "%s: Invalid instance [VUID-%s-%s-parameter]");\n' % (ext_cmd.name, ext_cmd.name, instance_var_name) + funcs += f' "{ext_cmd.name}: Invalid instance [VUID-{ext_cmd.name}-{instance_var_name}-parameter]");\n' funcs += ' abort(); /* Intentionally fail so user can correct issue. */\n' funcs += ' }\n' funcs += '#error("Not implemented. Likely needs to be manually generated!");\n' @@ -1420,8 +1418,8 @@ def CreateTrampTermFuncs(self): funcs += ');\n' funcs += ' if (NULL == disp) {\n' funcs += ' loader_log(NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,\n' - funcs += ' "%s: Invalid %s "\n' % (ext_cmd.name, ext_cmd.params[0].name) - funcs += ' "[VUID-%s-%s-parameter]");\n' % (ext_cmd.name, ext_cmd.params[0].name) + funcs += f' "{ext_cmd.name}: Invalid {ext_cmd.params[0].name} "\n' + funcs += f' "[VUID-{ext_cmd.name}-{ext_cmd.params[0].name}-parameter]");\n' funcs += ' abort(); /* Intentionally fail so user can correct issue. */\n' funcs += ' }\n' @@ -1447,7 +1445,7 @@ def CreateTrampTermFuncs(self): funcs += '}\n\n' if ext_cmd.protect is not None: - funcs += '#endif // %s\n' % ext_cmd.protect + funcs += f'#endif // {ext_cmd.protect}\n' return funcs @@ -1455,7 +1453,6 @@ def CreateTrampTermFuncs(self): # # Create a function for the extension GPA call def InstExtensionGPA(self): - entries = [] gpa_func = '' cur_extension_name = '' @@ -1471,32 +1468,32 @@ def InstExtensionGPA(self): continue if cur_cmd.ext_name != cur_extension_name: - gpa_func += '\n // ---- %s extension commands\n' % cur_cmd.ext_name + gpa_func += f'\n // ---- {cur_cmd.ext_name} extension commands\n' cur_extension_name = cur_cmd.ext_name if cur_cmd.protect is not None: - gpa_func += '#if defined(%s)\n' % cur_cmd.protect + gpa_func += f'#if defined({cur_cmd.protect})\n' #base_name = cur_cmd.name[2:] base_name = SHARED_ALIASES[cur_cmd.name] if cur_cmd.name in SHARED_ALIASES else cur_cmd.name[2:] - if (cur_cmd.ext_type == 'instance'): - gpa_func += ' if (!strcmp("%s", name)) {\n' % (cur_cmd.name) + if cur_cmd.ext_type == 'instance': + gpa_func += f' if (!strcmp("{cur_cmd.name}", name)) {{\n' gpa_func += ' *addr = (ptr_instance->enabled_known_extensions.' gpa_func += cur_cmd.ext_name[3:].lower() gpa_func += ' == 1)\n' - gpa_func += ' ? (void *)%s\n' % (base_name) + gpa_func += f' ? (void *){base_name}\n' gpa_func += ' : NULL;\n' gpa_func += ' return true;\n' gpa_func += ' }\n' else: - gpa_func += ' if (!strcmp("%s", name)) {\n' % (cur_cmd.name) - gpa_func += ' *addr = (void *)%s;\n' % (base_name) + gpa_func += f' if (!strcmp("{cur_cmd.name}", name)) {{\n' + gpa_func += f' *addr = (void *){base_name};\n' gpa_func += ' return true;\n' gpa_func += ' }\n' if cur_cmd.protect is not None: - gpa_func += '#endif // %s\n' % cur_cmd.protect + gpa_func += f'#endif // {cur_cmd.protect}\n' gpa_func += ' return false;\n' gpa_func += '}\n\n' @@ -1522,11 +1519,11 @@ def InstantExtensionCreate(self): continue if ext.name != cur_extension_name: - create_func += '\n // ---- %s extension commands\n' % ext.name + create_func += f'\n // ---- {ext.name} extension commands\n' cur_extension_name = ext.name if ext.protect is not None: - create_func += '#if defined(%s)\n' % ext.protect + create_func += f'#if defined({ext.protect})\n' if count == 0: create_func += ' if (0 == strcmp(pCreateInfo->ppEnabledExtensionNames[i], ' else: @@ -1538,7 +1535,7 @@ def InstantExtensionCreate(self): create_func += ' = 1;\n' if ext.protect is not None: - create_func += '#endif // %s\n' % ext.protect + create_func += f'#endif // {ext.protect}\n' count += 1 create_func += ' }\n' @@ -1573,22 +1570,22 @@ def DeviceExtensionGetTerminator(self): last_protect = ext_cmd.protect if ext_cmd.protect is not None: term_func += f'#if defined({ext_cmd.protect})\n' - if (last_ext != ext_cmd.ext_name): + if last_ext != ext_cmd.ext_name: term_func += f' // ---- {ext_cmd.ext_name} extension commands\n' last_ext = ext_cmd.ext_name term_func += f' if (!strcmp(name, "{ext_cmd.name[2:]}")) {{\n' - term_func += f' *found_name = true;\n' + term_func += ' *found_name = true;\n' if ext_cmd.require: dep_expr = self.ConvertDependencyExpression(ext_cmd.require, lambda ext_name: f'dev->driver_extensions.{ext_name[3:].lower()}_enabled') term_func += f' return (dev->driver_extensions.{ext_cmd.ext_name[3:].lower()}_enabled && ({dep_expr})) ?\n' else: term_func += f' return dev->driver_extensions.{ext_cmd.ext_name[3:].lower()}_enabled ?\n' term_func += f' (PFN_vkVoidFunction)terminator_{(ext_cmd.name[2:])} : NULL;\n' - term_func += f' }}\n' + term_func += ' }\n' if last_protect is not None: - term_func += '#endif // %s\n' % last_protect + term_func += f'#endif // {last_protect}\n' term_func += ' return NULL;\n' term_func += '}\n\n' @@ -1614,14 +1611,14 @@ def OutputDeviceFunctionTerminatorDispatchTable(self): last_protect = ext_cmd.protect if ext_cmd.protect is not None: term_func += f'#if defined({ext_cmd.protect})\n' - if (last_ext != ext_cmd.ext_name): + if last_ext != ext_cmd.ext_name: term_func += f' // ---- {ext_cmd.ext_name} extension commands\n' last_ext = ext_cmd.ext_name term_func += f' PFN_{ext_cmd.name} {ext_cmd.name[2:]};\n' if last_protect is not None: - term_func += '#endif // %s\n' % last_protect + term_func += f'#endif // {last_protect}\n' term_func += '};\n\n' @@ -1642,14 +1639,14 @@ def OutputDeviceFunctionTrampolinePrototypes(self): last_protect = ext_cmd.protect if ext_cmd.protect is not None: tramp_protos += f'#if defined({ext_cmd.protect})\n' - if (last_ext != ext_cmd.ext_name): + if last_ext != ext_cmd.ext_name: tramp_protos += f' // ---- {ext_cmd.ext_name} extension commands\n' last_ext = ext_cmd.ext_name tramp_protos += f'{ext_cmd.cdecl.replace("VKAPI_CALL vk", "VKAPI_CALL ")}\n' if last_protect is not None: - tramp_protos += '#endif // %s\n' % last_protect + tramp_protos += f'#endif // {last_protect}\n' tramp_protos += '\n' return tramp_protos @@ -1675,7 +1672,7 @@ def InitDeviceFunctionTerminatorDispatchTable(self): last_protect = ext_cmd.protect if ext_cmd.protect is not None: term_func += f'#if defined({ext_cmd.protect})\n' - if (last_ext != ext_cmd.ext_name): + if last_ext != ext_cmd.ext_name: term_func += f' // ---- {ext_cmd.ext_name} extension commands\n' last_ext = ext_cmd.ext_name @@ -1689,7 +1686,7 @@ def InitDeviceFunctionTerminatorDispatchTable(self): term_func += f' dispatch->{ext_cmd.name[2:]} = (PFN_{(ext_cmd.name)})gpda(dev->icd_device, "{(ext_cmd.name)}");\n' if last_protect is not None: - term_func += '#endif // %s\n' % last_protect + term_func += f'#endif // {last_protect}\n' term_func += '}\n\n' @@ -1719,9 +1716,9 @@ def InitInstLoaderExtensionDispatchTable(self): if cur_cmd.handle_type == 'VkInstance' or cur_cmd.handle_type == 'VkPhysicalDevice': if cur_cmd.ext_name != cur_extension_name: if version: - table += '\n // ---- Core %s commands\n' % version.name + table += f'\n // ---- Core {version.name} commands\n' else: - table += '\n // ---- %s extension commands\n' % cur_cmd.ext_name + table += f'\n // ---- {cur_cmd.ext_name} extension commands\n' cur_extension_name = cur_cmd.ext_name # Remove 'vk' from proto name @@ -1735,15 +1732,15 @@ def InitInstLoaderExtensionDispatchTable(self): continue if cur_cmd.protect is not None: - table += '#if defined(%s)\n' % cur_cmd.protect + table += f'#if defined({cur_cmd.protect})\n' if base_name == 'GetInstanceProcAddr': - table += ' .%s = %s,\n' % (base_name, cur_cmd.name) + table += f' .{base_name} = {cur_cmd.name},\n' else: - table += ' .%s = terminator_%s,\n' % (base_name, aliased_name) + table += f' .{base_name} = terminator_{aliased_name},\n' if cur_cmd.protect is not None: - table += '#endif // %s\n' % cur_cmd.protect + table += f'#endif // {cur_cmd.protect}\n' table += '};\n\n' return table @@ -1764,12 +1761,11 @@ def OutputInstantExtensionWhitelistArray(self): continue if ext.protect is not None: - table += '#if defined(%s)\n' % ext.protect + table += f'#if defined({ext.protect})\n' table += ' ' table += ext.define + ',\n' if ext.protect is not None: - table += '#endif // %s\n' % ext.protect + table += f'#endif // {ext.protect}\n' table += ' NULL };\n' return table -