2 * Copyright (c) 2011-2013 Luc Verhaegen <libv@skynet.be>
3 * Copyright (c) 2018-2019 Lima Project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
29 #include <util/macros.h>
31 #include "lima_format.h"
33 #define LIMA_TEXEL_FORMAT_L8 0x09
34 #define LIMA_TEXEL_FORMAT_A8 0x0a
35 #define LIMA_TEXEL_FORMAT_I8 0x0b
36 #define LIMA_TEXEL_FORMAT_BGR_565 0x0e
37 #define LIMA_TEXEL_FORMAT_BGRA_5551 0x0f
38 #define LIMA_TEXEL_FORMAT_BGRA_4444 0x10
39 #define LIMA_TEXEL_FORMAT_L8A8 0x11
40 #define LIMA_TEXEL_FORMAT_L16 0x12
41 #define LIMA_TEXEL_FORMAT_A16 0x13
42 #define LIMA_TEXEL_FORMAT_I16 0x14
43 #define LIMA_TEXEL_FORMAT_RGB_888 0x15
44 #define LIMA_TEXEL_FORMAT_RGBA_8888 0x16
45 #define LIMA_TEXEL_FORMAT_RGBX_8888 0x17
46 #define LIMA_TEXEL_FORMAT_ETC1_RGB8 0x20
47 #define LIMA_TEXEL_FORMAT_Z24S8 0x2c
48 #define LIMA_TEXEL_FORMAT_NONE -1
50 #define LIMA_PIXEL_FORMAT_B5G6R5 0x00
51 #define LIMA_PIXEL_FORMAT_B5G5R5A1 0x01
52 #define LIMA_PIXEL_FORMAT_B4G4R4A4 0x02
53 #define LIMA_PIXEL_FORMAT_B8G8R8A8 0x03
54 #define LIMA_PIXEL_FORMAT_Z16 0x0e
55 #define LIMA_PIXEL_FORMAT_Z24S8 0x0f
56 #define LIMA_PIXEL_FORMAT_NONE -1
63 uint32_t channel_layout
;
66 #define LIMA_FORMAT(pipe, tex, pix, swap, ch_layout) \
67 [PIPE_FORMAT_##pipe] = { \
68 .present = true, .texel = LIMA_TEXEL_FORMAT_##tex, \
69 .pixel = LIMA_PIXEL_FORMAT_##pix, .swap_r_b = swap, \
70 .channel_layout = ch_layout, \
73 static const struct lima_format lima_format_table
[] = {
74 LIMA_FORMAT(R8G8B8A8_UNORM
, RGBA_8888
, B8G8R8A8
, true, 0x8888),
75 LIMA_FORMAT(B8G8R8A8_UNORM
, RGBA_8888
, B8G8R8A8
, false, 0x8888),
76 LIMA_FORMAT(R8G8B8A8_SRGB
, RGBA_8888
, B8G8R8A8
, true, 0x8888),
77 LIMA_FORMAT(B8G8R8A8_SRGB
, RGBA_8888
, B8G8R8A8
, false, 0x8888),
78 LIMA_FORMAT(R8G8B8X8_UNORM
, RGBX_8888
, B8G8R8A8
, true, 0x8888),
79 LIMA_FORMAT(B8G8R8X8_UNORM
, RGBX_8888
, B8G8R8A8
, false, 0x8888),
80 LIMA_FORMAT(B5G6R5_UNORM
, BGR_565
, B5G6R5
, false, 0x8565),
81 /* BGRA_5551 seems to need channel layout 0x8565, it's not a typo */
82 LIMA_FORMAT(B5G5R5A1_UNORM
, BGRA_5551
, B5G5R5A1
, false, 0x8565),
83 LIMA_FORMAT(B4G4R4A4_UNORM
, BGRA_4444
, B4G4R4A4
, false, 0x8444),
84 LIMA_FORMAT(Z24_UNORM_S8_UINT
, Z24S8
, Z24S8
, false, 0x0000),
85 LIMA_FORMAT(Z24X8_UNORM
, Z24S8
, Z24S8
, false, 0x0000),
86 /* Blob uses L16 for Z16 */
87 LIMA_FORMAT(Z16_UNORM
, L16
, Z16
, false, 0x0000),
88 LIMA_FORMAT(L16_UNORM
, L16
, NONE
, false, 0x0000),
89 LIMA_FORMAT(L8_UNORM
, L8
, NONE
, false, 0x0000),
90 LIMA_FORMAT(A16_UNORM
, A16
, NONE
, false, 0x0000),
91 LIMA_FORMAT(A8_UNORM
, A8
, NONE
, false, 0x0000),
92 LIMA_FORMAT(I16_UNORM
, I16
, NONE
, false, 0x0000),
93 LIMA_FORMAT(I8_UNORM
, I8
, NONE
, false, 0x0000),
94 LIMA_FORMAT(L8A8_UNORM
, L8A8
, NONE
, false, 0x0000),
95 LIMA_FORMAT(ETC1_RGB8
, ETC1_RGB8
, NONE
, false, 0x8888),
98 static const struct lima_format
*
99 get_format(enum pipe_format f
)
101 if (f
>= ARRAY_SIZE(lima_format_table
) ||
102 !lima_format_table
[f
].present
)
105 return lima_format_table
+ f
;
109 lima_format_texel_supported(enum pipe_format f
)
111 const struct lima_format
*lf
= get_format(f
);
116 return lf
->texel
!= LIMA_TEXEL_FORMAT_NONE
;
120 lima_format_pixel_supported(enum pipe_format f
)
122 const struct lima_format
*lf
= get_format(f
);
127 return lf
->pixel
!= LIMA_PIXEL_FORMAT_NONE
;
131 lima_format_get_texel(enum pipe_format f
)
133 return lima_format_table
[f
].texel
;
137 lima_format_get_pixel(enum pipe_format f
)
139 return lima_format_table
[f
].pixel
;
143 lima_format_get_swap_rb(enum pipe_format f
)
145 return lima_format_table
[f
].swap_r_b
;
149 lima_format_get_channel_layout(enum pipe_format f
)
151 return lima_format_table
[f
].channel_layout
;