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:

committed by
Marge Bot

parent
04f1095e84
commit
74617eea46
@@ -66,6 +66,14 @@ $(intermediates)/util/vk_enum_to_str.c: $(MESA_TOP)/src/vulkan/util/gen_enum_to_
|
||||
|
||||
$(intermediates)/util/vk_enum_to_str.h: $(intermediates)/util/vk_enum_to_str.c
|
||||
|
||||
$(intermediates)/util/vk_dispatch_table.c: $(MESA_TOP)/src/vulkan/util/vk_dispatch_table_gen.py \
|
||||
$(vulkan_api_xml)
|
||||
@echo "target Generated: $(PRIVATE_MODULE) <= $(notdir $(@))"
|
||||
@mkdir -p $(dir $@)
|
||||
$(hide) $(MESA_PYTHON2) $< \
|
||||
--xml $(vulkan_api_xml) \
|
||||
--out-c $@
|
||||
|
||||
$(intermediates)/util/vk_dispatch_table.h: $(MESA_TOP)/src/vulkan/util/vk_dispatch_table_gen.py \
|
||||
$(vulkan_api_xml)
|
||||
@echo "target Generated: $(PRIVATE_MODULE) <= $(notdir $(@))"
|
||||
|
@@ -40,6 +40,7 @@ VULKAN_UTIL_FILES := \
|
||||
VULKAN_UTIL_GENERATED_FILES := \
|
||||
util/vk_enum_to_str.c \
|
||||
util/vk_enum_to_str.h \
|
||||
util/vk_dispatch_table.c \
|
||||
util/vk_dispatch_table.h \
|
||||
util/vk_extensions.c \
|
||||
util/vk_extensions.h
|
||||
|
@@ -38,10 +38,10 @@ files_vulkan_util = files(
|
||||
vk_dispatch_table = custom_target(
|
||||
'vk_dispatch_table',
|
||||
input : ['vk_dispatch_table_gen.py', vk_api_xml],
|
||||
output : ['vk_dispatch_table.h'],
|
||||
output : ['vk_dispatch_table.c', 'vk_dispatch_table.h'],
|
||||
command : [
|
||||
prog_python, '@INPUT0@', '--xml', '@INPUT1@',
|
||||
'--out-h', '@OUTPUT0@'
|
||||
'--out-c', '@OUTPUT0@', '--out-h', '@OUTPUT1@'
|
||||
],
|
||||
)
|
||||
|
||||
@@ -77,7 +77,7 @@ libvulkan_util = static_library(
|
||||
)
|
||||
|
||||
idep_vulkan_util_headers = declare_dependency(
|
||||
sources : [vk_dispatch_table[0], vk_enum_to_str[1], vk_extensions[1]],
|
||||
sources : [vk_dispatch_table[1], vk_enum_to_str[1], vk_extensions[1]],
|
||||
include_directories : include_directories('.')
|
||||
)
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user