• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2023 Valve Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef RADV_SDMA_H
25 #define RADV_SDMA_H
26 
27 #include "radv_private.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 struct radv_sdma_surf {
34    VkExtent3D extent;       /* Image extent. */
35    VkOffset3D offset;       /* Image offset. */
36    uint64_t va;             /* Virtual address of image data. */
37    unsigned bpp;            /* Bytes per pixel. */
38    unsigned blk_w;          /* Image format block width in pixels. */
39    unsigned blk_h;          /* Image format block height in pixels. */
40    unsigned mip_levels;     /* Mip levels in the image. */
41    uint8_t micro_tile_mode; /* Micro tile mode of the image. */
42    bool is_linear;          /* Whether the image is linear. */
43    bool is_3d;              /* Whether the image is 3-dimensional. */
44 
45    union {
46       /* linear images only */
47       struct {
48          unsigned pitch;       /* Row pitch in bytes. */
49          unsigned slice_pitch; /* Slice pitch in bytes. */
50       };
51       /* tiled images only */
52       struct {
53          uint64_t meta_va;      /* Virtual address of metadata. */
54          uint32_t meta_config;  /* Metadata configuration DWORD. */
55          uint32_t header_dword; /* Extra bits for the copy packet header. */
56          uint32_t info_dword;   /* Image information DWORD. */
57       };
58    };
59 };
60 
61 ALWAYS_INLINE static VkExtent3D
radv_sdma_get_copy_extent(const struct radv_image * const image,const VkImageSubresourceLayers subresource,VkExtent3D extent)62 radv_sdma_get_copy_extent(const struct radv_image *const image, const VkImageSubresourceLayers subresource,
63                           VkExtent3D extent)
64 {
65    if (image->vk.image_type != VK_IMAGE_TYPE_3D)
66       extent.depth = vk_image_subresource_layer_count(&image->vk, &subresource);
67 
68    return extent;
69 }
70 
71 struct radv_sdma_surf radv_sdma_get_buf_surf(const struct radv_buffer *const buffer,
72                                              const struct radv_image *const image,
73                                              const VkBufferImageCopy2 *const region,
74                                              const VkImageAspectFlags aspect_mask);
75 struct radv_sdma_surf radv_sdma_get_surf(const struct radv_device *const device, const struct radv_image *const image,
76                                          const VkImageSubresourceLayers subresource, const VkOffset3D offset,
77                                          const VkImageAspectFlags aspect_mask);
78 void radv_sdma_copy_buffer_image(const struct radv_device *device, struct radeon_cmdbuf *cs,
79                                  const struct radv_sdma_surf *buf, const struct radv_sdma_surf *img,
80                                  const VkExtent3D extent, bool to_image);
81 bool radv_sdma_use_unaligned_buffer_image_copy(const struct radv_device *device, const struct radv_sdma_surf *buf,
82                                                const struct radv_sdma_surf *img, const VkExtent3D ext);
83 void radv_sdma_copy_buffer_image_unaligned(const struct radv_device *device, struct radeon_cmdbuf *cs,
84                                            const struct radv_sdma_surf *buf, const struct radv_sdma_surf *img_in,
85                                            const VkExtent3D copy_extent, struct radeon_winsys_bo *temp_bo,
86                                            bool to_image);
87 void radv_sdma_copy_image(const struct radv_device *device, struct radeon_cmdbuf *cs, const struct radv_sdma_surf *src,
88                           const struct radv_sdma_surf *dst, const VkExtent3D extent);
89 bool radv_sdma_use_t2t_scanline_copy(const struct radv_device *device, const struct radv_sdma_surf *src,
90                                      const struct radv_sdma_surf *dst, const VkExtent3D extent);
91 void radv_sdma_copy_image_t2t_scanline(const struct radv_device *device, struct radeon_cmdbuf *cs,
92                                        const struct radv_sdma_surf *src, const struct radv_sdma_surf *dst,
93                                        const VkExtent3D extent, struct radeon_winsys_bo *temp_bo);
94 void radv_sdma_copy_buffer(const struct radv_device *device, struct radeon_cmdbuf *cs, uint64_t src_va, uint64_t dst_va,
95                            uint64_t size);
96 void radv_sdma_fill_buffer(const struct radv_device *device, struct radeon_cmdbuf *cs, const uint64_t va,
97                            const uint64_t size, const uint32_t value);
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 
103 #endif /* RADV_SDMA_H */
104