1b8e80941Smrg/*
2b8e80941Smrg * Mesa 3-D graphics library
3b8e80941Smrg *
4b8e80941Smrg * Copyright © 2015 Red Hat
5b8e80941Smrg *
6b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7b8e80941Smrg * copy of this software and associated documentation files (the "Software"),
8b8e80941Smrg * to deal in the Software without restriction, including without limitation
9b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the
11b8e80941Smrg * Software is furnished to do so, subject to the following conditions:
12b8e80941Smrg *
13b8e80941Smrg * The above copyright notice and this permission notice (including the next
14b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the
15b8e80941Smrg * Software.
16b8e80941Smrg *
17b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23b8e80941Smrg * IN THE SOFTWARE.
24b8e80941Smrg *
25b8e80941Smrg * Authors:
26b8e80941Smrg *    Rob Clark <robclark@freedesktop.org>
27b8e80941Smrg */
28b8e80941Smrg
29b8e80941Smrg#include "shader_enums.h"
30b8e80941Smrg#include "util/macros.h"
31b8e80941Smrg#include "mesa/main/config.h"
32b8e80941Smrg
33b8e80941Smrg#define ENUM(x) [x] = #x
34b8e80941Smrg#define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")
35b8e80941Smrg
36b8e80941Smrgconst char *
37b8e80941Smrggl_shader_stage_name(gl_shader_stage stage)
38b8e80941Smrg{
39b8e80941Smrg   static const char *names[] = {
40b8e80941Smrg      ENUM(MESA_SHADER_VERTEX),
41b8e80941Smrg      ENUM(MESA_SHADER_TESS_CTRL),
42b8e80941Smrg      ENUM(MESA_SHADER_TESS_EVAL),
43b8e80941Smrg      ENUM(MESA_SHADER_GEOMETRY),
44b8e80941Smrg      ENUM(MESA_SHADER_FRAGMENT),
45b8e80941Smrg      ENUM(MESA_SHADER_COMPUTE),
46b8e80941Smrg      ENUM(MESA_SHADER_KERNEL),
47b8e80941Smrg   };
48b8e80941Smrg   STATIC_ASSERT(ARRAY_SIZE(names) == MESA_ALL_SHADER_STAGES);
49b8e80941Smrg   return NAME(stage);
50b8e80941Smrg}
51b8e80941Smrg
52b8e80941Smrg/**
53b8e80941Smrg * Translate a gl_shader_stage to a short shader stage name for debug
54b8e80941Smrg * printouts and error messages.
55b8e80941Smrg */
56b8e80941Smrgconst char *
57b8e80941Smrg_mesa_shader_stage_to_string(unsigned stage)
58b8e80941Smrg{
59b8e80941Smrg   switch (stage) {
60b8e80941Smrg   case MESA_SHADER_VERTEX:   return "vertex";
61b8e80941Smrg   case MESA_SHADER_FRAGMENT: return "fragment";
62b8e80941Smrg   case MESA_SHADER_GEOMETRY: return "geometry";
63b8e80941Smrg   case MESA_SHADER_COMPUTE:  return "compute";
64b8e80941Smrg   case MESA_SHADER_KERNEL:   return "kernel";
65b8e80941Smrg   case MESA_SHADER_TESS_CTRL: return "tessellation control";
66b8e80941Smrg   case MESA_SHADER_TESS_EVAL: return "tessellation evaluation";
67b8e80941Smrg   }
68b8e80941Smrg
69b8e80941Smrg   unreachable("Unknown shader stage.");
70b8e80941Smrg}
71b8e80941Smrg
72b8e80941Smrg/**
73b8e80941Smrg * Translate a gl_shader_stage to a shader stage abbreviation (VS, GS, FS)
74b8e80941Smrg * for debug printouts and error messages.
75b8e80941Smrg */
76b8e80941Smrgconst char *
77b8e80941Smrg_mesa_shader_stage_to_abbrev(unsigned stage)
78b8e80941Smrg{
79b8e80941Smrg   switch (stage) {
80b8e80941Smrg   case MESA_SHADER_VERTEX:   return "VS";
81b8e80941Smrg   case MESA_SHADER_FRAGMENT: return "FS";
82b8e80941Smrg   case MESA_SHADER_GEOMETRY: return "GS";
83b8e80941Smrg   case MESA_SHADER_COMPUTE:  return "CS";
84b8e80941Smrg   case MESA_SHADER_KERNEL:   return "CL";
85b8e80941Smrg   case MESA_SHADER_TESS_CTRL: return "TCS";
86b8e80941Smrg   case MESA_SHADER_TESS_EVAL: return "TES";
87b8e80941Smrg   }
88b8e80941Smrg
89b8e80941Smrg   unreachable("Unknown shader stage.");
90b8e80941Smrg}
91b8e80941Smrg
92b8e80941Smrgconst char *
93b8e80941Smrggl_vert_attrib_name(gl_vert_attrib attrib)
94b8e80941Smrg{
95b8e80941Smrg   static const char *names[] = {
96b8e80941Smrg      ENUM(VERT_ATTRIB_POS),
97b8e80941Smrg      ENUM(VERT_ATTRIB_NORMAL),
98b8e80941Smrg      ENUM(VERT_ATTRIB_COLOR0),
99b8e80941Smrg      ENUM(VERT_ATTRIB_COLOR1),
100b8e80941Smrg      ENUM(VERT_ATTRIB_FOG),
101b8e80941Smrg      ENUM(VERT_ATTRIB_COLOR_INDEX),
102b8e80941Smrg      ENUM(VERT_ATTRIB_EDGEFLAG),
103b8e80941Smrg      ENUM(VERT_ATTRIB_TEX0),
104b8e80941Smrg      ENUM(VERT_ATTRIB_TEX1),
105b8e80941Smrg      ENUM(VERT_ATTRIB_TEX2),
106b8e80941Smrg      ENUM(VERT_ATTRIB_TEX3),
107b8e80941Smrg      ENUM(VERT_ATTRIB_TEX4),
108b8e80941Smrg      ENUM(VERT_ATTRIB_TEX5),
109b8e80941Smrg      ENUM(VERT_ATTRIB_TEX6),
110b8e80941Smrg      ENUM(VERT_ATTRIB_TEX7),
111b8e80941Smrg      ENUM(VERT_ATTRIB_POINT_SIZE),
112b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC0),
113b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC1),
114b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC2),
115b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC3),
116b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC4),
117b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC5),
118b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC6),
119b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC7),
120b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC8),
121b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC9),
122b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC10),
123b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC11),
124b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC12),
125b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC13),
126b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC14),
127b8e80941Smrg      ENUM(VERT_ATTRIB_GENERIC15),
128b8e80941Smrg   };
129b8e80941Smrg   STATIC_ASSERT(ARRAY_SIZE(names) == VERT_ATTRIB_MAX);
130b8e80941Smrg   return NAME(attrib);
131b8e80941Smrg}
132b8e80941Smrg
133b8e80941Smrgconst char *
134b8e80941Smrggl_varying_slot_name(gl_varying_slot slot)
135b8e80941Smrg{
136b8e80941Smrg   static const char *names[] = {
137b8e80941Smrg      ENUM(VARYING_SLOT_POS),
138b8e80941Smrg      ENUM(VARYING_SLOT_COL0),
139b8e80941Smrg      ENUM(VARYING_SLOT_COL1),
140b8e80941Smrg      ENUM(VARYING_SLOT_FOGC),
141b8e80941Smrg      ENUM(VARYING_SLOT_TEX0),
142b8e80941Smrg      ENUM(VARYING_SLOT_TEX1),
143b8e80941Smrg      ENUM(VARYING_SLOT_TEX2),
144b8e80941Smrg      ENUM(VARYING_SLOT_TEX3),
145b8e80941Smrg      ENUM(VARYING_SLOT_TEX4),
146b8e80941Smrg      ENUM(VARYING_SLOT_TEX5),
147b8e80941Smrg      ENUM(VARYING_SLOT_TEX6),
148b8e80941Smrg      ENUM(VARYING_SLOT_TEX7),
149b8e80941Smrg      ENUM(VARYING_SLOT_PSIZ),
150b8e80941Smrg      ENUM(VARYING_SLOT_BFC0),
151b8e80941Smrg      ENUM(VARYING_SLOT_BFC1),
152b8e80941Smrg      ENUM(VARYING_SLOT_EDGE),
153b8e80941Smrg      ENUM(VARYING_SLOT_CLIP_VERTEX),
154b8e80941Smrg      ENUM(VARYING_SLOT_CLIP_DIST0),
155b8e80941Smrg      ENUM(VARYING_SLOT_CLIP_DIST1),
156b8e80941Smrg      ENUM(VARYING_SLOT_CULL_DIST0),
157b8e80941Smrg      ENUM(VARYING_SLOT_CULL_DIST1),
158b8e80941Smrg      ENUM(VARYING_SLOT_PRIMITIVE_ID),
159b8e80941Smrg      ENUM(VARYING_SLOT_LAYER),
160b8e80941Smrg      ENUM(VARYING_SLOT_VIEWPORT),
161b8e80941Smrg      ENUM(VARYING_SLOT_FACE),
162b8e80941Smrg      ENUM(VARYING_SLOT_PNTC),
163b8e80941Smrg      ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
164b8e80941Smrg      ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
165b8e80941Smrg      ENUM(VARYING_SLOT_BOUNDING_BOX0),
166b8e80941Smrg      ENUM(VARYING_SLOT_BOUNDING_BOX1),
167b8e80941Smrg      ENUM(VARYING_SLOT_VIEW_INDEX),
168b8e80941Smrg      ENUM(VARYING_SLOT_VAR0),
169b8e80941Smrg      ENUM(VARYING_SLOT_VAR1),
170b8e80941Smrg      ENUM(VARYING_SLOT_VAR2),
171b8e80941Smrg      ENUM(VARYING_SLOT_VAR3),
172b8e80941Smrg      ENUM(VARYING_SLOT_VAR4),
173b8e80941Smrg      ENUM(VARYING_SLOT_VAR5),
174b8e80941Smrg      ENUM(VARYING_SLOT_VAR6),
175b8e80941Smrg      ENUM(VARYING_SLOT_VAR7),
176b8e80941Smrg      ENUM(VARYING_SLOT_VAR8),
177b8e80941Smrg      ENUM(VARYING_SLOT_VAR9),
178b8e80941Smrg      ENUM(VARYING_SLOT_VAR10),
179b8e80941Smrg      ENUM(VARYING_SLOT_VAR11),
180b8e80941Smrg      ENUM(VARYING_SLOT_VAR12),
181b8e80941Smrg      ENUM(VARYING_SLOT_VAR13),
182b8e80941Smrg      ENUM(VARYING_SLOT_VAR14),
183b8e80941Smrg      ENUM(VARYING_SLOT_VAR15),
184b8e80941Smrg      ENUM(VARYING_SLOT_VAR16),
185b8e80941Smrg      ENUM(VARYING_SLOT_VAR17),
186b8e80941Smrg      ENUM(VARYING_SLOT_VAR18),
187b8e80941Smrg      ENUM(VARYING_SLOT_VAR19),
188b8e80941Smrg      ENUM(VARYING_SLOT_VAR20),
189b8e80941Smrg      ENUM(VARYING_SLOT_VAR21),
190b8e80941Smrg      ENUM(VARYING_SLOT_VAR22),
191b8e80941Smrg      ENUM(VARYING_SLOT_VAR23),
192b8e80941Smrg      ENUM(VARYING_SLOT_VAR24),
193b8e80941Smrg      ENUM(VARYING_SLOT_VAR25),
194b8e80941Smrg      ENUM(VARYING_SLOT_VAR26),
195b8e80941Smrg      ENUM(VARYING_SLOT_VAR27),
196b8e80941Smrg      ENUM(VARYING_SLOT_VAR28),
197b8e80941Smrg      ENUM(VARYING_SLOT_VAR29),
198b8e80941Smrg      ENUM(VARYING_SLOT_VAR30),
199b8e80941Smrg      ENUM(VARYING_SLOT_VAR31),
200b8e80941Smrg   };
201b8e80941Smrg   STATIC_ASSERT(ARRAY_SIZE(names) == VARYING_SLOT_MAX);
202b8e80941Smrg   return NAME(slot);
203b8e80941Smrg}
204b8e80941Smrg
205b8e80941Smrgconst char *
206b8e80941Smrggl_system_value_name(gl_system_value sysval)
207b8e80941Smrg{
208b8e80941Smrg   static const char *names[] = {
209b8e80941Smrg     ENUM(SYSTEM_VALUE_SUBGROUP_SIZE),
210b8e80941Smrg     ENUM(SYSTEM_VALUE_SUBGROUP_INVOCATION),
211b8e80941Smrg     ENUM(SYSTEM_VALUE_SUBGROUP_EQ_MASK),
212b8e80941Smrg     ENUM(SYSTEM_VALUE_SUBGROUP_GE_MASK),
213b8e80941Smrg     ENUM(SYSTEM_VALUE_SUBGROUP_GT_MASK),
214b8e80941Smrg     ENUM(SYSTEM_VALUE_SUBGROUP_LE_MASK),
215b8e80941Smrg     ENUM(SYSTEM_VALUE_SUBGROUP_LT_MASK),
216b8e80941Smrg     ENUM(SYSTEM_VALUE_NUM_SUBGROUPS),
217b8e80941Smrg     ENUM(SYSTEM_VALUE_SUBGROUP_ID),
218b8e80941Smrg     ENUM(SYSTEM_VALUE_VERTEX_ID),
219b8e80941Smrg     ENUM(SYSTEM_VALUE_INSTANCE_ID),
220b8e80941Smrg     ENUM(SYSTEM_VALUE_INSTANCE_INDEX),
221b8e80941Smrg     ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
222b8e80941Smrg     ENUM(SYSTEM_VALUE_BASE_VERTEX),
223b8e80941Smrg     ENUM(SYSTEM_VALUE_FIRST_VERTEX),
224b8e80941Smrg     ENUM(SYSTEM_VALUE_IS_INDEXED_DRAW),
225b8e80941Smrg     ENUM(SYSTEM_VALUE_BASE_INSTANCE),
226b8e80941Smrg     ENUM(SYSTEM_VALUE_DRAW_ID),
227b8e80941Smrg     ENUM(SYSTEM_VALUE_INVOCATION_ID),
228b8e80941Smrg     ENUM(SYSTEM_VALUE_FRAG_COORD),
229b8e80941Smrg     ENUM(SYSTEM_VALUE_FRONT_FACE),
230b8e80941Smrg     ENUM(SYSTEM_VALUE_SAMPLE_ID),
231b8e80941Smrg     ENUM(SYSTEM_VALUE_SAMPLE_POS),
232b8e80941Smrg     ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
233b8e80941Smrg     ENUM(SYSTEM_VALUE_HELPER_INVOCATION),
234b8e80941Smrg     ENUM(SYSTEM_VALUE_TESS_COORD),
235b8e80941Smrg     ENUM(SYSTEM_VALUE_VERTICES_IN),
236b8e80941Smrg     ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
237b8e80941Smrg     ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
238b8e80941Smrg     ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
239b8e80941Smrg     ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
240b8e80941Smrg     ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX),
241b8e80941Smrg     ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_ID),
242b8e80941Smrg     ENUM(SYSTEM_VALUE_WORK_GROUP_ID),
243b8e80941Smrg     ENUM(SYSTEM_VALUE_NUM_WORK_GROUPS),
244b8e80941Smrg     ENUM(SYSTEM_VALUE_LOCAL_GROUP_SIZE),
245b8e80941Smrg     ENUM(SYSTEM_VALUE_GLOBAL_GROUP_SIZE),
246b8e80941Smrg     ENUM(SYSTEM_VALUE_WORK_DIM),
247b8e80941Smrg     ENUM(SYSTEM_VALUE_DEVICE_INDEX),
248b8e80941Smrg     ENUM(SYSTEM_VALUE_VIEW_INDEX),
249b8e80941Smrg     ENUM(SYSTEM_VALUE_VERTEX_CNT),
250b8e80941Smrg     ENUM(SYSTEM_VALUE_BARYCENTRIC_PIXEL),
251b8e80941Smrg     ENUM(SYSTEM_VALUE_BARYCENTRIC_SAMPLE),
252b8e80941Smrg     ENUM(SYSTEM_VALUE_BARYCENTRIC_CENTROID),
253b8e80941Smrg     ENUM(SYSTEM_VALUE_BARYCENTRIC_SIZE),
254b8e80941Smrg   };
255b8e80941Smrg   STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX);
256b8e80941Smrg   return NAME(sysval);
257b8e80941Smrg}
258b8e80941Smrg
259b8e80941Smrgconst char *
260b8e80941Smrgglsl_interp_mode_name(enum glsl_interp_mode qual)
261b8e80941Smrg{
262b8e80941Smrg   static const char *names[] = {
263b8e80941Smrg      ENUM(INTERP_MODE_NONE),
264b8e80941Smrg      ENUM(INTERP_MODE_SMOOTH),
265b8e80941Smrg      ENUM(INTERP_MODE_FLAT),
266b8e80941Smrg      ENUM(INTERP_MODE_NOPERSPECTIVE),
267b8e80941Smrg   };
268b8e80941Smrg   STATIC_ASSERT(ARRAY_SIZE(names) == INTERP_MODE_COUNT);
269b8e80941Smrg   return NAME(qual);
270b8e80941Smrg}
271b8e80941Smrg
272b8e80941Smrgconst char *
273b8e80941Smrggl_frag_result_name(gl_frag_result result)
274b8e80941Smrg{
275b8e80941Smrg   static const char *names[] = {
276b8e80941Smrg      ENUM(FRAG_RESULT_DEPTH),
277b8e80941Smrg      ENUM(FRAG_RESULT_STENCIL),
278b8e80941Smrg      ENUM(FRAG_RESULT_COLOR),
279b8e80941Smrg      ENUM(FRAG_RESULT_SAMPLE_MASK),
280b8e80941Smrg      ENUM(FRAG_RESULT_DATA0),
281b8e80941Smrg      ENUM(FRAG_RESULT_DATA1),
282b8e80941Smrg      ENUM(FRAG_RESULT_DATA2),
283b8e80941Smrg      ENUM(FRAG_RESULT_DATA3),
284b8e80941Smrg      ENUM(FRAG_RESULT_DATA4),
285b8e80941Smrg      ENUM(FRAG_RESULT_DATA5),
286b8e80941Smrg      ENUM(FRAG_RESULT_DATA6),
287b8e80941Smrg      ENUM(FRAG_RESULT_DATA7),
288b8e80941Smrg   };
289b8e80941Smrg   STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX);
290b8e80941Smrg   return NAME(result);
291b8e80941Smrg}
292