1 /*
2 * Copyright (C) 2013 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 */
24
25 #include "pipe/p_defines.h"
26 #include "util/format/u_format.h"
27
28 #include "fd3_format.h"
29
30 /* Specifies the table of all the formats and their features. Also supplies
31 * the helpers that look up various data in those tables.
32 */
33
34 struct fd3_format {
35 enum a3xx_vtx_fmt vtx;
36 enum a3xx_tex_fmt tex;
37 enum a3xx_color_fmt rb;
38 enum a3xx_color_swap swap;
39 boolean present;
40 };
41
42 /* vertex + texture */
43 #define VT(pipe, fmt, rbfmt, swapfmt) \
44 [PIPE_FORMAT_##pipe] = {.present = 1, \
45 .vtx = VFMT_##fmt, \
46 .tex = TFMT_##fmt, \
47 .rb = RB_##rbfmt, \
48 .swap = swapfmt}
49
50 /* texture-only */
51 #define _T(pipe, fmt, rbfmt, swapfmt) \
52 [PIPE_FORMAT_##pipe] = {.present = 1, \
53 .vtx = VFMT_NONE, \
54 .tex = TFMT_##fmt, \
55 .rb = RB_##rbfmt, \
56 .swap = swapfmt}
57
58 /* vertex-only */
59 #define V_(pipe, fmt, rbfmt, swapfmt) \
60 [PIPE_FORMAT_##pipe] = {.present = 1, \
61 .vtx = VFMT_##fmt, \
62 .tex = TFMT_NONE, \
63 .rb = RB_##rbfmt, \
64 .swap = swapfmt}
65
66 /* clang-format off */
67 static struct fd3_format formats[PIPE_FORMAT_COUNT] = {
68 /* 8-bit */
69 VT(R8_UNORM, 8_UNORM, R8_UNORM, WZYX),
70 _T(R8_SRGB, 8_UNORM, R8_UNORM, WZYX),
71 VT(R8_SNORM, 8_SNORM, NONE, WZYX),
72 VT(R8_UINT, 8_UINT, NONE, WZYX),
73 VT(R8_SINT, 8_SINT, NONE, WZYX),
74 V_(R8_USCALED, 8_UINT, NONE, WZYX),
75 V_(R8_SSCALED, 8_SINT, NONE, WZYX),
76
77 _T(A8_UNORM, 8_UNORM, A8_UNORM, WZYX),
78 _T(L8_UNORM, 8_UNORM, R8_UNORM, WZYX),
79 _T(I8_UNORM, 8_UNORM, NONE, WZYX),
80
81 _T(A8_UINT, 8_UINT, NONE, WZYX),
82 _T(A8_SINT, 8_SINT, NONE, WZYX),
83 _T(L8_UINT, 8_UINT, NONE, WZYX),
84 _T(L8_SINT, 8_SINT, NONE, WZYX),
85 _T(I8_UINT, 8_UINT, NONE, WZYX),
86 _T(I8_SINT, 8_SINT, NONE, WZYX),
87
88 _T(S8_UINT, 8_UINT, R8_UNORM, WZYX),
89
90 /* 16-bit */
91 VT(R16_UNORM, 16_UNORM, NONE, WZYX),
92 VT(R16_SNORM, 16_SNORM, NONE, WZYX),
93 VT(R16_UINT, 16_UINT, R16_UINT, WZYX),
94 VT(R16_SINT, 16_SINT, R16_SINT, WZYX),
95 V_(R16_USCALED, 16_UINT, NONE, WZYX),
96 V_(R16_SSCALED, 16_SINT, NONE, WZYX),
97 VT(R16_FLOAT, 16_FLOAT, R16_FLOAT,WZYX),
98
99 _T(A16_UNORM, 16_UNORM, NONE, WZYX),
100 _T(A16_SNORM, 16_SNORM, NONE, WZYX),
101 _T(A16_UINT, 16_UINT, NONE, WZYX),
102 _T(A16_SINT, 16_SINT, NONE, WZYX),
103 _T(A16_FLOAT, 16_FLOAT, 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(L16_FLOAT, 16_FLOAT, NONE, WZYX),
109 _T(I16_UNORM, 16_UNORM, NONE, WZYX),
110 _T(I16_SNORM, 16_SNORM, NONE, WZYX),
111 _T(I16_UINT, 16_UINT, NONE, WZYX),
112 _T(I16_SINT, 16_SINT, NONE, WZYX),
113 _T(I16_FLOAT, 16_FLOAT, NONE, WZYX),
114
115 VT(R8G8_UNORM, 8_8_UNORM, R8G8_UNORM, WZYX),
116 _T(R8G8_SRGB, 8_8_UNORM, R8G8_UNORM, WZYX),
117 VT(R8G8_SNORM, 8_8_SNORM, R8G8_SNORM, WZYX),
118 VT(R8G8_UINT, 8_8_UINT, R8G8_UINT, WZYX),
119 VT(R8G8_SINT, 8_8_SINT, R8G8_SINT, WZYX),
120 V_(R8G8_USCALED, 8_8_UINT, NONE, WZYX),
121 V_(R8G8_SSCALED, 8_8_SINT, NONE, WZYX),
122
123 _T(L8A8_UNORM, 8_8_UNORM, NONE, WZYX),
124 _T(L8A8_UINT, 8_8_UINT, NONE, WZYX),
125 _T(L8A8_SINT, 8_8_SINT, NONE, WZYX),
126
127 _T(Z16_UNORM, Z16_UNORM, R8G8_UNORM, WZYX),
128 _T(B5G6R5_UNORM, 5_6_5_UNORM, R5G6B5_UNORM, WXYZ),
129 _T(B5G5R5A1_UNORM, 5_5_5_1_UNORM, R5G5B5A1_UNORM, WXYZ),
130 _T(B5G5R5X1_UNORM, 5_5_5_1_UNORM, R5G5B5A1_UNORM, WXYZ),
131 _T(B4G4R4A4_UNORM, 4_4_4_4_UNORM, R4G4B4A4_UNORM, WXYZ),
132
133 /* 24-bit */
134 V_(R8G8B8_UNORM, 8_8_8_UNORM, NONE, WZYX),
135 V_(R8G8B8_SNORM, 8_8_8_SNORM, NONE, WZYX),
136 V_(R8G8B8_UINT, 8_8_8_UINT, NONE, WZYX),
137 V_(R8G8B8_SINT, 8_8_8_SINT, NONE, WZYX),
138 V_(R8G8B8_USCALED, 8_8_8_UINT, NONE, WZYX),
139 V_(R8G8B8_SSCALED, 8_8_8_SINT, NONE, WZYX),
140
141 /* 32-bit */
142 VT(R32_UINT, 32_UINT, R32_UINT, WZYX),
143 VT(R32_SINT, 32_SINT, R32_SINT, WZYX),
144 V_(R32_USCALED, 32_UINT, NONE, WZYX),
145 V_(R32_SSCALED, 32_SINT, NONE, WZYX),
146 VT(R32_FLOAT, 32_FLOAT, R32_FLOAT,WZYX),
147 V_(R32_FIXED, 32_FIXED, NONE, WZYX),
148
149 _T(A32_UINT, 32_UINT, NONE, WZYX),
150 _T(A32_SINT, 32_SINT, NONE, WZYX),
151 _T(A32_FLOAT, 32_FLOAT, NONE, WZYX),
152 _T(L32_UINT, 32_UINT, NONE, WZYX),
153 _T(L32_SINT, 32_SINT, NONE, WZYX),
154 _T(L32_FLOAT, 32_FLOAT, NONE, WZYX),
155 _T(I32_UINT, 32_UINT, NONE, WZYX),
156 _T(I32_SINT, 32_SINT, NONE, WZYX),
157 _T(I32_FLOAT, 32_FLOAT, NONE, WZYX),
158
159 VT(R16G16_UNORM, 16_16_UNORM, NONE, WZYX),
160 VT(R16G16_SNORM, 16_16_SNORM, NONE, WZYX),
161 VT(R16G16_UINT, 16_16_UINT, R16G16_UINT, WZYX),
162 VT(R16G16_SINT, 16_16_SINT, R16G16_SINT, WZYX),
163 V_(R16G16_USCALED, 16_16_UINT, NONE, WZYX),
164 V_(R16G16_SSCALED, 16_16_SINT, NONE, WZYX),
165 VT(R16G16_FLOAT, 16_16_FLOAT, R16G16_FLOAT,WZYX),
166
167 _T(L16A16_UNORM, 16_16_UNORM, NONE, WZYX),
168 _T(L16A16_SNORM, 16_16_SNORM, NONE, WZYX),
169 _T(L16A16_UINT, 16_16_UINT, NONE, WZYX),
170 _T(L16A16_SINT, 16_16_SINT, NONE, WZYX),
171 _T(L16A16_FLOAT, 16_16_FLOAT, NONE, WZYX),
172
173 VT(R8G8B8A8_UNORM, 8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
174 _T(R8G8B8X8_UNORM, 8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
175 _T(R8G8B8A8_SRGB, 8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
176 _T(R8G8B8X8_SRGB, 8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
177 VT(R8G8B8A8_SNORM, 8_8_8_8_SNORM, R8G8B8A8_SNORM, WZYX),
178 VT(R8G8B8A8_UINT, 8_8_8_8_UINT, R8G8B8A8_UINT, WZYX),
179 VT(R8G8B8A8_SINT, 8_8_8_8_SINT, R8G8B8A8_SINT, WZYX),
180 V_(R8G8B8A8_USCALED, 8_8_8_8_UINT, NONE, WZYX),
181 V_(R8G8B8A8_SSCALED, 8_8_8_8_SINT, NONE, WZYX),
182
183 VT(B8G8R8A8_UNORM, 8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
184 _T(B8G8R8X8_UNORM, 8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
185 VT(B8G8R8A8_SRGB, 8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
186 _T(B8G8R8X8_SRGB, 8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
187
188 VT(A8B8G8R8_UNORM, 8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
189 _T(X8B8G8R8_UNORM, 8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
190 _T(A8B8G8R8_SRGB, 8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
191 _T(X8B8G8R8_SRGB, 8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
192
193 VT(A8R8G8B8_UNORM, 8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
194 _T(X8R8G8B8_UNORM, 8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
195 _T(A8R8G8B8_SRGB, 8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
196 _T(X8R8G8B8_SRGB, 8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
197
198 VT(R10G10B10A2_UNORM, 10_10_10_2_UNORM, R10G10B10A2_UNORM, WZYX),
199 VT(B10G10R10A2_UNORM, 10_10_10_2_UNORM, R10G10B10A2_UNORM, WXYZ),
200 _T(B10G10R10X2_UNORM, 10_10_10_2_UNORM, R10G10B10A2_UNORM, WXYZ),
201 V_(R10G10B10A2_SNORM, 10_10_10_2_SNORM, NONE, WZYX),
202 V_(B10G10R10A2_SNORM, 10_10_10_2_SNORM, NONE, WXYZ),
203 VT(R10G10B10A2_UINT, 10_10_10_2_UINT, NONE, WZYX),
204 V_(B10G10R10A2_UINT, 10_10_10_2_UINT, NONE, WXYZ),
205 V_(R10G10B10A2_USCALED, 10_10_10_2_UINT, NONE, WZYX),
206 V_(B10G10R10A2_USCALED, 10_10_10_2_UINT, NONE, WXYZ),
207 V_(R10G10B10A2_SSCALED, 10_10_10_2_SINT, NONE, WZYX),
208 V_(B10G10R10A2_SSCALED, 10_10_10_2_SINT, NONE, WXYZ),
209
210 _T(R11G11B10_FLOAT, 11_11_10_FLOAT, R11G11B10_FLOAT, WZYX),
211 _T(R9G9B9E5_FLOAT, 9_9_9_E5_FLOAT, NONE, WZYX),
212
213 _T(Z24X8_UNORM, X8Z24_UNORM, R8G8B8A8_UNORM, WZYX),
214 _T(Z24_UNORM_S8_UINT, X8Z24_UNORM, R8G8B8A8_UNORM, WZYX),
215 _T(Z32_FLOAT, Z32_FLOAT, R8G8B8A8_UNORM, WZYX),
216 _T(Z32_FLOAT_S8X24_UINT, Z32_FLOAT,R8G8B8A8_UNORM, 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, NONE, WZYX),
229 VT(R16G16B16A16_SNORM, 16_16_16_16_SNORM, NONE, WZYX),
230 VT(R16G16B16A16_UINT, 16_16_16_16_UINT, R16G16B16A16_UINT, WZYX),
231 _T(R16G16B16X16_UINT, 16_16_16_16_UINT, R16G16B16A16_UINT, WZYX),
232 VT(R16G16B16A16_SINT, 16_16_16_16_SINT, R16G16B16A16_SINT, WZYX),
233 _T(R16G16B16X16_SINT, 16_16_16_16_SINT, R16G16B16A16_SINT, WZYX),
234 V_(R16G16B16A16_USCALED, 16_16_16_16_UINT, NONE, WZYX),
235 V_(R16G16B16A16_SSCALED, 16_16_16_16_SINT, NONE, WZYX),
236 VT(R16G16B16A16_FLOAT, 16_16_16_16_FLOAT, R16G16B16A16_FLOAT, WZYX),
237 _T(R16G16B16X16_FLOAT, 16_16_16_16_FLOAT, R16G16B16A16_FLOAT, WZYX),
238
239 VT(R32G32_UINT, 32_32_UINT, R32G32_UINT, WZYX),
240 VT(R32G32_SINT, 32_32_SINT, R32G32_SINT, WZYX),
241 V_(R32G32_USCALED, 32_32_UINT, NONE, WZYX),
242 V_(R32G32_SSCALED, 32_32_SINT, NONE, WZYX),
243 VT(R32G32_FLOAT, 32_32_FLOAT, R32G32_FLOAT,WZYX),
244 V_(R32G32_FIXED, 32_32_FIXED, NONE, WZYX),
245
246 _T(L32A32_UINT, 32_32_UINT, NONE, WZYX),
247 _T(L32A32_SINT, 32_32_SINT, NONE, WZYX),
248 _T(L32A32_FLOAT, 32_32_FLOAT, NONE, WZYX),
249
250 /* 96-bit */
251 V_(R32G32B32_UINT, 32_32_32_UINT, NONE, WZYX),
252 V_(R32G32B32_SINT, 32_32_32_SINT, NONE, WZYX),
253 V_(R32G32B32_USCALED, 32_32_32_UINT, NONE, WZYX),
254 V_(R32G32B32_SSCALED, 32_32_32_SINT, NONE, WZYX),
255 V_(R32G32B32_FLOAT, 32_32_32_FLOAT, NONE, WZYX),
256 V_(R32G32B32_FIXED, 32_32_32_FIXED, NONE, WZYX),
257
258 /* 128-bit */
259 VT(R32G32B32A32_UINT, 32_32_32_32_UINT, R32G32B32A32_UINT, WZYX),
260 _T(R32G32B32X32_UINT, 32_32_32_32_UINT, R32G32B32A32_UINT, WZYX),
261 VT(R32G32B32A32_SINT, 32_32_32_32_SINT, R32G32B32A32_SINT, WZYX),
262 _T(R32G32B32X32_SINT, 32_32_32_32_SINT, R32G32B32A32_SINT, WZYX),
263 V_(R32G32B32A32_USCALED, 32_32_32_32_UINT, NONE, WZYX),
264 V_(R32G32B32A32_SSCALED, 32_32_32_32_SINT, NONE, WZYX),
265 VT(R32G32B32A32_FLOAT, 32_32_32_32_FLOAT, R32G32B32A32_FLOAT, WZYX),
266 _T(R32G32B32X32_FLOAT, 32_32_32_32_FLOAT, R32G32B32A32_FLOAT, WZYX),
267 V_(R32G32B32A32_FIXED, 32_32_32_32_FIXED, NONE, WZYX),
268
269 /* compressed */
270 _T(ETC1_RGB8, ETC1, NONE, WZYX),
271 _T(ETC2_RGB8, ETC2_RGB8, NONE, WZYX),
272 _T(ETC2_SRGB8, ETC2_RGB8, NONE, WZYX),
273 _T(ETC2_RGB8A1, ETC2_RGB8A1, NONE, WZYX),
274 _T(ETC2_SRGB8A1, ETC2_RGB8A1, NONE, WZYX),
275 _T(ETC2_RGBA8, ETC2_RGBA8, NONE, WZYX),
276 _T(ETC2_SRGBA8, ETC2_RGBA8, NONE, WZYX),
277 _T(ETC2_R11_UNORM, ETC2_R11_UNORM, NONE, WZYX),
278 _T(ETC2_R11_SNORM, ETC2_R11_SNORM, NONE, WZYX),
279 _T(ETC2_RG11_UNORM, ETC2_RG11_UNORM, NONE, WZYX),
280 _T(ETC2_RG11_SNORM, ETC2_RG11_SNORM, NONE, WZYX),
281
282 _T(DXT1_RGB, DXT1, NONE, WZYX),
283 _T(DXT1_SRGB, DXT1, NONE, WZYX),
284 _T(DXT1_RGBA, DXT1, NONE, WZYX),
285 _T(DXT1_SRGBA, DXT1, NONE, WZYX),
286 _T(DXT3_RGBA, DXT3, NONE, WZYX),
287 _T(DXT3_SRGBA, DXT3, NONE, WZYX),
288 _T(DXT5_RGBA, DXT5, NONE, WZYX),
289 _T(DXT5_SRGBA, DXT5, NONE, WZYX),
290
291 /* faked */
292 _T(RGTC1_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
293 _T(RGTC1_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
294 _T(RGTC2_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
295 _T(RGTC2_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
296 _T(LATC1_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
297 _T(LATC1_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
298 _T(LATC2_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
299 _T(LATC2_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
300
301 _T(ATC_RGB, ATC_RGB, NONE, WZYX),
302 _T(ATC_RGBA_EXPLICIT, ATC_RGBA_EXPLICIT, NONE, WZYX),
303 _T(ATC_RGBA_INTERPOLATED, ATC_RGBA_INTERPOLATED, NONE, WZYX),
304 };
305 /* clang-format on */
306
307 enum a3xx_vtx_fmt
fd3_pipe2vtx(enum pipe_format format)308 fd3_pipe2vtx(enum pipe_format format)
309 {
310 if (!formats[format].present)
311 return VFMT_NONE;
312 return formats[format].vtx;
313 }
314
315 enum a3xx_tex_fmt
fd3_pipe2tex(enum pipe_format format)316 fd3_pipe2tex(enum pipe_format format)
317 {
318 if (!formats[format].present)
319 return TFMT_NONE;
320 return formats[format].tex;
321 }
322
323 enum a3xx_color_fmt
fd3_pipe2color(enum pipe_format format)324 fd3_pipe2color(enum pipe_format format)
325 {
326 if (!formats[format].present)
327 return RB_NONE;
328 return formats[format].rb;
329 }
330
331 enum a3xx_color_swap
fd3_pipe2swap(enum pipe_format format)332 fd3_pipe2swap(enum pipe_format format)
333 {
334 if (!formats[format].present)
335 return WZYX;
336 return formats[format].swap;
337 }
338
339 enum a3xx_color_fmt
fd3_fs_output_format(enum pipe_format format)340 fd3_fs_output_format(enum pipe_format format)
341 {
342 if (util_format_is_srgb(format))
343 return RB_R16G16B16A16_FLOAT;
344 switch (format) {
345 case PIPE_FORMAT_R16_FLOAT:
346 case PIPE_FORMAT_R16G16_FLOAT:
347 case PIPE_FORMAT_R11G11B10_FLOAT:
348 return RB_R16G16B16A16_FLOAT;
349 case PIPE_FORMAT_L8_UNORM:
350 return RB_R8G8B8A8_UNORM;
351 default:
352 return fd3_pipe2color(format);
353 }
354 }
355
356 static inline enum a3xx_tex_swiz
tex_swiz(unsigned swiz)357 tex_swiz(unsigned swiz)
358 {
359 switch (swiz) {
360 default:
361 case PIPE_SWIZZLE_X:
362 return A3XX_TEX_X;
363 case PIPE_SWIZZLE_Y:
364 return A3XX_TEX_Y;
365 case PIPE_SWIZZLE_Z:
366 return A3XX_TEX_Z;
367 case PIPE_SWIZZLE_W:
368 return A3XX_TEX_W;
369 case PIPE_SWIZZLE_0:
370 return A3XX_TEX_ZERO;
371 case PIPE_SWIZZLE_1:
372 return A3XX_TEX_ONE;
373 }
374 }
375
376 uint32_t
fd3_tex_swiz(enum pipe_format format,unsigned swizzle_r,unsigned swizzle_g,unsigned swizzle_b,unsigned swizzle_a)377 fd3_tex_swiz(enum pipe_format format, unsigned swizzle_r, unsigned swizzle_g,
378 unsigned swizzle_b, unsigned swizzle_a)
379 {
380 const struct util_format_description *desc = util_format_description(format);
381 unsigned char swiz[4] = {
382 swizzle_r,
383 swizzle_g,
384 swizzle_b,
385 swizzle_a,
386 }, rswiz[4];
387
388 util_format_compose_swizzles(desc->swizzle, swiz, rswiz);
389
390 return A3XX_TEX_CONST_0_SWIZ_X(tex_swiz(rswiz[0])) |
391 A3XX_TEX_CONST_0_SWIZ_Y(tex_swiz(rswiz[1])) |
392 A3XX_TEX_CONST_0_SWIZ_Z(tex_swiz(rswiz[2])) |
393 A3XX_TEX_CONST_0_SWIZ_W(tex_swiz(rswiz[3]));
394 }
395