1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
29 #include "pipe/p_defines.h"
30 #include "util/u_format.h"
32 #include "fd3_format.h"
34 /* convert pipe format to vertex buffer format: */
36 fd3_pipe2vtx(enum pipe_format format
)
40 case PIPE_FORMAT_R8_UNORM
:
41 return VFMT_NORM_UBYTE_8
;
43 case PIPE_FORMAT_R8_SNORM
:
44 return VFMT_NORM_BYTE_8
;
46 case PIPE_FORMAT_R8_UINT
:
47 case PIPE_FORMAT_R8_USCALED
:
50 case PIPE_FORMAT_R8_SINT
:
51 case PIPE_FORMAT_R8_SSCALED
:
55 case PIPE_FORMAT_R16_UNORM
:
56 case PIPE_FORMAT_Z16_UNORM
:
57 return VFMT_NORM_USHORT_16
;
59 case PIPE_FORMAT_R16_SNORM
:
60 return VFMT_NORM_SHORT_16
;
62 case PIPE_FORMAT_R16_UINT
:
63 case PIPE_FORMAT_R16_USCALED
:
64 return VFMT_USHORT_16
;
66 case PIPE_FORMAT_R16_SINT
:
67 case PIPE_FORMAT_R16_SSCALED
:
70 case PIPE_FORMAT_R16_FLOAT
:
73 case PIPE_FORMAT_R8G8_UNORM
:
74 return VFMT_NORM_UBYTE_8_8
;
76 case PIPE_FORMAT_R8G8_SNORM
:
77 return VFMT_NORM_BYTE_8_8
;
79 case PIPE_FORMAT_R8G8_UINT
:
80 case PIPE_FORMAT_R8G8_USCALED
:
81 return VFMT_UBYTE_8_8
;
83 case PIPE_FORMAT_R8G8_SINT
:
84 case PIPE_FORMAT_R8G8_SSCALED
:
88 case PIPE_FORMAT_R8G8B8_UNORM
:
89 return VFMT_NORM_UBYTE_8_8_8
;
91 case PIPE_FORMAT_R8G8B8_SNORM
:
92 return VFMT_NORM_BYTE_8_8_8
;
94 case PIPE_FORMAT_R8G8B8_UINT
:
95 case PIPE_FORMAT_R8G8B8_USCALED
:
96 return VFMT_UBYTE_8_8_8
;
98 case PIPE_FORMAT_R8G8B8_SINT
:
99 case PIPE_FORMAT_R8G8B8_SSCALED
:
100 return VFMT_BYTE_8_8_8
;
102 /* 32-bit buffers. */
103 case PIPE_FORMAT_A8B8G8R8_UNORM
:
104 case PIPE_FORMAT_A8R8G8B8_UNORM
:
105 case PIPE_FORMAT_B8G8R8A8_UNORM
:
106 case PIPE_FORMAT_R8G8B8A8_UNORM
:
107 return VFMT_NORM_UBYTE_8_8_8_8
;
109 case PIPE_FORMAT_R8G8B8A8_SNORM
:
110 return VFMT_NORM_BYTE_8_8_8_8
;
112 case PIPE_FORMAT_R8G8B8A8_UINT
:
113 case PIPE_FORMAT_R8G8B8A8_USCALED
:
114 return VFMT_UBYTE_8_8_8_8
;
116 case PIPE_FORMAT_R8G8B8A8_SINT
:
117 case PIPE_FORMAT_R8G8B8A8_SSCALED
:
118 return VFMT_BYTE_8_8_8_8
;
120 case PIPE_FORMAT_R16G16_SSCALED
:
121 case PIPE_FORMAT_R16G16_SINT
:
122 return VFMT_SHORT_16_16
;
124 case PIPE_FORMAT_R16G16_FLOAT
:
125 return VFMT_FLOAT_16_16
;
127 case PIPE_FORMAT_R16G16_UINT
:
128 case PIPE_FORMAT_R16G16_USCALED
:
129 return VFMT_USHORT_16_16
;
131 case PIPE_FORMAT_R16G16_UNORM
:
132 return VFMT_NORM_USHORT_16_16
;
134 case PIPE_FORMAT_R16G16_SNORM
:
135 return VFMT_NORM_SHORT_16_16
;
137 case PIPE_FORMAT_R32_UINT
:
138 case PIPE_FORMAT_R32_USCALED
:
141 case PIPE_FORMAT_R32_SINT
:
142 case PIPE_FORMAT_R32_SSCALED
:
145 case PIPE_FORMAT_R10G10B10A2_UNORM
:
146 return VFMT_NORM_UINT_10_10_10_2
;
148 case PIPE_FORMAT_R10G10B10A2_SNORM
:
149 return VFMT_NORM_INT_10_10_10_2
;
151 case PIPE_FORMAT_R10G10B10A2_UINT
:
152 case PIPE_FORMAT_R10G10B10A2_USCALED
:
153 return VFMT_UINT_10_10_10_2
;
155 case PIPE_FORMAT_R10G10B10A2_SSCALED
:
156 return VFMT_INT_10_10_10_2
;
158 /* 48-bit buffers. */
159 case PIPE_FORMAT_R16G16B16_FLOAT
:
160 return VFMT_FLOAT_16_16_16
;
162 case PIPE_FORMAT_R16G16B16_SINT
:
163 case PIPE_FORMAT_R16G16B16_SSCALED
:
164 return VFMT_SHORT_16_16_16
;
166 case PIPE_FORMAT_R16G16B16_UINT
:
167 case PIPE_FORMAT_R16G16B16_USCALED
:
168 return VFMT_USHORT_16_16_16
;
170 case PIPE_FORMAT_R16G16B16_SNORM
:
171 return VFMT_NORM_SHORT_16_16_16
;
173 case PIPE_FORMAT_R16G16B16_UNORM
:
174 return VFMT_NORM_USHORT_16_16_16
;
176 case PIPE_FORMAT_R32_FLOAT
:
177 case PIPE_FORMAT_Z32_FLOAT
:
178 return VFMT_FLOAT_32
;
180 case PIPE_FORMAT_R32_FIXED
:
181 return VFMT_FIXED_32
;
183 /* 64-bit buffers. */
184 case PIPE_FORMAT_R16G16B16A16_UNORM
:
185 return VFMT_NORM_USHORT_16_16_16_16
;
187 case PIPE_FORMAT_R16G16B16A16_SNORM
:
188 return VFMT_NORM_SHORT_16_16_16_16
;
190 case PIPE_FORMAT_R16G16B16A16_UINT
:
191 case PIPE_FORMAT_R16G16B16A16_USCALED
:
192 return VFMT_USHORT_16_16_16_16
;
194 case PIPE_FORMAT_R16G16B16A16_SINT
:
195 case PIPE_FORMAT_R16G16B16A16_SSCALED
:
196 return VFMT_SHORT_16_16_16_16
;
198 case PIPE_FORMAT_R32G32_FLOAT
:
199 return VFMT_FLOAT_32_32
;
201 case PIPE_FORMAT_R32G32_FIXED
:
202 return VFMT_FIXED_32_32
;
204 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
205 return VFMT_FLOAT_16_16_16_16
;
207 case PIPE_FORMAT_R32G32_UINT
:
208 case PIPE_FORMAT_R32G32_USCALED
:
209 return VFMT_UINT_32_32
;
211 case PIPE_FORMAT_R32G32_SINT
:
212 case PIPE_FORMAT_R32G32_SSCALED
:
213 return VFMT_INT_32_32
;
215 /* 96-bit buffers. */
216 case PIPE_FORMAT_R32G32B32_FLOAT
:
217 return VFMT_FLOAT_32_32_32
;
219 case PIPE_FORMAT_R32G32B32_FIXED
:
220 return VFMT_FIXED_32_32_32
;
222 case PIPE_FORMAT_R32G32B32_UINT
:
223 case PIPE_FORMAT_R32G32B32_USCALED
:
224 return VFMT_UINT_32_32_32
;
226 case PIPE_FORMAT_R32G32B32_SINT
:
227 case PIPE_FORMAT_R32G32B32_SSCALED
:
228 return VFMT_INT_32_32_32
;
230 /* 128-bit buffers. */
231 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
232 return VFMT_FLOAT_32_32_32_32
;
234 case PIPE_FORMAT_R32G32B32A32_FIXED
:
235 return VFMT_FIXED_32_32_32_32
;
237 case PIPE_FORMAT_R32G32B32A32_UINT
:
238 case PIPE_FORMAT_R32G32B32A32_USCALED
:
239 return VFMT_UINT_32_32_32_32
;
241 case PIPE_FORMAT_R32G32B32A32_SINT
:
242 case PIPE_FORMAT_R32G32B32A32_SSCALED
:
243 return VFMT_INT_32_32_32_32
;
245 /* TODO normalized 32bit int formats do not appear to be supported
246 * natively.. will require either shader variant or VFD_DECODE
247 * gymnastics like the blob driver does..
248 case PIPE_FORMAT_R32G32B32A32_SNORM:
249 case PIPE_FORMAT_R32G32B32A32_UNORM:
257 /* convert pipe format to texture sampler format: */
259 fd3_pipe2tex(enum pipe_format format
)
262 case PIPE_FORMAT_L8_UNORM
:
263 case PIPE_FORMAT_A8_UNORM
:
264 case PIPE_FORMAT_I8_UNORM
:
265 return TFMT_NORM_UINT_8
;
267 case PIPE_FORMAT_R8G8_UNORM
:
268 return TFMT_NORM_UINT_8_8
;
270 case PIPE_FORMAT_B8G8R8A8_UNORM
:
271 case PIPE_FORMAT_B8G8R8X8_UNORM
:
272 case PIPE_FORMAT_R8G8B8A8_UNORM
:
273 case PIPE_FORMAT_R8G8B8X8_UNORM
:
274 case PIPE_FORMAT_B8G8R8A8_SRGB
:
275 case PIPE_FORMAT_B8G8R8X8_SRGB
:
276 case PIPE_FORMAT_R8G8B8A8_SRGB
:
277 case PIPE_FORMAT_R8G8B8X8_SRGB
:
278 return TFMT_NORM_UINT_8_8_8_8
;
280 case PIPE_FORMAT_Z24X8_UNORM
:
281 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
282 return TFMT_NORM_UINT_X8Z24
;
284 case PIPE_FORMAT_Z16_UNORM
:
285 return TFMT_NORM_USHORT_Z16
;
287 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
288 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
289 return TFMT_FLOAT_16_16_16_16
;
291 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
292 case PIPE_FORMAT_R32G32B32X32_FLOAT
:
293 return TFMT_FLOAT_32_32_32_32
;
302 enum a3xx_tex_fetchsize
303 fd3_pipe2fetchsize(enum pipe_format format
)
306 case PIPE_FORMAT_L8_UNORM
:
307 case PIPE_FORMAT_A8_UNORM
:
308 case PIPE_FORMAT_I8_UNORM
:
309 return TFETCH_1_BYTE
;
311 case PIPE_FORMAT_Z16_UNORM
:
312 return TFETCH_2_BYTE
;
314 case PIPE_FORMAT_B8G8R8A8_UNORM
:
315 case PIPE_FORMAT_B8G8R8X8_UNORM
:
316 case PIPE_FORMAT_R8G8B8A8_UNORM
:
317 case PIPE_FORMAT_R8G8B8X8_UNORM
:
318 case PIPE_FORMAT_B8G8R8A8_SRGB
:
319 case PIPE_FORMAT_B8G8R8X8_SRGB
:
320 case PIPE_FORMAT_R8G8B8A8_SRGB
:
321 case PIPE_FORMAT_R8G8B8X8_SRGB
:
322 case PIPE_FORMAT_Z24X8_UNORM
:
323 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
324 return TFETCH_4_BYTE
;
329 return TFETCH_DISABLE
; /* safe default */
333 /* convert pipe format to MRT / copydest format used for render-target: */
335 fd3_pipe2color(enum pipe_format format
)
338 case PIPE_FORMAT_B8G8R8A8_UNORM
:
339 case PIPE_FORMAT_B8G8R8X8_UNORM
:
340 case PIPE_FORMAT_R8G8B8A8_UNORM
:
341 return RB_R8G8B8A8_UNORM
;
343 case PIPE_FORMAT_Z16_UNORM
:
344 return RB_R8G8_UNORM
;
346 case PIPE_FORMAT_Z24X8_UNORM
:
347 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
348 /* for DEPTHX_24_8, blob driver also seems to use R8G8B8A8 fmt.. */
349 return RB_R8G8B8A8_UNORM
;
351 case PIPE_FORMAT_R8_UNORM
:
352 case PIPE_FORMAT_L8_UNORM
:
355 case PIPE_FORMAT_A8_UNORM
:
358 case PIPE_FORMAT_R16G16B16A16_FLOAT
:
359 case PIPE_FORMAT_R16G16B16X16_FLOAT
:
360 return RB_R16G16B16A16_FLOAT
;
362 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
363 case PIPE_FORMAT_R32G32B32X32_FLOAT
:
364 return RB_R32G32B32A32_FLOAT
;
373 /* we need to special case a bit the depth/stencil restore, because we are
374 * using the texture sampler to blit into the depth/stencil buffer, *not*
375 * into a color buffer. Otherwise fd3_tex_swiz() will do the wrong thing,
376 * as it is assuming that you are sampling into normal render target..
379 fd3_gmem_restore_format(enum pipe_format format
)
382 case PIPE_FORMAT_Z24X8_UNORM
:
383 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
384 return PIPE_FORMAT_R8G8B8A8_UNORM
;
385 case PIPE_FORMAT_Z16_UNORM
:
386 return PIPE_FORMAT_R8G8_UNORM
;
393 fd3_pipe2swap(enum pipe_format format
)
396 case PIPE_FORMAT_B8G8R8A8_UNORM
:
397 case PIPE_FORMAT_B8G8R8X8_UNORM
:
398 case PIPE_FORMAT_B8G8R8A8_SRGB
:
399 case PIPE_FORMAT_B8G8R8X8_SRGB
:
402 case PIPE_FORMAT_A8R8G8B8_UNORM
:
403 case PIPE_FORMAT_X8R8G8B8_UNORM
:
404 case PIPE_FORMAT_A8R8G8B8_SRGB
:
405 case PIPE_FORMAT_X8R8G8B8_SRGB
:
408 case PIPE_FORMAT_A8B8G8R8_UNORM
:
409 case PIPE_FORMAT_X8B8G8R8_UNORM
:
410 case PIPE_FORMAT_A8B8G8R8_SRGB
:
411 case PIPE_FORMAT_X8B8G8R8_SRGB
:
414 case PIPE_FORMAT_R8G8B8A8_UNORM
:
415 case PIPE_FORMAT_R8G8B8X8_UNORM
:
416 case PIPE_FORMAT_Z24X8_UNORM
:
417 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
423 static inline enum a3xx_tex_swiz
424 tex_swiz(unsigned swiz
)
428 case PIPE_SWIZZLE_RED
: return A3XX_TEX_X
;
429 case PIPE_SWIZZLE_GREEN
: return A3XX_TEX_Y
;
430 case PIPE_SWIZZLE_BLUE
: return A3XX_TEX_Z
;
431 case PIPE_SWIZZLE_ALPHA
: return A3XX_TEX_W
;
432 case PIPE_SWIZZLE_ZERO
: return A3XX_TEX_ZERO
;
433 case PIPE_SWIZZLE_ONE
: return A3XX_TEX_ONE
;
438 fd3_tex_swiz(enum pipe_format format
, unsigned swizzle_r
, unsigned swizzle_g
,
439 unsigned swizzle_b
, unsigned swizzle_a
)
441 const struct util_format_description
*desc
=
442 util_format_description(format
);
443 unsigned char swiz
[4] = {
444 swizzle_r
, swizzle_g
, swizzle_b
, swizzle_a
,
447 util_format_compose_swizzles(desc
->swizzle
, swiz
, rswiz
);
449 return A3XX_TEX_CONST_0_SWIZ_X(tex_swiz(rswiz
[0])) |
450 A3XX_TEX_CONST_0_SWIZ_Y(tex_swiz(rswiz
[1])) |
451 A3XX_TEX_CONST_0_SWIZ_Z(tex_swiz(rswiz
[2])) |
452 A3XX_TEX_CONST_0_SWIZ_W(tex_swiz(rswiz
[3]));