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