anv: Add helpers to handle depth buffer layout transitions
authorNanley Chery <nanley.g.chery@intel.com>
Thu, 15 Dec 2016 01:58:41 +0000 (17:58 -0800)
committerNanley Chery <nanley.g.chery@intel.com>
Fri, 13 Jan 2017 04:52:20 +0000 (20:52 -0800)
Signed-off-by: Nanley Chery <nanley.g.chery@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/intel/vulkan/genX_cmd_buffer.c

index 74369f6ba1b5fd476962c05edeefe0440e492612..fff9bd37c0dfdacdff4a43149dc1f43f9185ceca 100644 (file)
@@ -310,6 +310,56 @@ need_input_attachment_state(const struct anv_render_pass_attachment *att)
    return vk_format_is_color(att->format) || vk_format_has_depth(att->format);
 }
 
+static enum isl_aux_usage
+layout_to_hiz_usage(VkImageLayout layout)
+{
+   switch (layout) {
+   case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
+      return ISL_AUX_USAGE_HIZ;
+   default:
+      return ISL_AUX_USAGE_NONE;
+   }
+}
+
+/* Transitions a HiZ-enabled depth buffer from one layout to another. Unless
+ * the initial layout is undefined, the HiZ buffer and depth buffer will
+ * represent the same data at the end of this operation.
+ */
+static void
+transition_depth_buffer(struct anv_cmd_buffer *cmd_buffer,
+                        const struct anv_image *image,
+                        VkImageLayout initial_layout,
+                        VkImageLayout final_layout)
+{
+   assert(image);
+
+   if (image->aux_usage != ISL_AUX_USAGE_HIZ)
+      return;
+
+   const bool hiz_enabled = layout_to_hiz_usage(initial_layout) ==
+                            ISL_AUX_USAGE_HIZ;
+   const bool enable_hiz = layout_to_hiz_usage(final_layout) ==
+                           ISL_AUX_USAGE_HIZ;
+
+   /* We've already initialized the aux HiZ buffer at BindImageMemory time,
+    * so there's no need to perform a HIZ resolve or clear to avoid GPU hangs.
+    * This initial layout indicates that the user doesn't care about the data
+    * that's currently in the buffer, so no resolves are necessary.
+    */
+   if (initial_layout == VK_IMAGE_LAYOUT_UNDEFINED)
+      return;
+
+   if (hiz_enabled == enable_hiz) {
+      /* The same buffer will be used, no resolves are necessary */
+   } else if (hiz_enabled && !enable_hiz) {
+      anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_DEPTH_RESOLVE);
+   } else {
+      assert(!hiz_enabled && enable_hiz);
+      anv_gen8_hiz_op_resolve(cmd_buffer, image, BLORP_HIZ_OP_HIZ_RESOLVE);
+   }
+}
+
+
 /**
  * Setup anv_cmd_state::attachments for vkCmdBeginRenderPass.
  */