1 /*
2 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors:
25 * Rob Clark <robclark@freedesktop.org>
26 */
27
28 #include "pipe/p_defines.h"
29 #include "util/format/u_format.h"
30
31 #include "fd6_format_table.h"
32
33 /* Specifies the table of all the formats and their features. Also supplies
34 * the helpers that look up various data in those tables.
35 */
36
37 struct fd6_format {
38 enum a6xx_format vtx;
39 enum a6xx_format tex;
40 enum a6xx_format rb;
41 enum a3xx_color_swap swap;
42 boolean present;
43 };
44
45 #define FMT(pipe, vtxfmt, texfmt, rbfmt, swapfmt) \
46 [PIPE_FORMAT_##pipe] = {.present = 1, \
47 .vtx = FMT6_##vtxfmt, \
48 .tex = FMT6_##texfmt, \
49 .rb = FMT6_##rbfmt, \
50 .swap = swapfmt}
51
52 /* vertex + texture + color */
53 #define VTC(pipe, fmt, swapfmt) FMT(pipe, fmt, fmt, fmt, swapfmt)
54
55 #define _TC(pipe, fmt, swapfmt) FMT(pipe, NONE, fmt, fmt, swapfmt)
56 #define _T_(pipe, fmt, swapfmt) FMT(pipe, NONE, fmt, NONE, swapfmt)
57 #define VT_(pipe, fmt, swapfmt) FMT(pipe, fmt, fmt, NONE, swapfmt)
58 #define V__(pipe, fmt, swapfmt) FMT(pipe, fmt, NONE, NONE, swapfmt)
59
60 /* clang-format off */
61 static const struct fd6_format formats[PIPE_FORMAT_COUNT] = {
62 /* 8-bit */
63 VTC(R8_UNORM, 8_UNORM, WZYX),
64 VTC(R8_SNORM, 8_SNORM, WZYX),
65 VTC(R8_UINT, 8_UINT, WZYX),
66 VTC(R8_SINT, 8_SINT, WZYX),
67 V__(R8_USCALED, 8_UINT, WZYX),
68 V__(R8_SSCALED, 8_SINT, WZYX),
69 _TC(R8_SRGB, 8_UNORM, WZYX),
70
71 FMT(A8_UNORM, NONE, 8_UNORM, A8_UNORM, WZYX),
72 _TC(L8_UNORM, 8_UNORM, WZYX),
73 _T_(I8_UNORM, 8_UNORM, WZYX),
74
75 _T_(A8_UINT, 8_UINT, WZYX),
76 _T_(A8_SINT, 8_SINT, WZYX),
77 _T_(L8_UINT, 8_UINT, WZYX),
78 _T_(L8_SINT, 8_SINT, WZYX),
79 _T_(I8_UINT, 8_UINT, WZYX),
80 _T_(I8_SINT, 8_SINT, WZYX),
81
82 _TC(S8_UINT, 8_UINT, WZYX),
83
84 /* 16-bit */
85 VTC(R16_UNORM, 16_UNORM, WZYX),
86 VTC(R16_SNORM, 16_SNORM, WZYX),
87 VTC(R16_UINT, 16_UINT, WZYX),
88 VTC(R16_SINT, 16_SINT, WZYX),
89 V__(R16_USCALED, 16_UINT, WZYX),
90 V__(R16_SSCALED, 16_SINT, WZYX),
91 VTC(R16_FLOAT, 16_FLOAT, WZYX),
92 _TC(Z16_UNORM, 16_UNORM, WZYX),
93
94 _T_(A16_UNORM, 16_UNORM, WZYX),
95 _T_(A16_SNORM, 16_SNORM, WZYX),
96 _T_(A16_UINT, 16_UINT, WZYX),
97 _T_(A16_SINT, 16_SINT, WZYX),
98 _T_(L16_UNORM, 16_UNORM, WZYX),
99 _T_(L16_SNORM, 16_SNORM, WZYX),
100 _T_(L16_UINT, 16_UINT, WZYX),
101 _T_(L16_SINT, 16_SINT, WZYX),
102 _T_(I16_UNORM, 16_UNORM, WZYX),
103 _T_(I16_SNORM, 16_SNORM, WZYX),
104 _T_(I16_UINT, 16_UINT, WZYX),
105 _T_(I16_SINT, 16_SINT, WZYX),
106
107 VTC(R8G8_UNORM, 8_8_UNORM, WZYX),
108 VTC(R8G8_SNORM, 8_8_SNORM, WZYX),
109 VTC(R8G8_UINT, 8_8_UINT, WZYX),
110 VTC(R8G8_SINT, 8_8_SINT, WZYX),
111 V__(R8G8_USCALED, 8_8_UINT, WZYX),
112 V__(R8G8_SSCALED, 8_8_SINT, WZYX),
113 _TC(R8G8_SRGB, 8_8_UNORM, WZYX),
114
115 _T_(L8A8_UINT, 8_8_UINT, WZYX),
116 _T_(L8A8_SINT, 8_8_SINT, WZYX),
117
118 _TC(R5G6B5_UNORM, 5_6_5_UNORM, WZYX),
119 _TC(B5G6R5_UNORM, 5_6_5_UNORM, WXYZ),
120
121 _TC(B5G5R5A1_UNORM, 5_5_5_1_UNORM, WXYZ),
122 _TC(B5G5R5X1_UNORM, 5_5_5_1_UNORM, WXYZ),
123 _TC(A1R5G5B5_UNORM, 5_5_5_1_UNORM, ZYXW),
124 _TC(A1B5G5R5_UNORM, 5_5_5_1_UNORM, XYZW),
125
126 _TC(R4G4B4A4_UNORM, 4_4_4_4_UNORM, WZYX),
127 _TC(B4G4R4A4_UNORM, 4_4_4_4_UNORM, WXYZ),
128 _TC(A4R4G4B4_UNORM, 4_4_4_4_UNORM, ZYXW),
129 _TC(A4B4G4R4_UNORM, 4_4_4_4_UNORM, XYZW),
130
131 /* 24-bit */
132 V__(R8G8B8_UNORM, 8_8_8_UNORM, WZYX),
133 V__(R8G8B8_SNORM, 8_8_8_SNORM, WZYX),
134 V__(R8G8B8_UINT, 8_8_8_UINT, WZYX),
135 V__(R8G8B8_SINT, 8_8_8_SINT, WZYX),
136 V__(R8G8B8_USCALED, 8_8_8_UINT, WZYX),
137 V__(R8G8B8_SSCALED, 8_8_8_SINT, WZYX),
138
139 /* 32-bit */
140 V__(R32_UNORM, 32_UNORM, WZYX),
141 V__(R32_SNORM, 32_SNORM, WZYX),
142 VTC(R32_UINT, 32_UINT, WZYX),
143 VTC(R32_SINT, 32_SINT, WZYX),
144 V__(R32_USCALED, 32_UINT, WZYX),
145 V__(R32_SSCALED, 32_SINT, WZYX),
146 VTC(R32_FLOAT, 32_FLOAT, WZYX),
147 V__(R32_FIXED, 32_FIXED, WZYX),
148
149 _T_(A32_UINT, 32_UINT, WZYX),
150 _T_(A32_SINT, 32_SINT, WZYX),
151 _T_(L32_UINT, 32_UINT, WZYX),
152 _T_(L32_SINT, 32_SINT, WZYX),
153 _T_(I32_UINT, 32_UINT, WZYX),
154 _T_(I32_SINT, 32_SINT, WZYX),
155
156 VTC(R16G16_UNORM, 16_16_UNORM, WZYX),
157 VTC(R16G16_SNORM, 16_16_SNORM, WZYX),
158 VTC(R16G16_UINT, 16_16_UINT, WZYX),
159 VTC(R16G16_SINT, 16_16_SINT, WZYX),
160 V__(R16G16_USCALED, 16_16_UINT, WZYX),
161 V__(R16G16_SSCALED, 16_16_SINT, WZYX),
162 VTC(R16G16_FLOAT, 16_16_FLOAT, WZYX),
163
164 _T_(L16A16_UNORM, 16_16_UNORM, WZYX),
165 _T_(L16A16_SNORM, 16_16_SNORM, WZYX),
166 _T_(L16A16_UINT, 16_16_UINT, WZYX),
167 _T_(L16A16_SINT, 16_16_SINT, WZYX),
168
169 VTC(R8G8B8A8_UNORM, 8_8_8_8_UNORM, WZYX),
170 _TC(R8G8B8X8_UNORM, 8_8_8_8_UNORM, WZYX),
171 _TC(R8G8B8A8_SRGB, 8_8_8_8_UNORM, WZYX),
172 _TC(R8G8B8X8_SRGB, 8_8_8_8_UNORM, WZYX),
173 VTC(R8G8B8A8_SNORM, 8_8_8_8_SNORM, WZYX),
174 VTC(R8G8B8A8_UINT, 8_8_8_8_UINT, WZYX),
175 VTC(R8G8B8A8_SINT, 8_8_8_8_SINT, WZYX),
176 V__(R8G8B8A8_USCALED, 8_8_8_8_UINT, WZYX),
177 V__(R8G8B8A8_SSCALED, 8_8_8_8_SINT, WZYX),
178
179 VTC(B8G8R8A8_UNORM, 8_8_8_8_UNORM, WXYZ),
180 _TC(B8G8R8X8_UNORM, 8_8_8_8_UNORM, WXYZ),
181 _TC(B8G8R8A8_SRGB, 8_8_8_8_UNORM, WXYZ),
182 _TC(B8G8R8X8_SRGB, 8_8_8_8_UNORM, WXYZ),
183 VTC(B8G8R8A8_SNORM, 8_8_8_8_SNORM, WXYZ),
184 VTC(B8G8R8A8_UINT, 8_8_8_8_UINT, WXYZ),
185 VTC(B8G8R8A8_SINT, 8_8_8_8_SINT, WXYZ),
186 V__(B8G8R8A8_USCALED, 8_8_8_8_UINT, WXYZ),
187 V__(B8G8R8A8_SSCALED, 8_8_8_8_SINT, WXYZ),
188
189 VTC(A8B8G8R8_UNORM, 8_8_8_8_UNORM, XYZW),
190 _TC(X8B8G8R8_UNORM, 8_8_8_8_UNORM, XYZW),
191 _TC(A8B8G8R8_SRGB, 8_8_8_8_UNORM, XYZW),
192 _TC(X8B8G8R8_SRGB, 8_8_8_8_UNORM, XYZW),
193
194 VTC(A8R8G8B8_UNORM, 8_8_8_8_UNORM, ZYXW),
195 _TC(X8R8G8B8_UNORM, 8_8_8_8_UNORM, ZYXW),
196 _TC(A8R8G8B8_SRGB, 8_8_8_8_UNORM, ZYXW),
197 _TC(X8R8G8B8_SRGB, 8_8_8_8_UNORM, ZYXW),
198
199 FMT(R10G10B10A2_UNORM, 10_10_10_2_UNORM, 10_10_10_2_UNORM, 10_10_10_2_UNORM_DEST, WZYX),
200 FMT(B10G10R10A2_UNORM, 10_10_10_2_UNORM, 10_10_10_2_UNORM, 10_10_10_2_UNORM_DEST, WXYZ),
201 FMT(B10G10R10X2_UNORM, NONE, 10_10_10_2_UNORM, 10_10_10_2_UNORM_DEST, WXYZ),
202 V__(R10G10B10A2_SNORM, 10_10_10_2_SNORM, WZYX),
203 V__(B10G10R10A2_SNORM, 10_10_10_2_SNORM, WXYZ),
204 VTC(R10G10B10A2_UINT, 10_10_10_2_UINT, WZYX),
205 V__(R10G10B10A2_SINT, 10_10_10_2_SINT, WZYX),
206 VTC(B10G10R10A2_UINT, 10_10_10_2_UINT, WXYZ),
207 V__(B10G10R10A2_SINT, 10_10_10_2_SINT, WXYZ),
208 V__(R10G10B10A2_USCALED, 10_10_10_2_UINT, WZYX),
209 V__(B10G10R10A2_USCALED, 10_10_10_2_UINT, WXYZ),
210 V__(R10G10B10A2_SSCALED, 10_10_10_2_SINT, WZYX),
211 V__(B10G10R10A2_SSCALED, 10_10_10_2_SINT, WXYZ),
212
213 VTC(R11G11B10_FLOAT, 11_11_10_FLOAT, WZYX),
214 _T_(R9G9B9E5_FLOAT, 9_9_9_E5_FLOAT, WZYX),
215
216 _TC(Z24X8_UNORM, Z24_UNORM_S8_UINT, WZYX),
217 _TC(X24S8_UINT, 8_8_8_8_UINT, WZYX),
218 _TC(Z24_UNORM_S8_UINT, Z24_UNORM_S8_UINT, WZYX),
219 _TC(Z32_FLOAT, 32_FLOAT, WZYX),
220 _TC(Z32_FLOAT_S8X24_UINT, 32_FLOAT, WZYX),
221 _TC(X32_S8X24_UINT, 8_UINT, WZYX),
222
223 /* special format for blits: */
224 _TC(Z24_UNORM_S8_UINT_AS_R8G8B8A8, Z24_UNORM_S8_UINT_AS_R8G8B8A8, WZYX),
225
226 /* 48-bit */
227 V__(R16G16B16_UNORM, 16_16_16_UNORM, WZYX),
228 V__(R16G16B16_SNORM, 16_16_16_SNORM, WZYX),
229 V__(R16G16B16_UINT, 16_16_16_UINT, WZYX),
230 V__(R16G16B16_SINT, 16_16_16_SINT, WZYX),
231 V__(R16G16B16_USCALED, 16_16_16_UINT, WZYX),
232 V__(R16G16B16_SSCALED, 16_16_16_SINT, WZYX),
233 V__(R16G16B16_FLOAT, 16_16_16_FLOAT, WZYX),
234
235 /* 64-bit */
236 VTC(R16G16B16A16_UNORM, 16_16_16_16_UNORM, WZYX),
237 VTC(R16G16B16X16_UNORM, 16_16_16_16_UNORM, WZYX),
238 VTC(R16G16B16A16_SNORM, 16_16_16_16_SNORM, WZYX),
239 VTC(R16G16B16X16_SNORM, 16_16_16_16_SNORM, WZYX),
240 VTC(R16G16B16A16_UINT, 16_16_16_16_UINT, WZYX),
241 VTC(R16G16B16X16_UINT, 16_16_16_16_UINT, WZYX),
242 VTC(R16G16B16A16_SINT, 16_16_16_16_SINT, WZYX),
243 VTC(R16G16B16X16_SINT, 16_16_16_16_SINT, WZYX),
244 V__(R16G16B16A16_USCALED, 16_16_16_16_UINT, WZYX),
245 V__(R16G16B16A16_SSCALED, 16_16_16_16_SINT, WZYX),
246 VTC(R16G16B16A16_FLOAT, 16_16_16_16_FLOAT, WZYX),
247 VTC(R16G16B16X16_FLOAT, 16_16_16_16_FLOAT, WZYX),
248
249 V__(R32G32_UNORM, 32_32_UNORM, WZYX),
250 V__(R32G32_SNORM, 32_32_SNORM, WZYX),
251 VTC(R32G32_UINT, 32_32_UINT, WZYX),
252 VTC(R32G32_SINT, 32_32_SINT, WZYX),
253 V__(R32G32_USCALED, 32_32_UINT, WZYX),
254 V__(R32G32_SSCALED, 32_32_SINT, WZYX),
255 VTC(R32G32_FLOAT, 32_32_FLOAT, WZYX),
256 V__(R32G32_FIXED, 32_32_FIXED, WZYX),
257
258 _T_(L32A32_UINT, 32_32_UINT, WZYX),
259 _T_(L32A32_SINT, 32_32_SINT, WZYX),
260
261 /* 96-bit */
262 V__(R32G32B32_UNORM, 32_32_32_UNORM, WZYX),
263 V__(R32G32B32_SNORM, 32_32_32_SNORM, WZYX),
264 VT_(R32G32B32_UINT, 32_32_32_UINT, WZYX),
265 VT_(R32G32B32_SINT, 32_32_32_SINT, WZYX),
266 V__(R32G32B32_USCALED, 32_32_32_UINT, WZYX),
267 V__(R32G32B32_SSCALED, 32_32_32_SINT, WZYX),
268 VT_(R32G32B32_FLOAT, 32_32_32_FLOAT, WZYX),
269 V__(R32G32B32_FIXED, 32_32_32_FIXED, WZYX),
270
271 /* 128-bit */
272 V__(R32G32B32A32_UNORM, 32_32_32_32_UNORM, WZYX),
273 V__(R32G32B32A32_SNORM, 32_32_32_32_SNORM, WZYX),
274 VTC(R32G32B32A32_UINT, 32_32_32_32_UINT, WZYX),
275 _TC(R32G32B32X32_UINT, 32_32_32_32_UINT, WZYX),
276 VTC(R32G32B32A32_SINT, 32_32_32_32_SINT, WZYX),
277 _TC(R32G32B32X32_SINT, 32_32_32_32_SINT, WZYX),
278 V__(R32G32B32A32_USCALED, 32_32_32_32_UINT, WZYX),
279 V__(R32G32B32A32_SSCALED, 32_32_32_32_SINT, WZYX),
280 VTC(R32G32B32A32_FLOAT, 32_32_32_32_FLOAT, WZYX),
281 _TC(R32G32B32X32_FLOAT, 32_32_32_32_FLOAT, WZYX),
282 V__(R32G32B32A32_FIXED, 32_32_32_32_FIXED, WZYX),
283
284 /* compressed */
285 _T_(ETC1_RGB8, ETC1, WZYX),
286 _T_(ETC2_RGB8, ETC2_RGB8, WZYX),
287 _T_(ETC2_SRGB8, ETC2_RGB8, WZYX),
288 _T_(ETC2_RGB8A1, ETC2_RGB8A1, WZYX),
289 _T_(ETC2_SRGB8A1, ETC2_RGB8A1, WZYX),
290 _T_(ETC2_RGBA8, ETC2_RGBA8, WZYX),
291 _T_(ETC2_SRGBA8, ETC2_RGBA8, WZYX),
292 _T_(ETC2_R11_UNORM, ETC2_R11_UNORM, WZYX),
293 _T_(ETC2_R11_SNORM, ETC2_R11_SNORM, WZYX),
294 _T_(ETC2_RG11_UNORM, ETC2_RG11_UNORM, WZYX),
295 _T_(ETC2_RG11_SNORM, ETC2_RG11_SNORM, WZYX),
296
297 _T_(DXT1_RGB, DXT1, WZYX),
298 _T_(DXT1_SRGB, DXT1, WZYX),
299 _T_(DXT1_RGBA, DXT1, WZYX),
300 _T_(DXT1_SRGBA, DXT1, WZYX),
301 _T_(DXT3_RGBA, DXT3, WZYX),
302 _T_(DXT3_SRGBA, DXT3, WZYX),
303 _T_(DXT5_RGBA, DXT5, WZYX),
304 _T_(DXT5_SRGBA, DXT5, WZYX),
305
306 _T_(BPTC_RGBA_UNORM, BPTC, WZYX),
307 _T_(BPTC_SRGBA, BPTC, WZYX),
308 _T_(BPTC_RGB_FLOAT, BPTC_FLOAT, WZYX),
309 _T_(BPTC_RGB_UFLOAT, BPTC_UFLOAT, WZYX),
310
311 _T_(RGTC1_UNORM, RGTC1_UNORM, WZYX),
312 _T_(RGTC1_SNORM, RGTC1_SNORM, WZYX),
313 _T_(RGTC2_UNORM, RGTC2_UNORM, WZYX),
314 _T_(RGTC2_SNORM, RGTC2_SNORM, WZYX),
315 _T_(LATC1_UNORM, RGTC1_UNORM, WZYX),
316 _T_(LATC1_SNORM, RGTC1_SNORM, WZYX),
317 _T_(LATC2_UNORM, RGTC2_UNORM, WZYX),
318 _T_(LATC2_SNORM, RGTC2_SNORM, WZYX),
319
320 _T_(ASTC_4x4, ASTC_4x4, WZYX),
321 _T_(ASTC_5x4, ASTC_5x4, WZYX),
322 _T_(ASTC_5x5, ASTC_5x5, WZYX),
323 _T_(ASTC_6x5, ASTC_6x5, WZYX),
324 _T_(ASTC_6x6, ASTC_6x6, WZYX),
325 _T_(ASTC_8x5, ASTC_8x5, WZYX),
326 _T_(ASTC_8x6, ASTC_8x6, WZYX),
327 _T_(ASTC_8x8, ASTC_8x8, WZYX),
328 _T_(ASTC_10x5, ASTC_10x5, WZYX),
329 _T_(ASTC_10x6, ASTC_10x6, WZYX),
330 _T_(ASTC_10x8, ASTC_10x8, WZYX),
331 _T_(ASTC_10x10, ASTC_10x10, WZYX),
332 _T_(ASTC_12x10, ASTC_12x10, WZYX),
333 _T_(ASTC_12x12, ASTC_12x12, WZYX),
334
335 _T_(ASTC_4x4_SRGB, ASTC_4x4, WZYX),
336 _T_(ASTC_5x4_SRGB, ASTC_5x4, WZYX),
337 _T_(ASTC_5x5_SRGB, ASTC_5x5, WZYX),
338 _T_(ASTC_6x5_SRGB, ASTC_6x5, WZYX),
339 _T_(ASTC_6x6_SRGB, ASTC_6x6, WZYX),
340 _T_(ASTC_8x5_SRGB, ASTC_8x5, WZYX),
341 _T_(ASTC_8x6_SRGB, ASTC_8x6, WZYX),
342 _T_(ASTC_8x8_SRGB, ASTC_8x8, WZYX),
343 _T_(ASTC_10x5_SRGB, ASTC_10x5, WZYX),
344 _T_(ASTC_10x6_SRGB, ASTC_10x6, WZYX),
345 _T_(ASTC_10x8_SRGB, ASTC_10x8, WZYX),
346 _T_(ASTC_10x10_SRGB, ASTC_10x10, WZYX),
347 _T_(ASTC_12x10_SRGB, ASTC_12x10, WZYX),
348 _T_(ASTC_12x12_SRGB, ASTC_12x12, WZYX),
349
350 _T_(R8G8_R8B8_UNORM, R8G8R8B8_422_UNORM, WZYX), /* YUYV */
351 _T_(G8R8_B8R8_UNORM, G8R8B8R8_422_UNORM, WZYX), /* UYVY */
352
353 _T_(R8_G8B8_420_UNORM, R8_G8B8_2PLANE_420_UNORM, WZYX),
354 _T_(R8_G8_B8_420_UNORM, R8_G8_B8_3PLANE_420_UNORM, WZYX),
355 };
356 /* clang-format on */
357
358 static enum a3xx_color_swap
fd6_pipe2swap(enum pipe_format format,enum a6xx_tile_mode tile_mode)359 fd6_pipe2swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
360 {
361 if (!formats[format].present)
362 return WZYX;
363
364 if (tile_mode)
365 return WZYX;
366
367 return formats[format].swap;
368 }
369
370 /* convert pipe format to vertex buffer format: */
371 enum a6xx_format
fd6_vertex_format(enum pipe_format format)372 fd6_vertex_format(enum pipe_format format)
373 {
374 if (!formats[format].present)
375 return FMT6_NONE;
376 return formats[format].vtx;
377 }
378
379 enum a3xx_color_swap
fd6_vertex_swap(enum pipe_format format)380 fd6_vertex_swap(enum pipe_format format)
381 {
382 return fd6_pipe2swap(format, TILE6_LINEAR);
383 }
384
385 /* convert pipe format to texture sampler format: */
386 enum a6xx_format
fd6_texture_format(enum pipe_format format,enum a6xx_tile_mode tile_mode)387 fd6_texture_format(enum pipe_format format, enum a6xx_tile_mode tile_mode)
388 {
389 if (!formats[format].present)
390 return FMT6_NONE;
391
392 /* Linear ARGB/ABGR1555 has a special format for sampling (tiled 1555/5551
393 * formats always have the same swizzle and layout).
394 */
395 if (!tile_mode) {
396 switch (format) {
397 case PIPE_FORMAT_A1R5G5B5_UNORM:
398 case PIPE_FORMAT_A1B5G5R5_UNORM:
399 return FMT6_1_5_5_5_UNORM;
400 default:
401 break;
402 }
403 }
404
405 return formats[format].tex;
406 }
407
408 enum a3xx_color_swap
fd6_texture_swap(enum pipe_format format,enum a6xx_tile_mode tile_mode)409 fd6_texture_swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
410 {
411 if (!tile_mode) {
412 switch (format) {
413 case PIPE_FORMAT_A1R5G5B5_UNORM:
414 return WZYX;
415 case PIPE_FORMAT_A1B5G5R5_UNORM:
416 return WXYZ;
417 default:
418 break;
419 }
420 }
421
422 return fd6_pipe2swap(format, tile_mode);
423 }
424
425 /* convert pipe format to MRT / copydest format used for render-target: */
426 enum a6xx_format
fd6_color_format(enum pipe_format format,enum a6xx_tile_mode tile_mode)427 fd6_color_format(enum pipe_format format, enum a6xx_tile_mode tile_mode)
428 {
429 if (!formats[format].present)
430 return FMT6_NONE;
431 return formats[format].rb;
432 }
433
434 enum a3xx_color_swap
fd6_color_swap(enum pipe_format format,enum a6xx_tile_mode tile_mode)435 fd6_color_swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
436 {
437 return fd6_pipe2swap(format, tile_mode);
438 }
439
440 enum a6xx_depth_format
fd6_pipe2depth(enum pipe_format format)441 fd6_pipe2depth(enum pipe_format format)
442 {
443 switch (format) {
444 case PIPE_FORMAT_Z16_UNORM:
445 return DEPTH6_16;
446 case PIPE_FORMAT_Z24X8_UNORM:
447 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
448 case PIPE_FORMAT_X8Z24_UNORM:
449 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
450 return DEPTH6_24_8;
451 case PIPE_FORMAT_Z32_FLOAT:
452 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
453 return DEPTH6_32;
454 default:
455 return ~0;
456 }
457 }
458