#include "tu_private.h"
#include "tu_blit.h"
+#include "tu_cs.h"
static void
clear_image(struct tu_cmd_buffer *cmdbuf,
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);
+ }
+ }
}