Skip to content

Commit

Permalink
Small refactor of codegen
Browse files Browse the repository at this point in the history
Renames `instanceExtensions` to extensions to reflect that it is all
extensions, not just instance.
Uses self.extensions instead of creating local variables.
  • Loading branch information
charles-lunarg committed Oct 29, 2024
1 parent d79f318 commit b3b62dc
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions scripts/loader_extension_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ def __init__(self,
self.ext_device_dispatch_list = [] # List of extension entries for device dispatch list
self.core_commands = [] # List of CommandData records for core Vulkan commands
self.ext_commands = [] # List of CommandData records for extension Vulkan commands
self.extensions = [] # List of ExtensionData records
self.CommandParam = namedtuple('CommandParam', ['type', 'name', 'cdecl'])
self.CommandData = namedtuple('CommandData', ['name', 'ext_name', 'ext_type', 'require', 'protect', 'return_type', 'handle_type', 'params', 'cdecl'])
self.instanceExtensions = []
self.ExtensionData = namedtuple('ExtensionData', ['name', 'type', 'protect', 'define', 'num_commands'])
self.ExtensionData = namedtuple('ExtensionData', ['name', 'type', 'protect', 'define'])

#
# Called once at the beginning of each run
Expand Down Expand Up @@ -314,7 +314,6 @@ def beginFeature(self, interface, emit):
self.name_definition = name_definition

self.type = interface.get('type')
self.num_commands = 0
name = interface.get('name')
self.currentExtension = name

Expand All @@ -327,18 +326,15 @@ def genCmd(self, cmdinfo, name, alias):
params = cmdinfo.elem.findall('param')
info = self.getTypeNameTuple(params[0])

self.num_commands += 1

if 'android' not in name:
self.AddCommandToDispatchList(self.currentExtension, self.type, name, cmdinfo, info[0])

def endFeature(self):

self.instanceExtensions.append(self.ExtensionData(name=self.currentExtension,
self.extensions.append(self.ExtensionData(name=self.currentExtension,
type=self.type,
protect=self.featureExtraProtect,
define=self.name_definition,
num_commands=self.num_commands))
define=self.name_definition))

# Finish processing in superclass
OutputGenerator.endFeature(self)
Expand Down Expand Up @@ -788,7 +784,7 @@ def OutputIcdDispatchTableInit(self):
# Create a struct which holds bools for each enabled instance extension
def OutputInstanceExtensionEnableStructDeclaration(self):
out = 'struct loader_instance_extension_enables {\n'
for ext in self.instanceExtensions:
for ext in self.extensions:
if self.getAPIVersion(ext.name) or ext.type == 'device':
continue
if ext.protect is not None:
Expand All @@ -803,7 +799,7 @@ def OutputInstanceExtensionEnableStructDeclaration(self):
def OutputInstanceExtensionEnableStructDefinition(self):
out = 'void fill_out_enabled_instance_extensions(uint32_t extension_count, const char *const * extension_list, struct loader_instance_extension_enables* enables) {\n'
out += ' for(uint32_t i = 0; i < extension_count; i++) {\n'
for ext in self.instanceExtensions:
for ext in self.extensions:
if self.getAPIVersion(ext.name) or ext.type == 'device':
continue
if ext.protect is not None:
Expand Down Expand Up @@ -1719,15 +1715,13 @@ def InitInstLoaderExtensionDispatchTable(self):
#
# Create the extension name whitelist array
def OutputInstantExtensionWhitelistArray(self):
extensions = self.instanceExtensions

table = ''
table += '// A null-terminated list of all of the instance extensions supported by the loader.\n'
table += '// If an instance extension name is not in this list, but it is exported by one or more of the\n'
table += '// ICDs detected by the loader, then the extension name not in the list will be filtered out\n'
table += '// before passing the list of extensions to the application.\n'
table += 'const char *const LOADER_INSTANCE_EXTENSIONS[] = {\n'
for ext in extensions:
for ext in self.extensions:
if ext.type == 'device' or self.getAPIVersion(ext.name):
continue

Expand Down

0 comments on commit b3b62dc

Please sign in to comment.