<div dir="ltr"><div>As a side-note, I pushed code on Friday that gets rid of two of these (the create_pipeline calls). I think the best way to solve emit_state_base_address is by moving a bit of code into genX_cmd_buffer.c. null surface states probably need to be moved into ISL.<br><br></div>In other words, while it's a nice cleanup, I think the correct answer for almost all cases is to just stop doing the switches.<br><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 17, 2016 at 8:51 AM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Wednesday, October 12, 2016 11:28:04 PM PDT Lionel Landwerlin wrote:<br>
> Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a><wbr>><br>
> ---<br>
> src/intel/vulkan/anv_cmd_<wbr>buffer.c | 33 ++++++------------------------<wbr>---<br>
> src/intel/vulkan/anv_device.c | 19 +------------------<br>
> src/intel/vulkan/anv_pipeline.<wbr>c | 30 ++++--------------------------<br>
> src/intel/vulkan/anv_private.h | 23 +++++++++++++++++++++++<br>
> 4 files changed, 34 insertions(+), 71 deletions(-)<br>
><br>
> diff --git a/src/intel/vulkan/anv_cmd_<wbr>buffer.c b/src/intel/vulkan/anv_cmd_<wbr>buffer.c<br>
> index 5bcd5e0..b051489 100644<br>
> --- a/src/intel/vulkan/anv_cmd_<wbr>buffer.c<br>
> +++ b/src/intel/vulkan/anv_cmd_<wbr>buffer.c<br>
> @@ -356,19 +356,9 @@ VkResult anv_ResetCommandBuffer(<br>
> void<br>
> anv_cmd_buffer_emit_state_<wbr>base_address(struct anv_cmd_buffer *cmd_buffer)<br>
> {<br>
> - switch (cmd_buffer->device->info.gen) {<br>
> - case 7:<br>
> - if (cmd_buffer->device->info.is_<wbr>haswell)<br>
> - return gen75_cmd_buffer_emit_state_<wbr>base_address(cmd_buffer);<br>
> - else<br>
> - return gen7_cmd_buffer_emit_state_<wbr>base_address(cmd_buffer);<br>
> - case 8:<br>
> - return gen8_cmd_buffer_emit_state_<wbr>base_address(cmd_buffer);<br>
> - case 9:<br>
> - return gen9_cmd_buffer_emit_state_<wbr>base_address(cmd_buffer);<br>
> - default:<br>
> - unreachable("unsupported gen\n");<br>
> - }<br>
> + ANV_GEN_DISPATCH(cmd_buffer-><wbr>device,<br>
> + cmd_buffer_emit_state_base_<wbr>address,<br>
> + cmd_buffer);<br>
> }<br>
><br>
> VkResult anv_BeginCommandBuffer(<br>
> @@ -714,20 +704,9 @@ static struct anv_state<br>
> anv_cmd_buffer_alloc_null_<wbr>surface_state(struct anv_cmd_buffer *cmd_buffer,<br>
> struct anv_framebuffer *fb)<br>
> {<br>
> - switch (cmd_buffer->device->info.gen) {<br>
> - case 7:<br>
> - if (cmd_buffer->device->info.is_<wbr>haswell) {<br>
> - return gen75_cmd_buffer_alloc_null_<wbr>surface_state(cmd_buffer, fb);<br>
> - } else {<br>
> - return gen7_cmd_buffer_alloc_null_<wbr>surface_state(cmd_buffer, fb);<br>
> - }<br>
> - case 8:<br>
> - return gen8_cmd_buffer_alloc_null_<wbr>surface_state(cmd_buffer, fb);<br>
> - case 9:<br>
> - return gen9_cmd_buffer_alloc_null_<wbr>surface_state(cmd_buffer, fb);<br>
> - default:<br>
> - unreachable("Invalid hardware generation");<br>
> - }<br>
> + return ANV_GEN_DISPATCH(cmd_buffer-><wbr>device,<br>
> + cmd_buffer_alloc_null_surface_<wbr>state,<br>
> + cmd_buffer, fb);<br>
> }<br>
><br>
> VkResult<br>
> diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
> index 24f7227..6dfdfdb 100644<br>
> --- a/src/intel/vulkan/anv_device.<wbr>c<br>
> +++ b/src/intel/vulkan/anv_device.<wbr>c<br>
> @@ -921,24 +921,7 @@ VkResult anv_CreateDevice(<br>
><br>
> anv_queue_init(device, &device->queue);<br>
><br>
> - switch (device->info.gen) {<br>
> - case 7:<br>
> - if (!device->info.is_haswell)<br>
> - result = gen7_init_device_state(device)<wbr>;<br>
> - else<br>
> - result = gen75_init_device_state(<wbr>device);<br>
> - break;<br>
> - case 8:<br>
> - result = gen8_init_device_state(device)<wbr>;<br>
> - break;<br>
> - case 9:<br>
> - result = gen9_init_device_state(device)<wbr>;<br>
> - break;<br>
> - default:<br>
> - /* Shouldn't get here as we don't create physical devices for any other<br>
> - * gens. */<br>
> - unreachable("unhandled gen");<br>
> - }<br>
> + result = ANV_GEN_DISPATCH(device, init_device_state, device);<br>
> if (result != VK_SUCCESS)<br>
> goto fail_fd;<br>
><br>
> diff --git a/src/intel/vulkan/anv_<wbr>pipeline.c b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> index 6b393a6..f9f1cbf 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> +++ b/src/intel/vulkan/anv_<wbr>pipeline.c<br>
> @@ -1182,19 +1182,8 @@ anv_graphics_pipeline_create(<br>
> ANV_FROM_HANDLE(anv_device, device, _device);<br>
> ANV_FROM_HANDLE(anv_pipeline_<wbr>cache, cache, _cache);<br>
><br>
> - switch (device->info.gen) {<br>
> - case 7:<br>
> - if (device->info.is_haswell)<br>
> - return gen75_graphics_pipeline_<wbr>create(_device, cache, pCreateInfo, extra, pAllocator, pPipeline);<br>
> - else<br>
> - return gen7_graphics_pipeline_create(<wbr>_device, cache, pCreateInfo, extra, pAllocator, pPipeline);<br>
> - case 8:<br>
> - return gen8_graphics_pipeline_create(<wbr>_device, cache, pCreateInfo, extra, pAllocator, pPipeline);<br>
> - case 9:<br>
> - return gen9_graphics_pipeline_create(<wbr>_device, cache, pCreateInfo, extra, pAllocator, pPipeline);<br>
> - default:<br>
> - unreachable("unsupported gen\n");<br>
> - }<br>
> + return ANV_GEN_DISPATCH(device, graphics_pipeline_create,<br>
> + _device, cache, pCreateInfo, extra, pAllocator, pPipeline);<br>
> }<br>
><br>
> VkResult anv_CreateGraphicsPipelines(<br>
> @@ -1235,19 +1224,8 @@ static VkResult anv_compute_pipeline_create(<br>
> ANV_FROM_HANDLE(anv_device, device, _device);<br>
> ANV_FROM_HANDLE(anv_pipeline_<wbr>cache, cache, _cache);<br>
><br>
> - switch (device->info.gen) {<br>
> - case 7:<br>
> - if (device->info.is_haswell)<br>
> - return gen75_compute_pipeline_create(<wbr>_device, cache, pCreateInfo, pAllocator, pPipeline);<br>
> - else<br>
> - return gen7_compute_pipeline_create(_<wbr>device, cache, pCreateInfo, pAllocator, pPipeline);<br>
> - case 8:<br>
> - return gen8_compute_pipeline_create(_<wbr>device, cache, pCreateInfo, pAllocator, pPipeline);<br>
> - case 9:<br>
> - return gen9_compute_pipeline_create(_<wbr>device, cache, pCreateInfo, pAllocator, pPipeline);<br>
> - default:<br>
> - unreachable("unsupported gen\n");<br>
> - }<br>
> + return ANV_GEN_DISPATCH(device, compute_pipeline_create,<br>
> + _device, cache, pCreateInfo, pAllocator, pPipeline);<br>
> }<br>
><br>
> VkResult anv_CreateComputePipelines(<br>
> diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
> index 0705263..27ae5e88 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>private.h<br>
> +++ b/src/intel/vulkan/anv_<wbr>private.h<br>
> @@ -1994,6 +1994,29 @@ ANV_DEFINE_STRUCT_CASTS(anv_<wbr>common, VkMemoryBarrier)<br>
> ANV_DEFINE_STRUCT_CASTS(anv_<wbr>common, VkBufferMemoryBarrier)<br>
> ANV_DEFINE_STRUCT_CASTS(anv_<wbr>common, VkImageMemoryBarrier)<br>
><br>
> +#define ANV_GEN_DISPATCH(device, name, ...) \<br>
> + ({ \<br>
> + __typeof(gen7_ ## name)* __func = NULL; \<br>
> + switch ((device)->info.gen) { \<br>
> + case 7: \<br>
> + if ((device)->info.is_haswell) { \<br>
> + __func = gen75_ ## name; \<br>
> + } else { \<br>
> + __func = gen7_ ## name; \<br>
> + } \<br>
> + break; \<br>
> + case 8: \<br>
> + __func = gen8_ ## name; \<br>
> + break; \<br>
> + case 9: \<br>
> + __func = gen9_ ## name; \<br>
> + break; \<br>
> + default: \<br>
> + unreachable("unhandled gen"); \<br>
> + }; \<br>
> + __func( __VA_ARGS__); \<br>
> + })<br>
> +<br>
> /* Gen-specific function declarations */<br>
> #ifdef genX<br>
> # include "anv_genX.h"<br>
><br>
<br>
</div></div>How does the generated assembly look now compared to before this patch?<br>
I don't have a good sense of whether the compiler can eliminate the<br>
function pointer or not.<br>
<br>
Assuming the compiler is able to generate sensible code for this,<br>
it looks great.<br>
<br>______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
<br></blockquote></div><br></div></div></div></div>