VK_LAYER_MEWIN_capture/generators/function_ids.cpp.py

54 lines
1.8 KiB
Python

import binascii
from common import func_name_to_caps, write_epilogue, write_preamble, FIRST_PARAM_BLACKLIST, FUNC_BLACKLIST
HEADER_GUARD = 'VK_CAPTURE_FUNCTION_IDS_H_INCLUDED'
_dbg_hashes = set()
def write_funccase(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
funchash = binascii.crc32(cmd['name'].encode('utf8'))
f.write(f"""
case VK_FUNCTION_{func_name_to_caps(cmd['name'])}_MWN:
*pName = "{cmd['name']}";
return VK_SUCCESS;""")
# just to make sure there are no hash collisions, we wouldn't want that
global _dbg_hashes
assert(funchash not in _dbg_hashes)
_dbg_hashes.add(funchash)
def generate(targets):
assert(len(targets) == 1)
with open(targets[0], 'w') as f:
write_preamble(f, includes = ['<vulkan/vulkan.h>', '"vk_function_ids.h"'])
commands = list(vulkan_hpp['commands'].values())
commands.sort(key=lambda cmd: cmd['platform'])
plat = ''
f.write("""
VkResult vkGetFunctionNameMWN(VkDevice /* device */, VkFunctionMWN function, const char** pName)
{
switch(function)
{""")
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_funccase(f, cmd)
# finish the final platform
f.write(f"""#endif // defined({vulkan_hpp['platforms'][plat]['protect']})\n""")
f.write("""
default:
return VK_ERROR_UNKNOWN;
}
}
""")
write_epilogue(f)