xref: /aosp_15_r20/external/mesa3d/src/amd/vulkan/radv_sdma.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2023 Valve Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #ifndef RADV_SDMA_H
8 #define RADV_SDMA_H
9 
10 #include "radv_image.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 struct radv_sdma_surf {
17    VkExtent3D extent;       /* Image extent. */
18    VkOffset3D offset;       /* Image offset. */
19    uint64_t va;             /* Virtual address of image data. */
20    unsigned bpp;            /* Bytes per pixel. */
21    unsigned blk_w;          /* Image format block width in pixels. */
22    unsigned blk_h;          /* Image format block height in pixels. */
23    unsigned mip_levels;     /* Mip levels in the image. */
24    uint8_t micro_tile_mode; /* Micro tile mode of the image. */
25    bool is_linear;          /* Whether the image is linear. */
26    bool is_3d;              /* Whether the image is 3-dimensional. */
27 
28    union {
29       /* linear images only */
30       struct {
31          unsigned pitch;       /* Row pitch in bytes. */
32          unsigned slice_pitch; /* Slice pitch in bytes. */
33       };
34       /* tiled images only */
35       struct {
36          uint64_t meta_va;      /* Virtual address of metadata. */
37          uint32_t meta_config;  /* Metadata configuration DWORD. */
38          uint32_t header_dword; /* Extra bits for the copy packet header. */
39          uint32_t info_dword;   /* Image information DWORD. */
40       };
41    };
42 };
43 
44 ALWAYS_INLINE static VkExtent3D
radv_sdma_get_copy_extent(const struct radv_image * const image,const VkImageSubresourceLayers subresource,VkExtent3D extent)45 radv_sdma_get_copy_extent(const struct radv_image *const image, const VkImageSubresourceLayers subresource,
46                           VkExtent3D extent)
47 {
48    if (image->vk.image_type != VK_IMAGE_TYPE_3D)
49       extent.depth = vk_image_subresource_layer_count(&image->vk, &subresource);
50 
51    return extent;
52 }
53 
54 struct radv_sdma_surf radv_sdma_get_buf_surf(const struct radv_buffer *const buffer,
55                                              const struct radv_image *const image,
56                                              const VkBufferImageCopy2 *const region,
57                                              const VkImageAspectFlags aspect_mask);
58 struct radv_sdma_surf radv_sdma_get_surf(const struct radv_device *const device, const struct radv_image *const image,
59                                          const VkImageSubresourceLayers subresource, const VkOffset3D offset,
60                                          const VkImageAspectFlags aspect_mask);
61 void radv_sdma_copy_buffer_image(const struct radv_device *device, struct radeon_cmdbuf *cs,
62                                  const struct radv_sdma_surf *buf, const struct radv_sdma_surf *img,
63                                  const VkExtent3D extent, bool to_image);
64 bool radv_sdma_use_unaligned_buffer_image_copy(const struct radv_device *device, const struct radv_sdma_surf *buf,
65                                                const struct radv_sdma_surf *img, const VkExtent3D ext);
66 void radv_sdma_copy_buffer_image_unaligned(const struct radv_device *device, struct radeon_cmdbuf *cs,
67                                            const struct radv_sdma_surf *buf, const struct radv_sdma_surf *img_in,
68                                            const VkExtent3D copy_extent, struct radeon_winsys_bo *temp_bo,
69                                            bool to_image);
70 void radv_sdma_copy_image(const struct radv_device *device, struct radeon_cmdbuf *cs, const struct radv_sdma_surf *src,
71                           const struct radv_sdma_surf *dst, const VkExtent3D extent);
72 bool radv_sdma_use_t2t_scanline_copy(const struct radv_device *device, const struct radv_sdma_surf *src,
73                                      const struct radv_sdma_surf *dst, const VkExtent3D extent);
74 void radv_sdma_copy_image_t2t_scanline(const struct radv_device *device, struct radeon_cmdbuf *cs,
75                                        const struct radv_sdma_surf *src, const struct radv_sdma_surf *dst,
76                                        const VkExtent3D extent, struct radeon_winsys_bo *temp_bo);
77 void radv_sdma_copy_buffer(const struct radv_device *device, struct radeon_cmdbuf *cs, uint64_t src_va, uint64_t dst_va,
78                            uint64_t size);
79 void radv_sdma_fill_buffer(const struct radv_device *device, struct radeon_cmdbuf *cs, const uint64_t va,
80                            const uint64_t size, const uint32_t value);
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif /* RADV_SDMA_H */
87