anv/state: Refactor surface state setup into a "fill" function
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 22 Jan 2016 19:40:56 +0000 (11:40 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 22 Jan 2016 19:40:56 +0000 (11:40 -0800)
src/vulkan/gen7_state.c
src/vulkan/gen8_state.c

index aecdfe2fe4d36692732cd675b1aee2998ea0f1b2..2d16bf3861b93220819caad848c6ae2b14e9ecbc 100644 (file)
@@ -148,11 +148,11 @@ static const uint8_t anv_valign[] = {
     [4] = VALIGN_4,
 };
 
-static struct GENX(RENDER_SURFACE_STATE)
-surface_state_for_image_view(struct anv_image_view *iview,
-                             struct anv_device *device,
-                             const VkImageViewCreateInfo *pCreateInfo,
-                             VkImageUsageFlagBits usage)
+static void
+genX(fill_image_surface_state)(struct anv_device *device, void *state_map,
+                               struct anv_image_view *iview,
+                               const VkImageViewCreateInfo *pCreateInfo,
+                               VkImageUsageFlagBits usage)
 {
    assert(usage & (VK_IMAGE_USAGE_SAMPLED_BIT |
                    VK_IMAGE_USAGE_STORAGE_BIT |
@@ -248,7 +248,10 @@ surface_state_for_image_view(struct anv_image_view *iview,
       template.MIPCountLOD = MAX2(range->levelCount, 1) - 1;
    }
 
-   return template;
+   GENX(RENDER_SURFACE_STATE_pack)(NULL, state_map, &template);
+
+   if (!device->info.has_llc)
+      anv_state_clflush(iview->nonrt_surface_state);
 }
 
 GENX_FUNC(GEN7, GEN75) void
@@ -263,47 +266,31 @@ genX(image_view_init)(struct anv_image_view *iview,
       anv_finishme("non-2D image views");
 
    if (image->needs_nonrt_surface_state) {
-      struct GENX(RENDER_SURFACE_STATE) surface_state =
-         surface_state_for_image_view(iview, device, pCreateInfo,
-                                      VK_IMAGE_USAGE_SAMPLED_BIT);
-
       iview->nonrt_surface_state = alloc_surface_state(device, cmd_buffer);
 
-      GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->nonrt_surface_state.map,
-                                      &surface_state);
-
-      if (!device->info.has_llc)
-         anv_state_clflush(iview->nonrt_surface_state);
+      genX(fill_image_surface_state)(device, iview->nonrt_surface_state.map,
+                                     iview, pCreateInfo,
+                                     VK_IMAGE_USAGE_SAMPLED_BIT);
    } else {
       iview->nonrt_surface_state.alloc_size = 0;
    }
 
    if (image->needs_color_rt_surface_state) {
-      struct GENX(RENDER_SURFACE_STATE) surface_state =
-         surface_state_for_image_view(iview, device, pCreateInfo,
-                                      VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
-
       iview->color_rt_surface_state = alloc_surface_state(device, cmd_buffer);
 
-      GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->color_rt_surface_state.map,
-                                      &surface_state);
-      if (!device->info.has_llc)
-         anv_state_clflush(iview->color_rt_surface_state);
+      genX(fill_image_surface_state)(device, iview->color_rt_surface_state.map,
+                                     iview, pCreateInfo,
+                                     VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
    } else {
       iview->color_rt_surface_state.alloc_size = 0;
    }
 
    if (image->needs_storage_surface_state) {
-      struct GENX(RENDER_SURFACE_STATE) surface_state =
-         surface_state_for_image_view(iview, device, pCreateInfo,
-                                      VK_IMAGE_USAGE_STORAGE_BIT);
-
       iview->storage_surface_state = alloc_surface_state(device, cmd_buffer);
 
-      GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->storage_surface_state.map,
-                                      &surface_state);
-      if (!device->info.has_llc)
-         anv_state_clflush(iview->storage_surface_state);
+      genX(fill_image_surface_state)(device, iview->storage_surface_state.map,
+                                     iview, pCreateInfo,
+                                     VK_IMAGE_USAGE_STORAGE_BIT);
    } else {
       iview->storage_surface_state.alloc_size = 0;
    }
index 9fad7961b3fe2fc8e2c971e7fd6cff298b46acf5..15bf0ffe4ac6c334dcb3b3055bfe8ad2d0548280 100644 (file)
@@ -162,11 +162,11 @@ get_qpitch(const struct isl_surf *surf)
    }
 }
 
-static struct GENX(RENDER_SURFACE_STATE)
-surface_state_for_image_view(struct anv_image_view *iview,
-                             struct anv_device *device,
-                             const VkImageViewCreateInfo *pCreateInfo,
-                             VkImageUsageFlagBits usage)
+static void
+genX(fill_image_surface_state)(struct anv_device *device, void *state_map,
+                               struct anv_image_view *iview,
+                               const VkImageViewCreateInfo *pCreateInfo,
+                               VkImageUsageFlagBits usage)
 {
    assert(usage & (VK_IMAGE_USAGE_SAMPLED_BIT |
                    VK_IMAGE_USAGE_STORAGE_BIT |
@@ -319,7 +319,10 @@ surface_state_for_image_view(struct anv_image_view *iview,
       template.MIPCountLOD = MAX2(range->levelCount, 1) - 1;
    }
 
-   return template;
+   GENX(RENDER_SURFACE_STATE_pack)(NULL, state_map, &template);
+
+   if (!device->info.has_llc)
+      anv_state_clflush(iview->nonrt_surface_state);
 }
 
 void
@@ -331,49 +334,34 @@ genX(image_view_init)(struct anv_image_view *iview,
    ANV_FROM_HANDLE(anv_image, image, pCreateInfo->image);
 
    if (image->needs_nonrt_surface_state) {
-      const struct GENX(RENDER_SURFACE_STATE) surface_state =
-         surface_state_for_image_view(iview, device, pCreateInfo,
-                                      VK_IMAGE_USAGE_SAMPLED_BIT);
-
       iview->nonrt_surface_state =
          alloc_surface_state(device, cmd_buffer);
 
-      GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->nonrt_surface_state.map,
-                                      &surface_state);
-      if (!device->info.has_llc)
-         anv_state_clflush(iview->nonrt_surface_state);
+      genX(fill_image_surface_state)(device, iview->nonrt_surface_state.map,
+                                     iview, pCreateInfo,
+                                     VK_IMAGE_USAGE_SAMPLED_BIT);
    } else {
       iview->nonrt_surface_state.alloc_size = 0;
    }
 
    if (image->needs_color_rt_surface_state) {
-      const struct GENX(RENDER_SURFACE_STATE) surface_state =
-         surface_state_for_image_view(iview, device, pCreateInfo,
-                                      VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
-
       iview->color_rt_surface_state =
          alloc_surface_state(device, cmd_buffer);
 
-      GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->color_rt_surface_state.map,
-                                      &surface_state);
-      if (!device->info.has_llc)
-         anv_state_clflush(iview->color_rt_surface_state);
+      genX(fill_image_surface_state)(device, iview->color_rt_surface_state.map,
+                                     iview, pCreateInfo,
+                                     VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
    } else {
       iview->color_rt_surface_state.alloc_size = 0;
    }
 
    if (image->needs_storage_surface_state) {
-      struct GENX(RENDER_SURFACE_STATE) surface_state =
-         surface_state_for_image_view(iview, device, pCreateInfo,
-                                      VK_IMAGE_USAGE_STORAGE_BIT);
-
       iview->storage_surface_state =
          alloc_surface_state(device, cmd_buffer);
 
-      GENX(RENDER_SURFACE_STATE_pack)(NULL, iview->storage_surface_state.map,
-                                      &surface_state);
-      if (!device->info.has_llc)
-         anv_state_clflush(iview->storage_surface_state);
+      genX(fill_image_surface_state)(device, iview->storage_surface_state.map,
+                                     iview, pCreateInfo,
+                                     VK_IMAGE_USAGE_STORAGE_BIT);
    } else {
       iview->storage_surface_state.alloc_size = 0;
    }