• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is 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
18  * THE 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  * Authors:
24  *    Rob Clark <robclark@freedesktop.org>
25  */
26 
27 #include "pipe/p_defines.h"
28 #include "util/format/u_format.h"
29 
30 #include "fd4_format.h"
31 
32 /* Specifies the table of all the formats and their features. Also supplies
33  * the helpers that look up various data in those tables.
34  */
35 
36 struct fd4_format {
37    enum a4xx_vtx_fmt vtx;
38    enum a4xx_tex_fmt tex;
39    enum a4xx_color_fmt rb;
40    enum a3xx_color_swap swap;
41    boolean present;
42 };
43 
44 /* vertex + texture */
45 #define VT(pipe, fmt, rbfmt, swapfmt)                                          \
46    [PIPE_FORMAT_##pipe] = {.present = 1,                                       \
47                            .vtx = VFMT4_##fmt,                                 \
48                            .tex = TFMT4_##fmt,                                 \
49                            .rb = RB4_##rbfmt,                                  \
50                            .swap = swapfmt}
51 
52 /* texture-only */
53 #define _T(pipe, fmt, rbfmt, swapfmt)                                          \
54    [PIPE_FORMAT_##pipe] = {.present = 1,                                       \
55                            .vtx = VFMT4_NONE,                                  \
56                            .tex = TFMT4_##fmt,                                 \
57                            .rb = RB4_##rbfmt,                                  \
58                            .swap = swapfmt}
59 
60 /* vertex-only */
61 #define V_(pipe, fmt, rbfmt, swapfmt)                                          \
62    [PIPE_FORMAT_##pipe] = {.present = 1,                                       \
63                            .vtx = VFMT4_##fmt,                                 \
64                            .tex = TFMT4_NONE,                                  \
65                            .rb = RB4_##rbfmt,                                  \
66                            .swap = swapfmt}
67 
68 /* clang-format off */
69 static struct fd4_format formats[PIPE_FORMAT_COUNT] = {
70    /* 8-bit */
71    VT(R8_UNORM,   8_UNORM, R8_UNORM, WZYX),
72    VT(R8_SNORM,   8_SNORM, R8_SNORM, WZYX),
73    VT(R8_UINT,    8_UINT,  R8_UINT,  WZYX),
74    VT(R8_SINT,    8_SINT,  R8_SINT,  WZYX),
75    V_(R8_USCALED, 8_UINT,  NONE,     WZYX),
76    V_(R8_SSCALED, 8_SINT,  NONE,     WZYX),
77 
78    _T(A8_UNORM,   8_UNORM, A8_UNORM, WZYX),
79    _T(L8_UNORM,   8_UNORM, R8_UNORM, WZYX),
80    _T(I8_UNORM,   8_UNORM, NONE,     WZYX),
81 
82    _T(A8_UINT,    8_UINT,  NONE,     WZYX),
83    _T(A8_SINT,    8_SINT,  NONE,     WZYX),
84    _T(L8_UINT,    8_UINT,  NONE,     WZYX),
85    _T(L8_SINT,    8_SINT,  NONE,     WZYX),
86    _T(I8_UINT,    8_UINT,  NONE,     WZYX),
87    _T(I8_SINT,    8_SINT,  NONE,     WZYX),
88 
89    _T(S8_UINT,    8_UINT,  R8_UNORM, WZYX),
90 
91    /* 16-bit */
92    VT(R16_UNORM,   16_UNORM, R16_UNORM, WZYX),
93    VT(R16_SNORM,   16_SNORM, R16_SNORM, WZYX),
94    VT(R16_UINT,    16_UINT,  R16_UINT,  WZYX),
95    VT(R16_SINT,    16_SINT,  R16_SINT,  WZYX),
96    V_(R16_USCALED, 16_UINT,  NONE,      WZYX),
97    V_(R16_SSCALED, 16_SINT,  NONE,      WZYX),
98    VT(R16_FLOAT,   16_FLOAT, R16_FLOAT, WZYX),
99 
100    _T(A16_UNORM,   16_UNORM, NONE,      WZYX),
101    _T(A16_SNORM,   16_SNORM, NONE,      WZYX),
102    _T(A16_UINT,    16_UINT,  NONE,      WZYX),
103    _T(A16_SINT,    16_SINT,  NONE,      WZYX),
104    _T(L16_UNORM,   16_UNORM, NONE,      WZYX),
105    _T(L16_SNORM,   16_SNORM, NONE,      WZYX),
106    _T(L16_UINT,    16_UINT,  NONE,      WZYX),
107    _T(L16_SINT,    16_SINT,  NONE,      WZYX),
108    _T(I16_UNORM,   16_UNORM, NONE,      WZYX),
109    _T(I16_SNORM,   16_SNORM, NONE,      WZYX),
110    _T(I16_UINT,    16_UINT,  NONE,      WZYX),
111    _T(I16_SINT,    16_SINT,  NONE,      WZYX),
112 
113    VT(R8G8_UNORM,   8_8_UNORM, R8G8_UNORM, WZYX),
114    VT(R8G8_SNORM,   8_8_SNORM, R8G8_SNORM, WZYX),
115    VT(R8G8_UINT,    8_8_UINT,  R8G8_UINT,  WZYX),
116    VT(R8G8_SINT,    8_8_SINT,  R8G8_SINT,  WZYX),
117    V_(R8G8_USCALED, 8_8_UINT,  NONE,       WZYX),
118    V_(R8G8_SSCALED, 8_8_SINT,  NONE,       WZYX),
119 
120    _T(L8A8_UINT,    8_8_UINT,  NONE,       WZYX),
121    _T(L8A8_SINT,    8_8_SINT,  NONE,       WZYX),
122 
123    _T(B5G6R5_UNORM,   5_6_5_UNORM,   R5G6B5_UNORM,   WXYZ),
124    _T(B5G5R5A1_UNORM, 5_5_5_1_UNORM, R5G5B5A1_UNORM, WXYZ),
125    _T(B5G5R5X1_UNORM, 5_5_5_1_UNORM, R5G5B5A1_UNORM, WXYZ),
126    _T(B4G4R4A4_UNORM, 4_4_4_4_UNORM, R4G4B4A4_UNORM, WXYZ),
127 
128    /* 24-bit */
129    V_(R8G8B8_UNORM,   8_8_8_UNORM, NONE, WZYX),
130    V_(R8G8B8_SNORM,   8_8_8_SNORM, NONE, WZYX),
131    V_(R8G8B8_UINT,    8_8_8_UINT,  NONE, WZYX),
132    V_(R8G8B8_SINT,    8_8_8_SINT,  NONE, WZYX),
133    V_(R8G8B8_USCALED, 8_8_8_UINT,  NONE, WZYX),
134    V_(R8G8B8_SSCALED, 8_8_8_SINT,  NONE, WZYX),
135 
136    /* 32-bit */
137    VT(R32_UINT,    32_UINT,  R32_UINT, WZYX),
138    VT(R32_SINT,    32_SINT,  R32_SINT, WZYX),
139    V_(R32_USCALED, 32_UINT,  NONE,     WZYX),
140    V_(R32_SSCALED, 32_SINT,  NONE,     WZYX),
141    VT(R32_FLOAT,   32_FLOAT, R32_FLOAT,WZYX),
142    V_(R32_FIXED,   32_FIXED, NONE,     WZYX),
143 
144    _T(A32_UINT,    32_UINT,  NONE,     WZYX),
145    _T(A32_SINT,    32_SINT,  NONE,     WZYX),
146    _T(L32_UINT,    32_UINT,  NONE,     WZYX),
147    _T(L32_SINT,    32_SINT,  NONE,     WZYX),
148    _T(I32_UINT,    32_UINT,  NONE,     WZYX),
149    _T(I32_SINT,    32_SINT,  NONE,     WZYX),
150 
151    VT(R16G16_UNORM,   16_16_UNORM, R16G16_UNORM, WZYX),
152    VT(R16G16_SNORM,   16_16_SNORM, R16G16_SNORM, WZYX),
153    VT(R16G16_UINT,    16_16_UINT,  R16G16_UINT,  WZYX),
154    VT(R16G16_SINT,    16_16_SINT,  R16G16_SINT,  WZYX),
155    V_(R16G16_USCALED, 16_16_UINT,  NONE,         WZYX),
156    V_(R16G16_SSCALED, 16_16_SINT,  NONE,         WZYX),
157    VT(R16G16_FLOAT,   16_16_FLOAT, R16G16_FLOAT, WZYX),
158 
159    _T(L16A16_UNORM,   16_16_UNORM, NONE,         WZYX),
160    _T(L16A16_SNORM,   16_16_SNORM, NONE,         WZYX),
161    _T(L16A16_UINT,    16_16_UINT,  NONE,         WZYX),
162    _T(L16A16_SINT,    16_16_SINT,  NONE,         WZYX),
163 
164    VT(R8G8B8A8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
165    _T(R8G8B8X8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
166    _T(R8G8B8A8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
167    _T(R8G8B8X8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
168    VT(R8G8B8A8_SNORM,   8_8_8_8_SNORM, R8G8B8A8_SNORM, WZYX),
169    VT(R8G8B8A8_UINT,    8_8_8_8_UINT,  R8G8B8A8_UINT,  WZYX),
170    VT(R8G8B8A8_SINT,    8_8_8_8_SINT,  R8G8B8A8_SINT,  WZYX),
171    V_(R8G8B8A8_USCALED, 8_8_8_8_UINT,  NONE,           WZYX),
172    V_(R8G8B8A8_SSCALED, 8_8_8_8_SINT,  NONE,           WZYX),
173 
174    VT(B8G8R8A8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
175    _T(B8G8R8X8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
176    VT(B8G8R8A8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
177    _T(B8G8R8X8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
178 
179    VT(A8B8G8R8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
180    _T(X8B8G8R8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
181    _T(A8B8G8R8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
182    _T(X8B8G8R8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
183 
184    VT(A8R8G8B8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
185    _T(X8R8G8B8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
186    _T(A8R8G8B8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
187    _T(X8R8G8B8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
188 
189    VT(R10G10B10A2_UNORM,   10_10_10_2_UNORM, R10G10B10A2_UNORM, WZYX),
190    VT(B10G10R10A2_UNORM,   10_10_10_2_UNORM, R10G10B10A2_UNORM, WXYZ),
191    _T(B10G10R10X2_UNORM,   10_10_10_2_UNORM, R10G10B10A2_UNORM, WXYZ),
192    V_(R10G10B10A2_SNORM,   10_10_10_2_SNORM, NONE,              WZYX),
193    V_(B10G10R10A2_SNORM,   10_10_10_2_SNORM, NONE,              WXYZ),
194    VT(R10G10B10A2_UINT,    10_10_10_2_UINT,  R10G10B10A2_UINT,  WZYX),
195    VT(B10G10R10A2_UINT,    10_10_10_2_UINT,  R10G10B10A2_UINT,  WXYZ),
196    V_(R10G10B10A2_USCALED, 10_10_10_2_UINT,  NONE,              WZYX),
197    V_(B10G10R10A2_USCALED, 10_10_10_2_UINT,  NONE,              WXYZ),
198    V_(R10G10B10A2_SSCALED, 10_10_10_2_SINT,  NONE,              WZYX),
199    V_(B10G10R10A2_SSCALED, 10_10_10_2_SINT,  NONE,              WXYZ),
200 
201    VT(R11G11B10_FLOAT, 11_11_10_FLOAT, R11G11B10_FLOAT, WZYX),
202    _T(R9G9B9E5_FLOAT,  9_9_9_E5_FLOAT, NONE,            WZYX),
203 
204    _T(Z16_UNORM,            16_UNORM,     R8G8_UNORM,     WZYX),
205    _T(Z24X8_UNORM,          X8Z24_UNORM,  R8G8B8A8_UNORM, WZYX),
206    _T(X24S8_UINT,           8_8_8_8_UINT, R8G8B8A8_UINT,  XYZW),
207    _T(Z24_UNORM_S8_UINT,    X8Z24_UNORM,  R8G8B8A8_UNORM, WZYX),
208    _T(Z32_FLOAT,            32_FLOAT,     R8G8B8A8_UNORM, WZYX),
209    _T(Z32_FLOAT_S8X24_UINT, 32_FLOAT,     R8G8B8A8_UNORM, WZYX),
210    _T(X32_S8X24_UINT,       8_UINT,       R8_UINT,        WZYX),
211 
212    /* 48-bit */
213    V_(R16G16B16_UNORM,   16_16_16_UNORM, NONE, WZYX),
214    V_(R16G16B16_SNORM,   16_16_16_SNORM, NONE, WZYX),
215    V_(R16G16B16_UINT,    16_16_16_UINT,  NONE, WZYX),
216    V_(R16G16B16_SINT,    16_16_16_SINT,  NONE, WZYX),
217    V_(R16G16B16_USCALED, 16_16_16_UINT,  NONE, WZYX),
218    V_(R16G16B16_SSCALED, 16_16_16_SINT,  NONE, WZYX),
219    V_(R16G16B16_FLOAT,   16_16_16_FLOAT, NONE, WZYX),
220 
221    /* 64-bit */
222    VT(R16G16B16A16_UNORM,   16_16_16_16_UNORM, R16G16B16A16_UNORM, WZYX),
223    VT(R16G16B16X16_UNORM,   16_16_16_16_UNORM, R16G16B16A16_UNORM, WZYX),
224    VT(R16G16B16A16_SNORM,   16_16_16_16_SNORM, R16G16B16A16_SNORM, WZYX),
225    VT(R16G16B16X16_SNORM,   16_16_16_16_SNORM, R16G16B16A16_SNORM, WZYX),
226    VT(R16G16B16A16_UINT,    16_16_16_16_UINT,  R16G16B16A16_UINT,  WZYX),
227    _T(R16G16B16X16_UINT,    16_16_16_16_UINT,  R16G16B16A16_UINT,  WZYX),
228    VT(R16G16B16A16_SINT,    16_16_16_16_SINT,  R16G16B16A16_SINT,  WZYX),
229    _T(R16G16B16X16_SINT,    16_16_16_16_SINT,  R16G16B16A16_SINT,  WZYX),
230    V_(R16G16B16A16_USCALED, 16_16_16_16_UINT,  NONE,               WZYX),
231    V_(R16G16B16A16_SSCALED, 16_16_16_16_SINT,  NONE,               WZYX),
232    VT(R16G16B16A16_FLOAT,   16_16_16_16_FLOAT, R16G16B16A16_FLOAT, WZYX),
233    _T(R16G16B16X16_FLOAT,   16_16_16_16_FLOAT, R16G16B16A16_FLOAT, WZYX),
234 
235    VT(R32G32_UINT,    32_32_UINT,  R32G32_UINT, WZYX),
236    VT(R32G32_SINT,    32_32_SINT,  R32G32_SINT, WZYX),
237    V_(R32G32_USCALED, 32_32_UINT,  NONE,        WZYX),
238    V_(R32G32_SSCALED, 32_32_SINT,  NONE,        WZYX),
239    VT(R32G32_FLOAT,   32_32_FLOAT, R32G32_FLOAT,WZYX),
240    V_(R32G32_FIXED,   32_32_FIXED, NONE,        WZYX),
241 
242    _T(L32A32_UINT,    32_32_UINT,  NONE,        WZYX),
243    _T(L32A32_SINT,    32_32_SINT,  NONE,        WZYX),
244 
245    /* 96-bit */
246    VT(R32G32B32_UINT,    32_32_32_UINT,  NONE, WZYX),
247    VT(R32G32B32_SINT,    32_32_32_SINT,  NONE, WZYX),
248    V_(R32G32B32_USCALED, 32_32_32_UINT,  NONE, WZYX),
249    V_(R32G32B32_SSCALED, 32_32_32_SINT,  NONE, WZYX),
250    VT(R32G32B32_FLOAT,   32_32_32_FLOAT, NONE, WZYX),
251    V_(R32G32B32_FIXED,   32_32_32_FIXED, NONE, WZYX),
252 
253    /* 128-bit */
254    VT(R32G32B32A32_UINT,    32_32_32_32_UINT,  R32G32B32A32_UINT,  WZYX),
255    _T(R32G32B32X32_UINT,    32_32_32_32_UINT,  R32G32B32A32_UINT,  WZYX),
256    VT(R32G32B32A32_SINT,    32_32_32_32_SINT,  R32G32B32A32_SINT,  WZYX),
257    _T(R32G32B32X32_SINT,    32_32_32_32_SINT,  R32G32B32A32_SINT,  WZYX),
258    V_(R32G32B32A32_USCALED, 32_32_32_32_UINT,  NONE,               WZYX),
259    V_(R32G32B32A32_SSCALED, 32_32_32_32_SINT,  NONE,               WZYX),
260    VT(R32G32B32A32_FLOAT,   32_32_32_32_FLOAT, R32G32B32A32_FLOAT, WZYX),
261    _T(R32G32B32X32_FLOAT,   32_32_32_32_FLOAT, R32G32B32A32_FLOAT, WZYX),
262    V_(R32G32B32A32_FIXED,   32_32_32_32_FIXED, NONE,               WZYX),
263 
264    /* compressed */
265    _T(ETC1_RGB8, ETC1, NONE, WZYX),
266    _T(ETC2_RGB8, ETC2_RGB8, NONE, WZYX),
267    _T(ETC2_SRGB8, ETC2_RGB8, NONE, WZYX),
268    _T(ETC2_RGB8A1, ETC2_RGB8A1, NONE, WZYX),
269    _T(ETC2_SRGB8A1, ETC2_RGB8A1, NONE, WZYX),
270    _T(ETC2_RGBA8, ETC2_RGBA8, NONE, WZYX),
271    _T(ETC2_SRGBA8, ETC2_RGBA8, NONE, WZYX),
272    _T(ETC2_R11_UNORM, ETC2_R11_UNORM, NONE, WZYX),
273    _T(ETC2_R11_SNORM, ETC2_R11_SNORM, NONE, WZYX),
274    _T(ETC2_RG11_UNORM, ETC2_RG11_UNORM, NONE, WZYX),
275    _T(ETC2_RG11_SNORM, ETC2_RG11_SNORM, NONE, WZYX),
276 
277    _T(DXT1_RGB,   DXT1, NONE, WZYX),
278    _T(DXT1_SRGB,  DXT1, NONE, WZYX),
279    _T(DXT1_RGBA,  DXT1, NONE, WZYX),
280    _T(DXT1_SRGBA, DXT1, NONE, WZYX),
281    _T(DXT3_RGBA,  DXT3, NONE, WZYX),
282    _T(DXT3_SRGBA, DXT3, NONE, WZYX),
283    _T(DXT5_RGBA,  DXT5, NONE, WZYX),
284    _T(DXT5_SRGBA, DXT5, NONE, WZYX),
285 
286    _T(BPTC_RGBA_UNORM, BPTC,        NONE, WZYX),
287    _T(BPTC_SRGBA,      BPTC,        NONE, WZYX),
288    _T(BPTC_RGB_FLOAT,  BPTC_FLOAT,  NONE, WZYX),
289    _T(BPTC_RGB_UFLOAT, BPTC_UFLOAT, NONE, WZYX),
290 
291    _T(RGTC1_UNORM, RGTC1_UNORM, NONE, WZYX),
292    _T(RGTC1_SNORM, RGTC1_SNORM, NONE, WZYX),
293    _T(RGTC2_UNORM, RGTC2_UNORM, NONE, WZYX),
294    _T(RGTC2_SNORM, RGTC2_SNORM, NONE, WZYX),
295    _T(LATC1_UNORM, RGTC1_UNORM, NONE, WZYX),
296    _T(LATC1_SNORM, RGTC1_SNORM, NONE, WZYX),
297    _T(LATC2_UNORM, RGTC2_UNORM, NONE, WZYX),
298    _T(LATC2_SNORM, RGTC2_SNORM, NONE, WZYX),
299 
300    _T(ASTC_4x4,   ASTC_4x4,   NONE, WZYX),
301    _T(ASTC_5x4,   ASTC_5x4,   NONE, WZYX),
302    _T(ASTC_5x5,   ASTC_5x5,   NONE, WZYX),
303    _T(ASTC_6x5,   ASTC_6x5,   NONE, WZYX),
304    _T(ASTC_6x6,   ASTC_6x6,   NONE, WZYX),
305    _T(ASTC_8x5,   ASTC_8x5,   NONE, WZYX),
306    _T(ASTC_8x6,   ASTC_8x6,   NONE, WZYX),
307    _T(ASTC_8x8,   ASTC_8x8,   NONE, WZYX),
308    _T(ASTC_10x5,  ASTC_10x5,  NONE, WZYX),
309    _T(ASTC_10x6,  ASTC_10x6,  NONE, WZYX),
310    _T(ASTC_10x8,  ASTC_10x8,  NONE, WZYX),
311    _T(ASTC_10x10, ASTC_10x10, NONE, WZYX),
312    _T(ASTC_12x10, ASTC_12x10, NONE, WZYX),
313    _T(ASTC_12x12, ASTC_12x12, NONE, WZYX),
314 
315    _T(ASTC_4x4_SRGB,   ASTC_4x4,   NONE, WZYX),
316    _T(ASTC_5x4_SRGB,   ASTC_5x4,   NONE, WZYX),
317    _T(ASTC_5x5_SRGB,   ASTC_5x5,   NONE, WZYX),
318    _T(ASTC_6x5_SRGB,   ASTC_6x5,   NONE, WZYX),
319    _T(ASTC_6x6_SRGB,   ASTC_6x6,   NONE, WZYX),
320    _T(ASTC_8x5_SRGB,   ASTC_8x5,   NONE, WZYX),
321    _T(ASTC_8x6_SRGB,   ASTC_8x6,   NONE, WZYX),
322    _T(ASTC_8x8_SRGB,   ASTC_8x8,   NONE, WZYX),
323    _T(ASTC_10x5_SRGB,  ASTC_10x5,  NONE, WZYX),
324    _T(ASTC_10x6_SRGB,  ASTC_10x6,  NONE, WZYX),
325    _T(ASTC_10x8_SRGB,  ASTC_10x8,  NONE, WZYX),
326    _T(ASTC_10x10_SRGB, ASTC_10x10, NONE, WZYX),
327    _T(ASTC_12x10_SRGB, ASTC_12x10, NONE, WZYX),
328    _T(ASTC_12x12_SRGB, ASTC_12x12, NONE, WZYX),
329 };
330 /* clang-format on */
331 
332 /* convert pipe format to vertex buffer format: */
333 enum a4xx_vtx_fmt
fd4_pipe2vtx(enum pipe_format format)334 fd4_pipe2vtx(enum pipe_format format)
335 {
336    if (!formats[format].present)
337       return VFMT4_NONE;
338    return formats[format].vtx;
339 }
340 
341 /* convert pipe format to texture sampler format: */
342 enum a4xx_tex_fmt
fd4_pipe2tex(enum pipe_format format)343 fd4_pipe2tex(enum pipe_format format)
344 {
345    if (!formats[format].present)
346       return TFMT4_NONE;
347    return formats[format].tex;
348 }
349 
350 /* convert pipe format to MRT / copydest format used for render-target: */
351 enum a4xx_color_fmt
fd4_pipe2color(enum pipe_format format)352 fd4_pipe2color(enum pipe_format format)
353 {
354    if (!formats[format].present)
355       return RB4_NONE;
356    return formats[format].rb;
357 }
358 
359 enum a3xx_color_swap
fd4_pipe2swap(enum pipe_format format)360 fd4_pipe2swap(enum pipe_format format)
361 {
362    if (!formats[format].present)
363       return WZYX;
364    return formats[format].swap;
365 }
366 
367 enum a4xx_depth_format
fd4_pipe2depth(enum pipe_format format)368 fd4_pipe2depth(enum pipe_format format)
369 {
370    switch (format) {
371    case PIPE_FORMAT_Z16_UNORM:
372       return DEPTH4_16;
373    case PIPE_FORMAT_Z24X8_UNORM:
374    case PIPE_FORMAT_Z24_UNORM_S8_UINT:
375    case PIPE_FORMAT_X8Z24_UNORM:
376    case PIPE_FORMAT_S8_UINT_Z24_UNORM:
377       return DEPTH4_24_8;
378    case PIPE_FORMAT_Z32_FLOAT:
379    case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
380       return DEPTH4_32;
381    default:
382       return ~0;
383    }
384 }
385 
386 static inline enum a4xx_tex_swiz
tex_swiz(unsigned swiz)387 tex_swiz(unsigned swiz)
388 {
389    switch (swiz) {
390    default:
391    case PIPE_SWIZZLE_X:
392       return A4XX_TEX_X;
393    case PIPE_SWIZZLE_Y:
394       return A4XX_TEX_Y;
395    case PIPE_SWIZZLE_Z:
396       return A4XX_TEX_Z;
397    case PIPE_SWIZZLE_W:
398       return A4XX_TEX_W;
399    case PIPE_SWIZZLE_0:
400       return A4XX_TEX_ZERO;
401    case PIPE_SWIZZLE_1:
402       return A4XX_TEX_ONE;
403    }
404 }
405 
406 uint32_t
fd4_tex_swiz(enum pipe_format format,unsigned swizzle_r,unsigned swizzle_g,unsigned swizzle_b,unsigned swizzle_a)407 fd4_tex_swiz(enum pipe_format format, unsigned swizzle_r, unsigned swizzle_g,
408              unsigned swizzle_b, unsigned swizzle_a)
409 {
410    const struct util_format_description *desc = util_format_description(format);
411    unsigned char swiz[4] = {
412       swizzle_r,
413       swizzle_g,
414       swizzle_b,
415       swizzle_a,
416    }, rswiz[4];
417 
418    util_format_compose_swizzles(desc->swizzle, swiz, rswiz);
419 
420    return A4XX_TEX_CONST_0_SWIZ_X(tex_swiz(rswiz[0])) |
421           A4XX_TEX_CONST_0_SWIZ_Y(tex_swiz(rswiz[1])) |
422           A4XX_TEX_CONST_0_SWIZ_Z(tex_swiz(rswiz[2])) |
423           A4XX_TEX_CONST_0_SWIZ_W(tex_swiz(rswiz[3]));
424 }
425