Home | History | Annotate | Download | only in a3xx
      1 /*
      2  * Copyright (C) 2013 Rob Clark <robclark (at) 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/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 #define RB_NONE ~0
     43 
     44 /* vertex + texture */
     45 #define VT(pipe, fmt, rbfmt, swapfmt) \
     46 	[PIPE_FORMAT_ ## pipe] = { \
     47 		.present = 1, \
     48 		.vtx = VFMT_ ## fmt, \
     49 		.tex = TFMT_ ## fmt, \
     50 		.rb = RB_ ## rbfmt, \
     51 		.swap = swapfmt \
     52 	}
     53 
     54 /* texture-only */
     55 #define _T(pipe, fmt, rbfmt, swapfmt) \
     56 	[PIPE_FORMAT_ ## pipe] = { \
     57 		.present = 1, \
     58 		.vtx = ~0, \
     59 		.tex = TFMT_ ## fmt, \
     60 		.rb = RB_ ## rbfmt, \
     61 		.swap = swapfmt \
     62 	}
     63 
     64 /* vertex-only */
     65 #define V_(pipe, fmt, rbfmt, swapfmt) \
     66 	[PIPE_FORMAT_ ## pipe] = { \
     67 		.present = 1, \
     68 		.vtx = VFMT_ ## fmt, \
     69 		.tex = ~0, \
     70 		.rb = RB_ ## rbfmt, \
     71 		.swap = swapfmt \
     72 	}
     73 
     74 static struct fd3_format formats[PIPE_FORMAT_COUNT] = {
     75 	/* 8-bit */
     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),
     82 
     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),
     86 
     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),
     93 
     94 	_T(S8_UINT,    8_UINT,  R8_UNORM, WZYX),
     95 
     96 	/* 16-bit */
     97 	VT(R16_UNORM,   16_UNORM, NONE,     WZYX),
     98 	VT(R16_SNORM,   16_SNORM, NONE,     WZYX),
     99 	VT(R16_UINT,    16_UINT,  R16_UINT, WZYX),
    100 	VT(R16_SINT,    16_SINT,  R16_SINT, WZYX),
    101 	V_(R16_USCALED, 16_UINT,  NONE,     WZYX),
    102 	V_(R16_SSCALED, 16_UINT,  NONE,     WZYX),
    103 	VT(R16_FLOAT,   16_FLOAT, R16_FLOAT,WZYX),
    104 
    105 	_T(A16_UINT,    16_UINT,  NONE,     WZYX),
    106 	_T(A16_SINT,    16_SINT,  NONE,     WZYX),
    107 	_T(L16_UINT,    16_UINT,  NONE,     WZYX),
    108 	_T(L16_SINT,    16_SINT,  NONE,     WZYX),
    109 	_T(I16_UINT,    16_UINT,  NONE,     WZYX),
    110 	_T(I16_SINT,    16_SINT,  NONE,     WZYX),
    111 
    112 	VT(R8G8_UNORM,   8_8_UNORM, R8G8_UNORM, WZYX),
    113 	VT(R8G8_SNORM,   8_8_SNORM, R8G8_SNORM, WZYX),
    114 	VT(R8G8_UINT,    8_8_UINT,  NONE,       WZYX),
    115 	VT(R8G8_SINT,    8_8_SINT,  NONE,       WZYX),
    116 	V_(R8G8_USCALED, 8_8_UINT,  NONE,       WZYX),
    117 	V_(R8G8_SSCALED, 8_8_SINT,  NONE,       WZYX),
    118 
    119 	_T(L8A8_UINT,    8_8_UINT,  NONE,       WZYX),
    120 	_T(L8A8_SINT,    8_8_SINT,  NONE,       WZYX),
    121 
    122 	_T(Z16_UNORM,      Z16_UNORM,     R8G8_UNORM,     WZYX),
    123 	_T(B5G6R5_UNORM,   5_6_5_UNORM,   R5G6B5_UNORM,   WXYZ),
    124 	_T(B5G5R5A1_UNORM, 5_5_5_1_UNORM, R5G5B5A1_UNORM, WXYZ),
    125 	_T(B5G5R5X1_UNORM, 5_5_5_1_UNORM, R5G5B5A1_UNORM, WXYZ),
    126 	_T(B4G4R4A4_UNORM, 4_4_4_4_UNORM, R4G4B4A4_UNORM, WXYZ),
    127 
    128 	/* 24-bit */
    129 	V_(R8G8B8_UNORM,   8_8_8_UNORM, NONE, WZYX),
    130 	V_(R8G8B8_SNORM,   8_8_8_SNORM, NONE, WZYX),
    131 	V_(R8G8B8_UINT,    8_8_8_UINT,  NONE, WZYX),
    132 	V_(R8G8B8_SINT,    8_8_8_SINT,  NONE, WZYX),
    133 	V_(R8G8B8_USCALED, 8_8_8_UINT,  NONE, WZYX),
    134 	V_(R8G8B8_SSCALED, 8_8_8_SINT,  NONE, WZYX),
    135 
    136 	/* 32-bit */
    137 	VT(R32_UINT,    32_UINT,  R32_UINT, WZYX),
    138 	VT(R32_SINT,    32_SINT,  R32_SINT, WZYX),
    139 	V_(R32_USCALED, 32_UINT,  NONE,     WZYX),
    140 	V_(R32_SSCALED, 32_UINT,  NONE,     WZYX),
    141 	VT(R32_FLOAT,   32_FLOAT, R32_FLOAT,WZYX),
    142 	V_(R32_FIXED,   32_FIXED, NONE,     WZYX),
    143 
    144 	_T(A32_UINT,    32_UINT,  NONE,     WZYX),
    145 	_T(A32_SINT,    32_SINT,  NONE,     WZYX),
    146 	_T(L32_UINT,    32_UINT,  NONE,     WZYX),
    147 	_T(L32_SINT,    32_SINT,  NONE,     WZYX),
    148 	_T(I32_UINT,    32_UINT,  NONE,     WZYX),
    149 	_T(I32_SINT,    32_SINT,  NONE,     WZYX),
    150 
    151 	VT(R16G16_UNORM,   16_16_UNORM, NONE,        WZYX),
    152 	VT(R16G16_SNORM,   16_16_SNORM, NONE,        WZYX),
    153 	VT(R16G16_UINT,    16_16_UINT,  R16G16_UINT, WZYX),
    154 	VT(R16G16_SINT,    16_16_SINT,  R16G16_SINT, WZYX),
    155 	V_(R16G16_USCALED, 16_16_UINT,  NONE,        WZYX),
    156 	V_(R16G16_SSCALED, 16_16_SINT,  NONE,        WZYX),
    157 	VT(R16G16_FLOAT,   16_16_FLOAT, R16G16_FLOAT,WZYX),
    158 
    159 	_T(L16A16_UINT,    16_16_UINT,  NONE,        WZYX),
    160 	_T(L16A16_SINT,    16_16_SINT,  NONE,        WZYX),
    161 
    162 	VT(R8G8B8A8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
    163 	_T(R8G8B8X8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
    164 	_T(R8G8B8A8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
    165 	_T(R8G8B8X8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, WZYX),
    166 	VT(R8G8B8A8_SNORM,   8_8_8_8_SNORM, R8G8B8A8_SNORM, WZYX),
    167 	VT(R8G8B8A8_UINT,    8_8_8_8_UINT,  R8G8B8A8_UINT,  WZYX),
    168 	VT(R8G8B8A8_SINT,    8_8_8_8_SINT,  R8G8B8A8_SINT,  WZYX),
    169 	V_(R8G8B8A8_USCALED, 8_8_8_8_UINT,  NONE,           WZYX),
    170 	V_(R8G8B8A8_SSCALED, 8_8_8_8_SINT,  NONE,           WZYX),
    171 
    172 	VT(B8G8R8A8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
    173 	_T(B8G8R8X8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
    174 	VT(B8G8R8A8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
    175 	_T(B8G8R8X8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, WXYZ),
    176 
    177 	VT(A8B8G8R8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
    178 	_T(X8B8G8R8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
    179 	_T(A8B8G8R8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
    180 	_T(X8B8G8R8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, XYZW),
    181 
    182 	VT(A8R8G8B8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
    183 	_T(X8R8G8B8_UNORM,   8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
    184 	_T(A8R8G8B8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
    185 	_T(X8R8G8B8_SRGB,    8_8_8_8_UNORM, R8G8B8A8_UNORM, ZYXW),
    186 
    187 	VT(R10G10B10A2_UNORM,   10_10_10_2_UNORM, R10G10B10A2_UNORM, WZYX),
    188 	VT(B10G10R10A2_UNORM,   10_10_10_2_UNORM, R10G10B10A2_UNORM, WXYZ),
    189 	_T(B10G10R10X2_UNORM,   10_10_10_2_UNORM, R10G10B10A2_UNORM, WXYZ),
    190 	V_(R10G10B10A2_SNORM,   10_10_10_2_SNORM, NONE,              WZYX),
    191 	V_(B10G10R10A2_SNORM,   10_10_10_2_SNORM, NONE,              WXYZ),
    192 	V_(R10G10B10A2_UINT,    10_10_10_2_UINT,  NONE,              WZYX),
    193 	V_(B10G10R10A2_UINT,    10_10_10_2_UINT,  NONE,              WXYZ),
    194 	V_(R10G10B10A2_USCALED, 10_10_10_2_UINT,  NONE,              WZYX),
    195 	V_(B10G10R10A2_USCALED, 10_10_10_2_UINT,  NONE,              WXYZ),
    196 	V_(R10G10B10A2_SSCALED, 10_10_10_2_SINT,  NONE,              WZYX),
    197 	V_(B10G10R10A2_SSCALED, 10_10_10_2_SINT,  NONE,              WXYZ),
    198 
    199 	_T(R11G11B10_FLOAT, 11_11_10_FLOAT, R11G11B10_FLOAT, WZYX),
    200 	_T(R9G9B9E5_FLOAT,  9_9_9_E5_FLOAT, NONE,            WZYX),
    201 
    202 	_T(Z24X8_UNORM,       X8Z24_UNORM, R8G8B8A8_UNORM, WZYX),
    203 	_T(Z24_UNORM_S8_UINT, X8Z24_UNORM, R8G8B8A8_UNORM, WZYX),
    204 	_T(Z32_FLOAT,         Z32_FLOAT,   R8G8B8A8_UNORM, WZYX),
    205 	_T(Z32_FLOAT_S8X24_UINT, Z32_FLOAT,R8G8B8A8_UNORM, WZYX),
    206 
    207 	/* 48-bit */
    208 	V_(R16G16B16_UNORM,   16_16_16_UNORM, NONE, WZYX),
    209 	V_(R16G16B16_SNORM,   16_16_16_SNORM, NONE, WZYX),
    210 	V_(R16G16B16_UINT,    16_16_16_UINT,  NONE, WZYX),
    211 	V_(R16G16B16_SINT,    16_16_16_SINT,  NONE, WZYX),
    212 	V_(R16G16B16_USCALED, 16_16_16_UINT,  NONE, WZYX),
    213 	V_(R16G16B16_SSCALED, 16_16_16_SINT,  NONE, WZYX),
    214 	V_(R16G16B16_FLOAT,   16_16_16_FLOAT, NONE, WZYX),
    215 
    216 	/* 64-bit */
    217 	VT(R16G16B16A16_UNORM,   16_16_16_16_UNORM, NONE,               WZYX),
    218 	VT(R16G16B16A16_SNORM,   16_16_16_16_SNORM, NONE,               WZYX),
    219 	VT(R16G16B16A16_UINT,    16_16_16_16_UINT,  R16G16B16A16_UINT,  WZYX),
    220 	_T(R16G16B16X16_UINT,    16_16_16_16_UINT,  R16G16B16A16_UINT,  WZYX),
    221 	VT(R16G16B16A16_SINT,    16_16_16_16_SINT,  R16G16B16A16_SINT,  WZYX),
    222 	_T(R16G16B16X16_SINT,    16_16_16_16_SINT,  R16G16B16A16_SINT,  WZYX),
    223 	V_(R16G16B16A16_USCALED, 16_16_16_16_UINT,  NONE,               WZYX),
    224 	V_(R16G16B16A16_SSCALED, 16_16_16_16_SINT,  NONE,               WZYX),
    225 	VT(R16G16B16A16_FLOAT,   16_16_16_16_FLOAT, R16G16B16A16_FLOAT, WZYX),
    226 	_T(R16G16B16X16_FLOAT,   16_16_16_16_FLOAT, R16G16B16A16_FLOAT, WZYX),
    227 
    228 	VT(R32G32_UINT,    32_32_UINT,  R32G32_UINT, WZYX),
    229 	VT(R32G32_SINT,    32_32_SINT,  R32G32_SINT, WZYX),
    230 	V_(R32G32_USCALED, 32_32_UINT,  NONE,        WZYX),
    231 	V_(R32G32_SSCALED, 32_32_SINT,  NONE,        WZYX),
    232 	VT(R32G32_FLOAT,   32_32_FLOAT, R32G32_FLOAT,WZYX),
    233 	V_(R32G32_FIXED,   32_32_FIXED, NONE,        WZYX),
    234 
    235 	_T(L32A32_UINT,    32_32_UINT,  NONE,        WZYX),
    236 	_T(L32A32_SINT,    32_32_SINT,  NONE,        WZYX),
    237 
    238 	/* 96-bit */
    239 	V_(R32G32B32_UINT,    32_32_32_UINT,  NONE, WZYX),
    240 	V_(R32G32B32_SINT,    32_32_32_SINT,  NONE, WZYX),
    241 	V_(R32G32B32_USCALED, 32_32_32_UINT,  NONE, WZYX),
    242 	V_(R32G32B32_SSCALED, 32_32_32_SINT,  NONE, WZYX),
    243 	V_(R32G32B32_FLOAT,   32_32_32_FLOAT, NONE, WZYX),
    244 	V_(R32G32B32_FIXED,   32_32_32_FIXED, NONE, WZYX),
    245 
    246 	/* 128-bit */
    247 	VT(R32G32B32A32_UINT,    32_32_32_32_UINT,  R32G32B32A32_UINT,  WZYX),
    248 	_T(R32G32B32X32_UINT,    32_32_32_32_UINT,  R32G32B32A32_UINT,  WZYX),
    249 	VT(R32G32B32A32_SINT,    32_32_32_32_SINT,  R32G32B32A32_SINT,  WZYX),
    250 	_T(R32G32B32X32_SINT,    32_32_32_32_SINT,  R32G32B32A32_SINT,  WZYX),
    251 	V_(R32G32B32A32_USCALED, 32_32_32_32_UINT,  NONE,               WZYX),
    252 	V_(R32G32B32A32_SSCALED, 32_32_32_32_SINT,  NONE,               WZYX),
    253 	VT(R32G32B32A32_FLOAT,   32_32_32_32_FLOAT, R32G32B32A32_FLOAT, WZYX),
    254 	_T(R32G32B32X32_FLOAT,   32_32_32_32_FLOAT, R32G32B32A32_FLOAT, WZYX),
    255 	V_(R32G32B32A32_FIXED,   32_32_32_32_FIXED, NONE,               WZYX),
    256 
    257 	/* compressed */
    258 	_T(ETC1_RGB8, ETC1, NONE, WZYX),
    259 	_T(ETC2_RGB8, ETC2_RGB8, NONE, WZYX),
    260 	_T(ETC2_SRGB8, ETC2_RGB8, NONE, WZYX),
    261 	_T(ETC2_RGB8A1, ETC2_RGB8A1, NONE, WZYX),
    262 	_T(ETC2_SRGB8A1, ETC2_RGB8A1, NONE, WZYX),
    263 	_T(ETC2_RGBA8, ETC2_RGBA8, NONE, WZYX),
    264 	_T(ETC2_SRGBA8, ETC2_RGBA8, NONE, WZYX),
    265 	_T(ETC2_R11_UNORM, ETC2_R11_UNORM, NONE, WZYX),
    266 	_T(ETC2_R11_SNORM, ETC2_R11_SNORM, NONE, WZYX),
    267 	_T(ETC2_RG11_UNORM, ETC2_RG11_UNORM, NONE, WZYX),
    268 	_T(ETC2_RG11_SNORM, ETC2_RG11_SNORM, NONE, WZYX),
    269 
    270 	_T(DXT1_RGB,   DXT1, NONE, WZYX),
    271 	_T(DXT1_SRGB,  DXT1, NONE, WZYX),
    272 	_T(DXT1_RGBA,  DXT1, NONE, WZYX),
    273 	_T(DXT1_SRGBA, DXT1, NONE, WZYX),
    274 	_T(DXT3_RGBA,  DXT3, NONE, WZYX),
    275 	_T(DXT3_SRGBA, DXT3, NONE, WZYX),
    276 	_T(DXT5_RGBA,  DXT5, NONE, WZYX),
    277 	_T(DXT5_SRGBA, DXT5, NONE, WZYX),
    278 
    279 	/* faked */
    280 	_T(RGTC1_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
    281 	_T(RGTC1_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
    282 	_T(RGTC2_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
    283 	_T(RGTC2_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
    284 	_T(LATC1_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
    285 	_T(LATC1_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
    286 	_T(LATC2_UNORM, 8_8_8_8_UNORM, NONE, WZYX),
    287 	_T(LATC2_SNORM, 8_8_8_8_SNORM, NONE, WZYX),
    288 };
    289 
    290 enum a3xx_vtx_fmt
    291 fd3_pipe2vtx(enum pipe_format format)
    292 {
    293 	if (!formats[format].present)
    294 		return ~0;
    295 	return formats[format].vtx;
    296 }
    297 
    298 enum a3xx_tex_fmt
    299 fd3_pipe2tex(enum pipe_format format)
    300 {
    301 	if (!formats[format].present)
    302 		return ~0;
    303 	return formats[format].tex;
    304 }
    305 
    306 enum a3xx_color_fmt
    307 fd3_pipe2color(enum pipe_format format)
    308 {
    309 	if (!formats[format].present)
    310 		return ~0;
    311 	return formats[format].rb;
    312 }
    313 
    314 enum a3xx_color_swap
    315 fd3_pipe2swap(enum pipe_format format)
    316 {
    317 	if (!formats[format].present)
    318 		return WZYX;
    319 	return formats[format].swap;
    320 }
    321 
    322 enum a3xx_tex_fetchsize
    323 fd3_pipe2fetchsize(enum pipe_format format)
    324 {
    325 	if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
    326 		format = PIPE_FORMAT_Z32_FLOAT;
    327 	else if (util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC)
    328 		format = PIPE_FORMAT_R8G8B8A8_UNORM;
    329 	switch (util_format_get_blocksizebits(format) / util_format_get_blockwidth(format)) {
    330 	case 8: return TFETCH_1_BYTE;
    331 	case 16: return TFETCH_2_BYTE;
    332 	case 32: return TFETCH_4_BYTE;
    333 	case 64: return TFETCH_8_BYTE;
    334 	case 128: return TFETCH_16_BYTE;
    335 	default:
    336 		debug_printf("Unknown block size for format %s: %d\n",
    337 					 util_format_name(format),
    338 					 util_format_get_blocksizebits(format));
    339 		return TFETCH_DISABLE;
    340 	}
    341 }
    342 
    343 unsigned
    344 fd3_pipe2nblocksx(enum pipe_format format, unsigned width)
    345 {
    346 	if (util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC)
    347 		format = PIPE_FORMAT_R8G8B8A8_UNORM;
    348 	return util_format_get_nblocksx(format, width);
    349 }
    350 
    351 enum a3xx_color_fmt
    352 fd3_fs_output_format(enum pipe_format format)
    353 {
    354 	if (util_format_is_srgb(format))
    355 		return RB_R16G16B16A16_FLOAT;
    356 	switch (format) {
    357 	case PIPE_FORMAT_R16_FLOAT:
    358 	case PIPE_FORMAT_R16G16_FLOAT:
    359 	case PIPE_FORMAT_R11G11B10_FLOAT:
    360 		return RB_R16G16B16A16_FLOAT;
    361 	case PIPE_FORMAT_L8_UNORM:
    362 		return RB_R8G8B8A8_UNORM;
    363 	default:
    364 		return fd3_pipe2color(format);
    365 	}
    366 }
    367 
    368 static inline enum a3xx_tex_swiz
    369 tex_swiz(unsigned swiz)
    370 {
    371 	switch (swiz) {
    372 	default:
    373 	case PIPE_SWIZZLE_X: return A3XX_TEX_X;
    374 	case PIPE_SWIZZLE_Y: return A3XX_TEX_Y;
    375 	case PIPE_SWIZZLE_Z: return A3XX_TEX_Z;
    376 	case PIPE_SWIZZLE_W: return A3XX_TEX_W;
    377 	case PIPE_SWIZZLE_0: return A3XX_TEX_ZERO;
    378 	case PIPE_SWIZZLE_1: return A3XX_TEX_ONE;
    379 	}
    380 }
    381 
    382 uint32_t
    383 fd3_tex_swiz(enum pipe_format format, unsigned swizzle_r, unsigned swizzle_g,
    384 		unsigned swizzle_b, unsigned swizzle_a)
    385 {
    386 	const struct util_format_description *desc =
    387 			util_format_description(format);
    388 	unsigned char swiz[4] = {
    389 			swizzle_r, swizzle_g, swizzle_b, swizzle_a,
    390 	}, rswiz[4];
    391 
    392 	util_format_compose_swizzles(desc->swizzle, swiz, rswiz);
    393 
    394 	return A3XX_TEX_CONST_0_SWIZ_X(tex_swiz(rswiz[0])) |
    395 			A3XX_TEX_CONST_0_SWIZ_Y(tex_swiz(rswiz[1])) |
    396 			A3XX_TEX_CONST_0_SWIZ_Z(tex_swiz(rswiz[2])) |
    397 			A3XX_TEX_CONST_0_SWIZ_W(tex_swiz(rswiz[3]));
    398 }
    399