shader_enums.c revision ed98bd31
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
36const char *
37gl_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_KERNEL),
47   };
48   STATIC_ASSERT(ARRAY_SIZE(names) == MESA_ALL_SHADER_STAGES);
49   return NAME(stage);
50}
51
52/**
53 * Translate a gl_shader_stage to a short shader stage name for debug
54 * printouts and error messages.
55 */
56const char *
57_mesa_shader_stage_to_string(unsigned stage)
58{
59   switch (stage) {
60   case MESA_SHADER_VERTEX:   return "vertex";
61   case MESA_SHADER_FRAGMENT: return "fragment";
62   case MESA_SHADER_GEOMETRY: return "geometry";
63   case MESA_SHADER_COMPUTE:  return "compute";
64   case MESA_SHADER_KERNEL:   return "kernel";
65   case MESA_SHADER_TESS_CTRL: return "tessellation control";
66   case MESA_SHADER_TESS_EVAL: return "tessellation evaluation";
67   }
68
69   unreachable("Unknown shader stage.");
70}
71
72/**
73 * Translate a gl_shader_stage to a shader stage abbreviation (VS, GS, FS)
74 * for debug printouts and error messages.
75 */
76const char *
77_mesa_shader_stage_to_abbrev(unsigned stage)
78{
79   switch (stage) {
80   case MESA_SHADER_VERTEX:   return "VS";
81   case MESA_SHADER_FRAGMENT: return "FS";
82   case MESA_SHADER_GEOMETRY: return "GS";
83   case MESA_SHADER_COMPUTE:  return "CS";
84   case MESA_SHADER_KERNEL:   return "CL";
85   case MESA_SHADER_TESS_CTRL: return "TCS";
86   case MESA_SHADER_TESS_EVAL: return "TES";
87   }
88
89   unreachable("Unknown shader stage.");
90}
91
92const char *
93gl_vert_attrib_name(gl_vert_attrib attrib)
94{
95   static const char *names[] = {
96      ENUM(VERT_ATTRIB_POS),
97      ENUM(VERT_ATTRIB_NORMAL),
98      ENUM(VERT_ATTRIB_COLOR0),
99      ENUM(VERT_ATTRIB_COLOR1),
100      ENUM(VERT_ATTRIB_FOG),
101      ENUM(VERT_ATTRIB_COLOR_INDEX),
102      ENUM(VERT_ATTRIB_EDGEFLAG),
103      ENUM(VERT_ATTRIB_TEX0),
104      ENUM(VERT_ATTRIB_TEX1),
105      ENUM(VERT_ATTRIB_TEX2),
106      ENUM(VERT_ATTRIB_TEX3),
107      ENUM(VERT_ATTRIB_TEX4),
108      ENUM(VERT_ATTRIB_TEX5),
109      ENUM(VERT_ATTRIB_TEX6),
110      ENUM(VERT_ATTRIB_TEX7),
111      ENUM(VERT_ATTRIB_POINT_SIZE),
112      ENUM(VERT_ATTRIB_GENERIC0),
113      ENUM(VERT_ATTRIB_GENERIC1),
114      ENUM(VERT_ATTRIB_GENERIC2),
115      ENUM(VERT_ATTRIB_GENERIC3),
116      ENUM(VERT_ATTRIB_GENERIC4),
117      ENUM(VERT_ATTRIB_GENERIC5),
118      ENUM(VERT_ATTRIB_GENERIC6),
119      ENUM(VERT_ATTRIB_GENERIC7),
120      ENUM(VERT_ATTRIB_GENERIC8),
121      ENUM(VERT_ATTRIB_GENERIC9),
122      ENUM(VERT_ATTRIB_GENERIC10),
123      ENUM(VERT_ATTRIB_GENERIC11),
124      ENUM(VERT_ATTRIB_GENERIC12),
125      ENUM(VERT_ATTRIB_GENERIC13),
126      ENUM(VERT_ATTRIB_GENERIC14),
127      ENUM(VERT_ATTRIB_GENERIC15),
128   };
129   STATIC_ASSERT(ARRAY_SIZE(names) == VERT_ATTRIB_MAX);
130   return NAME(attrib);
131}
132
133const char *
134gl_varying_slot_name(gl_varying_slot slot)
135{
136   static const char *names[] = {
137      ENUM(VARYING_SLOT_POS),
138      ENUM(VARYING_SLOT_COL0),
139      ENUM(VARYING_SLOT_COL1),
140      ENUM(VARYING_SLOT_FOGC),
141      ENUM(VARYING_SLOT_TEX0),
142      ENUM(VARYING_SLOT_TEX1),
143      ENUM(VARYING_SLOT_TEX2),
144      ENUM(VARYING_SLOT_TEX3),
145      ENUM(VARYING_SLOT_TEX4),
146      ENUM(VARYING_SLOT_TEX5),
147      ENUM(VARYING_SLOT_TEX6),
148      ENUM(VARYING_SLOT_TEX7),
149      ENUM(VARYING_SLOT_PSIZ),
150      ENUM(VARYING_SLOT_BFC0),
151      ENUM(VARYING_SLOT_BFC1),
152      ENUM(VARYING_SLOT_EDGE),
153      ENUM(VARYING_SLOT_CLIP_VERTEX),
154      ENUM(VARYING_SLOT_CLIP_DIST0),
155      ENUM(VARYING_SLOT_CLIP_DIST1),
156      ENUM(VARYING_SLOT_CULL_DIST0),
157      ENUM(VARYING_SLOT_CULL_DIST1),
158      ENUM(VARYING_SLOT_PRIMITIVE_ID),
159      ENUM(VARYING_SLOT_LAYER),
160      ENUM(VARYING_SLOT_VIEWPORT),
161      ENUM(VARYING_SLOT_FACE),
162      ENUM(VARYING_SLOT_PNTC),
163      ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
164      ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
165      ENUM(VARYING_SLOT_BOUNDING_BOX0),
166      ENUM(VARYING_SLOT_BOUNDING_BOX1),
167      ENUM(VARYING_SLOT_VIEW_INDEX),
168      ENUM(VARYING_SLOT_VAR0),
169      ENUM(VARYING_SLOT_VAR1),
170      ENUM(VARYING_SLOT_VAR2),
171      ENUM(VARYING_SLOT_VAR3),
172      ENUM(VARYING_SLOT_VAR4),
173      ENUM(VARYING_SLOT_VAR5),
174      ENUM(VARYING_SLOT_VAR6),
175      ENUM(VARYING_SLOT_VAR7),
176      ENUM(VARYING_SLOT_VAR8),
177      ENUM(VARYING_SLOT_VAR9),
178      ENUM(VARYING_SLOT_VAR10),
179      ENUM(VARYING_SLOT_VAR11),
180      ENUM(VARYING_SLOT_VAR12),
181      ENUM(VARYING_SLOT_VAR13),
182      ENUM(VARYING_SLOT_VAR14),
183      ENUM(VARYING_SLOT_VAR15),
184      ENUM(VARYING_SLOT_VAR16),
185      ENUM(VARYING_SLOT_VAR17),
186      ENUM(VARYING_SLOT_VAR18),
187      ENUM(VARYING_SLOT_VAR19),
188      ENUM(VARYING_SLOT_VAR20),
189      ENUM(VARYING_SLOT_VAR21),
190      ENUM(VARYING_SLOT_VAR22),
191      ENUM(VARYING_SLOT_VAR23),
192      ENUM(VARYING_SLOT_VAR24),
193      ENUM(VARYING_SLOT_VAR25),
194      ENUM(VARYING_SLOT_VAR26),
195      ENUM(VARYING_SLOT_VAR27),
196      ENUM(VARYING_SLOT_VAR28),
197      ENUM(VARYING_SLOT_VAR29),
198      ENUM(VARYING_SLOT_VAR30),
199      ENUM(VARYING_SLOT_VAR31),
200   };
201   STATIC_ASSERT(ARRAY_SIZE(names) == VARYING_SLOT_MAX);
202   return NAME(slot);
203}
204
205const char *
206gl_system_value_name(gl_system_value sysval)
207{
208   static const char *names[] = {
209     ENUM(SYSTEM_VALUE_SUBGROUP_SIZE),
210     ENUM(SYSTEM_VALUE_SUBGROUP_INVOCATION),
211     ENUM(SYSTEM_VALUE_SUBGROUP_EQ_MASK),
212     ENUM(SYSTEM_VALUE_SUBGROUP_GE_MASK),
213     ENUM(SYSTEM_VALUE_SUBGROUP_GT_MASK),
214     ENUM(SYSTEM_VALUE_SUBGROUP_LE_MASK),
215     ENUM(SYSTEM_VALUE_SUBGROUP_LT_MASK),
216     ENUM(SYSTEM_VALUE_NUM_SUBGROUPS),
217     ENUM(SYSTEM_VALUE_SUBGROUP_ID),
218     ENUM(SYSTEM_VALUE_VERTEX_ID),
219     ENUM(SYSTEM_VALUE_INSTANCE_ID),
220     ENUM(SYSTEM_VALUE_INSTANCE_INDEX),
221     ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
222     ENUM(SYSTEM_VALUE_BASE_VERTEX),
223     ENUM(SYSTEM_VALUE_FIRST_VERTEX),
224     ENUM(SYSTEM_VALUE_IS_INDEXED_DRAW),
225     ENUM(SYSTEM_VALUE_BASE_INSTANCE),
226     ENUM(SYSTEM_VALUE_DRAW_ID),
227     ENUM(SYSTEM_VALUE_INVOCATION_ID),
228     ENUM(SYSTEM_VALUE_FRAG_COORD),
229     ENUM(SYSTEM_VALUE_FRONT_FACE),
230     ENUM(SYSTEM_VALUE_SAMPLE_ID),
231     ENUM(SYSTEM_VALUE_SAMPLE_POS),
232     ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
233     ENUM(SYSTEM_VALUE_HELPER_INVOCATION),
234     ENUM(SYSTEM_VALUE_TESS_COORD),
235     ENUM(SYSTEM_VALUE_VERTICES_IN),
236     ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
237     ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
238     ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
239     ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
240     ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX),
241     ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_ID),
242     ENUM(SYSTEM_VALUE_WORK_GROUP_ID),
243     ENUM(SYSTEM_VALUE_NUM_WORK_GROUPS),
244     ENUM(SYSTEM_VALUE_LOCAL_GROUP_SIZE),
245     ENUM(SYSTEM_VALUE_GLOBAL_GROUP_SIZE),
246     ENUM(SYSTEM_VALUE_WORK_DIM),
247     ENUM(SYSTEM_VALUE_DEVICE_INDEX),
248     ENUM(SYSTEM_VALUE_VIEW_INDEX),
249     ENUM(SYSTEM_VALUE_VERTEX_CNT),
250     ENUM(SYSTEM_VALUE_BARYCENTRIC_PIXEL),
251     ENUM(SYSTEM_VALUE_BARYCENTRIC_SAMPLE),
252     ENUM(SYSTEM_VALUE_BARYCENTRIC_CENTROID),
253     ENUM(SYSTEM_VALUE_BARYCENTRIC_SIZE),
254   };
255   STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX);
256   return NAME(sysval);
257}
258
259const char *
260glsl_interp_mode_name(enum glsl_interp_mode qual)
261{
262   static const char *names[] = {
263      ENUM(INTERP_MODE_NONE),
264      ENUM(INTERP_MODE_SMOOTH),
265      ENUM(INTERP_MODE_FLAT),
266      ENUM(INTERP_MODE_NOPERSPECTIVE),
267   };
268   STATIC_ASSERT(ARRAY_SIZE(names) == INTERP_MODE_COUNT);
269   return NAME(qual);
270}
271
272const char *
273gl_frag_result_name(gl_frag_result result)
274{
275   static const char *names[] = {
276      ENUM(FRAG_RESULT_DEPTH),
277      ENUM(FRAG_RESULT_STENCIL),
278      ENUM(FRAG_RESULT_COLOR),
279      ENUM(FRAG_RESULT_SAMPLE_MASK),
280      ENUM(FRAG_RESULT_DATA0),
281      ENUM(FRAG_RESULT_DATA1),
282      ENUM(FRAG_RESULT_DATA2),
283      ENUM(FRAG_RESULT_DATA3),
284      ENUM(FRAG_RESULT_DATA4),
285      ENUM(FRAG_RESULT_DATA5),
286      ENUM(FRAG_RESULT_DATA6),
287      ENUM(FRAG_RESULT_DATA7),
288   };
289   STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX);
290   return NAME(result);
291}
292