Debian Codegraph @

src/panfrost/vulkan/panvk_meta.h

raw
1 /*
2 * Copyright © 2021 Collabora Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef PANVK_META_H
7 #define PANVK_META_H
8
9 #ifndef PAN_ARCH
10 #error "PAN_ARCH must be defined"
11 #endif
12
13 #include "panvk_image.h"
14 #include "panvk_mempool.h"
15
16 #include "vk_format.h"
17 #include "vk_meta.h"
18
19 enum panvk_meta_object_key_type {
20 PANVK_META_OBJECT_KEY_BLEND_SHADER = VK_META_OBJECT_KEY_DRIVER_OFFSET,
21 PANVK_META_OBJECT_KEY_COPY_DESC_SHADER,
22 PANVK_META_OBJECT_KEY_FB_ZS_PRELOAD_SHADER,
23 PANVK_META_OBJECT_KEY_FB_COLOR_PRELOAD_SHADER,
24 PANVK_META_OBJECT_KEY_FB_RESOLVE_SHADER,
25 };
26
27 static inline VkFormat
28 panvk_meta_get_uint_format_for_blk_size(unsigned blk_sz)
29 {
30 switch (blk_sz) {
31 case 1:
32 return VK_FORMAT_R8_UINT;
33 case 2:
34 return VK_FORMAT_R8G8_UINT;
35 case 3:
36 return VK_FORMAT_R8G8B8_UINT;
37 case 4:
38 return VK_FORMAT_R8G8B8A8_UINT;
39 case 6:
40 return VK_FORMAT_R16G16B16_UINT;
41 case 8:
42 return VK_FORMAT_R32G32_UINT;
43 case 12:
44 return VK_FORMAT_R32G32B32_UINT;
45 case 16:
46 return VK_FORMAT_R32G32B32A32_UINT;
47 default:
48 return VK_FORMAT_UNDEFINED;
49 }
50 }
51
52 static inline VkFormat
53 panvk_meta_get_blendable_format_for_blk_size(unsigned blk_sz)
54 {
55 /* We expect _UINT formats to be used if the blocksize is greater than
56 * 32-bit.
57 */
58 assert(blk_sz <= 4);
59
60 switch (blk_sz) {
61 case 1:
62 return VK_FORMAT_R8_UNORM;
63 case 2:
64 return VK_FORMAT_R8G8_UNORM;
65 case 3:
66 return VK_FORMAT_R8G8B8_UNORM;
67 case 4:
68 return VK_FORMAT_R8G8B8A8_UNORM;
69 default:
70 return VK_FORMAT_UNDEFINED;
71 }
72 }
73
74 static inline struct vk_meta_copy_image_properties
75 panvk_meta_copy_get_image_properties(struct panvk_image *img,
76 bool use_gfx_pipeline, bool is_destination)
77 {
78 uint64_t mod = img->vk.drm_format_mod;
79 enum pipe_format pfmt = vk_format_to_pipe_format(img->vk.format);
80 struct vk_meta_copy_image_properties props;
81 memset(&props, 0, sizeof(props));
82 const struct vk_format_ycbcr_info *ycbcr_info =
83 vk_format_get_ycbcr_info(img->vk.format);
84 const bool is_afbc = drm_is_afbc(img->vk.drm_format_mod);
85 /* Format re-interpretation is not an option on Bifrost */
86 const bool preserve_img_fmt = is_afbc && PAN_ARCH <= 7;
87 /* We prefer to use formats that are blendable by the fixed function
88 * hardware to avoid blend shaders. On Bifrost, only UNORM/sRGB
89 * is allowed, so we use UNORM formats when creating depth/stencil views too.
90 */
91 const bool prefer_blendable = use_gfx_pipeline && is_destination;
92
93 if (vk_format_is_depth_or_stencil(img->vk.format)) {
94 switch (img->vk.format) {
95 case VK_FORMAT_S8_UINT:
96 props.stencil.view_format =
97 prefer_blendable ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
98 props.stencil.component_mask = BITFIELD_MASK(1);
99 break;
100 case VK_FORMAT_D24_UNORM_S8_UINT:
101 if (panvk_image_is_planar_depth_stencil(img)) {
102 if (img->planes[0].image.props.format ==
103 PIPE_FORMAT_Z24_UNORM_PACKED) {
104 props.depth.view_format =
105 prefer_blendable ? VK_FORMAT_R8G8B8_UNORM : VK_FORMAT_R8G8B8_UINT;
106 } else {
107 assert(img->planes[0].image.props.format ==
108 PIPE_FORMAT_Z24X8_UNORM);
109 props.depth.view_format = prefer_blendable ? VK_FORMAT_R8G8B8A8_UNORM
110 : VK_FORMAT_R8G8B8A8_UINT;
111 }
112 props.depth.component_mask = BITFIELD_MASK(3);
113 props.stencil.view_format =
114 prefer_blendable ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
115 props.stencil.component_mask = BITFIELD_BIT(0);
116 } else {
117 props.depth.view_format = prefer_blendable
118 ? VK_FORMAT_R8G8B8A8_UNORM
119 : VK_FORMAT_R8G8B8A8_UINT;
120 props.depth.component_mask = BITFIELD_MASK(3);
121 props.stencil.view_format = props.depth.view_format;
122 props.stencil.component_mask = BITFIELD_BIT(3);
123 }
124 break;
125 case VK_FORMAT_X8_D24_UNORM_PACK32:
126 props.depth.view_format =
127 prefer_blendable ? VK_FORMAT_R8G8B8A8_UNORM : VK_FORMAT_R8G8B8A8_UINT;
128 props.depth.component_mask = BITFIELD_MASK(3);
129 break;
130 case VK_FORMAT_D32_SFLOAT_S8_UINT:
131 assert(panvk_image_is_planar_depth_stencil(img));
132 props.depth.view_format =
133 prefer_blendable ? VK_FORMAT_R8G8B8A8_UNORM : VK_FORMAT_R8G8B8A8_UINT;
134 props.depth.component_mask = BITFIELD_MASK(4);
135 props.stencil.view_format =
136 prefer_blendable ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
137 props.stencil.component_mask = BITFIELD_BIT(0);
138 break;
139 case VK_FORMAT_D16_UNORM:
140 props.depth.view_format =
141 prefer_blendable ? VK_FORMAT_R8G8_UNORM : VK_FORMAT_R8G8_UINT;
142 props.depth.component_mask = BITFIELD_MASK(2);
143 break;
144 case VK_FORMAT_D32_SFLOAT:
145 props.depth.view_format = prefer_blendable ? VK_FORMAT_R8G8B8A8_UNORM
146 : VK_FORMAT_R8G8B8A8_UINT;
147 props.depth.component_mask = BITFIELD_MASK(4);
148 break;
149 default:
150 assert(!"Invalid ZS format");
151 break;
152 }
153 } else if (ycbcr_info) {
154 for (uint32_t p = 0; p < ycbcr_info->n_planes; p++) {
155 unsigned blk_sz =
156 vk_format_get_blocksize(ycbcr_info->planes[p].format);
157 if (preserve_img_fmt) {
158 props.plane[p].view_format = ycbcr_info->planes[p].format;
159 } else {
160 props.plane[p].view_format =
161 /* there are no blendable formats with blk_sz > 4 */
162 (prefer_blendable && blk_sz <= 4) ?
163 panvk_meta_get_blendable_format_for_blk_size(blk_sz) :
164 panvk_meta_get_uint_format_for_blk_size(blk_sz);
165 }
166 }
167 } else {
168 unsigned blk_sz = util_format_get_blocksize(pfmt);
169
170 if (preserve_img_fmt) {
171 props.color.view_format = img->vk.format;
172 } else {
173 props.color.view_format =
174 /* there are no blendable formats with blk_sz > 4 */
175 (prefer_blendable && blk_sz <= 4) ?
176 panvk_meta_get_blendable_format_for_blk_size(blk_sz) :
177 panvk_meta_get_uint_format_for_blk_size(blk_sz);
178 }
179 }
180
181 if (mod == DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED ||
182 drm_is_afbc(mod)) {
183 props.tile_size.width = 16;
184 props.tile_size.height = 16;
185 props.tile_size.depth = 1;
186 } else {
187 /* When linear, pretend we have a 1D-tile so we end up with a <64,1,1>
188 * workgroup. */
189 props.tile_size.width = 64;
190 props.tile_size.height = 1;
191 props.tile_size.depth = 1;
192 }
193
194 return props;
195 }
196
197 #if PAN_ARCH < 9
198 struct panvk_cmd_buffer;
199 struct panvk_descriptor_state;
200 struct panvk_device;
201 struct panvk_shader_variant;
202 struct panvk_shader_desc_state;
203
204 VkResult panvk_per_arch(meta_get_copy_desc_job)(
205 struct panvk_cmd_buffer *cmdbuf, const struct panvk_shader_variant *shader,
206 const struct panvk_descriptor_state *desc_state,
207 const struct panvk_shader_desc_state *shader_desc_state,
208 uint32_t attrib_buf_idx_offset, struct pan_ptr *job_desc);
209 #endif
210
211 void panvk_per_arch(transition_image_layout_sync_scope)(
212 const VkImageMemoryBarrier2 *barrier,
213 VkPipelineStageFlags2 *out_stages, VkAccessFlags2 *out_access);
214 void panvk_per_arch(cmd_transition_image_layout)(
215 VkCommandBuffer _cmdbuf,
216 const VkImageMemoryBarrier2 *barrier);
217
218 #endif