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