anv/cmd_buffer: Centralize automatic layout transitions
authorNanley Chery <nanley.g.chery@intel.com>
Thu, 23 Feb 2017 20:11:58 +0000 (12:11 -0800)
committerNanley Chery <nanley.g.chery@intel.com>
Thu, 2 Mar 2017 21:17:55 +0000 (13:17 -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 0249999b34fef070cd8b548d49c609bba209a0b4..ae153d23f80c17983631c2c9709fab42980d9203 100644 (file)
@@ -2445,21 +2445,10 @@ genX(cmd_buffer_set_subpass)(struct anv_cmd_buffer *cmd_buffer,
 
    cmd_buffer->state.dirty |= ANV_CMD_DIRTY_RENDER_TARGETS;
 
-   const struct anv_image_view *iview =
-      anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
-
-   if (iview && iview->image->aux_usage == ISL_AUX_USAGE_HIZ) {
-      const uint32_t ds = subpass->depth_stencil_attachment.attachment;
-      transition_depth_buffer(cmd_buffer, iview->image,
-                              cmd_buffer->state.attachments[ds].current_layout,
-                              cmd_buffer->state.subpass->depth_stencil_attachment.layout);
-      cmd_buffer->state.attachments[ds].current_layout =
-         cmd_buffer->state.subpass->depth_stencil_attachment.layout;
-      cmd_buffer->state.attachments[ds].aux_usage =
-         anv_layout_to_aux_usage(&cmd_buffer->device->info, iview->image,
-            iview->aspect_mask,
-            cmd_buffer->state.subpass->depth_stencil_attachment.layout);
-   }
+   /* Perform transitions to the subpass layout before any writes have
+    * occurred.
+    */
+   cmd_buffer_subpass_transition_layouts(cmd_buffer, false);
 
    cmd_buffer_emit_depth_stencil(cmd_buffer);
 
@@ -2493,21 +2482,12 @@ void genX(CmdNextSubpass)(
 
    assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY);
 
-   const struct anv_image_view *iview =
-      anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
-
-   if (iview && iview->image->aux_usage == ISL_AUX_USAGE_HIZ) {
-      const uint32_t ds = cmd_buffer->state.subpass->depth_stencil_attachment.attachment;
+   anv_cmd_buffer_resolve_subpass(cmd_buffer);
 
-      if (cmd_buffer->state.subpass - cmd_buffer->state.pass->subpasses ==
-          cmd_buffer->state.pass->attachments[ds].last_subpass_idx) {
-         transition_depth_buffer(cmd_buffer, iview->image,
-                                 cmd_buffer->state.attachments[ds].current_layout,
-                                 cmd_buffer->state.pass->attachments[ds].final_layout);
-      }
-   }
+   /* Perform transitions to the final layout after all writes have occurred.
+    */
+   cmd_buffer_subpass_transition_layouts(cmd_buffer, true);
 
-   anv_cmd_buffer_resolve_subpass(cmd_buffer);
    genX(cmd_buffer_set_subpass)(cmd_buffer, cmd_buffer->state.subpass + 1);
 }
 
@@ -2516,22 +2496,12 @@ void genX(CmdEndRenderPass)(
 {
    ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
 
-   const struct anv_image_view *iview =
-      anv_cmd_buffer_get_depth_stencil_view(cmd_buffer);
-
-   if (iview && iview->image->aux_usage == ISL_AUX_USAGE_HIZ) {
-      const uint32_t ds = cmd_buffer->state.subpass->depth_stencil_attachment.attachment;
-
-      if (cmd_buffer->state.subpass - cmd_buffer->state.pass->subpasses ==
-          cmd_buffer->state.pass->attachments[ds].last_subpass_idx) {
-         transition_depth_buffer(cmd_buffer, iview->image,
-                                 cmd_buffer->state.attachments[ds].current_layout,
-                                 cmd_buffer->state.pass->attachments[ds].final_layout);
-      }
-   }
-
    anv_cmd_buffer_resolve_subpass(cmd_buffer);
 
+   /* Perform transitions to the final layout after all writes have occurred.
+    */
+   cmd_buffer_subpass_transition_layouts(cmd_buffer, true);
+
    cmd_buffer->state.hiz_enabled = false;
 
 #ifndef NDEBUG