freedreno/ir3: Improve shader key normalization.
[mesa.git] / src / compiler / 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 #include <stdbool.h>
30
31 /* Project-wide (GL and Vulkan) maximum. */
32 #define MAX_DRAW_BUFFERS 8
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /**
39 * Shader stages.
40 *
41 * The order must match how shaders are ordered in the pipeline.
42 * The GLSL linker assumes that if i<j, then the j-th shader is
43 * executed later than the i-th shader.
44 */
45 typedef enum
46 {
47 MESA_SHADER_NONE = -1,
48 MESA_SHADER_VERTEX = 0,
49 MESA_SHADER_TESS_CTRL = 1,
50 MESA_SHADER_TESS_EVAL = 2,
51 MESA_SHADER_GEOMETRY = 3,
52 MESA_SHADER_FRAGMENT = 4,
53 MESA_SHADER_COMPUTE = 5,
54 /* must be last so it doesn't affect the GL pipeline */
55 MESA_SHADER_KERNEL = 6,
56 } gl_shader_stage;
57
58 static inline bool
59 gl_shader_stage_is_compute(gl_shader_stage stage)
60 {
61 return stage == MESA_SHADER_COMPUTE || stage == MESA_SHADER_KERNEL;
62 }
63
64 /**
65 * Number of STATE_* values we need to address any GL state.
66 * Used to dimension arrays.
67 */
68 #define STATE_LENGTH 5
69
70 typedef short gl_state_index16; /* see enum gl_state_index */
71
72 const char *gl_shader_stage_name(gl_shader_stage stage);
73
74 /**
75 * Translate a gl_shader_stage to a short shader stage name for debug
76 * printouts and error messages.
77 */
78 const char *_mesa_shader_stage_to_string(unsigned stage);
79
80 /**
81 * Translate a gl_shader_stage to a shader stage abbreviation (VS, GS, FS)
82 * for debug printouts and error messages.
83 */
84 const char *_mesa_shader_stage_to_abbrev(unsigned stage);
85
86 /**
87 * GL related stages (not including CL)
88 */
89 #define MESA_SHADER_STAGES (MESA_SHADER_COMPUTE + 1)
90
91 /**
92 * All stages
93 */
94 #define MESA_ALL_SHADER_STAGES (MESA_SHADER_KERNEL + 1)
95
96
97 /**
98 * Indexes for vertex program attributes.
99 * GL_NV_vertex_program aliases generic attributes over the conventional
100 * attributes. In GL_ARB_vertex_program shader the aliasing is optional.
101 * In GL_ARB_vertex_shader / OpenGL 2.0 the aliasing is disallowed (the
102 * generic attributes are distinct/separate).
103 */
104 typedef enum
105 {
106 VERT_ATTRIB_POS,
107 VERT_ATTRIB_NORMAL,
108 VERT_ATTRIB_COLOR0,
109 VERT_ATTRIB_COLOR1,
110 VERT_ATTRIB_FOG,
111 VERT_ATTRIB_COLOR_INDEX,
112 VERT_ATTRIB_EDGEFLAG,
113 VERT_ATTRIB_TEX0,
114 VERT_ATTRIB_TEX1,
115 VERT_ATTRIB_TEX2,
116 VERT_ATTRIB_TEX3,
117 VERT_ATTRIB_TEX4,
118 VERT_ATTRIB_TEX5,
119 VERT_ATTRIB_TEX6,
120 VERT_ATTRIB_TEX7,
121 VERT_ATTRIB_POINT_SIZE,
122 VERT_ATTRIB_GENERIC0,
123 VERT_ATTRIB_GENERIC1,
124 VERT_ATTRIB_GENERIC2,
125 VERT_ATTRIB_GENERIC3,
126 VERT_ATTRIB_GENERIC4,
127 VERT_ATTRIB_GENERIC5,
128 VERT_ATTRIB_GENERIC6,
129 VERT_ATTRIB_GENERIC7,
130 VERT_ATTRIB_GENERIC8,
131 VERT_ATTRIB_GENERIC9,
132 VERT_ATTRIB_GENERIC10,
133 VERT_ATTRIB_GENERIC11,
134 VERT_ATTRIB_GENERIC12,
135 VERT_ATTRIB_GENERIC13,
136 VERT_ATTRIB_GENERIC14,
137 VERT_ATTRIB_GENERIC15,
138 VERT_ATTRIB_MAX
139 } gl_vert_attrib;
140
141 const char *gl_vert_attrib_name(gl_vert_attrib attrib);
142
143 /**
144 * Symbolic constats to help iterating over
145 * specific blocks of vertex attributes.
146 *
147 * VERT_ATTRIB_FF
148 * includes all fixed function attributes as well as
149 * the aliased GL_NV_vertex_program shader attributes.
150 * VERT_ATTRIB_TEX
151 * include the classic texture coordinate attributes.
152 * Is a subset of VERT_ATTRIB_FF.
153 * VERT_ATTRIB_GENERIC
154 * include the OpenGL 2.0+ GLSL generic shader attributes.
155 * These alias the generic GL_ARB_vertex_shader attributes.
156 * VERT_ATTRIB_MAT
157 * include the generic shader attributes used to alias
158 * varying material values for the TNL shader programs.
159 * They are located at the end of the generic attribute
160 * block not to overlap with the generic 0 attribute.
161 */
162 #define VERT_ATTRIB_FF(i) (VERT_ATTRIB_POS + (i))
163 #define VERT_ATTRIB_FF_MAX VERT_ATTRIB_GENERIC0
164
165 #define VERT_ATTRIB_TEX(i) (VERT_ATTRIB_TEX0 + (i))
166 #define VERT_ATTRIB_TEX_MAX MAX_TEXTURE_COORD_UNITS
167
168 #define VERT_ATTRIB_GENERIC(i) (VERT_ATTRIB_GENERIC0 + (i))
169 #define VERT_ATTRIB_GENERIC_MAX MAX_VERTEX_GENERIC_ATTRIBS
170
171 #define VERT_ATTRIB_MAT0 \
172 (VERT_ATTRIB_GENERIC_MAX - VERT_ATTRIB_MAT_MAX)
173 #define VERT_ATTRIB_MAT(i) \
174 VERT_ATTRIB_GENERIC((i) + VERT_ATTRIB_MAT0)
175 #define VERT_ATTRIB_MAT_MAX MAT_ATTRIB_MAX
176
177 /**
178 * Bitflags for vertex attributes.
179 * These are used in bitfields in many places.
180 */
181 /*@{*/
182 #define VERT_BIT_POS BITFIELD_BIT(VERT_ATTRIB_POS)
183 #define VERT_BIT_NORMAL BITFIELD_BIT(VERT_ATTRIB_NORMAL)
184 #define VERT_BIT_COLOR0 BITFIELD_BIT(VERT_ATTRIB_COLOR0)
185 #define VERT_BIT_COLOR1 BITFIELD_BIT(VERT_ATTRIB_COLOR1)
186 #define VERT_BIT_FOG BITFIELD_BIT(VERT_ATTRIB_FOG)
187 #define VERT_BIT_COLOR_INDEX BITFIELD_BIT(VERT_ATTRIB_COLOR_INDEX)
188 #define VERT_BIT_EDGEFLAG BITFIELD_BIT(VERT_ATTRIB_EDGEFLAG)
189 #define VERT_BIT_TEX0 BITFIELD_BIT(VERT_ATTRIB_TEX0)
190 #define VERT_BIT_TEX1 BITFIELD_BIT(VERT_ATTRIB_TEX1)
191 #define VERT_BIT_TEX2 BITFIELD_BIT(VERT_ATTRIB_TEX2)
192 #define VERT_BIT_TEX3 BITFIELD_BIT(VERT_ATTRIB_TEX3)
193 #define VERT_BIT_TEX4 BITFIELD_BIT(VERT_ATTRIB_TEX4)
194 #define VERT_BIT_TEX5 BITFIELD_BIT(VERT_ATTRIB_TEX5)
195 #define VERT_BIT_TEX6 BITFIELD_BIT(VERT_ATTRIB_TEX6)
196 #define VERT_BIT_TEX7 BITFIELD_BIT(VERT_ATTRIB_TEX7)
197 #define VERT_BIT_POINT_SIZE BITFIELD_BIT(VERT_ATTRIB_POINT_SIZE)
198 #define VERT_BIT_GENERIC0 BITFIELD_BIT(VERT_ATTRIB_GENERIC0)
199
200 #define VERT_BIT(i) BITFIELD_BIT(i)
201 #define VERT_BIT_ALL BITFIELD_RANGE(0, VERT_ATTRIB_MAX)
202
203 #define VERT_BIT_FF(i) VERT_BIT(i)
204 #define VERT_BIT_FF_ALL BITFIELD_RANGE(0, VERT_ATTRIB_FF_MAX)
205 #define VERT_BIT_TEX(i) VERT_BIT(VERT_ATTRIB_TEX(i))
206 #define VERT_BIT_TEX_ALL \
207 BITFIELD_RANGE(VERT_ATTRIB_TEX(0), VERT_ATTRIB_TEX_MAX)
208
209 #define VERT_BIT_GENERIC(i) VERT_BIT(VERT_ATTRIB_GENERIC(i))
210 #define VERT_BIT_GENERIC_ALL \
211 BITFIELD_RANGE(VERT_ATTRIB_GENERIC(0), VERT_ATTRIB_GENERIC_MAX)
212
213 #define VERT_BIT_MAT(i) VERT_BIT(VERT_ATTRIB_MAT(i))
214 #define VERT_BIT_MAT_ALL \
215 BITFIELD_RANGE(VERT_ATTRIB_MAT(0), VERT_ATTRIB_MAT_MAX)
216 /*@}*/
217
218 #define MAX_VARYING 32 /**< number of float[4] vectors */
219
220 /**
221 * Indexes for vertex shader outputs, geometry shader inputs/outputs, and
222 * fragment shader inputs.
223 *
224 * Note that some of these values are not available to all pipeline stages.
225 *
226 * When this enum is updated, the following code must be updated too:
227 * - vertResults (in prog_print.c's arb_output_attrib_string())
228 * - fragAttribs (in prog_print.c's arb_input_attrib_string())
229 * - _mesa_varying_slot_in_fs()
230 */
231 typedef enum
232 {
233 VARYING_SLOT_POS,
234 VARYING_SLOT_COL0, /* COL0 and COL1 must be contiguous */
235 VARYING_SLOT_COL1,
236 VARYING_SLOT_FOGC,
237 VARYING_SLOT_TEX0, /* TEX0-TEX7 must be contiguous */
238 VARYING_SLOT_TEX1,
239 VARYING_SLOT_TEX2,
240 VARYING_SLOT_TEX3,
241 VARYING_SLOT_TEX4,
242 VARYING_SLOT_TEX5,
243 VARYING_SLOT_TEX6,
244 VARYING_SLOT_TEX7,
245 VARYING_SLOT_PSIZ, /* Does not appear in FS */
246 VARYING_SLOT_BFC0, /* Does not appear in FS */
247 VARYING_SLOT_BFC1, /* Does not appear in FS */
248 VARYING_SLOT_EDGE, /* Does not appear in FS */
249 VARYING_SLOT_CLIP_VERTEX, /* Does not appear in FS */
250 VARYING_SLOT_CLIP_DIST0,
251 VARYING_SLOT_CLIP_DIST1,
252 VARYING_SLOT_CULL_DIST0,
253 VARYING_SLOT_CULL_DIST1,
254 VARYING_SLOT_PRIMITIVE_ID, /* Does not appear in VS */
255 VARYING_SLOT_LAYER, /* Appears as VS or GS output */
256 VARYING_SLOT_VIEWPORT, /* Appears as VS or GS output */
257 VARYING_SLOT_FACE, /* FS only */
258 VARYING_SLOT_PNTC, /* FS only */
259 VARYING_SLOT_TESS_LEVEL_OUTER, /* Only appears as TCS output. */
260 VARYING_SLOT_TESS_LEVEL_INNER, /* Only appears as TCS output. */
261 VARYING_SLOT_BOUNDING_BOX0, /* Only appears as TCS output. */
262 VARYING_SLOT_BOUNDING_BOX1, /* Only appears as TCS output. */
263 VARYING_SLOT_VIEW_INDEX,
264 VARYING_SLOT_VIEWPORT_MASK, /* Does not appear in FS */
265 VARYING_SLOT_VAR0, /* First generic varying slot */
266 /* the remaining are simply for the benefit of gl_varying_slot_name()
267 * and not to be construed as an upper bound:
268 */
269 VARYING_SLOT_VAR1,
270 VARYING_SLOT_VAR2,
271 VARYING_SLOT_VAR3,
272 VARYING_SLOT_VAR4,
273 VARYING_SLOT_VAR5,
274 VARYING_SLOT_VAR6,
275 VARYING_SLOT_VAR7,
276 VARYING_SLOT_VAR8,
277 VARYING_SLOT_VAR9,
278 VARYING_SLOT_VAR10,
279 VARYING_SLOT_VAR11,
280 VARYING_SLOT_VAR12,
281 VARYING_SLOT_VAR13,
282 VARYING_SLOT_VAR14,
283 VARYING_SLOT_VAR15,
284 VARYING_SLOT_VAR16,
285 VARYING_SLOT_VAR17,
286 VARYING_SLOT_VAR18,
287 VARYING_SLOT_VAR19,
288 VARYING_SLOT_VAR20,
289 VARYING_SLOT_VAR21,
290 VARYING_SLOT_VAR22,
291 VARYING_SLOT_VAR23,
292 VARYING_SLOT_VAR24,
293 VARYING_SLOT_VAR25,
294 VARYING_SLOT_VAR26,
295 VARYING_SLOT_VAR27,
296 VARYING_SLOT_VAR28,
297 VARYING_SLOT_VAR29,
298 VARYING_SLOT_VAR30,
299 VARYING_SLOT_VAR31,
300 } gl_varying_slot;
301
302
303 #define VARYING_SLOT_MAX (VARYING_SLOT_VAR0 + MAX_VARYING)
304 #define VARYING_SLOT_PATCH0 (VARYING_SLOT_MAX)
305 #define VARYING_SLOT_TESS_MAX (VARYING_SLOT_PATCH0 + MAX_VARYING)
306 #define MAX_VARYINGS_INCL_PATCH (VARYING_SLOT_TESS_MAX - VARYING_SLOT_VAR0)
307
308 const char *gl_varying_slot_name(gl_varying_slot slot);
309
310 /**
311 * Bitflags for varying slots.
312 */
313 /*@{*/
314 #define VARYING_BIT_POS BITFIELD64_BIT(VARYING_SLOT_POS)
315 #define VARYING_BIT_COL0 BITFIELD64_BIT(VARYING_SLOT_COL0)
316 #define VARYING_BIT_COL1 BITFIELD64_BIT(VARYING_SLOT_COL1)
317 #define VARYING_BIT_FOGC BITFIELD64_BIT(VARYING_SLOT_FOGC)
318 #define VARYING_BIT_TEX0 BITFIELD64_BIT(VARYING_SLOT_TEX0)
319 #define VARYING_BIT_TEX1 BITFIELD64_BIT(VARYING_SLOT_TEX1)
320 #define VARYING_BIT_TEX2 BITFIELD64_BIT(VARYING_SLOT_TEX2)
321 #define VARYING_BIT_TEX3 BITFIELD64_BIT(VARYING_SLOT_TEX3)
322 #define VARYING_BIT_TEX4 BITFIELD64_BIT(VARYING_SLOT_TEX4)
323 #define VARYING_BIT_TEX5 BITFIELD64_BIT(VARYING_SLOT_TEX5)
324 #define VARYING_BIT_TEX6 BITFIELD64_BIT(VARYING_SLOT_TEX6)
325 #define VARYING_BIT_TEX7 BITFIELD64_BIT(VARYING_SLOT_TEX7)
326 #define VARYING_BIT_TEX(U) BITFIELD64_BIT(VARYING_SLOT_TEX0 + (U))
327 #define VARYING_BITS_TEX_ANY BITFIELD64_RANGE(VARYING_SLOT_TEX0, \
328 MAX_TEXTURE_COORD_UNITS)
329 #define VARYING_BIT_PSIZ BITFIELD64_BIT(VARYING_SLOT_PSIZ)
330 #define VARYING_BIT_BFC0 BITFIELD64_BIT(VARYING_SLOT_BFC0)
331 #define VARYING_BIT_BFC1 BITFIELD64_BIT(VARYING_SLOT_BFC1)
332 #define VARYING_BITS_COLOR (VARYING_BIT_COL0 | \
333 VARYING_BIT_COL1 | \
334 VARYING_BIT_BFC0 | \
335 VARYING_BIT_BFC1)
336 #define VARYING_BIT_EDGE BITFIELD64_BIT(VARYING_SLOT_EDGE)
337 #define VARYING_BIT_CLIP_VERTEX BITFIELD64_BIT(VARYING_SLOT_CLIP_VERTEX)
338 #define VARYING_BIT_CLIP_DIST0 BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST0)
339 #define VARYING_BIT_CLIP_DIST1 BITFIELD64_BIT(VARYING_SLOT_CLIP_DIST1)
340 #define VARYING_BIT_CULL_DIST0 BITFIELD64_BIT(VARYING_SLOT_CULL_DIST0)
341 #define VARYING_BIT_CULL_DIST1 BITFIELD64_BIT(VARYING_SLOT_CULL_DIST1)
342 #define VARYING_BIT_PRIMITIVE_ID BITFIELD64_BIT(VARYING_SLOT_PRIMITIVE_ID)
343 #define VARYING_BIT_LAYER BITFIELD64_BIT(VARYING_SLOT_LAYER)
344 #define VARYING_BIT_VIEWPORT BITFIELD64_BIT(VARYING_SLOT_VIEWPORT)
345 #define VARYING_BIT_FACE BITFIELD64_BIT(VARYING_SLOT_FACE)
346 #define VARYING_BIT_PNTC BITFIELD64_BIT(VARYING_SLOT_PNTC)
347 #define VARYING_BIT_TESS_LEVEL_OUTER BITFIELD64_BIT(VARYING_SLOT_TESS_LEVEL_OUTER)
348 #define VARYING_BIT_TESS_LEVEL_INNER BITFIELD64_BIT(VARYING_SLOT_TESS_LEVEL_INNER)
349 #define VARYING_BIT_BOUNDING_BOX0 BITFIELD64_BIT(VARYING_SLOT_BOUNDING_BOX0)
350 #define VARYING_BIT_BOUNDING_BOX1 BITFIELD64_BIT(VARYING_SLOT_BOUNDING_BOX1)
351 #define VARYING_BIT_VIEWPORT_MASK BITFIELD64_BIT(VARYING_SLOT_VIEWPORT_MASK)
352 #define VARYING_BIT_VAR(V) BITFIELD64_BIT(VARYING_SLOT_VAR0 + (V))
353 /*@}*/
354
355 /**
356 * Bitflags for system values.
357 */
358 #define SYSTEM_BIT_SAMPLE_ID ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_ID)
359 #define SYSTEM_BIT_SAMPLE_POS ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_POS)
360 #define SYSTEM_BIT_SAMPLE_MASK_IN ((uint64_t)1 << SYSTEM_VALUE_SAMPLE_MASK_IN)
361 #define SYSTEM_BIT_LOCAL_INVOCATION_ID ((uint64_t)1 << SYSTEM_VALUE_LOCAL_INVOCATION_ID)
362
363 /**
364 * If the gl_register_file is PROGRAM_SYSTEM_VALUE, the register index will be
365 * one of these values. If a NIR variable's mode is nir_var_system_value, it
366 * will be one of these values.
367 */
368 typedef enum
369 {
370 /**
371 * \name System values applicable to all shaders
372 */
373 /*@{*/
374
375 /**
376 * Builtin variables added by GL_ARB_shader_ballot.
377 */
378 /*@{*/
379
380 /**
381 * From the GL_ARB_shader-ballot spec:
382 *
383 * "A sub-group is a collection of invocations which execute in lockstep.
384 * The variable <gl_SubGroupSizeARB> is the maximum number of
385 * invocations in a sub-group. The maximum <gl_SubGroupSizeARB>
386 * supported in this extension is 64."
387 *
388 * The spec defines this as a uniform. However, it's highly unlikely that
389 * implementations actually treat it as a uniform (which is loaded from a
390 * constant buffer). Most likely, this is an implementation-wide constant,
391 * or perhaps something that depends on the shader stage.
392 */
393 SYSTEM_VALUE_SUBGROUP_SIZE,
394
395 /**
396 * From the GL_ARB_shader_ballot spec:
397 *
398 * "The variable <gl_SubGroupInvocationARB> holds the index of the
399 * invocation within sub-group. This variable is in the range 0 to
400 * <gl_SubGroupSizeARB>-1, where <gl_SubGroupSizeARB> is the total
401 * number of invocations in a sub-group."
402 */
403 SYSTEM_VALUE_SUBGROUP_INVOCATION,
404
405 /**
406 * From the GL_ARB_shader_ballot spec:
407 *
408 * "The <gl_SubGroup??MaskARB> variables provide a bitmask for all
409 * invocations, with one bit per invocation starting with the least
410 * significant bit, according to the following table,
411 *
412 * variable equation for bit values
413 * -------------------- ------------------------------------
414 * gl_SubGroupEqMaskARB bit index == gl_SubGroupInvocationARB
415 * gl_SubGroupGeMaskARB bit index >= gl_SubGroupInvocationARB
416 * gl_SubGroupGtMaskARB bit index > gl_SubGroupInvocationARB
417 * gl_SubGroupLeMaskARB bit index <= gl_SubGroupInvocationARB
418 * gl_SubGroupLtMaskARB bit index < gl_SubGroupInvocationARB
419 */
420 SYSTEM_VALUE_SUBGROUP_EQ_MASK,
421 SYSTEM_VALUE_SUBGROUP_GE_MASK,
422 SYSTEM_VALUE_SUBGROUP_GT_MASK,
423 SYSTEM_VALUE_SUBGROUP_LE_MASK,
424 SYSTEM_VALUE_SUBGROUP_LT_MASK,
425 /*@}*/
426
427 /**
428 * Builtin variables added by VK_KHR_subgroups
429 */
430 /*@{*/
431 SYSTEM_VALUE_NUM_SUBGROUPS,
432 SYSTEM_VALUE_SUBGROUP_ID,
433 /*@}*/
434
435 /*@}*/
436
437 /**
438 * \name Vertex shader system values
439 */
440 /*@{*/
441 /**
442 * OpenGL-style vertex ID.
443 *
444 * Section 2.11.7 (Shader Execution), subsection Shader Inputs, of the
445 * OpenGL 3.3 core profile spec says:
446 *
447 * "gl_VertexID holds the integer index i implicitly passed by
448 * DrawArrays or one of the other drawing commands defined in section
449 * 2.8.3."
450 *
451 * Section 2.8.3 (Drawing Commands) of the same spec says:
452 *
453 * "The commands....are equivalent to the commands with the same base
454 * name (without the BaseVertex suffix), except that the ith element
455 * transferred by the corresponding draw call will be taken from
456 * element indices[i] + basevertex of each enabled array."
457 *
458 * Additionally, the overview in the GL_ARB_shader_draw_parameters spec
459 * says:
460 *
461 * "In unextended GL, vertex shaders have inputs named gl_VertexID and
462 * gl_InstanceID, which contain, respectively the index of the vertex
463 * and instance. The value of gl_VertexID is the implicitly passed
464 * index of the vertex being processed, which includes the value of
465 * baseVertex, for those commands that accept it."
466 *
467 * gl_VertexID gets basevertex added in. This differs from DirectX where
468 * SV_VertexID does \b not get basevertex added in.
469 *
470 * \note
471 * If all system values are available, \c SYSTEM_VALUE_VERTEX_ID will be
472 * equal to \c SYSTEM_VALUE_VERTEX_ID_ZERO_BASE plus
473 * \c SYSTEM_VALUE_BASE_VERTEX.
474 *
475 * \sa SYSTEM_VALUE_VERTEX_ID_ZERO_BASE, SYSTEM_VALUE_BASE_VERTEX
476 */
477 SYSTEM_VALUE_VERTEX_ID,
478
479 /**
480 * Instanced ID as supplied to gl_InstanceID
481 *
482 * Values assigned to gl_InstanceID always begin with zero, regardless of
483 * the value of baseinstance.
484 *
485 * Section 11.1.3.9 (Shader Inputs) of the OpenGL 4.4 core profile spec
486 * says:
487 *
488 * "gl_InstanceID holds the integer instance number of the current
489 * primitive in an instanced draw call (see section 10.5)."
490 *
491 * Through a big chain of pseudocode, section 10.5 describes that
492 * baseinstance is not counted by gl_InstanceID. In that section, notice
493 *
494 * "If an enabled vertex attribute array is instanced (it has a
495 * non-zero divisor as specified by VertexAttribDivisor), the element
496 * index that is transferred to the GL, for all vertices, is given by
497 *
498 * floor(instance/divisor) + baseinstance
499 *
500 * If an array corresponding to an attribute required by a vertex
501 * shader is not enabled, then the corresponding element is taken from
502 * the current attribute state (see section 10.2)."
503 *
504 * Note that baseinstance is \b not included in the value of instance.
505 */
506 SYSTEM_VALUE_INSTANCE_ID,
507
508 /**
509 * Vulkan InstanceIndex.
510 *
511 * InstanceIndex = gl_InstanceID + gl_BaseInstance
512 */
513 SYSTEM_VALUE_INSTANCE_INDEX,
514
515 /**
516 * DirectX-style vertex ID.
517 *
518 * Unlike \c SYSTEM_VALUE_VERTEX_ID, this system value does \b not include
519 * the value of basevertex.
520 *
521 * \sa SYSTEM_VALUE_VERTEX_ID, SYSTEM_VALUE_BASE_VERTEX
522 */
523 SYSTEM_VALUE_VERTEX_ID_ZERO_BASE,
524
525 /**
526 * Value of \c basevertex passed to \c glDrawElementsBaseVertex and similar
527 * functions.
528 *
529 * \sa SYSTEM_VALUE_VERTEX_ID, SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
530 */
531 SYSTEM_VALUE_BASE_VERTEX,
532
533 /**
534 * Depending on the type of the draw call (indexed or non-indexed),
535 * is the value of \c basevertex passed to \c glDrawElementsBaseVertex and
536 * similar, or is the value of \c first passed to \c glDrawArrays and
537 * similar.
538 *
539 * \note
540 * It can be used to calculate the \c SYSTEM_VALUE_VERTEX_ID as
541 * \c SYSTEM_VALUE_VERTEX_ID_ZERO_BASE plus \c SYSTEM_VALUE_FIRST_VERTEX.
542 *
543 * \sa SYSTEM_VALUE_VERTEX_ID_ZERO_BASE, SYSTEM_VALUE_VERTEX_ID
544 */
545 SYSTEM_VALUE_FIRST_VERTEX,
546
547 /**
548 * If the Draw command used to start the rendering was an indexed draw
549 * or not (~0/0). Useful to calculate \c SYSTEM_VALUE_BASE_VERTEX as
550 * \c SYSTEM_VALUE_IS_INDEXED_DRAW & \c SYSTEM_VALUE_FIRST_VERTEX.
551 */
552 SYSTEM_VALUE_IS_INDEXED_DRAW,
553
554 /**
555 * Value of \c baseinstance passed to instanced draw entry points
556 *
557 * \sa SYSTEM_VALUE_INSTANCE_ID
558 */
559 SYSTEM_VALUE_BASE_INSTANCE,
560
561 /**
562 * From _ARB_shader_draw_parameters:
563 *
564 * "Additionally, this extension adds a further built-in variable,
565 * gl_DrawID to the shading language. This variable contains the index
566 * of the draw currently being processed by a Multi* variant of a
567 * drawing command (such as MultiDrawElements or
568 * MultiDrawArraysIndirect)."
569 *
570 * If GL_ARB_multi_draw_indirect is not supported, this is always 0.
571 */
572 SYSTEM_VALUE_DRAW_ID,
573 /*@}*/
574
575 /**
576 * \name Geometry shader system values
577 */
578 /*@{*/
579 SYSTEM_VALUE_INVOCATION_ID, /**< (Also in Tessellation Control shader) */
580 /*@}*/
581
582 /**
583 * \name Fragment shader system values
584 */
585 /*@{*/
586 SYSTEM_VALUE_FRAG_COORD,
587 SYSTEM_VALUE_POINT_COORD,
588 SYSTEM_VALUE_FRONT_FACE,
589 SYSTEM_VALUE_SAMPLE_ID,
590 SYSTEM_VALUE_SAMPLE_POS,
591 SYSTEM_VALUE_SAMPLE_MASK_IN,
592 SYSTEM_VALUE_HELPER_INVOCATION,
593 SYSTEM_VALUE_COLOR0,
594 SYSTEM_VALUE_COLOR1,
595 /*@}*/
596
597 /**
598 * \name Tessellation Evaluation shader system values
599 */
600 /*@{*/
601 SYSTEM_VALUE_TESS_COORD,
602 SYSTEM_VALUE_VERTICES_IN, /**< Tessellation vertices in input patch */
603 SYSTEM_VALUE_PRIMITIVE_ID,
604 SYSTEM_VALUE_TESS_LEVEL_OUTER, /**< TES input */
605 SYSTEM_VALUE_TESS_LEVEL_INNER, /**< TES input */
606 SYSTEM_VALUE_TESS_LEVEL_OUTER_DEFAULT, /**< TCS input for passthru TCS */
607 SYSTEM_VALUE_TESS_LEVEL_INNER_DEFAULT, /**< TCS input for passthru TCS */
608 /*@}*/
609
610 /**
611 * \name Compute shader system values
612 */
613 /*@{*/
614 SYSTEM_VALUE_LOCAL_INVOCATION_ID,
615 SYSTEM_VALUE_LOCAL_INVOCATION_INDEX,
616 SYSTEM_VALUE_GLOBAL_INVOCATION_ID,
617 SYSTEM_VALUE_GLOBAL_INVOCATION_INDEX,
618 SYSTEM_VALUE_WORK_GROUP_ID,
619 SYSTEM_VALUE_NUM_WORK_GROUPS,
620 SYSTEM_VALUE_LOCAL_GROUP_SIZE,
621 SYSTEM_VALUE_GLOBAL_GROUP_SIZE,
622 SYSTEM_VALUE_WORK_DIM,
623 SYSTEM_VALUE_USER_DATA_AMD,
624 /*@}*/
625
626 /** Required for VK_KHR_device_group */
627 SYSTEM_VALUE_DEVICE_INDEX,
628
629 /** Required for VK_KHX_multiview */
630 SYSTEM_VALUE_VIEW_INDEX,
631
632 /**
633 * Driver internal vertex-count, used (for example) for drivers to
634 * calculate stride for stream-out outputs. Not externally visible.
635 */
636 SYSTEM_VALUE_VERTEX_CNT,
637
638 /**
639 * Required for AMD_shader_explicit_vertex_parameter and also used for
640 * varying-fetch instructions.
641 *
642 * The _SIZE value is "primitive size", used to scale i/j in primitive
643 * space to pixel space.
644 */
645 SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL,
646 SYSTEM_VALUE_BARYCENTRIC_PERSP_SAMPLE,
647 SYSTEM_VALUE_BARYCENTRIC_PERSP_CENTROID,
648 SYSTEM_VALUE_BARYCENTRIC_PERSP_SIZE,
649 SYSTEM_VALUE_BARYCENTRIC_LINEAR_PIXEL,
650 SYSTEM_VALUE_BARYCENTRIC_LINEAR_CENTROID,
651 SYSTEM_VALUE_BARYCENTRIC_LINEAR_SAMPLE,
652 SYSTEM_VALUE_BARYCENTRIC_PULL_MODEL,
653
654 /**
655 * IR3 specific geometry shader and tesselation control shader system
656 * values that packs invocation id, thread id and vertex id. Having this
657 * as a nir level system value lets us do the unpacking in nir.
658 */
659 SYSTEM_VALUE_GS_HEADER_IR3,
660 SYSTEM_VALUE_TCS_HEADER_IR3,
661
662 SYSTEM_VALUE_MAX /**< Number of values */
663 } gl_system_value;
664
665 const char *gl_system_value_name(gl_system_value sysval);
666
667 /**
668 * The possible interpolation qualifiers that can be applied to a fragment
669 * shader input in GLSL.
670 *
671 * Note: INTERP_MODE_NONE must be 0 so that memsetting the
672 * ir_variable data structure to 0 causes the default behavior.
673 */
674 enum glsl_interp_mode
675 {
676 INTERP_MODE_NONE = 0,
677 INTERP_MODE_SMOOTH,
678 INTERP_MODE_FLAT,
679 INTERP_MODE_NOPERSPECTIVE,
680 INTERP_MODE_EXPLICIT,
681 INTERP_MODE_COUNT /**< Number of interpolation qualifiers */
682 };
683
684 enum glsl_interface_packing {
685 GLSL_INTERFACE_PACKING_STD140,
686 GLSL_INTERFACE_PACKING_SHARED,
687 GLSL_INTERFACE_PACKING_PACKED,
688 GLSL_INTERFACE_PACKING_STD430
689 };
690
691 const char *glsl_interp_mode_name(enum glsl_interp_mode qual);
692
693 /**
694 * Fragment program results
695 */
696 typedef enum
697 {
698 FRAG_RESULT_DEPTH = 0,
699 FRAG_RESULT_STENCIL = 1,
700 /* If a single color should be written to all render targets, this
701 * register is written. No FRAG_RESULT_DATAn will be written.
702 */
703 FRAG_RESULT_COLOR = 2,
704 FRAG_RESULT_SAMPLE_MASK = 3,
705
706 /* FRAG_RESULT_DATAn are the per-render-target (GLSL gl_FragData[n]
707 * or ARB_fragment_program fragment.color[n]) color results. If
708 * any are written, FRAG_RESULT_COLOR will not be written.
709 * FRAG_RESULT_DATA1 and up are simply for the benefit of
710 * gl_frag_result_name() and not to be construed as an upper bound
711 */
712 FRAG_RESULT_DATA0 = 4,
713 FRAG_RESULT_DATA1,
714 FRAG_RESULT_DATA2,
715 FRAG_RESULT_DATA3,
716 FRAG_RESULT_DATA4,
717 FRAG_RESULT_DATA5,
718 FRAG_RESULT_DATA6,
719 FRAG_RESULT_DATA7,
720 } gl_frag_result;
721
722 const char *gl_frag_result_name(gl_frag_result result);
723
724 #define FRAG_RESULT_MAX (FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS)
725
726 /**
727 * \brief Layout qualifiers for gl_FragDepth.
728 *
729 * Extension AMD_conservative_depth allows gl_FragDepth to be redeclared with
730 * a layout qualifier.
731 *
732 * \see enum ir_depth_layout
733 */
734 enum gl_frag_depth_layout
735 {
736 FRAG_DEPTH_LAYOUT_NONE, /**< No layout is specified. */
737 FRAG_DEPTH_LAYOUT_ANY,
738 FRAG_DEPTH_LAYOUT_GREATER,
739 FRAG_DEPTH_LAYOUT_LESS,
740 FRAG_DEPTH_LAYOUT_UNCHANGED
741 };
742
743 /**
744 * \brief Buffer access qualifiers
745 */
746 enum gl_access_qualifier
747 {
748 ACCESS_COHERENT = (1 << 0),
749 ACCESS_RESTRICT = (1 << 1),
750 ACCESS_VOLATILE = (1 << 2),
751 ACCESS_NON_READABLE = (1 << 3),
752 ACCESS_NON_WRITEABLE = (1 << 4),
753
754 /** The access may use a non-uniform buffer or image index */
755 ACCESS_NON_UNIFORM = (1 << 5),
756
757 /* This has the same semantics as NIR_INTRINSIC_CAN_REORDER, only to be
758 * used with loads. In other words, it means that the load can be
759 * arbitrarily reordered, or combined with other loads to the same address.
760 * It is implied by ACCESS_NON_WRITEABLE together with ACCESS_RESTRICT, and
761 * a lack of ACCESS_COHERENT and ACCESS_VOLATILE.
762 */
763 ACCESS_CAN_REORDER = (1 << 6),
764
765 /** Use as little cache space as possible. */
766 ACCESS_STREAM_CACHE_POLICY = (1 << 7),
767 };
768
769 /**
770 * \brief Blend support qualifiers
771 */
772 enum gl_advanced_blend_mode
773 {
774 BLEND_NONE = 0x0000,
775
776 BLEND_MULTIPLY = 0x0001,
777 BLEND_SCREEN = 0x0002,
778 BLEND_OVERLAY = 0x0004,
779 BLEND_DARKEN = 0x0008,
780 BLEND_LIGHTEN = 0x0010,
781 BLEND_COLORDODGE = 0x0020,
782 BLEND_COLORBURN = 0x0040,
783 BLEND_HARDLIGHT = 0x0080,
784 BLEND_SOFTLIGHT = 0x0100,
785 BLEND_DIFFERENCE = 0x0200,
786 BLEND_EXCLUSION = 0x0400,
787 BLEND_HSL_HUE = 0x0800,
788 BLEND_HSL_SATURATION = 0x1000,
789 BLEND_HSL_COLOR = 0x2000,
790 BLEND_HSL_LUMINOSITY = 0x4000,
791
792 BLEND_ALL = 0x7fff,
793 };
794
795 enum blend_func
796 {
797 BLEND_FUNC_ADD,
798 BLEND_FUNC_SUBTRACT,
799 BLEND_FUNC_REVERSE_SUBTRACT,
800 BLEND_FUNC_MIN,
801 BLEND_FUNC_MAX,
802 };
803
804 enum blend_factor
805 {
806 BLEND_FACTOR_ZERO,
807 BLEND_FACTOR_SRC_COLOR,
808 BLEND_FACTOR_DST_COLOR,
809 BLEND_FACTOR_SRC_ALPHA,
810 BLEND_FACTOR_DST_ALPHA,
811 BLEND_FACTOR_CONSTANT_COLOR,
812 BLEND_FACTOR_CONSTANT_ALPHA,
813 BLEND_FACTOR_SRC_ALPHA_SATURATE,
814 };
815
816 enum gl_tess_spacing
817 {
818 TESS_SPACING_UNSPECIFIED,
819 TESS_SPACING_EQUAL,
820 TESS_SPACING_FRACTIONAL_ODD,
821 TESS_SPACING_FRACTIONAL_EVEN,
822 };
823
824 /**
825 * A compare function enum for use in compiler lowering passes. This is in
826 * the same order as GL's compare functions (shifted down by GL_NEVER), and is
827 * exactly the same as gallium's PIPE_FUNC_*.
828 */
829 enum compare_func
830 {
831 COMPARE_FUNC_NEVER,
832 COMPARE_FUNC_LESS,
833 COMPARE_FUNC_EQUAL,
834 COMPARE_FUNC_LEQUAL,
835 COMPARE_FUNC_GREATER,
836 COMPARE_FUNC_NOTEQUAL,
837 COMPARE_FUNC_GEQUAL,
838 COMPARE_FUNC_ALWAYS,
839 };
840
841 /**
842 * Arrangements for grouping invocations from NV_compute_shader_derivatives.
843 *
844 * The extension provides new layout qualifiers that support two different
845 * arrangements of compute shader invocations for the purpose of derivative
846 * computation. When specifying
847 *
848 * layout(derivative_group_quadsNV) in;
849 *
850 * compute shader invocations are grouped into 2x2x1 arrays whose four local
851 * invocation ID values follow the pattern:
852 *
853 * +-----------------+------------------+
854 * | (2x+0, 2y+0, z) | (2x+1, 2y+0, z) |
855 * +-----------------+------------------+
856 * | (2x+0, 2y+1, z) | (2x+1, 2y+1, z) |
857 * +-----------------+------------------+
858 *
859 * where Y increases from bottom to top. When specifying
860 *
861 * layout(derivative_group_linearNV) in;
862 *
863 * compute shader invocations are grouped into 2x2x1 arrays whose four local
864 * invocation index values follow the pattern:
865 *
866 * +------+------+
867 * | 4n+0 | 4n+1 |
868 * +------+------+
869 * | 4n+2 | 4n+3 |
870 * +------+------+
871 *
872 * If neither layout qualifier is specified, derivatives in compute shaders
873 * return zero, which is consistent with the handling of built-in texture
874 * functions like texture() in GLSL 4.50 compute shaders.
875 */
876 enum gl_derivative_group {
877 DERIVATIVE_GROUP_NONE = 0,
878 DERIVATIVE_GROUP_QUADS,
879 DERIVATIVE_GROUP_LINEAR,
880 };
881
882 enum float_controls
883 {
884 FLOAT_CONTROLS_DEFAULT_FLOAT_CONTROL_MODE = 0x0000,
885 FLOAT_CONTROLS_DENORM_PRESERVE_FP16 = 0x0001,
886 FLOAT_CONTROLS_DENORM_PRESERVE_FP32 = 0x0002,
887 FLOAT_CONTROLS_DENORM_PRESERVE_FP64 = 0x0004,
888 FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP16 = 0x0008,
889 FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP32 = 0x0010,
890 FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP64 = 0x0020,
891 FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP16 = 0x0040,
892 FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP32 = 0x0080,
893 FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP64 = 0x0100,
894 FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP16 = 0x0200,
895 FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32 = 0x0400,
896 FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP64 = 0x0800,
897 FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP16 = 0x1000,
898 FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP32 = 0x2000,
899 FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP64 = 0x4000,
900 };
901
902 #ifdef __cplusplus
903 } /* extern "C" */
904 #endif
905
906 #endif /* SHADER_ENUMS_H */