anv: Separate surface states by layout instead of aux_usage
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 11 Jul 2017 15:53:42 +0000 (08:53 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sun, 23 Jul 2017 04:41:12 +0000 (21:41 -0700)
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/vulkan/anv_descriptor_set.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/genX_cmd_buffer.c

index 4b58b0be95cccacd7b0f69bfff46618f189505fa..91387c065e42ef51b3ba9aee771d584ecbd4c383 100644 (file)
@@ -615,12 +615,9 @@ anv_descriptor_set_write_image_view(struct anv_descriptor_set *set,
 
    *desc = (struct anv_descriptor) {
       .type = type,
+      .layout = info->imageLayout,
       .image_view = image_view,
       .sampler = sampler,
-      .aux_usage = image_view == NULL ? ISL_AUX_USAGE_NONE :
-                   anv_layout_to_aux_usage(devinfo, image_view->image,
-                                           image_view->aspect_mask,
-                                           info->imageLayout),
    };
 }
 
index 70a8c28bacaa502c481a36147b20df64aa5424bc..c7069cff8251802024cf18de126d71d18a0b3480 100644 (file)
@@ -748,54 +748,50 @@ anv_CreateImageView(VkDevice _device,
    if (image->usage & VK_IMAGE_USAGE_SAMPLED_BIT ||
        (image->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT &&
         !(iview->aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT))) {
-      iview->sampler_surface_state = alloc_surface_state(device);
-      iview->no_aux_sampler_surface_state = alloc_surface_state(device);
+      iview->optimal_sampler_surface_state = alloc_surface_state(device);
+      iview->general_sampler_surface_state = alloc_surface_state(device);
 
-      /* Sampling is performed in one of two buffer configurations in anv: with
-       * an auxiliary buffer or without it. Sampler states aren't always needed
-       * for both configurations, but are currently created unconditionally for
-       * simplicity.
-       *
-       * TODO: Consider allocating each surface state only when necessary.
-       */
-
-      /* Create a sampler state with the optimal aux_usage for sampling. This
-       * may use the aux_buffer.
-       */
-      const enum isl_aux_usage surf_usage =
+      iview->general_sampler_aux_usage =
+         anv_layout_to_aux_usage(&device->info, image, iview->aspect_mask,
+                                 VK_IMAGE_LAYOUT_GENERAL);
+      iview->optimal_sampler_aux_usage =
          anv_layout_to_aux_usage(&device->info, image, iview->aspect_mask,
                                  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
 
       /* If this is a HiZ buffer we can sample from with a programmable clear
        * value (SKL+), define the clear value to the optimal constant.
        */
-      const float red_clear_color = surf_usage == ISL_AUX_USAGE_HIZ &&
-                                    device->info.gen >= 9 ?
-                                    ANV_HZ_FC_VAL : 0.0f;
+      union isl_color_value clear_color = { .u32 = { 0, } };
+      if ((iview->aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) &&
+          device->info.gen >= 9)
+         clear_color.f32[0] = ANV_HZ_FC_VAL;
 
       struct isl_view view = iview->isl;
       view.usage |= ISL_SURF_USAGE_TEXTURE_BIT;
+
       isl_surf_fill_state(&device->isl_dev,
-                          iview->sampler_surface_state.map,
+                          iview->optimal_sampler_surface_state.map,
                           .surf = &surface->isl,
                           .view = &view,
-                          .clear_color.f32 = { red_clear_color,},
+                          .clear_color = clear_color,
                           .aux_surf = &image->aux_surface.isl,
-                          .aux_usage = surf_usage,
+                          .aux_usage = iview->optimal_sampler_aux_usage,
                           .mocs = device->default_mocs);
 
-      /* Create a sampler state that only uses the main buffer. */
       isl_surf_fill_state(&device->isl_dev,
-                          iview->no_aux_sampler_surface_state.map,
+                          iview->general_sampler_surface_state.map,
                           .surf = &surface->isl,
                           .view = &view,
+                          .clear_color = clear_color,
+                          .aux_surf = &image->aux_surface.isl,
+                          .aux_usage = iview->general_sampler_aux_usage,
                           .mocs = device->default_mocs);
 
-      anv_state_flush(device, iview->sampler_surface_state);
-      anv_state_flush(device, iview->no_aux_sampler_surface_state);
+      anv_state_flush(device, iview->optimal_sampler_surface_state);
+      anv_state_flush(device, iview->general_sampler_surface_state);
    } else {
-      iview->sampler_surface_state.alloc_size = 0;
-      iview->no_aux_sampler_surface_state.alloc_size = 0;
+      iview->optimal_sampler_surface_state.alloc_size = 0;
+      iview->general_sampler_surface_state.alloc_size = 0;
    }
 
    /* NOTE: This one needs to go last since it may stomp isl_view.format */
@@ -866,14 +862,14 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview,
    if (!iview)
       return;
 
-   if (iview->sampler_surface_state.alloc_size > 0) {
+   if (iview->optimal_sampler_surface_state.alloc_size > 0) {
       anv_state_pool_free(&device->surface_state_pool,
-                          iview->sampler_surface_state);
+                          iview->optimal_sampler_surface_state);
    }
 
-   if (iview->no_aux_sampler_surface_state.alloc_size > 0) {
+   if (iview->general_sampler_surface_state.alloc_size > 0) {
       anv_state_pool_free(&device->surface_state_pool,
-                          iview->no_aux_sampler_surface_state);
+                          iview->general_sampler_surface_state);
    }
 
    if (iview->storage_surface_state.alloc_size > 0) {
index 9bc6db8b88fc55ca887616ca5e99c92f0450bd87..faf784989185fd66c1d3a973fb2cb7dff22d4ebf 100644 (file)
@@ -1077,13 +1077,9 @@ struct anv_descriptor {
 
    union {
       struct {
+         VkImageLayout layout;
          struct anv_image_view *image_view;
          struct anv_sampler *sampler;
-
-         /* Used to determine whether or not we need the surface state to have
-          * the auxiliary buffer enabled.
-          */
-         enum isl_aux_usage aux_usage;
       };
 
       struct {
@@ -2164,14 +2160,19 @@ struct anv_image_view {
    VkFormat vk_format;
    VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
 
-   /** RENDER_SURFACE_STATE when using image as a sampler surface. */
-   struct anv_state sampler_surface_state;
+   /**
+    * RENDER_SURFACE_STATE when using image as a sampler surface with an image
+    * layout of SHADER_READ_ONLY_OPTIMAL or DEPTH_STENCIL_READ_ONLY_OPTIMAL.
+    */
+   enum isl_aux_usage optimal_sampler_aux_usage;
+   struct anv_state optimal_sampler_surface_state;
 
    /**
-    * RENDER_SURFACE_STATE when using image as a sampler surface with the
-    * auxiliary buffer disabled.
+    * RENDER_SURFACE_STATE when using image as a sampler surface with an image
+    * layout of GENERAL.
     */
-   struct anv_state no_aux_sampler_surface_state;
+   enum isl_aux_usage general_sampler_aux_usage;
+   struct anv_state general_sampler_surface_state;
 
    /**
     * RENDER_SURFACE_STATE when using image as a storage image. Separate states
index ad49799c84eca1d116f1cb984c1ea4bc097ca371..280efcc22454f761f06b8bf40fea227ff8c566e8 100644 (file)
@@ -1584,28 +1584,39 @@ emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
          continue;
 
       case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
-      case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
-         surface_state = desc->aux_usage == ISL_AUX_USAGE_NONE ?
-            desc->image_view->no_aux_sampler_surface_state :
-            desc->image_view->sampler_surface_state;
+      case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: {
+         enum isl_aux_usage aux_usage;
+         if (desc->layout == VK_IMAGE_LAYOUT_GENERAL) {
+            surface_state = desc->image_view->general_sampler_surface_state;
+            aux_usage = desc->image_view->general_sampler_aux_usage;
+         } else {
+            surface_state = desc->image_view->optimal_sampler_surface_state;
+            aux_usage = desc->image_view->optimal_sampler_aux_usage;
+         }
          assert(surface_state.alloc_size);
          add_image_relocs(cmd_buffer, desc->image_view->image,
                           desc->image_view->aspect_mask,
-                          desc->aux_usage, surface_state);
+                          aux_usage, surface_state);
          break;
+      }
       case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
          assert(stage == MESA_SHADER_FRAGMENT);
          if (desc->image_view->aspect_mask != VK_IMAGE_ASPECT_COLOR_BIT) {
             /* For depth and stencil input attachments, we treat it like any
              * old texture that a user may have bound.
              */
-            surface_state = desc->aux_usage == ISL_AUX_USAGE_NONE ?
-               desc->image_view->no_aux_sampler_surface_state :
-               desc->image_view->sampler_surface_state;
+            enum isl_aux_usage aux_usage;
+            if (desc->layout == VK_IMAGE_LAYOUT_GENERAL) {
+               surface_state = desc->image_view->general_sampler_surface_state;
+               aux_usage = desc->image_view->general_sampler_aux_usage;
+            } else {
+               surface_state = desc->image_view->optimal_sampler_surface_state;
+               aux_usage = desc->image_view->optimal_sampler_aux_usage;
+            }
             assert(surface_state.alloc_size);
             add_image_relocs(cmd_buffer, desc->image_view->image,
                              desc->image_view->aspect_mask,
-                             desc->aux_usage, surface_state);
+                             aux_usage, surface_state);
          } else {
             /* For color input attachments, we create the surface state at
              * vkBeginRenderPass time so that we can include aux and clear