load: remove global i_table

This commit is contained in:
Danny Robson 2019-03-03 23:36:14 +11:00
parent d4ff9cbc7a
commit e531875ad6
2 changed files with 4 additions and 59 deletions

View File

@ -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)

View File

@ -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<indirect<VkInstance,cruft::vk::load::instance_table>> ();
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"""