Debian Codegraph @

src/imagination/vulkan/pvr_formats.h

raw
1 /*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * 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 THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #ifndef PVR_FORMATS_H
25 #define PVR_FORMATS_H
26
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <vulkan/vulkan.h>
30
31 #include "pvr_macros.h"
32
33 #include "util/format/u_formats.h"
34 #include "vk_format.h"
35
36 struct pvr_device_info;
37
38 /* This is based on VkClearColorValue which is an array of RGBA, and on the
39 * output register usage for the biggest 32 bit 4 component formats which use up
40 * all 4 output registers.
41 * So this can be used for both unpacked RGBA value and to represent values
42 * packed according to the hardware (the accum format).
43 */
44 #define PVR_CLEAR_COLOR_ARRAY_SIZE 4
45
46 enum pvr_pbe_accum_format {
47 PVR_PBE_ACCUM_FORMAT_INVALID = 0, /* Explicitly treat 0 as invalid. */
48 PVR_PBE_ACCUM_FORMAT_U8,
49 PVR_PBE_ACCUM_FORMAT_S8,
50 PVR_PBE_ACCUM_FORMAT_U16,
51 PVR_PBE_ACCUM_FORMAT_S16,
52 PVR_PBE_ACCUM_FORMAT_F16,
53 PVR_PBE_ACCUM_FORMAT_F32,
54 PVR_PBE_ACCUM_FORMAT_UINT8,
55 PVR_PBE_ACCUM_FORMAT_UINT16,
56 PVR_PBE_ACCUM_FORMAT_UINT32,
57 PVR_PBE_ACCUM_FORMAT_SINT8,
58 PVR_PBE_ACCUM_FORMAT_SINT16,
59 PVR_PBE_ACCUM_FORMAT_SINT32,
60 /* Formats with medp shader output precision. */
61 PVR_PBE_ACCUM_FORMAT_UINT32_MEDP,
62 PVR_PBE_ACCUM_FORMAT_SINT32_MEDP,
63 PVR_PBE_ACCUM_FORMAT_U1010102,
64 PVR_PBE_ACCUM_FORMAT_U24,
65 };
66
67 /**
68 * Pixel related shader selector. The logic selecting the shader has to take
69 * into account the pixel related properties (controlling the conversion path in
70 * the shader) and the geometry related properties (controlling the sample
71 * position calcs). These two can be orthogonal.
72 *
73 * integer format conversions, bit depth : 8, 16, 32 per ch formats : signed,
74 * unsigned. Strategy: convert everything to U32 or S32 then USC pack. PBE just
75 * pass through.
76 *
77 * fixed point format conversions, bit depth 565, 1555, 555 etc. Strategy:
78 * fcnorm to 4 F32, then USC pack to F16F16. PBE converts to destination
79 *
80 * float/fixed format conversions
81 * strategy: fcnorm, then pack to f16 _when_ destination is not f32.
82 * fmt | unorm | flt |
83 * 8 | x | |
84 * 16 | x | x |
85 * 32 | x | x |
86 *
87 *
88 * non-merge type DS blit table
89 * **********************************************
90 * * * S8 D16 D24S8 D32 D32S8 *
91 * **********************************************
92 * * S8 * cpy i i i i *
93 * * D16 * i cpy i - i *
94 * * D24S8 * swiz - cpy (1) - *
95 * * D32 * i - i cpy i *
96 * * D32S8 * (2) - - cpy cpy *
97 * **********************************************
98 *
99 * merge with stencil pick type DS blit table
100 * **********************************************
101 * * * S8 D16 D24S8 D32 D32S8 *
102 * **********************************************
103 * * S8 * i i (1) i (2) *
104 * * D16 * i i i i i *
105 * * D24S8 * i i (3) i (4) *
106 * * D32 * i i i i i *
107 * * D32S8 * i i (5) i (6) *
108 * **********************************************
109 *
110 * merge with depth pick type DS blit table
111 * **********************************************
112 * * * S8 D16 D24S8 D32 D32S8 *
113 * **********************************************
114 * * S8 * i i i i i *
115 * * D16 * - - - - - *
116 * * D24S8 * - - (s) - - *
117 * * D32 * - - (1) - (2) *
118 * * D32S8 * - - - - (s) *
119 * **********************************************
120 *
121 * D formats are unpacked into a single register according to their format
122 * S formats are unpacked into a single register in U8
123 * D24S8 is in a single 32 bit register (as the PBE can't read it from
124 * unpacked.)
125 *
126 * Swizzles are applied on the TPU not the PBE because of potential
127 * accumulation i.e. a non-iterated shader doesn't know if it writes the output
128 * buffer for PBE emit or a second pass blend.
129 */
130 enum pvr_transfer_pbe_pixel_src {
131 PVR_TRANSFER_PBE_PIXEL_SRC_UU8888 = 0,
132 PVR_TRANSFER_PBE_PIXEL_SRC_US8888 = 1,
133 PVR_TRANSFER_PBE_PIXEL_SRC_UU16U16 = 2,
134 PVR_TRANSFER_PBE_PIXEL_SRC_US16S16 = 3,
135 PVR_TRANSFER_PBE_PIXEL_SRC_SU8888 = 4,
136 PVR_TRANSFER_PBE_PIXEL_SRC_SS8888 = 5,
137 PVR_TRANSFER_PBE_PIXEL_SRC_SU16U16 = 6,
138 PVR_TRANSFER_PBE_PIXEL_SRC_SS16S16 = 7,
139
140 PVR_TRANSFER_PBE_PIXEL_SRC_UU1010102 = 8,
141 PVR_TRANSFER_PBE_PIXEL_SRC_SU1010102 = 9,
142 PVR_TRANSFER_PBE_PIXEL_SRC_RBSWAP_UU1010102 = 10,
143 PVR_TRANSFER_PBE_PIXEL_SRC_RBSWAP_SU1010102 = 11,
144
145 PVR_TRANSFER_PBE_PIXEL_SRC_SU32U32 = 12,
146 PVR_TRANSFER_PBE_PIXEL_SRC_S4XU32 = 13,
147 PVR_TRANSFER_PBE_PIXEL_SRC_US32S32 = 14,
148 PVR_TRANSFER_PBE_PIXEL_SRC_U4XS32 = 15,
149
150 PVR_TRANSFER_PBE_PIXEL_SRC_F16F16 = 16,
151 PVR_TRANSFER_PBE_PIXEL_SRC_U16NORM = 17,
152 PVR_TRANSFER_PBE_PIXEL_SRC_S16NORM = 18,
153
154 PVR_TRANSFER_PBE_PIXEL_SRC_F32X4 = 19,
155 PVR_TRANSFER_PBE_PIXEL_SRC_F32X2 = 20,
156 PVR_TRANSFER_PBE_PIXEL_SRC_F32 = 21,
157
158 PVR_TRANSFER_PBE_PIXEL_SRC_RAW32 = 22,
159 PVR_TRANSFER_PBE_PIXEL_SRC_RAW64 = 23,
160 PVR_TRANSFER_PBE_PIXEL_SRC_RAW128 = 24,
161
162 /* f16 to U8 conversion in shader. */
163 PVR_TRANSFER_PBE_PIXEL_SRC_F16_U8 = 25,
164
165 PVR_TRANSFER_PBE_PIXEL_SRC_SWAP_LMSB = 26,
166 PVR_TRANSFER_PBE_PIXEL_SRC_MOV_BY45 = 27,
167
168 PVR_TRANSFER_PBE_PIXEL_SRC_D24S8 = 28,
169 PVR_TRANSFER_PBE_PIXEL_SRC_S8D24 = 29,
170 PVR_TRANSFER_PBE_PIXEL_SRC_D32S8 = 30,
171
172 /* D: D32_S8 */
173 PVR_TRANSFER_PBE_PIXEL_SRC_SMRG_S8_D32S8 = 31,
174 PVR_TRANSFER_PBE_PIXEL_SRC_SMRG_D24S8_D32S8 = 32,
175 PVR_TRANSFER_PBE_PIXEL_SRC_SMRG_D32S8_D32S8 = 33,
176 PVR_TRANSFER_PBE_PIXEL_SRC_DMRG_D32S8_D32S8 = 34,
177
178 /* D: D32 */
179 PVR_TRANSFER_PBE_PIXEL_SRC_CONV_D24_D32 = 35,
180 PVR_TRANSFER_PBE_PIXEL_SRC_CONV_D32U_D32F = 36,
181
182 /* D : D24_S8 */
183 PVR_TRANSFER_PBE_PIXEL_SRC_SMRG_S8_D24S8 = 37,
184 PVR_TRANSFER_PBE_PIXEL_SRC_SMRG_D24S8_D24S8 = 38,
185 PVR_TRANSFER_PBE_PIXEL_SRC_DMRG_D24S8_D24S8 = 39,
186 PVR_TRANSFER_PBE_PIXEL_SRC_CONV_D32_D24S8 = 40,
187 PVR_TRANSFER_PBE_PIXEL_SRC_DMRG_D32_D24S8 = 41,
188 PVR_TRANSFER_PBE_PIXEL_SRC_DMRG_D32U_D24S8 = 42,
189
190 /* ob0 holds Y and ob0 holds U or V. */
191 PVR_TRANSFER_PBE_PIXEL_SRC_YUV_PACKED = 43,
192
193 /* ob0 holds Y, ob1 holds U, ob2 holds V. */
194 PVR_TRANSFER_PBE_PIXEL_SRC_Y_U_V = 44,
195
196 PVR_TRANSFER_PBE_PIXEL_SRC_MASK16 = 45,
197 PVR_TRANSFER_PBE_PIXEL_SRC_MASK32 = 46,
198 PVR_TRANSFER_PBE_PIXEL_SRC_MASK48 = 47,
199 PVR_TRANSFER_PBE_PIXEL_SRC_MASK64 = 48,
200 PVR_TRANSFER_PBE_PIXEL_SRC_MASK96 = 49,
201 PVR_TRANSFER_PBE_PIXEL_SRC_MASK128 = 50,
202
203 PVR_TRANSFER_PBE_PIXEL_SRC_CONV_S8D24_D24S8 = 51,
204
205 /* ob0 holds Y and ob0 holds V or U. */
206 PVR_TRANSFER_PBE_PIXEL_SRC_YVU_PACKED = 52,
207
208 /* ob0 holds Y, ob1 holds UV interleaved. */
209 PVR_TRANSFER_PBE_PIXEL_SRC_Y_UV_INTERLEAVED = 53,
210
211 /* FIXME: This changes for other BVNC's which may change the hashing logic
212 * in pvr_hash_shader.
213 */
214 PVR_TRANSFER_PBE_PIXEL_SRC_NUM = 54,
215 };
216
217 #define PVR_BIND_VERTEX_BUFFER BITFIELD_BIT(0)
218 #define PVR_BIND_SAMPLER_VIEW BITFIELD_BIT(1)
219 #define PVR_BIND_RENDER_TARGET BITFIELD_BIT(2)
220 #define PVR_BIND_DEPTH_STENCIL BITFIELD_BIT(3)
221 #define PVR_BIND_STORAGE_IMAGE BITFIELD_BIT(4)
222
223 struct pvr_format {
224 uint32_t tex_format;
225 uint32_t depth_tex_format;
226 uint32_t stencil_tex_format;
227 uint32_t bind;
228 };
229
230 struct pvr_format_table {
231 const struct pvr_format *formats;
232 unsigned count;
233 };
234
235 struct util_format_description;
236
237 const uint8_t *
238 pvr_get_format_swizzle_for_tpu(const struct util_format_description *desc);
239 const uint8_t *pvr_get_format_swizzle(VkFormat vk_format);
240 uint32_t pvr_rogue_get_pbe_accum_format(VkFormat vk_format);
241 uint32_t pvr_get_pbe_accum_format_size_in_bytes(VkFormat vk_format);
242 void pvr_get_hw_clear_color(VkFormat vk_format,
243 VkClearColorValue value,
244 uint32_t packed_out[static const 4]);
245
246 uint32_t pvr_pbe_pixel_num_loads(enum pvr_transfer_pbe_pixel_src pbe_format);
247 bool pvr_pbe_pixel_is_norm(enum pvr_transfer_pbe_pixel_src pbe_format);
248 uint32_t pvr_pbe_pixel_size(enum pvr_transfer_pbe_pixel_src pbe_format);
249
250 static inline bool pvr_vk_format_has_32bit_component(VkFormat vk_format)
251 {
252 const struct util_format_description *desc =
253 vk_format_description(vk_format);
254
255 for (uint32_t i = 0; i < desc->nr_channels; i++) {
256 if (desc->channel[i].size == 32U)
257 return true;
258 }
259
260 return false;
261 }
262
263 static inline bool pvr_vk_format_is_fully_normalized(VkFormat vk_format)
264 {
265 const struct util_format_description *desc =
266 vk_format_description(vk_format);
267
268 for (uint32_t i = 0; i < desc->nr_channels; i++) {
269 if (!desc->channel[i].normalized)
270 return false;
271 }
272
273 return true;
274 }
275
276 static inline bool
277 pvr_vk_format_is_combined_ds(VkFormat format)
278 {
279 return vk_format_has_depth(format) && vk_format_has_stencil(format);
280 }
281
282 static inline uint32_t
283 pvr_vk_format_get_common_color_channel_count(VkFormat src_format,
284 VkFormat dst_format)
285 {
286 const struct util_format_description *dst_desc =
287 vk_format_description(dst_format);
288 const struct util_format_description *src_desc =
289 vk_format_description(src_format);
290 uint32_t count = 0;
291
292 /* Check if destination format is alpha only and source format has alpha
293 * channel.
294 */
295 if (util_format_is_alpha(vk_format_to_pipe_format(dst_format))) {
296 count = 1;
297 } else if (dst_desc->nr_channels <= src_desc->nr_channels) {
298 for (uint32_t i = 0; i < dst_desc->nr_channels; i++) {
299 enum pipe_swizzle swizzle = dst_desc->swizzle[i];
300
301 if (swizzle > PIPE_SWIZZLE_W)
302 continue;
303
304 for (uint32_t j = 0; j < src_desc->nr_channels; j++) {
305 if (src_desc->swizzle[j] == swizzle) {
306 count++;
307 break;
308 }
309 }
310 }
311 } else {
312 count = dst_desc->nr_channels;
313 }
314
315 return count;
316 }
317
318 #ifdef PVR_PER_ARCH
319
320 struct pvr_format_table PVR_PER_ARCH(get_format_table)(void);
321 # define pvr_arch_get_format_table PVR_PER_ARCH(get_format_table)
322
323 uint32_t PVR_PER_ARCH(get_tex_format)(VkFormat vk_format);
324 # define pvr_arch_get_tex_format PVR_PER_ARCH(get_tex_format)
325
326 uint32_t PVR_PER_ARCH(get_tex_format_aspect)(VkFormat vk_format,
327 VkImageAspectFlags aspect_mask);
328 # define pvr_arch_get_tex_format_aspect PVR_PER_ARCH(get_tex_format_aspect)
329
330 uint32_t PVR_PER_ARCH(get_pbe_packmode)(VkFormat vk_format);
331 # define pvr_arch_get_pbe_packmode PVR_PER_ARCH(get_pbe_packmode)
332
333 uint32_t PVR_PER_ARCH(get_pbe_accum_format)(VkFormat vk_format);
334 # define pvr_arch_get_pbe_accum_format PVR_PER_ARCH(get_pbe_accum_format)
335
336 bool PVR_PER_ARCH(format_is_pbe_downscalable)(
337 const struct pvr_device_info *dev_info,
338 VkFormat vk_format);
339 # define pvr_arch_format_is_pbe_downscalable \
340 PVR_PER_ARCH(format_is_pbe_downscalable)
341
342 #endif /* PVR_PER_ARCH */
343
344 #endif /* PVR_FORMATS_H */