lima/ppir: remove assert on ppir_emit_tex unsupported feature
[mesa.git] / src / gallium / drivers / lima / lima_format.c
1 /*
2 * Copyright (c) 2011-2013 Luc Verhaegen <libv@skynet.be>
3 * Copyright (c) 2018-2019 Lima Project
4 *
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:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
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.
23 *
24 */
25
26 #include <stdlib.h>
27
28 #include <util/macros.h>
29
30 #include "lima_format.h"
31
32 #define LIMA_TEXEL_FORMAT_L8 0x09
33 #define LIMA_TEXEL_FORMAT_A8 0x0a
34 #define LIMA_TEXEL_FORMAT_I8 0x0b
35 #define LIMA_TEXEL_FORMAT_BGR_565 0x0e
36 #define LIMA_TEXEL_FORMAT_L8A8 0x11
37 #define LIMA_TEXEL_FORMAT_L16 0x12
38 #define LIMA_TEXEL_FORMAT_A16 0x13
39 #define LIMA_TEXEL_FORMAT_I16 0x14
40 #define LIMA_TEXEL_FORMAT_RGB_888 0x15
41 #define LIMA_TEXEL_FORMAT_RGBA_8888 0x16
42 #define LIMA_TEXEL_FORMAT_RGBX_8888 0x17
43 #define LIMA_TEXEL_FORMAT_Z24S8 0x2c
44 #define LIMA_TEXEL_FORMAT_NONE -1
45
46 #define LIMA_PIXEL_FORMAT_B5G6R5 0x00
47 #define LIMA_PIXEL_FORMAT_B8G8R8A8 0x03
48 #define LIMA_PIXEL_FORMAT_Z16 0x0e
49 #define LIMA_PIXEL_FORMAT_Z24S8 0x0f
50 #define LIMA_PIXEL_FORMAT_NONE -1
51
52 struct lima_format {
53 bool present;
54 int texel;
55 int pixel;
56 bool swap_r_b;
57 };
58
59 #define LIMA_FORMAT(pipe, tex, pix, swap) \
60 [PIPE_FORMAT_##pipe] = { \
61 .present = true, .texel = LIMA_TEXEL_FORMAT_##tex, \
62 .pixel = LIMA_PIXEL_FORMAT_##pix, .swap_r_b = swap, \
63 }
64
65 static const struct lima_format lima_format_table[] = {
66 LIMA_FORMAT(R8G8B8A8_UNORM, RGBA_8888, B8G8R8A8, true),
67 LIMA_FORMAT(B8G8R8A8_UNORM, RGBA_8888, B8G8R8A8, false),
68 LIMA_FORMAT(R8G8B8A8_SRGB, RGBA_8888, B8G8R8A8, true),
69 LIMA_FORMAT(B8G8R8A8_SRGB, RGBA_8888, B8G8R8A8, false),
70 LIMA_FORMAT(R8G8B8X8_UNORM, RGBX_8888, B8G8R8A8, true),
71 LIMA_FORMAT(B8G8R8X8_UNORM, RGBX_8888, B8G8R8A8, false),
72 LIMA_FORMAT(R8G8B8_UNORM, RGB_888, NONE, true),
73 LIMA_FORMAT(B5G6R5_UNORM, BGR_565, B5G6R5, false),
74 LIMA_FORMAT(Z24_UNORM_S8_UINT, Z24S8, Z24S8, false),
75 LIMA_FORMAT(Z24X8_UNORM, Z24S8, Z24S8, false),
76 /* Blob uses L16 for Z16 */
77 LIMA_FORMAT(Z16_UNORM, L16, Z16, false),
78 LIMA_FORMAT(L16_UNORM, L16, NONE, false),
79 LIMA_FORMAT(L8_UNORM, L8, NONE, false),
80 LIMA_FORMAT(A16_UNORM, A16, NONE, false),
81 LIMA_FORMAT(A8_UNORM, A8, NONE, false),
82 LIMA_FORMAT(I16_UNORM, I16, NONE, false),
83 LIMA_FORMAT(I8_UNORM, I8, NONE, false),
84 LIMA_FORMAT(L8A8_UNORM, L8A8, NONE, false),
85 };
86
87 static const struct lima_format *
88 get_format(enum pipe_format f)
89 {
90 if (f >= ARRAY_SIZE(lima_format_table) ||
91 !lima_format_table[f].present)
92 return NULL;
93
94 return lima_format_table + f;
95 }
96
97 bool
98 lima_format_texel_supported(enum pipe_format f)
99 {
100 const struct lima_format *lf = get_format(f);
101
102 if (!lf)
103 return false;
104
105 return lf->texel != LIMA_TEXEL_FORMAT_NONE;
106 }
107
108 bool
109 lima_format_pixel_supported(enum pipe_format f)
110 {
111 const struct lima_format *lf = get_format(f);
112
113 if (!lf)
114 return false;
115
116 return lf->pixel != LIMA_PIXEL_FORMAT_NONE;
117 }
118
119 int
120 lima_format_get_texel(enum pipe_format f)
121 {
122 return lima_format_table[f].texel;
123 }
124
125 int
126 lima_format_get_pixel(enum pipe_format f)
127 {
128 return lima_format_table[f].pixel;
129 }
130
131 bool
132 lima_format_get_swap_rb(enum pipe_format f)
133 {
134 return lima_format_table[f].swap_r_b;
135 }