• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    _TC(Y8_UNORM,   NV12_Y,                      WZYX),
71 
72    FMT(A8_UNORM,   NONE, 8_UNORM, A8_UNORM,     WZYX),
73    _TC(L8_UNORM,   8_UNORM,                     WZYX),
74    _TC(L8_SNORM,   8_SNORM,                     WZYX),
75    _T_(I8_UNORM,   8_UNORM,                     WZYX),
76    _T_(I8_SNORM,   8_SNORM,                     WZYX),
77 
78    _T_(A8_UINT,    8_UINT,                      WZYX),
79    _T_(A8_SINT,    8_SINT,                      WZYX),
80    _T_(L8_UINT,    8_UINT,                      WZYX),
81    _T_(L8_SINT,    8_SINT,                      WZYX),
82    _T_(I8_UINT,    8_UINT,                      WZYX),
83    _T_(I8_SINT,    8_SINT,                      WZYX),
84 
85    _TC(S8_UINT,    8_UINT,                      WZYX),
86 
87    /* 16-bit */
88    VTC(R16_UNORM,   16_UNORM,                   WZYX),
89    VTC(R16_SNORM,   16_SNORM,                   WZYX),
90    VTC(R16_UINT,    16_UINT,                    WZYX),
91    VTC(R16_SINT,    16_SINT,                    WZYX),
92    V__(R16_USCALED, 16_UINT,                    WZYX),
93    V__(R16_SSCALED, 16_SINT,                    WZYX),
94    VTC(R16_FLOAT,   16_FLOAT,                   WZYX),
95    _TC(Z16_UNORM,   16_UNORM,                   WZYX),
96 
97    _T_(A16_UNORM,   16_UNORM,                   WZYX),
98    _T_(A16_SNORM,   16_SNORM,                   WZYX),
99    _T_(A16_UINT,    16_UINT,                    WZYX),
100    _T_(A16_SINT,    16_SINT,                    WZYX),
101    _T_(A16_FLOAT,   16_FLOAT,                   WZYX),
102    _T_(L16_UNORM,   16_UNORM,                   WZYX),
103    _T_(L16_SNORM,   16_SNORM,                   WZYX),
104    _T_(L16_UINT,    16_UINT,                    WZYX),
105    _T_(L16_SINT,    16_SINT,                    WZYX),
106    _T_(L16_FLOAT,   16_FLOAT,                   WZYX),
107    _T_(I16_UNORM,   16_UNORM,                   WZYX),
108    _T_(I16_SNORM,   16_SNORM,                   WZYX),
109    _T_(I16_UINT,    16_UINT,                    WZYX),
110    _T_(I16_SINT,    16_SINT,                    WZYX),
111    _T_(I16_FLOAT,   16_FLOAT,                   WZYX),
112 
113    VTC(R8G8_UNORM,   8_8_UNORM,                 WZYX),
114    VTC(R8G8_SNORM,   8_8_SNORM,                 WZYX),
115    VTC(R8G8_UINT,    8_8_UINT,                  WZYX),
116    VTC(R8G8_SINT,    8_8_SINT,                  WZYX),
117    V__(R8G8_USCALED, 8_8_UINT,                  WZYX),
118    V__(R8G8_SSCALED, 8_8_SINT,                  WZYX),
119    _TC(R8G8_SRGB,    8_8_UNORM,                 WZYX),
120 
121    _T_(L8A8_UNORM,   8_8_UNORM,                 WZYX),
122    _T_(L8A8_UINT,    8_8_UINT,                  WZYX),
123    _T_(L8A8_SINT,    8_8_SINT,                  WZYX),
124 
125    _TC(R5G6B5_UNORM,   5_6_5_UNORM,             WZYX),
126    _TC(B5G6R5_UNORM,   5_6_5_UNORM,             WXYZ),
127 
128    _TC(B5G5R5A1_UNORM, 5_5_5_1_UNORM,           WXYZ),
129    _TC(B5G5R5X1_UNORM, 5_5_5_1_UNORM,           WXYZ),
130    _TC(A1R5G5B5_UNORM, 5_5_5_1_UNORM,           ZYXW),
131    _TC(A1B5G5R5_UNORM, 5_5_5_1_UNORM,           XYZW),
132 
133    _TC(R4G4B4A4_UNORM, 4_4_4_4_UNORM,           WZYX),
134    _TC(B4G4R4A4_UNORM, 4_4_4_4_UNORM,           WXYZ),
135    _TC(A4R4G4B4_UNORM, 4_4_4_4_UNORM,           ZYXW),
136    _TC(A4B4G4R4_UNORM, 4_4_4_4_UNORM,           XYZW),
137 
138    /* 24-bit */
139    VT_(R8G8B8_UNORM,   8_8_8_UNORM,             WZYX),
140    VT_(R8G8B8_SNORM,   8_8_8_SNORM,             WZYX),
141    VT_(R8G8B8_UINT,    8_8_8_UINT,              WZYX),
142    VT_(R8G8B8_SINT,    8_8_8_SINT,              WZYX),
143    V__(R8G8B8_USCALED, 8_8_8_UINT,              WZYX),
144    V__(R8G8B8_SSCALED, 8_8_8_SINT,              WZYX),
145 
146    /* 32-bit */
147    V__(R32_UNORM,   32_UNORM,                   WZYX),
148    V__(R32_SNORM,   32_SNORM,                   WZYX),
149    VTC(R32_UINT,    32_UINT,                    WZYX),
150    VTC(R32_SINT,    32_SINT,                    WZYX),
151    V__(R32_USCALED, 32_UINT,                    WZYX),
152    V__(R32_SSCALED, 32_SINT,                    WZYX),
153    VTC(R32_FLOAT,   32_FLOAT,                   WZYX),
154    V__(R32_FIXED,   32_FIXED,                   WZYX),
155 
156    _T_(A32_UINT,    32_UINT,                    WZYX),
157    _T_(A32_SINT,    32_SINT,                    WZYX),
158    _T_(A32_FLOAT,   32_FLOAT,                   WZYX),
159    _T_(L32_UINT,    32_UINT,                    WZYX),
160    _T_(L32_SINT,    32_SINT,                    WZYX),
161    _T_(L32_FLOAT,   32_FLOAT,                   WZYX),
162    _T_(I32_UINT,    32_UINT,                    WZYX),
163    _T_(I32_SINT,    32_SINT,                    WZYX),
164    _T_(I32_FLOAT,   32_FLOAT,                   WZYX),
165 
166    VTC(R16G16_UNORM,   16_16_UNORM,             WZYX),
167    VTC(R16G16_SNORM,   16_16_SNORM,             WZYX),
168    VTC(R16G16_UINT,    16_16_UINT,              WZYX),
169    VTC(R16G16_SINT,    16_16_SINT,              WZYX),
170    V__(R16G16_USCALED, 16_16_UINT,              WZYX),
171    V__(R16G16_SSCALED, 16_16_SINT,              WZYX),
172    VTC(R16G16_FLOAT,   16_16_FLOAT,             WZYX),
173 
174    _T_(L16A16_UNORM,   16_16_UNORM,             WZYX),
175    _T_(L16A16_SNORM,   16_16_SNORM,             WZYX),
176    _T_(L16A16_UINT,    16_16_UINT,              WZYX),
177    _T_(L16A16_SINT,    16_16_SINT,              WZYX),
178    _T_(L16A16_FLOAT,   16_16_FLOAT,             WZYX),
179 
180    VTC(R8G8B8A8_UNORM,   8_8_8_8_UNORM,         WZYX),
181    _TC(R8G8B8X8_UNORM,   8_8_8_8_UNORM,         WZYX),
182    _TC(R8G8B8A8_SRGB,    8_8_8_8_UNORM,         WZYX),
183    _TC(R8G8B8X8_SRGB,    8_8_8_8_UNORM,         WZYX),
184    VTC(R8G8B8A8_SNORM,   8_8_8_8_SNORM,         WZYX),
185    VTC(R8G8B8A8_UINT,    8_8_8_8_UINT,          WZYX),
186    VTC(R8G8B8A8_SINT,    8_8_8_8_SINT,          WZYX),
187    V__(R8G8B8A8_USCALED, 8_8_8_8_UINT,          WZYX),
188    V__(R8G8B8A8_SSCALED, 8_8_8_8_SINT,          WZYX),
189 
190    VTC(B8G8R8A8_UNORM,   8_8_8_8_UNORM,         WXYZ),
191    _TC(B8G8R8X8_UNORM,   8_8_8_8_UNORM,         WXYZ),
192    _TC(B8G8R8A8_SRGB,    8_8_8_8_UNORM,         WXYZ),
193    _TC(B8G8R8X8_SRGB,    8_8_8_8_UNORM,         WXYZ),
194    VTC(B8G8R8A8_SNORM,   8_8_8_8_SNORM,         WXYZ),
195    VTC(B8G8R8A8_UINT,    8_8_8_8_UINT,          WXYZ),
196    VTC(B8G8R8A8_SINT,    8_8_8_8_SINT,          WXYZ),
197    V__(B8G8R8A8_USCALED, 8_8_8_8_UINT,          WXYZ),
198    V__(B8G8R8A8_SSCALED, 8_8_8_8_SINT,          WXYZ),
199 
200    VTC(A8B8G8R8_UNORM,   8_8_8_8_UNORM,         XYZW),
201    _TC(X8B8G8R8_UNORM,   8_8_8_8_UNORM,         XYZW),
202    _TC(A8B8G8R8_SRGB,    8_8_8_8_UNORM,         XYZW),
203    _TC(X8B8G8R8_SRGB,    8_8_8_8_UNORM,         XYZW),
204 
205    VTC(A8R8G8B8_UNORM,   8_8_8_8_UNORM,         ZYXW),
206    _TC(X8R8G8B8_UNORM,   8_8_8_8_UNORM,         ZYXW),
207    _TC(A8R8G8B8_SRGB,    8_8_8_8_UNORM,         ZYXW),
208    _TC(X8R8G8B8_SRGB,    8_8_8_8_UNORM,         ZYXW),
209 
210    FMT(R10G10B10A2_UNORM, 10_10_10_2_UNORM, 10_10_10_2_UNORM, 10_10_10_2_UNORM_DEST, WZYX),
211    FMT(B10G10R10A2_UNORM, 10_10_10_2_UNORM, 10_10_10_2_UNORM, 10_10_10_2_UNORM_DEST, WXYZ),
212    FMT(B10G10R10X2_UNORM, NONE,             10_10_10_2_UNORM, 10_10_10_2_UNORM_DEST, WXYZ),
213    V__(R10G10B10A2_SNORM,   10_10_10_2_SNORM,   WZYX),
214    V__(B10G10R10A2_SNORM,   10_10_10_2_SNORM,   WXYZ),
215    VTC(R10G10B10A2_UINT,    10_10_10_2_UINT,    WZYX),
216    V__(R10G10B10A2_SINT,    10_10_10_2_SINT,    WZYX),
217    VTC(B10G10R10A2_UINT,    10_10_10_2_UINT,    WXYZ),
218    V__(B10G10R10A2_SINT,    10_10_10_2_SINT,    WXYZ),
219    V__(R10G10B10A2_USCALED, 10_10_10_2_UINT,    WZYX),
220    V__(B10G10R10A2_USCALED, 10_10_10_2_UINT,    WXYZ),
221    V__(R10G10B10A2_SSCALED, 10_10_10_2_SINT,    WZYX),
222    V__(B10G10R10A2_SSCALED, 10_10_10_2_SINT,    WXYZ),
223 
224    VTC(R11G11B10_FLOAT, 11_11_10_FLOAT,         WZYX),
225    _T_(R9G9B9E5_FLOAT,  9_9_9_E5_FLOAT,         WZYX),
226 
227    _TC(Z24X8_UNORM,          Z24_UNORM_S8_UINT, WZYX),
228    _TC(X24S8_UINT,           8_8_8_8_UINT,      WZYX),
229    _TC(Z24_UNORM_S8_UINT,    Z24_UNORM_S8_UINT, WZYX),
230    _TC(Z32_FLOAT,            32_FLOAT,          WZYX),
231    _TC(Z32_FLOAT_S8X24_UINT, 32_FLOAT,          WZYX),
232    _TC(X32_S8X24_UINT,       8_UINT,            WZYX),
233 
234    /* special format for blits: */
235    _TC(Z24_UNORM_S8_UINT_AS_R8G8B8A8, Z24_UNORM_S8_UINT_AS_R8G8B8A8, WZYX),
236 
237    /* 48-bit */
238    VT_(R16G16B16_UNORM,   16_16_16_UNORM,       WZYX),
239    VT_(R16G16B16_SNORM,   16_16_16_SNORM,       WZYX),
240    VT_(R16G16B16_UINT,    16_16_16_UINT,        WZYX),
241    VT_(R16G16B16_SINT,    16_16_16_SINT,        WZYX),
242    V__(R16G16B16_USCALED, 16_16_16_UINT,        WZYX),
243    V__(R16G16B16_SSCALED, 16_16_16_SINT,        WZYX),
244    VT_(R16G16B16_FLOAT,   16_16_16_FLOAT,       WZYX),
245 
246    /* 64-bit */
247    VTC(R16G16B16A16_UNORM,   16_16_16_16_UNORM, WZYX),
248    VTC(R16G16B16X16_UNORM,   16_16_16_16_UNORM, WZYX),
249    VTC(R16G16B16A16_SNORM,   16_16_16_16_SNORM, WZYX),
250    VTC(R16G16B16X16_SNORM,   16_16_16_16_SNORM, WZYX),
251    VTC(R16G16B16A16_UINT,    16_16_16_16_UINT,  WZYX),
252    VTC(R16G16B16X16_UINT,    16_16_16_16_UINT,  WZYX),
253    VTC(R16G16B16A16_SINT,    16_16_16_16_SINT,  WZYX),
254    VTC(R16G16B16X16_SINT,    16_16_16_16_SINT,  WZYX),
255    V__(R16G16B16A16_USCALED, 16_16_16_16_UINT,  WZYX),
256    V__(R16G16B16A16_SSCALED, 16_16_16_16_SINT,  WZYX),
257    VTC(R16G16B16A16_FLOAT,   16_16_16_16_FLOAT, WZYX),
258    VTC(R16G16B16X16_FLOAT,   16_16_16_16_FLOAT, WZYX),
259 
260    V__(R32G32_UNORM,   32_32_UNORM,             WZYX),
261    V__(R32G32_SNORM,   32_32_SNORM,             WZYX),
262    VTC(R32G32_UINT,    32_32_UINT,              WZYX),
263    VTC(R32G32_SINT,    32_32_SINT,              WZYX),
264    V__(R32G32_USCALED, 32_32_UINT,              WZYX),
265    V__(R32G32_SSCALED, 32_32_SINT,              WZYX),
266    VTC(R32G32_FLOAT,   32_32_FLOAT,             WZYX),
267    V__(R32G32_FIXED,   32_32_FIXED,             WZYX),
268 
269    _T_(L32A32_UINT,    32_32_UINT,              WZYX),
270    _T_(L32A32_SINT,    32_32_SINT,              WZYX),
271    _T_(L32A32_FLOAT,   32_32_FLOAT,             WZYX),
272 
273    /* 96-bit */
274    V__(R32G32B32_UNORM,   32_32_32_UNORM,       WZYX),
275    V__(R32G32B32_SNORM,   32_32_32_SNORM,       WZYX),
276    VT_(R32G32B32_UINT,    32_32_32_UINT,        WZYX),
277    VT_(R32G32B32_SINT,    32_32_32_SINT,        WZYX),
278    V__(R32G32B32_USCALED, 32_32_32_UINT,        WZYX),
279    V__(R32G32B32_SSCALED, 32_32_32_SINT,        WZYX),
280    VT_(R32G32B32_FLOAT,   32_32_32_FLOAT,       WZYX),
281    V__(R32G32B32_FIXED,   32_32_32_FIXED,       WZYX),
282 
283    /* 128-bit */
284    V__(R32G32B32A32_UNORM,   32_32_32_32_UNORM, WZYX),
285    V__(R32G32B32A32_SNORM,   32_32_32_32_SNORM, WZYX),
286    VTC(R32G32B32A32_UINT,    32_32_32_32_UINT,  WZYX),
287    _TC(R32G32B32X32_UINT,    32_32_32_32_UINT,  WZYX),
288    VTC(R32G32B32A32_SINT,    32_32_32_32_SINT,  WZYX),
289    _TC(R32G32B32X32_SINT,    32_32_32_32_SINT,  WZYX),
290    V__(R32G32B32A32_USCALED, 32_32_32_32_UINT,  WZYX),
291    V__(R32G32B32A32_SSCALED, 32_32_32_32_SINT,  WZYX),
292    VTC(R32G32B32A32_FLOAT,   32_32_32_32_FLOAT, WZYX),
293    _TC(R32G32B32X32_FLOAT,   32_32_32_32_FLOAT, WZYX),
294    V__(R32G32B32A32_FIXED,   32_32_32_32_FIXED, WZYX),
295 
296    /* compressed */
297    _T_(ETC1_RGB8, ETC1,                         WZYX),
298    _T_(ETC2_RGB8, ETC2_RGB8,                    WZYX),
299    _T_(ETC2_SRGB8, ETC2_RGB8,                   WZYX),
300    _T_(ETC2_RGB8A1, ETC2_RGB8A1,                WZYX),
301    _T_(ETC2_SRGB8A1, ETC2_RGB8A1,               WZYX),
302    _T_(ETC2_RGBA8, ETC2_RGBA8,                  WZYX),
303    _T_(ETC2_SRGBA8, ETC2_RGBA8,                 WZYX),
304    _T_(ETC2_R11_UNORM, ETC2_R11_UNORM,          WZYX),
305    _T_(ETC2_R11_SNORM, ETC2_R11_SNORM,          WZYX),
306    _T_(ETC2_RG11_UNORM, ETC2_RG11_UNORM,        WZYX),
307    _T_(ETC2_RG11_SNORM, ETC2_RG11_SNORM,        WZYX),
308 
309    _T_(DXT1_RGB,   DXT1,                        WZYX),
310    _T_(DXT1_SRGB,  DXT1,                        WZYX),
311    _T_(DXT1_RGBA,  DXT1,                        WZYX),
312    _T_(DXT1_SRGBA, DXT1,                        WZYX),
313    _T_(DXT3_RGBA,  DXT3,                        WZYX),
314    _T_(DXT3_SRGBA, DXT3,                        WZYX),
315    _T_(DXT5_RGBA,  DXT5,                        WZYX),
316    _T_(DXT5_SRGBA, DXT5,                        WZYX),
317 
318    _T_(BPTC_RGBA_UNORM, BPTC,                   WZYX),
319    _T_(BPTC_SRGBA,      BPTC,                   WZYX),
320    _T_(BPTC_RGB_FLOAT,  BPTC_FLOAT,             WZYX),
321    _T_(BPTC_RGB_UFLOAT, BPTC_UFLOAT,            WZYX),
322 
323    _T_(RGTC1_UNORM, RGTC1_UNORM,                WZYX),
324    _T_(RGTC1_SNORM, RGTC1_SNORM,                WZYX),
325    _T_(RGTC2_UNORM, RGTC2_UNORM,                WZYX),
326    _T_(RGTC2_SNORM, RGTC2_SNORM,                WZYX),
327    _T_(LATC1_UNORM, RGTC1_UNORM,                WZYX),
328    _T_(LATC1_SNORM, RGTC1_SNORM,                WZYX),
329    _T_(LATC2_UNORM, RGTC2_UNORM,                WZYX),
330    _T_(LATC2_SNORM, RGTC2_SNORM,                WZYX),
331 
332    _T_(ASTC_4x4,   ASTC_4x4,                    WZYX),
333    _T_(ASTC_5x4,   ASTC_5x4,                    WZYX),
334    _T_(ASTC_5x5,   ASTC_5x5,                    WZYX),
335    _T_(ASTC_6x5,   ASTC_6x5,                    WZYX),
336    _T_(ASTC_6x6,   ASTC_6x6,                    WZYX),
337    _T_(ASTC_8x5,   ASTC_8x5,                    WZYX),
338    _T_(ASTC_8x6,   ASTC_8x6,                    WZYX),
339    _T_(ASTC_8x8,   ASTC_8x8,                    WZYX),
340    _T_(ASTC_10x5,  ASTC_10x5,                   WZYX),
341    _T_(ASTC_10x6,  ASTC_10x6,                   WZYX),
342    _T_(ASTC_10x8,  ASTC_10x8,                   WZYX),
343    _T_(ASTC_10x10, ASTC_10x10,                  WZYX),
344    _T_(ASTC_12x10, ASTC_12x10,                  WZYX),
345    _T_(ASTC_12x12, ASTC_12x12,                  WZYX),
346 
347    _T_(ASTC_4x4_SRGB,   ASTC_4x4,               WZYX),
348    _T_(ASTC_5x4_SRGB,   ASTC_5x4,               WZYX),
349    _T_(ASTC_5x5_SRGB,   ASTC_5x5,               WZYX),
350    _T_(ASTC_6x5_SRGB,   ASTC_6x5,               WZYX),
351    _T_(ASTC_6x6_SRGB,   ASTC_6x6,               WZYX),
352    _T_(ASTC_8x5_SRGB,   ASTC_8x5,               WZYX),
353    _T_(ASTC_8x6_SRGB,   ASTC_8x6,               WZYX),
354    _T_(ASTC_8x8_SRGB,   ASTC_8x8,               WZYX),
355    _T_(ASTC_10x5_SRGB,  ASTC_10x5,              WZYX),
356    _T_(ASTC_10x6_SRGB,  ASTC_10x6,              WZYX),
357    _T_(ASTC_10x8_SRGB,  ASTC_10x8,              WZYX),
358    _T_(ASTC_10x10_SRGB, ASTC_10x10,             WZYX),
359    _T_(ASTC_12x10_SRGB, ASTC_12x10,             WZYX),
360    _T_(ASTC_12x12_SRGB, ASTC_12x12,             WZYX),
361 
362    _T_(R8G8_R8B8_UNORM, R8G8R8B8_422_UNORM, WZYX), /* YUYV */
363    _T_(G8R8_B8R8_UNORM, G8R8B8R8_422_UNORM, WZYX), /* UYVY */
364 
365    _T_(R8_G8B8_420_UNORM, R8_G8B8_2PLANE_420_UNORM, WZYX), /* Gallium NV12 */
366    _T_(G8_B8R8_420_UNORM, R8_G8B8_2PLANE_420_UNORM, WZYX), /* Vulkan NV12 */
367    _T_(G8_B8_R8_420_UNORM, R8_G8_B8_3PLANE_420_UNORM, WZYX),
368 };
369 /* clang-format on */
370 
371 static enum a3xx_color_swap
fd6_pipe2swap(enum pipe_format format,enum a6xx_tile_mode tile_mode)372 fd6_pipe2swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
373 {
374    if (!formats[format].present)
375       return WZYX;
376 
377    /* It seems CCU ignores swap and always uses WZYX when tiled.  TP, on the
378     * other hand, always respects swap.  We should return WZYX such that CCU
379     * and TP agree each other.
380     */
381    if (tile_mode)
382       return WZYX;
383 
384    return formats[format].swap;
385 }
386 
387 /* convert pipe format to vertex buffer format: */
388 enum a6xx_format
fd6_vertex_format(enum pipe_format format)389 fd6_vertex_format(enum pipe_format format)
390 {
391    if (!formats[format].present)
392       return FMT6_NONE;
393    return formats[format].vtx;
394 }
395 
396 enum a3xx_color_swap
fd6_vertex_swap(enum pipe_format format)397 fd6_vertex_swap(enum pipe_format format)
398 {
399    return fd6_pipe2swap(format, TILE6_LINEAR);
400 }
401 
402 /* convert pipe format to texture sampler format: */
403 enum a6xx_format
fd6_texture_format(enum pipe_format format,enum a6xx_tile_mode tile_mode)404 fd6_texture_format(enum pipe_format format, enum a6xx_tile_mode tile_mode)
405 {
406    if (!formats[format].present)
407       return FMT6_NONE;
408 
409    if (!tile_mode) {
410       switch (format) {
411       /* Linear ARGB/ABGR1555 has a special format for sampling (tiled
412        * 1555/5551 formats always have the same swizzle and layout).
413        */
414       case PIPE_FORMAT_A1R5G5B5_UNORM:
415       case PIPE_FORMAT_A1B5G5R5_UNORM:
416          return FMT6_1_5_5_5_UNORM;
417       /* note: this may be more about UBWC than tiling, but we don't support
418        * tiled non-UBWC NV12
419        */
420       case PIPE_FORMAT_Y8_UNORM:
421          return FMT6_8_UNORM;
422       default:
423          break;
424       }
425    }
426 
427    return formats[format].tex;
428 }
429 
430 enum a3xx_color_swap
fd6_texture_swap(enum pipe_format format,enum a6xx_tile_mode tile_mode)431 fd6_texture_swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
432 {
433    if (!tile_mode) {
434       switch (format) {
435       case PIPE_FORMAT_A1R5G5B5_UNORM:
436          return WZYX;
437       case PIPE_FORMAT_A1B5G5R5_UNORM:
438          return WXYZ;
439       default:
440          break;
441       }
442    }
443 
444    /* format is PIPE_FORMAT_X24S8_UINT when texturing the stencil aspect of
445     * PIPE_FORMAT_Z24_UNORM_S8_UINT.  Because we map the format to
446     * FMT6_8_8_8_8_UINT, return XYZW such that the stencil value is in X
447     * component.
448     *
449     * We used to return WZYX and apply swizzles.  That required us to
450     * un-swizzle the user-specified border color, which could not be done for
451     * turnip.
452     */
453    if (format == PIPE_FORMAT_X24S8_UINT)
454       return XYZW;
455 
456    return fd6_pipe2swap(format, tile_mode);
457 }
458 
459 /* convert pipe format to MRT / copydest format used for render-target: */
460 enum a6xx_format
fd6_color_format(enum pipe_format format,enum a6xx_tile_mode tile_mode)461 fd6_color_format(enum pipe_format format, enum a6xx_tile_mode tile_mode)
462 {
463    if (!formats[format].present)
464       return FMT6_NONE;
465 
466    if (!tile_mode && format == PIPE_FORMAT_Y8_UNORM)
467       return FMT6_8_UNORM;
468 
469    return formats[format].rb;
470 }
471 
472 enum a3xx_color_swap
fd6_color_swap(enum pipe_format format,enum a6xx_tile_mode tile_mode)473 fd6_color_swap(enum pipe_format format, enum a6xx_tile_mode tile_mode)
474 {
475    return fd6_pipe2swap(format, tile_mode);
476 }
477 
478 enum a6xx_depth_format
fd6_pipe2depth(enum pipe_format format)479 fd6_pipe2depth(enum pipe_format format)
480 {
481    switch (format) {
482    case PIPE_FORMAT_Z16_UNORM:
483       return DEPTH6_16;
484    case PIPE_FORMAT_Z24X8_UNORM:
485    case PIPE_FORMAT_Z24_UNORM_S8_UINT:
486    case PIPE_FORMAT_X8Z24_UNORM:
487    case PIPE_FORMAT_S8_UINT_Z24_UNORM:
488       return DEPTH6_24_8;
489    case PIPE_FORMAT_Z32_FLOAT:
490    case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
491       return DEPTH6_32;
492    default:
493       return ~0;
494    }
495 }
496