• 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_EDGEFLAG),
127       ENUM(VERT_ATTRIB_TEX0),
128       ENUM(VERT_ATTRIB_TEX1),
129       ENUM(VERT_ATTRIB_TEX2),
130       ENUM(VERT_ATTRIB_TEX3),
131       ENUM(VERT_ATTRIB_TEX4),
132       ENUM(VERT_ATTRIB_TEX5),
133       ENUM(VERT_ATTRIB_TEX6),
134       ENUM(VERT_ATTRIB_TEX7),
135       ENUM(VERT_ATTRIB_POINT_SIZE),
136       ENUM(VERT_ATTRIB_GENERIC0),
137       ENUM(VERT_ATTRIB_GENERIC1),
138       ENUM(VERT_ATTRIB_GENERIC2),
139       ENUM(VERT_ATTRIB_GENERIC3),
140       ENUM(VERT_ATTRIB_GENERIC4),
141       ENUM(VERT_ATTRIB_GENERIC5),
142       ENUM(VERT_ATTRIB_GENERIC6),
143       ENUM(VERT_ATTRIB_GENERIC7),
144       ENUM(VERT_ATTRIB_GENERIC8),
145       ENUM(VERT_ATTRIB_GENERIC9),
146       ENUM(VERT_ATTRIB_GENERIC10),
147       ENUM(VERT_ATTRIB_GENERIC11),
148       ENUM(VERT_ATTRIB_GENERIC12),
149       ENUM(VERT_ATTRIB_GENERIC13),
150       ENUM(VERT_ATTRIB_GENERIC14),
151       ENUM(VERT_ATTRIB_GENERIC15),
152    };
153    STATIC_ASSERT(ARRAY_SIZE(names) == VERT_ATTRIB_MAX);
154    return NAME(attrib);
155 }
156 
157 const char *
gl_varying_slot_name(gl_varying_slot slot)158 gl_varying_slot_name(gl_varying_slot slot)
159 {
160    static const char *names[] = {
161       ENUM(VARYING_SLOT_POS),
162       ENUM(VARYING_SLOT_COL0),
163       ENUM(VARYING_SLOT_COL1),
164       ENUM(VARYING_SLOT_FOGC),
165       ENUM(VARYING_SLOT_TEX0),
166       ENUM(VARYING_SLOT_TEX1),
167       ENUM(VARYING_SLOT_TEX2),
168       ENUM(VARYING_SLOT_TEX3),
169       ENUM(VARYING_SLOT_TEX4),
170       ENUM(VARYING_SLOT_TEX5),
171       ENUM(VARYING_SLOT_TEX6),
172       ENUM(VARYING_SLOT_TEX7),
173       ENUM(VARYING_SLOT_PSIZ),
174       ENUM(VARYING_SLOT_BFC0),
175       ENUM(VARYING_SLOT_BFC1),
176       ENUM(VARYING_SLOT_EDGE),
177       ENUM(VARYING_SLOT_CLIP_VERTEX),
178       ENUM(VARYING_SLOT_CLIP_DIST0),
179       ENUM(VARYING_SLOT_CLIP_DIST1),
180       ENUM(VARYING_SLOT_CULL_DIST0),
181       ENUM(VARYING_SLOT_CULL_DIST1),
182       ENUM(VARYING_SLOT_PRIMITIVE_ID),
183       ENUM(VARYING_SLOT_LAYER),
184       ENUM(VARYING_SLOT_VIEWPORT),
185       ENUM(VARYING_SLOT_FACE),
186       ENUM(VARYING_SLOT_PNTC),
187       ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
188       ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
189       ENUM(VARYING_SLOT_BOUNDING_BOX0),
190       ENUM(VARYING_SLOT_BOUNDING_BOX1),
191       ENUM(VARYING_SLOT_VIEW_INDEX),
192       ENUM(VARYING_SLOT_VIEWPORT_MASK),
193       ENUM(VARYING_SLOT_VAR0),
194       ENUM(VARYING_SLOT_VAR1),
195       ENUM(VARYING_SLOT_VAR2),
196       ENUM(VARYING_SLOT_VAR3),
197       ENUM(VARYING_SLOT_VAR4),
198       ENUM(VARYING_SLOT_VAR5),
199       ENUM(VARYING_SLOT_VAR6),
200       ENUM(VARYING_SLOT_VAR7),
201       ENUM(VARYING_SLOT_VAR8),
202       ENUM(VARYING_SLOT_VAR9),
203       ENUM(VARYING_SLOT_VAR10),
204       ENUM(VARYING_SLOT_VAR11),
205       ENUM(VARYING_SLOT_VAR12),
206       ENUM(VARYING_SLOT_VAR13),
207       ENUM(VARYING_SLOT_VAR14),
208       ENUM(VARYING_SLOT_VAR15),
209       ENUM(VARYING_SLOT_VAR16),
210       ENUM(VARYING_SLOT_VAR17),
211       ENUM(VARYING_SLOT_VAR18),
212       ENUM(VARYING_SLOT_VAR19),
213       ENUM(VARYING_SLOT_VAR20),
214       ENUM(VARYING_SLOT_VAR21),
215       ENUM(VARYING_SLOT_VAR22),
216       ENUM(VARYING_SLOT_VAR23),
217       ENUM(VARYING_SLOT_VAR24),
218       ENUM(VARYING_SLOT_VAR25),
219       ENUM(VARYING_SLOT_VAR26),
220       ENUM(VARYING_SLOT_VAR27),
221       ENUM(VARYING_SLOT_VAR28),
222       ENUM(VARYING_SLOT_VAR29),
223       ENUM(VARYING_SLOT_VAR30),
224       ENUM(VARYING_SLOT_VAR31),
225    };
226    STATIC_ASSERT(ARRAY_SIZE(names) == VARYING_SLOT_MAX);
227    return NAME(slot);
228 }
229 
230 const char *
gl_system_value_name(gl_system_value sysval)231 gl_system_value_name(gl_system_value sysval)
232 {
233    static const char *names[] = {
234      ENUM(SYSTEM_VALUE_SUBGROUP_SIZE),
235      ENUM(SYSTEM_VALUE_SUBGROUP_INVOCATION),
236      ENUM(SYSTEM_VALUE_SUBGROUP_EQ_MASK),
237      ENUM(SYSTEM_VALUE_SUBGROUP_GE_MASK),
238      ENUM(SYSTEM_VALUE_SUBGROUP_GT_MASK),
239      ENUM(SYSTEM_VALUE_SUBGROUP_LE_MASK),
240      ENUM(SYSTEM_VALUE_SUBGROUP_LT_MASK),
241      ENUM(SYSTEM_VALUE_NUM_SUBGROUPS),
242      ENUM(SYSTEM_VALUE_SUBGROUP_ID),
243      ENUM(SYSTEM_VALUE_VERTEX_ID),
244      ENUM(SYSTEM_VALUE_INSTANCE_ID),
245      ENUM(SYSTEM_VALUE_INSTANCE_INDEX),
246      ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
247      ENUM(SYSTEM_VALUE_BASE_VERTEX),
248      ENUM(SYSTEM_VALUE_FIRST_VERTEX),
249      ENUM(SYSTEM_VALUE_IS_INDEXED_DRAW),
250      ENUM(SYSTEM_VALUE_BASE_INSTANCE),
251      ENUM(SYSTEM_VALUE_DRAW_ID),
252      ENUM(SYSTEM_VALUE_INVOCATION_ID),
253      ENUM(SYSTEM_VALUE_FRAG_COORD),
254      ENUM(SYSTEM_VALUE_POINT_COORD),
255      ENUM(SYSTEM_VALUE_LINE_COORD),
256      ENUM(SYSTEM_VALUE_FRONT_FACE),
257      ENUM(SYSTEM_VALUE_SAMPLE_ID),
258      ENUM(SYSTEM_VALUE_SAMPLE_POS),
259      ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
260      ENUM(SYSTEM_VALUE_HELPER_INVOCATION),
261      ENUM(SYSTEM_VALUE_COLOR0),
262      ENUM(SYSTEM_VALUE_COLOR1),
263      ENUM(SYSTEM_VALUE_TESS_COORD),
264      ENUM(SYSTEM_VALUE_VERTICES_IN),
265      ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
266      ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
267      ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
268      ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER_DEFAULT),
269      ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER_DEFAULT),
270      ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
271      ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX),
272      ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_ID),
273      ENUM(SYSTEM_VALUE_BASE_GLOBAL_INVOCATION_ID),
274      ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_INDEX),
275      ENUM(SYSTEM_VALUE_WORK_GROUP_ID),
276      ENUM(SYSTEM_VALUE_NUM_WORK_GROUPS),
277      ENUM(SYSTEM_VALUE_LOCAL_GROUP_SIZE),
278      ENUM(SYSTEM_VALUE_GLOBAL_GROUP_SIZE),
279      ENUM(SYSTEM_VALUE_USER_DATA_AMD),
280      ENUM(SYSTEM_VALUE_WORK_DIM),
281      ENUM(SYSTEM_VALUE_DEVICE_INDEX),
282      ENUM(SYSTEM_VALUE_VIEW_INDEX),
283      ENUM(SYSTEM_VALUE_VERTEX_CNT),
284      ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL),
285      ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_SAMPLE),
286      ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_CENTROID),
287      ENUM(SYSTEM_VALUE_BARYCENTRIC_PERSP_SIZE),
288      ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_PIXEL),
289      ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_CENTROID),
290      ENUM(SYSTEM_VALUE_BARYCENTRIC_LINEAR_SAMPLE),
291      ENUM(SYSTEM_VALUE_BARYCENTRIC_PULL_MODEL),
292      ENUM(SYSTEM_VALUE_RAY_LAUNCH_ID),
293      ENUM(SYSTEM_VALUE_RAY_LAUNCH_SIZE),
294      ENUM(SYSTEM_VALUE_RAY_WORLD_ORIGIN),
295      ENUM(SYSTEM_VALUE_RAY_WORLD_DIRECTION),
296      ENUM(SYSTEM_VALUE_RAY_OBJECT_ORIGIN),
297      ENUM(SYSTEM_VALUE_RAY_OBJECT_DIRECTION),
298      ENUM(SYSTEM_VALUE_RAY_T_MIN),
299      ENUM(SYSTEM_VALUE_RAY_T_MAX),
300      ENUM(SYSTEM_VALUE_RAY_OBJECT_TO_WORLD),
301      ENUM(SYSTEM_VALUE_RAY_WORLD_TO_OBJECT),
302      ENUM(SYSTEM_VALUE_RAY_HIT_KIND),
303      ENUM(SYSTEM_VALUE_RAY_FLAGS),
304      ENUM(SYSTEM_VALUE_RAY_GEOMETRY_INDEX),
305      ENUM(SYSTEM_VALUE_GS_HEADER_IR3),
306      ENUM(SYSTEM_VALUE_TCS_HEADER_IR3),
307    };
308    STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX);
309    return NAME(sysval);
310 }
311 
312 const char *
glsl_interp_mode_name(enum glsl_interp_mode qual)313 glsl_interp_mode_name(enum glsl_interp_mode qual)
314 {
315    static const char *names[] = {
316       ENUM(INTERP_MODE_NONE),
317       ENUM(INTERP_MODE_SMOOTH),
318       ENUM(INTERP_MODE_FLAT),
319       ENUM(INTERP_MODE_NOPERSPECTIVE),
320       ENUM(INTERP_MODE_EXPLICIT),
321       ENUM(INTERP_MODE_COLOR),
322    };
323    STATIC_ASSERT(ARRAY_SIZE(names) == INTERP_MODE_COUNT);
324    return NAME(qual);
325 }
326 
327 const char *
gl_frag_result_name(gl_frag_result result)328 gl_frag_result_name(gl_frag_result result)
329 {
330    static const char *names[] = {
331       ENUM(FRAG_RESULT_DEPTH),
332       ENUM(FRAG_RESULT_STENCIL),
333       ENUM(FRAG_RESULT_COLOR),
334       ENUM(FRAG_RESULT_SAMPLE_MASK),
335       ENUM(FRAG_RESULT_DATA0),
336       ENUM(FRAG_RESULT_DATA1),
337       ENUM(FRAG_RESULT_DATA2),
338       ENUM(FRAG_RESULT_DATA3),
339       ENUM(FRAG_RESULT_DATA4),
340       ENUM(FRAG_RESULT_DATA5),
341       ENUM(FRAG_RESULT_DATA6),
342       ENUM(FRAG_RESULT_DATA7),
343    };
344    STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX);
345    return NAME(result);
346 }
347