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