<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Mar 6, 2017 at 10:18 AM, Chad Versace <span dir="ltr"><<a href="mailto:chadversary@chromium.org" target="_blank">chadversary@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Creation of hiz, ccs, and mcs surfaces was encoded by a giant 'if' tree<br>
at the tail of make_surface(). This patch extracts that 'if' tree into<br>
the new functions:<br>
<br>
    make_hiz_surface_maybe()<br>
    make_ccs_surface_maybe()<br>
    make_mcs_surface_maybe()<br></blockquote><div><br></div><div>How about "try_make_hiz_surface"?  _maybe doesn't sit right with me.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
For clarity, also rename make_surface() to make_main_surface().<br>
---<br>
 src/intel/vulkan/anv_image.c | 175 ++++++++++++++++++++++++++----<wbr>-------------<br>
 1 file changed, 107 insertions(+), 68 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c<br>
index 8f4fbd56a16..52a126fe995 100644<br>
--- a/src/intel/vulkan/anv_image.c<br>
+++ b/src/intel/vulkan/anv_image.c<br>
@@ -131,6 +131,106 @@ add_surface(struct anv_image *image, struct anv_surface *surf)<br>
    image->alignment = MAX2(image->alignment, surf->isl.alignment);<br>
 }<br>
<br>
+static void<br>
+make_hiz_surface_maybe(const struct anv_device *dev,<br>
+                       const VkImageCreateInfo *base_info,<br>
+                       struct anv_image *image)<br>
+{<br>
+   bool ok;<br>
+<br>
+   assert(image->aux_surface.isl.<wbr>size == 0);<br>
+   assert(!(image->usage & VK_IMAGE_USAGE_STORAGE_BIT));<br>
+<br>
+   /* Allow the user to control HiZ enabling through environment variables.<br>
+    * Disable by default on gen7 because resolves are not currently<br>
+    * implemented pre-BDW.<br>
+    */<br>
+   if (!(image->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_<wbr>ATTACHMENT_BIT)) {<br>
+      /* It will never be used as an attachment, HiZ is pointless. */<br>
+   } else if (!env_var_as_boolean("INTEL_<wbr>VK_HIZ", dev->info.gen >= 8)) {<br>
+      anv_finishme("Implement gen7 HiZ");<br>
+   } else if (base_info->mipLevels > 1) {<br>
+      anv_finishme("Test multi-LOD HiZ");<br>
+   } else if (base_info->arrayLayers > 1) {<br>
+      anv_finishme("Implement multi-arrayLayer HiZ clears and resolves");<br>
+   } else if (dev->info.gen == 8 && base_info->samples > 1) {<br>
+      anv_finishme("Test gen8 multisampled HiZ");<br>
+   } else {<br>
+      ok = isl_surf_get_hiz_surf(&dev-><wbr>isl_dev, &image->depth_surface.isl,<br>
+                                 &image->aux_surface.isl);<br>
+      assert(ok);<br>
+      add_surface(image, &image->aux_surface);<br>
+      image->aux_usage = ISL_AUX_USAGE_HIZ;<br>
+   }<br>
+}<br>
+<br>
+static void<br>
+make_ccs_surface_maybe(const struct anv_device *dev,<br>
+                       const VkImageCreateInfo *base_info,<br>
+                       struct anv_image *image)<br>
+{<br>
+   bool ok;<br>
+<br>
+   assert(image->aux_surface.isl.<wbr>size == 0);<br>
+<br>
+   if (unlikely(INTEL_DEBUG & DEBUG_NO_RBC))<br>
+      return;<br>
+<br>
+   ok = isl_surf_get_ccs_surf(&dev-><wbr>isl_dev, &image->color_surface.isl,<br>
+                              &image->aux_surface.isl);<br>
+   if (!ok)<br>
+      return;<br>
+<br>
+   add_surface(image, &image->aux_surface);<br>
+<br>
+   /* For images created without MUTABLE_FORMAT_BIT set, we know that they will<br>
+    * always be used with the original format.  In particular, they will always<br>
+    * be used with a format that supports color compression.  If it's never<br>
+    * used as a storage image, then it will only be used through the sampler or<br>
+    * the as a render target.  This means that it's safe to just leave<br>
+    * compression on at all times for these formats.<br>
+    */<br>
+   if (!(base_info->usage & VK_IMAGE_USAGE_STORAGE_BIT) &&<br>
+       !(base_info->flags & VK_IMAGE_CREATE_MUTABLE_<wbr>FORMAT_BIT) &&<br>
+       isl_format_supports_ccs_e(&<wbr>dev->info, image->color_surface.isl.<wbr>format)) {<br>
+      image->aux_usage = ISL_AUX_USAGE_CCS_E;<br>
+   }<br>
+}<br>
+<br>
+static void<br>
+make_mcs_surface_maybe(const struct anv_device *dev,<br>
+                       const VkImageCreateInfo *base_info,<br>
+                       struct anv_image *image)<br>
+{<br>
+   bool ok;<br>
+<br>
+   assert(image->aux_surface.isl.<wbr>size == 0);<br>
+   assert(!(base_info->usage & VK_IMAGE_USAGE_STORAGE_BIT));<br>
+<br>
+   ok = isl_surf_get_mcs_surf(&dev-><wbr>isl_dev, &image->color_surface.isl,<br>
+                              &image->aux_surface.isl);<br>
+   if (!ok)<br>
+      return;<br>
+<br>
+   add_surface(image, &image->aux_surface);<br>
+   image->aux_usage = ISL_AUX_USAGE_MCS;<br>
+}<br>
+<br>
+static void<br>
+make_aux_surface_maybe(const struct anv_device *dev,<br>
+                       const VkImageCreateInfo *base_info,<br>
+                       VkImageAspectFlags aspect,<br>
+                       struct anv_image *image)<br></blockquote><div><br></div><div>This one could probably get inlined below but I think it also makes sense on its own or as part of make_surface.  Whatever...<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+{<br>
+   if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) {<br>
+      make_hiz_surface_maybe(dev, base_info, image);<br>
+   } else if (aspect == VK_IMAGE_ASPECT_COLOR_BIT && base_info->samples == 1) {<br>
+      make_ccs_surface_maybe(dev, base_info, image);<br>
+   } else if (aspect == VK_IMAGE_ASPECT_COLOR_BIT && base_info->samples > 1) {<br>
+      make_mcs_surface_maybe(dev, base_info, image);<br>
+   }<br>
+}<br>
+<br>
 /**<br>
  * Initialize the anv_image::*_surface selected by \a aspect. Then update the<br>
  * image's memory requirements (that is, the image's size and alignment).<br>
@@ -138,10 +238,10 @@ add_surface(struct anv_image *image, struct anv_surface *surf)<br>
  * Exactly one bit must be set in \a aspect.<br>
  */<br>
 static void<br>
-make_surface(const struct anv_device *dev,<br>
-             struct anv_image *image,<br>
-             const struct anv_image_create_info *anv_info,<br>
-             VkImageAspectFlags aspect)<br>
+make_main_surface(const struct anv_device *dev,<br>
+                  const struct anv_image_create_info *anv_info,<br>
+                  VkImageAspectFlags aspect,<br>
+                  struct anv_image *image)<br>
 {<br>
    const VkImageCreateInfo *base_info = anv_info->vk_info;<br>
    bool ok UNUSED;<br>
@@ -182,69 +282,6 @@ make_surface(const struct anv_device *dev,<br>
    assert(ok);<br>
<br>
    add_surface(image, anv_surf);<br>
-<br>
-   /* Add a HiZ surface to a depth buffer that will be used for rendering.<br>
-    */<br>
-   if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) {<br>
-      /* We don't advertise that depth buffers could be used as storage<br>
-       * images.<br>
-       */<br>
-       assert(!(image->usage & VK_IMAGE_USAGE_STORAGE_BIT));<br>
-<br>
-      /* Allow the user to control HiZ enabling. Disable by default on gen7<br>
-       * because resolves are not currently implemented pre-BDW.<br>
-       */<br>
-      if (!(image->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_<wbr>ATTACHMENT_BIT)) {<br>
-         /* It will never be used as an attachment, HiZ is pointless. */<br>
-      } else if (!env_var_as_boolean("INTEL_<wbr>VK_HIZ", dev->info.gen >= 8)) {<br>
-         anv_finishme("Implement gen7 HiZ");<br>
-      } else if (base_info->mipLevels > 1) {<br>
-         anv_finishme("Test multi-LOD HiZ");<br>
-      } else if (base_info->arrayLayers > 1) {<br>
-         anv_finishme("Implement multi-arrayLayer HiZ clears and resolves");<br>
-      } else if (dev->info.gen == 8 && base_info->samples > 1) {<br>
-         anv_finishme("Test gen8 multisampled HiZ");<br>
-      } else {<br>
-         assert(image->aux_surface.isl.<wbr>size == 0);<br>
-         ok = isl_surf_get_hiz_surf(&dev-><wbr>isl_dev, &image->depth_surface.isl,<br>
-                                    &image->aux_surface.isl);<br>
-         assert(ok);<br>
-         add_surface(image, &image->aux_surface);<br>
-         image->aux_usage = ISL_AUX_USAGE_HIZ;<br>
-      }<br>
-   } else if (aspect == VK_IMAGE_ASPECT_COLOR_BIT && base_info->samples == 1) {<br>
-      if (!unlikely(INTEL_DEBUG & DEBUG_NO_RBC)) {<br>
-         assert(image->aux_surface.isl.<wbr>size == 0);<br>
-         ok = isl_surf_get_ccs_surf(&dev-><wbr>isl_dev, &anv_surf->isl,<br>
-                                    &image->aux_surface.isl);<br>
-         if (ok) {<br>
-            add_surface(image, &image->aux_surface);<br>
-<br>
-            /* For images created without MUTABLE_FORMAT_BIT set, we know that<br>
-             * they will always be used with the original format.  In<br>
-             * particular, they will always be used with a format that<br>
-             * supports color compression.  If it's never used as a storage<br>
-             * image, then it will only be used through the sampler or the as<br>
-             * a render target.  This means that it's safe to just leave<br>
-             * compression on at all times for these formats.<br>
-             */<br>
-            if (!(base_info->usage & VK_IMAGE_USAGE_STORAGE_BIT) &&<br>
-                !(base_info->flags & VK_IMAGE_CREATE_MUTABLE_<wbr>FORMAT_BIT) &&<br>
-                isl_format_supports_ccs_e(&<wbr>dev->info, format)) {<br>
-               image->aux_usage = ISL_AUX_USAGE_CCS_E;<br>
-            }<br>
-         }<br>
-      }<br>
-   } else if (aspect == VK_IMAGE_ASPECT_COLOR_BIT && base_info->samples > 1) {<br>
-      assert(image->aux_surface.isl.<wbr>size == 0);<br>
-      assert(!(base_info->usage & VK_IMAGE_USAGE_STORAGE_BIT));<br>
-      ok = isl_surf_get_mcs_surf(&dev-><wbr>isl_dev, &anv_surf->isl,<br>
-                                 &image->aux_surface.isl);<br>
-      if (ok) {<br>
-         add_surface(image, &image->aux_surface);<br>
-         image->aux_usage = ISL_AUX_USAGE_MCS;<br>
-      }<br>
-   }<br>
 }<br>
<br>
 VkResult<br>
@@ -285,7 +322,9 @@ anv_image_create(VkDevice _device,<br>
<br>
    uint32_t b;<br>
    for_each_bit(b, image->aspects) {<br>
-      make_surface(device, image, anv_info, (1 << b));<br>
+      VkImageAspectFlagBits aspect = 1 << b;<br>
+      make_main_surface(device, anv_info, aspect, image);<br>
+      make_aux_surface_maybe(device, base_info, aspect, image);<br>
    }<br>
<br>
    *pImage = anv_image_to_handle(image);<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.12.0<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>
</font></span></blockquote></div><br></div></div>