1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2016 Red Hat.
3bf215546Sopenharmony_ci * Copyright © 2016 Bas Nieuwenhuizen
4bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * based in part on anv driver which is:
7bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation
8bf215546Sopenharmony_ci */
9bf215546Sopenharmony_ci
10bf215546Sopenharmony_ci#ifndef TU_IMAGE_H
11bf215546Sopenharmony_ci#define TU_IMAGE_H
12bf215546Sopenharmony_ci
13bf215546Sopenharmony_ci#include "tu_common.h"
14bf215546Sopenharmony_ci
15bf215546Sopenharmony_ci#define tu_image_view_stencil(iview, x) \
16bf215546Sopenharmony_ci   ((iview->view.x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_8_UINT))
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_ci#define tu_image_view_depth(iview, x) \
19bf215546Sopenharmony_ci   ((iview->view.x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_32_FLOAT))
20bf215546Sopenharmony_ci
21bf215546Sopenharmony_cistruct tu_image
22bf215546Sopenharmony_ci{
23bf215546Sopenharmony_ci   struct vk_image vk;
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci   struct fdl_layout layout[3];
26bf215546Sopenharmony_ci   uint32_t total_size;
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#ifdef ANDROID
29bf215546Sopenharmony_ci   /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
30bf215546Sopenharmony_ci   VkDeviceMemory owned_memory;
31bf215546Sopenharmony_ci#endif
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci   /* Set when bound */
34bf215546Sopenharmony_ci   struct tu_bo *bo;
35bf215546Sopenharmony_ci   uint64_t iova;
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci   uint32_t lrz_height;
38bf215546Sopenharmony_ci   uint32_t lrz_pitch;
39bf215546Sopenharmony_ci   uint32_t lrz_offset;
40bf215546Sopenharmony_ci   uint32_t lrz_fc_offset;
41bf215546Sopenharmony_ci   uint32_t lrz_fc_size;
42bf215546Sopenharmony_ci};
43bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(tu_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cistruct tu_image_view
46bf215546Sopenharmony_ci{
47bf215546Sopenharmony_ci   struct vk_image_view vk;
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   struct tu_image *image; /**< VkImageViewCreateInfo::image */
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci   struct fdl6_view view;
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci   /* for d32s8 separate depth */
54bf215546Sopenharmony_ci   uint64_t depth_base_addr;
55bf215546Sopenharmony_ci   uint32_t depth_layer_size;
56bf215546Sopenharmony_ci   uint32_t depth_PITCH;
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci   /* for d32s8 separate stencil */
59bf215546Sopenharmony_ci   uint64_t stencil_base_addr;
60bf215546Sopenharmony_ci   uint32_t stencil_layer_size;
61bf215546Sopenharmony_ci   uint32_t stencil_PITCH;
62bf215546Sopenharmony_ci};
63bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view, vk.base, VkImageView,
64bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_IMAGE_VIEW);
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_cistruct tu_buffer_view
67bf215546Sopenharmony_ci{
68bf215546Sopenharmony_ci   struct vk_object_base base;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   uint32_t descriptor[A6XX_TEX_CONST_DWORDS];
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   struct tu_buffer *buffer;
73bf215546Sopenharmony_ci};
74bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view, base, VkBufferView,
75bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_BUFFER_VIEW)
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ciuint32_t tu6_plane_count(VkFormat format);
78bf215546Sopenharmony_cienum pipe_format tu6_plane_format(VkFormat format, uint32_t plane);
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ciuint32_t tu6_plane_index(VkFormat format, VkImageAspectFlags aspect_mask);
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_cienum pipe_format tu_format_for_aspect(enum pipe_format format,
83bf215546Sopenharmony_ci                                      VkImageAspectFlags aspect_mask);
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_civoid
86bf215546Sopenharmony_citu_cs_image_ref(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer);
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_civoid
89bf215546Sopenharmony_citu_cs_image_ref_2d(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer, bool src);
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_civoid
92bf215546Sopenharmony_citu_cs_image_flag_ref(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer);
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_civoid
95bf215546Sopenharmony_citu_cs_image_stencil_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_civoid
98bf215546Sopenharmony_citu_cs_image_depth_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_cibool
101bf215546Sopenharmony_citiling_possible(VkFormat format);
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_cibool
104bf215546Sopenharmony_ciubwc_possible(VkFormat format, VkImageType type, VkImageUsageFlags usage, VkImageUsageFlags stencil_usage,
105bf215546Sopenharmony_ci              const struct fd_dev_info *info, VkSampleCountFlagBits samples,
106bf215546Sopenharmony_ci              bool use_z24uint_s8uint);
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_civoid
109bf215546Sopenharmony_citu_buffer_view_init(struct tu_buffer_view *view,
110bf215546Sopenharmony_ci                    struct tu_device *device,
111bf215546Sopenharmony_ci                    const VkBufferViewCreateInfo *pCreateInfo);
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci#endif /* TU_IMAGE_H */
114