panfrost: Add RGB565, RGB5A1 texture formats
[mesa.git] / src / gallium / drivers / panfrost / pan_pretty_print.c
1 /*
2 * © Copyright 2017-2098 The Panfrost Communiy
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 #include "pan_pretty_print.h"
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <assert.h>
29
30 /* Some self-contained prettyprinting functions shared between pandecode and
31 * the main driver */
32
33 #define DEFINE_CASE(name) case MALI_## name: return "MALI_" #name
34 char *pandecode_format_name(enum mali_format format)
35 {
36 static char unk_format_str[5];
37
38 switch (format) {
39 DEFINE_CASE(RGB565);
40 DEFINE_CASE(RGB5_A1_UNORM);
41 DEFINE_CASE(RGB10_A2_UNORM);
42 DEFINE_CASE(RGB10_A2_SNORM);
43 DEFINE_CASE(RGB10_A2UI);
44 DEFINE_CASE(RGB10_A2I);
45 DEFINE_CASE(NV12);
46 DEFINE_CASE(Z32_UNORM);
47 DEFINE_CASE(R32_FIXED);
48 DEFINE_CASE(RG32_FIXED);
49 DEFINE_CASE(RGB32_FIXED);
50 DEFINE_CASE(RGBA32_FIXED);
51 DEFINE_CASE(R11F_G11F_B10F);
52 DEFINE_CASE(VARYING_POS);
53 DEFINE_CASE(VARYING_DISCARD);
54
55 DEFINE_CASE(R8_SNORM);
56 DEFINE_CASE(R16_SNORM);
57 DEFINE_CASE(R32_SNORM);
58 DEFINE_CASE(RG8_SNORM);
59 DEFINE_CASE(RG16_SNORM);
60 DEFINE_CASE(RG32_SNORM);
61 DEFINE_CASE(RGB8_SNORM);
62 DEFINE_CASE(RGB16_SNORM);
63 DEFINE_CASE(RGB32_SNORM);
64 DEFINE_CASE(RGBA8_SNORM);
65 DEFINE_CASE(RGBA16_SNORM);
66 DEFINE_CASE(RGBA32_SNORM);
67
68 DEFINE_CASE(R8UI);
69 DEFINE_CASE(R16UI);
70 DEFINE_CASE(R32UI);
71 DEFINE_CASE(RG8UI);
72 DEFINE_CASE(RG16UI);
73 DEFINE_CASE(RG32UI);
74 DEFINE_CASE(RGB8UI);
75 DEFINE_CASE(RGB16UI);
76 DEFINE_CASE(RGB32UI);
77 DEFINE_CASE(RGBA8UI);
78 DEFINE_CASE(RGBA16UI);
79 DEFINE_CASE(RGBA32UI);
80
81 DEFINE_CASE(R8_UNORM);
82 DEFINE_CASE(R16_UNORM);
83 DEFINE_CASE(R32_UNORM);
84 DEFINE_CASE(R32F);
85 DEFINE_CASE(RG8_UNORM);
86 DEFINE_CASE(RG16_UNORM);
87 DEFINE_CASE(RG32_UNORM);
88 DEFINE_CASE(RG32F);
89 DEFINE_CASE(RGB8_UNORM);
90 DEFINE_CASE(RGB16_UNORM);
91 DEFINE_CASE(RGB32_UNORM);
92 DEFINE_CASE(RGB32F);
93 DEFINE_CASE(RGBA8_UNORM);
94 DEFINE_CASE(RGBA16_UNORM);
95 DEFINE_CASE(RGBA32_UNORM);
96 DEFINE_CASE(RGBA32F);
97
98 DEFINE_CASE(R8I);
99 DEFINE_CASE(R16I);
100 DEFINE_CASE(R32I);
101 DEFINE_CASE(RG8I);
102 DEFINE_CASE(R16F);
103 DEFINE_CASE(RG16I);
104 DEFINE_CASE(RG32I);
105 DEFINE_CASE(RG16F);
106 DEFINE_CASE(RGB8I);
107 DEFINE_CASE(RGB16I);
108 DEFINE_CASE(RGB32I);
109 DEFINE_CASE(RGB16F);
110 DEFINE_CASE(RGBA8I);
111 DEFINE_CASE(RGBA16I);
112 DEFINE_CASE(RGBA32I);
113 DEFINE_CASE(RGBA16F);
114
115 DEFINE_CASE(RGBA4);
116 DEFINE_CASE(RGBA8_2);
117 DEFINE_CASE(RGB10_A2_2);
118 default:
119 snprintf(unk_format_str, sizeof(unk_format_str), "0x%02x", format);
120 return unk_format_str;
121 }
122 }
123
124 #undef DEFINE_CASE
125
126 /* Helper to dump fixed-function blend part for debugging */
127
128 static const char *
129 panfrost_factor_name(enum mali_dominant_factor factor)
130 {
131 switch (factor) {
132 case MALI_DOMINANT_UNK0:
133 return "unk0";
134
135 case MALI_DOMINANT_ZERO:
136 return "zero";
137
138 case MALI_DOMINANT_SRC_COLOR:
139 return "source color";
140
141 case MALI_DOMINANT_DST_COLOR:
142 return "dest color";
143
144 case MALI_DOMINANT_UNK4:
145 return "unk4";
146
147 case MALI_DOMINANT_SRC_ALPHA:
148 return "source alpha";
149
150 case MALI_DOMINANT_DST_ALPHA:
151 return "dest alpha";
152
153 case MALI_DOMINANT_CONSTANT:
154 return "constant";
155 }
156
157 return "unreachable";
158 }
159
160 static const char *
161 panfrost_modifier_name(enum mali_blend_modifier mod)
162 {
163 switch (mod) {
164 case MALI_BLEND_MOD_UNK0:
165 return "unk0";
166
167 case MALI_BLEND_MOD_NORMAL:
168 return "normal";
169
170 case MALI_BLEND_MOD_SOURCE_ONE:
171 return "source one";
172
173 case MALI_BLEND_MOD_DEST_ONE:
174 return "dest one";
175 }
176
177 return "unreachable";
178 }
179
180 static void
181 panfrost_print_fixed_part(const char *name, unsigned u)
182 {
183 struct mali_blend_mode part;
184 memcpy(&part, &u, sizeof(part));
185
186 printf("%s blend mode (%X):\n", name, u);
187
188 printf(" %s dominant:\n",
189 (part.dominant == MALI_BLEND_DOM_SOURCE) ? "source" : "destination");
190
191 printf(" %s\n", panfrost_factor_name(part.dominant_factor));
192
193 if (part.complement_dominant)
194 printf(" complement\n");
195
196
197 printf(" nondominant %s\n",
198 (part.nondominant_mode == MALI_BLEND_NON_MIRROR) ? "mirror" : "zero");
199
200
201 printf(" mode: %s\n", panfrost_modifier_name(part.clip_modifier));
202
203 if (part.negate_source) printf(" negate source\n");
204
205 if (part.negate_dest) printf(" negate dest\n");
206
207 assert(!(part.unused_0 || part.unused_1));
208 }
209
210 void
211 panfrost_print_blend_equation(struct mali_blend_equation eq)
212 {
213 printf("\n");
214 panfrost_print_fixed_part("RGB", eq.rgb_mode);
215 panfrost_print_fixed_part("Alpha", eq.alpha_mode);
216
217 assert(!eq.zero1);
218
219 printf("Mask: %s%s%s%s\n",
220 (eq.color_mask & MALI_MASK_R) ? "R" : "",
221 (eq.color_mask & MALI_MASK_G) ? "G" : "",
222 (eq.color_mask & MALI_MASK_B) ? "B" : "",
223 (eq.color_mask & MALI_MASK_A) ? "A" : "");
224
225 printf("Constant: %f\n", eq.constant);
226 }