[Mesa-dev] [PATCH 3/3] anv: Define trampolines as the weak functions

Lionel Landwerlin lionel.g.landwerlin at intel.com
Fri Oct 19 14:04:30 UTC 2018


Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>

On 15/10/2018 04:47, Jason Ekstrand wrote:
> Instead of having weak references to the anv functions and separate
> trampoline functions with their own dispatch table, just make the
> trampoline functions weak.  This gets rid of a dispatch table and
> potentially lets the compiler delete the unused weak function.  The
> end result is a reduction in the .text section of 5.7K and a reduction
> in the .data section of 1.4K.
>
> Before:
>
>     text	   data	    bss	    dec	    hex	filename
> 3190329	 282232	   8960	3481521	 351fb1	_install/lib64/libvulkan_intel.so
>
> After:
>
>     text	   data	    bss	    dec	    hex	filename
> 3184548	 280792	   8960	3474300	 35037c	_install/lib64/libvulkan_intel.so
> ---
>   src/intel/vulkan/anv_device.c           |  5 +-
>   src/intel/vulkan/anv_entrypoints_gen.py | 65 ++++++++-----------------
>   2 files changed, 21 insertions(+), 49 deletions(-)
>
> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
> index a2551452eb1..f68226217b4 100644
> --- a/src/intel/vulkan/anv_device.c
> +++ b/src/intel/vulkan/anv_device.c
> @@ -653,12 +653,9 @@ VkResult anv_CreateInstance(
>         if (!anv_device_entrypoint_is_enabled(i, instance->app_info.api_version,
>                                               &instance->enabled_extensions, NULL)) {
>            instance->device_dispatch.entrypoints[i] = NULL;
> -      } else if (anv_device_dispatch_table.entrypoints[i] != NULL) {
> -         instance->device_dispatch.entrypoints[i] =
> -            anv_device_dispatch_table.entrypoints[i];
>         } else {
>            instance->device_dispatch.entrypoints[i] =
> -            anv_tramp_device_dispatch_table.entrypoints[i];
> +            anv_device_dispatch_table.entrypoints[i];
>         }
>      }
>   
> diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
> index 25a532fd706..792e3b6c90c 100644
> --- a/src/intel/vulkan/anv_entrypoints_gen.py
> +++ b/src/intel/vulkan/anv_entrypoints_gen.py
> @@ -92,7 +92,6 @@ extern const struct anv_instance_dispatch_table anv_instance_dispatch_table;
>   %for layer in LAYERS:
>   extern const struct anv_device_dispatch_table ${layer}_device_dispatch_table;
>   %endfor
> -extern const struct anv_device_dispatch_table anv_tramp_device_dispatch_table;
>   
>   % for e in instance_entrypoints:
>     % if e.alias:
> @@ -247,7 +246,26 @@ const struct anv_instance_dispatch_table anv_instance_dispatch_table = {
>       % if e.guard is not None:
>   #ifdef ${e.guard}
>       % endif
> -    ${e.return_type} ${e.prefixed_name(layer)}(${e.decl_params()}) __attribute__ ((weak));
> +    % if layer == 'anv':
> +      ${e.return_type} __attribute__ ((weak))
> +      ${e.prefixed_name('anv')}(${e.decl_params()})
> +      {
> +        % if e.params[0].type == 'VkDevice':
> +          ANV_FROM_HANDLE(anv_device, anv_device, ${e.params[0].name});
> +          return anv_device->dispatch.${e.name}(${e.call_params()});
> +        % elif e.params[0].type == 'VkCommandBuffer':
> +          ANV_FROM_HANDLE(anv_cmd_buffer, anv_cmd_buffer, ${e.params[0].name});
> +          return anv_cmd_buffer->device->dispatch.${e.name}(${e.call_params()});
> +        % elif e.params[0].type == 'VkQueue':
> +          ANV_FROM_HANDLE(anv_queue, anv_queue, ${e.params[0].name});
> +          return anv_queue->device->dispatch.${e.name}(${e.call_params()});
> +        % else:
> +          assert(!"Unhandled device child trampoline case: ${e.params[0].type}");
> +        % endif
> +      }
> +    % else:
> +      ${e.return_type} ${e.prefixed_name(layer)}(${e.decl_params()}) __attribute__ ((weak));
> +    % endif
>       % if e.guard is not None:
>   #endif // ${e.guard}
>       % endif
> @@ -267,49 +285,6 @@ const struct anv_instance_dispatch_table anv_instance_dispatch_table = {
>   % endfor
>   
>   
> -/** Trampoline entrypoints for all device functions */
> -
> -% for e in device_entrypoints:
> -  % if e.alias:
> -    <% continue %>
> -  % endif
> -  % if e.guard is not None:
> -#ifdef ${e.guard}
> -  % endif
> -  static ${e.return_type}
> -  ${e.prefixed_name('anv_tramp')}(${e.decl_params()})
> -  {
> -    % if e.params[0].type == 'VkDevice':
> -      ANV_FROM_HANDLE(anv_device, anv_device, ${e.params[0].name});
> -      return anv_device->dispatch.${e.name}(${e.call_params()});
> -    % elif e.params[0].type == 'VkCommandBuffer':
> -      ANV_FROM_HANDLE(anv_cmd_buffer, anv_cmd_buffer, ${e.params[0].name});
> -      return anv_cmd_buffer->device->dispatch.${e.name}(${e.call_params()});
> -    % elif e.params[0].type == 'VkQueue':
> -      ANV_FROM_HANDLE(anv_queue, anv_queue, ${e.params[0].name});
> -      return anv_queue->device->dispatch.${e.name}(${e.call_params()});
> -    % else:
> -      assert(!"Unhandled device child trampoline case: ${e.params[0].type}");
> -    % endif
> -  }
> -  % if e.guard is not None:
> -#endif // ${e.guard}
> -  % endif
> -% endfor
> -
> -const struct anv_device_dispatch_table anv_tramp_device_dispatch_table = {
> -% for e in device_entrypoints:
> -  % if e.guard is not None:
> -#ifdef ${e.guard}
> -  % endif
> -    .${e.name} = ${e.prefixed_name('anv_tramp')},
> -  % if e.guard is not None:
> -#endif // ${e.guard}
> -  % endif
> -% endfor
> -};
> -
> -
>   /** Return true if the core version or extension in which the given entrypoint
>    * is defined is enabled.
>    *




More information about the mesa-dev mailing list