From 77c50891b65a98fda392d83aba188e9bcace6381 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 17 Jun 2020 13:42:15 -0500 Subject: anv: Use resolve_device_entrypoint for dispatch init There's no good reason to have the "which table do I use?" code duplicated twice. The only advantage to the way we were doing it before was that we could move the switch statement outside the loop. If this is ever an actual device initialization perf problem that someone cares about, we can optimize that when the time comes. For now, the duplicated cases are simply a platform-enabling pit-fall. Reviewed-by: Jordan Justen Part-of: --- src/intel/vulkan/anv_device.c | 64 ++++++++------------------------- src/intel/vulkan/anv_entrypoints_gen.py | 2 +- src/intel/vulkan/anv_private.h | 2 ++ 3 files changed, 17 insertions(+), 51 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 9bb535749b9..97d0088bd90 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -2491,55 +2491,6 @@ VkResult anv_EnumerateDeviceExtensionProperties( return vk_outarray_status(&out); } -static void -anv_device_init_dispatch(struct anv_device *device) -{ - const struct anv_instance *instance = device->physical->instance; - - const struct anv_device_dispatch_table *genX_table; - switch (device->info.gen) { - case 12: - genX_table = &gen12_device_dispatch_table; - break; - case 11: - genX_table = &gen11_device_dispatch_table; - break; - case 10: - genX_table = &gen10_device_dispatch_table; - break; - case 9: - genX_table = &gen9_device_dispatch_table; - break; - case 8: - genX_table = &gen8_device_dispatch_table; - break; - case 7: - if (device->info.is_haswell) - genX_table = &gen75_device_dispatch_table; - else - genX_table = &gen7_device_dispatch_table; - break; - default: - unreachable("unsupported gen\n"); - } - - for (unsigned i = 0; i < ARRAY_SIZE(device->dispatch.entrypoints); i++) { - /* Vulkan requires that entrypoints for extensions which have not been - * enabled must not be advertised. - */ - if (!anv_device_entrypoint_is_enabled(i, instance->app_info.api_version, - &instance->enabled_extensions, - &device->enabled_extensions)) { - device->dispatch.entrypoints[i] = NULL; - } else if (genX_table->entrypoints[i]) { - device->dispatch.entrypoints[i] = genX_table->entrypoints[i]; - } else { - device->dispatch.entrypoints[i] = - anv_device_dispatch_table.entrypoints[i]; - } - } -} - static int vk_priority_to_gen(int priority) { @@ -2869,7 +2820,20 @@ VkResult anv_CreateDevice( device->robust_buffer_access = robust_buffer_access; device->enabled_extensions = enabled_extensions; - anv_device_init_dispatch(device); + const struct anv_instance *instance = physical_device->instance; + for (unsigned i = 0; i < ARRAY_SIZE(device->dispatch.entrypoints); i++) { + /* Vulkan requires that entrypoints for extensions which have not been + * enabled must not be advertised. + */ + if (!anv_device_entrypoint_is_enabled(i, instance->app_info.api_version, + &instance->enabled_extensions, + &device->enabled_extensions)) { + device->dispatch.entrypoints[i] = NULL; + } else { + device->dispatch.entrypoints[i] = + anv_resolve_device_entrypoint(&device->info, i); + } + } if (pthread_mutex_init(&device->mutex, NULL) != 0) { result = vk_error(VK_ERROR_INITIALIZATION_FAILED); diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py index fc2ee097961..ff166186a0b 100644 --- a/src/intel/vulkan/anv_entrypoints_gen.py +++ b/src/intel/vulkan/anv_entrypoints_gen.py @@ -513,7 +513,7 @@ anv_get_device_entry_name(int index) return device_entry_name(index); } -static void * __attribute__ ((noinline)) +void * __attribute__ ((noinline)) anv_resolve_device_entrypoint(const struct gen_device_info *devinfo, uint32_t index) { const struct anv_device_dispatch_table *genX_table; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 884396089ee..a6104bdcfa1 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -4327,6 +4327,8 @@ anv_device_entrypoint_is_enabled(int index, uint32_t core_version, const struct anv_instance_extension_table *instance, const struct anv_device_extension_table *device); +void *anv_resolve_device_entrypoint(const struct gen_device_info *devinfo, + uint32_t index); void *anv_lookup_entrypoint(const struct gen_device_info *devinfo, const char *name); -- cgit v1.2.3