turnip: implement CmdFillBuffer/CmdUpdateBuffer
authorJonathan Marek <jonathan@marek.ca>
Mon, 16 Dec 2019 15:00:20 +0000 (10:00 -0500)
committerJonathan Marek <jonathan@marek.ca>
Mon, 16 Dec 2019 18:13:53 +0000 (13:13 -0500)
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/freedreno/vulkan/tu_meta_buffer.c

index 98a73413cf2f589eb562f9978ee4a048a15c3626..ea764c5790e419a02ab6ba78aebc9eabda50f4d9 100644 (file)
@@ -1,4 +1,6 @@
 #include "tu_private.h"
+#include "tu_blit.h"
+#include "tu_cs.h"
 
 void
 tu_CmdFillBuffer(VkCommandBuffer commandBuffer,
@@ -7,6 +9,27 @@ tu_CmdFillBuffer(VkCommandBuffer commandBuffer,
                  VkDeviceSize fillSize,
                  uint32_t data)
 {
+   TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
+   TU_FROM_HANDLE(tu_buffer, buffer, dstBuffer);
+
+   if (fillSize == VK_WHOLE_SIZE)
+      fillSize = buffer->size - dstOffset;
+
+   tu_bo_list_add(&cmd->bo_list, buffer->bo, MSM_SUBMIT_BO_WRITE);
+
+   tu_blit(cmd, &(struct tu_blit) {
+      .dst = {
+         .fmt = VK_FORMAT_R32_UINT,
+         .va = tu_buffer_iova(buffer) + dstOffset,
+         .width = fillSize / 4,
+         .height = 1,
+         .samples = 1,
+      },
+      .layers = 1,
+      .clear_value[0] = data,
+      .type = TU_BLIT_CLEAR,
+      .buffer = true,
+   });
 }
 
 void
@@ -16,4 +39,37 @@ tu_CmdUpdateBuffer(VkCommandBuffer commandBuffer,
                    VkDeviceSize dataSize,
                    const void *pData)
 {
+   TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
+   TU_FROM_HANDLE(tu_buffer, buffer, dstBuffer);
+
+   tu_bo_list_add(&cmd->bo_list, buffer->bo, MSM_SUBMIT_BO_WRITE);
+
+   struct ts_cs_memory tmp;
+   VkResult result = tu_cs_alloc(cmd->device, &cmd->sub_cs, DIV_ROUND_UP(dataSize, 64), 64, &tmp);
+   if (result != VK_SUCCESS) {
+      cmd->record_result = result;
+      return;
+   }
+
+   memcpy(tmp.map, pData, dataSize);
+
+   tu_blit(cmd, &(struct tu_blit) {
+      .dst = {
+         .fmt = VK_FORMAT_R32_UINT,
+         .va = tu_buffer_iova(buffer) + dstOffset,
+         .width = dataSize / 4,
+         .height = 1,
+         .samples = 1,
+      },
+      .src = {
+         .fmt = VK_FORMAT_R32_UINT,
+         .va = tmp.iova,
+         .width = dataSize / 4,
+         .height = 1,
+         .samples = 1,
+      },
+      .layers = 1,
+      .type = TU_BLIT_COPY,
+      .buffer = true,
+   });
 }