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