From e531875ad6f9cc6d0e270a727fe9642cc9db543f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 3 Mar 2019 23:36:14 +1100 Subject: [PATCH] load: remove global i_table --- load/init.cpp | 47 ----------------------------------------------- tools/spec.py | 16 ++++------------ 2 files changed, 4 insertions(+), 59 deletions(-) diff --git a/load/init.cpp b/load/init.cpp index f06fcb8..4151d28 100644 --- a/load/init.cpp +++ b/load/init.cpp @@ -29,57 +29,10 @@ static void setup_tables (void) static auto libraries = cruft::vk::load::enumerate (); static cruft::vk::load::vendor v (libraries[0]); - cruft::vk::load::i_table = &v.itable; cruft::vk::load::v_table = &v.vtable; } -/////////////////////////////////////////////////////////////////////////////// -static VkResult _vkCreateInstance ( - const VkInstanceCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkInstance* pInstance -) { - setup_tables (); - return cruft::vk::load::i_table->vkCreateInstance (pCreateInfo, pAllocator, pInstance); -} - - -//----------------------------------------------------------------------------- -static PFN_vkVoidFunction -_vkGetInstanceProcAddr (VkInstance instance,const char* pName) -{ - setup_tables (); - return cruft::vk::load::i_table->vkGetInstanceProcAddr (instance, pName); -} - - -//----------------------------------------------------------------------------- -VkResult _vkEnumerateInstanceExtensionProperties ( - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties -) { - setup_tables (); - return cruft::vk::load::i_table->vkEnumerateInstanceExtensionProperties ( - pLayerName, - pPropertyCount, - pProperties - ); -} - - -//----------------------------------------------------------------------------- -static cruft::vk::load::instance_table const _initialiser { - .vkCreateInstance = _vkCreateInstance, - .vkGetInstanceProcAddr = _vkGetInstanceProcAddr, - .vkEnumerateInstanceExtensionProperties = _vkEnumerateInstanceExtensionProperties, -}; - - -cruft::vk::load::instance_table const *cruft::vk::load::i_table = &_initialiser; - - /////////////////////////////////////////////////////////////////////////////// static void* _vk_icdGetInstanceProcAddr (VkInstance instance, char const *name) diff --git a/tools/spec.py b/tools/spec.py index 7bf2dd0..f4e0b4a 100644 --- a/tools/spec.py +++ b/tools/spec.py @@ -838,7 +838,6 @@ def write_load(dst: TextIO, q: List[Type], reg: Registry): dst.write(""" struct vendor_table; extern cruft::vk::load::vendor_table const *v_table [[gnu::visibility("default")]]; - extern cruft::vk::load::instance_table const *i_table [[gnu::visibility("default")]]; } """) @@ -866,7 +865,8 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry): implementations = { 'vkCreateInstance': """ auto res = std::make_unique> (); - auto err = cruft::vk::load::i_table->vkCreateInstance (pCreateInfo, pAllocator, &res->handle); + auto ptr = (decltype(vkCreateInstance)*) (cruft::vk::load::v_table->vk_icdGetInstanceProcAddr (nullptr, "vkCreateInstance")); + auto err = (*ptr) (pCreateInfo, pAllocator, &res->handle); if (err != VK_SUCCESS) return err; @@ -944,10 +944,6 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry): for obj in (i for i in q if isinstance(i, Command)): first_arg = reg.types[obj.params[0].type] - instance_forward = f""" - return cruft::vk::load::i_table->{obj.name} ({", ".join(p.name for p in obj.params)}); - """ - if obj.is_instance(reg): table = 'instance' elif obj.is_device(reg): @@ -964,12 +960,8 @@ def write_dispatch(dst: TextIO, q: List[Type], reg: Registry): if obj.is_instance(reg) and obj.params[0].type not in ['VkInstance', 'VkPhysicalDevice']: forwarding = f""" - if (::cruft::vk::load::i_table->{obj.name}) - return ::cruft::vk::load::i_table->{obj.name} ({', '.join (i.name for i in obj.params)}); - else {{ - auto ptr= cruft::vk::load::v_table->vk_icdGetInstanceProcAddr (nullptr, "{obj.name}"); - return ((decltype({obj.name})*) (ptr)) ({', '.join (i.name for i in obj.params)}); - }} + auto ptr= cruft::vk::load::v_table->vk_icdGetInstanceProcAddr (nullptr, "{obj.name}"); + return ((decltype({obj.name})*) (ptr)) ({', '.join (i.name for i in obj.params)}); """ else: forwarding = f"""