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
),
88 V_(R16_UNORM
, 16_UNORM
, NONE
, WZYX
),
89 V_(R16_SNORM
, 16_SNORM
, NONE
, WZYX
),
90 VT(R16_UINT
, 16_UINT
, R16_UINT
, WZYX
),
91 VT(R16_SINT
, 16_SINT
, R16_SINT
, WZYX
),
92 V_(R16_USCALED
, 16_UINT
, NONE
, WZYX
),
93 V_(R16_SSCALED
, 16_UINT
, NONE
, WZYX
),
94 VT(R16_FLOAT
, 16_FLOAT
, NONE
, WZYX
),
96 VT(R8G8_UNORM
, 8_8_UNORM
, R8G8_UNORM
, WZYX
),
97 VT(R8G8_SNORM
, 8_8_SNORM
, R8G8_SNORM
, WZYX
),
98 VT(R8G8_UINT
, 8_8_UINT
, NONE
, WZYX
),
99 VT(R8G8_SINT
, 8_8_SINT
, NONE
, WZYX
),
100 V_(R8G8_USCALED
, 8_8_UINT
, NONE
, WZYX
),
101 V_(R8G8_SSCALED
, 8_8_SINT
, NONE
, WZYX
),
103 _T(Z16_UNORM
, Z16_UNORM
, R8G8_UNORM
, WZYX
),
104 /*_T(B5G6R5_UNORM, 5_6_5_UNORM, R5G6B5_UNORM, WXYZ),*/
105 _T(B5G5R5A1_UNORM
, 5_5_5_1_UNORM
, R5G5B5A1_UNORM
, WXYZ
),
106 _T(B5G5R5X1_UNORM
, 5_5_5_1_UNORM
, R5G5B5A1_UNORM
, WXYZ
),
107 _T(B4G4R4A4_UNORM
, 4_4_4_4_UNORM
, R4G4B4A4_UNORM
, WXYZ
),
110 V_(R8G8B8_UNORM
, 8_8_8_UNORM
, NONE
, WZYX
),
111 V_(R8G8B8_SNORM
, 8_8_8_SNORM
, NONE
, WZYX
),
112 V_(R8G8B8_UINT
, 8_8_8_UINT
, NONE
, WZYX
),
113 V_(R8G8B8_SINT
, 8_8_8_SINT
, NONE
, WZYX
),
114 V_(R8G8B8_USCALED
, 8_8_8_UINT
, NONE
, WZYX
),
115 V_(R8G8B8_SSCALED
, 8_8_8_SINT
, NONE
, WZYX
),
118 VT(R32_UINT
, 32_UINT
, R32_UINT
, WZYX
),
119 VT(R32_SINT
, 32_SINT
, R32_SINT
, WZYX
),
120 V_(R32_USCALED
, 32_UINT
, NONE
, WZYX
),
121 V_(R32_SSCALED
, 32_UINT
, NONE
, WZYX
),
122 VT(R32_FLOAT
, 32_FLOAT
, NONE
, WZYX
),
123 V_(R32_FIXED
, 32_FIXED
, NONE
, WZYX
),
125 V_(R16G16_UNORM
, 16_16_UNORM
, NONE
, WZYX
),
126 V_(R16G16_SNORM
, 16_16_SNORM
, NONE
, WZYX
),
127 VT(R16G16_UINT
, 16_16_UINT
, R16G16_UINT
, WZYX
),
128 VT(R16G16_SINT
, 16_16_SINT
, R16G16_SINT
, WZYX
),
129 V_(R16G16_USCALED
, 16_16_UINT
, NONE
, WZYX
),
130 V_(R16G16_SSCALED
, 16_16_SINT
, NONE
, WZYX
),
131 VT(R16G16_FLOAT
, 16_16_FLOAT
, NONE
, WZYX
),
133 VT(R8G8B8A8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WZYX
),
134 _T(R8G8B8X8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WZYX
),
135 _T(R8G8B8A8_SRGB
, 8_8_8_8_UNORM
, NONE
, WZYX
),
136 _T(R8G8B8X8_SRGB
, 8_8_8_8_UNORM
, NONE
, WZYX
),
137 VT(R8G8B8A8_SNORM
, 8_8_8_8_SNORM
, R8G8B8A8_SNORM
, WZYX
),
138 VT(R8G8B8A8_UINT
, 8_8_8_8_UINT
, R8G8B8A8_UINT
, WZYX
),
139 VT(R8G8B8A8_SINT
, 8_8_8_8_SINT
, R8G8B8A8_SINT
, WZYX
),
140 V_(R8G8B8A8_USCALED
, 8_8_8_8_UINT
, NONE
, WZYX
),
141 V_(R8G8B8A8_SSCALED
, 8_8_8_8_SINT
, NONE
, WZYX
),
143 VT(B8G8R8A8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WXYZ
),
144 _T(B8G8R8X8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, WXYZ
),
145 VT(B8G8R8A8_SRGB
, 8_8_8_8_UNORM
, NONE
, WXYZ
),
146 _T(B8G8R8X8_SRGB
, 8_8_8_8_UNORM
, NONE
, WXYZ
),
148 VT(A8B8G8R8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, XYZW
),
149 _T(X8B8G8R8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, XYZW
),
150 _T(A8B8G8R8_SRGB
, 8_8_8_8_UNORM
, NONE
, XYZW
),
151 _T(X8B8G8R8_SRGB
, 8_8_8_8_UNORM
, NONE
, XYZW
),
153 VT(A8R8G8B8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, ZYXW
),
154 _T(X8R8G8B8_UNORM
, 8_8_8_8_UNORM
, R8G8B8A8_UNORM
, ZYXW
),
155 _T(A8R8G8B8_SRGB
, 8_8_8_8_UNORM
, NONE
, ZYXW
),
156 _T(X8R8G8B8_SRGB
, 8_8_8_8_UNORM
, NONE
, ZYXW
),
158 V_(R10G10B10A2_UNORM
, 10_10_10_2_UNORM
, NONE
/*R10G10B10A2_UNORM*/, WZYX
),
159 V_(R10G10B10A2_SNORM
, 10_10_10_2_SNORM
, NONE
, WZYX
),
160 V_(R10G10B10A2_UINT
, 10_10_10_2_UINT
, NONE
, WZYX
),
161 V_(R10G10B10A2_USCALED
, 10_10_10_2_UINT
, NONE
, WZYX
),
162 V_(R10G10B10A2_SSCALED
, 10_10_10_2_SINT
, NONE
, WZYX
),
164 _T(R11G11B10_FLOAT
, 11_11_10_FLOAT
, R11G11B10_FLOAT
, WZYX
),
165 _T(R9G9B9E5_FLOAT
, 9_9_9_E5_FLOAT
, NONE
, WZYX
),
167 _T(Z24X8_UNORM
, X8Z24_UNORM
, R8G8B8A8_UNORM
, WZYX
),
168 _T(Z24_UNORM_S8_UINT
, X8Z24_UNORM
, R8G8B8A8_UNORM
, WZYX
),
169 /*_T(Z32_FLOAT, Z32_FLOAT, R8G8B8A8_UNORM, WZYX),*/
172 V_(R16G16B16_UNORM
, 16_16_16_UNORM
, NONE
, WZYX
),
173 V_(R16G16B16_SNORM
, 16_16_16_SNORM
, NONE
, WZYX
),
174 V_(R16G16B16_UINT
, 16_16_16_UINT
, NONE
, WZYX
),
175 V_(R16G16B16_SINT
, 16_16_16_SINT
, NONE
, WZYX
),
176 V_(R16G16B16_USCALED
, 16_16_16_UINT
, NONE
, WZYX
),
177 V_(R16G16B16_SSCALED
, 16_16_16_SINT
, NONE
, WZYX
),
178 V_(R16G16B16_FLOAT
, 16_16_16_FLOAT
, NONE
, WZYX
),
181 V_(R16G16B16A16_UNORM
, 16_16_16_16_UNORM
, NONE
, WZYX
),
182 V_(R16G16B16A16_SNORM
, 16_16_16_16_SNORM
, NONE
, WZYX
),
183 VT(R16G16B16A16_UINT
, 16_16_16_16_UINT
, R16G16B16A16_UINT
, WZYX
),
184 _T(R16G16B16X16_UINT
, 16_16_16_16_UINT
, R16G16B16A16_UINT
, WZYX
),
185 VT(R16G16B16A16_SINT
, 16_16_16_16_SINT
, R16G16B16A16_SINT
, WZYX
),
186 _T(R16G16B16X16_SINT
, 16_16_16_16_SINT
, R16G16B16A16_SINT
, WZYX
),
187 V_(R16G16B16A16_USCALED
, 16_16_16_16_UINT
, NONE
, WZYX
),
188 V_(R16G16B16A16_SSCALED
, 16_16_16_16_SINT
, NONE
, WZYX
),
189 VT(R16G16B16A16_FLOAT
, 16_16_16_16_FLOAT
, R16G16B16A16_FLOAT
, WZYX
),
190 _T(R16G16B16X16_FLOAT
, 16_16_16_16_FLOAT
, R16G16B16A16_FLOAT
, WZYX
),
192 VT(R32G32_UINT
, 32_32_UINT
, R32G32_UINT
, WZYX
),
193 VT(R32G32_SINT
, 32_32_SINT
, R32G32_SINT
, WZYX
),
194 V_(R32G32_USCALED
, 32_32_UINT
, NONE
, WZYX
),
195 V_(R32G32_SSCALED
, 32_32_SINT
, NONE
, WZYX
),
196 VT(R32G32_FLOAT
, 32_32_FLOAT
, NONE
, WZYX
),
197 V_(R32G32_FIXED
, 32_32_FIXED
, NONE
, WZYX
),
200 V_(R32G32B32_UINT
, 32_32_32_UINT
, NONE
, WZYX
),
201 V_(R32G32B32_SINT
, 32_32_32_SINT
, NONE
, WZYX
),
202 V_(R32G32B32_USCALED
, 32_32_32_UINT
, NONE
, WZYX
),
203 V_(R32G32B32_SSCALED
, 32_32_32_SINT
, NONE
, WZYX
),
204 V_(R32G32B32_FLOAT
, 32_32_32_FLOAT
, NONE
, WZYX
),
205 V_(R32G32B32_FIXED
, 32_32_32_FIXED
, NONE
, WZYX
),
208 VT(R32G32B32A32_UINT
, 32_32_32_32_UINT
, R32G32B32A32_UINT
, WZYX
),
209 _T(R32G32B32X32_UINT
, 32_32_32_32_UINT
, R32G32B32A32_UINT
, WZYX
),
210 VT(R32G32B32A32_SINT
, 32_32_32_32_SINT
, R32G32B32A32_SINT
, WZYX
),
211 _T(R32G32B32X32_SINT
, 32_32_32_32_SINT
, R32G32B32A32_SINT
, WZYX
),
212 V_(R32G32B32A32_USCALED
, 32_32_32_32_UINT
, NONE
, WZYX
),
213 V_(R32G32B32A32_SSCALED
, 32_32_32_32_SINT
, NONE
, WZYX
),
214 VT(R32G32B32A32_FLOAT
, 32_32_32_32_FLOAT
, R32G32B32A32_FLOAT
, WZYX
),
215 _T(R32G32B32X32_FLOAT
, 32_32_32_32_FLOAT
, R32G32B32A32_FLOAT
, WZYX
),
216 V_(R32G32B32A32_FIXED
, 32_32_32_32_FIXED
, NONE
, WZYX
),
220 fd3_pipe2vtx(enum pipe_format format
)
222 if (!formats
[format
].present
)
224 return formats
[format
].vtx
;
228 fd3_pipe2tex(enum pipe_format format
)
230 if (!formats
[format
].present
)
232 return formats
[format
].tex
;
236 fd3_pipe2color(enum pipe_format format
)
238 if (!formats
[format
].present
)
240 /* Integer formats don't render properly yet */
241 if (util_format_is_pure_integer(format
))
243 return formats
[format
].rb
;
247 fd3_pipe2swap(enum pipe_format format
)
249 if (!formats
[format
].present
)
251 return formats
[format
].swap
;
254 enum a3xx_tex_fetchsize
255 fd3_pipe2fetchsize(enum pipe_format format
)
257 switch (util_format_get_blocksizebits(format
)) {
258 case 8: return TFETCH_1_BYTE
;
259 case 16: return TFETCH_2_BYTE
;
260 case 32: return TFETCH_4_BYTE
;
261 case 64: return TFETCH_8_BYTE
;
262 case 128: return TFETCH_16_BYTE
;
264 debug_printf("Unknown block size for format %s: %d\n",
265 util_format_name(format
),
266 util_format_get_blocksizebits(format
));
267 return TFETCH_DISABLE
;
271 /* we need to special case a bit the depth/stencil restore, because we are
272 * using the texture sampler to blit into the depth/stencil buffer, *not*
273 * into a color buffer. Otherwise fd3_tex_swiz() will do the wrong thing,
274 * as it is assuming that you are sampling into normal render target..
277 fd3_gmem_restore_format(enum pipe_format format
)
280 case PIPE_FORMAT_Z24X8_UNORM
:
281 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
282 return PIPE_FORMAT_R8G8B8A8_UNORM
;
283 case PIPE_FORMAT_Z16_UNORM
:
284 return PIPE_FORMAT_R8G8_UNORM
;
290 static inline enum a3xx_tex_swiz
291 tex_swiz(unsigned swiz
)
295 case PIPE_SWIZZLE_RED
: return A3XX_TEX_X
;
296 case PIPE_SWIZZLE_GREEN
: return A3XX_TEX_Y
;
297 case PIPE_SWIZZLE_BLUE
: return A3XX_TEX_Z
;
298 case PIPE_SWIZZLE_ALPHA
: return A3XX_TEX_W
;
299 case PIPE_SWIZZLE_ZERO
: return A3XX_TEX_ZERO
;
300 case PIPE_SWIZZLE_ONE
: return A3XX_TEX_ONE
;
305 fd3_tex_swiz(enum pipe_format format
, unsigned swizzle_r
, unsigned swizzle_g
,
306 unsigned swizzle_b
, unsigned swizzle_a
)
308 const struct util_format_description
*desc
=
309 util_format_description(format
);
310 unsigned char swiz
[4] = {
311 swizzle_r
, swizzle_g
, swizzle_b
, swizzle_a
,
314 util_format_compose_swizzles(desc
->swizzle
, swiz
, rswiz
);
316 return A3XX_TEX_CONST_0_SWIZ_X(tex_swiz(rswiz
[0])) |
317 A3XX_TEX_CONST_0_SWIZ_Y(tex_swiz(rswiz
[1])) |
318 A3XX_TEX_CONST_0_SWIZ_Z(tex_swiz(rswiz
[2])) |
319 A3XX_TEX_CONST_0_SWIZ_W(tex_swiz(rswiz
[3]));