1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 * SPDX-License-Identifier: MIT
5 *
6 * based in part on anv driver which is:
7 * Copyright © 2015 Intel Corporation
8 */
9
10 #ifndef TU_IMAGE_H
11 #define TU_IMAGE_H
12
13 #include "tu_common.h"
14
15 #define TU_MAX_PLANE_COUNT 3
16
17 #define tu_fdl_view_stencil(view, x) \
18 (((view)->x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_8_UINT))
19
20 #define tu_fdl_view_depth(view, x) \
21 (((view)->x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_32_FLOAT))
22
23 #define tu_image_view_stencil(iview, x) \
24 tu_fdl_view_stencil(&iview->view, x)
25
26 #define tu_image_view_depth(iview, x) \
27 tu_fdl_view_depth(&iview->view, x)
28
29 struct tu_image
30 {
31 struct vk_image vk;
32
33 struct fdl_layout layout[3];
34 uint64_t total_size;
35
36 /* Set when bound */
37 struct tu_bo *bo;
38 uint64_t bo_offset;
39 uint64_t iova;
40
41 /* For fragment density map */
42 void *map;
43
44 uint32_t lrz_height;
45 uint32_t lrz_pitch;
46 uint32_t lrz_offset;
47 uint32_t lrz_fc_offset;
48 bool has_lrz_fc;
49
50 bool ubwc_enabled;
51 bool force_linear_tile;
52 bool is_mutable;
53 };
54 VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
55
56 struct tu_image_view
57 {
58 struct vk_image_view vk;
59
60 struct tu_image *image; /**< VkImageViewCreateInfo::image */
61
62 struct fdl6_view view;
63
64 unsigned char swizzle[4];
65
66 /* for d32s8 separate depth */
67 uint64_t depth_base_addr;
68 uint32_t depth_layer_size;
69 uint32_t depth_pitch;
70
71 /* for d32s8 separate stencil */
72 uint64_t stencil_base_addr;
73 uint32_t stencil_layer_size;
74 uint32_t stencil_pitch;
75 };
76 VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view, vk.base, VkImageView,
77 VK_OBJECT_TYPE_IMAGE_VIEW);
78
79 uint32_t tu6_plane_count(VkFormat format);
80
81 enum pipe_format tu6_plane_format(VkFormat format, uint32_t plane);
82
83 uint32_t tu6_plane_index(VkFormat format, VkImageAspectFlags aspect_mask);
84
85 enum pipe_format tu_format_for_aspect(enum pipe_format format,
86 VkImageAspectFlags aspect_mask);
87
88 static inline enum pipe_format
tu_aspects_to_plane(VkFormat format,VkImageAspectFlags aspect_mask)89 tu_aspects_to_plane(VkFormat format, VkImageAspectFlags aspect_mask)
90 {
91 uint32_t plane = tu6_plane_index(format, aspect_mask);
92 return tu6_plane_format(format, plane);
93 }
94
95 uint64_t
96 tu_layer_address(const struct fdl6_view *iview, uint32_t layer);
97
98 void
99 tu_cs_image_ref(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer);
100
101 template <chip CHIP>
102 void
103 tu_cs_image_ref_2d(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer, bool src);
104
105 void
106 tu_cs_image_flag_ref(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer);
107
108 void
109 tu_cs_image_stencil_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
110
111 void
112 tu_cs_image_depth_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
113
114 bool
115 tiling_possible(VkFormat format);
116
117 bool
118 ubwc_possible(struct tu_device *device,
119 VkFormat format,
120 VkImageType type,
121 VkImageUsageFlags usage,
122 VkImageUsageFlags stencil_usage,
123 const struct fd_dev_info *info,
124 VkSampleCountFlagBits samples,
125 uint32_t mip_levels,
126 bool use_z24uint_s8uint);
127
128 struct tu_frag_area {
129 float width;
130 float height;
131 };
132
133 void
134 tu_fragment_density_map_sample(const struct tu_image_view *fdm,
135 uint32_t x, uint32_t y,
136 uint32_t width, uint32_t height,
137 uint32_t layers, struct tu_frag_area *areas);
138
139 VkResult
140 tu_image_update_layout(struct tu_device *device, struct tu_image *image,
141 uint64_t modifier, const VkSubresourceLayout *plane_layouts);
142
143 #endif /* TU_IMAGE_H */
144