loader: Separate out the python generator script
Loader is a reference component. Intel driver is a sample component. Loader
should not be sharing files with driver. This is a first step in that direction.
Also loader has special cases that are not in driver or layers. So it simplifies
their scripts not to have loader baggage in them.
diff --git a/vk-generate.py b/vk-generate.py
index 6a2222a..024fce8 100755
--- a/vk-generate.py
+++ b/vk-generate.py
@@ -42,24 +42,6 @@
def run(self):
print(self.generate())
- def _does_function_create_object(self, proto):
- out_objs = proto.object_out_params()
- if proto.name == "ResetFences":
- return False
- return out_objs and out_objs[-1] == proto.params[-1]
-
- def _is_loader_special_case(self, proto):
- if proto.name in ["GetProcAddr", "EnumeratePhysicalDevices", "EnumerateLayers", "DbgRegisterMsgCallback", "DbgUnregisterMsgCallback", "DbgSetGlobalOption", "DestroyInstance"]:
- return True
- return not self.is_dispatchable_object_first_param(proto)
-
-
- def is_dispatchable_object_first_param(self, proto):
- in_objs = proto.object_in_params()
- non_dispatch_objs = []
- param0 = proto.params[0]
- return (len(in_objs) > 0) and (in_objs[0].ty == param0.ty) and (param0.ty not in non_dispatch_objs)
-
def generate(self):
copyright = self.generate_copyright()
header = self.generate_header()
@@ -114,111 +96,6 @@
def generate_footer(self):
pass
-class LoaderEntrypointsSubcommand(Subcommand):
- def generate_header(self):
- return "#include \"loader.h\""
-
- def _generate_object_setup(self, proto):
- method = "loader_init_dispatch"
- cond = "res == VK_SUCCESS"
-
- if "Get" in proto.name:
- method = "loader_set_dispatch"
-
- setup = []
-
- if proto.name == "AllocDescriptorSets":
- psets = proto.params[-2].name
- pcount = proto.params[-1].name
- setup.append("uint32_t i;")
- setup.append("for (i = 0; i < *%s; i++)" % pcount)
- setup.append(" %s(%s[i], disp);" % (method, psets))
- elif proto.name == "GetPhysicalDeviceInfo":
- ptype = proto.params[-3].name
- psize = proto.params[-2].name
- pdata = proto.params[-1].name
- cond = ("%s == VK_PHYSICAL_DEVICE_INFO_TYPE_DISPLAY_PROPERTIES_WSI && "
- "%s && %s" % (ptype, pdata, cond))
- setup.append("VkDisplayPropertiesWSI *info = %s;" % pdata)
- setup.append("size_t count = *%s / sizeof(*info), i;" % psize)
- setup.append("for (i = 0; i < count; i++) {")
- setup.append(" %s(info[i].display, disp);" % method)
- setup.append("}")
- elif proto.name == "GetSwapChainInfoWSI":
- ptype = proto.params[-3].name
- psize = proto.params[-2].name
- pdata = proto.params[-1].name
- cond = ("%s == VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI && "
- "%s && %s" % (ptype, pdata, cond))
- setup.append("VkSwapChainImageInfoWSI *info = %s;" % pdata)
- setup.append("size_t count = *%s / sizeof(*info), i;" % psize)
- setup.append("for (i = 0; i < count; i++) {")
- setup.append(" %s(info[i].image, disp);" % method)
- setup.append(" %s(info[i].memory, disp);" % method)
- setup.append("}")
- elif proto.name != "ResetFences":
- obj_params = proto.object_out_params()
- for param in obj_params:
- setup.append("%s(*%s, disp);" % (method, param.name))
-
- if setup:
- joined = "\n ".join(setup)
- setup = []
- setup.append(" if (%s) {" % cond)
- setup.append(" " + joined)
- setup.append(" }")
-
- return "\n".join(setup)
-
- def _generate_loader_dispatch_entrypoints(self, qual=""):
- if qual:
- qual += " "
-
- funcs = []
- for proto in self.protos:
- if self._is_loader_special_case(proto):
- continue
- func = []
-
- obj_setup = self._generate_object_setup(proto)
-
- func.append(qual + proto.c_func(prefix="vk", attr="VKAPI"))
- func.append("{")
-
- # declare local variables
- func.append(" const VkLayerDispatchTable *disp;")
- if proto.ret != 'void' and obj_setup:
- func.append(" VkResult res;")
- func.append("")
-
- # get dispatch table
- func.append(" disp = loader_get_dispatch(%s);" %
- proto.params[0].name)
- func.append("")
-
- # dispatch!
- dispatch = "disp->%s;" % proto.c_call()
- if proto.ret == 'void':
- func.append(" " + dispatch)
- elif not obj_setup:
- func.append(" return " + dispatch)
- else:
- func.append(" res = " + dispatch)
- func.append(obj_setup)
- func.append("")
- func.append(" return res;")
-
- func.append("}")
-
- funcs.append("\n".join(func))
-
- return "\n\n".join(funcs)
-
- def generate_body(self):
- body = [self._generate_loader_dispatch_entrypoints("LOADER_EXPORT")]
-
- return "\n\n".join(body)
-
class DispatchTableOpsSubcommand(Subcommand):
def run(self):
if len(self.argv) != 1:
@@ -231,13 +108,12 @@
def generate_header(self):
return "\n".join(["#include <vulkan.h>",
"#include <vkLayer.h>",
- "#include <string.h>",
- "#include \"loader_platform.h\""])
+ "#include <string.h>"])
def _generate_init(self):
stmts = []
for proto in self.protos:
- if self.is_dispatchable_object_first_param(proto) or proto.name == "CreateInstance":
+ if proto.name != "GetGlobalExtensionInfo":
stmts.append("table->%s = (PFN_vk%s) gpa(gpu, \"vk%s\");" %
(proto.name, proto.name, proto.name))
else:
@@ -260,7 +136,7 @@
def _generate_lookup(self):
lookups = []
for proto in self.protos:
- if self.is_dispatchable_object_first_param(proto):
+ if proto.name != "GetGlobalExtensionInfo":
lookups.append("if (!strcmp(name, \"%s\"))" % (proto.name))
lookups.append(" return (void *) table->%s;"
% (proto.name))
@@ -464,76 +340,13 @@
return "\n".join(body)
-class LoaderGetProcAddrSubcommand(Subcommand):
- def run(self):
- self.prefix = "vk"
-
- # we could get the list from argv if wanted
- self.intercepted = [proto.name for proto in self.protos]
-
- for proto in self.protos:
- if proto.name == "GetProcAddr":
- self.gpa = proto
-
- super().run()
-
- def generate_header(self):
- return "\n".join(["#include <string.h>"])
-
- def generate_body(self):
- lookups = []
- for proto in self.protos:
- if proto.name not in self.intercepted:
- lookups.append("/* no %s%s */" % (self.prefix, proto.name))
- continue
-
- lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
- lookups.append(" return (%s) %s%s;" %
- (self.gpa.ret, self.prefix, proto.name))
-
- special_lookups = []
- # these functions require special trampoline code beyond just the normal create object trampoline code
- special_names = ["AllocDescriptorSets", "GetMultiDeviceCompatibility"]
- for proto in self.protos:
- if self._is_loader_special_case(proto) or self._does_function_create_object(proto) or proto.name in special_names:
- special_lookups.append("if (!strcmp(name, \"%s\"))" % proto.name)
- special_lookups.append(" return (%s) %s%s;" %
- (self.gpa.ret, self.prefix, proto.name))
- else:
- continue
- body = []
- body.append("static inline %s globalGetProcAddr(const char *name)" %
- self.gpa.ret)
- body.append("{")
- body.append(generate_get_proc_addr_check("name"))
- body.append("")
- body.append(" name += 2;")
- body.append(" %s" % "\n ".join(lookups))
- body.append("")
- body.append(" return NULL;")
- body.append("}")
- body.append("")
- body.append("static inline void *loader_non_passthrough_gpa(const char *name)")
- body.append("{")
- body.append(generate_get_proc_addr_check("name"))
- body.append("")
- body.append(" name += 2;")
- body.append(" %s" % "\n ".join(special_lookups))
- body.append("")
- body.append(" return NULL;")
- body.append("}")
-
- return "\n".join(body)
-
def main():
subcommands = {
- "loader-entrypoints": LoaderEntrypointsSubcommand,
"dispatch-table-ops": DispatchTableOpsSubcommand,
"icd-dummy-entrypoints": IcdDummyEntrypointsSubcommand,
"icd-get-proc-addr": IcdGetProcAddrSubcommand,
"layer-intercept-proc": LayerInterceptProcSubcommand,
"win-def-file": WinDefFileSubcommand,
- "loader-get-proc-addr": LoaderGetProcAddrSubcommand,
}
if len(sys.argv) < 2 or sys.argv[1] not in subcommands: