v3d/tex: only look up the 2nd texture gather offset for 1d non-arrays
[mesa.git] / src / freedreno / vulkan / tu_clear_blit.c
index c07e7e0bd0e485a3c3f9646fd5191a94f695d888..550c66174631f97b12bf8a8a17534b2cf1c08c20 100644 (file)
@@ -1777,8 +1777,6 @@ tu_clear_sysmem_attachments_2d(struct tu_cmd_buffer *cmd,
 
    for (uint32_t j = 0; j < attachment_count; j++) {
          uint32_t a;
-         uint8_t mask = 0xf;
-
          if (attachments[j].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
             a = subpass->color_attachments[attachments[j].colorAttachment].attachment;
          } else {
@@ -1789,17 +1787,19 @@ tu_clear_sysmem_attachments_2d(struct tu_cmd_buffer *cmd,
             /* also flush color to avoid losing contents from invalidate */
             tu6_emit_event_write(cmd, cs, PC_CCU_FLUSH_COLOR_TS, true);
             tu6_emit_event_write(cmd, cs, PC_CCU_INVALIDATE_COLOR, false);
+         }
 
+         if (a == VK_ATTACHMENT_UNUSED)
+               continue;
 
+         uint8_t mask = 0xf;
+         if (cmd->state.pass->attachments[a].format == VK_FORMAT_D24_UNORM_S8_UINT) {
             if (!(attachments[j].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT))
                mask &= ~0x7;
             if (!(attachments[j].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT))
                mask &= ~0x8;
          }
 
-         if (a == VK_ATTACHMENT_UNUSED)
-               continue;
-
          const struct tu_image_view *iview =
             cmd->state.framebuffer->attachments[a].attachment;
 
@@ -2071,21 +2071,22 @@ tu_clear_gmem_attachments(struct tu_cmd_buffer *cmd,
 
       for (unsigned j = 0; j < attachment_count; j++) {
          uint32_t a;
-         unsigned clear_mask = 0;
-         if (attachments[j].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
-            clear_mask = 0xf;
+         if (attachments[j].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT)
             a = subpass->color_attachments[attachments[j].colorAttachment].attachment;
-         } else {
+         else
             a = subpass->depth_stencil_attachment.attachment;
-            if (attachments[j].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT)
-               clear_mask |= 0x7;
-            if (attachments[j].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)
-               clear_mask |= 0x8;
-         }
 
          if (a == VK_ATTACHMENT_UNUSED)
                continue;
 
+         unsigned clear_mask = 0xf;
+         if (cmd->state.pass->attachments[a].format == VK_FORMAT_D24_UNORM_S8_UINT) {
+            if (!(attachments[j].aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT))
+               clear_mask &= ~0x7;
+            if (!(attachments[j].aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT))
+               clear_mask &= ~0x8;
+         }
+
          tu_emit_clear_gmem_attachment(cmd, cs, a, clear_mask,
                                        &attachments[j].clearValue);
       }
@@ -2123,17 +2124,14 @@ tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
       &cmd->state.pass->attachments[a];
    uint8_t mask = 0;
 
-   if (attachment->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR)
+   if (attachment->clear_mask == VK_IMAGE_ASPECT_COLOR_BIT)
       mask = 0xf;
+   if (attachment->clear_mask & VK_IMAGE_ASPECT_DEPTH_BIT)
+      mask |= 0x7;
+   if (attachment->clear_mask & VK_IMAGE_ASPECT_STENCIL_BIT)
+      mask |= 0x8;
 
-   if (attachment->format == VK_FORMAT_D24_UNORM_S8_UINT) {
-      mask &= 0x7;
-      if (attachment->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR)
-         mask |= 0x8;
-   }
-
-   /* gmem_offset<0 means it isn't used by any subpass and shouldn't be cleared */
-   if (attachment->gmem_offset < 0 || !mask)
+   if (!mask)
       return;
 
    const struct blit_ops *ops = &r2d_ops;
@@ -2160,18 +2158,13 @@ tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
       &cmd->state.pass->attachments[a];
    unsigned clear_mask = 0;
 
-   /* note: this means it isn't used by any subpass and shouldn't be cleared anyway */
-   if (attachment->gmem_offset < 0)
-      return;
-
-   if (attachment->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR)
+   if (attachment->clear_mask == VK_IMAGE_ASPECT_COLOR_BIT)
       clear_mask = 0xf;
+   if (attachment->clear_mask & VK_IMAGE_ASPECT_DEPTH_BIT)
+      clear_mask |= 0x7;
+   if (attachment->clear_mask & VK_IMAGE_ASPECT_STENCIL_BIT)
+      clear_mask |= 0x8;
 
-   if (vk_format_has_stencil(attachment->format)) {
-      clear_mask &= 0x7;
-      if (attachment->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR)
-         clear_mask |= 0x8;
-   }
    if (!clear_mask)
       return;
 
@@ -2185,7 +2178,7 @@ static void
 tu_emit_blit(struct tu_cmd_buffer *cmd,
              struct tu_cs *cs,
              const struct tu_image_view *iview,
-             struct tu_render_pass_attachment *attachment,
+             const struct tu_render_pass_attachment *attachment,
              bool resolve)
 {
    tu_cs_emit_regs(cs,
@@ -2246,28 +2239,18 @@ blit_can_resolve(VkFormat format)
 }
 
 void
-tu_emit_load_gmem_attachment(struct tu_cmd_buffer *cmd, struct tu_cs *cs, uint32_t a)
-{
-   tu_emit_blit(cmd, cs,
-                cmd->state.framebuffer->attachments[a].attachment,
-                &cmd->state.pass->attachments[a],
-                false);
-}
-
-void
-tu_load_gmem_attachment(struct tu_cmd_buffer *cmd, struct tu_cs *cs, uint32_t a)
+tu_load_gmem_attachment(struct tu_cmd_buffer *cmd,
+                        struct tu_cs *cs,
+                        uint32_t a,
+                        bool force_load)
 {
+   const struct tu_image_view *iview =
+      cmd->state.framebuffer->attachments[a].attachment;
    const struct tu_render_pass_attachment *attachment =
       &cmd->state.pass->attachments[a];
 
-   if (attachment->gmem_offset < 0)
-      return;
-
-   if (attachment->load_op == VK_ATTACHMENT_LOAD_OP_LOAD ||
-       (vk_format_has_stencil(attachment->format) &&
-        attachment->stencil_load_op == VK_ATTACHMENT_LOAD_OP_LOAD)) {
-      tu_emit_load_gmem_attachment(cmd, cs, a);
-   }
+   if (attachment->load || force_load)
+      tu_emit_blit(cmd, cs, iview, attachment, false);
 }
 
 void
@@ -2282,7 +2265,7 @@ tu_store_gmem_attachment(struct tu_cmd_buffer *cmd,
    struct tu_image_view *iview = cmd->state.framebuffer->attachments[a].attachment;
    struct tu_render_pass_attachment *src = &cmd->state.pass->attachments[gmem_a];
 
-   if (dst->store_op == VK_ATTACHMENT_STORE_OP_DONT_CARE)
+   if (!dst->store)
       return;
 
    uint32_t x1 = render_area->offset.x;