turnip: MSAA resolve directly from GMEM
authorJonathan Marek <jonathan@marek.ca>
Fri, 22 Nov 2019 23:25:43 +0000 (18:25 -0500)
committerJonathan Marek <jonathan@marek.ca>
Wed, 4 Dec 2019 19:39:06 +0000 (14:39 -0500)
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/freedreno/vulkan/tu_cmd_buffer.c
src/freedreno/vulkan/tu_pass.c
src/freedreno/vulkan/tu_private.h

index 6ad18f18aa77f352648c821de14a6fbe7cc5fb3c..91baac6f7ec69b2d439f73ff9f244a2a253bc523 100644 (file)
@@ -814,11 +814,29 @@ tu6_emit_tile_load(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
       tu6_emit_tile_load_attachment(cmd, cs, a, subpass->color_count);
 }
 
+static void
+tu6_emit_store_attachment(struct tu_cmd_buffer *cmd,
+                          struct tu_cs *cs,
+                          uint32_t a,
+                          uint32_t gmem_index)
+{
+   const struct tu_framebuffer *fb = cmd->state.framebuffer;
+   const struct tu_tiling_config *tiling = &cmd->state.tiling_config;
+
+   if (a == VK_ATTACHMENT_UNUSED)
+      return;
+
+   tu6_emit_blit_info(cmd, cs, fb->attachments[a].attachment,
+                      tiling->gmem_offsets[gmem_index], 0);
+   tu6_emit_blit(cmd, cs);
+}
+
 static void
 tu6_emit_tile_store(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 {
    const struct tu_framebuffer *fb = cmd->state.framebuffer;
    const struct tu_tiling_config *tiling = &cmd->state.tiling_config;
+   const struct tu_subpass *subpass = cmd->state.subpass;
 
    if (false) {
       /* hw binning? */
@@ -841,24 +859,20 @@ tu6_emit_tile_store(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 
    tu6_emit_blit_scissor(cmd, cs);
 
-   for (uint32_t i = 0; i < cmd->state.subpass->color_count; ++i) {
-      uint32_t a = cmd->state.subpass->color_attachments[i].attachment;
-      if (a == VK_ATTACHMENT_UNUSED)
-         continue;
-
-      const struct tu_image_view *iview = fb->attachments[a].attachment;
-      tu6_emit_blit_info(cmd, cs, iview, tiling->gmem_offsets[i], 0);
-      tu6_emit_blit(cmd, cs);
+   for (uint32_t i = 0; i < subpass->color_count; ++i) {
+      tu6_emit_store_attachment(cmd, cs,
+                                subpass->color_attachments[i].attachment,
+                                i);
+      if (subpass->resolve_attachments) {
+         tu6_emit_store_attachment(cmd, cs,
+                                   subpass->resolve_attachments[i].attachment,
+                                   i);
+      }
    }
 
-   const uint32_t a = cmd->state.subpass->depth_stencil_attachment.attachment;
-   if (a != VK_ATTACHMENT_UNUSED) {
-      const struct tu_image_view *iview = fb->attachments[a].attachment;
-      tu6_emit_blit_info(cmd, cs, iview,
-                         tiling->gmem_offsets[cmd->state.subpass->color_count],
-                         0);
-      tu6_emit_blit(cmd, cs);
-   }
+   tu6_emit_store_attachment(cmd, cs,
+                             subpass->depth_stencil_attachment.attachment,
+                             subpass->color_count);
 }
 
 static void
@@ -1120,31 +1134,6 @@ tu6_render_end(struct tu_cmd_buffer *cmd, struct tu_cs *cs)
 
    tu6_emit_event_write(cmd, cs, CACHE_FLUSH_TS, true);
 
-   if (subpass->has_resolve) {
-      for (uint32_t i = 0; i < subpass->color_count; ++i) {
-         struct tu_subpass_attachment src_att = subpass->color_attachments[i];
-         struct tu_subpass_attachment dst_att = subpass->resolve_attachments[i];
-
-         if (dst_att.attachment == VK_ATTACHMENT_UNUSED)
-            continue;
-
-         struct tu_image *src_img = fb->attachments[src_att.attachment].attachment->image;
-         struct tu_image *dst_img = fb->attachments[dst_att.attachment].attachment->image;
-
-         assert(src_img->extent.width == dst_img->extent.width);
-         assert(src_img->extent.height == dst_img->extent.height);
-
-         tu_bo_list_add(&cmd->bo_list, src_img->bo, MSM_SUBMIT_BO_READ);
-         tu_bo_list_add(&cmd->bo_list, dst_img->bo, MSM_SUBMIT_BO_WRITE);
-
-         tu_blit(cmd, &(struct tu_blit) {
-            .dst = tu_blit_surf_whole(dst_img, 0, 0),
-            .src = tu_blit_surf_whole(src_img, 0, 0),
-            .layers = 1,
-         });
-      }
-   }
-
    tu_cs_sanity_check(cs);
 }
 
index e3d9f23df649cf446665c5c924733e3d84fb61de..21ae90361a97508d8205fbc18896b5921876cf0b 100644 (file)
@@ -150,9 +150,8 @@ tu_CreateRenderPass(VkDevice _device,
          }
       }
 
-      subpass->has_resolve = false;
+      subpass->resolve_attachments = desc->pResolveAttachments ? p : NULL;
       if (desc->pResolveAttachments) {
-         subpass->resolve_attachments = p;
          p += desc->colorAttachmentCount;
 
          for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
@@ -162,7 +161,6 @@ tu_CreateRenderPass(VkDevice _device,
                .layout = desc->pResolveAttachments[j].layout,
             };
             if (a != VK_ATTACHMENT_UNUSED) {
-               subpass->has_resolve = true;
                pass->attachments[desc->pResolveAttachments[j].attachment]
                   .view_mask |= subpass->view_mask;
             }
@@ -325,9 +323,8 @@ tu_CreateRenderPass2KHR(VkDevice _device,
          }
       }
 
-      subpass->has_resolve = false;
+      subpass->resolve_attachments = desc->pResolveAttachments ? p : NULL;
       if (desc->pResolveAttachments) {
-         subpass->resolve_attachments = p;
          p += desc->colorAttachmentCount;
 
          for (uint32_t j = 0; j < desc->colorAttachmentCount; j++) {
@@ -337,7 +334,6 @@ tu_CreateRenderPass2KHR(VkDevice _device,
                .layout = desc->pResolveAttachments[j].layout,
             };
             if (a != VK_ATTACHMENT_UNUSED) {
-               subpass->has_resolve = true;
                pass->attachments[desc->pResolveAttachments[j].attachment]
                   .view_mask |= subpass->view_mask;
             }
index 549d1de8b8711ab7da092f37e1ba272f42146804..3b0096d16884b4f03f9b6b2c0add0d9481b82cf8 100644 (file)
@@ -1485,9 +1485,6 @@ struct tu_subpass
    struct tu_subpass_attachment *resolve_attachments;
    struct tu_subpass_attachment depth_stencil_attachment;
 
-   /** Subpass has at least one resolve attachment */
-   bool has_resolve;
-
    struct tu_subpass_barrier start_barrier;
 
    uint32_t view_mask;