84 lines
3.0 KiB
Python
84 lines
3.0 KiB
Python
|
|
from common import func_name_to_caps, write_epilogue, write_preamble, FIRST_PARAM_BLACKLIST, FUNC_BLACKLIST
|
|
|
|
def write_funcdef(f, cmd):
|
|
if 'alias' in cmd or cmd["name"] in FUNC_BLACKLIST:
|
|
return
|
|
if len(cmd['params']) > 0 and cmd['params'][0]['type'] in FIRST_PARAM_BLACKLIST:
|
|
return
|
|
f.write(f"""{cmd["return_type"]} {cmd["name"]}(""")
|
|
f.write(", ".join([f"""{p['type']} {p['name']}{p['name_type_suffix']}""" for p in cmd['params']]))
|
|
|
|
func_name = f"VK_FUNCTION_{func_name_to_caps(cmd['name'])}_MWN"
|
|
param_list_pass = ", ".join([f"""{p['name']}""" for p in cmd['params']])
|
|
if cmd['return_type'] == 'void':
|
|
f.write(f""")
|
|
{{
|
|
g_dispatchTable.{cmd["name"][2:]}({param_list_pass});
|
|
recordVoidFunction({func_name}, {param_list_pass});
|
|
}}
|
|
""")
|
|
else:
|
|
f.write(f""")
|
|
{{
|
|
auto result = g_dispatchTable.{cmd["name"][2:]}({param_list_pass});
|
|
recordFunction({func_name}, result, {param_list_pass});
|
|
return result;
|
|
}}
|
|
""")
|
|
|
|
def write_funcgetter(f, cmd, alias_for = ''):
|
|
if cmd["name"] in FUNC_BLACKLIST:
|
|
return
|
|
if 'alias' in cmd:
|
|
write_funcgetter(f, vulkan_hpp['commands'][cmd['alias']], alias_for=cmd['name'])
|
|
return
|
|
if len(cmd['params']) > 0 and cmd['params'][0]['type'] in FIRST_PARAM_BLACKLIST:
|
|
return
|
|
f.write(f"""
|
|
if (std::strcmp(pName, "{alias_for or cmd['name']}") == 0) {{
|
|
return reinterpret_cast<PFN_vkVoidFunction>(&{cmd['name']});
|
|
}} else""")
|
|
|
|
def generate(targets):
|
|
assert(len(targets) == 1)
|
|
with open(targets[0], 'w') as f:
|
|
write_preamble(f, includes = ['<cstring>', '"dispatch_table.hpp"', '"functions.hpp"', '"record_list.hpp"', '"vk_function_ids.h"'])
|
|
commands = list(vulkan_hpp['commands'].values())
|
|
commands.sort(key=lambda cmd: cmd['platform'])
|
|
plat = ''
|
|
for cmd in commands:
|
|
if plat != cmd['platform']:
|
|
if plat != '':
|
|
f.write(f"""
|
|
#endif // defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
|
plat = cmd['platform']
|
|
f.write(f"""
|
|
#if defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
|
write_funcdef(f, cmd)
|
|
# finish the final platform
|
|
f.write(f"""#endif // defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
|
|
|
f.write("""PFN_vkVoidFunction getWrappedFunctionPtr(const char* pName)
|
|
{
|
|
""")
|
|
plat = ''
|
|
for cmd in commands:
|
|
if plat != cmd['platform']:
|
|
if plat != '':
|
|
f.write(f"""
|
|
#endif // defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
|
plat = cmd['platform']
|
|
f.write(f"""
|
|
#if defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
|
write_funcgetter(f, cmd)
|
|
# finish the final platform
|
|
f.write(f"""
|
|
#endif // defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
|
|
f.write("""
|
|
{{
|
|
return nullptr;
|
|
}}
|
|
}""")
|
|
write_epilogue(f)
|