vulkan-overlay-layer: Use the new dispatch tables

This lets us drop the dispatch tables in enum_to_str and replace them
with the new, better versions.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
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:47:35 -06:00 committed by Marge Bot
parent 74617eea46
commit 1cf035a96b
2 changed files with 21 additions and 102 deletions

View file

@ -43,11 +43,13 @@
#include "util/simple_mtx.h"
#include "vk_enum_to_str.h"
#include "vk_dispatch_table.h"
#include "vk_util.h"
/* Mapped from VkInstace/VkPhysicalDevice */
struct instance_data {
struct vk_instance_dispatch_table vtable;
struct vk_physical_device_dispatch_table pd_vtable;
VkInstance instance;
struct overlay_params params;
@ -419,14 +421,14 @@ static void device_map_queues(struct device_data *data,
struct instance_data *instance_data = data->instance;
uint32_t n_family_props;
instance_data->vtable.GetPhysicalDeviceQueueFamilyProperties(data->physical_device,
&n_family_props,
NULL);
instance_data->pd_vtable.GetPhysicalDeviceQueueFamilyProperties(data->physical_device,
&n_family_props,
NULL);
VkQueueFamilyProperties *family_props =
(VkQueueFamilyProperties *)malloc(sizeof(VkQueueFamilyProperties) * n_family_props);
instance_data->vtable.GetPhysicalDeviceQueueFamilyProperties(data->physical_device,
&n_family_props,
family_props);
instance_data->pd_vtable.GetPhysicalDeviceQueueFamilyProperties(data->physical_device,
&n_family_props,
family_props);
uint32_t queue_index = 0;
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
@ -1007,7 +1009,7 @@ static uint32_t vk_memory_type(struct device_data *data,
uint32_t type_bits)
{
VkPhysicalDeviceMemoryProperties prop;
data->instance->vtable.GetPhysicalDeviceMemoryProperties(data->physical_device, &prop);
data->instance->pd_vtable.GetPhysicalDeviceMemoryProperties(data->physical_device, &prop);
for (uint32_t i = 0; i < prop.memoryTypeCount; i++)
if ((prop.memoryTypes[i].propertyFlags & properties) == properties && type_bits & (1<<i))
return i;
@ -2499,10 +2501,11 @@ static VkResult overlay_CreateDevice(
struct device_data *device_data = new_device_data(*pDevice, instance_data);
device_data->physical_device = physicalDevice;
vk_load_device_commands(*pDevice, fpGetDeviceProcAddr, &device_data->vtable);
vk_device_dispatch_table_load(&device_data->vtable,
fpGetDeviceProcAddr, *pDevice);
instance_data->vtable.GetPhysicalDeviceProperties(device_data->physical_device,
&device_data->properties);
instance_data->pd_vtable.GetPhysicalDeviceProperties(device_data->physical_device,
&device_data->properties);
VkLayerDeviceCreateInfo *load_data_info =
get_device_chain_info(pCreateInfo, VK_LOADER_DATA_CALLBACK);
@ -2547,9 +2550,12 @@ static VkResult overlay_CreateInstance(
if (result != VK_SUCCESS) return result;
struct instance_data *instance_data = new_instance_data(*pInstance);
vk_load_instance_commands(instance_data->instance,
fpGetInstanceProcAddr,
&instance_data->vtable);
vk_instance_dispatch_table_load(&instance_data->vtable,
fpGetInstanceProcAddr,
instance_data->instance);
vk_physical_device_dispatch_table_load(&instance_data->pd_vtable,
fpGetInstanceProcAddr,
instance_data->instance);
instance_data_map_physical_devices(instance_data, true);
parse_overlay_env(&instance_data->params, getenv("VK_LAYER_MESA_OVERLAY_CONFIG"));

View file

@ -105,44 +105,6 @@ C_TEMPLATE = Template(textwrap.dedent(u"""\
unreachable("Undefined struct type.");
}
}
void vk_load_instance_commands(VkInstance instance,
PFN_vkGetInstanceProcAddr gpa,
struct vk_instance_dispatch_table *table)
{
memset(table, 0, sizeof(*table));
table->GetInstanceProcAddr = gpa;
% for cmd in commands:
% if not cmd.device_entrypoint and cmd.name != 'vkGetInstanceProcAddr':
% if cmd.extension is not None and cmd.extension.define is not None:
#ifdef ${cmd.extension.define}
table->${cmd.name[2:]} = (PFN_${cmd.name}) gpa(instance, "${cmd.name}");
#endif
% else:
table->${cmd.name[2:]} = (PFN_${cmd.name}) gpa(instance, "${cmd.name}");
% endif
% endif
%endfor
}
void vk_load_device_commands(VkDevice device,
PFN_vkGetDeviceProcAddr gpa,
struct vk_device_dispatch_table *table)
{
memset(table, 0, sizeof(*table));
table->GetDeviceProcAddr = gpa;
% for cmd in commands:
% if cmd.device_entrypoint and cmd.name != 'vkGetDeviceProcAddr':
% if cmd.extension is not None and cmd.extension.define is not None:
#ifdef ${cmd.extension.define}
table->${cmd.name[2:]} = (PFN_${cmd.name}) gpa(device, "${cmd.name}");
#endif
% else:
table->${cmd.name[2:]} = (PFN_${cmd.name}) gpa(device, "${cmd.name}");
% endif
% endif
%endfor
}
"""),
output_encoding='utf-8')
@ -179,39 +141,6 @@ H_TEMPLATE = Template(textwrap.dedent(u"""\
size_t vk_structure_type_size(const struct VkBaseInStructure *item);
struct vk_instance_dispatch_table {
PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
% for cmd in commands:
% if not cmd.device_entrypoint and cmd.name != 'vkGetInstanceProcAddr':
% if cmd.extension is not None and cmd.extension.define is not None:
#ifdef ${cmd.extension.define}
PFN_${cmd.name} ${cmd.name[2:]};
#endif
% else:
PFN_${cmd.name} ${cmd.name[2:]};
% endif
% endif
%endfor
};
struct vk_device_dispatch_table {
PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
% for cmd in commands:
% if cmd.device_entrypoint and cmd.name != 'vkGetDeviceProcAddr':
% if cmd.extension is not None and cmd.extension.define is not None:
#ifdef ${cmd.extension.define}
PFN_${cmd.name} ${cmd.name[2:]};
#endif
% else:
PFN_${cmd.name} ${cmd.name[2:]};
% endif
% endif
%endfor
};
void vk_load_instance_commands(VkInstance instance, PFN_vkGetInstanceProcAddr gpa, struct vk_instance_dispatch_table *table);
void vk_load_device_commands(VkDevice device, PFN_vkGetDeviceProcAddr gpa, struct vk_device_dispatch_table *table);
#ifdef __cplusplus
} /* extern "C" */
#endif
@ -339,7 +268,7 @@ def struct_get_stype(xml_node):
return None
def parse_xml(cmd_factory, enum_factory, ext_factory, struct_factory, filename):
def parse_xml(enum_factory, ext_factory, struct_factory, filename):
"""Parse the XML file. Accumulate results into the factories.
This parser is a memory efficient iterative XML parser that returns a list
@ -358,14 +287,6 @@ def parse_xml(cmd_factory, enum_factory, ext_factory, struct_factory, filename):
if enum is not None:
enum.add_value_from_xml(value)
for command in xml.findall('./commands/command'):
name = command.find('./proto/name')
first_arg = command.find('./param/type')
# Some commands are alias KHR -> nonKHR, ignore those
if name is not None:
cmd_factory(name.text,
device_entrypoint=(first_arg.text in ('VkDevice', 'VkCommandBuffer', 'VkQueue')))
for struct_type in xml.findall('./types/type[@category="struct"]'):
name = struct_type.attrib['name']
stype = struct_get_stype(struct_type)
@ -401,11 +322,6 @@ def parse_xml(cmd_factory, enum_factory, ext_factory, struct_factory, filename):
if enum is not None:
enum.set_guard(define)
for t in ext_elem.findall('./require/command'):
command = cmd_factory.get(t.attrib['name'])
if command is not None:
command.extension = extension
def main():
parser = argparse.ArgumentParser()
@ -419,13 +335,11 @@ def main():
args = parser.parse_args()
command_factory = NamedFactory(VkCommand)
enum_factory = NamedFactory(VkEnum)
ext_factory = NamedFactory(VkExtension)
struct_factory = NamedFactory(VkChainStruct)
for filename in args.xml_files:
parse_xml(command_factory, enum_factory, ext_factory, struct_factory, filename)
commands = sorted(command_factory.registry.values(), key=lambda e: e.name)
parse_xml(enum_factory, ext_factory, struct_factory, filename)
enums = sorted(enum_factory.registry.values(), key=lambda e: e.name)
extensions = sorted(ext_factory.registry.values(), key=lambda e: e.name)
structs = sorted(struct_factory.registry.values(), key=lambda e: e.name)
@ -435,7 +349,6 @@ def main():
with open(file_, 'wb') as f:
f.write(template.render(
file=os.path.basename(__file__),
commands=commands,
enums=enums,
extensions=extensions,
structs=structs,