vk/vec4: Use the right constant for offset into a UBO
[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 #include "main/config.h"
27
28 #ifndef SHADER_ENUMS_H
29 #define SHADER_ENUMS_H
30
31 /**
32 * Shader stages. Note that these will become 5 with tessellation.
33 *
34 * The order must match how shaders are ordered in the pipeline.
35 * The GLSL linker assumes that if i<j, then the j-th shader is
36 * executed later than the i-th shader.
37 */
38 typedef enum
39 {
40 MESA_SHADER_VERTEX = 0,
41 MESA_SHADER_TESS_CTRL = 1,
42 MESA_SHADER_TESS_EVAL = 2,
43 MESA_SHADER_GEOMETRY = 3,
44 MESA_SHADER_FRAGMENT = 4,
45 MESA_SHADER_COMPUTE = 5,
46 } gl_shader_stage;
47
48 #define MESA_SHADER_STAGES (MESA_SHADER_COMPUTE + 1)
49
50 /**
51 * Bitflags for system values.
52 */
53 #define SYSTEM_BIT_SAMPLE_ID ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_ID)
54 #define SYSTEM_BIT_SAMPLE_POS ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_POS)
55 #define SYSTEM_BIT_SAMPLE_MASK_IN ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_MASK_IN)
56 /**
57 * If the gl_register_file is PROGRAM_SYSTEM_VALUE, the register index will be
58 * one of these values. If a NIR variable's mode is nir_var_system_value, it
59 * will be one of these values.
60 */
61 typedef enum
62 {
63 /**
64 * \name Vertex shader system values
65 */
66 /*@{*/
67 /**
68 * OpenGL-style vertex ID.
69 *
70 * Section 2.11.7 (Shader Execution), subsection Shader Inputs, of the
71 * OpenGL 3.3 core profile spec says:
72 *
73 * "gl_VertexID holds the integer index i implicitly passed by
74 * DrawArrays or one of the other drawing commands defined in section
75 * 2.8.3."
76 *
77 * Section 2.8.3 (Drawing Commands) of the same spec says:
78 *
79 * "The commands....are equivalent to the commands with the same base
80 * name (without the BaseVertex suffix), except that the ith element
81 * transferred by the corresponding draw call will be taken from
82 * element indices[i] + basevertex of each enabled array."
83 *
84 * Additionally, the overview in the GL_ARB_shader_draw_parameters spec
85 * says:
86 *
87 * "In unextended GL, vertex shaders have inputs named gl_VertexID and
88 * gl_InstanceID, which contain, respectively the index of the vertex
89 * and instance. The value of gl_VertexID is the implicitly passed
90 * index of the vertex being processed, which includes the value of
91 * baseVertex, for those commands that accept it."
92 *
93 * gl_VertexID gets basevertex added in. This differs from DirectX where
94 * SV_VertexID does \b not get basevertex added in.
95 *
96 * \note
97 * If all system values are available, \c SYSTEM_VALUE_VERTEX_ID will be
98 * equal to \c SYSTEM_VALUE_VERTEX_ID_ZERO_BASE plus
99 * \c SYSTEM_VALUE_BASE_VERTEX.
100 *
101 * \sa SYSTEM_VALUE_VERTEX_ID_ZERO_BASE, SYSTEM_VALUE_BASE_VERTEX
102 */
103 SYSTEM_VALUE_VERTEX_ID,
104
105 /**
106 * Instanced ID as supplied to gl_InstanceID
107 *
108 * Values assigned to gl_InstanceID always begin with zero, regardless of
109 * the value of baseinstance.
110 *
111 * Section 11.1.3.9 (Shader Inputs) of the OpenGL 4.4 core profile spec
112 * says:
113 *
114 * "gl_InstanceID holds the integer instance number of the current
115 * primitive in an instanced draw call (see section 10.5)."
116 *
117 * Through a big chain of pseudocode, section 10.5 describes that
118 * baseinstance is not counted by gl_InstanceID. In that section, notice
119 *
120 * "If an enabled vertex attribute array is instanced (it has a
121 * non-zero divisor as specified by VertexAttribDivisor), the element
122 * index that is transferred to the GL, for all vertices, is given by
123 *
124 * floor(instance/divisor) + baseinstance
125 *
126 * If an array corresponding to an attribute required by a vertex
127 * shader is not enabled, then the corresponding element is taken from
128 * the current attribute state (see section 10.2)."
129 *
130 * Note that baseinstance is \b not included in the value of instance.
131 */
132 SYSTEM_VALUE_INSTANCE_ID,
133
134 /**
135 * DirectX-style vertex ID.
136 *
137 * Unlike \c SYSTEM_VALUE_VERTEX_ID, this system value does \b not include
138 * the value of basevertex.
139 *
140 * \sa SYSTEM_VALUE_VERTEX_ID, SYSTEM_VALUE_BASE_VERTEX
141 */
142 SYSTEM_VALUE_VERTEX_ID_ZERO_BASE,
143
144 /**
145 * Value of \c basevertex passed to \c glDrawElementsBaseVertex and similar
146 * functions.
147 *
148 * \sa SYSTEM_VALUE_VERTEX_ID, SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
149 */
150 SYSTEM_VALUE_BASE_VERTEX,
151 /*@}*/
152
153 /**
154 * \name Geometry shader system values
155 */
156 /*@{*/
157 SYSTEM_VALUE_INVOCATION_ID, /**< (Also in Tessellation Control shader) */
158 /*@}*/
159
160 /**
161 * \name Fragment shader system values
162 */
163 /*@{*/
164 SYSTEM_VALUE_FRONT_FACE, /**< (not done yet) */
165 SYSTEM_VALUE_SAMPLE_ID,
166 SYSTEM_VALUE_SAMPLE_POS,
167 SYSTEM_VALUE_SAMPLE_MASK_IN,
168 /*@}*/
169
170 /**
171 * \name Tessellation Evaluation shader system values
172 */
173 /*@{*/
174 SYSTEM_VALUE_TESS_COORD,
175 SYSTEM_VALUE_VERTICES_IN, /**< Tessellation vertices in input patch */
176 SYSTEM_VALUE_PRIMITIVE_ID, /**< (currently not used by GS) */
177 SYSTEM_VALUE_TESS_LEVEL_OUTER, /**< TES input */
178 SYSTEM_VALUE_TESS_LEVEL_INNER, /**< TES input */
179 /*@}*/
180
181 SYSTEM_VALUE_MAX /**< Number of values */
182 } gl_system_value;
183
184
185 /**
186 * The possible interpolation qualifiers that can be applied to a fragment
187 * shader input in GLSL.
188 *
189 * Note: INTERP_QUALIFIER_NONE must be 0 so that memsetting the
190 * gl_fragment_program data structure to 0 causes the default behavior.
191 */
192 enum glsl_interp_qualifier
193 {
194 INTERP_QUALIFIER_NONE = 0,
195 INTERP_QUALIFIER_SMOOTH,
196 INTERP_QUALIFIER_FLAT,
197 INTERP_QUALIFIER_NOPERSPECTIVE,
198 INTERP_QUALIFIER_COUNT /**< Number of interpolation qualifiers */
199 };
200
201
202 /**
203 * Indexes for vertex program attributes.
204 * GL_NV_vertex_program aliases generic attributes over the conventional
205 * attributes. In GL_ARB_vertex_program shader the aliasing is optional.
206 * In GL_ARB_vertex_shader / OpenGL 2.0 the aliasing is disallowed (the
207 * generic attributes are distinct/separate).
208 */
209 typedef enum
210 {
211 VERT_ATTRIB_POS = 0,
212 VERT_ATTRIB_WEIGHT = 1,
213 VERT_ATTRIB_NORMAL = 2,
214 VERT_ATTRIB_COLOR0 = 3,
215 VERT_ATTRIB_COLOR1 = 4,
216 VERT_ATTRIB_FOG = 5,
217 VERT_ATTRIB_COLOR_INDEX = 6,
218 VERT_ATTRIB_EDGEFLAG = 7,
219 VERT_ATTRIB_TEX0 = 8,
220 VERT_ATTRIB_TEX1 = 9,
221 VERT_ATTRIB_TEX2 = 10,
222 VERT_ATTRIB_TEX3 = 11,
223 VERT_ATTRIB_TEX4 = 12,
224 VERT_ATTRIB_TEX5 = 13,
225 VERT_ATTRIB_TEX6 = 14,
226 VERT_ATTRIB_TEX7 = 15,
227 VERT_ATTRIB_POINT_SIZE = 16,
228 VERT_ATTRIB_GENERIC0 = 17,
229 VERT_ATTRIB_GENERIC1 = 18,
230 VERT_ATTRIB_GENERIC2 = 19,
231 VERT_ATTRIB_GENERIC3 = 20,
232 VERT_ATTRIB_GENERIC4 = 21,
233 VERT_ATTRIB_GENERIC5 = 22,
234 VERT_ATTRIB_GENERIC6 = 23,
235 VERT_ATTRIB_GENERIC7 = 24,
236 VERT_ATTRIB_GENERIC8 = 25,
237 VERT_ATTRIB_GENERIC9 = 26,
238 VERT_ATTRIB_GENERIC10 = 27,
239 VERT_ATTRIB_GENERIC11 = 28,
240 VERT_ATTRIB_GENERIC12 = 29,
241 VERT_ATTRIB_GENERIC13 = 30,
242 VERT_ATTRIB_GENERIC14 = 31,
243 VERT_ATTRIB_GENERIC15 = 32,
244 VERT_ATTRIB_MAX = 33
245 } gl_vert_attrib;
246
247 /**
248 * Symbolic constats to help iterating over
249 * specific blocks of vertex attributes.
250 *
251 * VERT_ATTRIB_FF
252 * includes all fixed function attributes as well as
253 * the aliased GL_NV_vertex_program shader attributes.
254 * VERT_ATTRIB_TEX
255 * include the classic texture coordinate attributes.
256 * Is a subset of VERT_ATTRIB_FF.
257 * VERT_ATTRIB_GENERIC
258 * include the OpenGL 2.0+ GLSL generic shader attributes.
259 * These alias the generic GL_ARB_vertex_shader attributes.
260 */
261 #define VERT_ATTRIB_FF(i) (VERT_ATTRIB_POS + (i))
262 #define VERT_ATTRIB_FF_MAX VERT_ATTRIB_GENERIC0
263
264 #define VERT_ATTRIB_TEX(i) (VERT_ATTRIB_TEX0 + (i))
265 #define VERT_ATTRIB_TEX_MAX MAX_TEXTURE_COORD_UNITS
266
267 #define VERT_ATTRIB_GENERIC(i) (VERT_ATTRIB_GENERIC0 + (i))
268 #define VERT_ATTRIB_GENERIC_MAX MAX_VERTEX_GENERIC_ATTRIBS
269
270 /**
271 * Bitflags for vertex attributes.
272 * These are used in bitfields in many places.
273 */
274 /*@{*/
275 #define VERT_BIT_POS BITFIELD64_BIT(VERT_ATTRIB_POS)
276 #define VERT_BIT_WEIGHT BITFIELD64_BIT(VERT_ATTRIB_WEIGHT)
277 #define VERT_BIT_NORMAL BITFIELD64_BIT(VERT_ATTRIB_NORMAL)
278 #define VERT_BIT_COLOR0 BITFIELD64_BIT(VERT_ATTRIB_COLOR0)
279 #define VERT_BIT_COLOR1 BITFIELD64_BIT(VERT_ATTRIB_COLOR1)
280 #define VERT_BIT_FOG BITFIELD64_BIT(VERT_ATTRIB_FOG)
281 #define VERT_BIT_COLOR_INDEX BITFIELD64_BIT(VERT_ATTRIB_COLOR_INDEX)
282 #define VERT_BIT_EDGEFLAG BITFIELD64_BIT(VERT_ATTRIB_EDGEFLAG)
283 #define VERT_BIT_TEX0 BITFIELD64_BIT(VERT_ATTRIB_TEX0)
284 #define VERT_BIT_TEX1 BITFIELD64_BIT(VERT_ATTRIB_TEX1)
285 #define VERT_BIT_TEX2 BITFIELD64_BIT(VERT_ATTRIB_TEX2)
286 #define VERT_BIT_TEX3 BITFIELD64_BIT(VERT_ATTRIB_TEX3)
287 #define VERT_BIT_TEX4 BITFIELD64_BIT(VERT_ATTRIB_TEX4)
288 #define VERT_BIT_TEX5 BITFIELD64_BIT(VERT_ATTRIB_TEX5)
289 #define VERT_BIT_TEX6 BITFIELD64_BIT(VERT_ATTRIB_TEX6)
290 #define VERT_BIT_TEX7 BITFIELD64_BIT(VERT_ATTRIB_TEX7)
291 #define VERT_BIT_POINT_SIZE BITFIELD64_BIT(VERT_ATTRIB_POINT_SIZE)
292 #define VERT_BIT_GENERIC0 BITFIELD64_BIT(VERT_ATTRIB_GENERIC0)
293
294 #define VERT_BIT(i) BITFIELD64_BIT(i)
295 #define VERT_BIT_ALL BITFIELD64_RANGE(0, VERT_ATTRIB_MAX)
296
297 #define VERT_BIT_FF(i) VERT_BIT(i)
298 #define VERT_BIT_FF_ALL BITFIELD64_RANGE(0, VERT_ATTRIB_FF_MAX)
299 #define VERT_BIT_TEX(i) VERT_BIT(VERT_ATTRIB_TEX(i))
300 #define VERT_BIT_TEX_ALL \
301 BITFIELD64_RANGE(VERT_ATTRIB_TEX(0), VERT_ATTRIB_TEX_MAX)
302
303 #define VERT_BIT_GENERIC(i) VERT_BIT(VERT_ATTRIB_GENERIC(i))
304 #define VERT_BIT_GENERIC_ALL \
305 BITFIELD64_RANGE(VERT_ATTRIB_GENERIC(0), VERT_ATTRIB_GENERIC_MAX)
306 /*@}*/
307
308
309 /**
310 * Indexes for vertex shader outputs, geometry shader inputs/outputs, and
311 * fragment shader inputs.
312 *
313 * Note that some of these values are not available to all pipeline stages.
314 *
315 * When this enum is updated, the following code must be updated too:
316 * - vertResults (in prog_print.c's arb_output_attrib_string())
317 * - fragAttribs (in prog_print.c's arb_input_attrib_string())
318 * - _mesa_varying_slot_in_fs()
319 */
320 typedef enum
321 {
322 VARYING_SLOT_POS,
323 VARYING_SLOT_COL0, /* COL0 and COL1 must be contiguous */
324 VARYING_SLOT_COL1,
325 VARYING_SLOT_FOGC,
326 VARYING_SLOT_TEX0, /* TEX0-TEX7 must be contiguous */
327 VARYING_SLOT_TEX1,
328 VARYING_SLOT_TEX2,
329 VARYING_SLOT_TEX3,
330 VARYING_SLOT_TEX4,
331 VARYING_SLOT_TEX5,
332 VARYING_SLOT_TEX6,
333 VARYING_SLOT_TEX7,
334 VARYING_SLOT_PSIZ, /* Does not appear in FS */
335 VARYING_SLOT_BFC0, /* Does not appear in FS */
336 VARYING_SLOT_BFC1, /* Does not appear in FS */
337 VARYING_SLOT_EDGE, /* Does not appear in FS */
338 VARYING_SLOT_CLIP_VERTEX, /* Does not appear in FS */
339 VARYING_SLOT_CLIP_DIST0,
340 VARYING_SLOT_CLIP_DIST1,
341 VARYING_SLOT_PRIMITIVE_ID, /* Does not appear in VS */
342 VARYING_SLOT_LAYER, /* Appears as VS or GS output */
343 VARYING_SLOT_VIEWPORT, /* Appears as VS or GS output */
344 VARYING_SLOT_FACE, /* FS only */
345 VARYING_SLOT_PNTC, /* FS only */
346 VARYING_SLOT_TESS_LEVEL_OUTER, /* Only appears as TCS output. */
347 VARYING_SLOT_TESS_LEVEL_INNER, /* Only appears as TCS output. */
348 VARYING_SLOT_VAR0, /* First generic varying slot */
349 VARYING_SLOT_MAX = VARYING_SLOT_VAR0 + MAX_VARYING,
350 VARYING_SLOT_PATCH0 = VARYING_SLOT_MAX,
351 VARYING_SLOT_TESS_MAX = VARYING_SLOT_PATCH0 + MAX_VARYING
352 } gl_varying_slot;
353
354
355 /**
356 * Bitflags for varying slots.
357 */
358 /*@{*/
359 #define VARYING_BIT_POS BITFIELD64_BIT(VARYING_SLOT_POS)
360 #define VARYING_BIT_COL0 BITFIELD64_BIT(VARYING_SLOT_COL0)
361 #define VARYING_BIT_COL1 BITFIELD64_BIT(VARYING_SLOT_COL1)
362 #define VARYING_BIT_FOGC BITFIELD64_BIT(VARYING_SLOT_FOGC)
363 #define VARYING_BIT_TEX0 BITFIELD64_BIT(VARYING_SLOT_TEX0)
364 #define VARYING_BIT_TEX1 BITFIELD64_BIT(VARYING_SLOT_TEX1)
365 #define VARYING_BIT_TEX2 BITFIELD64_BIT(VARYING_SLOT_TEX2)
366 #define VARYING_BIT_TEX3 BITFIELD64_BIT(VARYING_SLOT_TEX3)
367 #define VARYING_BIT_TEX4 BITFIELD64_BIT(VARYING_SLOT_TEX4)
368 #define VARYING_BIT_TEX5 BITFIELD64_BIT(VARYING_SLOT_TEX5)
369 #define VARYING_BIT_TEX6 BITFIELD64_BIT(VARYING_SLOT_TEX6)
370 #define VARYING_BIT_TEX7 BITFIELD64_BIT(VARYING_SLOT_TEX7)
371 #define VARYING_BIT_TEX(U) BITFIELD64_BIT(VARYING_SLOT_TEX0 + (U))
372 #define VARYING_BITS_TEX_ANY BITFIELD64_RANGE(VARYING_SLOT_TEX0, \
373 MAX_TEXTURE_COORD_UNITS)
374 #define VARYING_BIT_PSIZ BITFIELD64_BIT(VARYING_SLOT_PSIZ)
375 #define VARYING_BIT_BFC0 BITFIELD64_BIT(VARYING_SLOT_BFC0)
376 #define VARYING_BIT_BFC1 BITFIELD64_BIT(VARYING_SLOT_BFC1)
377 #define VARYING_BIT_EDGE BITFIELD64_BIT(VARYING_SLOT_EDGE)
378 #define VARYING_BIT_CLIP_VERTEX BITFIELD64_BIT(VARYING_SLOT_CLIP_VERTEX)
379 #define VARYING_BIT_CLIP_DIST0 BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST0)
380 #define VARYING_BIT_CLIP_DIST1 BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST1)
381 #define VARYING_BIT_PRIMITIVE_ID BITFIELD64_BIT(VARYING_SLOT_PRIMITIVE_ID)
382 #define VARYING_BIT_LAYER BITFIELD64_BIT(VARYING_SLOT_LAYER)
383 #define VARYING_BIT_VIEWPORT BITFIELD64_BIT(VARYING_SLOT_VIEWPORT)
384 #define VARYING_BIT_FACE BITFIELD64_BIT(VARYING_SLOT_FACE)
385 #define VARYING_BIT_PNTC BITFIELD64_BIT(VARYING_SLOT_PNTC)
386 #define VARYING_BIT_VAR(V) BITFIELD64_BIT(VARYING_SLOT_VAR0 + (V))
387 /*@}*/
388
389
390 /**
391 * Fragment program results
392 */
393 typedef enum
394 {
395 FRAG_RESULT_DEPTH = 0,
396 FRAG_RESULT_STENCIL = 1,
397 /* If a single color should be written to all render targets, this
398 * register is written. No FRAG_RESULT_DATAn will be written.
399 */
400 FRAG_RESULT_COLOR = 2,
401 FRAG_RESULT_SAMPLE_MASK = 3,
402
403 /* FRAG_RESULT_DATAn are the per-render-target (GLSL gl_FragData[n]
404 * or ARB_fragment_program fragment.color[n]) color results. If
405 * any are written, FRAG_RESULT_COLOR will not be written.
406 */
407 FRAG_RESULT_DATA0 = 4,
408 FRAG_RESULT_MAX = (FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS)
409 } gl_frag_result;
410
411
412 #endif /* SHADER_ENUMS_H */