Module: Mesa
Branch: main
Commit: ec0605ff723d5d9301fc4c9cf18bd6f2892fc5fc
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ec0605ff723d5d9301fc4c9cf18bd6f2892fc5fc

Author: Timur Kristóf <timur.kris...@gmail.com>
Date:   Thu Oct  5 13:35:58 2023 +0200

radv: Add temporary BO for transfer queues.

Some copy operations are poorly supported by the SDMA hardware,
meaning that the built-in packets don't support them, so we will
need to work around that by copying to and from a temporary BO.

The size of the temporary buffer was chosen so that it can fit
at least one full pixel row of the largest possible image.

Signed-off-by: Timur Kristóf <timur.kris...@gmail.com>
Reviewed-by: Tatsuyuki Ishi <ishitatsuy...@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoi...@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25831>

---

 src/amd/vulkan/meta/radv_meta_copy.c | 20 ++++++++++++++++++++
 src/amd/vulkan/radv_cmd_buffer.c     |  2 ++
 src/amd/vulkan/radv_constants.h      |  5 +++++
 src/amd/vulkan/radv_private.h        |  5 +++++
 4 files changed, 32 insertions(+)

diff --git a/src/amd/vulkan/meta/radv_meta_copy.c 
b/src/amd/vulkan/meta/radv_meta_copy.c
index 3e288b68d84..86a91c8b302 100644
--- a/src/amd/vulkan/meta/radv_meta_copy.c
+++ b/src/amd/vulkan/meta/radv_meta_copy.c
@@ -85,6 +85,26 @@ radv_image_is_renderable(const struct radv_device *device, 
const struct radv_ima
    return true;
 }
 
+static bool
+alloc_transfer_temp_bo(struct radv_cmd_buffer *cmd_buffer)
+{
+   if (cmd_buffer->transfer.copy_temp)
+      return true;
+
+   const struct radv_device *const device = cmd_buffer->device;
+   const VkResult r = device->ws->buffer_create(device->ws, 
RADV_SDMA_TRANSFER_TEMP_BYTES, 4096, RADEON_DOMAIN_VRAM,
+                                                RADEON_FLAG_NO_CPU_ACCESS | 
RADEON_FLAG_NO_INTERPROCESS_SHARING,
+                                                RADV_BO_PRIORITY_SCRATCH, 0, 
&cmd_buffer->transfer.copy_temp);
+
+   if (r != VK_SUCCESS) {
+      vk_command_buffer_set_error(&cmd_buffer->vk, r);
+      return false;
+   }
+
+   radv_cs_add_buffer(device->ws, cmd_buffer->cs, 
cmd_buffer->transfer.copy_temp);
+   return true;
+}
+
 static void
 transfer_copy_buffer_image(struct radv_cmd_buffer *cmd_buffer, struct 
radv_buffer *buffer, struct radv_image *image,
                            const VkBufferImageCopy2 *region, bool to_image)
diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c
index 6c4f9ee6aef..709de1256f6 100644
--- a/src/amd/vulkan/radv_cmd_buffer.c
+++ b/src/amd/vulkan/radv_cmd_buffer.c
@@ -312,6 +312,8 @@ radv_destroy_cmd_buffer(struct vk_command_buffer 
*vk_cmd_buffer)
       cmd_buffer->device->ws->cs_destroy(cmd_buffer->cs);
    if (cmd_buffer->gang.cs)
       cmd_buffer->device->ws->cs_destroy(cmd_buffer->gang.cs);
+   if (cmd_buffer->transfer.copy_temp)
+      cmd_buffer->device->ws->buffer_destroy(cmd_buffer->device->ws, 
cmd_buffer->transfer.copy_temp);
 
    for (unsigned i = 0; i < MAX_BIND_POINTS; i++) {
       struct radv_descriptor_set_header *set = 
&cmd_buffer->descriptors[i].push_set.set;
diff --git a/src/amd/vulkan/radv_constants.h b/src/amd/vulkan/radv_constants.h
index 4178138ce11..796a1c87f63 100644
--- a/src/amd/vulkan/radv_constants.h
+++ b/src/amd/vulkan/radv_constants.h
@@ -166,4 +166,9 @@
 /* Number of samples for line smooth lowering (hw requirement). */
 #define RADV_NUM_SMOOTH_AA_SAMPLES 4
 
+/* Size of the temporary buffer allocated for transfer queue copy command 
workarounds.
+ * The size is chosen so that it can fit two lines of (1 << 14) blocks at 16 
bpp.
+ */
+#define RADV_SDMA_TRANSFER_TEMP_BYTES (2 * (1 << 14) * 16)
+
 #endif /* RADV_CONSTANTS_H */
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index cbaba423f35..56002af0bab 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -1869,6 +1869,11 @@ struct radv_cmd_buffer {
       struct rvcn_decode_buffer_s *decode_buffer;
    } video;
 
+   struct {
+      /* Temporary space for some transfer queue copy command workarounds. */
+      struct radeon_winsys_bo *copy_temp;
+   } transfer;
+
    uint64_t shader_upload_seq;
 
    uint32_t sqtt_cb_id;

Reply via email to