turnip: implement CmdClearAttachments
authorJonathan Marek <jonathan@marek.ca>
Fri, 22 Nov 2019 23:09:32 +0000 (18:09 -0500)
committerJonathan Marek <jonathan@marek.ca>
Wed, 4 Dec 2019 19:39:06 +0000 (14:39 -0500)
Passes these deqp tests: dEQP-VK.api.image_clearing.core.*attach*single*

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/freedreno/vulkan/tu_meta_clear.c

index fdfd0ec36e80f4f4067922a3919ec326fa8a7dbc..48754e4660136d1b45dcf3ba43e5f9c6f819147d 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "tu_private.h"
 #include "tu_blit.h"
+#include "tu_cs.h"
 
 static void
 clear_image(struct tu_cmd_buffer *cmdbuf,
@@ -99,5 +100,68 @@ tu_CmdClearAttachments(VkCommandBuffer commandBuffer,
                        uint32_t rectCount,
                        const VkClearRect *pRects)
 {
-   tu_finishme("CmdClearAttachments");
+   TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
+   const struct tu_subpass *subpass = cmd->state.subpass;
+   struct tu_cs *cs = &cmd->draw_cs;
+
+   VkResult result = tu_cs_reserve_space(cmd->device, cs,
+                                         rectCount * (3 + 15 * attachmentCount));
+   if (result != VK_SUCCESS) {
+      cmd->record_result = result;
+      return;
+   }
+
+   /* TODO: deal with layered rendering (when layered rendering is implemented)
+    * TODO: disable bypass rendering for subpass (when bypass is implemented)
+    */
+
+   for (unsigned i = 0; i < rectCount; i++) {
+      unsigned x1 = pRects[i].rect.offset.x;
+      unsigned y1 = pRects[i].rect.offset.y;
+      unsigned x2 = x1 + pRects[i].rect.extent.width - 1;
+      unsigned y2 = y1 + pRects[i].rect.extent.height - 1;
+
+      tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_SCISSOR_TL, 2);
+      tu_cs_emit(cs, A6XX_RB_BLIT_SCISSOR_TL_X(x1) | A6XX_RB_BLIT_SCISSOR_TL_Y(y1));
+      tu_cs_emit(cs, A6XX_RB_BLIT_SCISSOR_BR_X(x2) | A6XX_RB_BLIT_SCISSOR_BR_Y(y2));
+
+      for (unsigned j = 0; j < attachmentCount; j++) {
+         uint32_t index, a;
+         if (pAttachments[j].aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
+            index = pAttachments[j].colorAttachment;
+            a = subpass->color_attachments[index].attachment;
+         } else {
+            index = subpass->color_count;
+            a = subpass->depth_stencil_attachment.attachment;
+         }
+         /* TODO: partial depth/stencil clear? */
+
+         VkFormat fmt = cmd->state.pass->attachments[a].format;
+         const struct tu_native_format *format = tu6_get_native_format(fmt);
+         assert(format && format->rb >= 0);
+
+         tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_DST_INFO, 1);
+         tu_cs_emit(cs, A6XX_RB_BLIT_DST_INFO_COLOR_FORMAT(format->rb));
+
+         tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_INFO, 1);
+         tu_cs_emit(cs, A6XX_RB_BLIT_INFO_GMEM | A6XX_RB_BLIT_INFO_CLEAR_MASK(0xf));
+
+         tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_BASE_GMEM, 1);
+         tu_cs_emit(cs, cmd->state.tiling_config.gmem_offsets[index]);
+
+         tu_cs_emit_pkt4(cs, REG_A6XX_RB_UNKNOWN_88D0, 1);
+         tu_cs_emit(cs, 0);
+
+         uint32_t clear_vals[4] = { 0 };
+         tu_pack_clear_value(&pAttachments[j].clearValue, fmt, clear_vals);
+
+         tu_cs_emit_pkt4(cs, REG_A6XX_RB_BLIT_CLEAR_COLOR_DW0, 4);
+         tu_cs_emit(cs, clear_vals[0]);
+         tu_cs_emit(cs, clear_vals[1]);
+         tu_cs_emit(cs, clear_vals[2]);
+         tu_cs_emit(cs, clear_vals[3]);
+
+         tu6_emit_event_write(cmd, cs, BLIT, false);
+      }
+   }
 }