glsl: remove specical case subroutine type counting
[mesa.git] / src / glsl / shader_enums.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR 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
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #ifndef SHADER_ENUMS_H
27 #define SHADER_ENUMS_H
28
29 /**
30 * Shader stages. Note that these will become 5 with tessellation.
31 *
32 * The order must match how shaders are ordered in the pipeline.
33 * The GLSL linker assumes that if i<j, then the j-th shader is
34 * executed later than the i-th shader.
35 */
36 typedef enum
37 {
38 MESA_SHADER_VERTEX = 0,
39 MESA_SHADER_TESS_CTRL = 1,
40 MESA_SHADER_TESS_EVAL = 2,
41 MESA_SHADER_GEOMETRY = 3,
42 MESA_SHADER_FRAGMENT = 4,
43 MESA_SHADER_COMPUTE = 5,
44 } gl_shader_stage;
45
46 #define MESA_SHADER_STAGES (MESA_SHADER_COMPUTE + 1)
47
48 /**
49 * Indexes for vertex shader outputs, geometry shader inputs/outputs, and
50 * fragment shader inputs.
51 *
52 * Note that some of these values are not available to all pipeline stages.
53 *
54 * When this enum is updated, the following code must be updated too:
55 * - vertResults (in prog_print.c's arb_output_attrib_string())
56 * - fragAttribs (in prog_print.c's arb_input_attrib_string())
57 * - _mesa_varying_slot_in_fs()
58 */
59 typedef enum
60 {
61 VARYING_SLOT_POS,
62 VARYING_SLOT_COL0, /* COL0 and COL1 must be contiguous */
63 VARYING_SLOT_COL1,
64 VARYING_SLOT_FOGC,
65 VARYING_SLOT_TEX0, /* TEX0-TEX7 must be contiguous */
66 VARYING_SLOT_TEX1,
67 VARYING_SLOT_TEX2,
68 VARYING_SLOT_TEX3,
69 VARYING_SLOT_TEX4,
70 VARYING_SLOT_TEX5,
71 VARYING_SLOT_TEX6,
72 VARYING_SLOT_TEX7,
73 VARYING_SLOT_PSIZ, /* Does not appear in FS */
74 VARYING_SLOT_BFC0, /* Does not appear in FS */
75 VARYING_SLOT_BFC1, /* Does not appear in FS */
76 VARYING_SLOT_EDGE, /* Does not appear in FS */
77 VARYING_SLOT_CLIP_VERTEX, /* Does not appear in FS */
78 VARYING_SLOT_CLIP_DIST0,
79 VARYING_SLOT_CLIP_DIST1,
80 VARYING_SLOT_PRIMITIVE_ID, /* Does not appear in VS */
81 VARYING_SLOT_LAYER, /* Appears as VS or GS output */
82 VARYING_SLOT_VIEWPORT, /* Appears as VS or GS output */
83 VARYING_SLOT_FACE, /* FS only */
84 VARYING_SLOT_PNTC, /* FS only */
85 VARYING_SLOT_TESS_LEVEL_OUTER, /* Only appears as TCS output. */
86 VARYING_SLOT_TESS_LEVEL_INNER, /* Only appears as TCS output. */
87 VARYING_SLOT_VAR0, /* First generic varying slot */
88 } gl_varying_slot;
89
90
91 /**
92 * Bitflags for varying slots.
93 */
94 /*@{*/
95 #define VARYING_BIT_POS BITFIELD64_BIT(VARYING_SLOT_POS)
96 #define VARYING_BIT_COL0 BITFIELD64_BIT(VARYING_SLOT_COL0)
97 #define VARYING_BIT_COL1 BITFIELD64_BIT(VARYING_SLOT_COL1)
98 #define VARYING_BIT_FOGC BITFIELD64_BIT(VARYING_SLOT_FOGC)
99 #define VARYING_BIT_TEX0 BITFIELD64_BIT(VARYING_SLOT_TEX0)
100 #define VARYING_BIT_TEX1 BITFIELD64_BIT(VARYING_SLOT_TEX1)
101 #define VARYING_BIT_TEX2 BITFIELD64_BIT(VARYING_SLOT_TEX2)
102 #define VARYING_BIT_TEX3 BITFIELD64_BIT(VARYING_SLOT_TEX3)
103 #define VARYING_BIT_TEX4 BITFIELD64_BIT(VARYING_SLOT_TEX4)
104 #define VARYING_BIT_TEX5 BITFIELD64_BIT(VARYING_SLOT_TEX5)
105 #define VARYING_BIT_TEX6 BITFIELD64_BIT(VARYING_SLOT_TEX6)
106 #define VARYING_BIT_TEX7 BITFIELD64_BIT(VARYING_SLOT_TEX7)
107 #define VARYING_BIT_TEX(U) BITFIELD64_BIT(VARYING_SLOT_TEX0 + (U))
108 #define VARYING_BITS_TEX_ANY BITFIELD64_RANGE(VARYING_SLOT_TEX0, \
109 MAX_TEXTURE_COORD_UNITS)
110 #define VARYING_BIT_PSIZ BITFIELD64_BIT(VARYING_SLOT_PSIZ)
111 #define VARYING_BIT_BFC0 BITFIELD64_BIT(VARYING_SLOT_BFC0)
112 #define VARYING_BIT_BFC1 BITFIELD64_BIT(VARYING_SLOT_BFC1)
113 #define VARYING_BIT_EDGE BITFIELD64_BIT(VARYING_SLOT_EDGE)
114 #define VARYING_BIT_CLIP_VERTEX BITFIELD64_BIT(VARYING_SLOT_CLIP_VERTEX)
115 #define VARYING_BIT_CLIP_DIST0 BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST0)
116 #define VARYING_BIT_CLIP_DIST1 BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST1)
117 #define VARYING_BIT_PRIMITIVE_ID BITFIELD64_BIT(VARYING_SLOT_PRIMITIVE_ID)
118 #define VARYING_BIT_LAYER BITFIELD64_BIT(VARYING_SLOT_LAYER)
119 #define VARYING_BIT_VIEWPORT BITFIELD64_BIT(VARYING_SLOT_VIEWPORT)
120 #define VARYING_BIT_FACE BITFIELD64_BIT(VARYING_SLOT_FACE)
121 #define VARYING_BIT_PNTC BITFIELD64_BIT(VARYING_SLOT_PNTC)
122 #define VARYING_BIT_TESS_LEVEL_OUTER BITFIELD64_BIT(VARYING_SLOT_TESS_LEVEL_OUTER)
123 #define VARYING_BIT_TESS_LEVEL_INNER BITFIELD64_BIT(VARYING_SLOT_TESS_LEVEL_INNER)
124 #define VARYING_BIT_VAR(V) BITFIELD64_BIT(VARYING_SLOT_VAR0 + (V))
125 /*@}*/
126
127 /**
128 * Bitflags for system values.
129 */
130 #define SYSTEM_BIT_SAMPLE_ID ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_ID)
131 #define SYSTEM_BIT_SAMPLE_POS ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_POS)
132 #define SYSTEM_BIT_SAMPLE_MASK_IN ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_MASK_IN)
133 /**
134 * If the gl_register_file is PROGRAM_SYSTEM_VALUE, the register index will be
135 * one of these values. If a NIR variable's mode is nir_var_system_value, it
136 * will be one of these values.
137 */
138 typedef enum
139 {
140 /**
141 * \name Vertex shader system values
142 */
143 /*@{*/
144 /**
145 * OpenGL-style vertex ID.
146 *
147 * Section 2.11.7 (Shader Execution), subsection Shader Inputs, of the
148 * OpenGL 3.3 core profile spec says:
149 *
150 * "gl_VertexID holds the integer index i implicitly passed by
151 * DrawArrays or one of the other drawing commands defined in section
152 * 2.8.3."
153 *
154 * Section 2.8.3 (Drawing Commands) of the same spec says:
155 *
156 * "The commands....are equivalent to the commands with the same base
157 * name (without the BaseVertex suffix), except that the ith element
158 * transferred by the corresponding draw call will be taken from
159 * element indices[i] + basevertex of each enabled array."
160 *
161 * Additionally, the overview in the GL_ARB_shader_draw_parameters spec
162 * says:
163 *
164 * "In unextended GL, vertex shaders have inputs named gl_VertexID and
165 * gl_InstanceID, which contain, respectively the index of the vertex
166 * and instance. The value of gl_VertexID is the implicitly passed
167 * index of the vertex being processed, which includes the value of
168 * baseVertex, for those commands that accept it."
169 *
170 * gl_VertexID gets basevertex added in. This differs from DirectX where
171 * SV_VertexID does \b not get basevertex added in.
172 *
173 * \note
174 * If all system values are available, \c SYSTEM_VALUE_VERTEX_ID will be
175 * equal to \c SYSTEM_VALUE_VERTEX_ID_ZERO_BASE plus
176 * \c SYSTEM_VALUE_BASE_VERTEX.
177 *
178 * \sa SYSTEM_VALUE_VERTEX_ID_ZERO_BASE, SYSTEM_VALUE_BASE_VERTEX
179 */
180 SYSTEM_VALUE_VERTEX_ID,
181
182 /**
183 * Instanced ID as supplied to gl_InstanceID
184 *
185 * Values assigned to gl_InstanceID always begin with zero, regardless of
186 * the value of baseinstance.
187 *
188 * Section 11.1.3.9 (Shader Inputs) of the OpenGL 4.4 core profile spec
189 * says:
190 *
191 * "gl_InstanceID holds the integer instance number of the current
192 * primitive in an instanced draw call (see section 10.5)."
193 *
194 * Through a big chain of pseudocode, section 10.5 describes that
195 * baseinstance is not counted by gl_InstanceID. In that section, notice
196 *
197 * "If an enabled vertex attribute array is instanced (it has a
198 * non-zero divisor as specified by VertexAttribDivisor), the element
199 * index that is transferred to the GL, for all vertices, is given by
200 *
201 * floor(instance/divisor) + baseinstance
202 *
203 * If an array corresponding to an attribute required by a vertex
204 * shader is not enabled, then the corresponding element is taken from
205 * the current attribute state (see section 10.2)."
206 *
207 * Note that baseinstance is \b not included in the value of instance.
208 */
209 SYSTEM_VALUE_INSTANCE_ID,
210
211 /**
212 * DirectX-style vertex ID.
213 *
214 * Unlike \c SYSTEM_VALUE_VERTEX_ID, this system value does \b not include
215 * the value of basevertex.
216 *
217 * \sa SYSTEM_VALUE_VERTEX_ID, SYSTEM_VALUE_BASE_VERTEX
218 */
219 SYSTEM_VALUE_VERTEX_ID_ZERO_BASE,
220
221 /**
222 * Value of \c basevertex passed to \c glDrawElementsBaseVertex and similar
223 * functions.
224 *
225 * \sa SYSTEM_VALUE_VERTEX_ID, SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
226 */
227 SYSTEM_VALUE_BASE_VERTEX,
228 /*@}*/
229
230 /**
231 * \name Geometry shader system values
232 */
233 /*@{*/
234 SYSTEM_VALUE_INVOCATION_ID, /**< (Also in Tessellation Control shader) */
235 /*@}*/
236
237 /**
238 * \name Fragment shader system values
239 */
240 /*@{*/
241 SYSTEM_VALUE_FRONT_FACE, /**< (not done yet) */
242 SYSTEM_VALUE_SAMPLE_ID,
243 SYSTEM_VALUE_SAMPLE_POS,
244 SYSTEM_VALUE_SAMPLE_MASK_IN,
245 /*@}*/
246
247 /**
248 * \name Tessellation Evaluation shader system values
249 */
250 /*@{*/
251 SYSTEM_VALUE_TESS_COORD,
252 SYSTEM_VALUE_VERTICES_IN, /**< Tessellation vertices in input patch */
253 SYSTEM_VALUE_PRIMITIVE_ID, /**< (currently not used by GS) */
254 SYSTEM_VALUE_TESS_LEVEL_OUTER, /**< TES input */
255 SYSTEM_VALUE_TESS_LEVEL_INNER, /**< TES input */
256 /*@}*/
257
258 SYSTEM_VALUE_MAX /**< Number of values */
259 } gl_system_value;
260
261
262 /**
263 * The possible interpolation qualifiers that can be applied to a fragment
264 * shader input in GLSL.
265 *
266 * Note: INTERP_QUALIFIER_NONE must be 0 so that memsetting the
267 * gl_fragment_program data structure to 0 causes the default behavior.
268 */
269 enum glsl_interp_qualifier
270 {
271 INTERP_QUALIFIER_NONE = 0,
272 INTERP_QUALIFIER_SMOOTH,
273 INTERP_QUALIFIER_FLAT,
274 INTERP_QUALIFIER_NOPERSPECTIVE,
275 INTERP_QUALIFIER_COUNT /**< Number of interpolation qualifiers */
276 };
277
278 /**
279 * Fragment program results
280 */
281 typedef enum
282 {
283 FRAG_RESULT_DEPTH = 0,
284 FRAG_RESULT_STENCIL = 1,
285 /* If a single color should be written to all render targets, this
286 * register is written. No FRAG_RESULT_DATAn will be written.
287 */
288 FRAG_RESULT_COLOR = 2,
289 FRAG_RESULT_SAMPLE_MASK = 3,
290
291 /* FRAG_RESULT_DATAn are the per-render-target (GLSL gl_FragData[n]
292 * or ARB_fragment_program fragment.color[n]) color results. If
293 * any are written, FRAG_RESULT_COLOR will not be written.
294 */
295 FRAG_RESULT_DATA0 = 4,
296 } gl_frag_result;
297
298 #endif /* SHADER_ENUMS_H */