VK Loader Zgen
VK Loader Zgen
VK Loader Zgen
import os
original_stdout = sys.stdout
def printheader_in_h(profile_type):
if (profile_type == "vkcore"):
profile_name = "core"
elif (profile_type == "vkwin32"):
profile_name = "win32"
print("#pragma once\n")
print("#define VK_NO_PROTOTYPES");
print("#include <vulkan/vulkan_core.h>\n")
if (profile_type == "vkwin32"):
print("#define WIN32_LEAN_AND_MEAN")
print("#include <windows.h>")
print("#include <vulkan/vulkan_win32.h>\n")
print("typedef void (*PFN_apiproc)(void);")
print("typedef PFN_apiproc (*PFN_loadfunc_vk)(VkInstance vk_instance, const
char* name);")
print("\n//#define VK_LOADER_" + profile_name.upper() + "_PRINT_ERRORS")
if (profile_type != "vkcore"):
print("\n")
# }
def printheader_in_cpp(profile_type):
if (profile_type == "vkcore"):
profile_name = "core"
elif (profile_type == "vkwin32"):
profile_name = "win32"
print("#include " + '"' + "vk_loader_" + profile_name + ".h" + '"')
print("\n#include <stdio.h>")
print("#if defined VK_LOADER_" + profile_name.upper() + "_PRINT_ERRORS")
print('#define print_msg(format, ...) printf(format ' + '"\\n"' + ',
__VA_ARGS__)')
print("#else")
print("#define print_msg")
print("#endif")
print("\n")
# }
vk_loader_func = "load"
is_func_def_block = False
vk_core_func_define_list_cpp = []
vk_core_init_func_versions_list_cpp = []
# gl_core_func_define_list_cpp = []
# gl_core_init_func_versions_list_cpp = []
vk_core_init_func_list_cpp = []
is_first_version_brace_cpp = True
printheader_in_h(profile_type)
if (is_version_line):
print("\n")
print(version_line, end='')
print("")
is_version_line = False
#sys.stdout = fout_cpp
if (is_first_version_brace_cpp):
is_first_version_brace_cpp = False
else:
vk_core_init_func_versions_list_cpp.append("}\n\n")
vk_core_init_func_versions_list_cpp.append("\nvoid vkfnlib_init_" +
version_name + "(PFN_loadfunc_vk load, VkInstance vk_instance) {\n")
vk_core_init_func_list_cpp.append("vkfnlib_init_" + version_name +
"(load, vk_instance);")
vk_core_func_define_list_cpp.append(version_line)
#sys.stdout = fout_h
# print(func_prototype_line_h, end='')
for i in range(0, len(words)):
if (words[i] == 'VKAPI_CALL'):
func_name = words[i+1]
func_name = func_name.replace("(", "")
# print(func_name)
func_name_ptr = "PFN_" + func_name
# header
func_ptrdefine_line_h = func_name_ptr + " " + func_name
vk_core_func_define_list_cpp.append(func_ptrdefine_line_h + " =
nullptr;")
func_ptrdecl_line_h = "extern " + func_ptrdefine_line_h + ";"
# cpp
func_init_cpp = func_name + " = (" + func_name_ptr + ")" +
vk_loader_func + '(vk_instance, "' + func_name + '");'
func_check_cpp = "if (!" + func_name + ') { print_msg("' +
func_name + ' not loaded"); }'
# cpp
vk_core_init_func_versions_list_cpp.append("\t" + func_init_cpp)
vk_core_init_func_versions_list_cpp.append("\n")
vk_core_init_func_versions_list_cpp.append("\t" + func_check_cpp)
vk_core_init_func_versions_list_cpp.append("\n")
is_func_def_block = False
sys.stdout = fout_cpp
printheader_in_cpp(profile_type)
for i in vk_core_func_define_list_cpp:
print(i)
print()
loader_internal_init = ""
if (profile_type == "vkwin32"):
loader_internal_init = "vkfnlib_init_vkwin32"
print("void " + loader_internal_init + "(PFN_loadfunc_vk load, VkInstance
vk_instance) {")
for i in vk_core_init_func_versions_list_cpp:
if 'vkGetInstanceProcAddr' in i \
or 'vkEnumerateInstanceExtensionProperties' in i or
'vkEnumerateInstanceLayerProperties' in i \
or 'vkCreateInstance' in i or 'vkEnumerateInstanceVersion' in i:
i = '\t//' + i.replace('\t', '')
print(i, end='')
print("}")
loader_init_func_name = ""
if (profile_type == "vkcore"):
loader_init_func_name = "vkfnlib_load_core"
elif (profile_type == "vkwin32"):
loader_init_func_name = "vkfnlib_load_vkwin32"
if (profile_type == "vkcore"):
for i in vk_core_init_func_list_cpp:
print("\t" + i)
else:
print("\t" + loader_internal_init + "(load, vk_instance);")
print("}")
sys.stdout = fout_h
print("\n\n// Loader Function")
print("void " + loader_init_func_name + "(PFN_loadfunc_vk load, VkInstance
vk_instance);")
vk_core_func_define_list_cpp.clear()
vk_core_init_func_versions_list_cpp.clear()
# } // process_vk_ext