2 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
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:
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
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
25 #include "pipe/p_defines.h"
26 #include "util/u_format.h"
28 #include "fd3_format.h"
30 /* Specifies the table of all the formats and their features. Also supplies
31 * the helpers that look up various data in those tables.
35 enum a3xx_vtx_fmt vtx
;
36 enum a3xx_tex_fmt tex
;
37 enum a3xx_color_fmt rb
;
38 enum a3xx_color_swap swap
;
44 /* vertex + texture */
45 #define VT(pipe, fmt, rbfmt, swapfmt) \
46 [PIPE_FORMAT_ ## pipe] = { \
48 .vtx = VFMT_ ## fmt, \
49 .tex = TFMT_ ## fmt, \
55 #define _T(pipe, fmt, rbfmt, swapfmt) \
56 [PIPE_FORMAT_ ## pipe] = { \
59 .tex = TFMT_ ## fmt, \
65 #define V_(pipe, fmt, rbfmt, swapfmt) \
66 [PIPE_FORMAT_ ## pipe] = { \
68 .vtx = VFMT_ ## fmt, \
74 static struct fd3_format formats
[PIPE_FORMAT_COUNT
] = {
76 VT(R8_UNORM
, 8_UNORM
, R8_UNORM
, WZYX
),
77 VT(R8_SNORM
, 8_SNORM
, NONE
, WZYX
),
78 VT(R8_UINT
, 8_UINT
, R8_UINT
, WZYX
),
79 VT(R8_SINT
, 8_SINT
, R8_SINT
, WZYX
),
80 V_(R8_USCALED
, 8_UINT
, NONE
, WZYX
),
81 V_(R8_SSCALED
, 8_UINT
, NONE
, WZYX
),
83 _T(A8_UNORM
, 8_UNORM
, A8_UNORM
, WZYX
),
84 _T(L8_UNORM
, 8_UNORM
, R8_UNORM
, WZYX
),
85 _T(I8_UNORM
, 8_UNORM
, NONE
, WZYX
),
87 _T(A8_UINT
, 8_UINT
, NONE
, WZYX
),
88 _T(A8_SINT
, 8_SINT
, NONE
, WZYX
),
89 _T(L8_UINT
, 8_UINT
, NONE
, WZYX
),
90 _T(L8_SINT
, 8_SINT
, NONE
, WZYX
),
91 _T(I8_UINT
, 8_UINT
, NONE
, WZYX
),
92 _T(I8_SINT
, 8_SINT
, NONE
, WZYX
),
95 VT(R16_UNORM
, 16_UNORM
, NONE
, WZYX
),
96 VT(R16_SNORM
, 16_SNORM
, NONE
, WZYX
),
97 VT(R16_UINT
, 16_UINT
, R16_UINT
, WZYX
),
98 VT(R16_SINT
, 16_SINT
, R16_SINT
, WZYX
),
99 V_(R16_USCALED
, 16_UINT
, NONE
, WZYX
),
100 V_(R16_SSCALED
, 16_UINT
, NONE
, WZYX
),
101 VT(R16_FLOAT
, 16_FLOAT
, NONE
, WZYX
),
103 _T(A16_UINT
, 16_UINT
, NONE
, WZYX
),
104 _T(A16_SINT
, 16_SINT
, NONE
, WZYX
),
105 _T(L16_UINT
, 16_UINT
, NONE
, WZYX
),
106 _T(L16_SINT
, 16_SINT
, NONE
, WZYX
),
107 _T(I16_UINT
, 16_UINT
, NONE
, WZYX
),
108 _T(I16_SINT
, 16_SINT
, NONE
, WZYX
),
110 VT(R8G8_UNORM
, 8_8_UNORM
, R8G8_UNORM
, WZYX
),
111 VT(R8G8_SNORM
, 8_8_SNORM
, R8G8_SNORM
, WZYX
),
112 VT(R8G8_UINT
, 8_8_UINT
, NONE
, WZYX
),
113 VT(R8G8_SINT
, 8_8_SINT
, NONE
, WZYX
),
114 V_(R8G8_USCALED
, 8_8_UINT
, NONE
, WZYX
),
115 V_(R8G8_SSCALED
, 8_8_SINT
, NONE
, WZYX
),
117 _T(L8A8_UINT
, 8_8_UINT
, NONE
, WZYX
),
118 _T(L8A8_SINT
, 8_8_SINT
, NONE
, WZYX
),
120 _T(Z16_UNORM
, Z16_UNORM
, R8G8_UNORM
, WZYX
),
121 _T(B5G6R5_UNORM
, 5_6_5_UNORM
, R5G6B5_UNORM
, WXYZ
),
122 _T(B5G5R5A1_UNORM
, 5_5_5_1_UNORM
, R5G5B5A1_UNORM
, WXYZ
),
123 _T(B5G5R5X1_UNORM
, 5_5_5_1_UNORM
, R5G5B5A1_UNORM
, WXYZ
),
124 _T(B4G4R4A4_UNORM
, 4_4_4_4_UNORM
, R4G4B4A4_UNORM
, WXYZ
),
127 V_(R8G8B8_UNORM
, 8_8_8_UNORM
, NONE
, WZYX
),
128 V_(R8G8B8_SNORM
, 8_8_8_SNORM
, NONE
, WZYX
),
129 V_(R8G8B8_UINT
, 8_8_8_UINT
, NONE
, WZYX
),
130 V_(R8G8B8_SINT
, 8_8_8_SINT
, NONE
, WZYX
),
131 V_(R8G8B8_USCALED
, 8_8_8_UINT
, NONE
, WZYX
),
132 V_(R8G8B8_SSCALED
, 8_8_8_SINT
, NONE
, WZYX
),
135 VT(R32_UINT
, 32_UINT
, R32_UINT
, WZYX
),
136 VT(R32_SINT
, 32_SINT
, R32_SINT
, WZYX
),
137 V_(R32_USCALED
, 32_UINT
, NONE
, WZYX
),
138 V_(R32_SSCALED
, 32_UINT
, NONE
, WZYX
),
139 VT(R32_FLOAT
, 32_FLOAT
, NONE
, WZYX
),
140 V_(R32_FIXED
, 32_FIXED
, NONE
, WZYX
),
142 _T(A32_UINT
, 32_UINT
, NONE
, WZYX
),
143 _T(A32_SINT
, 32_SINT
, NONE
, WZYX
),
144 _T(L32_UINT
, 32_UINT
, NONE
, WZYX
),
145 _T(L32_SINT
, 32_SINT
, NONE
, WZYX
),
146 _T(I32_UINT
, 32_UINT
, NONE
, WZYX
),
147 _T(I32_SINT
, 32_SINT
, NONE
, WZYX
),
149 VT(R16G16_UNORM
, 16_16_UNORM
, NONE
, WZYX
),
150 VT(R16G16_SNORM
, 16_16_SNORM
, NONE
, WZYX
),
151 VT(R16G16_UINT
, 16_16_UINT
, R16G16_UINT
, WZYX
),
152 VT(R16G16_SINT
, 16_16_SINT
, R16G16_SINT
, WZYX
),
153 V_(R16G16_USCALED
, 16_16_UINT
, NONE
, WZYX
),
154 V_(R16G16_SSCALED
, 16_16_SINT
, NONE
, WZYX
),
155 VT(R16G16_FLOAT
, 16_16_FLOAT
, NONE
, WZYX
),
157 _T(L16A16_UINT
, 16_16_UINT
, NONE
, WZYX
),
158 _T(L16A16_SINT
, 16_16_SINT
, NONE
, WZYX
),
160 VT(R8G8B8A8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WZYX
),
161 _T(R8G8B8X8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WZYX
),
162 _T(R8G8B8A8_SRGB
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WZYX
),
163 _T(R8G8B8X8_SRGB
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WZYX
),
164 VT(R8G8B8A8_SNORM
, 8_8_8_8_SNORM
, R8G8B8A8_SNORM
, WZYX
),
165 VT(R8G8B8A8_UINT
, 8_8_8_8_UINT
, R8G8B8A8_UINT
, WZYX
),
166 VT(R8G8B8A8_SINT
, 8_8_8_8_SINT
, R8G8B8A8_SINT
, WZYX
),
167 V_(R8G8B8A8_USCALED
, 8_8_8_8_UINT
, NONE
, WZYX
),
168 V_(R8G8B8A8_SSCALED
, 8_8_8_8_SINT
, NONE
, WZYX
),
170 VT(B8G8R8A8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WXYZ
),
171 _T(B8G8R8X8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WXYZ
),
172 VT(B8G8R8A8_SRGB
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WXYZ
),
173 _T(B8G8R8X8_SRGB
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WXYZ
),
175 VT(A8B8G8R8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, XYZW
),
176 _T(X8B8G8R8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, XYZW
),
177 _T(A8B8G8R8_SRGB
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, XYZW
),
178 _T(X8B8G8R8_SRGB
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, XYZW
),
180 VT(A8R8G8B8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, ZYXW
),
181 _T(X8R8G8B8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, ZYXW
),
182 _T(A8R8G8B8_SRGB
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, ZYXW
),
183 _T(X8R8G8B8_SRGB
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, ZYXW
),
185 VT(R10G10B10A2_UNORM
, 10_10_10_2_UNORM
, R10G10B10A2_UNORM
, WZYX
),
186 VT(B10G10R10A2_UNORM
, 10_10_10_2_UNORM
, R10G10B10A2_UNORM
, WXYZ
),
187 _T(B10G10R10X2_UNORM
, 10_10_10_2_UNORM
, R10G10B10A2_UNORM
, WXYZ
),
188 V_(R10G10B10A2_SNORM
, 10_10_10_2_SNORM
, NONE
, WZYX
),
189 V_(R10G10B10A2_UINT
, 10_10_10_2_UINT
, NONE
, WZYX
),
190 V_(R10G10B10A2_USCALED
, 10_10_10_2_UINT
, NONE
, WZYX
),
191 V_(R10G10B10A2_SSCALED
, 10_10_10_2_SINT
, NONE
, WZYX
),
193 _T(R11G11B10_FLOAT
, 11_11_10_FLOAT
, R11G11B10_FLOAT
, WZYX
),
194 _T(R9G9B9E5_FLOAT
, 9_9_9_E5_FLOAT
, NONE
, WZYX
),
196 _T(Z24X8_UNORM
, X8Z24_UNORM
, R8G8B8A8_UNORM
, WZYX
),
197 _T(Z24_UNORM_S8_UINT
, X8Z24_UNORM
, R8G8B8A8_UNORM
, WZYX
),
198 /*_T(Z32_FLOAT, Z32_FLOAT, R8G8B8A8_UNORM, WZYX),*/
201 V_(R16G16B16_UNORM
, 16_16_16_UNORM
, NONE
, WZYX
),
202 V_(R16G16B16_SNORM
, 16_16_16_SNORM
, NONE
, WZYX
),
203 V_(R16G16B16_UINT
, 16_16_16_UINT
, NONE
, WZYX
),
204 V_(R16G16B16_SINT
, 16_16_16_SINT
, NONE
, WZYX
),
205 V_(R16G16B16_USCALED
, 16_16_16_UINT
, NONE
, WZYX
),
206 V_(R16G16B16_SSCALED
, 16_16_16_SINT
, NONE
, WZYX
),
207 V_(R16G16B16_FLOAT
, 16_16_16_FLOAT
, NONE
, WZYX
),
210 VT(R16G16B16A16_UNORM
, 16_16_16_16_UNORM
, NONE
, WZYX
),
211 VT(R16G16B16A16_SNORM
, 16_16_16_16_SNORM
, NONE
, WZYX
),
212 VT(R16G16B16A16_UINT
, 16_16_16_16_UINT
, R16G16B16A16_UINT
, WZYX
),
213 _T(R16G16B16X16_UINT
, 16_16_16_16_UINT
, R16G16B16A16_UINT
, WZYX
),
214 VT(R16G16B16A16_SINT
, 16_16_16_16_SINT
, R16G16B16A16_SINT
, WZYX
),
215 _T(R16G16B16X16_SINT
, 16_16_16_16_SINT
, R16G16B16A16_SINT
, WZYX
),
216 V_(R16G16B16A16_USCALED
, 16_16_16_16_UINT
, NONE
, WZYX
),
217 V_(R16G16B16A16_SSCALED
, 16_16_16_16_SINT
, NONE
, WZYX
),
218 VT(R16G16B16A16_FLOAT
, 16_16_16_16_FLOAT
, R16G16B16A16_FLOAT
, WZYX
),
219 _T(R16G16B16X16_FLOAT
, 16_16_16_16_FLOAT
, R16G16B16A16_FLOAT
, WZYX
),
221 VT(R32G32_UINT
, 32_32_UINT
, R32G32_UINT
, WZYX
),
222 VT(R32G32_SINT
, 32_32_SINT
, R32G32_SINT
, WZYX
),
223 V_(R32G32_USCALED
, 32_32_UINT
, NONE
, WZYX
),
224 V_(R32G32_SSCALED
, 32_32_SINT
, NONE
, WZYX
),
225 VT(R32G32_FLOAT
, 32_32_FLOAT
, NONE
, WZYX
),
226 V_(R32G32_FIXED
, 32_32_FIXED
, NONE
, WZYX
),
228 _T(L32A32_UINT
, 32_32_UINT
, NONE
, WZYX
),
229 _T(L32A32_SINT
, 32_32_SINT
, NONE
, WZYX
),
232 V_(R32G32B32_UINT
, 32_32_32_UINT
, NONE
, WZYX
),
233 V_(R32G32B32_SINT
, 32_32_32_SINT
, NONE
, WZYX
),
234 V_(R32G32B32_USCALED
, 32_32_32_UINT
, NONE
, WZYX
),
235 V_(R32G32B32_SSCALED
, 32_32_32_SINT
, NONE
, WZYX
),
236 V_(R32G32B32_FLOAT
, 32_32_32_FLOAT
, NONE
, WZYX
),
237 V_(R32G32B32_FIXED
, 32_32_32_FIXED
, NONE
, WZYX
),
240 VT(R32G32B32A32_UINT
, 32_32_32_32_UINT
, R32G32B32A32_UINT
, WZYX
),
241 _T(R32G32B32X32_UINT
, 32_32_32_32_UINT
, R32G32B32A32_UINT
, WZYX
),
242 VT(R32G32B32A32_SINT
, 32_32_32_32_SINT
, R32G32B32A32_SINT
, WZYX
),
243 _T(R32G32B32X32_SINT
, 32_32_32_32_SINT
, R32G32B32A32_SINT
, WZYX
),
244 V_(R32G32B32A32_USCALED
, 32_32_32_32_UINT
, NONE
, WZYX
),
245 V_(R32G32B32A32_SSCALED
, 32_32_32_32_SINT
, NONE
, WZYX
),
246 VT(R32G32B32A32_FLOAT
, 32_32_32_32_FLOAT
, R32G32B32A32_FLOAT
, WZYX
),
247 _T(R32G32B32X32_FLOAT
, 32_32_32_32_FLOAT
, R32G32B32A32_FLOAT
, WZYX
),
248 V_(R32G32B32A32_FIXED
, 32_32_32_32_FIXED
, NONE
, WZYX
),
251 _T(ETC1_RGB8
, ETC1
, NONE
, WZYX
),
252 _T(ETC2_RGB8
, ETC2_RGB8
, NONE
, WZYX
),
253 _T(ETC2_SRGB8
, ETC2_RGB8
, NONE
, WZYX
),
254 _T(ETC2_RGB8A1
, ETC2_RGB8A1
, NONE
, WZYX
),
255 _T(ETC2_SRGB8A1
, ETC2_RGB8A1
, NONE
, WZYX
),
256 _T(ETC2_RGBA8
, ETC2_RGBA8
, NONE
, WZYX
),
257 _T(ETC2_SRGBA8
, ETC2_RGBA8
, NONE
, WZYX
),
258 _T(ETC2_R11_UNORM
, ETC2_R11_UNORM
, NONE
, WZYX
),
259 _T(ETC2_R11_SNORM
, ETC2_R11_SNORM
, NONE
, WZYX
),
260 _T(ETC2_RG11_UNORM
, ETC2_RG11_UNORM
, NONE
, WZYX
),
261 _T(ETC2_RG11_SNORM
, ETC2_RG11_SNORM
, NONE
, WZYX
),
265 fd3_pipe2vtx(enum pipe_format format
)
267 if (!formats
[format
].present
)
269 return formats
[format
].vtx
;
273 fd3_pipe2tex(enum pipe_format format
)
275 if (!formats
[format
].present
)
277 return formats
[format
].tex
;
281 fd3_pipe2color(enum pipe_format format
)
283 if (!formats
[format
].present
)
285 return formats
[format
].rb
;
289 fd3_pipe2swap(enum pipe_format format
)
291 if (!formats
[format
].present
)
293 return formats
[format
].swap
;
296 enum a3xx_tex_fetchsize
297 fd3_pipe2fetchsize(enum pipe_format format
)
299 switch (util_format_get_blocksizebits(format
)) {
300 case 8: return TFETCH_1_BYTE
;
301 case 16: return TFETCH_2_BYTE
;
302 case 32: return TFETCH_4_BYTE
;
303 case 64: return TFETCH_8_BYTE
;
304 case 128: return TFETCH_16_BYTE
;
306 debug_printf("Unknown block size for format %s: %d\n",
307 util_format_name(format
),
308 util_format_get_blocksizebits(format
));
309 return TFETCH_DISABLE
;
313 /* we need to special case a bit the depth/stencil restore, because we are
314 * using the texture sampler to blit into the depth/stencil buffer, *not*
315 * into a color buffer. Otherwise fd3_tex_swiz() will do the wrong thing,
316 * as it is assuming that you are sampling into normal render target..
319 fd3_gmem_restore_format(enum pipe_format format
)
322 case PIPE_FORMAT_Z24X8_UNORM
:
323 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
324 return PIPE_FORMAT_R8G8B8A8_UNORM
;
325 case PIPE_FORMAT_Z16_UNORM
:
326 return PIPE_FORMAT_R8G8_UNORM
;
333 fd3_fs_output_format(enum pipe_format format
)
335 if (util_format_is_srgb(format
))
336 return RB_R16G16B16A16_FLOAT
;
338 case PIPE_FORMAT_R11G11B10_FLOAT
:
339 return RB_R16G16B16A16_FLOAT
;
341 return fd3_pipe2color(format
);
345 static inline enum a3xx_tex_swiz
346 tex_swiz(unsigned swiz
)
350 case PIPE_SWIZZLE_RED
: return A3XX_TEX_X
;
351 case PIPE_SWIZZLE_GREEN
: return A3XX_TEX_Y
;
352 case PIPE_SWIZZLE_BLUE
: return A3XX_TEX_Z
;
353 case PIPE_SWIZZLE_ALPHA
: return A3XX_TEX_W
;
354 case PIPE_SWIZZLE_ZERO
: return A3XX_TEX_ZERO
;
355 case PIPE_SWIZZLE_ONE
: return A3XX_TEX_ONE
;
360 fd3_tex_swiz(enum pipe_format format
, unsigned swizzle_r
, unsigned swizzle_g
,
361 unsigned swizzle_b
, unsigned swizzle_a
)
363 const struct util_format_description
*desc
=
364 util_format_description(format
);
365 unsigned char swiz
[4] = {
366 swizzle_r
, swizzle_g
, swizzle_b
, swizzle_a
,
369 util_format_compose_swizzles(desc
->swizzle
, swiz
, rswiz
);
371 return A3XX_TEX_CONST_0_SWIZ_X(tex_swiz(rswiz
[0])) |
372 A3XX_TEX_CONST_0_SWIZ_Y(tex_swiz(rswiz
[1])) |
373 A3XX_TEX_CONST_0_SWIZ_Z(tex_swiz(rswiz
[2])) |
374 A3XX_TEX_CONST_0_SWIZ_W(tex_swiz(rswiz
[3]));