vulkan: Add dispatch table loading helpers

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8676>
This commit is contained in:
Jason Ekstrand
2021-01-23 11:36:18 -06:00
committed by Marge Bot
parent 04f1095e84
commit 74617eea46
4 changed files with 76 additions and 3 deletions

View File

@@ -95,6 +95,19 @@ ${dispatch_table('instance', instance_entrypoints)}
${dispatch_table('physical_device', physical_device_entrypoints)}
${dispatch_table('device', device_entrypoints)}
void
vk_instance_dispatch_table_load(struct vk_instance_dispatch_table *table,
PFN_vkGetInstanceProcAddr gpa,
VkInstance instance);
void
vk_physical_device_dispatch_table_load(struct vk_physical_device_dispatch_table *table,
PFN_vkGetInstanceProcAddr gpa,
VkInstance instance);
void
vk_device_dispatch_table_load(struct vk_device_dispatch_table *table,
PFN_vkGetDeviceProcAddr gpa,
VkDevice device);
#ifdef __cplusplus
}
#endif
@@ -102,6 +115,51 @@ ${dispatch_table('device', device_entrypoints)}
#endif /* VK_DISPATCH_TABLE_H */
""", output_encoding='utf-8')
TEMPLATE_C = Template(COPYRIGHT + """\
/* This file generated from ${filename}, don't edit directly. */
#include "vk_dispatch_table.h"
<%def name="load_dispatch_table(type, VkType, ProcAddr, entrypoints)">
void
vk_${type}_dispatch_table_load(struct vk_${type}_dispatch_table *table,
PFN_vk${ProcAddr} gpa,
${VkType} obj)
{
% if type != 'physical_device':
table->${ProcAddr} = gpa;
% endif
% for e in entrypoints:
% if e.alias or e.name == '${ProcAddr}':
<% continue %>
% endif
% if e.guard is not None:
#ifdef ${e.guard}
% endif
table->${e.name} = (PFN_vk${e.name}) gpa(obj, "vk${e.name}");
% for a in e.aliases:
if (table->${e.name} == NULL) {
table->${e.name} = (PFN_vk${e.name}) gpa(obj, "vk${a.name}");
}
% endfor
% if e.guard is not None:
#endif
% endif
% endfor
}
</%def>
${load_dispatch_table('instance', 'VkInstance', 'GetInstanceProcAddr',
instance_entrypoints)}
${load_dispatch_table('physical_device', 'VkInstance', 'GetInstanceProcAddr',
physical_device_entrypoints)}
${load_dispatch_table('device', 'VkDevice', 'GetDeviceProcAddr',
device_entrypoints)}
""", output_encoding='utf-8')
EntrypointParam = namedtuple('EntrypointParam', 'type name decl')
class EntrypointBase(object):
@@ -237,6 +295,7 @@ def get_entrypoints_defines(doc):
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--out-c', help='Output C file.')
parser.add_argument('--out-h', help='Output H file.')
parser.add_argument('--xml',
help='Vulkan API XML file.',
@@ -283,6 +342,11 @@ def main():
physical_device_entrypoints=physical_device_entrypoints,
device_entrypoints=device_entrypoints,
filename=os.path.basename(__file__)))
with open(args.out_c, 'wb') as f:
f.write(TEMPLATE_C.render(instance_entrypoints=instance_entrypoints,
physical_device_entrypoints=physical_device_entrypoints,
device_entrypoints=device_entrypoints,
filename=os.path.basename(__file__)))
except Exception:
# In the event there's an error, this imports some helpers from mako
# to print a useful stack trace and prints it, then exits with