• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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       default:
169          /* Not an overlapping value. */
170          break;
171       }
172       break;
173 
174    case MESA_SHADER_TASK:
175       switch (slot) {
176       case VARYING_SLOT_TASK_COUNT: return "VARYING_SLOT_TASK_COUNT";
177       default:
178          /* Not an overlapping value. */
179          break;
180       }
181       break;
182 
183    default:
184       break;
185    }
186 
187    static const char *names[] = {
188       ENUM(VARYING_SLOT_POS),
189       ENUM(VARYING_SLOT_COL0),
190       ENUM(VARYING_SLOT_COL1),
191       ENUM(VARYING_SLOT_FOGC),
192       ENUM(VARYING_SLOT_TEX0),
193       ENUM(VARYING_SLOT_TEX1),
194       ENUM(VARYING_SLOT_TEX2),
195       ENUM(VARYING_SLOT_TEX3),
196       ENUM(VARYING_SLOT_TEX4),
197       ENUM(VARYING_SLOT_TEX5),
198       ENUM(VARYING_SLOT_TEX6),
199       ENUM(VARYING_SLOT_TEX7),
200       ENUM(VARYING_SLOT_PSIZ),
201       ENUM(VARYING_SLOT_BFC0),
202       ENUM(VARYING_SLOT_BFC1),
203       ENUM(VARYING_SLOT_EDGE),
204       ENUM(VARYING_SLOT_CLIP_VERTEX),
205       ENUM(VARYING_SLOT_CLIP_DIST0),
206       ENUM(VARYING_SLOT_CLIP_DIST1),
207       ENUM(VARYING_SLOT_CULL_DIST0),
208       ENUM(VARYING_SLOT_CULL_DIST1),
209       ENUM(VARYING_SLOT_PRIMITIVE_ID),
210       ENUM(VARYING_SLOT_LAYER),
211       ENUM(VARYING_SLOT_VIEWPORT),
212       ENUM(VARYING_SLOT_FACE),
213       ENUM(VARYING_SLOT_PNTC),
214       ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
215       ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
216       ENUM(VARYING_SLOT_BOUNDING_BOX0),
217       ENUM(VARYING_SLOT_BOUNDING_BOX1),
218       ENUM(VARYING_SLOT_VIEW_INDEX),
219       ENUM(VARYING_SLOT_VIEWPORT_MASK),
220       ENUM(VARYING_SLOT_VAR0),
221       ENUM(VARYING_SLOT_VAR1),
222       ENUM(VARYING_SLOT_VAR2),
223       ENUM(VARYING_SLOT_VAR3),
224       ENUM(VARYING_SLOT_VAR4),
225       ENUM(VARYING_SLOT_VAR5),
226       ENUM(VARYING_SLOT_VAR6),
227       ENUM(VARYING_SLOT_VAR7),
228       ENUM(VARYING_SLOT_VAR8),
229       ENUM(VARYING_SLOT_VAR9),
230       ENUM(VARYING_SLOT_VAR10),
231       ENUM(VARYING_SLOT_VAR11),
232       ENUM(VARYING_SLOT_VAR12),
233       ENUM(VARYING_SLOT_VAR13),
234       ENUM(VARYING_SLOT_VAR14),
235       ENUM(VARYING_SLOT_VAR15),
236       ENUM(VARYING_SLOT_VAR16),
237       ENUM(VARYING_SLOT_VAR17),
238       ENUM(VARYING_SLOT_VAR18),
239       ENUM(VARYING_SLOT_VAR19),
240       ENUM(VARYING_SLOT_VAR20),
241       ENUM(VARYING_SLOT_VAR21),
242       ENUM(VARYING_SLOT_VAR22),
243       ENUM(VARYING_SLOT_VAR23),
244       ENUM(VARYING_SLOT_VAR24),
245       ENUM(VARYING_SLOT_VAR25),
246       ENUM(VARYING_SLOT_VAR26),
247       ENUM(VARYING_SLOT_VAR27),
248       ENUM(VARYING_SLOT_VAR28),
249       ENUM(VARYING_SLOT_VAR29),
250       ENUM(VARYING_SLOT_VAR30),
251       ENUM(VARYING_SLOT_VAR31),
252    };
253    STATIC_ASSERT(ARRAY_SIZE(names) == VARYING_SLOT_MAX);
254    return NAME(slot);
255 }
256 
257 const char *
gl_system_value_name(gl_system_value sysval)258 gl_system_value_name(gl_system_value sysval)
259 {
260    static const char *names[] = {
261      ENUM(SYSTEM_VALUE_SUBGROUP_SIZE),
262      ENUM(SYSTEM_VALUE_SUBGROUP_INVOCATION),
263      ENUM(SYSTEM_VALUE_SUBGROUP_EQ_MASK),
264      ENUM(SYSTEM_VALUE_SUBGROUP_GE_MASK),
265      ENUM(SYSTEM_VALUE_SUBGROUP_GT_MASK),
266      ENUM(SYSTEM_VALUE_SUBGROUP_LE_MASK),
267      ENUM(SYSTEM_VALUE_SUBGROUP_LT_MASK),
268      ENUM(SYSTEM_VALUE_NUM_SUBGROUPS),
269      ENUM(SYSTEM_VALUE_SUBGROUP_ID),
270      ENUM(SYSTEM_VALUE_VERTEX_ID),
271      ENUM(SYSTEM_VALUE_INSTANCE_ID),
272      ENUM(SYSTEM_VALUE_INSTANCE_INDEX),
273      ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
274      ENUM(SYSTEM_VALUE_BASE_VERTEX),
275      ENUM(SYSTEM_VALUE_FIRST_VERTEX),
276      ENUM(SYSTEM_VALUE_IS_INDEXED_DRAW),
277      ENUM(SYSTEM_VALUE_BASE_INSTANCE),
278      ENUM(SYSTEM_VALUE_DRAW_ID),
279      ENUM(SYSTEM_VALUE_INVOCATION_ID),
280      ENUM(SYSTEM_VALUE_FRAG_COORD),
281      ENUM(SYSTEM_VALUE_POINT_COORD),
282      ENUM(SYSTEM_VALUE_LINE_COORD),
283      ENUM(SYSTEM_VALUE_FRONT_FACE),
284      ENUM(SYSTEM_VALUE_SAMPLE_ID),
285      ENUM(SYSTEM_VALUE_SAMPLE_POS),
286      ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
287      ENUM(SYSTEM_VALUE_HELPER_INVOCATION),
288      ENUM(SYSTEM_VALUE_COLOR0),
289      ENUM(SYSTEM_VALUE_COLOR1),
290      ENUM(SYSTEM_VALUE_TESS_COORD),
291      ENUM(SYSTEM_VALUE_VERTICES_IN),
292      ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
293      ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
294      ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
295      ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER_DEFAULT),
296      ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER_DEFAULT),
297      ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
298      ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX),
299      ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_ID),
300      ENUM(SYSTEM_VALUE_BASE_GLOBAL_INVOCATION_ID),
301      ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_INDEX),
302      ENUM(SYSTEM_VALUE_WORKGROUP_ID),
303      ENUM(SYSTEM_VALUE_NUM_WORKGROUPS),
304      ENUM(SYSTEM_VALUE_WORKGROUP_SIZE),
305      ENUM(SYSTEM_VALUE_GLOBAL_GROUP_SIZE),
306      ENUM(SYSTEM_VALUE_USER_DATA_AMD),
307      ENUM(SYSTEM_VALUE_WORK_DIM),
308      ENUM(SYSTEM_VALUE_DEVICE_INDEX),
309      ENUM(SYSTEM_VALUE_VIEW_INDEX),
310      ENUM(SYSTEM_VALUE_VERTEX_CNT),
311      ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL),
312      ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_SAMPLE),
313      ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_CENTROID),
314      ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_SIZE),
315      ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_PIXEL),
316      ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_CENTROID),
317      ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_SAMPLE),
318      ENUM(SYSTEM_VALUE_BARYCENTRIC_PULL_MODEL),
319      ENUM(SYSTEM_VALUE_RAY_LAUNCH_ID),
320      ENUM(SYSTEM_VALUE_RAY_LAUNCH_SIZE),
321      ENUM(SYSTEM_VALUE_RAY_WORLD_ORIGIN),
322      ENUM(SYSTEM_VALUE_RAY_WORLD_DIRECTION),
323      ENUM(SYSTEM_VALUE_RAY_OBJECT_ORIGIN),
324      ENUM(SYSTEM_VALUE_RAY_OBJECT_DIRECTION),
325      ENUM(SYSTEM_VALUE_RAY_T_MIN),
326      ENUM(SYSTEM_VALUE_RAY_T_MAX),
327      ENUM(SYSTEM_VALUE_RAY_OBJECT_TO_WORLD),
328      ENUM(SYSTEM_VALUE_RAY_WORLD_TO_OBJECT),
329      ENUM(SYSTEM_VALUE_RAY_HIT_KIND),
330      ENUM(SYSTEM_VALUE_RAY_FLAGS),
331      ENUM(SYSTEM_VALUE_RAY_GEOMETRY_INDEX),
332      ENUM(SYSTEM_VALUE_GS_HEADER_IR3),
333      ENUM(SYSTEM_VALUE_TCS_HEADER_IR3),
334      ENUM(SYSTEM_VALUE_REL_PATCH_ID_IR3),
335      ENUM(SYSTEM_VALUE_FRAG_SHADING_RATE),
336    };
337    STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX);
338    return NAME(sysval);
339 }
340 
341 const char *
glsl_interp_mode_name(enum glsl_interp_mode qual)342 glsl_interp_mode_name(enum glsl_interp_mode qual)
343 {
344    static const char *names[] = {
345       ENUM(INTERP_MODE_NONE),
346       ENUM(INTERP_MODE_SMOOTH),
347       ENUM(INTERP_MODE_FLAT),
348       ENUM(INTERP_MODE_NOPERSPECTIVE),
349       ENUM(INTERP_MODE_EXPLICIT),
350       ENUM(INTERP_MODE_COLOR),
351    };
352    STATIC_ASSERT(ARRAY_SIZE(names) == INTERP_MODE_COUNT);
353    return NAME(qual);
354 }
355 
356 const char *
gl_frag_result_name(gl_frag_result result)357 gl_frag_result_name(gl_frag_result result)
358 {
359    static const char *names[] = {
360       ENUM(FRAG_RESULT_DEPTH),
361       ENUM(FRAG_RESULT_STENCIL),
362       ENUM(FRAG_RESULT_COLOR),
363       ENUM(FRAG_RESULT_SAMPLE_MASK),
364       ENUM(FRAG_RESULT_DATA0),
365       ENUM(FRAG_RESULT_DATA1),
366       ENUM(FRAG_RESULT_DATA2),
367       ENUM(FRAG_RESULT_DATA3),
368       ENUM(FRAG_RESULT_DATA4),
369       ENUM(FRAG_RESULT_DATA5),
370       ENUM(FRAG_RESULT_DATA6),
371       ENUM(FRAG_RESULT_DATA7),
372    };
373    STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX);
374    return NAME(result);
375 }
376