1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright © 2015 Red Hat
5 *
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:
12 *
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
15 * Software.
16 *
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
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * IN THE SOFTWARE.
24 *
25 * Authors:
26 * Rob Clark <robclark@freedesktop.org>
27 */
28
29 #include "shader_enums.h"
30 #include "util/macros.h"
31 #include "mesa/main/config.h"
32
33 #define ENUM(x) [x] = #x
34 #define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")
35
36 const char *
gl_shader_stage_name(gl_shader_stage stage)37 gl_shader_stage_name(gl_shader_stage stage)
38 {
39 static const char *names[] = {
40 ENUM(MESA_SHADER_VERTEX),
41 ENUM(MESA_SHADER_TESS_CTRL),
42 ENUM(MESA_SHADER_TESS_EVAL),
43 ENUM(MESA_SHADER_GEOMETRY),
44 ENUM(MESA_SHADER_FRAGMENT),
45 ENUM(MESA_SHADER_COMPUTE),
46 ENUM(MESA_SHADER_TASK),
47 ENUM(MESA_SHADER_MESH),
48 ENUM(MESA_SHADER_RAYGEN),
49 ENUM(MESA_SHADER_ANY_HIT),
50 ENUM(MESA_SHADER_CLOSEST_HIT),
51 ENUM(MESA_SHADER_MISS),
52 ENUM(MESA_SHADER_INTERSECTION),
53 ENUM(MESA_SHADER_CALLABLE),
54 ENUM(MESA_SHADER_KERNEL),
55 };
56 STATIC_ASSERT(ARRAY_SIZE(names) == MESA_ALL_SHADER_STAGES);
57 return NAME(stage);
58 }
59
60 /**
61 * Translate a gl_shader_stage to a short shader stage name for debug
62 * printouts and error messages.
63 */
64 const char *
_mesa_shader_stage_to_string(unsigned stage)65 _mesa_shader_stage_to_string(unsigned stage)
66 {
67 switch (stage) {
68 case MESA_SHADER_VERTEX: return "vertex";
69 case MESA_SHADER_FRAGMENT: return "fragment";
70 case MESA_SHADER_GEOMETRY: return "geometry";
71 case MESA_SHADER_COMPUTE: return "compute";
72 case MESA_SHADER_KERNEL: return "kernel";
73 case MESA_SHADER_TESS_CTRL: return "tessellation control";
74 case MESA_SHADER_TESS_EVAL: return "tessellation evaluation";
75 case MESA_SHADER_TASK: return "task";
76 case MESA_SHADER_MESH: return "mesh";
77 case MESA_SHADER_RAYGEN: return "raygen";
78 case MESA_SHADER_ANY_HIT: return "any hit";
79 case MESA_SHADER_CLOSEST_HIT: return "closest hit";
80 case MESA_SHADER_MISS: return "miss";
81 case MESA_SHADER_INTERSECTION: return "intersection";
82 case MESA_SHADER_CALLABLE: return "callable";
83 }
84
85 unreachable("Unknown shader stage.");
86 }
87
88 /**
89 * Translate a gl_shader_stage to a shader stage abbreviation (VS, GS, FS)
90 * for debug printouts and error messages.
91 */
92 const char *
_mesa_shader_stage_to_abbrev(unsigned stage)93 _mesa_shader_stage_to_abbrev(unsigned stage)
94 {
95 switch (stage) {
96 case MESA_SHADER_VERTEX: return "VS";
97 case MESA_SHADER_FRAGMENT: return "FS";
98 case MESA_SHADER_GEOMETRY: return "GS";
99 case MESA_SHADER_COMPUTE: return "CS";
100 case MESA_SHADER_KERNEL: return "CL";
101 case MESA_SHADER_TESS_CTRL: return "TCS";
102 case MESA_SHADER_TESS_EVAL: return "TES";
103 case MESA_SHADER_TASK: return "TASK";
104 case MESA_SHADER_MESH: return "MESH";
105 case MESA_SHADER_RAYGEN: return "RGEN";
106 case MESA_SHADER_ANY_HIT: return "RAHIT";
107 case MESA_SHADER_CLOSEST_HIT: return "RCHIT";
108 case MESA_SHADER_MISS: return "RMISS";
109 case MESA_SHADER_INTERSECTION: return "RINT";
110 case MESA_SHADER_CALLABLE: return "RCALL";
111 }
112
113 unreachable("Unknown shader stage.");
114 }
115
116 const char *
gl_vert_attrib_name(gl_vert_attrib attrib)117 gl_vert_attrib_name(gl_vert_attrib attrib)
118 {
119 static const char *names[] = {
120 ENUM(VERT_ATTRIB_POS),
121 ENUM(VERT_ATTRIB_NORMAL),
122 ENUM(VERT_ATTRIB_COLOR0),
123 ENUM(VERT_ATTRIB_COLOR1),
124 ENUM(VERT_ATTRIB_FOG),
125 ENUM(VERT_ATTRIB_COLOR_INDEX),
126 ENUM(VERT_ATTRIB_TEX0),
127 ENUM(VERT_ATTRIB_TEX1),
128 ENUM(VERT_ATTRIB_TEX2),
129 ENUM(VERT_ATTRIB_TEX3),
130 ENUM(VERT_ATTRIB_TEX4),
131 ENUM(VERT_ATTRIB_TEX5),
132 ENUM(VERT_ATTRIB_TEX6),
133 ENUM(VERT_ATTRIB_TEX7),
134 ENUM(VERT_ATTRIB_POINT_SIZE),
135 ENUM(VERT_ATTRIB_GENERIC0),
136 ENUM(VERT_ATTRIB_GENERIC1),
137 ENUM(VERT_ATTRIB_GENERIC2),
138 ENUM(VERT_ATTRIB_GENERIC3),
139 ENUM(VERT_ATTRIB_GENERIC4),
140 ENUM(VERT_ATTRIB_GENERIC5),
141 ENUM(VERT_ATTRIB_GENERIC6),
142 ENUM(VERT_ATTRIB_GENERIC7),
143 ENUM(VERT_ATTRIB_GENERIC8),
144 ENUM(VERT_ATTRIB_GENERIC9),
145 ENUM(VERT_ATTRIB_GENERIC10),
146 ENUM(VERT_ATTRIB_GENERIC11),
147 ENUM(VERT_ATTRIB_GENERIC12),
148 ENUM(VERT_ATTRIB_GENERIC13),
149 ENUM(VERT_ATTRIB_GENERIC14),
150 ENUM(VERT_ATTRIB_GENERIC15),
151 ENUM(VERT_ATTRIB_EDGEFLAG),
152 };
153 STATIC_ASSERT(ARRAY_SIZE(names) == VERT_ATTRIB_MAX);
154 return NAME(attrib);
155 }
156
157 const char *
gl_varying_slot_name_for_stage(gl_varying_slot slot,gl_shader_stage stage)158 gl_varying_slot_name_for_stage(gl_varying_slot slot, gl_shader_stage stage)
159 {
160 if (stage != MESA_SHADER_FRAGMENT && slot == VARYING_SLOT_PRIMITIVE_SHADING_RATE)
161 return "VARYING_SLOT_PRIMITIVE_SHADING_RATE";
162
163 switch (stage) {
164 case MESA_SHADER_MESH:
165 switch (slot) {
166 case VARYING_SLOT_PRIMITIVE_COUNT: return "VARYING_SLOT_PRIMITIVE_COUNT";
167 case VARYING_SLOT_PRIMITIVE_INDICES: return "VARYING_SLOT_PRIMITIVE_INDICES";
168 case VARYING_SLOT_CULL_PRIMITIVE: return "VARYING_SLOT_CULL_PRIMITIVE";
169 default:
170 /* Not an overlapping value. */
171 break;
172 }
173 break;
174
175 case MESA_SHADER_TASK:
176 switch (slot) {
177 case VARYING_SLOT_TASK_COUNT: return "VARYING_SLOT_TASK_COUNT";
178 default:
179 /* Not an overlapping value. */
180 break;
181 }
182 break;
183
184 default:
185 break;
186 }
187
188 static const char *names[] = {
189 ENUM(VARYING_SLOT_POS),
190 ENUM(VARYING_SLOT_COL0),
191 ENUM(VARYING_SLOT_COL1),
192 ENUM(VARYING_SLOT_FOGC),
193 ENUM(VARYING_SLOT_TEX0),
194 ENUM(VARYING_SLOT_TEX1),
195 ENUM(VARYING_SLOT_TEX2),
196 ENUM(VARYING_SLOT_TEX3),
197 ENUM(VARYING_SLOT_TEX4),
198 ENUM(VARYING_SLOT_TEX5),
199 ENUM(VARYING_SLOT_TEX6),
200 ENUM(VARYING_SLOT_TEX7),
201 ENUM(VARYING_SLOT_PSIZ),
202 ENUM(VARYING_SLOT_BFC0),
203 ENUM(VARYING_SLOT_BFC1),
204 ENUM(VARYING_SLOT_EDGE),
205 ENUM(VARYING_SLOT_CLIP_VERTEX),
206 ENUM(VARYING_SLOT_CLIP_DIST0),
207 ENUM(VARYING_SLOT_CLIP_DIST1),
208 ENUM(VARYING_SLOT_CULL_DIST0),
209 ENUM(VARYING_SLOT_CULL_DIST1),
210 ENUM(VARYING_SLOT_PRIMITIVE_ID),
211 ENUM(VARYING_SLOT_LAYER),
212 ENUM(VARYING_SLOT_VIEWPORT),
213 ENUM(VARYING_SLOT_FACE),
214 ENUM(VARYING_SLOT_PNTC),
215 ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
216 ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
217 ENUM(VARYING_SLOT_BOUNDING_BOX0),
218 ENUM(VARYING_SLOT_BOUNDING_BOX1),
219 ENUM(VARYING_SLOT_VIEW_INDEX),
220 ENUM(VARYING_SLOT_VIEWPORT_MASK),
221 ENUM(VARYING_SLOT_VAR0),
222 ENUM(VARYING_SLOT_VAR1),
223 ENUM(VARYING_SLOT_VAR2),
224 ENUM(VARYING_SLOT_VAR3),
225 ENUM(VARYING_SLOT_VAR4),
226 ENUM(VARYING_SLOT_VAR5),
227 ENUM(VARYING_SLOT_VAR6),
228 ENUM(VARYING_SLOT_VAR7),
229 ENUM(VARYING_SLOT_VAR8),
230 ENUM(VARYING_SLOT_VAR9),
231 ENUM(VARYING_SLOT_VAR10),
232 ENUM(VARYING_SLOT_VAR11),
233 ENUM(VARYING_SLOT_VAR12),
234 ENUM(VARYING_SLOT_VAR13),
235 ENUM(VARYING_SLOT_VAR14),
236 ENUM(VARYING_SLOT_VAR15),
237 ENUM(VARYING_SLOT_VAR16),
238 ENUM(VARYING_SLOT_VAR17),
239 ENUM(VARYING_SLOT_VAR18),
240 ENUM(VARYING_SLOT_VAR19),
241 ENUM(VARYING_SLOT_VAR20),
242 ENUM(VARYING_SLOT_VAR21),
243 ENUM(VARYING_SLOT_VAR22),
244 ENUM(VARYING_SLOT_VAR23),
245 ENUM(VARYING_SLOT_VAR24),
246 ENUM(VARYING_SLOT_VAR25),
247 ENUM(VARYING_SLOT_VAR26),
248 ENUM(VARYING_SLOT_VAR27),
249 ENUM(VARYING_SLOT_VAR28),
250 ENUM(VARYING_SLOT_VAR29),
251 ENUM(VARYING_SLOT_VAR30),
252 ENUM(VARYING_SLOT_VAR31),
253 };
254 STATIC_ASSERT(ARRAY_SIZE(names) == VARYING_SLOT_MAX);
255 return NAME(slot);
256 }
257
258 const char *
gl_system_value_name(gl_system_value sysval)259 gl_system_value_name(gl_system_value sysval)
260 {
261 static const char *names[] = {
262 ENUM(SYSTEM_VALUE_SUBGROUP_SIZE),
263 ENUM(SYSTEM_VALUE_SUBGROUP_INVOCATION),
264 ENUM(SYSTEM_VALUE_SUBGROUP_EQ_MASK),
265 ENUM(SYSTEM_VALUE_SUBGROUP_GE_MASK),
266 ENUM(SYSTEM_VALUE_SUBGROUP_GT_MASK),
267 ENUM(SYSTEM_VALUE_SUBGROUP_LE_MASK),
268 ENUM(SYSTEM_VALUE_SUBGROUP_LT_MASK),
269 ENUM(SYSTEM_VALUE_NUM_SUBGROUPS),
270 ENUM(SYSTEM_VALUE_SUBGROUP_ID),
271 ENUM(SYSTEM_VALUE_VERTEX_ID),
272 ENUM(SYSTEM_VALUE_INSTANCE_ID),
273 ENUM(SYSTEM_VALUE_INSTANCE_INDEX),
274 ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
275 ENUM(SYSTEM_VALUE_BASE_VERTEX),
276 ENUM(SYSTEM_VALUE_FIRST_VERTEX),
277 ENUM(SYSTEM_VALUE_IS_INDEXED_DRAW),
278 ENUM(SYSTEM_VALUE_BASE_INSTANCE),
279 ENUM(SYSTEM_VALUE_DRAW_ID),
280 ENUM(SYSTEM_VALUE_INVOCATION_ID),
281 ENUM(SYSTEM_VALUE_FRAG_COORD),
282 ENUM(SYSTEM_VALUE_POINT_COORD),
283 ENUM(SYSTEM_VALUE_LINE_COORD),
284 ENUM(SYSTEM_VALUE_FRONT_FACE),
285 ENUM(SYSTEM_VALUE_SAMPLE_ID),
286 ENUM(SYSTEM_VALUE_SAMPLE_POS),
287 ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
288 ENUM(SYSTEM_VALUE_HELPER_INVOCATION),
289 ENUM(SYSTEM_VALUE_COLOR0),
290 ENUM(SYSTEM_VALUE_COLOR1),
291 ENUM(SYSTEM_VALUE_TESS_COORD),
292 ENUM(SYSTEM_VALUE_VERTICES_IN),
293 ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
294 ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
295 ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
296 ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER_DEFAULT),
297 ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER_DEFAULT),
298 ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
299 ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX),
300 ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_ID),
301 ENUM(SYSTEM_VALUE_BASE_GLOBAL_INVOCATION_ID),
302 ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_INDEX),
303 ENUM(SYSTEM_VALUE_WORKGROUP_ID),
304 ENUM(SYSTEM_VALUE_NUM_WORKGROUPS),
305 ENUM(SYSTEM_VALUE_WORKGROUP_SIZE),
306 ENUM(SYSTEM_VALUE_GLOBAL_GROUP_SIZE),
307 ENUM(SYSTEM_VALUE_USER_DATA_AMD),
308 ENUM(SYSTEM_VALUE_WORK_DIM),
309 ENUM(SYSTEM_VALUE_DEVICE_INDEX),
310 ENUM(SYSTEM_VALUE_VIEW_INDEX),
311 ENUM(SYSTEM_VALUE_VERTEX_CNT),
312 ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL),
313 ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_SAMPLE),
314 ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_CENTROID),
315 ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_CENTER_RHW),
316 ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_PIXEL),
317 ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_CENTROID),
318 ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_SAMPLE),
319 ENUM(SYSTEM_VALUE_BARYCENTRIC_PULL_MODEL),
320 ENUM(SYSTEM_VALUE_RAY_LAUNCH_ID),
321 ENUM(SYSTEM_VALUE_RAY_LAUNCH_SIZE),
322 ENUM(SYSTEM_VALUE_RAY_LAUNCH_SIZE_ADDR_AMD),
323 ENUM(SYSTEM_VALUE_RAY_WORLD_ORIGIN),
324 ENUM(SYSTEM_VALUE_RAY_WORLD_DIRECTION),
325 ENUM(SYSTEM_VALUE_RAY_OBJECT_ORIGIN),
326 ENUM(SYSTEM_VALUE_RAY_OBJECT_DIRECTION),
327 ENUM(SYSTEM_VALUE_RAY_T_MIN),
328 ENUM(SYSTEM_VALUE_RAY_T_MAX),
329 ENUM(SYSTEM_VALUE_RAY_OBJECT_TO_WORLD),
330 ENUM(SYSTEM_VALUE_RAY_WORLD_TO_OBJECT),
331 ENUM(SYSTEM_VALUE_RAY_HIT_KIND),
332 ENUM(SYSTEM_VALUE_RAY_FLAGS),
333 ENUM(SYSTEM_VALUE_RAY_GEOMETRY_INDEX),
334 ENUM(SYSTEM_VALUE_CULL_MASK),
335 ENUM(SYSTEM_VALUE_MESH_VIEW_COUNT),
336 ENUM(SYSTEM_VALUE_MESH_VIEW_INDICES),
337 ENUM(SYSTEM_VALUE_GS_HEADER_IR3),
338 ENUM(SYSTEM_VALUE_TCS_HEADER_IR3),
339 ENUM(SYSTEM_VALUE_REL_PATCH_ID_IR3),
340 ENUM(SYSTEM_VALUE_FRAG_SHADING_RATE),
341 };
342 STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX);
343 return NAME(sysval);
344 }
345
346 const char *
glsl_interp_mode_name(enum glsl_interp_mode qual)347 glsl_interp_mode_name(enum glsl_interp_mode qual)
348 {
349 static const char *names[] = {
350 ENUM(INTERP_MODE_NONE),
351 ENUM(INTERP_MODE_SMOOTH),
352 ENUM(INTERP_MODE_FLAT),
353 ENUM(INTERP_MODE_NOPERSPECTIVE),
354 ENUM(INTERP_MODE_EXPLICIT),
355 ENUM(INTERP_MODE_COLOR),
356 };
357 STATIC_ASSERT(ARRAY_SIZE(names) == INTERP_MODE_COUNT);
358 return NAME(qual);
359 }
360
361 const char *
gl_frag_result_name(gl_frag_result result)362 gl_frag_result_name(gl_frag_result result)
363 {
364 static const char *names[] = {
365 ENUM(FRAG_RESULT_DEPTH),
366 ENUM(FRAG_RESULT_STENCIL),
367 ENUM(FRAG_RESULT_COLOR),
368 ENUM(FRAG_RESULT_SAMPLE_MASK),
369 ENUM(FRAG_RESULT_DATA0),
370 ENUM(FRAG_RESULT_DATA1),
371 ENUM(FRAG_RESULT_DATA2),
372 ENUM(FRAG_RESULT_DATA3),
373 ENUM(FRAG_RESULT_DATA4),
374 ENUM(FRAG_RESULT_DATA5),
375 ENUM(FRAG_RESULT_DATA6),
376 ENUM(FRAG_RESULT_DATA7),
377 };
378 STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX);
379 return NAME(result);
380 }
381
382 unsigned
num_mesh_vertices_per_primitive(unsigned prim)383 num_mesh_vertices_per_primitive(unsigned prim)
384 {
385 switch (prim) {
386 case SHADER_PRIM_POINTS:
387 return 1;
388 case SHADER_PRIM_LINES:
389 return 2;
390 case SHADER_PRIM_TRIANGLES:
391 return 3;
392 default:
393 unreachable("invalid mesh shader primitive type");
394 }
395 }
396