summaryrefslogtreecommitdiffstats
path: root/src/compiler/shader_enums.c
blob: 0f3b1acae7a69d800c76086bca67a6b06a9d3f11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*
 * Mesa 3-D graphics library
 *
 * Copyright © 2015 Red Hat
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Rob Clark <robclark@freedesktop.org>
 */

#include "shader_enums.h"
#include "util/macros.h"
#include "mesa/main/config.h"

#define ENUM(x) [x] = #x
#define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")

const char *
gl_shader_stage_name(gl_shader_stage stage)
{
   static const char *names[] = {
      ENUM(MESA_SHADER_VERTEX),
      ENUM(MESA_SHADER_TESS_CTRL),
      ENUM(MESA_SHADER_TESS_EVAL),
      ENUM(MESA_SHADER_GEOMETRY),
      ENUM(MESA_SHADER_FRAGMENT),
      ENUM(MESA_SHADER_COMPUTE),
   };
   STATIC_ASSERT(ARRAY_SIZE(names) == MESA_SHADER_STAGES);
   return NAME(stage);
}

/**
 * Translate a gl_shader_stage to a short shader stage name for debug
 * printouts and error messages.
 */
const char *
_mesa_shader_stage_to_string(unsigned stage)
{
   switch (stage) {
   case MESA_SHADER_VERTEX:   return "vertex";
   case MESA_SHADER_FRAGMENT: return "fragment";
   case MESA_SHADER_GEOMETRY: return "geometry";
   case MESA_SHADER_COMPUTE:  return "compute";
   case MESA_SHADER_TESS_CTRL: return "tessellation control";
   case MESA_SHADER_TESS_EVAL: return "tessellation evaluation";
   }

   unreachable("Unknown shader stage.");
}

/**
 * Translate a gl_shader_stage to a shader stage abbreviation (VS, GS, FS)
 * for debug printouts and error messages.
 */
const char *
_mesa_shader_stage_to_abbrev(unsigned stage)
{
   switch (stage) {
   case MESA_SHADER_VERTEX:   return "VS";
   case MESA_SHADER_FRAGMENT: return "FS";
   case MESA_SHADER_GEOMETRY: return "GS";
   case MESA_SHADER_COMPUTE:  return "CS";
   case MESA_SHADER_TESS_CTRL: return "TCS";
   case MESA_SHADER_TESS_EVAL: return "TES";
   }

   unreachable("Unknown shader stage.");
}

const char *
gl_vert_attrib_name(gl_vert_attrib attrib)
{
   static const char *names[] = {
      ENUM(VERT_ATTRIB_POS),
      ENUM(VERT_ATTRIB_NORMAL),
      ENUM(VERT_ATTRIB_COLOR0),
      ENUM(VERT_ATTRIB_COLOR1),
      ENUM(VERT_ATTRIB_FOG),
      ENUM(VERT_ATTRIB_COLOR_INDEX),
      ENUM(VERT_ATTRIB_EDGEFLAG),
      ENUM(VERT_ATTRIB_TEX0),
      ENUM(VERT_ATTRIB_TEX1),
      ENUM(VERT_ATTRIB_TEX2),
      ENUM(VERT_ATTRIB_TEX3),
      ENUM(VERT_ATTRIB_TEX4),
      ENUM(VERT_ATTRIB_TEX5),
      ENUM(VERT_ATTRIB_TEX6),
      ENUM(VERT_ATTRIB_TEX7),
      ENUM(VERT_ATTRIB_POINT_SIZE),
      ENUM(VERT_ATTRIB_GENERIC0),
      ENUM(VERT_ATTRIB_GENERIC1),
      ENUM(VERT_ATTRIB_GENERIC2),
      ENUM(VERT_ATTRIB_GENERIC3),
      ENUM(VERT_ATTRIB_GENERIC4),
      ENUM(VERT_ATTRIB_GENERIC5),
      ENUM(VERT_ATTRIB_GENERIC6),
      ENUM(VERT_ATTRIB_GENERIC7),
      ENUM(VERT_ATTRIB_GENERIC8),
      ENUM(VERT_ATTRIB_GENERIC9),
      ENUM(VERT_ATTRIB_GENERIC10),
      ENUM(VERT_ATTRIB_GENERIC11),
      ENUM(VERT_ATTRIB_GENERIC12),
      ENUM(VERT_ATTRIB_GENERIC13),
      ENUM(VERT_ATTRIB_GENERIC14),
      ENUM(VERT_ATTRIB_GENERIC15),
   };
   STATIC_ASSERT(ARRAY_SIZE(names) == VERT_ATTRIB_MAX);
   return NAME(attrib);
}

const char *
gl_varying_slot_name(gl_varying_slot slot)
{
   static const char *names[] = {
      ENUM(VARYING_SLOT_POS),
      ENUM(VARYING_SLOT_COL0),
      ENUM(VARYING_SLOT_COL1),
      ENUM(VARYING_SLOT_FOGC),
      ENUM(VARYING_SLOT_TEX0),
      ENUM(VARYING_SLOT_TEX1),
      ENUM(VARYING_SLOT_TEX2),
      ENUM(VARYING_SLOT_TEX3),
      ENUM(VARYING_SLOT_TEX4),
      ENUM(VARYING_SLOT_TEX5),
      ENUM(VARYING_SLOT_TEX6),
      ENUM(VARYING_SLOT_TEX7),
      ENUM(VARYING_SLOT_PSIZ),
      ENUM(VARYING_SLOT_BFC0),
      ENUM(VARYING_SLOT_BFC1),
      ENUM(VARYING_SLOT_EDGE),
      ENUM(VARYING_SLOT_CLIP_VERTEX),
      ENUM(VARYING_SLOT_CLIP_DIST0),
      ENUM(VARYING_SLOT_CLIP_DIST1),
      ENUM(VARYING_SLOT_CULL_DIST0),
      ENUM(VARYING_SLOT_CULL_DIST1),
      ENUM(VARYING_SLOT_PRIMITIVE_ID),
      ENUM(VARYING_SLOT_LAYER),
      ENUM(VARYING_SLOT_VIEWPORT),
      ENUM(VARYING_SLOT_FACE),
      ENUM(VARYING_SLOT_PNTC),
      ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
      ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
      ENUM(VARYING_SLOT_BOUNDING_BOX0),
      ENUM(VARYING_SLOT_BOUNDING_BOX1),
      ENUM(VARYING_SLOT_VIEW_INDEX),
      ENUM(VARYING_SLOT_VAR0),
      ENUM(VARYING_SLOT_VAR1),
      ENUM(VARYING_SLOT_VAR2),
      ENUM(VARYING_SLOT_VAR3),
      ENUM(VARYING_SLOT_VAR4),
      ENUM(VARYING_SLOT_VAR5),
      ENUM(VARYING_SLOT_VAR6),
      ENUM(VARYING_SLOT_VAR7),
      ENUM(VARYING_SLOT_VAR8),
      ENUM(VARYING_SLOT_VAR9),
      ENUM(VARYING_SLOT_VAR10),
      ENUM(VARYING_SLOT_VAR11),
      ENUM(VARYING_SLOT_VAR12),
      ENUM(VARYING_SLOT_VAR13),
      ENUM(VARYING_SLOT_VAR14),
      ENUM(VARYING_SLOT_VAR15),
      ENUM(VARYING_SLOT_VAR16),
      ENUM(VARYING_SLOT_VAR17),
      ENUM(VARYING_SLOT_VAR18),
      ENUM(VARYING_SLOT_VAR19),
      ENUM(VARYING_SLOT_VAR20),
      ENUM(VARYING_SLOT_VAR21),
      ENUM(VARYING_SLOT_VAR22),
      ENUM(VARYING_SLOT_VAR23),
      ENUM(VARYING_SLOT_VAR24),
      ENUM(VARYING_SLOT_VAR25),
      ENUM(VARYING_SLOT_VAR26),
      ENUM(VARYING_SLOT_VAR27),
      ENUM(VARYING_SLOT_VAR28),
      ENUM(VARYING_SLOT_VAR29),
      ENUM(VARYING_SLOT_VAR30),
      ENUM(VARYING_SLOT_VAR31),
   };
   STATIC_ASSERT(ARRAY_SIZE(names) == VARYING_SLOT_MAX);
   return NAME(slot);
}

const char *
gl_system_value_name(gl_system_value sysval)
{
   static const char *names[] = {
     ENUM(SYSTEM_VALUE_SUBGROUP_SIZE),
     ENUM(SYSTEM_VALUE_SUBGROUP_INVOCATION),
     ENUM(SYSTEM_VALUE_SUBGROUP_EQ_MASK),
     ENUM(SYSTEM_VALUE_SUBGROUP_GE_MASK),
     ENUM(SYSTEM_VALUE_SUBGROUP_GT_MASK),
     ENUM(SYSTEM_VALUE_SUBGROUP_LE_MASK),
     ENUM(SYSTEM_VALUE_SUBGROUP_LT_MASK),
     ENUM(SYSTEM_VALUE_NUM_SUBGROUPS),
     ENUM(SYSTEM_VALUE_SUBGROUP_ID),
     ENUM(SYSTEM_VALUE_VERTEX_ID),
     ENUM(SYSTEM_VALUE_INSTANCE_ID),
     ENUM(SYSTEM_VALUE_INSTANCE_INDEX),
     ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
     ENUM(SYSTEM_VALUE_BASE_VERTEX),
     ENUM(SYSTEM_VALUE_FIRST_VERTEX),
     ENUM(SYSTEM_VALUE_IS_INDEXED_DRAW),
     ENUM(SYSTEM_VALUE_BASE_INSTANCE),
     ENUM(SYSTEM_VALUE_DRAW_ID),
     ENUM(SYSTEM_VALUE_INVOCATION_ID),
     ENUM(SYSTEM_VALUE_FRAG_COORD),
     ENUM(SYSTEM_VALUE_FRONT_FACE),
     ENUM(SYSTEM_VALUE_SAMPLE_ID),
     ENUM(SYSTEM_VALUE_SAMPLE_POS),
     ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
     ENUM(SYSTEM_VALUE_HELPER_INVOCATION),
     ENUM(SYSTEM_VALUE_TESS_COORD),
     ENUM(SYSTEM_VALUE_VERTICES_IN),
     ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
     ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
     ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
     ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
     ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX),
     ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_ID),
     ENUM(SYSTEM_VALUE_WORK_GROUP_ID),
     ENUM(SYSTEM_VALUE_NUM_WORK_GROUPS),
     ENUM(SYSTEM_VALUE_LOCAL_GROUP_SIZE),
     ENUM(SYSTEM_VALUE_DEVICE_INDEX),
     ENUM(SYSTEM_VALUE_VIEW_INDEX),
     ENUM(SYSTEM_VALUE_VERTEX_CNT),
   };
   STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX);
   return NAME(sysval);
}

const char *
glsl_interp_mode_name(enum glsl_interp_mode qual)
{
   static const char *names[] = {
      ENUM(INTERP_MODE_NONE),
      ENUM(INTERP_MODE_SMOOTH),
      ENUM(INTERP_MODE_FLAT),
      ENUM(INTERP_MODE_NOPERSPECTIVE),
   };
   STATIC_ASSERT(ARRAY_SIZE(names) == INTERP_MODE_COUNT);
   return NAME(qual);
}

const char *
gl_frag_result_name(gl_frag_result result)
{
   static const char *names[] = {
      ENUM(FRAG_RESULT_DEPTH),
      ENUM(FRAG_RESULT_STENCIL),
      ENUM(FRAG_RESULT_COLOR),
      ENUM(FRAG_RESULT_SAMPLE_MASK),
      ENUM(FRAG_RESULT_DATA0),
      ENUM(FRAG_RESULT_DATA1),
      ENUM(FRAG_RESULT_DATA2),
      ENUM(FRAG_RESULT_DATA3),
      ENUM(FRAG_RESULT_DATA4),
      ENUM(FRAG_RESULT_DATA5),
      ENUM(FRAG_RESULT_DATA6),
      ENUM(FRAG_RESULT_DATA7),
   };
   STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX);
   return NAME(result);
}