[Mesa-dev] [PATCH 4/5] anv: add dispatch macro to find right function for given generation

Lionel Landwerlin llandwerlin at gmail.com
Mon Oct 17 15:46:58 UTC 2016


Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
---
 src/intel/vulkan/anv_cmd_buffer.c | 33 ++++++---------------------------
 src/intel/vulkan/anv_device.c     | 19 +------------------
 src/intel/vulkan/anv_private.h    | 23 +++++++++++++++++++++++
 3 files changed, 30 insertions(+), 45 deletions(-)

diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c
index 5bcd5e0..b051489 100644
--- a/src/intel/vulkan/anv_cmd_buffer.c
+++ b/src/intel/vulkan/anv_cmd_buffer.c
@@ -356,19 +356,9 @@ VkResult anv_ResetCommandBuffer(
 void
 anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer)
 {
-   switch (cmd_buffer->device->info.gen) {
-   case 7:
-      if (cmd_buffer->device->info.is_haswell)
-         return gen75_cmd_buffer_emit_state_base_address(cmd_buffer);
-      else
-         return gen7_cmd_buffer_emit_state_base_address(cmd_buffer);
-   case 8:
-      return gen8_cmd_buffer_emit_state_base_address(cmd_buffer);
-   case 9:
-      return gen9_cmd_buffer_emit_state_base_address(cmd_buffer);
-   default:
-      unreachable("unsupported gen\n");
-   }
+   ANV_GEN_DISPATCH(cmd_buffer->device,
+                    cmd_buffer_emit_state_base_address,
+                    cmd_buffer);
 }
 
 VkResult anv_BeginCommandBuffer(
@@ -714,20 +704,9 @@ static struct anv_state
 anv_cmd_buffer_alloc_null_surface_state(struct anv_cmd_buffer *cmd_buffer,
                                         struct anv_framebuffer *fb)
 {
-   switch (cmd_buffer->device->info.gen) {
-   case 7:
-      if (cmd_buffer->device->info.is_haswell) {
-         return gen75_cmd_buffer_alloc_null_surface_state(cmd_buffer, fb);
-      } else {
-         return gen7_cmd_buffer_alloc_null_surface_state(cmd_buffer, fb);
-      }
-   case 8:
-      return gen8_cmd_buffer_alloc_null_surface_state(cmd_buffer, fb);
-   case 9:
-      return gen9_cmd_buffer_alloc_null_surface_state(cmd_buffer, fb);
-   default:
-      unreachable("Invalid hardware generation");
-   }
+   return ANV_GEN_DISPATCH(cmd_buffer->device,
+                           cmd_buffer_alloc_null_surface_state,
+                           cmd_buffer, fb);
 }
 
 VkResult
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 53b9b1b..ce1b9c1 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -920,24 +920,7 @@ VkResult anv_CreateDevice(
 
    anv_queue_init(device, &device->queue);
 
-   switch (device->info.gen) {
-   case 7:
-      if (!device->info.is_haswell)
-         result = gen7_init_device_state(device);
-      else
-         result = gen75_init_device_state(device);
-      break;
-   case 8:
-      result = gen8_init_device_state(device);
-      break;
-   case 9:
-      result = gen9_init_device_state(device);
-      break;
-   default:
-      /* Shouldn't get here as we don't create physical devices for any other
-       * gens. */
-      unreachable("unhandled gen");
-   }
+   result = ANV_GEN_DISPATCH(device, init_device_state, device);
    if (result != VK_SUCCESS)
       goto fail_fd;
 
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index c9d102d..69e6aac 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1873,6 +1873,29 @@ ANV_DEFINE_STRUCT_CASTS(anv_common, VkMemoryBarrier)
 ANV_DEFINE_STRUCT_CASTS(anv_common, VkBufferMemoryBarrier)
 ANV_DEFINE_STRUCT_CASTS(anv_common, VkImageMemoryBarrier)
 
+#define ANV_GEN_DISPATCH(device, name, ...)      \
+   ({                                            \
+      __typeof(gen7_ ## name)* __func = NULL;    \
+      switch ((device)->info.gen) {              \
+      case 7:                                    \
+         if ((device)->info.is_haswell) {        \
+            __func = gen75_ ## name;             \
+         } else {                                \
+            __func = gen7_ ## name;              \
+         }                                       \
+         break;                                  \
+      case 8:                                    \
+         __func = gen8_ ## name;                 \
+         break;                                  \
+      case 9:                                    \
+         __func = gen9_ ## name;                 \
+         break;                                  \
+      default:                                   \
+         unreachable("unhandled gen");           \
+      };                                         \
+      __func( __VA_ARGS__);                      \
+   })
+
 /* Gen-specific function declarations */
 #ifdef genX
 #  include "anv_genX.h"
-- 
2.9.3



More information about the mesa-dev mailing list