blob: 00261d1988c5bea23cc732e0371a7f660496972b [file] [log] [blame]
Rob Clarkf2533f22015-09-11 12:48:05 -04001/*
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
Rob Clarkc9b982b2015-10-08 18:19:00 -040029#include "shader_enums.h"
Rob Clarkf2533f22015-09-11 12:48:05 -040030#include "util/macros.h"
Rob Clark33de9982015-10-09 16:27:45 -040031#include "mesa/main/config.h"
Rob Clarkf2533f22015-09-11 12:48:05 -040032
33#define ENUM(x) [x] = #x
34#define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")
35
Matt Turnera4397882016-01-15 13:31:34 -080036const char *
37gl_shader_stage_name(gl_shader_stage stage)
Rob Clarkf2533f22015-09-11 12:48:05 -040038{
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 };
Rob Clark33de9982015-10-09 16:27:45 -040047 STATIC_ASSERT(ARRAY_SIZE(names) == MESA_SHADER_STAGES);
Rob Clarkf2533f22015-09-11 12:48:05 -040048 return NAME(stage);
49}
50
Kristian Høgsberg Kristensen82ad5712016-01-08 12:35:48 -080051/**
52 * Translate a gl_shader_stage to a short shader stage name for debug
53 * printouts and error messages.
54 */
Matt Turnera4397882016-01-15 13:31:34 -080055const char *
56_mesa_shader_stage_to_string(unsigned stage)
Kristian Høgsberg Kristensen82ad5712016-01-08 12:35:48 -080057{
58 switch (stage) {
59 case MESA_SHADER_VERTEX: return "vertex";
60 case MESA_SHADER_FRAGMENT: return "fragment";
61 case MESA_SHADER_GEOMETRY: return "geometry";
62 case MESA_SHADER_COMPUTE: return "compute";
Kenneth Graunke4fc01852015-12-31 16:28:08 -080063 case MESA_SHADER_TESS_CTRL: return "tessellation control";
64 case MESA_SHADER_TESS_EVAL: return "tessellation evaluation";
Kristian Høgsberg Kristensen82ad5712016-01-08 12:35:48 -080065 }
66
67 unreachable("Unknown shader stage.");
68}
69
70/**
71 * Translate a gl_shader_stage to a shader stage abbreviation (VS, GS, FS)
72 * for debug printouts and error messages.
73 */
Matt Turnera4397882016-01-15 13:31:34 -080074const char *
75_mesa_shader_stage_to_abbrev(unsigned stage)
Kristian Høgsberg Kristensen82ad5712016-01-08 12:35:48 -080076{
77 switch (stage) {
78 case MESA_SHADER_VERTEX: return "VS";
79 case MESA_SHADER_FRAGMENT: return "FS";
80 case MESA_SHADER_GEOMETRY: return "GS";
81 case MESA_SHADER_COMPUTE: return "CS";
82 case MESA_SHADER_TESS_CTRL: return "TCS";
83 case MESA_SHADER_TESS_EVAL: return "TES";
84 }
85
86 unreachable("Unknown shader stage.");
87}
88
Matt Turnera4397882016-01-15 13:31:34 -080089const char *
90gl_vert_attrib_name(gl_vert_attrib attrib)
Rob Clarkf2533f22015-09-11 12:48:05 -040091{
92 static const char *names[] = {
93 ENUM(VERT_ATTRIB_POS),
94 ENUM(VERT_ATTRIB_WEIGHT),
95 ENUM(VERT_ATTRIB_NORMAL),
96 ENUM(VERT_ATTRIB_COLOR0),
97 ENUM(VERT_ATTRIB_COLOR1),
98 ENUM(VERT_ATTRIB_FOG),
99 ENUM(VERT_ATTRIB_COLOR_INDEX),
100 ENUM(VERT_ATTRIB_EDGEFLAG),
101 ENUM(VERT_ATTRIB_TEX0),
102 ENUM(VERT_ATTRIB_TEX1),
103 ENUM(VERT_ATTRIB_TEX2),
104 ENUM(VERT_ATTRIB_TEX3),
105 ENUM(VERT_ATTRIB_TEX4),
106 ENUM(VERT_ATTRIB_TEX5),
107 ENUM(VERT_ATTRIB_TEX6),
108 ENUM(VERT_ATTRIB_TEX7),
109 ENUM(VERT_ATTRIB_POINT_SIZE),
110 ENUM(VERT_ATTRIB_GENERIC0),
111 ENUM(VERT_ATTRIB_GENERIC1),
112 ENUM(VERT_ATTRIB_GENERIC2),
113 ENUM(VERT_ATTRIB_GENERIC3),
114 ENUM(VERT_ATTRIB_GENERIC4),
115 ENUM(VERT_ATTRIB_GENERIC5),
116 ENUM(VERT_ATTRIB_GENERIC6),
117 ENUM(VERT_ATTRIB_GENERIC7),
118 ENUM(VERT_ATTRIB_GENERIC8),
119 ENUM(VERT_ATTRIB_GENERIC9),
120 ENUM(VERT_ATTRIB_GENERIC10),
121 ENUM(VERT_ATTRIB_GENERIC11),
122 ENUM(VERT_ATTRIB_GENERIC12),
123 ENUM(VERT_ATTRIB_GENERIC13),
124 ENUM(VERT_ATTRIB_GENERIC14),
125 ENUM(VERT_ATTRIB_GENERIC15),
126 };
Rob Clark33de9982015-10-09 16:27:45 -0400127 STATIC_ASSERT(ARRAY_SIZE(names) == VERT_ATTRIB_MAX);
Rob Clarkf2533f22015-09-11 12:48:05 -0400128 return NAME(attrib);
129}
130
Matt Turnera4397882016-01-15 13:31:34 -0800131const char *
132gl_varying_slot_name(gl_varying_slot slot)
Rob Clarkf2533f22015-09-11 12:48:05 -0400133{
134 static const char *names[] = {
135 ENUM(VARYING_SLOT_POS),
136 ENUM(VARYING_SLOT_COL0),
137 ENUM(VARYING_SLOT_COL1),
138 ENUM(VARYING_SLOT_FOGC),
139 ENUM(VARYING_SLOT_TEX0),
140 ENUM(VARYING_SLOT_TEX1),
141 ENUM(VARYING_SLOT_TEX2),
142 ENUM(VARYING_SLOT_TEX3),
143 ENUM(VARYING_SLOT_TEX4),
144 ENUM(VARYING_SLOT_TEX5),
145 ENUM(VARYING_SLOT_TEX6),
146 ENUM(VARYING_SLOT_TEX7),
147 ENUM(VARYING_SLOT_PSIZ),
148 ENUM(VARYING_SLOT_BFC0),
149 ENUM(VARYING_SLOT_BFC1),
150 ENUM(VARYING_SLOT_EDGE),
151 ENUM(VARYING_SLOT_CLIP_VERTEX),
152 ENUM(VARYING_SLOT_CLIP_DIST0),
153 ENUM(VARYING_SLOT_CLIP_DIST1),
154 ENUM(VARYING_SLOT_PRIMITIVE_ID),
155 ENUM(VARYING_SLOT_LAYER),
156 ENUM(VARYING_SLOT_VIEWPORT),
157 ENUM(VARYING_SLOT_FACE),
158 ENUM(VARYING_SLOT_PNTC),
159 ENUM(VARYING_SLOT_TESS_LEVEL_OUTER),
160 ENUM(VARYING_SLOT_TESS_LEVEL_INNER),
161 ENUM(VARYING_SLOT_VAR0),
162 ENUM(VARYING_SLOT_VAR1),
163 ENUM(VARYING_SLOT_VAR2),
164 ENUM(VARYING_SLOT_VAR3),
165 ENUM(VARYING_SLOT_VAR4),
166 ENUM(VARYING_SLOT_VAR5),
167 ENUM(VARYING_SLOT_VAR6),
168 ENUM(VARYING_SLOT_VAR7),
169 ENUM(VARYING_SLOT_VAR8),
170 ENUM(VARYING_SLOT_VAR9),
171 ENUM(VARYING_SLOT_VAR10),
172 ENUM(VARYING_SLOT_VAR11),
173 ENUM(VARYING_SLOT_VAR12),
174 ENUM(VARYING_SLOT_VAR13),
175 ENUM(VARYING_SLOT_VAR14),
176 ENUM(VARYING_SLOT_VAR15),
177 ENUM(VARYING_SLOT_VAR16),
178 ENUM(VARYING_SLOT_VAR17),
179 ENUM(VARYING_SLOT_VAR18),
180 ENUM(VARYING_SLOT_VAR19),
181 ENUM(VARYING_SLOT_VAR20),
182 ENUM(VARYING_SLOT_VAR21),
183 ENUM(VARYING_SLOT_VAR22),
184 ENUM(VARYING_SLOT_VAR23),
185 ENUM(VARYING_SLOT_VAR24),
186 ENUM(VARYING_SLOT_VAR25),
187 ENUM(VARYING_SLOT_VAR26),
188 ENUM(VARYING_SLOT_VAR27),
189 ENUM(VARYING_SLOT_VAR28),
190 ENUM(VARYING_SLOT_VAR29),
191 ENUM(VARYING_SLOT_VAR30),
192 ENUM(VARYING_SLOT_VAR31),
193 };
Rob Clark33de9982015-10-09 16:27:45 -0400194 STATIC_ASSERT(ARRAY_SIZE(names) == VARYING_SLOT_MAX);
Rob Clarkf2533f22015-09-11 12:48:05 -0400195 return NAME(slot);
196}
197
Matt Turnera4397882016-01-15 13:31:34 -0800198const char *
199gl_system_value_name(gl_system_value sysval)
Rob Clarkf2533f22015-09-11 12:48:05 -0400200{
201 static const char *names[] = {
202 ENUM(SYSTEM_VALUE_VERTEX_ID),
203 ENUM(SYSTEM_VALUE_INSTANCE_ID),
Jason Ekstrand22836db2016-03-25 10:50:11 -0700204 ENUM(SYSTEM_VALUE_INSTANCE_INDEX),
Rob Clarkf2533f22015-09-11 12:48:05 -0400205 ENUM(SYSTEM_VALUE_VERTEX_ID_ZERO_BASE),
206 ENUM(SYSTEM_VALUE_BASE_VERTEX),
207 ENUM(SYSTEM_VALUE_INVOCATION_ID),
208 ENUM(SYSTEM_VALUE_FRONT_FACE),
209 ENUM(SYSTEM_VALUE_SAMPLE_ID),
210 ENUM(SYSTEM_VALUE_SAMPLE_POS),
211 ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
212 ENUM(SYSTEM_VALUE_TESS_COORD),
213 ENUM(SYSTEM_VALUE_VERTICES_IN),
214 ENUM(SYSTEM_VALUE_PRIMITIVE_ID),
215 ENUM(SYSTEM_VALUE_TESS_LEVEL_OUTER),
216 ENUM(SYSTEM_VALUE_TESS_LEVEL_INNER),
217 ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_ID),
Jason Ekstrand39103142016-03-25 10:51:23 -0700218 ENUM(SYSTEM_VALUE_LOCAL_INVOCATION_INDEX),
219 ENUM(SYSTEM_VALUE_GLOBAL_INVOCATION_ID),
Rob Clarkf2533f22015-09-11 12:48:05 -0400220 ENUM(SYSTEM_VALUE_WORK_GROUP_ID),
Rob Clark33de9982015-10-09 16:27:45 -0400221 ENUM(SYSTEM_VALUE_NUM_WORK_GROUPS),
Rob Clark4a121e12015-09-11 17:01:23 -0400222 ENUM(SYSTEM_VALUE_VERTEX_CNT),
Rob Clarkf2533f22015-09-11 12:48:05 -0400223 };
Rob Clark33de9982015-10-09 16:27:45 -0400224 STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX);
Rob Clarkf2533f22015-09-11 12:48:05 -0400225 return NAME(sysval);
226}
227
Matt Turnera4397882016-01-15 13:31:34 -0800228const char *
Kenneth Graunkeac1181f2016-07-07 02:02:38 -0700229glsl_interp_mode_name(enum glsl_interp_mode qual)
Rob Clarkf2533f22015-09-11 12:48:05 -0400230{
231 static const char *names[] = {
Kenneth Graunkeac1181f2016-07-07 02:02:38 -0700232 ENUM(INTERP_MODE_NONE),
233 ENUM(INTERP_MODE_SMOOTH),
234 ENUM(INTERP_MODE_FLAT),
235 ENUM(INTERP_MODE_NOPERSPECTIVE),
Rob Clarkf2533f22015-09-11 12:48:05 -0400236 };
Kenneth Graunkeac1181f2016-07-07 02:02:38 -0700237 STATIC_ASSERT(ARRAY_SIZE(names) == INTERP_MODE_COUNT);
Rob Clarkf2533f22015-09-11 12:48:05 -0400238 return NAME(qual);
239}
240
Matt Turnera4397882016-01-15 13:31:34 -0800241const char *
242gl_frag_result_name(gl_frag_result result)
Rob Clarkf2533f22015-09-11 12:48:05 -0400243{
244 static const char *names[] = {
245 ENUM(FRAG_RESULT_DEPTH),
246 ENUM(FRAG_RESULT_STENCIL),
247 ENUM(FRAG_RESULT_COLOR),
248 ENUM(FRAG_RESULT_SAMPLE_MASK),
249 ENUM(FRAG_RESULT_DATA0),
250 ENUM(FRAG_RESULT_DATA1),
251 ENUM(FRAG_RESULT_DATA2),
252 ENUM(FRAG_RESULT_DATA3),
253 ENUM(FRAG_RESULT_DATA4),
254 ENUM(FRAG_RESULT_DATA5),
255 ENUM(FRAG_RESULT_DATA6),
256 ENUM(FRAG_RESULT_DATA7),
257 };
Rob Clark33de9982015-10-09 16:27:45 -0400258 STATIC_ASSERT(ARRAY_SIZE(names) == FRAG_RESULT_MAX);
Rob Clarkf2533f22015-09-11 12:48:05 -0400259 return NAME(result);
260}