diff --git a/tools/info.cpp b/tools/info.cpp index 691f332..fcade9a 100644 --- a/tools/info.cpp +++ b/tools/info.cpp @@ -9,6 +9,7 @@ #include +#include #include #include @@ -26,19 +27,21 @@ int main (int, char**) { + std::cout << "[ "; for (auto const &i: cruft::vk::icd::enumerate ()) { cruft::vk::icd::vendor v (i); - cruft::vk::icd::g_table = &v.vtable; - //std::cout << "available_layers: [ " - // << cruft::make_infix (cruft::vk::instance::available_layers ()) - // << " ]\n"; - cruft::vk::instance instance; - std::cout << "instance: " << instance << '\n'; - //for (const auto &d: cruft::vk::physical_device::find (instance)) - // std::cout << d << '\n'; + std::cout + << "{ vendor: " << i + << ", available_layers: [ " + << cruft::make_infix (cruft::vk::instance::available_layers ()) + << " ] }" + << ", instance: " << instance + << ", devices: [ " << cruft::make_infix (cruft::vk::physical_device::find (instance)) << " ], " + << " }, "; } + std::cout << " ]\n"; } \ No newline at end of file diff --git a/tools/spec.py b/tools/spec.py index b361ec2..18f356f 100644 --- a/tools/spec.py +++ b/tools/spec.py @@ -391,6 +391,16 @@ class Constant(Type): ############################################################################### class Command(Type): class Param(Type): + name: str + """An appropriate title for this parameter""" + type: str + """The name of this parameter's dependant type""" + param: str + """ + The components of this type for a C definition (ie, includes + pointer, const, and other decorations + """ + def __init__(self, node, **kwargs): assert node.tag == 'param' @@ -409,6 +419,9 @@ class Command(Type): # normalise whitespace self.param = " ".join(self.param.split()) + def is_pointer(self): + return '*' in self.param + def __init__(self, node): assert node.tag == "command" proto = node.find('proto') @@ -432,7 +445,9 @@ class Command(Type): if not self.params: return True - return not isinstance(self.params[0], Handle) + first_name = self.params[0].type + first_obj = reg.types[first_name] + return not isinstance(first_obj, Handle) def is_instance(self, reg: Registry): assert reg @@ -831,12 +846,17 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry): else: raise Exception("Unhandled command type") + if obj.params: + last_param = obj.params[-1] + last_obj = reg.types[last_param.type] + is_creating = isinstance(last_obj, Handle) and last_param.is_pointer() + else: + is_creating = False + dst.write(f""" extern "C" {obj.result} {rename(obj.name)} ({", ".join(p.param for p in obj.params)}) noexcept {{ - using first_arg_t = std::decay_t; - auto const entry = reinterpret_cast ({obj.params[0].name}); - auto const *table = reinterpret_cast<{table}_table*> (entry->table); + auto const *table = reinterpret_cast (entry->table); return (table->{obj.name})( reinterpret_cast (entry->handle)