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 /**
27  * \file mtypes.h
28  * Main Mesa data structures.
29  *
30  * Please try to mark derived values with a leading underscore ('_').
31  */
32 
33 #ifndef MTYPES_H
34 #define MTYPES_H
35 
36 
37 #include <stdint.h>             /* uint32_t */
38 #include <stdbool.h>
39 #include "c11/threads.h"
40 
41 #include "main/glheader.h"
42 #include "main/config.h"
43 #include "glapi/glapi.h"
44 #include "math/m_matrix.h"	/* GLmatrix */
45 #include "compiler/shader_enums.h"
46 #include "compiler/shader_info.h"
47 #include "main/formats.h"       /* MESA_FORMAT_COUNT */
48 #include "compiler/glsl/list.h"
49 #include "util/simple_mtx.h"
50 #include "util/u_dynarray.h"
51 
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 
58 /** Set a single bit */
59 #define BITFIELD_BIT(b)      ((GLbitfield)1 << (b))
60 /** Set all bits up to excluding bit b */
61 #define BITFIELD_MASK(b)      \
62    ((b) == 32 ? (~(GLbitfield)0) : BITFIELD_BIT(b) - 1)
63 /** Set count bits starting from bit b  */
64 #define BITFIELD_RANGE(b, count) \
65    (BITFIELD_MASK((b) + (count)) & ~BITFIELD_MASK(b))
66 
67 
68 /**
69  * \name 64-bit extension of GLbitfield.
70  */
71 /*@{*/
72 typedef GLuint64 GLbitfield64;
73 
74 /** Set a single bit */
75 #define BITFIELD64_BIT(b)      ((GLbitfield64)1 << (b))
76 /** Set all bits up to excluding bit b */
77 #define BITFIELD64_MASK(b)      \
78    ((b) == 64 ? (~(GLbitfield64)0) : BITFIELD64_BIT(b) - 1)
79 /** Set count bits starting from bit b  */
80 #define BITFIELD64_RANGE(b, count) \
81    (BITFIELD64_MASK((b) + (count)) & ~BITFIELD64_MASK(b))
82 
83 
84 /**
85  * \name Some forward type declarations
86  */
87 /*@{*/
88 struct _mesa_HashTable;
89 struct gl_attrib_node;
90 struct gl_list_extensions;
91 struct gl_meta_state;
92 struct gl_program_cache;
93 struct gl_texture_object;
94 struct gl_debug_state;
95 struct gl_context;
96 struct st_context;
97 struct gl_uniform_storage;
98 struct prog_instruction;
99 struct gl_program_parameter_list;
100 struct gl_shader_spirv_data;
101 struct set;
102 struct vbo_context;
103 /*@}*/
104 
105 
106 /** Extra draw modes beyond GL_POINTS, GL_TRIANGLE_FAN, etc */
107 #define PRIM_MAX                 GL_PATCHES
108 #define PRIM_OUTSIDE_BEGIN_END   (PRIM_MAX + 1)
109 #define PRIM_UNKNOWN             (PRIM_MAX + 2)
110 
111 /**
112  * Determine if the given gl_varying_slot appears in the fragment shader.
113  */
114 static inline GLboolean
_mesa_varying_slot_in_fs(gl_varying_slot slot)115 _mesa_varying_slot_in_fs(gl_varying_slot slot)
116 {
117    switch (slot) {
118    case VARYING_SLOT_PSIZ:
119    case VARYING_SLOT_BFC0:
120    case VARYING_SLOT_BFC1:
121    case VARYING_SLOT_EDGE:
122    case VARYING_SLOT_CLIP_VERTEX:
123    case VARYING_SLOT_LAYER:
124    case VARYING_SLOT_TESS_LEVEL_OUTER:
125    case VARYING_SLOT_TESS_LEVEL_INNER:
126    case VARYING_SLOT_BOUNDING_BOX0:
127    case VARYING_SLOT_BOUNDING_BOX1:
128       return GL_FALSE;
129    default:
130       return GL_TRUE;
131    }
132 }
133 
134 /**
135  * Indexes for all renderbuffers
136  */
137 typedef enum
138 {
139    /* the four standard color buffers */
140    BUFFER_FRONT_LEFT,
141    BUFFER_BACK_LEFT,
142    BUFFER_FRONT_RIGHT,
143    BUFFER_BACK_RIGHT,
144    BUFFER_DEPTH,
145    BUFFER_STENCIL,
146    BUFFER_ACCUM,
147    /* optional aux buffer */
148    BUFFER_AUX0,
149    /* generic renderbuffers */
150    BUFFER_COLOR0,
151    BUFFER_COLOR1,
152    BUFFER_COLOR2,
153    BUFFER_COLOR3,
154    BUFFER_COLOR4,
155    BUFFER_COLOR5,
156    BUFFER_COLOR6,
157    BUFFER_COLOR7,
158    BUFFER_COUNT,
159    BUFFER_NONE = -1,
160 } gl_buffer_index;
161 
162 /**
163  * Bit flags for all renderbuffers
164  */
165 #define BUFFER_BIT_FRONT_LEFT   (1 << BUFFER_FRONT_LEFT)
166 #define BUFFER_BIT_BACK_LEFT    (1 << BUFFER_BACK_LEFT)
167 #define BUFFER_BIT_FRONT_RIGHT  (1 << BUFFER_FRONT_RIGHT)
168 #define BUFFER_BIT_BACK_RIGHT   (1 << BUFFER_BACK_RIGHT)
169 #define BUFFER_BIT_AUX0         (1 << BUFFER_AUX0)
170 #define BUFFER_BIT_AUX1         (1 << BUFFER_AUX1)
171 #define BUFFER_BIT_AUX2         (1 << BUFFER_AUX2)
172 #define BUFFER_BIT_AUX3         (1 << BUFFER_AUX3)
173 #define BUFFER_BIT_DEPTH        (1 << BUFFER_DEPTH)
174 #define BUFFER_BIT_STENCIL      (1 << BUFFER_STENCIL)
175 #define BUFFER_BIT_ACCUM        (1 << BUFFER_ACCUM)
176 #define BUFFER_BIT_COLOR0       (1 << BUFFER_COLOR0)
177 #define BUFFER_BIT_COLOR1       (1 << BUFFER_COLOR1)
178 #define BUFFER_BIT_COLOR2       (1 << BUFFER_COLOR2)
179 #define BUFFER_BIT_COLOR3       (1 << BUFFER_COLOR3)
180 #define BUFFER_BIT_COLOR4       (1 << BUFFER_COLOR4)
181 #define BUFFER_BIT_COLOR5       (1 << BUFFER_COLOR5)
182 #define BUFFER_BIT_COLOR6       (1 << BUFFER_COLOR6)
183 #define BUFFER_BIT_COLOR7       (1 << BUFFER_COLOR7)
184 
185 /**
186  * Mask of all the color buffer bits (but not accum).
187  */
188 #define BUFFER_BITS_COLOR  (BUFFER_BIT_FRONT_LEFT | \
189                             BUFFER_BIT_BACK_LEFT | \
190                             BUFFER_BIT_FRONT_RIGHT | \
191                             BUFFER_BIT_BACK_RIGHT | \
192                             BUFFER_BIT_AUX0 | \
193                             BUFFER_BIT_COLOR0 | \
194                             BUFFER_BIT_COLOR1 | \
195                             BUFFER_BIT_COLOR2 | \
196                             BUFFER_BIT_COLOR3 | \
197                             BUFFER_BIT_COLOR4 | \
198                             BUFFER_BIT_COLOR5 | \
199                             BUFFER_BIT_COLOR6 | \
200                             BUFFER_BIT_COLOR7)
201 
202 /* Mask of bits for depth+stencil buffers */
203 #define BUFFER_BITS_DEPTH_STENCIL (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)
204 
205 /**
206  * Framebuffer configuration (aka visual / pixelformat)
207  * Note: some of these fields should be boolean, but it appears that
208  * code in drivers/dri/common/util.c requires int-sized fields.
209  */
210 struct gl_config
211 {
212    GLboolean rgbMode;
213    GLboolean floatMode;
214    GLuint doubleBufferMode;
215    GLuint stereoMode;
216 
217    GLboolean haveAccumBuffer;
218    GLboolean haveDepthBuffer;
219    GLboolean haveStencilBuffer;
220 
221    GLint redBits, greenBits, blueBits, alphaBits;	/* bits per comp */
222    GLuint redMask, greenMask, blueMask, alphaMask;
223    GLint rgbBits;		/* total bits for rgb */
224    GLint indexBits;		/* total bits for colorindex */
225 
226    GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits;
227    GLint depthBits;
228    GLint stencilBits;
229 
230    GLint numAuxBuffers;
231 
232    GLint level;
233 
234    /* EXT_visual_rating / GLX 1.2 */
235    GLint visualRating;
236 
237    /* EXT_visual_info / GLX 1.2 */
238    GLint transparentPixel;
239    /*    colors are floats scaled to ints */
240    GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha;
241    GLint transparentIndex;
242 
243    /* ARB_multisample / SGIS_multisample */
244    GLint sampleBuffers;
245    GLuint samples;
246 
247    /* SGIX_pbuffer / GLX 1.3 */
248    GLint maxPbufferWidth;
249    GLint maxPbufferHeight;
250    GLint maxPbufferPixels;
251    GLint optimalPbufferWidth;   /* Only for SGIX_pbuffer. */
252    GLint optimalPbufferHeight;  /* Only for SGIX_pbuffer. */
253 
254    /* OML_swap_method */
255    GLint swapMethod;
256 
257    /* EXT_texture_from_pixmap */
258    GLint bindToTextureRgb;
259    GLint bindToTextureRgba;
260    GLint bindToMipmapTexture;
261    GLint bindToTextureTargets;
262    GLint yInverted;
263 
264    /* EXT_framebuffer_sRGB */
265    GLint sRGBCapable;
266 };
267 
268 
269 /**
270  * \name Bit flags used for updating material values.
271  */
272 /*@{*/
273 #define MAT_ATTRIB_FRONT_AMBIENT           0
274 #define MAT_ATTRIB_BACK_AMBIENT            1
275 #define MAT_ATTRIB_FRONT_DIFFUSE           2
276 #define MAT_ATTRIB_BACK_DIFFUSE            3
277 #define MAT_ATTRIB_FRONT_SPECULAR          4
278 #define MAT_ATTRIB_BACK_SPECULAR           5
279 #define MAT_ATTRIB_FRONT_EMISSION          6
280 #define MAT_ATTRIB_BACK_EMISSION           7
281 #define MAT_ATTRIB_FRONT_SHININESS         8
282 #define MAT_ATTRIB_BACK_SHININESS          9
283 #define MAT_ATTRIB_FRONT_INDEXES           10
284 #define MAT_ATTRIB_BACK_INDEXES            11
285 #define MAT_ATTRIB_MAX                     12
286 
287 #define MAT_ATTRIB_AMBIENT(f)  (MAT_ATTRIB_FRONT_AMBIENT+(f))
288 #define MAT_ATTRIB_DIFFUSE(f)  (MAT_ATTRIB_FRONT_DIFFUSE+(f))
289 #define MAT_ATTRIB_SPECULAR(f) (MAT_ATTRIB_FRONT_SPECULAR+(f))
290 #define MAT_ATTRIB_EMISSION(f) (MAT_ATTRIB_FRONT_EMISSION+(f))
291 #define MAT_ATTRIB_SHININESS(f)(MAT_ATTRIB_FRONT_SHININESS+(f))
292 #define MAT_ATTRIB_INDEXES(f)  (MAT_ATTRIB_FRONT_INDEXES+(f))
293 
294 #define MAT_INDEX_AMBIENT  0
295 #define MAT_INDEX_DIFFUSE  1
296 #define MAT_INDEX_SPECULAR 2
297 
298 #define MAT_BIT_FRONT_AMBIENT         (1<<MAT_ATTRIB_FRONT_AMBIENT)
299 #define MAT_BIT_BACK_AMBIENT          (1<<MAT_ATTRIB_BACK_AMBIENT)
300 #define MAT_BIT_FRONT_DIFFUSE         (1<<MAT_ATTRIB_FRONT_DIFFUSE)
301 #define MAT_BIT_BACK_DIFFUSE          (1<<MAT_ATTRIB_BACK_DIFFUSE)
302 #define MAT_BIT_FRONT_SPECULAR        (1<<MAT_ATTRIB_FRONT_SPECULAR)
303 #define MAT_BIT_BACK_SPECULAR         (1<<MAT_ATTRIB_BACK_SPECULAR)
304 #define MAT_BIT_FRONT_EMISSION        (1<<MAT_ATTRIB_FRONT_EMISSION)
305 #define MAT_BIT_BACK_EMISSION         (1<<MAT_ATTRIB_BACK_EMISSION)
306 #define MAT_BIT_FRONT_SHININESS       (1<<MAT_ATTRIB_FRONT_SHININESS)
307 #define MAT_BIT_BACK_SHININESS        (1<<MAT_ATTRIB_BACK_SHININESS)
308 #define MAT_BIT_FRONT_INDEXES         (1<<MAT_ATTRIB_FRONT_INDEXES)
309 #define MAT_BIT_BACK_INDEXES          (1<<MAT_ATTRIB_BACK_INDEXES)
310 
311 
312 #define FRONT_MATERIAL_BITS	(MAT_BIT_FRONT_EMISSION | 	\
313 				 MAT_BIT_FRONT_AMBIENT |	\
314 				 MAT_BIT_FRONT_DIFFUSE | 	\
315 				 MAT_BIT_FRONT_SPECULAR |	\
316 				 MAT_BIT_FRONT_SHININESS | 	\
317 				 MAT_BIT_FRONT_INDEXES)
318 
319 #define BACK_MATERIAL_BITS	(MAT_BIT_BACK_EMISSION |	\
320 				 MAT_BIT_BACK_AMBIENT |		\
321 				 MAT_BIT_BACK_DIFFUSE |		\
322 				 MAT_BIT_BACK_SPECULAR |	\
323 				 MAT_BIT_BACK_SHININESS |	\
324 				 MAT_BIT_BACK_INDEXES)
325 
326 #define ALL_MATERIAL_BITS	(FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
327 /*@}*/
328 
329 
330 /**
331  * Material state.
332  */
333 struct gl_material
334 {
335    GLfloat Attrib[MAT_ATTRIB_MAX][4];
336 };
337 
338 
339 /**
340  * Light state flags.
341  */
342 /*@{*/
343 #define LIGHT_SPOT         0x1
344 #define LIGHT_LOCAL_VIEWER 0x2
345 #define LIGHT_POSITIONAL   0x4
346 #define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
347 /*@}*/
348 
349 
350 /**
351  * Light source state.
352  */
353 struct gl_light
354 {
355    GLfloat Ambient[4];		/**< ambient color */
356    GLfloat Diffuse[4];		/**< diffuse color */
357    GLfloat Specular[4];		/**< specular color */
358    GLfloat EyePosition[4];	/**< position in eye coordinates */
359    GLfloat SpotDirection[4];	/**< spotlight direction in eye coordinates */
360    GLfloat SpotExponent;
361    GLfloat SpotCutoff;		/**< in degrees */
362    GLfloat _CosCutoff;		/**< = MAX(0, cos(SpotCutoff)) */
363    GLfloat ConstantAttenuation;
364    GLfloat LinearAttenuation;
365    GLfloat QuadraticAttenuation;
366    GLboolean Enabled;		/**< On/off flag */
367 
368    /**
369     * \name Derived fields
370     */
371    /*@{*/
372    GLbitfield _Flags;		/**< Mask of LIGHT_x bits defined above */
373 
374    GLfloat _Position[4];	/**< position in eye/obj coordinates */
375    GLfloat _VP_inf_norm[3];	/**< Norm direction to infinite light */
376    GLfloat _h_inf_norm[3];	/**< Norm( _VP_inf_norm + <0,0,1> ) */
377    GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */
378    GLfloat _VP_inf_spot_attenuation;
379 
380    GLfloat _MatAmbient[2][3];	/**< material ambient * light ambient */
381    GLfloat _MatDiffuse[2][3];	/**< material diffuse * light diffuse */
382    GLfloat _MatSpecular[2][3];	/**< material spec * light specular */
383    /*@}*/
384 };
385 
386 
387 /**
388  * Light model state.
389  */
390 struct gl_lightmodel
391 {
392    GLfloat Ambient[4];		/**< ambient color */
393    GLboolean LocalViewer;	/**< Local (or infinite) view point? */
394    GLboolean TwoSide;		/**< Two (or one) sided lighting? */
395    GLenum ColorControl;		/**< either GL_SINGLE_COLOR
396 				 *    or GL_SEPARATE_SPECULAR_COLOR */
397 };
398 
399 
400 /**
401  * Accumulation buffer attribute group (GL_ACCUM_BUFFER_BIT)
402  */
403 struct gl_accum_attrib
404 {
405    GLfloat ClearColor[4];	/**< Accumulation buffer clear color */
406 };
407 
408 
409 /**
410  * Used for storing clear color, texture border color, etc.
411  * The float values are typically unclamped.
412  */
413 union gl_color_union
414 {
415    GLfloat f[4];
416    GLint i[4];
417    GLuint ui[4];
418 };
419 
420 
421 /**
422  * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
423  */
424 struct gl_colorbuffer_attrib
425 {
426    GLuint ClearIndex;                      /**< Index for glClear */
427    union gl_color_union ClearColor;        /**< Color for glClear, unclamped */
428    GLuint IndexMask;                       /**< Color index write mask */
429    GLubyte ColorMask[MAX_DRAW_BUFFERS][4]; /**< Each flag is 0xff or 0x0 */
430 
431    GLenum DrawBuffer[MAX_DRAW_BUFFERS];	/**< Which buffer to draw into */
432 
433    /**
434     * \name alpha testing
435     */
436    /*@{*/
437    GLboolean AlphaEnabled;		/**< Alpha test enabled flag */
438    GLenum AlphaFunc;			/**< Alpha test function */
439    GLfloat AlphaRefUnclamped;
440    GLclampf AlphaRef;			/**< Alpha reference value */
441    /*@}*/
442 
443    /**
444     * \name Blending
445     */
446    /*@{*/
447    GLbitfield BlendEnabled;		/**< Per-buffer blend enable flags */
448 
449    /* NOTE: this does _not_ depend on fragment clamping or any other clamping
450     * control, only on the fixed-pointness of the render target.
451     * The query does however depend on fragment color clamping.
452     */
453    GLfloat BlendColorUnclamped[4];               /**< Blending color */
454    GLfloat BlendColor[4];		/**< Blending color */
455 
456    struct
457    {
458       GLenum SrcRGB;             /**< RGB blend source term */
459       GLenum DstRGB;             /**< RGB blend dest term */
460       GLenum SrcA;               /**< Alpha blend source term */
461       GLenum DstA;               /**< Alpha blend dest term */
462       GLenum EquationRGB;        /**< GL_ADD, GL_SUBTRACT, etc. */
463       GLenum EquationA;          /**< GL_ADD, GL_SUBTRACT, etc. */
464       /**
465        * Set if any blend factor uses SRC1.  Computed at the time blend factors
466        * get set.
467        */
468       GLboolean _UsesDualSrc;
469    } Blend[MAX_DRAW_BUFFERS];
470    /** Are the blend func terms currently different for each buffer/target? */
471    GLboolean _BlendFuncPerBuffer;
472    /** Are the blend equations currently different for each buffer/target? */
473    GLboolean _BlendEquationPerBuffer;
474 
475    /**
476     * Which advanced blending mode is in use (or BLEND_NONE).
477     *
478     * KHR_blend_equation_advanced only allows advanced blending with a single
479     * draw buffer, and NVX_blend_equation_advanced_multi_draw_buffer still
480     * requires all draw buffers to match, so we only need a single value.
481     */
482    enum gl_advanced_blend_mode _AdvancedBlendMode;
483 
484    /** Coherency requested via glEnable(GL_BLEND_ADVANCED_COHERENT_KHR)? */
485    bool BlendCoherent;
486    /*@}*/
487 
488    /**
489     * \name Logic op
490     */
491    /*@{*/
492    GLboolean IndexLogicOpEnabled;	/**< Color index logic op enabled flag */
493    GLboolean ColorLogicOpEnabled;	/**< RGBA logic op enabled flag */
494    GLenum LogicOp;			/**< Logic operator */
495 
496    /*@}*/
497 
498    GLboolean DitherFlag;		/**< Dither enable flag */
499 
500    GLboolean _ClampFragmentColor; /** < with GL_FIXED_ONLY_ARB resolved */
501    GLenum ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
502    GLenum ClampReadColor;     /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
503 
504    GLboolean sRGBEnabled;    /**< Framebuffer sRGB blending/updating requested */
505 };
506 
507 
508 /**
509  * Current attribute group (GL_CURRENT_BIT).
510  */
511 struct gl_current_attrib
512 {
513    /**
514     * \name Current vertex attributes (color, texcoords, etc).
515     * \note Values are valid only after FLUSH_VERTICES has been called.
516     * \note Index and Edgeflag current values are stored as floats in the
517     * SIX and SEVEN attribute slots.
518     * \note We need double storage for 64-bit vertex attributes
519     */
520    GLfloat Attrib[VERT_ATTRIB_MAX][4*2];
521 
522    /**
523     * \name Current raster position attributes (always up to date after a
524     * glRasterPos call).
525     */
526    GLfloat RasterPos[4];
527    GLfloat RasterDistance;
528    GLfloat RasterColor[4];
529    GLfloat RasterSecondaryColor[4];
530    GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
531    GLboolean RasterPosValid;
532 };
533 
534 
535 /**
536  * Depth buffer attribute group (GL_DEPTH_BUFFER_BIT).
537  */
538 struct gl_depthbuffer_attrib
539 {
540    GLenum Func;			/**< Function for depth buffer compare */
541    GLclampd Clear;		/**< Value to clear depth buffer to */
542    GLboolean Test;		/**< Depth buffering enabled flag */
543    GLboolean Mask;		/**< Depth buffer writable? */
544    GLboolean BoundsTest;        /**< GL_EXT_depth_bounds_test */
545    GLfloat BoundsMin, BoundsMax;/**< GL_EXT_depth_bounds_test */
546 };
547 
548 
549 /**
550  * Evaluator attribute group (GL_EVAL_BIT).
551  */
552 struct gl_eval_attrib
553 {
554    /**
555     * \name Enable bits
556     */
557    /*@{*/
558    GLboolean Map1Color4;
559    GLboolean Map1Index;
560    GLboolean Map1Normal;
561    GLboolean Map1TextureCoord1;
562    GLboolean Map1TextureCoord2;
563    GLboolean Map1TextureCoord3;
564    GLboolean Map1TextureCoord4;
565    GLboolean Map1Vertex3;
566    GLboolean Map1Vertex4;
567    GLboolean Map2Color4;
568    GLboolean Map2Index;
569    GLboolean Map2Normal;
570    GLboolean Map2TextureCoord1;
571    GLboolean Map2TextureCoord2;
572    GLboolean Map2TextureCoord3;
573    GLboolean Map2TextureCoord4;
574    GLboolean Map2Vertex3;
575    GLboolean Map2Vertex4;
576    GLboolean AutoNormal;
577    /*@}*/
578 
579    /**
580     * \name Map Grid endpoints and divisions and calculated du values
581     */
582    /*@{*/
583    GLint MapGrid1un;
584    GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
585    GLint MapGrid2un, MapGrid2vn;
586    GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
587    GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
588    /*@}*/
589 };
590 
591 
592 /**
593  * Compressed fog mode.
594  */
595 enum gl_fog_mode
596 {
597    FOG_NONE,
598    FOG_LINEAR,
599    FOG_EXP,
600    FOG_EXP2,
601 };
602 
603 
604 /**
605  * Fog attribute group (GL_FOG_BIT).
606  */
607 struct gl_fog_attrib
608 {
609    GLboolean Enabled;		/**< Fog enabled flag */
610    GLboolean ColorSumEnabled;
611    uint8_t _PackedMode;		/**< Fog mode as 2 bits */
612    uint8_t _PackedEnabledMode;	/**< Masked CompressedMode */
613    GLfloat ColorUnclamped[4];            /**< Fog color */
614    GLfloat Color[4];		/**< Fog color */
615    GLfloat Density;		/**< Density >= 0.0 */
616    GLfloat Start;		/**< Start distance in eye coords */
617    GLfloat End;			/**< End distance in eye coords */
618    GLfloat Index;		/**< Fog index */
619    GLenum Mode;			/**< Fog mode */
620    GLenum FogCoordinateSource;  /**< GL_EXT_fog_coord */
621    GLfloat _Scale;		/**< (End == Start) ? 1.0 : 1.0 / (End - Start) */
622    GLenum FogDistanceMode;     /**< GL_NV_fog_distance */
623 };
624 
625 
626 /**
627  * Hint attribute group (GL_HINT_BIT).
628  *
629  * Values are always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE.
630  */
631 struct gl_hint_attrib
632 {
633    GLenum PerspectiveCorrection;
634    GLenum PointSmooth;
635    GLenum LineSmooth;
636    GLenum PolygonSmooth;
637    GLenum Fog;
638    GLenum TextureCompression;   /**< GL_ARB_texture_compression */
639    GLenum GenerateMipmap;       /**< GL_SGIS_generate_mipmap */
640    GLenum FragmentShaderDerivative; /**< GL_ARB_fragment_shader */
641 };
642 
643 
644 /**
645  * Lighting attribute group (GL_LIGHT_BIT).
646  */
647 struct gl_light_attrib
648 {
649    struct gl_light Light[MAX_LIGHTS];	/**< Array of light sources */
650    struct gl_lightmodel Model;		/**< Lighting model */
651 
652    /**
653     * Front and back material values.
654     * Note: must call FLUSH_VERTICES() before using.
655     */
656    struct gl_material Material;
657 
658    GLboolean Enabled;			/**< Lighting enabled flag */
659    GLboolean ColorMaterialEnabled;
660 
661    GLenum ShadeModel;			/**< GL_FLAT or GL_SMOOTH */
662    GLenum ProvokingVertex;              /**< GL_EXT_provoking_vertex */
663    GLenum ColorMaterialFace;		/**< GL_FRONT, BACK or FRONT_AND_BACK */
664    GLenum ColorMaterialMode;		/**< GL_AMBIENT, GL_DIFFUSE, etc */
665    GLbitfield _ColorMaterialBitmask;	/**< bitmask formed from Face and Mode */
666 
667 
668    GLboolean _ClampVertexColor;
669    GLenum ClampVertexColor;             /**< GL_TRUE, GL_FALSE, GL_FIXED_ONLY */
670 
671    /**
672     * Derived state for optimizations:
673     */
674    /*@{*/
675    GLbitfield _EnabledLights;	/**< bitmask containing enabled lights */
676 
677    GLboolean _NeedEyeCoords;
678    GLboolean _NeedVertices;		/**< Use fast shader? */
679 
680    GLfloat _BaseColor[2][3];
681    /*@}*/
682 };
683 
684 
685 /**
686  * Line attribute group (GL_LINE_BIT).
687  */
688 struct gl_line_attrib
689 {
690    GLboolean SmoothFlag;	/**< GL_LINE_SMOOTH enabled? */
691    GLboolean StippleFlag;	/**< GL_LINE_STIPPLE enabled? */
692    GLushort StipplePattern;	/**< Stipple pattern */
693    GLint StippleFactor;		/**< Stipple repeat factor */
694    GLfloat Width;		/**< Line width */
695 };
696 
697 
698 /**
699  * Display list attribute group (GL_LIST_BIT).
700  */
701 struct gl_list_attrib
702 {
703    GLuint ListBase;
704 };
705 
706 
707 /**
708  * Multisample attribute group (GL_MULTISAMPLE_BIT).
709  */
710 struct gl_multisample_attrib
711 {
712    GLboolean Enabled;
713    GLboolean SampleAlphaToCoverage;
714    GLboolean SampleAlphaToOne;
715    GLboolean SampleCoverage;
716    GLboolean SampleCoverageInvert;
717    GLboolean SampleShading;
718 
719    /* ARB_texture_multisample / GL3.2 additions */
720    GLboolean SampleMask;
721 
722    GLfloat SampleCoverageValue;  /**< In range [0, 1] */
723    GLfloat MinSampleShadingValue;  /**< In range [0, 1] */
724 
725    /** The GL spec defines this as an array but >32x MSAA is madness */
726    GLbitfield SampleMaskValue;
727 };
728 
729 
730 /**
731  * A pixelmap (see glPixelMap)
732  */
733 struct gl_pixelmap
734 {
735    GLint Size;
736    GLfloat Map[MAX_PIXEL_MAP_TABLE];
737 };
738 
739 
740 /**
741  * Collection of all pixelmaps
742  */
743 struct gl_pixelmaps
744 {
745    struct gl_pixelmap RtoR;  /**< i.e. GL_PIXEL_MAP_R_TO_R */
746    struct gl_pixelmap GtoG;
747    struct gl_pixelmap BtoB;
748    struct gl_pixelmap AtoA;
749    struct gl_pixelmap ItoR;
750    struct gl_pixelmap ItoG;
751    struct gl_pixelmap ItoB;
752    struct gl_pixelmap ItoA;
753    struct gl_pixelmap ItoI;
754    struct gl_pixelmap StoS;
755 };
756 
757 
758 /**
759  * Pixel attribute group (GL_PIXEL_MODE_BIT).
760  */
761 struct gl_pixel_attrib
762 {
763    GLenum ReadBuffer;		/**< source buffer for glRead/CopyPixels() */
764 
765    /*--- Begin Pixel Transfer State ---*/
766    /* Fields are in the order in which they're applied... */
767 
768    /** Scale & Bias (index shift, offset) */
769    /*@{*/
770    GLfloat RedBias, RedScale;
771    GLfloat GreenBias, GreenScale;
772    GLfloat BlueBias, BlueScale;
773    GLfloat AlphaBias, AlphaScale;
774    GLfloat DepthBias, DepthScale;
775    GLint IndexShift, IndexOffset;
776    /*@}*/
777 
778    /* Pixel Maps */
779    /* Note: actual pixel maps are not part of this attrib group */
780    GLboolean MapColorFlag;
781    GLboolean MapStencilFlag;
782 
783    /*--- End Pixel Transfer State ---*/
784 
785    /** glPixelZoom */
786    GLfloat ZoomX, ZoomY;
787 };
788 
789 
790 /**
791  * Point attribute group (GL_POINT_BIT).
792  */
793 struct gl_point_attrib
794 {
795    GLfloat Size;		/**< User-specified point size */
796    GLfloat Params[3];		/**< GL_EXT_point_parameters */
797    GLfloat MinSize, MaxSize;	/**< GL_EXT_point_parameters */
798    GLfloat Threshold;		/**< GL_EXT_point_parameters */
799    GLboolean SmoothFlag;	/**< True if GL_POINT_SMOOTH is enabled */
800    GLboolean _Attenuated;	/**< True if Params != [1, 0, 0] */
801    GLboolean PointSprite;	/**< GL_NV/ARB_point_sprite */
802    GLbitfield CoordReplace;     /**< GL_ARB_point_sprite*/
803    GLenum SpriteRMode;		/**< GL_NV_point_sprite (only!) */
804    GLenum SpriteOrigin;		/**< GL_ARB_point_sprite */
805 };
806 
807 
808 /**
809  * Polygon attribute group (GL_POLYGON_BIT).
810  */
811 struct gl_polygon_attrib
812 {
813    GLenum FrontFace;		/**< Either GL_CW or GL_CCW */
814    GLenum FrontMode;		/**< Either GL_POINT, GL_LINE or GL_FILL */
815    GLenum BackMode;		/**< Either GL_POINT, GL_LINE or GL_FILL */
816    GLboolean CullFlag;		/**< Culling on/off flag */
817    GLboolean SmoothFlag;	/**< True if GL_POLYGON_SMOOTH is enabled */
818    GLboolean StippleFlag;	/**< True if GL_POLYGON_STIPPLE is enabled */
819    GLenum CullFaceMode;		/**< Culling mode GL_FRONT or GL_BACK */
820    GLfloat OffsetFactor;	/**< Polygon offset factor, from user */
821    GLfloat OffsetUnits;		/**< Polygon offset units, from user */
822    GLfloat OffsetClamp;		/**< Polygon offset clamp, from user */
823    GLboolean OffsetPoint;	/**< Offset in GL_POINT mode */
824    GLboolean OffsetLine;	/**< Offset in GL_LINE mode */
825    GLboolean OffsetFill;	/**< Offset in GL_FILL mode */
826 };
827 
828 
829 /**
830  * Scissor attributes (GL_SCISSOR_BIT).
831  */
832 struct gl_scissor_rect
833 {
834    GLint X, Y;			/**< Lower left corner of box */
835    GLsizei Width, Height;	/**< Size of box */
836 };
837 struct gl_scissor_attrib
838 {
839    GLbitfield EnableFlags;	/**< Scissor test enabled? */
840    struct gl_scissor_rect ScissorArray[MAX_VIEWPORTS];
841    GLint NumWindowRects;        /**< Count of enabled window rectangles */
842    GLenum WindowRectMode;       /**< Whether to include or exclude the rects */
843    struct gl_scissor_rect WindowRects[MAX_WINDOW_RECTANGLES];
844 };
845 
846 
847 /**
848  * Stencil attribute group (GL_STENCIL_BUFFER_BIT).
849  *
850  * Three sets of stencil data are tracked so that OpenGL 2.0,
851  * GL_EXT_stencil_two_side, and GL_ATI_separate_stencil can all be supported
852  * simultaneously.  In each of the stencil state arrays, element 0 corresponds
853  * to GL_FRONT.  Element 1 corresponds to the OpenGL 2.0 /
854  * GL_ATI_separate_stencil GL_BACK state.  Element 2 corresponds to the
855  * GL_EXT_stencil_two_side GL_BACK state.
856  *
857  * The derived value \c _BackFace is either 1 or 2 depending on whether or
858  * not GL_STENCIL_TEST_TWO_SIDE_EXT is enabled.
859  *
860  * The derived value \c _TestTwoSide is set when the front-face and back-face
861  * stencil state are different.
862  */
863 struct gl_stencil_attrib
864 {
865    GLboolean Enabled;		/**< Enabled flag */
866    GLboolean TestTwoSide;	/**< GL_EXT_stencil_two_side */
867    GLubyte ActiveFace;		/**< GL_EXT_stencil_two_side (0 or 2) */
868    GLubyte _BackFace;           /**< Current back stencil state (1 or 2) */
869    GLenum Function[3];		/**< Stencil function */
870    GLenum FailFunc[3];		/**< Fail function */
871    GLenum ZPassFunc[3];		/**< Depth buffer pass function */
872    GLenum ZFailFunc[3];		/**< Depth buffer fail function */
873    GLint Ref[3];		/**< Reference value */
874    GLuint ValueMask[3];		/**< Value mask */
875    GLuint WriteMask[3];		/**< Write mask */
876    GLuint Clear;		/**< Clear value */
877 };
878 
879 
880 /**
881  * An index for each type of texture object.  These correspond to the GL
882  * texture target enums, such as GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.
883  * Note: the order is from highest priority to lowest priority.
884  */
885 typedef enum
886 {
887    TEXTURE_2D_MULTISAMPLE_INDEX,
888    TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX,
889    TEXTURE_CUBE_ARRAY_INDEX,
890    TEXTURE_BUFFER_INDEX,
891    TEXTURE_2D_ARRAY_INDEX,
892    TEXTURE_1D_ARRAY_INDEX,
893    TEXTURE_EXTERNAL_INDEX,
894    TEXTURE_CUBE_INDEX,
895    TEXTURE_3D_INDEX,
896    TEXTURE_RECT_INDEX,
897    TEXTURE_2D_INDEX,
898    TEXTURE_1D_INDEX,
899    NUM_TEXTURE_TARGETS
900 } gl_texture_index;
901 
902 
903 /**
904  * Bit flags for each type of texture object
905  */
906 /*@{*/
907 #define TEXTURE_2D_MULTISAMPLE_BIT (1 << TEXTURE_2D_MULTISAMPLE_INDEX)
908 #define TEXTURE_2D_MULTISAMPLE_ARRAY_BIT (1 << TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX)
909 #define TEXTURE_CUBE_ARRAY_BIT (1 << TEXTURE_CUBE_ARRAY_INDEX)
910 #define TEXTURE_BUFFER_BIT   (1 << TEXTURE_BUFFER_INDEX)
911 #define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
912 #define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
913 #define TEXTURE_EXTERNAL_BIT (1 << TEXTURE_EXTERNAL_INDEX)
914 #define TEXTURE_CUBE_BIT     (1 << TEXTURE_CUBE_INDEX)
915 #define TEXTURE_3D_BIT       (1 << TEXTURE_3D_INDEX)
916 #define TEXTURE_RECT_BIT     (1 << TEXTURE_RECT_INDEX)
917 #define TEXTURE_2D_BIT       (1 << TEXTURE_2D_INDEX)
918 #define TEXTURE_1D_BIT       (1 << TEXTURE_1D_INDEX)
919 /*@}*/
920 
921 
922 /**
923  * Texture image state.  Drivers will typically create a subclass of this
924  * with extra fields for memory buffers, etc.
925  */
926 struct gl_texture_image
927 {
928    GLint InternalFormat;	/**< Internal format as given by the user */
929    GLenum _BaseFormat;		/**< Either GL_RGB, GL_RGBA, GL_ALPHA,
930 				 *   GL_LUMINANCE, GL_LUMINANCE_ALPHA,
931 				 *   GL_INTENSITY, GL_DEPTH_COMPONENT or
932 				 *   GL_DEPTH_STENCIL_EXT only. Used for
933 				 *   choosing TexEnv arithmetic.
934 				 */
935    mesa_format TexFormat;         /**< The actual texture memory format */
936 
937    GLuint Border;		/**< 0 or 1 */
938    GLuint Width;		/**< = 2^WidthLog2 + 2*Border */
939    GLuint Height;		/**< = 2^HeightLog2 + 2*Border */
940    GLuint Depth;		/**< = 2^DepthLog2 + 2*Border */
941    GLuint Width2;		/**< = Width - 2*Border */
942    GLuint Height2;		/**< = Height - 2*Border */
943    GLuint Depth2;		/**< = Depth - 2*Border */
944    GLuint WidthLog2;		/**< = log2(Width2) */
945    GLuint HeightLog2;		/**< = log2(Height2) */
946    GLuint DepthLog2;		/**< = log2(Depth2) */
947    GLuint MaxNumLevels;		/**< = maximum possible number of mipmap
948                                        levels, computed from the dimensions */
949 
950    struct gl_texture_object *TexObject;  /**< Pointer back to parent object */
951    GLuint Level;                /**< Which mipmap level am I? */
952    /** Cube map face: index into gl_texture_object::Image[] array */
953    GLuint Face;
954 
955    /** GL_ARB_texture_multisample */
956    GLuint NumSamples;            /**< Sample count, or 0 for non-multisample */
957    GLboolean FixedSampleLocations; /**< Same sample locations for all pixels? */
958 };
959 
960 
961 /**
962  * Indexes for cube map faces.
963  */
964 typedef enum
965 {
966    FACE_POS_X = 0,
967    FACE_NEG_X = 1,
968    FACE_POS_Y = 2,
969    FACE_NEG_Y = 3,
970    FACE_POS_Z = 4,
971    FACE_NEG_Z = 5,
972    MAX_FACES = 6
973 } gl_face_index;
974 
975 
976 /**
977  * Sampler object state.  These objects are new with GL_ARB_sampler_objects
978  * and OpenGL 3.3.  Legacy texture objects also contain a sampler object.
979  */
980 struct gl_sampler_object
981 {
982    simple_mtx_t Mutex;
983    GLuint Name;
984    GLint RefCount;
985    GLchar *Label;               /**< GL_KHR_debug */
986 
987    GLenum WrapS;		/**< S-axis texture image wrap mode */
988    GLenum WrapT;		/**< T-axis texture image wrap mode */
989    GLenum WrapR;		/**< R-axis texture image wrap mode */
990    GLenum MinFilter;		/**< minification filter */
991    GLenum MagFilter;		/**< magnification filter */
992    union gl_color_union BorderColor;  /**< Interpreted according to texture format */
993    GLfloat MinLod;		/**< min lambda, OpenGL 1.2 */
994    GLfloat MaxLod;		/**< max lambda, OpenGL 1.2 */
995    GLfloat LodBias;		/**< OpenGL 1.4 */
996    GLfloat MaxAnisotropy;	/**< GL_EXT_texture_filter_anisotropic */
997    GLenum CompareMode;		/**< GL_ARB_shadow */
998    GLenum CompareFunc;		/**< GL_ARB_shadow */
999    GLenum sRGBDecode;           /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */
1000    GLboolean CubeMapSeamless;   /**< GL_AMD_seamless_cubemap_per_texture */
1001 
1002    /** GL_ARB_bindless_texture */
1003    bool HandleAllocated;
1004    struct util_dynarray Handles;
1005 };
1006 
1007 
1008 /**
1009  * Texture object state.  Contains the array of mipmap images, border color,
1010  * wrap modes, filter modes, and shadow/texcompare state.
1011  */
1012 struct gl_texture_object
1013 {
1014    simple_mtx_t Mutex;      /**< for thread safety */
1015    GLint RefCount;             /**< reference count */
1016    GLuint Name;                /**< the user-visible texture object ID */
1017    GLchar *Label;               /**< GL_KHR_debug */
1018    GLenum Target;              /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
1019    gl_texture_index TargetIndex; /**< The gl_texture_unit::CurrentTex index.
1020                                       Only valid when Target is valid. */
1021 
1022    struct gl_sampler_object Sampler;
1023 
1024    GLenum DepthMode;           /**< GL_ARB_depth_texture */
1025 
1026    GLfloat Priority;           /**< in [0,1] */
1027    GLint BaseLevel;            /**< min mipmap level, OpenGL 1.2 */
1028    GLint MaxLevel;             /**< max mipmap level, OpenGL 1.2 */
1029    GLint ImmutableLevels;      /**< ES 3.0 / ARB_texture_view */
1030    GLint _MaxLevel;            /**< actual max mipmap level (q in the spec) */
1031    GLfloat _MaxLambda;         /**< = _MaxLevel - BaseLevel (q - p in spec) */
1032    GLint CropRect[4];          /**< GL_OES_draw_texture */
1033    GLenum Swizzle[4];          /**< GL_EXT_texture_swizzle */
1034    GLuint _Swizzle;            /**< same as Swizzle, but SWIZZLE_* format */
1035    GLboolean GenerateMipmap;   /**< GL_SGIS_generate_mipmap */
1036    GLboolean _BaseComplete;    /**< Is the base texture level valid? */
1037    GLboolean _MipmapComplete;  /**< Is the whole mipmap valid? */
1038    GLboolean _IsIntegerFormat; /**< Does the texture store integer values? */
1039    GLboolean _RenderToTexture; /**< Any rendering to this texture? */
1040    GLboolean Purgeable;        /**< Is the buffer purgeable under memory
1041                                     pressure? */
1042    GLboolean Immutable;        /**< GL_ARB_texture_storage */
1043    GLboolean _IsFloat;         /**< GL_OES_float_texture */
1044    GLboolean _IsHalfFloat;     /**< GL_OES_half_float_texture */
1045    bool StencilSampling;       /**< Should we sample stencil instead of depth? */
1046    bool HandleAllocated;       /**< GL_ARB_bindless_texture */
1047 
1048    GLuint MinLevel;            /**< GL_ARB_texture_view */
1049    GLuint MinLayer;            /**< GL_ARB_texture_view */
1050    GLuint NumLevels;           /**< GL_ARB_texture_view */
1051    GLuint NumLayers;           /**< GL_ARB_texture_view */
1052 
1053    /** GL_EXT_memory_object */
1054    GLenum TextureTiling;
1055 
1056    /** Actual texture images, indexed by [cube face] and [mipmap level] */
1057    struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
1058 
1059    /** GL_ARB_texture_buffer_object */
1060    struct gl_buffer_object *BufferObject;
1061    GLenum BufferObjectFormat;
1062    /** Equivalent Mesa format for BufferObjectFormat. */
1063    mesa_format _BufferObjectFormat;
1064    /** GL_ARB_texture_buffer_range */
1065    GLintptr BufferOffset;
1066    GLsizeiptr BufferSize; /**< if this is -1, use BufferObject->Size instead */
1067 
1068    /** GL_OES_EGL_image_external */
1069    GLint RequiredTextureImageUnits;
1070 
1071    /** GL_ARB_shader_image_load_store */
1072    GLenum ImageFormatCompatibilityType;
1073 
1074    /** GL_ARB_bindless_texture */
1075    struct util_dynarray SamplerHandles;
1076    struct util_dynarray ImageHandles;
1077 };
1078 
1079 
1080 /** Up to four combiner sources are possible with GL_NV_texture_env_combine4 */
1081 #define MAX_COMBINER_TERMS 4
1082 
1083 
1084 /**
1085  * Texture combine environment state.
1086  */
1087 struct gl_tex_env_combine_state
1088 {
1089    GLenum ModeRGB;       /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1090    GLenum ModeA;         /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1091    /** Source terms: GL_PRIMARY_COLOR, GL_TEXTURE, etc */
1092    GLenum SourceRGB[MAX_COMBINER_TERMS];
1093    GLenum SourceA[MAX_COMBINER_TERMS];
1094    /** Source operands: GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, etc */
1095    GLenum OperandRGB[MAX_COMBINER_TERMS];
1096    GLenum OperandA[MAX_COMBINER_TERMS];
1097    GLuint ScaleShiftRGB; /**< 0, 1 or 2 */
1098    GLuint ScaleShiftA;   /**< 0, 1 or 2 */
1099    GLuint _NumArgsRGB;   /**< Number of inputs used for the RGB combiner */
1100    GLuint _NumArgsA;     /**< Number of inputs used for the A combiner */
1101 };
1102 
1103 
1104 /** Compressed TexEnv effective Combine mode */
1105 enum gl_tex_env_mode
1106 {
1107    TEXENV_MODE_REPLACE,                 /* r = a0 */
1108    TEXENV_MODE_MODULATE,                /* r = a0 * a1 */
1109    TEXENV_MODE_ADD,                     /* r = a0 + a1 */
1110    TEXENV_MODE_ADD_SIGNED,              /* r = a0 + a1 - 0.5 */
1111    TEXENV_MODE_INTERPOLATE,             /* r = a0 * a2 + a1 * (1 - a2) */
1112    TEXENV_MODE_SUBTRACT,                /* r = a0 - a1 */
1113    TEXENV_MODE_DOT3_RGB,                /* r = a0 . a1 */
1114    TEXENV_MODE_DOT3_RGB_EXT,            /* r = a0 . a1 */
1115    TEXENV_MODE_DOT3_RGBA,               /* r = a0 . a1 */
1116    TEXENV_MODE_DOT3_RGBA_EXT,           /* r = a0 . a1 */
1117    TEXENV_MODE_MODULATE_ADD_ATI,        /* r = a0 * a2 + a1 */
1118    TEXENV_MODE_MODULATE_SIGNED_ADD_ATI, /* r = a0 * a2 + a1 - 0.5 */
1119    TEXENV_MODE_MODULATE_SUBTRACT_ATI,   /* r = a0 * a2 - a1 */
1120    TEXENV_MODE_ADD_PRODUCTS_NV,         /* r = a0 * a1 + a2 * a3 */
1121    TEXENV_MODE_ADD_PRODUCTS_SIGNED_NV,  /* r = a0 * a1 + a2 * a3 - 0.5 */
1122 };
1123 
1124 
1125 /** Compressed TexEnv Combine source */
1126 enum gl_tex_env_source
1127 {
1128    TEXENV_SRC_TEXTURE0,
1129    TEXENV_SRC_TEXTURE1,
1130    TEXENV_SRC_TEXTURE2,
1131    TEXENV_SRC_TEXTURE3,
1132    TEXENV_SRC_TEXTURE4,
1133    TEXENV_SRC_TEXTURE5,
1134    TEXENV_SRC_TEXTURE6,
1135    TEXENV_SRC_TEXTURE7,
1136    TEXENV_SRC_TEXTURE,
1137    TEXENV_SRC_PREVIOUS,
1138    TEXENV_SRC_PRIMARY_COLOR,
1139    TEXENV_SRC_CONSTANT,
1140    TEXENV_SRC_ZERO,
1141    TEXENV_SRC_ONE,
1142 };
1143 
1144 
1145 /** Compressed TexEnv Combine operand */
1146 enum gl_tex_env_operand
1147 {
1148    TEXENV_OPR_COLOR,
1149    TEXENV_OPR_ONE_MINUS_COLOR,
1150    TEXENV_OPR_ALPHA,
1151    TEXENV_OPR_ONE_MINUS_ALPHA,
1152 };
1153 
1154 
1155 /** Compressed TexEnv Combine argument */
1156 struct gl_tex_env_argument
1157 {
1158 #ifdef __GNUC__
1159    __extension__ uint8_t Source:4;  /**< TEXENV_SRC_x */
1160    __extension__ uint8_t Operand:2; /**< TEXENV_OPR_x */
1161 #else
1162    uint8_t Source;  /**< SRC_x */
1163    uint8_t Operand; /**< OPR_x */
1164 #endif
1165 };
1166 
1167 
1168 /***
1169  * Compressed TexEnv Combine state.
1170  */
1171 struct gl_tex_env_combine_packed
1172 {
1173    uint32_t ModeRGB:4;          /**< Effective mode for RGB as 4 bits */
1174    uint32_t ModeA:4;            /**< Effective mode for RGB as 4 bits */
1175    uint32_t ScaleShiftRGB:2;    /**< 0, 1 or 2 */
1176    uint32_t ScaleShiftA:2;      /**< 0, 1 or 2 */
1177    uint32_t NumArgsRGB:3;       /**< Number of inputs used for the RGB combiner */
1178    uint32_t NumArgsA:3;         /**< Number of inputs used for the A combiner */
1179    /** Source arguments in a packed manner */
1180    struct gl_tex_env_argument ArgsRGB[MAX_COMBINER_TERMS];
1181    struct gl_tex_env_argument ArgsA[MAX_COMBINER_TERMS];
1182 };
1183 
1184 
1185 /**
1186  * TexGenEnabled flags.
1187  */
1188 /*@{*/
1189 #define S_BIT 1
1190 #define T_BIT 2
1191 #define R_BIT 4
1192 #define Q_BIT 8
1193 #define STR_BITS (S_BIT | T_BIT | R_BIT)
1194 /*@}*/
1195 
1196 
1197 /**
1198  * Bit flag versions of the corresponding GL_ constants.
1199  */
1200 /*@{*/
1201 #define TEXGEN_SPHERE_MAP        0x1
1202 #define TEXGEN_OBJ_LINEAR        0x2
1203 #define TEXGEN_EYE_LINEAR        0x4
1204 #define TEXGEN_REFLECTION_MAP_NV 0x8
1205 #define TEXGEN_NORMAL_MAP_NV     0x10
1206 
1207 #define TEXGEN_NEED_NORMALS      (TEXGEN_SPHERE_MAP        | \
1208 				  TEXGEN_REFLECTION_MAP_NV | \
1209 				  TEXGEN_NORMAL_MAP_NV)
1210 #define TEXGEN_NEED_EYE_COORD    (TEXGEN_SPHERE_MAP        | \
1211 				  TEXGEN_REFLECTION_MAP_NV | \
1212 				  TEXGEN_NORMAL_MAP_NV     | \
1213 				  TEXGEN_EYE_LINEAR)
1214 /*@}*/
1215 
1216 
1217 
1218 /** Tex-gen enabled for texture unit? */
1219 #define ENABLE_TEXGEN(unit) (1 << (unit))
1220 
1221 /** Non-identity texture matrix for texture unit? */
1222 #define ENABLE_TEXMAT(unit) (1 << (unit))
1223 
1224 
1225 /**
1226  * Texture coord generation state.
1227  */
1228 struct gl_texgen
1229 {
1230    GLenum Mode;         /**< GL_EYE_LINEAR, GL_SPHERE_MAP, etc */
1231    GLbitfield _ModeBit; /**< TEXGEN_x bit corresponding to Mode */
1232    GLfloat ObjectPlane[4];
1233    GLfloat EyePlane[4];
1234 };
1235 
1236 
1237 /**
1238  * Texture unit state.  Contains enable flags, texture environment/function/
1239  * combiners, texgen state, and pointers to current texture objects.
1240  */
1241 struct gl_texture_unit
1242 {
1243    GLbitfield Enabled;          /**< bitmask of TEXTURE_*_BIT flags */
1244 
1245    GLenum EnvMode;              /**< GL_MODULATE, GL_DECAL, GL_BLEND, etc. */
1246    GLclampf EnvColor[4];
1247    GLfloat EnvColorUnclamped[4];
1248 
1249    struct gl_texgen GenS;
1250    struct gl_texgen GenT;
1251    struct gl_texgen GenR;
1252    struct gl_texgen GenQ;
1253    GLbitfield TexGenEnabled;	/**< Bitwise-OR of [STRQ]_BIT values */
1254    GLbitfield _GenFlags;	/**< Bitwise-OR of Gen[STRQ]._ModeBit */
1255 
1256    GLfloat LodBias;		/**< for biasing mipmap levels */
1257 
1258    /** Texture targets that have a non-default texture bound */
1259    GLbitfield _BoundTextures;
1260 
1261    /** Current sampler object (GL_ARB_sampler_objects) */
1262    struct gl_sampler_object *Sampler;
1263 
1264    /**
1265     * \name GL_EXT_texture_env_combine
1266     */
1267    struct gl_tex_env_combine_state Combine;
1268 
1269    /**
1270     * Derived state based on \c EnvMode and the \c BaseFormat of the
1271     * currently enabled texture.
1272     */
1273    struct gl_tex_env_combine_state _EnvMode;
1274 
1275    /**
1276     * Currently enabled combiner state.  This will point to either
1277     * \c Combine or \c _EnvMode.
1278     */
1279    struct gl_tex_env_combine_state *_CurrentCombine;
1280 
1281    /** Current texture object pointers */
1282    struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
1283 
1284    /** Points to highest priority, complete and enabled texture object */
1285    struct gl_texture_object *_Current;
1286 
1287    /** Current compressed TexEnv & Combine state */
1288    struct gl_tex_env_combine_packed _CurrentCombinePacked;
1289 };
1290 
1291 
1292 /**
1293  * Texture attribute group (GL_TEXTURE_BIT).
1294  */
1295 struct gl_texture_attrib
1296 {
1297    GLuint CurrentUnit;   /**< GL_ACTIVE_TEXTURE */
1298 
1299    /** GL_ARB_seamless_cubemap */
1300    GLboolean CubeMapSeamless;
1301 
1302    struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
1303 
1304    /** GL_ARB_texture_buffer_object */
1305    struct gl_buffer_object *BufferObject;
1306 
1307    /** Texture coord units/sets used for fragment texturing */
1308    GLbitfield _EnabledCoordUnits;
1309 
1310    /** Texture coord units that have texgen enabled */
1311    GLbitfield _TexGenEnabled;
1312 
1313    /** Texture coord units that have non-identity matrices */
1314    GLbitfield _TexMatEnabled;
1315 
1316    /** Bitwise-OR of all Texture.Unit[i]._GenFlags */
1317    GLbitfield _GenFlags;
1318 
1319    /** Largest index of a texture unit with _Current != NULL. */
1320    GLint _MaxEnabledTexImageUnit;
1321 
1322    /** Largest index + 1 of texture units that have had any CurrentTex set. */
1323    GLint NumCurrentTexUsed;
1324 
1325    struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
1326 };
1327 
1328 
1329 /**
1330  * Data structure representing a single clip plane (e.g. one of the elements
1331  * of the ctx->Transform.EyeUserPlane or ctx->Transform._ClipUserPlane array).
1332  */
1333 typedef GLfloat gl_clip_plane[4];
1334 
1335 
1336 /**
1337  * Transformation attribute group (GL_TRANSFORM_BIT).
1338  */
1339 struct gl_transform_attrib
1340 {
1341    GLenum MatrixMode;				/**< Matrix mode */
1342    gl_clip_plane EyeUserPlane[MAX_CLIP_PLANES];	/**< User clip planes */
1343    gl_clip_plane _ClipUserPlane[MAX_CLIP_PLANES]; /**< derived */
1344    GLbitfield ClipPlanesEnabled;                /**< on/off bitmask */
1345    GLboolean Normalize;				/**< Normalize all normals? */
1346    GLboolean RescaleNormals;			/**< GL_EXT_rescale_normal */
1347    GLboolean RasterPositionUnclipped;           /**< GL_IBM_rasterpos_clip */
1348    GLboolean DepthClamp;			/**< GL_ARB_depth_clamp */
1349    /** GL_ARB_clip_control */
1350    GLenum ClipOrigin;     /**< GL_LOWER_LEFT or GL_UPPER_LEFT */
1351    GLenum ClipDepthMode;  /**< GL_NEGATIVE_ONE_TO_ONE or GL_ZERO_TO_ONE */
1352 };
1353 
1354 
1355 /**
1356  * Viewport attribute group (GL_VIEWPORT_BIT).
1357  */
1358 struct gl_viewport_attrib
1359 {
1360    GLfloat X, Y;		/**< position */
1361    GLfloat Width, Height;	/**< size */
1362    GLdouble Near, Far;		/**< Depth buffer range */
1363 };
1364 
1365 
1366 typedef enum {
1367    MAP_USER,
1368    MAP_INTERNAL,
1369 
1370    MAP_COUNT
1371 } gl_map_buffer_index;
1372 
1373 
1374 /**
1375  * Fields describing a mapped buffer range.
1376  */
1377 struct gl_buffer_mapping {
1378    GLbitfield AccessFlags; /**< Mask of GL_MAP_x_BIT flags */
1379    GLvoid *Pointer;     /**< User-space address of mapping */
1380    GLintptr Offset;     /**< Mapped offset */
1381    GLsizeiptr Length;   /**< Mapped length */
1382 };
1383 
1384 
1385 /**
1386  * Usages we've seen for a buffer object.
1387  */
1388 typedef enum {
1389    USAGE_UNIFORM_BUFFER = 0x1,
1390    USAGE_TEXTURE_BUFFER = 0x2,
1391    USAGE_ATOMIC_COUNTER_BUFFER = 0x4,
1392    USAGE_SHADER_STORAGE_BUFFER = 0x8,
1393    USAGE_TRANSFORM_FEEDBACK_BUFFER = 0x10,
1394    USAGE_PIXEL_PACK_BUFFER = 0x20,
1395    USAGE_DISABLE_MINMAX_CACHE = 0x40,
1396 } gl_buffer_usage;
1397 
1398 
1399 /**
1400  * GL_ARB_vertex/pixel_buffer_object buffer object
1401  */
1402 struct gl_buffer_object
1403 {
1404    simple_mtx_t Mutex;
1405    GLint RefCount;
1406    GLuint Name;
1407    GLchar *Label;       /**< GL_KHR_debug */
1408    GLenum Usage;        /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */
1409    GLbitfield StorageFlags; /**< GL_MAP_PERSISTENT_BIT, etc. */
1410    GLsizeiptrARB Size;  /**< Size of buffer storage in bytes */
1411    GLubyte *Data;       /**< Location of storage either in RAM or VRAM. */
1412    GLboolean DeletePending;   /**< true if buffer object is removed from the hash */
1413    GLboolean Written;   /**< Ever written to? (for debugging) */
1414    GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */
1415    GLboolean Immutable; /**< GL_ARB_buffer_storage */
1416    gl_buffer_usage UsageHistory; /**< How has this buffer been used so far? */
1417 
1418    /** Counters used for buffer usage warnings */
1419    GLuint NumSubDataCalls;
1420    GLuint NumMapBufferWriteCalls;
1421 
1422    struct gl_buffer_mapping Mappings[MAP_COUNT];
1423 
1424    /** Memoization of min/max index computations for static index buffers */
1425    struct hash_table *MinMaxCache;
1426    unsigned MinMaxCacheHitIndices;
1427    unsigned MinMaxCacheMissIndices;
1428    bool MinMaxCacheDirty;
1429 
1430    bool HandleAllocated; /**< GL_ARB_bindless_texture */
1431 };
1432 
1433 
1434 /**
1435  * Client pixel packing/unpacking attributes
1436  */
1437 struct gl_pixelstore_attrib
1438 {
1439    GLint Alignment;
1440    GLint RowLength;
1441    GLint SkipPixels;
1442    GLint SkipRows;
1443    GLint ImageHeight;
1444    GLint SkipImages;
1445    GLboolean SwapBytes;
1446    GLboolean LsbFirst;
1447    GLboolean Invert;        /**< GL_MESA_pack_invert */
1448    GLint CompressedBlockWidth;   /**< GL_ARB_compressed_texture_pixel_storage */
1449    GLint CompressedBlockHeight;
1450    GLint CompressedBlockDepth;
1451    GLint CompressedBlockSize;
1452    struct gl_buffer_object *BufferObj; /**< GL_ARB_pixel_buffer_object */
1453 };
1454 
1455 
1456 /**
1457  * Vertex array information which is derived from gl_array_attributes
1458  * and gl_vertex_buffer_binding information.  Used by the VBO module and
1459  * device drivers.
1460  */
1461 struct gl_vertex_array
1462 {
1463    GLint Size;                  /**< components per element (1,2,3,4) */
1464    GLenum Type;                 /**< datatype: GL_FLOAT, GL_INT, etc */
1465    GLenum Format;               /**< default: GL_RGBA, but may be GL_BGRA */
1466    GLsizei StrideB;		/**< actual stride in bytes */
1467    GLuint _ElementSize;         /**< size of each element in bytes */
1468    const GLubyte *Ptr;          /**< Points to array data */
1469    GLboolean Normalized;        /**< GL_ARB_vertex_program */
1470    GLboolean Integer;           /**< Integer-valued? */
1471    GLboolean Doubles;       /**< double precision values are not converted to floats */
1472    GLuint InstanceDivisor;      /**< GL_ARB_instanced_arrays */
1473 
1474    struct gl_buffer_object *BufferObj;/**< GL_ARB_vertex_buffer_object */
1475 };
1476 
1477 
1478 /**
1479  * Attributes to describe a vertex array.
1480  *
1481  * Contains the size, type, format and normalization flag,
1482  * along with the index of a vertex buffer binding point.
1483  *
1484  * Note that the Stride field corresponds to VERTEX_ATTRIB_ARRAY_STRIDE
1485  * and is only present for backwards compatibility reasons.
1486  * Rendering always uses VERTEX_BINDING_STRIDE.
1487  * The gl*Pointer() functions will set VERTEX_ATTRIB_ARRAY_STRIDE
1488  * and VERTEX_BINDING_STRIDE to the same value, while
1489  * glBindVertexBuffer() will only set VERTEX_BINDING_STRIDE.
1490  */
1491 struct gl_array_attributes
1492 {
1493    GLint Size;              /**< Components per element (1,2,3,4) */
1494    GLenum Type;             /**< Datatype: GL_FLOAT, GL_INT, etc */
1495    GLenum Format;           /**< Default: GL_RGBA, but may be GL_BGRA */
1496    GLsizei Stride;          /**< Stride as specified with gl*Pointer() */
1497    const GLubyte *Ptr;      /**< Points to client array data. Not used when a VBO is bound */
1498    GLintptr RelativeOffset; /**< Offset of the first element relative to the binding offset */
1499    GLboolean Enabled;       /**< Whether the array is enabled */
1500    GLboolean Normalized;    /**< Fixed-point values are normalized when converted to floats */
1501    GLboolean Integer;       /**< Fixed-point values are not converted to floats */
1502    GLboolean Doubles;       /**< double precision values are not converted to floats */
1503    GLuint _ElementSize;     /**< Size of each element in bytes */
1504    GLuint BufferBindingIndex;    /**< Vertex buffer binding */
1505 };
1506 
1507 
1508 /**
1509  * This describes the buffer object used for a vertex array (or
1510  * multiple vertex arrays).  If BufferObj points to the default/null
1511  * buffer object, then the vertex array lives in user memory and not a VBO.
1512  */
1513 struct gl_vertex_buffer_binding
1514 {
1515    GLintptr Offset;                    /**< User-specified offset */
1516    GLsizei Stride;                     /**< User-specified stride */
1517    GLuint InstanceDivisor;             /**< GL_ARB_instanced_arrays */
1518    struct gl_buffer_object *BufferObj; /**< GL_ARB_vertex_buffer_object */
1519    GLbitfield _BoundArrays;            /**< Arrays bound to this binding point */
1520 };
1521 
1522 
1523 /**
1524  * A representation of "Vertex Array Objects" (VAOs) from OpenGL 3.1+ /
1525  * the GL_ARB_vertex_array_object extension.
1526  */
1527 struct gl_vertex_array_object
1528 {
1529    /** Name of the VAO as received from glGenVertexArray. */
1530    GLuint Name;
1531 
1532    GLint RefCount;
1533 
1534    GLchar *Label;       /**< GL_KHR_debug */
1535 
1536    /**
1537     * Has this array object been bound?
1538     */
1539    GLboolean EverBound;
1540 
1541    /**
1542     * Derived vertex attribute arrays
1543     *
1544     * This is a legacy data structure created from gl_vertex_attrib_array and
1545     * gl_vertex_buffer_binding, for compatibility with existing driver code.
1546     */
1547    struct gl_vertex_array _VertexAttrib[VERT_ATTRIB_MAX];
1548 
1549    /** Vertex attribute arrays */
1550    struct gl_array_attributes VertexAttrib[VERT_ATTRIB_MAX];
1551 
1552    /** Vertex buffer bindings */
1553    struct gl_vertex_buffer_binding BufferBinding[VERT_ATTRIB_MAX];
1554 
1555    /** Mask indicating which vertex arrays have vertex buffer associated. */
1556    GLbitfield VertexAttribBufferMask;
1557 
1558    /** Mask of VERT_BIT_* values indicating which arrays are enabled */
1559    GLbitfield _Enabled;
1560 
1561    /** Mask of VERT_BIT_* values indicating changed/dirty arrays */
1562    GLbitfield NewArrays;
1563 
1564    /** The index buffer (also known as the element array buffer in OpenGL). */
1565    struct gl_buffer_object *IndexBufferObj;
1566 };
1567 
1568 
1569 /** Used to signal when transitioning from one kind of drawing method
1570  * to another.
1571  */
1572 typedef enum {
1573    DRAW_NONE,          /**< Initial value only */
1574    DRAW_BEGIN_END,
1575    DRAW_DISPLAY_LIST,
1576    DRAW_ARRAYS
1577 } gl_draw_method;
1578 
1579 /**
1580  * Enum for the OpenGL APIs we know about and may support.
1581  *
1582  * NOTE: This must match the api_enum table in
1583  * src/mesa/main/get_hash_generator.py
1584  */
1585 typedef enum
1586 {
1587    API_OPENGL_COMPAT,      /* legacy / compatibility contexts */
1588    API_OPENGLES,
1589    API_OPENGLES2,
1590    API_OPENGL_CORE,
1591    API_OPENGL_LAST = API_OPENGL_CORE
1592 } gl_api;
1593 
1594 /**
1595  * Vertex array state
1596  */
1597 struct gl_array_attrib
1598 {
1599    /** Currently bound array object. */
1600    struct gl_vertex_array_object *VAO;
1601 
1602    /** The default vertex array object */
1603    struct gl_vertex_array_object *DefaultVAO;
1604 
1605    /** The last VAO accessed by a DSA function */
1606    struct gl_vertex_array_object *LastLookedUpVAO;
1607 
1608    /** Array objects (GL_ARB_vertex_array_object) */
1609    struct _mesa_HashTable *Objects;
1610 
1611    GLint ActiveTexture;		/**< Client Active Texture */
1612    GLuint LockFirst;            /**< GL_EXT_compiled_vertex_array */
1613    GLuint LockCount;            /**< GL_EXT_compiled_vertex_array */
1614 
1615    /**
1616     * \name Primitive restart controls
1617     *
1618     * Primitive restart is enabled if either \c PrimitiveRestart or
1619     * \c PrimitiveRestartFixedIndex is set.
1620     */
1621    /*@{*/
1622    GLboolean PrimitiveRestart;
1623    GLboolean PrimitiveRestartFixedIndex;
1624    GLboolean _PrimitiveRestart;
1625    GLuint RestartIndex;
1626    /*@}*/
1627 
1628    /** One of the DRAW_xxx flags, not consumed by drivers */
1629    gl_draw_method DrawMethod;
1630 
1631    /* GL_ARB_vertex_buffer_object */
1632    struct gl_buffer_object *ArrayBufferObj;
1633 
1634    /**
1635     * Vertex arrays as consumed by a driver.
1636     * The array pointer is set up only by the VBO module.
1637     */
1638    const struct gl_vertex_array **_DrawArrays; /**< 0..VERT_ATTRIB_MAX-1 */
1639 
1640    /** Legal array datatypes and the API for which they have been computed */
1641    GLbitfield LegalTypesMask;
1642    gl_api LegalTypesMaskAPI;
1643 };
1644 
1645 
1646 /**
1647  * Feedback buffer state
1648  */
1649 struct gl_feedback
1650 {
1651    GLenum Type;
1652    GLbitfield _Mask;    /**< FB_* bits */
1653    GLfloat *Buffer;
1654    GLuint BufferSize;
1655    GLuint Count;
1656 };
1657 
1658 
1659 /**
1660  * Selection buffer state
1661  */
1662 struct gl_selection
1663 {
1664    GLuint *Buffer;	/**< selection buffer */
1665    GLuint BufferSize;	/**< size of the selection buffer */
1666    GLuint BufferCount;	/**< number of values in the selection buffer */
1667    GLuint Hits;		/**< number of records in the selection buffer */
1668    GLuint NameStackDepth; /**< name stack depth */
1669    GLuint NameStack[MAX_NAME_STACK_DEPTH]; /**< name stack */
1670    GLboolean HitFlag;	/**< hit flag */
1671    GLfloat HitMinZ;	/**< minimum hit depth */
1672    GLfloat HitMaxZ;	/**< maximum hit depth */
1673 };
1674 
1675 
1676 /**
1677  * 1-D Evaluator control points
1678  */
1679 struct gl_1d_map
1680 {
1681    GLuint Order;	/**< Number of control points */
1682    GLfloat u1, u2, du;	/**< u1, u2, 1.0/(u2-u1) */
1683    GLfloat *Points;	/**< Points to contiguous control points */
1684 };
1685 
1686 
1687 /**
1688  * 2-D Evaluator control points
1689  */
1690 struct gl_2d_map
1691 {
1692    GLuint Uorder;		/**< Number of control points in U dimension */
1693    GLuint Vorder;		/**< Number of control points in V dimension */
1694    GLfloat u1, u2, du;
1695    GLfloat v1, v2, dv;
1696    GLfloat *Points;		/**< Points to contiguous control points */
1697 };
1698 
1699 
1700 /**
1701  * All evaluator control point state
1702  */
1703 struct gl_evaluators
1704 {
1705    /**
1706     * \name 1-D maps
1707     */
1708    /*@{*/
1709    struct gl_1d_map Map1Vertex3;
1710    struct gl_1d_map Map1Vertex4;
1711    struct gl_1d_map Map1Index;
1712    struct gl_1d_map Map1Color4;
1713    struct gl_1d_map Map1Normal;
1714    struct gl_1d_map Map1Texture1;
1715    struct gl_1d_map Map1Texture2;
1716    struct gl_1d_map Map1Texture3;
1717    struct gl_1d_map Map1Texture4;
1718    /*@}*/
1719 
1720    /**
1721     * \name 2-D maps
1722     */
1723    /*@{*/
1724    struct gl_2d_map Map2Vertex3;
1725    struct gl_2d_map Map2Vertex4;
1726    struct gl_2d_map Map2Index;
1727    struct gl_2d_map Map2Color4;
1728    struct gl_2d_map Map2Normal;
1729    struct gl_2d_map Map2Texture1;
1730    struct gl_2d_map Map2Texture2;
1731    struct gl_2d_map Map2Texture3;
1732    struct gl_2d_map Map2Texture4;
1733    /*@}*/
1734 };
1735 
1736 
1737 struct gl_transform_feedback_varying_info
1738 {
1739    char *Name;
1740    GLenum Type;
1741    GLint BufferIndex;
1742    GLint Size;
1743    GLint Offset;
1744 };
1745 
1746 
1747 /**
1748  * Per-output info vertex shaders for transform feedback.
1749  */
1750 struct gl_transform_feedback_output
1751 {
1752    uint32_t OutputRegister;
1753    uint32_t OutputBuffer;
1754    uint32_t NumComponents;
1755    uint32_t StreamId;
1756 
1757    /** offset (in DWORDs) of this output within the interleaved structure */
1758    uint32_t DstOffset;
1759 
1760    /**
1761     * Offset into the output register of the data to output.  For example,
1762     * if NumComponents is 2 and ComponentOffset is 1, then the data to
1763     * offset is in the y and z components of the output register.
1764     */
1765    uint32_t ComponentOffset;
1766 };
1767 
1768 
1769 struct gl_transform_feedback_buffer
1770 {
1771    uint32_t Binding;
1772 
1773    uint32_t NumVaryings;
1774 
1775    /**
1776     * Total number of components stored in each buffer.  This may be used by
1777     * hardware back-ends to determine the correct stride when interleaving
1778     * multiple transform feedback outputs in the same buffer.
1779     */
1780    uint32_t Stride;
1781 
1782    /**
1783     * Which transform feedback stream this buffer binding is associated with.
1784     */
1785    uint32_t Stream;
1786 };
1787 
1788 
1789 /** Post-link transform feedback info. */
1790 struct gl_transform_feedback_info
1791 {
1792    /* Was xfb enabled via the api or in shader layout qualifiers */
1793    bool api_enabled;
1794 
1795    unsigned NumOutputs;
1796 
1797    /* Bitmask of active buffer indices. */
1798    unsigned ActiveBuffers;
1799 
1800    struct gl_transform_feedback_output *Outputs;
1801 
1802    /** Transform feedback varyings used for the linking of this shader program.
1803     *
1804     * Use for glGetTransformFeedbackVarying().
1805     */
1806    struct gl_transform_feedback_varying_info *Varyings;
1807    GLint NumVarying;
1808 
1809    struct gl_transform_feedback_buffer Buffers[MAX_FEEDBACK_BUFFERS];
1810 };
1811 
1812 
1813 /**
1814  * Transform feedback object state
1815  */
1816 struct gl_transform_feedback_object
1817 {
1818    GLuint Name;  /**< AKA the object ID */
1819    GLint RefCount;
1820    GLchar *Label;     /**< GL_KHR_debug */
1821    GLboolean Active;  /**< Is transform feedback enabled? */
1822    GLboolean Paused;  /**< Is transform feedback paused? */
1823    GLboolean EndedAnytime; /**< Has EndTransformFeedback been called
1824                                 at least once? */
1825    GLboolean EverBound; /**< Has this object been bound? */
1826 
1827    /**
1828     * GLES: if Active is true, remaining number of primitives which can be
1829     * rendered without overflow.  This is necessary to track because GLES
1830     * requires us to generate INVALID_OPERATION if a call to glDrawArrays or
1831     * glDrawArraysInstanced would overflow transform feedback buffers.
1832     * Undefined if Active is false.
1833     *
1834     * Not tracked for desktop GL since it's unnecessary.
1835     */
1836    unsigned GlesRemainingPrims;
1837 
1838    /**
1839     * The program active when BeginTransformFeedback() was called.
1840     * When active and unpaused, this equals ctx->Shader.CurrentProgram[stage],
1841     * where stage is the pipeline stage that is the source of data for
1842     * transform feedback.
1843     */
1844    struct gl_program *program;
1845 
1846    /** The feedback buffers */
1847    GLuint BufferNames[MAX_FEEDBACK_BUFFERS];
1848    struct gl_buffer_object *Buffers[MAX_FEEDBACK_BUFFERS];
1849 
1850    /** Start of feedback data in dest buffer */
1851    GLintptr Offset[MAX_FEEDBACK_BUFFERS];
1852 
1853    /**
1854     * Max data to put into dest buffer (in bytes).  Computed based on
1855     * RequestedSize and the actual size of the buffer.
1856     */
1857    GLsizeiptr Size[MAX_FEEDBACK_BUFFERS];
1858 
1859    /**
1860     * Size that was specified when the buffer was bound.  If the buffer was
1861     * bound with glBindBufferBase() or glBindBufferOffsetEXT(), this value is
1862     * zero.
1863     */
1864    GLsizeiptr RequestedSize[MAX_FEEDBACK_BUFFERS];
1865 };
1866 
1867 
1868 /**
1869  * Context state for transform feedback.
1870  */
1871 struct gl_transform_feedback_state
1872 {
1873    GLenum Mode;       /**< GL_POINTS, GL_LINES or GL_TRIANGLES */
1874 
1875    /** The general binding point (GL_TRANSFORM_FEEDBACK_BUFFER) */
1876    struct gl_buffer_object *CurrentBuffer;
1877 
1878    /** The table of all transform feedback objects */
1879    struct _mesa_HashTable *Objects;
1880 
1881    /** The current xform-fb object (GL_TRANSFORM_FEEDBACK_BINDING) */
1882    struct gl_transform_feedback_object *CurrentObject;
1883 
1884    /** The default xform-fb object (Name==0) */
1885    struct gl_transform_feedback_object *DefaultObject;
1886 };
1887 
1888 
1889 /**
1890  * A "performance monitor" as described in AMD_performance_monitor.
1891  */
1892 struct gl_perf_monitor_object
1893 {
1894    GLuint Name;
1895 
1896    /** True if the monitor is currently active (Begin called but not End). */
1897    GLboolean Active;
1898 
1899    /**
1900     * True if the monitor has ended.
1901     *
1902     * This is distinct from !Active because it may never have began.
1903     */
1904    GLboolean Ended;
1905 
1906    /**
1907     * A list of groups with currently active counters.
1908     *
1909     * ActiveGroups[g] == n if there are n counters active from group 'g'.
1910     */
1911    unsigned *ActiveGroups;
1912 
1913    /**
1914     * An array of bitsets, subscripted by group ID, then indexed by counter ID.
1915     *
1916     * Checking whether counter 'c' in group 'g' is active can be done via:
1917     *
1918     *    BITSET_TEST(ActiveCounters[g], c)
1919     */
1920    GLuint **ActiveCounters;
1921 };
1922 
1923 
1924 union gl_perf_monitor_counter_value
1925 {
1926    float f;
1927    uint64_t u64;
1928    uint32_t u32;
1929 };
1930 
1931 
1932 struct gl_perf_monitor_counter
1933 {
1934    /** Human readable name for the counter. */
1935    const char *Name;
1936 
1937    /**
1938     * Data type of the counter.  Valid values are FLOAT, UNSIGNED_INT,
1939     * UNSIGNED_INT64_AMD, and PERCENTAGE_AMD.
1940     */
1941    GLenum Type;
1942 
1943    /** Minimum counter value. */
1944    union gl_perf_monitor_counter_value Minimum;
1945 
1946    /** Maximum counter value. */
1947    union gl_perf_monitor_counter_value Maximum;
1948 };
1949 
1950 
1951 struct gl_perf_monitor_group
1952 {
1953    /** Human readable name for the group. */
1954    const char *Name;
1955 
1956    /**
1957     * Maximum number of counters in this group which can be active at the
1958     * same time.
1959     */
1960    GLuint MaxActiveCounters;
1961 
1962    /** Array of counters within this group. */
1963    const struct gl_perf_monitor_counter *Counters;
1964    GLuint NumCounters;
1965 };
1966 
1967 
1968 /**
1969  * A query object instance as described in INTEL_performance_query.
1970  *
1971  * NB: We want to keep this and the corresponding backend structure
1972  * relatively lean considering that applications may expect to
1973  * allocate enough objects to be able to query around all draw calls
1974  * in a frame.
1975  */
1976 struct gl_perf_query_object
1977 {
1978    GLuint Id;          /**< hash table ID/name */
1979    unsigned Used:1;    /**< has been used for 1 or more queries */
1980    unsigned Active:1;  /**< inside Begin/EndPerfQuery */
1981    unsigned Ready:1;   /**< result is ready? */
1982 };
1983 
1984 
1985 /**
1986  * Context state for AMD_performance_monitor.
1987  */
1988 struct gl_perf_monitor_state
1989 {
1990    /** Array of performance monitor groups (indexed by group ID) */
1991    const struct gl_perf_monitor_group *Groups;
1992    GLuint NumGroups;
1993 
1994    /** The table of all performance monitors. */
1995    struct _mesa_HashTable *Monitors;
1996 };
1997 
1998 
1999 /**
2000  * Context state for INTEL_performance_query.
2001  */
2002 struct gl_perf_query_state
2003 {
2004    struct _mesa_HashTable *Objects; /**< The table of all performance query objects */
2005 };
2006 
2007 
2008 /**
2009  * A bindless sampler object.
2010  */
2011 struct gl_bindless_sampler
2012 {
2013    /** Texture unit (set by glUniform1()). */
2014    GLubyte unit;
2015 
2016    /** Whether this bindless sampler is bound to a unit. */
2017    GLboolean bound;
2018 
2019    /** Texture Target (TEXTURE_1D/2D/3D/etc_INDEX). */
2020    gl_texture_index target;
2021 
2022    /** Pointer to the base of the data. */
2023    GLvoid *data;
2024 };
2025 
2026 /**
2027  * A bindless image object.
2028  */
2029 struct gl_bindless_image
2030 {
2031    /** Image unit (set by glUniform1()). */
2032    GLubyte unit;
2033 
2034    /** Whether this bindless image is bound to a unit. */
2035    GLboolean bound;
2036 
2037    /** Access qualifier (GL_READ_WRITE, GL_READ_ONLY, GL_WRITE_ONLY) */
2038    GLenum access;
2039 
2040    /** Pointer to the base of the data. */
2041    GLvoid *data;
2042 };
2043 
2044 /**
2045  * Names of the various vertex/fragment program register files, etc.
2046  *
2047  * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
2048  * All values should fit in a 4-bit field.
2049  *
2050  * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be
2051  * considered to be "uniform" variables since they can only be set outside
2052  * glBegin/End.  They're also all stored in the same Parameters array.
2053  */
2054 typedef enum
2055 {
2056    PROGRAM_TEMPORARY,   /**< machine->Temporary[] */
2057    PROGRAM_ARRAY,       /**< Arrays & Matrixes */
2058    PROGRAM_INPUT,       /**< machine->Inputs[] */
2059    PROGRAM_OUTPUT,      /**< machine->Outputs[] */
2060    PROGRAM_STATE_VAR,   /**< gl_program->Parameters[] */
2061    PROGRAM_CONSTANT,    /**< gl_program->Parameters[] */
2062    PROGRAM_UNIFORM,     /**< gl_program->Parameters[] */
2063    PROGRAM_WRITE_ONLY,  /**< A dummy, write-only register */
2064    PROGRAM_ADDRESS,     /**< machine->AddressReg */
2065    PROGRAM_SAMPLER,     /**< for shader samplers, compile-time only */
2066    PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */
2067    PROGRAM_UNDEFINED,   /**< Invalid/TBD value */
2068    PROGRAM_IMMEDIATE,   /**< Immediate value, used by TGSI */
2069    PROGRAM_BUFFER,      /**< for shader buffers, compile-time only */
2070    PROGRAM_MEMORY,      /**< for shared, global and local memory */
2071    PROGRAM_IMAGE,       /**< for shader images, compile-time only */
2072    PROGRAM_HW_ATOMIC,   /**< for hw atomic counters, compile-time only */
2073    PROGRAM_FILE_MAX
2074 } gl_register_file;
2075 
2076 
2077 /**
2078  * Base class for any kind of program object
2079  */
2080 struct gl_program
2081 {
2082    /** FIXME: This must be first until we split shader_info from nir_shader */
2083    struct shader_info info;
2084 
2085    GLuint Id;
2086    GLint RefCount;
2087    GLubyte *String;  /**< Null-terminated program text */
2088 
2089    GLenum Target;    /**< GL_VERTEX/FRAGMENT_PROGRAM_ARB, GL_GEOMETRY_PROGRAM_NV */
2090    GLenum Format;    /**< String encoding format */
2091 
2092    GLboolean _Used;        /**< Ever used for drawing? Used for debugging */
2093 
2094    struct nir_shader *nir;
2095 
2096    /* Saved and restored with metadata. Freed with ralloc. */
2097    void *driver_cache_blob;
2098    size_t driver_cache_blob_size;
2099 
2100    bool is_arb_asm; /** Is this an ARB assembly-style program */
2101 
2102    /** Is this program written to on disk shader cache */
2103    bool program_written_to_cache;
2104 
2105    GLbitfield64 SecondaryOutputsWritten; /**< Subset of OutputsWritten outputs written with non-zero index. */
2106    GLbitfield TexturesUsed[MAX_COMBINED_TEXTURE_IMAGE_UNITS];  /**< TEXTURE_x_BIT bitmask */
2107    GLbitfield SamplersUsed;   /**< Bitfield of which samplers are used */
2108    GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */
2109    GLbitfield ExternalSamplersUsed; /**< Texture units used for samplerExternalOES */
2110 
2111    /* Fragement shader only fields */
2112    GLboolean OriginUpperLeft;
2113    GLboolean PixelCenterInteger;
2114 
2115    /** Named parameters, constants, etc. from program text */
2116    struct gl_program_parameter_list *Parameters;
2117 
2118    /** Map from sampler unit to texture unit (set by glUniform1i()) */
2119    GLubyte SamplerUnits[MAX_SAMPLERS];
2120 
2121    /* FIXME: We should be able to make this struct a union. However some
2122     * drivers (i915/fragment_programs, swrast/prog_execute) mix the use of
2123     * these fields, we should fix this.
2124     */
2125    struct {
2126       /** Fields used by GLSL programs */
2127       struct {
2128          /** Data shared by gl_program and gl_shader_program */
2129          struct gl_shader_program_data *data;
2130 
2131          struct gl_active_atomic_buffer **AtomicBuffers;
2132 
2133          /** Post-link transform feedback info. */
2134          struct gl_transform_feedback_info *LinkedTransformFeedback;
2135 
2136          /**
2137           * Number of types for subroutine uniforms.
2138           */
2139          GLuint NumSubroutineUniformTypes;
2140 
2141          /**
2142           * Subroutine uniform remap table
2143           * based on the program level uniform remap table.
2144           */
2145          GLuint NumSubroutineUniforms; /* non-sparse total */
2146          GLuint NumSubroutineUniformRemapTable;
2147          struct gl_uniform_storage **SubroutineUniformRemapTable;
2148 
2149          /**
2150           * Num of subroutine functions for this stage and storage for them.
2151           */
2152          GLuint NumSubroutineFunctions;
2153          GLuint MaxSubroutineFunctionIndex;
2154          struct gl_subroutine_function *SubroutineFunctions;
2155 
2156          /**
2157           * Map from image uniform index to image unit (set by glUniform1i())
2158           *
2159           * An image uniform index is associated with each image uniform by
2160           * the linker.  The image index associated with each uniform is
2161           * stored in the \c gl_uniform_storage::image field.
2162           */
2163          GLubyte ImageUnits[MAX_IMAGE_UNIFORMS];
2164 
2165          /**
2166           * Access qualifier specified in the shader for each image uniform
2167           * index.  Either \c GL_READ_ONLY, \c GL_WRITE_ONLY or \c
2168           * GL_READ_WRITE.
2169           *
2170           * It may be different, though only more strict than the value of
2171           * \c gl_image_unit::Access for the corresponding image unit.
2172           */
2173          GLenum ImageAccess[MAX_IMAGE_UNIFORMS];
2174 
2175          struct gl_uniform_block **UniformBlocks;
2176          struct gl_uniform_block **ShaderStorageBlocks;
2177 
2178          /** Which texture target is being sampled
2179           * (TEXTURE_1D/2D/3D/etc_INDEX)
2180           */
2181          gl_texture_index SamplerTargets[MAX_SAMPLERS];
2182 
2183          /**
2184           * Number of samplers declared with the bindless_sampler layout
2185           * qualifier as specified by ARB_bindless_texture.
2186           */
2187          GLuint NumBindlessSamplers;
2188          GLboolean HasBoundBindlessSampler;
2189          struct gl_bindless_sampler *BindlessSamplers;
2190 
2191          /**
2192           * Number of images declared with the bindless_image layout qualifier
2193           * as specified by ARB_bindless_texture.
2194           */
2195          GLuint NumBindlessImages;
2196          GLboolean HasBoundBindlessImage;
2197          struct gl_bindless_image *BindlessImages;
2198 
2199          union {
2200             struct {
2201                /**
2202                 * A bitmask of gl_advanced_blend_mode values
2203                 */
2204                GLbitfield BlendSupport;
2205             } fs;
2206          };
2207       } sh;
2208 
2209       /** ARB assembly-style program fields */
2210       struct {
2211          struct prog_instruction *Instructions;
2212 
2213          /**
2214           * Local parameters used by the program.
2215           *
2216           * It's dynamically allocated because it is rarely used (just
2217           * assembly-style programs), and MAX_PROGRAM_LOCAL_PARAMS entries
2218           * once it's allocated.
2219           */
2220          GLfloat (*LocalParams)[4];
2221 
2222          /** Bitmask of which register files are read/written with indirect
2223           * addressing.  Mask of (1 << PROGRAM_x) bits.
2224           */
2225          GLbitfield IndirectRegisterFiles;
2226 
2227          /** Logical counts */
2228          /*@{*/
2229          GLuint NumInstructions;
2230          GLuint NumTemporaries;
2231          GLuint NumParameters;
2232          GLuint NumAttributes;
2233          GLuint NumAddressRegs;
2234          GLuint NumAluInstructions;
2235          GLuint NumTexInstructions;
2236          GLuint NumTexIndirections;
2237          /*@}*/
2238          /** Native, actual h/w counts */
2239          /*@{*/
2240          GLuint NumNativeInstructions;
2241          GLuint NumNativeTemporaries;
2242          GLuint NumNativeParameters;
2243          GLuint NumNativeAttributes;
2244          GLuint NumNativeAddressRegs;
2245          GLuint NumNativeAluInstructions;
2246          GLuint NumNativeTexInstructions;
2247          GLuint NumNativeTexIndirections;
2248          /*@}*/
2249 
2250          /** Used by ARB assembly-style programs. Can only be true for vertex
2251           * programs.
2252           */
2253          GLboolean IsPositionInvariant;
2254       } arb;
2255    };
2256 };
2257 
2258 
2259 /**
2260  * State common to vertex and fragment programs.
2261  */
2262 struct gl_program_state
2263 {
2264    GLint ErrorPos;                       /* GL_PROGRAM_ERROR_POSITION_ARB/NV */
2265    const char *ErrorString;              /* GL_PROGRAM_ERROR_STRING_ARB/NV */
2266 };
2267 
2268 
2269 /**
2270  * Context state for vertex programs.
2271  */
2272 struct gl_vertex_program_state
2273 {
2274    GLboolean Enabled;            /**< User-set GL_VERTEX_PROGRAM_ARB/NV flag */
2275    GLboolean PointSizeEnabled;   /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
2276    GLboolean TwoSideEnabled;     /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
2277    /** Should fixed-function T&L be implemented with a vertex prog? */
2278    GLboolean _MaintainTnlProgram;
2279 
2280    struct gl_program *Current;  /**< User-bound vertex program */
2281 
2282    /** Currently enabled and valid vertex program (including internal
2283     * programs, user-defined vertex programs and GLSL vertex shaders).
2284     * This is the program we must use when rendering.
2285     */
2286    struct gl_program *_Current;
2287 
2288    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
2289 
2290    /** Program to emulate fixed-function T&L (see above) */
2291    struct gl_program *_TnlProgram;
2292 
2293    /** Cache of fixed-function programs */
2294    struct gl_program_cache *Cache;
2295 
2296    GLboolean _Overriden;
2297 };
2298 
2299 /**
2300  * Context state for tessellation control programs.
2301  */
2302 struct gl_tess_ctrl_program_state
2303 {
2304    /** Currently bound and valid shader. */
2305    struct gl_program *_Current;
2306 
2307    GLint patch_vertices;
2308    GLfloat patch_default_outer_level[4];
2309    GLfloat patch_default_inner_level[2];
2310 };
2311 
2312 /**
2313  * Context state for tessellation evaluation programs.
2314  */
2315 struct gl_tess_eval_program_state
2316 {
2317    /** Currently bound and valid shader. */
2318    struct gl_program *_Current;
2319 };
2320 
2321 /**
2322  * Context state for geometry programs.
2323  */
2324 struct gl_geometry_program_state
2325 {
2326    /** Currently enabled and valid program (including internal programs
2327     * and compiled shader programs).
2328     */
2329    struct gl_program *_Current;
2330 };
2331 
2332 /**
2333  * Context state for fragment programs.
2334  */
2335 struct gl_fragment_program_state
2336 {
2337    GLboolean Enabled;     /**< User-set fragment program enable flag */
2338    /** Should fixed-function texturing be implemented with a fragment prog? */
2339    GLboolean _MaintainTexEnvProgram;
2340 
2341    struct gl_program *Current;  /**< User-bound fragment program */
2342 
2343    /** Currently enabled and valid fragment program (including internal
2344     * programs, user-defined fragment programs and GLSL fragment shaders).
2345     * This is the program we must use when rendering.
2346     */
2347    struct gl_program *_Current;
2348 
2349    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
2350 
2351    /** Program to emulate fixed-function texture env/combine (see above) */
2352    struct gl_program *_TexEnvProgram;
2353 
2354    /** Cache of fixed-function programs */
2355    struct gl_program_cache *Cache;
2356 };
2357 
2358 
2359 /**
2360  * Context state for compute programs.
2361  */
2362 struct gl_compute_program_state
2363 {
2364    /** Currently enabled and valid program (including internal programs
2365     * and compiled shader programs).
2366     */
2367    struct gl_program *_Current;
2368 };
2369 
2370 
2371 /**
2372  * ATI_fragment_shader runtime state
2373  */
2374 
2375 struct atifs_instruction;
2376 struct atifs_setupinst;
2377 
2378 /**
2379  * ATI fragment shader
2380  */
2381 struct ati_fragment_shader
2382 {
2383    GLuint Id;
2384    GLint RefCount;
2385    struct atifs_instruction *Instructions[2];
2386    struct atifs_setupinst *SetupInst[2];
2387    GLfloat Constants[8][4];
2388    GLbitfield LocalConstDef;  /**< Indicates which constants have been set */
2389    GLubyte numArithInstr[2];
2390    GLubyte regsAssigned[2];
2391    GLubyte NumPasses;         /**< 1 or 2 */
2392    /** Current compile stage: 0 setup pass1, 1 arith pass1, 2 setup pass2, 3 arith pass2 */
2393    GLubyte cur_pass;
2394    GLubyte last_optype;
2395    GLboolean interpinp1;
2396    GLboolean isValid;
2397    /** Array of 2 bit values for each tex unit to remember whether
2398     * STR or STQ swizzle was used
2399     */
2400    GLuint swizzlerq;
2401    struct gl_program *Program;
2402 };
2403 
2404 /**
2405  * Context state for GL_ATI_fragment_shader
2406  */
2407 struct gl_ati_fragment_shader_state
2408 {
2409    GLboolean Enabled;
2410    GLboolean Compiling;
2411    GLfloat GlobalConstants[8][4];
2412    struct ati_fragment_shader *Current;
2413 };
2414 
2415 /**
2416  *  Shader subroutine function definition
2417  */
2418 struct gl_subroutine_function
2419 {
2420    char *name;
2421    int index;
2422    int num_compat_types;
2423    const struct glsl_type **types;
2424 };
2425 
2426 /**
2427  * Shader information needed by both gl_shader and gl_linked shader.
2428  */
2429 struct gl_shader_info
2430 {
2431    /**
2432     * Tessellation Control shader state from layout qualifiers.
2433     */
2434    struct {
2435       /**
2436        * 0 - vertices not declared in shader, or
2437        * 1 .. GL_MAX_PATCH_VERTICES
2438        */
2439       GLint VerticesOut;
2440    } TessCtrl;
2441 
2442    /**
2443     * Tessellation Evaluation shader state from layout qualifiers.
2444     */
2445    struct {
2446       /**
2447        * GL_TRIANGLES, GL_QUADS, GL_ISOLINES or PRIM_UNKNOWN if it's not set
2448        * in this shader.
2449        */
2450       GLenum PrimitiveMode;
2451 
2452       enum gl_tess_spacing Spacing;
2453 
2454       /**
2455        * GL_CW, GL_CCW, or 0 if it's not set in this shader.
2456        */
2457       GLenum VertexOrder;
2458       /**
2459        * 1, 0, or -1 if it's not set in this shader.
2460        */
2461       int PointMode;
2462    } TessEval;
2463 
2464    /**
2465     * Geometry shader state from GLSL 1.50 layout qualifiers.
2466     */
2467    struct {
2468       GLint VerticesOut;
2469       /**
2470        * 0 - Invocations count not declared in shader, or
2471        * 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS
2472        */
2473       GLint Invocations;
2474       /**
2475        * GL_POINTS, GL_LINES, GL_LINES_ADJACENCY, GL_TRIANGLES, or
2476        * GL_TRIANGLES_ADJACENCY, or PRIM_UNKNOWN if it's not set in this
2477        * shader.
2478        */
2479       GLenum InputType;
2480        /**
2481         * GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP, or PRIM_UNKNOWN if
2482         * it's not set in this shader.
2483         */
2484       GLenum OutputType;
2485    } Geom;
2486 
2487    /**
2488     * Compute shader state from ARB_compute_shader and
2489     * ARB_compute_variable_group_size layout qualifiers.
2490     */
2491    struct {
2492       /**
2493        * Size specified using local_size_{x,y,z}, or all 0's to indicate that
2494        * it's not set in this shader.
2495        */
2496       unsigned LocalSize[3];
2497 
2498       /**
2499        * Whether a variable work group size has been specified as defined by
2500        * ARB_compute_variable_group_size.
2501        */
2502       bool LocalSizeVariable;
2503    } Comp;
2504 };
2505 
2506 /**
2507  * A linked GLSL shader object.
2508  */
2509 struct gl_linked_shader
2510 {
2511    gl_shader_stage Stage;
2512 
2513 #ifdef DEBUG
2514    unsigned SourceChecksum;
2515 #endif
2516 
2517    struct gl_program *Program;  /**< Post-compile assembly code */
2518 
2519    /**
2520     * \name Sampler tracking
2521     *
2522     * \note Each of these fields is only set post-linking.
2523     */
2524    /*@{*/
2525    GLbitfield shadow_samplers;	/**< Samplers used for shadow sampling. */
2526    /*@}*/
2527 
2528    /**
2529     * Number of default uniform block components used by this shader.
2530     *
2531     * This field is only set post-linking.
2532     */
2533    unsigned num_uniform_components;
2534 
2535    /**
2536     * Number of combined uniform components used by this shader.
2537     *
2538     * This field is only set post-linking.  It is the sum of the uniform block
2539     * sizes divided by sizeof(float), and num_uniform_compoennts.
2540     */
2541    unsigned num_combined_uniform_components;
2542 
2543    struct exec_list *ir;
2544    struct exec_list *packed_varyings;
2545    struct exec_list *fragdata_arrays;
2546    struct glsl_symbol_table *symbols;
2547 };
2548 
2549 
2550 /**
2551  * Compile status enum. compile_skipped is used to indicate the compile
2552  * was skipped due to the shader matching one that's been seen before by
2553  * the on-disk cache.
2554  */
2555 enum gl_compile_status
2556 {
2557    compile_failure = 0,
2558    compile_success,
2559    compile_skipped,
2560    compiled_no_opts
2561 };
2562 
2563 /**
2564  * A GLSL shader object.
2565  */
2566 struct gl_shader
2567 {
2568    /** GL_FRAGMENT_SHADER || GL_VERTEX_SHADER || GL_GEOMETRY_SHADER_ARB ||
2569     *  GL_TESS_CONTROL_SHADER || GL_TESS_EVALUATION_SHADER.
2570     * Must be the first field.
2571     */
2572    GLenum Type;
2573    gl_shader_stage Stage;
2574    GLuint Name;  /**< AKA the handle */
2575    GLint RefCount;  /**< Reference count */
2576    GLchar *Label;   /**< GL_KHR_debug */
2577    unsigned char sha1[20]; /**< SHA1 hash of pre-processed source */
2578    GLboolean DeletePending;
2579    bool IsES;              /**< True if this shader uses GLSL ES */
2580 
2581    enum gl_compile_status CompileStatus;
2582 
2583 #ifdef DEBUG
2584    unsigned SourceChecksum;       /**< for debug/logging purposes */
2585 #endif
2586    const GLchar *Source;  /**< Source code string */
2587 
2588    const GLchar *FallbackSource;  /**< Fallback string used by on-disk cache*/
2589 
2590    GLchar *InfoLog;
2591 
2592    unsigned Version;       /**< GLSL version used for linking */
2593 
2594    /**
2595     * A bitmask of gl_advanced_blend_mode values
2596     */
2597    GLbitfield BlendSupport;
2598 
2599    struct exec_list *ir;
2600    struct glsl_symbol_table *symbols;
2601 
2602    /**
2603     * Whether early fragment tests are enabled as defined by
2604     * ARB_shader_image_load_store.
2605     */
2606    bool EarlyFragmentTests;
2607 
2608    bool ARB_fragment_coord_conventions_enable;
2609 
2610    bool redeclares_gl_fragcoord;
2611    bool uses_gl_fragcoord;
2612 
2613    bool PostDepthCoverage;
2614    bool InnerCoverage;
2615 
2616    /**
2617     * Fragment shader state from GLSL 1.50 layout qualifiers.
2618     */
2619    bool origin_upper_left;
2620    bool pixel_center_integer;
2621 
2622    /**
2623     * Whether bindless_sampler/bindless_image, and respectively
2624     * bound_sampler/bound_image are declared at global scope as defined by
2625     * ARB_bindless_texture.
2626     */
2627    bool bindless_sampler;
2628    bool bindless_image;
2629    bool bound_sampler;
2630    bool bound_image;
2631 
2632    /** Global xfb_stride out qualifier if any */
2633    GLuint TransformFeedbackBufferStride[MAX_FEEDBACK_BUFFERS];
2634 
2635    struct gl_shader_info info;
2636 
2637    /* ARB_gl_spirv related data */
2638    struct gl_shader_spirv_data *spirv_data;
2639 };
2640 
2641 
2642 struct gl_uniform_buffer_variable
2643 {
2644    char *Name;
2645 
2646    /**
2647     * Name of the uniform as seen by glGetUniformIndices.
2648     *
2649     * glGetUniformIndices requires that the block instance index \b not be
2650     * present in the name of queried uniforms.
2651     *
2652     * \note
2653     * \c gl_uniform_buffer_variable::IndexName and
2654     * \c gl_uniform_buffer_variable::Name may point to identical storage.
2655     */
2656    char *IndexName;
2657 
2658    const struct glsl_type *Type;
2659    unsigned int Offset;
2660    GLboolean RowMajor;
2661 };
2662 
2663 
2664 struct gl_uniform_block
2665 {
2666    /** Declared name of the uniform block */
2667    char *Name;
2668 
2669    /** Array of supplemental information about UBO ir_variables. */
2670    struct gl_uniform_buffer_variable *Uniforms;
2671    GLuint NumUniforms;
2672 
2673    /**
2674     * Index (GL_UNIFORM_BLOCK_BINDING) into ctx->UniformBufferBindings[] to use
2675     * with glBindBufferBase to bind a buffer object to this uniform block.
2676     */
2677    GLuint Binding;
2678 
2679    /**
2680     * Minimum size (in bytes) of a buffer object to back this uniform buffer
2681     * (GL_UNIFORM_BLOCK_DATA_SIZE).
2682     */
2683    GLuint UniformBufferSize;
2684 
2685    /** Stages that reference this block */
2686    uint8_t stageref;
2687 
2688    /**
2689     * Linearized array index for uniform block instance arrays
2690     *
2691     * Given a uniform block instance array declared with size
2692     * blk[s_0][s_1]..[s_m], the block referenced by blk[i_0][i_1]..[i_m] will
2693     * have the linearized array index
2694     *
2695     *           m-1       m
2696     *     i_m + ∑   i_j * ∏     s_k
2697     *           j=0       k=j+1
2698     *
2699     * For a uniform block instance that is not an array, this is always 0.
2700     */
2701    uint8_t linearized_array_index;
2702 
2703    /**
2704     * Layout specified in the shader
2705     *
2706     * This isn't accessible through the API, but it is used while
2707     * cross-validating uniform blocks.
2708     */
2709    enum glsl_interface_packing _Packing;
2710    GLboolean _RowMajor;
2711 };
2712 
2713 /**
2714  * Structure that represents a reference to an atomic buffer from some
2715  * shader program.
2716  */
2717 struct gl_active_atomic_buffer
2718 {
2719    /** Uniform indices of the atomic counters declared within it. */
2720    GLuint *Uniforms;
2721    GLuint NumUniforms;
2722 
2723    /** Binding point index associated with it. */
2724    GLuint Binding;
2725 
2726    /** Minimum reasonable size it is expected to have. */
2727    GLuint MinimumSize;
2728 
2729    /** Shader stages making use of it. */
2730    GLboolean StageReferences[MESA_SHADER_STAGES];
2731 };
2732 
2733 /**
2734  * Data container for shader queries. This holds only the minimal
2735  * amount of required information for resource queries to work.
2736  */
2737 struct gl_shader_variable
2738 {
2739    /**
2740     * Declared type of the variable
2741     */
2742    const struct glsl_type *type;
2743 
2744    /**
2745     * If the variable is in an interface block, this is the type of the block.
2746     */
2747    const struct glsl_type *interface_type;
2748 
2749    /**
2750     * For variables inside structs (possibly recursively), this is the
2751     * outermost struct type.
2752     */
2753    const struct glsl_type *outermost_struct_type;
2754 
2755    /**
2756     * Declared name of the variable
2757     */
2758    char *name;
2759 
2760    /**
2761     * Storage location of the base of this variable
2762     *
2763     * The precise meaning of this field depends on the nature of the variable.
2764     *
2765     *   - Vertex shader input: one of the values from \c gl_vert_attrib.
2766     *   - Vertex shader output: one of the values from \c gl_varying_slot.
2767     *   - Geometry shader input: one of the values from \c gl_varying_slot.
2768     *   - Geometry shader output: one of the values from \c gl_varying_slot.
2769     *   - Fragment shader input: one of the values from \c gl_varying_slot.
2770     *   - Fragment shader output: one of the values from \c gl_frag_result.
2771     *   - Uniforms: Per-stage uniform slot number for default uniform block.
2772     *   - Uniforms: Index within the uniform block definition for UBO members.
2773     *   - Non-UBO Uniforms: explicit location until linking then reused to
2774     *     store uniform slot number.
2775     *   - Other: This field is not currently used.
2776     *
2777     * If the variable is a uniform, shader input, or shader output, and the
2778     * slot has not been assigned, the value will be -1.
2779     */
2780    int location;
2781 
2782    /**
2783     * Specifies the first component the variable is stored in as per
2784     * ARB_enhanced_layouts.
2785     */
2786    unsigned component:2;
2787 
2788    /**
2789     * Output index for dual source blending.
2790     *
2791     * \note
2792     * The GLSL spec only allows the values 0 or 1 for the index in \b dual
2793     * source blending.
2794     */
2795    unsigned index:1;
2796 
2797    /**
2798     * Specifies whether a shader input/output is per-patch in tessellation
2799     * shader stages.
2800     */
2801    unsigned patch:1;
2802 
2803    /**
2804     * Storage class of the variable.
2805     *
2806     * \sa (n)ir_variable_mode
2807     */
2808    unsigned mode:4;
2809 
2810    /**
2811     * Interpolation mode for shader inputs / outputs
2812     *
2813     * \sa glsl_interp_mode
2814     */
2815    unsigned interpolation:2;
2816 
2817    /**
2818     * Was the location explicitly set in the shader?
2819     *
2820     * If the location is explicitly set in the shader, it \b cannot be changed
2821     * by the linker or by the API (e.g., calls to \c glBindAttribLocation have
2822     * no effect).
2823     */
2824    unsigned explicit_location:1;
2825 
2826    /**
2827     * Precision qualifier.
2828     */
2829    unsigned precision:2;
2830 };
2831 
2832 /**
2833  * Active resource in a gl_shader_program
2834  */
2835 struct gl_program_resource
2836 {
2837    GLenum Type; /** Program interface type. */
2838    const void *Data; /** Pointer to resource associated data structure. */
2839    uint8_t StageReferences; /** Bitmask of shader stage references. */
2840 };
2841 
2842 /**
2843  * Link status enum. linking_skipped is used to indicate linking
2844  * was skipped due to the shader being loaded from the on-disk cache.
2845  */
2846 enum gl_link_status
2847 {
2848    linking_failure = 0,
2849    linking_success,
2850    linking_skipped
2851 };
2852 
2853 /**
2854  * A data structure to be shared by gl_shader_program and gl_program.
2855  */
2856 struct gl_shader_program_data
2857 {
2858    GLint RefCount;  /**< Reference count */
2859 
2860    /** SHA1 hash of linked shader program */
2861    unsigned char sha1[20];
2862 
2863    unsigned NumUniformStorage;
2864    unsigned NumHiddenUniforms;
2865    struct gl_uniform_storage *UniformStorage;
2866 
2867    unsigned NumUniformBlocks;
2868    unsigned NumShaderStorageBlocks;
2869 
2870    struct gl_uniform_block *UniformBlocks;
2871    struct gl_uniform_block *ShaderStorageBlocks;
2872 
2873    struct gl_active_atomic_buffer *AtomicBuffers;
2874    unsigned NumAtomicBuffers;
2875 
2876    /* Shader cache variables used during restore */
2877    unsigned NumUniformDataSlots;
2878    union gl_constant_value *UniformDataSlots;
2879 
2880    /* Used to hold initial uniform values for program binary restores.
2881     *
2882     * From the ARB_get_program_binary spec:
2883     *
2884     *    "A successful call to ProgramBinary will reset all uniform
2885     *    variables to their initial values. The initial value is either
2886     *    the value of the variable's initializer as specified in the
2887     *    original shader source, or 0 if no initializer was present.
2888     */
2889    union gl_constant_value *UniformDataDefaults;
2890 
2891    GLboolean Validated;
2892 
2893    /** List of all active resources after linking. */
2894    struct gl_program_resource *ProgramResourceList;
2895    unsigned NumProgramResourceList;
2896 
2897    enum gl_link_status LinkStatus;   /**< GL_LINK_STATUS */
2898    GLchar *InfoLog;
2899 
2900    unsigned Version;       /**< GLSL version used for linking */
2901 
2902    /* Mask of stages this program was linked against */
2903    unsigned linked_stages;
2904 };
2905 
2906 /**
2907  * A GLSL program object.
2908  * Basically a linked collection of vertex and fragment shaders.
2909  */
2910 struct gl_shader_program
2911 {
2912    GLenum Type;  /**< Always GL_SHADER_PROGRAM (internal token) */
2913    GLuint Name;  /**< aka handle or ID */
2914    GLchar *Label;   /**< GL_KHR_debug */
2915    GLint RefCount;  /**< Reference count */
2916    GLboolean DeletePending;
2917 
2918    /**
2919     * Is the application intending to glGetProgramBinary this program?
2920     */
2921    GLboolean BinaryRetreivableHint;
2922 
2923    /**
2924     * Indicates whether program can be bound for individual pipeline stages
2925     * using UseProgramStages after it is next linked.
2926     */
2927    GLboolean SeparateShader;
2928 
2929    GLuint NumShaders;          /**< number of attached shaders */
2930    struct gl_shader **Shaders; /**< List of attached the shaders */
2931 
2932    /**
2933     * User-defined attribute bindings
2934     *
2935     * These are set via \c glBindAttribLocation and are used to direct the
2936     * GLSL linker.  These are \b not the values used in the compiled shader,
2937     * and they are \b not the values returned by \c glGetAttribLocation.
2938     */
2939    struct string_to_uint_map *AttributeBindings;
2940 
2941    /**
2942     * User-defined fragment data bindings
2943     *
2944     * These are set via \c glBindFragDataLocation and are used to direct the
2945     * GLSL linker.  These are \b not the values used in the compiled shader,
2946     * and they are \b not the values returned by \c glGetFragDataLocation.
2947     */
2948    struct string_to_uint_map *FragDataBindings;
2949    struct string_to_uint_map *FragDataIndexBindings;
2950 
2951    /**
2952     * Transform feedback varyings last specified by
2953     * glTransformFeedbackVaryings().
2954     *
2955     * For the current set of transform feedback varyings used for transform
2956     * feedback output, see LinkedTransformFeedback.
2957     */
2958    struct {
2959       GLenum BufferMode;
2960       /** Global xfb_stride out qualifier if any */
2961       GLuint BufferStride[MAX_FEEDBACK_BUFFERS];
2962       GLuint NumVarying;
2963       GLchar **VaryingNames;  /**< Array [NumVarying] of char * */
2964    } TransformFeedback;
2965 
2966    struct gl_program *last_vert_prog;
2967 
2968    /** Post-link gl_FragDepth layout for ARB_conservative_depth. */
2969    enum gl_frag_depth_layout FragDepthLayout;
2970 
2971    /**
2972     * Geometry shader state - copied into gl_program by
2973     * _mesa_copy_linked_program_data().
2974     */
2975    struct {
2976       GLint VerticesIn;
2977 
2978       bool UsesEndPrimitive;
2979       bool UsesStreams;
2980    } Geom;
2981 
2982    /**
2983     * Compute shader state - copied into gl_program by
2984     * _mesa_copy_linked_program_data().
2985     */
2986    struct {
2987       /**
2988        * Size of shared variables accessed by the compute shader.
2989        */
2990       unsigned SharedSize;
2991    } Comp;
2992 
2993    /** Data shared by gl_program and gl_shader_program */
2994    struct gl_shader_program_data *data;
2995 
2996    /**
2997     * Mapping from GL uniform locations returned by \c glUniformLocation to
2998     * UniformStorage entries. Arrays will have multiple contiguous slots
2999     * in the UniformRemapTable, all pointing to the same UniformStorage entry.
3000     */
3001    unsigned NumUniformRemapTable;
3002    struct gl_uniform_storage **UniformRemapTable;
3003 
3004    /**
3005     * Sometimes there are empty slots left over in UniformRemapTable after we
3006     * allocate slots to explicit locations. This list stores the blocks of
3007     * continuous empty slots inside UniformRemapTable.
3008     */
3009    struct exec_list EmptyUniformLocations;
3010 
3011    /**
3012     * Total number of explicit uniform location including inactive uniforms.
3013     */
3014    unsigned NumExplicitUniformLocations;
3015 
3016    /**
3017     * Map of active uniform names to locations
3018     *
3019     * Maps any active uniform that is not an array element to a location.
3020     * Each active uniform, including individual structure members will appear
3021     * in this map.  This roughly corresponds to the set of names that would be
3022     * enumerated by \c glGetActiveUniform.
3023     */
3024    struct string_to_uint_map *UniformHash;
3025 
3026    GLboolean SamplersValidated; /**< Samplers validated against texture units? */
3027 
3028    bool IsES;              /**< True if this program uses GLSL ES */
3029 
3030    /**
3031     * Per-stage shaders resulting from the first stage of linking.
3032     *
3033     * Set of linked shaders for this program.  The array is accessed using the
3034     * \c MESA_SHADER_* defines.  Entries for non-existent stages will be
3035     * \c NULL.
3036     */
3037    struct gl_linked_shader *_LinkedShaders[MESA_SHADER_STAGES];
3038 
3039    /* True if any of the fragment shaders attached to this program use:
3040     * #extension ARB_fragment_coord_conventions: enable
3041     */
3042    GLboolean ARB_fragment_coord_conventions_enable;
3043 };
3044 
3045 
3046 #define GLSL_DUMP      0x1  /**< Dump shaders to stdout */
3047 #define GLSL_LOG       0x2  /**< Write shaders to files */
3048 #define GLSL_UNIFORMS  0x4  /**< Print glUniform calls */
3049 #define GLSL_NOP_VERT  0x8  /**< Force no-op vertex shaders */
3050 #define GLSL_NOP_FRAG 0x10  /**< Force no-op fragment shaders */
3051 #define GLSL_USE_PROG 0x20  /**< Log glUseProgram calls */
3052 #define GLSL_REPORT_ERRORS 0x40  /**< Print compilation errors */
3053 #define GLSL_DUMP_ON_ERROR 0x80 /**< Dump shaders to stderr on compile error */
3054 #define GLSL_CACHE_INFO 0x100 /**< Print debug information about shader cache */
3055 #define GLSL_CACHE_FALLBACK 0x200 /**< Force shader cache fallback paths */
3056 
3057 
3058 /**
3059  * Context state for GLSL vertex/fragment shaders.
3060  * Extended to support pipeline object
3061  */
3062 struct gl_pipeline_object
3063 {
3064    /** Name of the pipeline object as received from glGenProgramPipelines.
3065     * It would be 0 for shaders without separate shader objects.
3066     */
3067    GLuint Name;
3068 
3069    GLint RefCount;
3070 
3071    GLchar *Label;   /**< GL_KHR_debug */
3072 
3073    /**
3074     * Programs used for rendering
3075     *
3076     * There is a separate program set for each shader stage.
3077     */
3078    struct gl_program *CurrentProgram[MESA_SHADER_STAGES];
3079 
3080    struct gl_shader_program *ReferencedPrograms[MESA_SHADER_STAGES];
3081 
3082    /**
3083     * Program used by glUniform calls.
3084     *
3085     * Explicitly set by \c glUseProgram and \c glActiveProgramEXT.
3086     */
3087    struct gl_shader_program *ActiveProgram;
3088 
3089    GLbitfield Flags;                    /**< Mask of GLSL_x flags */
3090 
3091    GLboolean EverBound;                 /**< Has the pipeline object been created */
3092 
3093    GLboolean Validated;                 /**< Pipeline Validation status */
3094 
3095    GLchar *InfoLog;
3096 };
3097 
3098 /**
3099  * Context state for GLSL pipeline shaders.
3100  */
3101 struct gl_pipeline_shader_state
3102 {
3103    /** Currently bound pipeline object. See _mesa_BindProgramPipeline() */
3104    struct gl_pipeline_object *Current;
3105 
3106    /* Default Object to ensure that _Shader is never NULL */
3107    struct gl_pipeline_object *Default;
3108 
3109    /** Pipeline objects */
3110    struct _mesa_HashTable *Objects;
3111 };
3112 
3113 /**
3114  * Compiler options for a single GLSL shaders type
3115  */
3116 struct gl_shader_compiler_options
3117 {
3118    /** Driver-selectable options: */
3119    GLboolean EmitNoLoops;
3120    GLboolean EmitNoCont;                  /**< Emit CONT opcode? */
3121    GLboolean EmitNoMainReturn;            /**< Emit CONT/RET opcodes? */
3122    GLboolean EmitNoPow;                   /**< Emit POW opcodes? */
3123    GLboolean EmitNoSat;                   /**< Emit SAT opcodes? */
3124    GLboolean LowerCombinedClipCullDistance; /** Lower gl_ClipDistance and
3125                                               * gl_CullDistance together from
3126                                               * float[8] to vec4[2]
3127                                               **/
3128 
3129    /**
3130     * \name Forms of indirect addressing the driver cannot do.
3131     */
3132    /*@{*/
3133    GLboolean EmitNoIndirectInput;   /**< No indirect addressing of inputs */
3134    GLboolean EmitNoIndirectOutput;  /**< No indirect addressing of outputs */
3135    GLboolean EmitNoIndirectTemp;    /**< No indirect addressing of temps */
3136    GLboolean EmitNoIndirectUniform; /**< No indirect addressing of constants */
3137    GLboolean EmitNoIndirectSampler; /**< No indirect addressing of samplers */
3138    /*@}*/
3139 
3140    GLuint MaxIfDepth;               /**< Maximum nested IF blocks */
3141    GLuint MaxUnrollIterations;
3142 
3143    /**
3144     * Optimize code for array of structures backends.
3145     *
3146     * This is a proxy for:
3147     *   - preferring DP4 instructions (rather than MUL/MAD) for
3148     *     matrix * vector operations, such as position transformation.
3149     */
3150    GLboolean OptimizeForAOS;
3151 
3152    GLboolean LowerBufferInterfaceBlocks; /**< Lower UBO and SSBO access to intrinsics. */
3153 
3154    /** Clamp UBO and SSBO block indices so they don't go out-of-bounds. */
3155    GLboolean ClampBlockIndicesToArrayBounds;
3156 
3157    const struct nir_shader_compiler_options *NirOptions;
3158 };
3159 
3160 
3161 /**
3162  * Occlusion/timer query object.
3163  */
3164 struct gl_query_object
3165 {
3166    GLenum Target;      /**< The query target, when active */
3167    GLuint Id;          /**< hash table ID/name */
3168    GLchar *Label;       /**< GL_KHR_debug */
3169    GLuint64EXT Result; /**< the counter */
3170    GLboolean Active;   /**< inside Begin/EndQuery */
3171    GLboolean Ready;    /**< result is ready? */
3172    GLboolean EverBound;/**< has query object ever been bound */
3173    GLuint Stream;      /**< The stream */
3174 };
3175 
3176 
3177 /**
3178  * Context state for query objects.
3179  */
3180 struct gl_query_state
3181 {
3182    struct _mesa_HashTable *QueryObjects;
3183    struct gl_query_object *CurrentOcclusionObject; /* GL_ARB_occlusion_query */
3184    struct gl_query_object *CurrentTimerObject;     /* GL_EXT_timer_query */
3185 
3186    /** GL_NV_conditional_render */
3187    struct gl_query_object *CondRenderQuery;
3188 
3189    /** GL_EXT_transform_feedback */
3190    struct gl_query_object *PrimitivesGenerated[MAX_VERTEX_STREAMS];
3191    struct gl_query_object *PrimitivesWritten[MAX_VERTEX_STREAMS];
3192 
3193    /** GL_ARB_transform_feedback_overflow_query */
3194    struct gl_query_object *TransformFeedbackOverflow[MAX_VERTEX_STREAMS];
3195    struct gl_query_object *TransformFeedbackOverflowAny;
3196 
3197    /** GL_ARB_timer_query */
3198    struct gl_query_object *TimeElapsed;
3199 
3200    /** GL_ARB_pipeline_statistics_query */
3201    struct gl_query_object *pipeline_stats[MAX_PIPELINE_STATISTICS];
3202 
3203    GLenum CondRenderMode;
3204 };
3205 
3206 
3207 /** Sync object state */
3208 struct gl_sync_object
3209 {
3210    GLuint Name;               /**< Fence name */
3211    GLint RefCount;            /**< Reference count */
3212    GLchar *Label;             /**< GL_KHR_debug */
3213    GLboolean DeletePending;   /**< Object was deleted while there were still
3214 			       * live references (e.g., sync not yet finished)
3215 			       */
3216    GLenum SyncCondition;
3217    GLbitfield Flags;          /**< Flags passed to glFenceSync */
3218    GLuint StatusFlag:1;       /**< Has the sync object been signaled? */
3219 };
3220 
3221 
3222 /**
3223  * State which can be shared by multiple contexts:
3224  */
3225 struct gl_shared_state
3226 {
3227    simple_mtx_t Mutex;		   /**< for thread safety */
3228    GLint RefCount;			   /**< Reference count */
3229    struct _mesa_HashTable *DisplayList;	   /**< Display lists hash table */
3230    struct _mesa_HashTable *BitmapAtlas;    /**< For optimized glBitmap text */
3231    struct _mesa_HashTable *TexObjects;	   /**< Texture objects hash table */
3232 
3233    /** Default texture objects (shared by all texture units) */
3234    struct gl_texture_object *DefaultTex[NUM_TEXTURE_TARGETS];
3235 
3236    /** Fallback texture used when a bound texture is incomplete */
3237    struct gl_texture_object *FallbackTex[NUM_TEXTURE_TARGETS];
3238 
3239    /**
3240     * \name Thread safety and statechange notification for texture
3241     * objects.
3242     *
3243     * \todo Improve the granularity of locking.
3244     */
3245    /*@{*/
3246    mtx_t TexMutex;		/**< texobj thread safety */
3247    GLuint TextureStateStamp;	        /**< state notification for shared tex */
3248    /*@}*/
3249 
3250    /** Default buffer object for vertex arrays that aren't in VBOs */
3251    struct gl_buffer_object *NullBufferObj;
3252 
3253    /**
3254     * \name Vertex/geometry/fragment programs
3255     */
3256    /*@{*/
3257    struct _mesa_HashTable *Programs; /**< All vertex/fragment programs */
3258    struct gl_program *DefaultVertexProgram;
3259    struct gl_program *DefaultFragmentProgram;
3260    /*@}*/
3261 
3262    /* GL_ATI_fragment_shader */
3263    struct _mesa_HashTable *ATIShaders;
3264    struct ati_fragment_shader *DefaultFragmentShader;
3265 
3266    struct _mesa_HashTable *BufferObjects;
3267 
3268    /** Table of both gl_shader and gl_shader_program objects */
3269    struct _mesa_HashTable *ShaderObjects;
3270 
3271    /* GL_EXT_framebuffer_object */
3272    struct _mesa_HashTable *RenderBuffers;
3273    struct _mesa_HashTable *FrameBuffers;
3274 
3275    /* GL_ARB_sync */
3276    struct set *SyncObjects;
3277 
3278    /** GL_ARB_sampler_objects */
3279    struct _mesa_HashTable *SamplerObjects;
3280 
3281    /* GL_ARB_bindless_texture */
3282    struct hash_table_u64 *TextureHandles;
3283    struct hash_table_u64 *ImageHandles;
3284    mtx_t HandlesMutex; /**< For texture/image handles safety */
3285 
3286    /**
3287     * Some context in this share group was affected by a GPU reset
3288     *
3289     * On the next call to \c glGetGraphicsResetStatus, contexts that have not
3290     * been affected by a GPU reset must also return
3291     * \c GL_INNOCENT_CONTEXT_RESET_ARB.
3292     *
3293     * Once this field becomes true, it is never reset to false.
3294     */
3295    bool ShareGroupReset;
3296 
3297    /** EXT_external_objects */
3298    struct _mesa_HashTable *MemoryObjects;
3299 
3300    /**
3301     * Some context in this share group was affected by a disjoint
3302     * operation. This operation can be anything that has effects on
3303     * values of timer queries in such manner that they become invalid for
3304     * performance metrics. As example gpu reset, counter overflow or gpu
3305     * frequency changes.
3306     */
3307    bool DisjointOperation;
3308 };
3309 
3310 
3311 
3312 /**
3313  * Renderbuffers represent drawing surfaces such as color, depth and/or
3314  * stencil.  A framebuffer object has a set of renderbuffers.
3315  * Drivers will typically derive subclasses of this type.
3316  */
3317 struct gl_renderbuffer
3318 {
3319    simple_mtx_t Mutex; /**< for thread safety */
3320    GLuint ClassID;        /**< Useful for drivers */
3321    GLuint Name;
3322    GLchar *Label;         /**< GL_KHR_debug */
3323    GLint RefCount;
3324    GLuint Width, Height;
3325    GLuint Depth;
3326    GLboolean Purgeable;  /**< Is the buffer purgeable under memory pressure? */
3327    GLboolean AttachedAnytime; /**< TRUE if it was attached to a framebuffer */
3328    /**
3329     * True for renderbuffers that wrap textures, giving the driver a chance to
3330     * flush render caches through the FinishRenderTexture hook.
3331     *
3332     * Drivers may also set this on renderbuffers other than those generated by
3333     * glFramebufferTexture(), though it means FinishRenderTexture() would be
3334     * called without a rb->TexImage.
3335     */
3336    GLboolean NeedsFinishRenderTexture;
3337    GLubyte NumSamples;    /**< zero means not multisampled */
3338    GLenum InternalFormat; /**< The user-specified format */
3339    GLenum _BaseFormat;    /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
3340                                GL_STENCIL_INDEX. */
3341    mesa_format Format;      /**< The actual renderbuffer memory format */
3342    /**
3343     * Pointer to the texture image if this renderbuffer wraps a texture,
3344     * otherwise NULL.
3345     *
3346     * Note that the reference on the gl_texture_object containing this
3347     * TexImage is held by the gl_renderbuffer_attachment.
3348     */
3349    struct gl_texture_image *TexImage;
3350 
3351    /** Delete this renderbuffer */
3352    void (*Delete)(struct gl_context *ctx, struct gl_renderbuffer *rb);
3353 
3354    /** Allocate new storage for this renderbuffer */
3355    GLboolean (*AllocStorage)(struct gl_context *ctx,
3356                              struct gl_renderbuffer *rb,
3357                              GLenum internalFormat,
3358                              GLuint width, GLuint height);
3359 };
3360 
3361 
3362 /**
3363  * A renderbuffer attachment points to either a texture object (and specifies
3364  * a mipmap level, cube face or 3D texture slice) or points to a renderbuffer.
3365  */
3366 struct gl_renderbuffer_attachment
3367 {
3368    GLenum Type;  /**< \c GL_NONE or \c GL_TEXTURE or \c GL_RENDERBUFFER_EXT */
3369    GLboolean Complete;
3370 
3371    /**
3372     * If \c Type is \c GL_RENDERBUFFER_EXT, this stores a pointer to the
3373     * application supplied renderbuffer object.
3374     */
3375    struct gl_renderbuffer *Renderbuffer;
3376 
3377    /**
3378     * If \c Type is \c GL_TEXTURE, this stores a pointer to the application
3379     * supplied texture object.
3380     */
3381    struct gl_texture_object *Texture;
3382    GLuint TextureLevel; /**< Attached mipmap level. */
3383    GLuint CubeMapFace;  /**< 0 .. 5, for cube map textures. */
3384    GLuint Zoffset;      /**< Slice for 3D textures,  or layer for both 1D
3385                          * and 2D array textures */
3386    GLboolean Layered;
3387 };
3388 
3389 
3390 /**
3391  * A framebuffer is a collection of renderbuffers (color, depth, stencil, etc).
3392  * In C++ terms, think of this as a base class from which device drivers
3393  * will make derived classes.
3394  */
3395 struct gl_framebuffer
3396 {
3397    simple_mtx_t Mutex;  /**< for thread safety */
3398    /**
3399     * If zero, this is a window system framebuffer.  If non-zero, this
3400     * is a FBO framebuffer; note that for some devices (i.e. those with
3401     * a natural pixel coordinate system for FBOs that differs from the
3402     * OpenGL/Mesa coordinate system), this means that the viewport,
3403     * polygon face orientation, and polygon stipple will have to be inverted.
3404     */
3405    GLuint Name;
3406    GLint RefCount;
3407 
3408    GLchar *Label;       /**< GL_KHR_debug */
3409 
3410    GLboolean DeletePending;
3411 
3412    /**
3413     * The framebuffer's visual. Immutable if this is a window system buffer.
3414     * Computed from attachments if user-made FBO.
3415     */
3416    struct gl_config Visual;
3417 
3418    /**
3419     * Size of frame buffer in pixels. If there are no attachments, then both
3420     * of these are 0.
3421     */
3422    GLuint Width, Height;
3423 
3424    /**
3425     * In the case that the framebuffer has no attachment (i.e.
3426     * GL_ARB_framebuffer_no_attachments) then the geometry of
3427     * the framebuffer is specified by the default values.
3428     */
3429    struct {
3430      GLuint Width, Height, Layers, NumSamples;
3431      GLboolean FixedSampleLocations;
3432      /* Derived from NumSamples by the driver so that it can choose a valid
3433       * value for the hardware.
3434       */
3435      GLuint _NumSamples;
3436    } DefaultGeometry;
3437 
3438    /** \name  Drawing bounds (Intersection of buffer size and scissor box)
3439     * The drawing region is given by [_Xmin, _Xmax) x [_Ymin, _Ymax),
3440     * (inclusive for _Xmin and _Ymin while exclusive for _Xmax and _Ymax)
3441     */
3442    /*@{*/
3443    GLint _Xmin, _Xmax;
3444    GLint _Ymin, _Ymax;
3445    /*@}*/
3446 
3447    /** \name  Derived Z buffer stuff */
3448    /*@{*/
3449    GLuint _DepthMax;	/**< Max depth buffer value */
3450    GLfloat _DepthMaxF;	/**< Float max depth buffer value */
3451    GLfloat _MRD;	/**< minimum resolvable difference in Z values */
3452    /*@}*/
3453 
3454    /** One of the GL_FRAMEBUFFER_(IN)COMPLETE_* tokens */
3455    GLenum _Status;
3456 
3457    /** Whether one of Attachment has Type != GL_NONE
3458     * NOTE: the values for Width and Height are set to 0 in case of having
3459     * no attachments, a backend driver supporting the extension
3460     * GL_ARB_framebuffer_no_attachments must check for the flag _HasAttachments
3461     * and if GL_FALSE, must then use the values in DefaultGeometry to initialize
3462     * its viewport, scissor and so on (in particular _Xmin, _Xmax, _Ymin and
3463     * _Ymax do NOT take into account _HasAttachments being false). To get the
3464     * geometry of the framebuffer, the  helper functions
3465     *   _mesa_geometric_width(),
3466     *   _mesa_geometric_height(),
3467     *   _mesa_geometric_samples() and
3468     *   _mesa_geometric_layers()
3469     * are available that check _HasAttachments.
3470     */
3471    bool _HasAttachments;
3472 
3473    GLbitfield _IntegerBuffers;  /**< Which color buffers are integer valued */
3474 
3475    /* ARB_color_buffer_float */
3476    GLboolean _AllColorBuffersFixedPoint; /* no integer, no float */
3477    GLboolean _HasSNormOrFloatColorBuffer;
3478 
3479    /**
3480     * The maximum number of layers in the framebuffer, or 0 if the framebuffer
3481     * is not layered.  For cube maps and cube map arrays, each cube face
3482     * counts as a layer. As the case for Width, Height a backend driver
3483     * supporting GL_ARB_framebuffer_no_attachments must use DefaultGeometry
3484     * in the case that _HasAttachments is false
3485     */
3486    GLuint MaxNumLayers;
3487 
3488    /** Array of all renderbuffer attachments, indexed by BUFFER_* tokens. */
3489    struct gl_renderbuffer_attachment Attachment[BUFFER_COUNT];
3490 
3491    /* In unextended OpenGL these vars are part of the GL_COLOR_BUFFER
3492     * attribute group and GL_PIXEL attribute group, respectively.
3493     */
3494    GLenum ColorDrawBuffer[MAX_DRAW_BUFFERS];
3495    GLenum ColorReadBuffer;
3496 
3497    /** Computed from ColorDraw/ReadBuffer above */
3498    GLuint _NumColorDrawBuffers;
3499    gl_buffer_index _ColorDrawBufferIndexes[MAX_DRAW_BUFFERS];
3500    gl_buffer_index _ColorReadBufferIndex;
3501    struct gl_renderbuffer *_ColorDrawBuffers[MAX_DRAW_BUFFERS];
3502    struct gl_renderbuffer *_ColorReadBuffer;
3503 
3504    /** Delete this framebuffer */
3505    void (*Delete)(struct gl_framebuffer *fb);
3506 };
3507 
3508 
3509 /**
3510  * Precision info for shader datatypes.  See glGetShaderPrecisionFormat().
3511  */
3512 struct gl_precision
3513 {
3514    GLushort RangeMin;   /**< min value exponent */
3515    GLushort RangeMax;   /**< max value exponent */
3516    GLushort Precision;  /**< number of mantissa bits */
3517 };
3518 
3519 
3520 /**
3521  * Limits for vertex, geometry and fragment programs/shaders.
3522  */
3523 struct gl_program_constants
3524 {
3525    /* logical limits */
3526    GLuint MaxInstructions;
3527    GLuint MaxAluInstructions;
3528    GLuint MaxTexInstructions;
3529    GLuint MaxTexIndirections;
3530    GLuint MaxAttribs;
3531    GLuint MaxTemps;
3532    GLuint MaxAddressRegs;
3533    GLuint MaxAddressOffset;  /**< [-MaxAddressOffset, MaxAddressOffset-1] */
3534    GLuint MaxParameters;
3535    GLuint MaxLocalParams;
3536    GLuint MaxEnvParams;
3537    /* native/hardware limits */
3538    GLuint MaxNativeInstructions;
3539    GLuint MaxNativeAluInstructions;
3540    GLuint MaxNativeTexInstructions;
3541    GLuint MaxNativeTexIndirections;
3542    GLuint MaxNativeAttribs;
3543    GLuint MaxNativeTemps;
3544    GLuint MaxNativeAddressRegs;
3545    GLuint MaxNativeParameters;
3546    /* For shaders */
3547    GLuint MaxUniformComponents;  /**< Usually == MaxParameters * 4 */
3548 
3549    /**
3550     * \name Per-stage input / output limits
3551     *
3552     * Previous to OpenGL 3.2, the intrastage data limits were advertised with
3553     * a single value: GL_MAX_VARYING_COMPONENTS (GL_MAX_VARYING_VECTORS in
3554     * ES).  This is stored as \c gl_constants::MaxVarying.
3555     *
3556     * Starting with OpenGL 3.2, the limits are advertised with per-stage
3557     * variables.  Each stage as a certain number of outputs that it can feed
3558     * to the next stage and a certain number inputs that it can consume from
3559     * the previous stage.
3560     *
3561     * Vertex shader inputs do not participate this in this accounting.
3562     * These are tracked exclusively by \c gl_program_constants::MaxAttribs.
3563     *
3564     * Fragment shader outputs do not participate this in this accounting.
3565     * These are tracked exclusively by \c gl_constants::MaxDrawBuffers.
3566     */
3567    /*@{*/
3568    GLuint MaxInputComponents;
3569    GLuint MaxOutputComponents;
3570    /*@}*/
3571 
3572    /* ES 2.0 and GL_ARB_ES2_compatibility */
3573    struct gl_precision LowFloat, MediumFloat, HighFloat;
3574    struct gl_precision LowInt, MediumInt, HighInt;
3575    /* GL_ARB_uniform_buffer_object */
3576    GLuint MaxUniformBlocks;
3577    GLuint MaxCombinedUniformComponents;
3578    GLuint MaxTextureImageUnits;
3579 
3580    /* GL_ARB_shader_atomic_counters */
3581    GLuint MaxAtomicBuffers;
3582    GLuint MaxAtomicCounters;
3583 
3584    /* GL_ARB_shader_image_load_store */
3585    GLuint MaxImageUniforms;
3586 
3587    /* GL_ARB_shader_storage_buffer_object */
3588    GLuint MaxShaderStorageBlocks;
3589 };
3590 
3591 /**
3592  * Constants which may be overridden by device driver during context creation
3593  * but are never changed after that.
3594  */
3595 struct gl_constants
3596 {
3597    GLuint MaxTextureMbytes;      /**< Max memory per image, in MB */
3598    GLuint MaxTextureLevels;      /**< Max mipmap levels. */
3599    GLuint Max3DTextureLevels;    /**< Max mipmap levels for 3D textures */
3600    GLuint MaxCubeTextureLevels;  /**< Max mipmap levels for cube textures */
3601    GLuint MaxArrayTextureLayers; /**< Max layers in array textures */
3602    GLuint MaxTextureRectSize;    /**< Max rectangle texture size, in pixes */
3603    GLuint MaxTextureCoordUnits;
3604    GLuint MaxCombinedTextureImageUnits;
3605    GLuint MaxTextureUnits; /**< = MIN(CoordUnits, FragmentProgram.ImageUnits) */
3606    GLfloat MaxTextureMaxAnisotropy;  /**< GL_EXT_texture_filter_anisotropic */
3607    GLfloat MaxTextureLodBias;        /**< GL_EXT_texture_lod_bias */
3608    GLuint MaxTextureBufferSize;      /**< GL_ARB_texture_buffer_object */
3609 
3610    GLuint TextureBufferOffsetAlignment; /**< GL_ARB_texture_buffer_range */
3611 
3612    GLuint MaxArrayLockSize;
3613 
3614    GLint SubPixelBits;
3615 
3616    GLfloat MinPointSize, MaxPointSize;	     /**< aliased */
3617    GLfloat MinPointSizeAA, MaxPointSizeAA;   /**< antialiased */
3618    GLfloat PointSizeGranularity;
3619    GLfloat MinLineWidth, MaxLineWidth;       /**< aliased */
3620    GLfloat MinLineWidthAA, MaxLineWidthAA;   /**< antialiased */
3621    GLfloat LineWidthGranularity;
3622 
3623    GLuint MaxClipPlanes;
3624    GLuint MaxLights;
3625    GLfloat MaxShininess;                     /**< GL_NV_light_max_exponent */
3626    GLfloat MaxSpotExponent;                  /**< GL_NV_light_max_exponent */
3627 
3628    GLuint MaxViewportWidth, MaxViewportHeight;
3629    GLuint MaxViewports;                      /**< GL_ARB_viewport_array */
3630    GLuint ViewportSubpixelBits;              /**< GL_ARB_viewport_array */
3631    struct {
3632       GLfloat Min;
3633       GLfloat Max;
3634    } ViewportBounds;                         /**< GL_ARB_viewport_array */
3635    GLuint MaxWindowRectangles;               /**< GL_EXT_window_rectangles */
3636 
3637    struct gl_program_constants Program[MESA_SHADER_STAGES];
3638    GLuint MaxProgramMatrices;
3639    GLuint MaxProgramMatrixStackDepth;
3640 
3641    struct {
3642       GLuint SamplesPassed;
3643       GLuint TimeElapsed;
3644       GLuint Timestamp;
3645       GLuint PrimitivesGenerated;
3646       GLuint PrimitivesWritten;
3647       GLuint VerticesSubmitted;
3648       GLuint PrimitivesSubmitted;
3649       GLuint VsInvocations;
3650       GLuint TessPatches;
3651       GLuint TessInvocations;
3652       GLuint GsInvocations;
3653       GLuint GsPrimitives;
3654       GLuint FsInvocations;
3655       GLuint ComputeInvocations;
3656       GLuint ClInPrimitives;
3657       GLuint ClOutPrimitives;
3658    } QueryCounterBits;
3659 
3660    GLuint MaxDrawBuffers;    /**< GL_ARB_draw_buffers */
3661 
3662    GLuint MaxColorAttachments;   /**< GL_EXT_framebuffer_object */
3663    GLuint MaxRenderbufferSize;   /**< GL_EXT_framebuffer_object */
3664    GLuint MaxSamples;            /**< GL_ARB_framebuffer_object */
3665 
3666    /**
3667     * GL_ARB_framebuffer_no_attachments
3668     */
3669    GLuint MaxFramebufferWidth;
3670    GLuint MaxFramebufferHeight;
3671    GLuint MaxFramebufferLayers;
3672    GLuint MaxFramebufferSamples;
3673 
3674    /** Number of varying vectors between any two shader stages. */
3675    GLuint MaxVarying;
3676 
3677    /** @{
3678     * GL_ARB_uniform_buffer_object
3679     */
3680    GLuint MaxCombinedUniformBlocks;
3681    GLuint MaxUniformBufferBindings;
3682    GLuint MaxUniformBlockSize;
3683    GLuint UniformBufferOffsetAlignment;
3684    /** @} */
3685 
3686    /** @{
3687     * GL_ARB_shader_storage_buffer_object
3688     */
3689    GLuint MaxCombinedShaderStorageBlocks;
3690    GLuint MaxShaderStorageBufferBindings;
3691    GLuint MaxShaderStorageBlockSize;
3692    GLuint ShaderStorageBufferOffsetAlignment;
3693    /** @} */
3694 
3695    /**
3696     * GL_ARB_explicit_uniform_location
3697     */
3698    GLuint MaxUserAssignableUniformLocations;
3699 
3700    /** geometry shader */
3701    GLuint MaxGeometryOutputVertices;
3702    GLuint MaxGeometryTotalOutputComponents;
3703 
3704    GLuint GLSLVersion;  /**< Desktop GLSL version supported (ex: 120 = 1.20) */
3705 
3706    /**
3707     * Changes default GLSL extension behavior from "error" to "warn".  It's out
3708     * of spec, but it can make some apps work that otherwise wouldn't.
3709     */
3710    GLboolean ForceGLSLExtensionsWarn;
3711 
3712    /**
3713     * If non-zero, forces GLSL shaders to behave as if they began
3714     * with "#version ForceGLSLVersion".
3715     */
3716    GLuint ForceGLSLVersion;
3717 
3718    /**
3719     * Allow GLSL #extension directives in the middle of shaders.
3720     */
3721    GLboolean AllowGLSLExtensionDirectiveMidShader;
3722 
3723    /**
3724     * Allow GLSL built-in variables to be redeclared verbatim
3725     */
3726    GLboolean AllowGLSLBuiltinVariableRedeclaration;
3727 
3728    /**
3729     * Allow GLSL interpolation qualifier mismatch across shader stages.
3730     */
3731    GLboolean AllowGLSLCrossStageInterpolationMismatch;
3732 
3733    /**
3734     * Allow creating a higher compat profile (version 3.1+) for apps that
3735     * request it. Be careful when adding that driconf option because some
3736     * features are unimplemented and might not work correctly.
3737     */
3738    GLboolean AllowHigherCompatVersion;
3739 
3740    /**
3741     * Force computing the absolute value for sqrt() and inversesqrt() to follow
3742     * D3D9 when apps rely on this behaviour.
3743     */
3744    GLboolean ForceGLSLAbsSqrt;
3745 
3746    /**
3747     * Force uninitialized variables to default to zero.
3748     */
3749    GLboolean GLSLZeroInit;
3750 
3751    /**
3752     * Does the driver support real 32-bit integers?  (Otherwise, integers are
3753     * simulated via floats.)
3754     */
3755    GLboolean NativeIntegers;
3756 
3757    /**
3758     * Does VertexID count from zero or from base vertex?
3759     *
3760     * \note
3761     * If desktop GLSL 1.30 or GLSL ES 3.00 are not supported, this field is
3762     * ignored and need not be set.
3763     */
3764    bool VertexID_is_zero_based;
3765 
3766    /**
3767     * If the driver supports real 32-bit integers, what integer value should be
3768     * used for boolean true in uniform uploads?  (Usually 1 or ~0.)
3769     */
3770    GLuint UniformBooleanTrue;
3771 
3772    /**
3773     * Maximum amount of time, measured in nanseconds, that the server can wait.
3774     */
3775    GLuint64 MaxServerWaitTimeout;
3776 
3777    /** GL_EXT_provoking_vertex */
3778    GLboolean QuadsFollowProvokingVertexConvention;
3779 
3780    /** GL_ARB_viewport_array */
3781    GLenum LayerAndVPIndexProvokingVertex;
3782 
3783    /** OpenGL version 3.0 */
3784    GLbitfield ContextFlags;  /**< Ex: GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT */
3785 
3786    /** OpenGL version 3.2 */
3787    GLbitfield ProfileMask;   /**< Mask of CONTEXT_x_PROFILE_BIT */
3788 
3789    /** OpenGL version 4.4 */
3790    GLuint MaxVertexAttribStride;
3791 
3792    /** GL_EXT_transform_feedback */
3793    GLuint MaxTransformFeedbackBuffers;
3794    GLuint MaxTransformFeedbackSeparateComponents;
3795    GLuint MaxTransformFeedbackInterleavedComponents;
3796    GLuint MaxVertexStreams;
3797 
3798    /** GL_EXT_gpu_shader4 */
3799    GLint MinProgramTexelOffset, MaxProgramTexelOffset;
3800 
3801    /** GL_ARB_texture_gather */
3802    GLuint MinProgramTextureGatherOffset;
3803    GLuint MaxProgramTextureGatherOffset;
3804    GLuint MaxProgramTextureGatherComponents;
3805 
3806    /* GL_ARB_robustness */
3807    GLenum ResetStrategy;
3808 
3809    /* GL_KHR_robustness */
3810    GLboolean RobustAccess;
3811 
3812    /* GL_ARB_blend_func_extended */
3813    GLuint MaxDualSourceDrawBuffers;
3814 
3815    /**
3816     * Whether the implementation strips out and ignores texture borders.
3817     *
3818     * Many GPU hardware implementations don't support rendering with texture
3819     * borders and mipmapped textures.  (Note: not static border color, but the
3820     * old 1-pixel border around each edge).  Implementations then have to do
3821     * slow fallbacks to be correct, or just ignore the border and be fast but
3822     * wrong.  Setting the flag strips the border off of TexImage calls,
3823     * providing "fast but wrong" at significantly reduced driver complexity.
3824     *
3825     * Texture borders are deprecated in GL 3.0.
3826     **/
3827    GLboolean StripTextureBorder;
3828 
3829    /**
3830     * For drivers which can do a better job at eliminating unused uniforms
3831     * than the GLSL compiler.
3832     *
3833     * XXX Remove these as soon as a better solution is available.
3834     */
3835    GLboolean GLSLSkipStrictMaxUniformLimitCheck;
3836 
3837    /** Whether gl_FragCoord and gl_FrontFacing are system values. */
3838    bool GLSLFragCoordIsSysVal;
3839    bool GLSLFrontFacingIsSysVal;
3840 
3841    /**
3842     * Run the minimum amount of GLSL optimizations to be able to link
3843     * shaders optimally (eliminate dead varyings and uniforms) and just do
3844     * all the necessary lowering.
3845     */
3846    bool GLSLOptimizeConservatively;
3847 
3848    /**
3849     * True if gl_TessLevelInner/Outer[] in the TES should be inputs
3850     * (otherwise, they're system values).
3851     */
3852    bool GLSLTessLevelsAsInputs;
3853 
3854    /**
3855     * Always use the GetTransformFeedbackVertexCount() driver hook, rather
3856     * than passing the transform feedback object to the drawing function.
3857     */
3858    GLboolean AlwaysUseGetTransformFeedbackVertexCount;
3859 
3860    /** GL_ARB_map_buffer_alignment */
3861    GLuint MinMapBufferAlignment;
3862 
3863    /**
3864     * Disable varying packing.  This is out of spec, but potentially useful
3865     * for older platforms that supports a limited number of texture
3866     * indirections--on these platforms, unpacking the varyings in the fragment
3867     * shader increases the number of texture indirections by 1, which might
3868     * make some shaders not executable at all.
3869     *
3870     * Drivers that support transform feedback must set this value to GL_FALSE.
3871     */
3872    GLboolean DisableVaryingPacking;
3873 
3874    /**
3875     * UBOs and SSBOs can be packed tightly by the OpenGL implementation when
3876     * layout is set as shared (the default) or packed. However most Mesa drivers
3877     * just use STD140 for these layouts. This flag allows drivers to use STD430
3878     * for packed and shared layouts which allows arrays to be packed more
3879     * tightly.
3880     */
3881    bool UseSTD430AsDefaultPacking;
3882 
3883    /**
3884     * Should meaningful names be generated for compiler temporary variables?
3885     *
3886     * Generally, it is not useful to have the compiler generate "meaningful"
3887     * names for temporary variables that it creates.  This can, however, be a
3888     * useful debugging aid.  In Mesa debug builds or release builds when
3889     * MESA_GLSL is set at run-time, meaningful names will be generated.
3890     * Drivers can also force names to be generated by setting this field.
3891     * For example, the i965 driver may set it when INTEL_DEBUG=vs (to dump
3892     * vertex shader assembly) is set at run-time.
3893     */
3894    bool GenerateTemporaryNames;
3895 
3896    /*
3897     * Maximum value supported for an index in DrawElements and friends.
3898     *
3899     * This must be at least (1ull<<24)-1.  The default value is
3900     * (1ull<<32)-1.
3901     *
3902     * \since ES 3.0 or GL_ARB_ES3_compatibility
3903     * \sa _mesa_init_constants
3904     */
3905    GLuint64 MaxElementIndex;
3906 
3907    /**
3908     * Disable interpretation of line continuations (lines ending with a
3909     * backslash character ('\') in GLSL source.
3910     */
3911    GLboolean DisableGLSLLineContinuations;
3912 
3913    /** GL_ARB_texture_multisample */
3914    GLint MaxColorTextureSamples;
3915    GLint MaxDepthTextureSamples;
3916    GLint MaxIntegerSamples;
3917 
3918    /**
3919     * GL_EXT_texture_multisample_blit_scaled implementation assumes that
3920     * samples are laid out in a rectangular grid roughly corresponding to
3921     * sample locations within a pixel. Below SampleMap{2,4,8}x variables
3922     * are used to map indices of rectangular grid to sample numbers within
3923     * a pixel. This mapping of indices to sample numbers must be initialized
3924     * by the driver for the target hardware. For example, if we have the 8X
3925     * MSAA sample number layout (sample positions) for XYZ hardware:
3926     *
3927     *        sample indices layout          sample number layout
3928     *            ---------                      ---------
3929     *            | 0 | 1 |                      | a | b |
3930     *            ---------                      ---------
3931     *            | 2 | 3 |                      | c | d |
3932     *            ---------                      ---------
3933     *            | 4 | 5 |                      | e | f |
3934     *            ---------                      ---------
3935     *            | 6 | 7 |                      | g | h |
3936     *            ---------                      ---------
3937     *
3938     * Where a,b,c,d,e,f,g,h are integers between [0-7].
3939     *
3940     * Then, initialize the SampleMap8x variable for XYZ hardware as shown
3941     * below:
3942     *    SampleMap8x = {a, b, c, d, e, f, g, h};
3943     *
3944     * Follow the logic for sample counts 2-8.
3945     *
3946     * For 16x the sample indices layout as a 4x4 grid as follows:
3947     *
3948     *            -----------------
3949     *            | 0 | 1 | 2 | 3 |
3950     *            -----------------
3951     *            | 4 | 5 | 6 | 7 |
3952     *            -----------------
3953     *            | 8 | 9 |10 |11 |
3954     *            -----------------
3955     *            |12 |13 |14 |15 |
3956     *            -----------------
3957     */
3958    uint8_t SampleMap2x[2];
3959    uint8_t SampleMap4x[4];
3960    uint8_t SampleMap8x[8];
3961    uint8_t SampleMap16x[16];
3962 
3963    /** GL_ARB_shader_atomic_counters */
3964    GLuint MaxAtomicBufferBindings;
3965    GLuint MaxAtomicBufferSize;
3966    GLuint MaxCombinedAtomicBuffers;
3967    GLuint MaxCombinedAtomicCounters;
3968 
3969    /** GL_ARB_vertex_attrib_binding */
3970    GLint MaxVertexAttribRelativeOffset;
3971    GLint MaxVertexAttribBindings;
3972 
3973    /* GL_ARB_shader_image_load_store */
3974    GLuint MaxImageUnits;
3975    GLuint MaxCombinedShaderOutputResources;
3976    GLuint MaxImageSamples;
3977    GLuint MaxCombinedImageUniforms;
3978 
3979    /** GL_ARB_compute_shader */
3980    GLuint MaxComputeWorkGroupCount[3]; /* Array of x, y, z dimensions */
3981    GLuint MaxComputeWorkGroupSize[3]; /* Array of x, y, z dimensions */
3982    GLuint MaxComputeWorkGroupInvocations;
3983    GLuint MaxComputeSharedMemorySize;
3984 
3985    /** GL_ARB_compute_variable_group_size */
3986    GLuint MaxComputeVariableGroupSize[3]; /* Array of x, y, z dimensions */
3987    GLuint MaxComputeVariableGroupInvocations;
3988 
3989    /** GL_ARB_gpu_shader5 */
3990    GLfloat MinFragmentInterpolationOffset;
3991    GLfloat MaxFragmentInterpolationOffset;
3992 
3993    GLboolean FakeSWMSAA;
3994 
3995    /** GL_KHR_context_flush_control */
3996    GLenum ContextReleaseBehavior;
3997 
3998    struct gl_shader_compiler_options ShaderCompilerOptions[MESA_SHADER_STAGES];
3999 
4000    /** GL_ARB_tessellation_shader */
4001    GLuint MaxPatchVertices;
4002    GLuint MaxTessGenLevel;
4003    GLuint MaxTessPatchComponents;
4004    GLuint MaxTessControlTotalOutputComponents;
4005    bool LowerTessLevel; /**< Lower gl_TessLevel* from float[n] to vecn? */
4006    bool PrimitiveRestartForPatches;
4007    bool LowerCsDerivedVariables;    /**< Lower gl_GlobalInvocationID and
4008                                      *   gl_LocalInvocationIndex based on
4009                                      *   other builtin variables. */
4010 
4011    /** GL_OES_primitive_bounding_box */
4012    bool NoPrimitiveBoundingBoxOutput;
4013 
4014    /** GL_ARB_sparse_buffer */
4015    GLuint SparseBufferPageSize;
4016 
4017    /** Used as an input for sha1 generation in the on-disk shader cache */
4018    unsigned char *dri_config_options_sha1;
4019 
4020    /** When drivers are OK with mapped buffers during draw and other calls. */
4021    bool AllowMappedBuffersDuringExecution;
4022 
4023    /** GL_ARB_get_program_binary */
4024    GLuint NumProgramBinaryFormats;
4025 };
4026 
4027 
4028 /**
4029  * Enable flag for each OpenGL extension.  Different device drivers will
4030  * enable different extensions at runtime.
4031  */
4032 struct gl_extensions
4033 {
4034    GLboolean dummy;  /* don't remove this! */
4035    GLboolean dummy_true;  /* Set true by _mesa_init_extensions(). */
4036    GLboolean dummy_false; /* Set false by _mesa_init_extensions(). */
4037    GLboolean ANGLE_texture_compression_dxt;
4038    GLboolean ARB_ES2_compatibility;
4039    GLboolean ARB_ES3_compatibility;
4040    GLboolean ARB_ES3_1_compatibility;
4041    GLboolean ARB_ES3_2_compatibility;
4042    GLboolean ARB_arrays_of_arrays;
4043    GLboolean ARB_base_instance;
4044    GLboolean ARB_bindless_texture;
4045    GLboolean ARB_blend_func_extended;
4046    GLboolean ARB_buffer_storage;
4047    GLboolean ARB_clear_texture;
4048    GLboolean ARB_clip_control;
4049    GLboolean ARB_color_buffer_float;
4050    GLboolean ARB_compute_shader;
4051    GLboolean ARB_compute_variable_group_size;
4052    GLboolean ARB_conditional_render_inverted;
4053    GLboolean ARB_conservative_depth;
4054    GLboolean ARB_copy_image;
4055    GLboolean ARB_cull_distance;
4056    GLboolean ARB_depth_buffer_float;
4057    GLboolean ARB_depth_clamp;
4058    GLboolean ARB_depth_texture;
4059    GLboolean ARB_derivative_control;
4060    GLboolean ARB_draw_buffers_blend;
4061    GLboolean ARB_draw_elements_base_vertex;
4062    GLboolean ARB_draw_indirect;
4063    GLboolean ARB_draw_instanced;
4064    GLboolean ARB_fragment_coord_conventions;
4065    GLboolean ARB_fragment_layer_viewport;
4066    GLboolean ARB_fragment_program;
4067    GLboolean ARB_fragment_program_shadow;
4068    GLboolean ARB_fragment_shader;
4069    GLboolean ARB_framebuffer_no_attachments;
4070    GLboolean ARB_framebuffer_object;
4071    GLboolean ARB_enhanced_layouts;
4072    GLboolean ARB_explicit_attrib_location;
4073    GLboolean ARB_explicit_uniform_location;
4074    GLboolean ARB_gl_spirv;
4075    GLboolean ARB_gpu_shader5;
4076    GLboolean ARB_gpu_shader_fp64;
4077    GLboolean ARB_gpu_shader_int64;
4078    GLboolean ARB_half_float_vertex;
4079    GLboolean ARB_indirect_parameters;
4080    GLboolean ARB_instanced_arrays;
4081    GLboolean ARB_internalformat_query;
4082    GLboolean ARB_internalformat_query2;
4083    GLboolean ARB_map_buffer_range;
4084    GLboolean ARB_occlusion_query;
4085    GLboolean ARB_occlusion_query2;
4086    GLboolean ARB_pipeline_statistics_query;
4087    GLboolean ARB_point_sprite;
4088    GLboolean ARB_polygon_offset_clamp;
4089    GLboolean ARB_post_depth_coverage;
4090    GLboolean ARB_query_buffer_object;
4091    GLboolean ARB_robust_buffer_access_behavior;
4092    GLboolean ARB_sample_shading;
4093    GLboolean ARB_seamless_cube_map;
4094    GLboolean ARB_shader_atomic_counter_ops;
4095    GLboolean ARB_shader_atomic_counters;
4096    GLboolean ARB_shader_ballot;
4097    GLboolean ARB_shader_bit_encoding;
4098    GLboolean ARB_shader_clock;
4099    GLboolean ARB_shader_draw_parameters;
4100    GLboolean ARB_shader_group_vote;
4101    GLboolean ARB_shader_image_load_store;
4102    GLboolean ARB_shader_image_size;
4103    GLboolean ARB_shader_precision;
4104    GLboolean ARB_shader_stencil_export;
4105    GLboolean ARB_shader_storage_buffer_object;
4106    GLboolean ARB_shader_texture_image_samples;
4107    GLboolean ARB_shader_texture_lod;
4108    GLboolean ARB_shader_viewport_layer_array;
4109    GLboolean ARB_shading_language_packing;
4110    GLboolean ARB_shading_language_420pack;
4111    GLboolean ARB_shadow;
4112    GLboolean ARB_sparse_buffer;
4113    GLboolean ARB_stencil_texturing;
4114    GLboolean ARB_sync;
4115    GLboolean ARB_tessellation_shader;
4116    GLboolean ARB_texture_border_clamp;
4117    GLboolean ARB_texture_buffer_object;
4118    GLboolean ARB_texture_buffer_object_rgb32;
4119    GLboolean ARB_texture_buffer_range;
4120    GLboolean ARB_texture_compression_bptc;
4121    GLboolean ARB_texture_compression_rgtc;
4122    GLboolean ARB_texture_cube_map;
4123    GLboolean ARB_texture_cube_map_array;
4124    GLboolean ARB_texture_env_combine;
4125    GLboolean ARB_texture_env_crossbar;
4126    GLboolean ARB_texture_env_dot3;
4127    GLboolean ARB_texture_filter_anisotropic;
4128    GLboolean ARB_texture_float;
4129    GLboolean ARB_texture_gather;
4130    GLboolean ARB_texture_mirror_clamp_to_edge;
4131    GLboolean ARB_texture_multisample;
4132    GLboolean ARB_texture_non_power_of_two;
4133    GLboolean ARB_texture_stencil8;
4134    GLboolean ARB_texture_query_levels;
4135    GLboolean ARB_texture_query_lod;
4136    GLboolean ARB_texture_rg;
4137    GLboolean ARB_texture_rgb10_a2ui;
4138    GLboolean ARB_texture_view;
4139    GLboolean ARB_timer_query;
4140    GLboolean ARB_transform_feedback2;
4141    GLboolean ARB_transform_feedback3;
4142    GLboolean ARB_transform_feedback_instanced;
4143    GLboolean ARB_transform_feedback_overflow_query;
4144    GLboolean ARB_uniform_buffer_object;
4145    GLboolean ARB_vertex_attrib_64bit;
4146    GLboolean ARB_vertex_program;
4147    GLboolean ARB_vertex_shader;
4148    GLboolean ARB_vertex_type_10f_11f_11f_rev;
4149    GLboolean ARB_vertex_type_2_10_10_10_rev;
4150    GLboolean ARB_viewport_array;
4151    GLboolean EXT_blend_color;
4152    GLboolean EXT_blend_equation_separate;
4153    GLboolean EXT_blend_func_separate;
4154    GLboolean EXT_blend_minmax;
4155    GLboolean EXT_depth_bounds_test;
4156    GLboolean EXT_disjoint_timer_query;
4157    GLboolean EXT_draw_buffers2;
4158    GLboolean EXT_framebuffer_multisample;
4159    GLboolean EXT_framebuffer_multisample_blit_scaled;
4160    GLboolean EXT_framebuffer_sRGB;
4161    GLboolean EXT_gpu_program_parameters;
4162    GLboolean EXT_gpu_shader4;
4163    GLboolean EXT_memory_object;
4164    GLboolean EXT_memory_object_fd;
4165    GLboolean EXT_packed_float;
4166    GLboolean EXT_pixel_buffer_object;
4167    GLboolean EXT_point_parameters;
4168    GLboolean EXT_provoking_vertex;
4169    GLboolean EXT_shader_integer_mix;
4170    GLboolean EXT_shader_samples_identical;
4171    GLboolean EXT_stencil_two_side;
4172    GLboolean EXT_texture_array;
4173    GLboolean EXT_texture_compression_latc;
4174    GLboolean EXT_texture_compression_s3tc;
4175    GLboolean EXT_texture_env_dot3;
4176    GLboolean EXT_texture_filter_anisotropic;
4177    GLboolean EXT_texture_integer;
4178    GLboolean EXT_texture_mirror_clamp;
4179    GLboolean EXT_texture_shared_exponent;
4180    GLboolean EXT_texture_snorm;
4181    GLboolean EXT_texture_sRGB;
4182    GLboolean EXT_texture_sRGB_decode;
4183    GLboolean EXT_texture_swizzle;
4184    GLboolean EXT_texture_type_2_10_10_10_REV;
4185    GLboolean EXT_transform_feedback;
4186    GLboolean EXT_timer_query;
4187    GLboolean EXT_vertex_array_bgra;
4188    GLboolean EXT_window_rectangles;
4189    GLboolean OES_copy_image;
4190    GLboolean OES_primitive_bounding_box;
4191    GLboolean OES_sample_variables;
4192    GLboolean OES_standard_derivatives;
4193    GLboolean OES_texture_buffer;
4194    GLboolean OES_texture_cube_map_array;
4195    GLboolean OES_viewport_array;
4196    /* vendor extensions */
4197    GLboolean AMD_performance_monitor;
4198    GLboolean AMD_pinned_memory;
4199    GLboolean AMD_seamless_cubemap_per_texture;
4200    GLboolean AMD_vertex_shader_layer;
4201    GLboolean AMD_vertex_shader_viewport_index;
4202    GLboolean ANDROID_extension_pack_es31a;
4203    GLboolean APPLE_object_purgeable;
4204    GLboolean ATI_meminfo;
4205    GLboolean ATI_texture_compression_3dc;
4206    GLboolean ATI_texture_mirror_once;
4207    GLboolean ATI_texture_env_combine3;
4208    GLboolean ATI_fragment_shader;
4209    GLboolean ATI_separate_stencil;
4210    GLboolean GREMEDY_string_marker;
4211    GLboolean INTEL_conservative_rasterization;
4212    GLboolean INTEL_performance_query;
4213    GLboolean KHR_blend_equation_advanced;
4214    GLboolean KHR_blend_equation_advanced_coherent;
4215    GLboolean KHR_robustness;
4216    GLboolean KHR_texture_compression_astc_hdr;
4217    GLboolean KHR_texture_compression_astc_ldr;
4218    GLboolean KHR_texture_compression_astc_sliced_3d;
4219    GLboolean MESA_tile_raster_order;
4220    GLboolean MESA_pack_invert;
4221    GLboolean MESA_shader_framebuffer_fetch;
4222    GLboolean MESA_shader_framebuffer_fetch_non_coherent;
4223    GLboolean MESA_shader_integer_functions;
4224    GLboolean MESA_ycbcr_texture;
4225    GLboolean NV_conditional_render;
4226    GLboolean NV_fill_rectangle;
4227    GLboolean NV_fog_distance;
4228    GLboolean NV_point_sprite;
4229    GLboolean NV_primitive_restart;
4230    GLboolean NV_texture_barrier;
4231    GLboolean NV_texture_env_combine4;
4232    GLboolean NV_texture_rectangle;
4233    GLboolean NV_vdpau_interop;
4234    GLboolean NVX_gpu_memory_info;
4235    GLboolean TDFX_texture_compression_FXT1;
4236    GLboolean OES_EGL_image;
4237    GLboolean OES_draw_texture;
4238    GLboolean OES_depth_texture_cube_map;
4239    GLboolean OES_EGL_image_external;
4240    GLboolean OES_texture_float;
4241    GLboolean OES_texture_float_linear;
4242    GLboolean OES_texture_half_float;
4243    GLboolean OES_texture_half_float_linear;
4244    GLboolean OES_compressed_ETC1_RGB8_texture;
4245    GLboolean OES_geometry_shader;
4246    GLboolean OES_texture_compression_astc;
4247    GLboolean extension_sentinel;
4248    /** The extension string */
4249    const GLubyte *String;
4250    /** Number of supported extensions */
4251    GLuint Count;
4252    /**
4253     * The context version which extension helper functions compare against.
4254     * By default, the value is equal to ctx->Version. This changes to ~0
4255     * while meta is in progress.
4256     */
4257    GLubyte Version;
4258    /**
4259     * Force-enabled, yet unrecognized, extensions.
4260     * See _mesa_one_time_init_extension_overrides()
4261     */
4262 #define MAX_UNRECOGNIZED_EXTENSIONS 16
4263    const char *unrecognized_extensions[MAX_UNRECOGNIZED_EXTENSIONS];
4264 };
4265 
4266 
4267 /**
4268  * A stack of matrices (projection, modelview, color, texture, etc).
4269  */
4270 struct gl_matrix_stack
4271 {
4272    GLmatrix *Top;      /**< points into Stack */
4273    GLmatrix *Stack;    /**< array [MaxDepth] of GLmatrix */
4274    unsigned StackSize; /**< Number of elements in Stack */
4275    GLuint Depth;       /**< 0 <= Depth < MaxDepth */
4276    GLuint MaxDepth;    /**< size of Stack[] array */
4277    GLuint DirtyFlag;   /**< _NEW_MODELVIEW or _NEW_PROJECTION, for example */
4278 };
4279 
4280 
4281 /**
4282  * \name Bits for image transfer operations
4283  * \sa __struct gl_contextRec::ImageTransferState.
4284  */
4285 /*@{*/
4286 #define IMAGE_SCALE_BIAS_BIT                      0x1
4287 #define IMAGE_SHIFT_OFFSET_BIT                    0x2
4288 #define IMAGE_MAP_COLOR_BIT                       0x4
4289 #define IMAGE_CLAMP_BIT                           0x800
4290 
4291 
4292 /** Pixel Transfer ops */
4293 #define IMAGE_BITS (IMAGE_SCALE_BIAS_BIT |			\
4294 		    IMAGE_SHIFT_OFFSET_BIT |			\
4295 		    IMAGE_MAP_COLOR_BIT)
4296 
4297 /**
4298  * \name Bits to indicate what state has changed.
4299  */
4300 /*@{*/
4301 #define _NEW_MODELVIEW         (1u << 0)   /**< gl_context::ModelView */
4302 #define _NEW_PROJECTION        (1u << 1)   /**< gl_context::Projection */
4303 #define _NEW_TEXTURE_MATRIX    (1u << 2)   /**< gl_context::TextureMatrix */
4304 #define _NEW_COLOR             (1u << 3)   /**< gl_context::Color */
4305 #define _NEW_DEPTH             (1u << 4)   /**< gl_context::Depth */
4306 #define _NEW_EVAL              (1u << 5)   /**< gl_context::Eval, EvalMap */
4307 #define _NEW_FOG               (1u << 6)   /**< gl_context::Fog */
4308 #define _NEW_HINT              (1u << 7)   /**< gl_context::Hint */
4309 #define _NEW_LIGHT             (1u << 8)   /**< gl_context::Light */
4310 #define _NEW_LINE              (1u << 9)   /**< gl_context::Line */
4311 #define _NEW_PIXEL             (1u << 10)  /**< gl_context::Pixel */
4312 #define _NEW_POINT             (1u << 11)  /**< gl_context::Point */
4313 #define _NEW_POLYGON           (1u << 12)  /**< gl_context::Polygon */
4314 #define _NEW_POLYGONSTIPPLE    (1u << 13)  /**< gl_context::PolygonStipple */
4315 #define _NEW_SCISSOR           (1u << 14)  /**< gl_context::Scissor */
4316 #define _NEW_STENCIL           (1u << 15)  /**< gl_context::Stencil */
4317 #define _NEW_TEXTURE_OBJECT    (1u << 16)  /**< gl_context::Texture (bindings only) */
4318 #define _NEW_TRANSFORM         (1u << 17)  /**< gl_context::Transform */
4319 #define _NEW_VIEWPORT          (1u << 18)  /**< gl_context::Viewport */
4320 #define _NEW_TEXTURE_STATE     (1u << 19)  /**< gl_context::Texture (states only) */
4321 #define _NEW_ARRAY             (1u << 20)  /**< gl_context::Array */
4322 #define _NEW_RENDERMODE        (1u << 21)  /**< gl_context::RenderMode, etc */
4323 #define _NEW_BUFFERS           (1u << 22)  /**< gl_context::Visual, DrawBuffer, */
4324 #define _NEW_CURRENT_ATTRIB    (1u << 23)  /**< gl_context::Current */
4325 #define _NEW_MULTISAMPLE       (1u << 24)  /**< gl_context::Multisample */
4326 #define _NEW_TRACK_MATRIX      (1u << 25)  /**< gl_context::VertexProgram */
4327 #define _NEW_PROGRAM           (1u << 26)  /**< New program/shader state */
4328 #define _NEW_PROGRAM_CONSTANTS (1u << 27)
4329 /* gap */
4330 #define _NEW_FRAG_CLAMP        (1u << 29)
4331 /* gap, re-use for core Mesa state only; use ctx->DriverFlags otherwise */
4332 #define _NEW_VARYING_VP_INPUTS (1u << 31) /**< gl_context::varying_vp_inputs */
4333 #define _NEW_ALL ~0
4334 /*@}*/
4335 
4336 
4337 /**
4338  * Composite state flags
4339  */
4340 /*@{*/
4341 #define _NEW_TEXTURE   (_NEW_TEXTURE_OBJECT | _NEW_TEXTURE_STATE)
4342 
4343 #define _MESA_NEW_NEED_EYE_COORDS         (_NEW_LIGHT |		\
4344                                            _NEW_TEXTURE_STATE |	\
4345                                            _NEW_POINT |		\
4346                                            _NEW_PROGRAM |	\
4347                                            _NEW_MODELVIEW)
4348 
4349 #define _MESA_NEW_SEPARATE_SPECULAR        (_NEW_LIGHT | \
4350                                             _NEW_FOG | \
4351                                             _NEW_PROGRAM)
4352 
4353 
4354 /*@}*/
4355 
4356 
4357 
4358 
4359 /* This has to be included here. */
4360 #include "dd.h"
4361 
4362 
4363 /**
4364  * Display list flags.
4365  * Strictly this is a tnl-private concept, but it doesn't seem
4366  * worthwhile adding a tnl private structure just to hold this one bit
4367  * of information:
4368  */
4369 #define DLIST_DANGLING_REFS     0x1
4370 
4371 
4372 /** Opaque declaration of display list payload data type */
4373 union gl_dlist_node;
4374 
4375 
4376 /**
4377  * Provide a location where information about a display list can be
4378  * collected.  Could be extended with driverPrivate structures,
4379  * etc. in the future.
4380  */
4381 struct gl_display_list
4382 {
4383    GLuint Name;
4384    GLbitfield Flags;  /**< DLIST_x flags */
4385    GLchar *Label;     /**< GL_KHR_debug */
4386    /** The dlist commands are in a linked list of nodes */
4387    union gl_dlist_node *Head;
4388 };
4389 
4390 
4391 /**
4392  * State used during display list compilation and execution.
4393  */
4394 struct gl_dlist_state
4395 {
4396    struct gl_display_list *CurrentList; /**< List currently being compiled */
4397    union gl_dlist_node *CurrentBlock; /**< Pointer to current block of nodes */
4398    GLuint CurrentPos;		/**< Index into current block of nodes */
4399    GLuint CallDepth;		/**< Current recursion calling depth */
4400 
4401    GLvertexformat ListVtxfmt;
4402 
4403    GLubyte ActiveAttribSize[VERT_ATTRIB_MAX];
4404    GLfloat CurrentAttrib[VERT_ATTRIB_MAX][4];
4405 
4406    GLubyte ActiveMaterialSize[MAT_ATTRIB_MAX];
4407    GLfloat CurrentMaterial[MAT_ATTRIB_MAX][4];
4408 
4409    struct {
4410       /* State known to have been set by the currently-compiling display
4411        * list.  Used to eliminate some redundant state changes.
4412        */
4413       GLenum ShadeModel;
4414    } Current;
4415 };
4416 
4417 /** @{
4418  *
4419  * These are a mapping of the GL_ARB_debug_output/GL_KHR_debug enums
4420  * to small enums suitable for use as an array index.
4421  */
4422 
4423 enum mesa_debug_source {
4424    MESA_DEBUG_SOURCE_API,
4425    MESA_DEBUG_SOURCE_WINDOW_SYSTEM,
4426    MESA_DEBUG_SOURCE_SHADER_COMPILER,
4427    MESA_DEBUG_SOURCE_THIRD_PARTY,
4428    MESA_DEBUG_SOURCE_APPLICATION,
4429    MESA_DEBUG_SOURCE_OTHER,
4430    MESA_DEBUG_SOURCE_COUNT
4431 };
4432 
4433 enum mesa_debug_type {
4434    MESA_DEBUG_TYPE_ERROR,
4435    MESA_DEBUG_TYPE_DEPRECATED,
4436    MESA_DEBUG_TYPE_UNDEFINED,
4437    MESA_DEBUG_TYPE_PORTABILITY,
4438    MESA_DEBUG_TYPE_PERFORMANCE,
4439    MESA_DEBUG_TYPE_OTHER,
4440    MESA_DEBUG_TYPE_MARKER,
4441    MESA_DEBUG_TYPE_PUSH_GROUP,
4442    MESA_DEBUG_TYPE_POP_GROUP,
4443    MESA_DEBUG_TYPE_COUNT
4444 };
4445 
4446 enum mesa_debug_severity {
4447    MESA_DEBUG_SEVERITY_LOW,
4448    MESA_DEBUG_SEVERITY_MEDIUM,
4449    MESA_DEBUG_SEVERITY_HIGH,
4450    MESA_DEBUG_SEVERITY_NOTIFICATION,
4451    MESA_DEBUG_SEVERITY_COUNT
4452 };
4453 
4454 /** @} */
4455 
4456 /**
4457  * Driver-specific state flags.
4458  *
4459  * These are or'd with gl_context::NewDriverState to notify a driver about
4460  * a state change. The driver sets the flags at context creation and
4461  * the meaning of the bits set is opaque to core Mesa.
4462  */
4463 struct gl_driver_flags
4464 {
4465    /** gl_context::Array::_DrawArrays (vertex array state) */
4466    uint64_t NewArray;
4467 
4468    /** gl_context::TransformFeedback::CurrentObject */
4469    uint64_t NewTransformFeedback;
4470 
4471    /** gl_context::TransformFeedback::CurrentObject::shader_program */
4472    uint64_t NewTransformFeedbackProg;
4473 
4474    /** gl_context::RasterDiscard */
4475    uint64_t NewRasterizerDiscard;
4476 
4477    /** gl_context::TileRasterOrder* */
4478    uint64_t NewTileRasterOrder;
4479 
4480    /**
4481     * gl_context::UniformBufferBindings
4482     * gl_shader_program::UniformBlocks
4483     */
4484    uint64_t NewUniformBuffer;
4485 
4486    /**
4487     * gl_context::ShaderStorageBufferBindings
4488     * gl_shader_program::ShaderStorageBlocks
4489     */
4490    uint64_t NewShaderStorageBuffer;
4491 
4492    uint64_t NewTextureBuffer;
4493 
4494    /**
4495     * gl_context::AtomicBufferBindings
4496     */
4497    uint64_t NewAtomicBuffer;
4498 
4499    /**
4500     * gl_context::ImageUnits
4501     */
4502    uint64_t NewImageUnits;
4503 
4504    /**
4505     * gl_context::TessCtrlProgram::patch_default_*
4506     */
4507    uint64_t NewDefaultTessLevels;
4508 
4509    /**
4510     * gl_context::IntelConservativeRasterization
4511     */
4512    uint64_t NewIntelConservativeRasterization;
4513 
4514    /**
4515     * gl_context::Scissor::WindowRects
4516     */
4517    uint64_t NewWindowRectangles;
4518 
4519    /** gl_context::Color::sRGBEnabled */
4520    uint64_t NewFramebufferSRGB;
4521 
4522    /** gl_context::Scissor::EnableFlags */
4523    uint64_t NewScissorTest;
4524 
4525    /** gl_context::Scissor::ScissorArray */
4526    uint64_t NewScissorRect;
4527 
4528    /** gl_context::Color::Alpha* */
4529    uint64_t NewAlphaTest;
4530 
4531    /** gl_context::Color::Blend/Dither */
4532    uint64_t NewBlend;
4533 
4534    /** gl_context::Color::BlendColor */
4535    uint64_t NewBlendColor;
4536 
4537    /** gl_context::Color::Color/Index */
4538    uint64_t NewColorMask;
4539 
4540    /** gl_context::Depth */
4541    uint64_t NewDepth;
4542 
4543    /** gl_context::Color::LogicOp/ColorLogicOp/IndexLogicOp */
4544    uint64_t NewLogicOp;
4545 
4546    /** gl_context::Multisample::Enabled */
4547    uint64_t NewMultisampleEnable;
4548 
4549    /** gl_context::Multisample::SampleAlphaTo* */
4550    uint64_t NewSampleAlphaToXEnable;
4551 
4552    /** gl_context::Multisample::SampleCoverage/SampleMaskValue */
4553    uint64_t NewSampleMask;
4554 
4555    /** gl_context::Multisample::(Min)SampleShading */
4556    uint64_t NewSampleShading;
4557 
4558    /** gl_context::Stencil */
4559    uint64_t NewStencil;
4560 
4561    /** gl_context::Transform::ClipOrigin/ClipDepthMode */
4562    uint64_t NewClipControl;
4563 
4564    /** gl_context::Transform::EyeUserPlane */
4565    uint64_t NewClipPlane;
4566 
4567    /** gl_context::Transform::ClipPlanesEnabled */
4568    uint64_t NewClipPlaneEnable;
4569 
4570    /** gl_context::Transform::DepthClamp */
4571    uint64_t NewDepthClamp;
4572 
4573    /** gl_context::Line */
4574    uint64_t NewLineState;
4575 
4576    /** gl_context::Polygon */
4577    uint64_t NewPolygonState;
4578 
4579    /** gl_context::PolygonStipple */
4580    uint64_t NewPolygonStipple;
4581 
4582    /** gl_context::ViewportArray */
4583    uint64_t NewViewport;
4584 
4585    /** Shader constants (uniforms, program parameters, state constants) */
4586    uint64_t NewShaderConstants[MESA_SHADER_STAGES];
4587 };
4588 
4589 struct gl_buffer_binding
4590 {
4591    struct gl_buffer_object *BufferObject;
4592    /** Start of uniform block data in the buffer */
4593    GLintptr Offset;
4594    /** Size of data allowed to be referenced from the buffer (in bytes) */
4595    GLsizeiptr Size;
4596    /**
4597     * glBindBufferBase() indicates that the Size should be ignored and only
4598     * limited by the current size of the BufferObject.
4599     */
4600    GLboolean AutomaticSize;
4601 };
4602 
4603 /**
4604  * ARB_shader_image_load_store image unit.
4605  */
4606 struct gl_image_unit
4607 {
4608    /**
4609     * Texture object bound to this unit.
4610     */
4611    struct gl_texture_object *TexObj;
4612 
4613    /**
4614     * Level of the texture object bound to this unit.
4615     */
4616    GLuint Level;
4617 
4618    /**
4619     * \c GL_TRUE if the whole level is bound as an array of layers, \c
4620     * GL_FALSE if only some specific layer of the texture is bound.
4621     * \sa Layer
4622     */
4623    GLboolean Layered;
4624 
4625    /**
4626     * Layer of the texture object bound to this unit as specified by the
4627     * application.
4628     */
4629    GLuint Layer;
4630 
4631    /**
4632     * Layer of the texture object bound to this unit, or zero if the
4633     * whole level is bound.
4634     */
4635    GLuint _Layer;
4636 
4637    /**
4638     * Access allowed to this texture image.  Either \c GL_READ_ONLY,
4639     * \c GL_WRITE_ONLY or \c GL_READ_WRITE.
4640     */
4641    GLenum Access;
4642 
4643    /**
4644     * GL internal format that determines the interpretation of the
4645     * image memory when shader image operations are performed through
4646     * this unit.
4647     */
4648    GLenum Format;
4649 
4650    /**
4651     * Mesa format corresponding to \c Format.
4652     */
4653    mesa_format _ActualFormat;
4654 
4655 };
4656 
4657 /**
4658  * Shader subroutines storage
4659  */
4660 struct gl_subroutine_index_binding
4661 {
4662    GLuint NumIndex;
4663    GLuint *IndexPtr;
4664 };
4665 
4666 struct gl_texture_handle_object
4667 {
4668    struct gl_texture_object *texObj;
4669    struct gl_sampler_object *sampObj;
4670    GLuint64 handle;
4671 };
4672 
4673 struct gl_image_handle_object
4674 {
4675    struct gl_image_unit imgObj;
4676    GLuint64 handle;
4677 };
4678 
4679 struct gl_memory_object
4680 {
4681    GLuint Name;            /**< hash table ID/name */
4682    GLboolean Immutable;    /**< denotes mutability state of parameters */
4683    GLboolean Dedicated;    /**< import memory from a dedicated allocation */
4684 };
4685 
4686 /**
4687  * Mesa rendering context.
4688  *
4689  * This is the central context data structure for Mesa.  Almost all
4690  * OpenGL state is contained in this structure.
4691  * Think of this as a base class from which device drivers will derive
4692  * sub classes.
4693  */
4694 struct gl_context
4695 {
4696    /** State possibly shared with other contexts in the address space */
4697    struct gl_shared_state *Shared;
4698 
4699    /** \name API function pointer tables */
4700    /*@{*/
4701    gl_api API;
4702 
4703    /**
4704     * The current dispatch table for non-displaylist-saving execution, either
4705     * BeginEnd or OutsideBeginEnd
4706     */
4707    struct _glapi_table *Exec;
4708    /**
4709     * The normal dispatch table for non-displaylist-saving, non-begin/end
4710     */
4711    struct _glapi_table *OutsideBeginEnd;
4712    /** The dispatch table used between glNewList() and glEndList() */
4713    struct _glapi_table *Save;
4714    /**
4715     * The dispatch table used between glBegin() and glEnd() (outside of a
4716     * display list).  Only valid functions between those two are set, which is
4717     * mostly just the set in a GLvertexformat struct.
4718     */
4719    struct _glapi_table *BeginEnd;
4720    /**
4721     * Dispatch table for when a graphics reset has happened.
4722     */
4723    struct _glapi_table *ContextLost;
4724    /**
4725     * Dispatch table used to marshal API calls from the client program to a
4726     * separate server thread.  NULL if API calls are not being marshalled to
4727     * another thread.
4728     */
4729    struct _glapi_table *MarshalExec;
4730    /**
4731     * Dispatch table currently in use for fielding API calls from the client
4732     * program.  If API calls are being marshalled to another thread, this ==
4733     * MarshalExec.  Otherwise it == CurrentServerDispatch.
4734     */
4735    struct _glapi_table *CurrentClientDispatch;
4736 
4737    /**
4738     * Dispatch table currently in use for performing API calls.  == Save or
4739     * Exec.
4740     */
4741    struct _glapi_table *CurrentServerDispatch;
4742 
4743    /*@}*/
4744 
4745    struct glthread_state *GLThread;
4746 
4747    struct gl_config Visual;
4748    struct gl_framebuffer *DrawBuffer;	/**< buffer for writing */
4749    struct gl_framebuffer *ReadBuffer;	/**< buffer for reading */
4750    struct gl_framebuffer *WinSysDrawBuffer;  /**< set with MakeCurrent */
4751    struct gl_framebuffer *WinSysReadBuffer;  /**< set with MakeCurrent */
4752 
4753    /**
4754     * Device driver function pointer table
4755     */
4756    struct dd_function_table Driver;
4757 
4758    /** Core/Driver constants */
4759    struct gl_constants Const;
4760 
4761    /** \name The various 4x4 matrix stacks */
4762    /*@{*/
4763    struct gl_matrix_stack ModelviewMatrixStack;
4764    struct gl_matrix_stack ProjectionMatrixStack;
4765    struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
4766    struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
4767    struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
4768    /*@}*/
4769 
4770    /** Combined modelview and projection matrix */
4771    GLmatrix _ModelProjectMatrix;
4772 
4773    /** \name Display lists */
4774    struct gl_dlist_state ListState;
4775 
4776    GLboolean ExecuteFlag;	/**< Execute GL commands? */
4777    GLboolean CompileFlag;	/**< Compile GL commands into display list? */
4778 
4779    /** Extension information */
4780    struct gl_extensions Extensions;
4781 
4782    /** GL version integer, for example 31 for GL 3.1, or 20 for GLES 2.0. */
4783    GLuint Version;
4784    char *VersionString;
4785 
4786    /** \name State attribute stack (for glPush/PopAttrib) */
4787    /*@{*/
4788    GLuint AttribStackDepth;
4789    struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
4790    /*@}*/
4791 
4792    /** \name Renderer attribute groups
4793     *
4794     * We define a struct for each attribute group to make pushing and popping
4795     * attributes easy.  Also it's a good organization.
4796     */
4797    /*@{*/
4798    struct gl_accum_attrib	Accum;		/**< Accum buffer attributes */
4799    struct gl_colorbuffer_attrib	Color;		/**< Color buffer attributes */
4800    struct gl_current_attrib	Current;	/**< Current attributes */
4801    struct gl_depthbuffer_attrib	Depth;		/**< Depth buffer attributes */
4802    struct gl_eval_attrib	Eval;		/**< Eval attributes */
4803    struct gl_fog_attrib		Fog;		/**< Fog attributes */
4804    struct gl_hint_attrib	Hint;		/**< Hint attributes */
4805    struct gl_light_attrib	Light;		/**< Light attributes */
4806    struct gl_line_attrib	Line;		/**< Line attributes */
4807    struct gl_list_attrib	List;		/**< List attributes */
4808    struct gl_multisample_attrib Multisample;
4809    struct gl_pixel_attrib	Pixel;		/**< Pixel attributes */
4810    struct gl_point_attrib	Point;		/**< Point attributes */
4811    struct gl_polygon_attrib	Polygon;	/**< Polygon attributes */
4812    GLuint PolygonStipple[32];			/**< Polygon stipple */
4813    struct gl_scissor_attrib	Scissor;	/**< Scissor attributes */
4814    struct gl_stencil_attrib	Stencil;	/**< Stencil buffer attributes */
4815    struct gl_texture_attrib	Texture;	/**< Texture attributes */
4816    struct gl_transform_attrib	Transform;	/**< Transformation attributes */
4817    struct gl_viewport_attrib	ViewportArray[MAX_VIEWPORTS];	/**< Viewport attributes */
4818    /*@}*/
4819 
4820    /** \name Client attribute stack */
4821    /*@{*/
4822    GLuint ClientAttribStackDepth;
4823    struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
4824    /*@}*/
4825 
4826    /** \name Client attribute groups */
4827    /*@{*/
4828    struct gl_array_attrib	Array;	/**< Vertex arrays */
4829    struct gl_pixelstore_attrib	Pack;	/**< Pixel packing */
4830    struct gl_pixelstore_attrib	Unpack;	/**< Pixel unpacking */
4831    struct gl_pixelstore_attrib	DefaultPacking;	/**< Default params */
4832    /*@}*/
4833 
4834    /** \name Other assorted state (not pushed/popped on attribute stack) */
4835    /*@{*/
4836    struct gl_pixelmaps          PixelMaps;
4837 
4838    struct gl_evaluators EvalMap;   /**< All evaluators */
4839    struct gl_feedback   Feedback;  /**< Feedback */
4840    struct gl_selection  Select;    /**< Selection */
4841 
4842    struct gl_program_state Program;  /**< general program state */
4843    struct gl_vertex_program_state VertexProgram;
4844    struct gl_fragment_program_state FragmentProgram;
4845    struct gl_geometry_program_state GeometryProgram;
4846    struct gl_compute_program_state ComputeProgram;
4847    struct gl_tess_ctrl_program_state TessCtrlProgram;
4848    struct gl_tess_eval_program_state TessEvalProgram;
4849    struct gl_ati_fragment_shader_state ATIFragmentShader;
4850 
4851    struct gl_pipeline_shader_state Pipeline; /**< GLSL pipeline shader object state */
4852    struct gl_pipeline_object Shader; /**< GLSL shader object state */
4853 
4854    /**
4855     * Current active shader pipeline state
4856     *
4857     * Almost all internal users want ::_Shader instead of ::Shader.  The
4858     * exceptions are bits of legacy GLSL API that do not know about separate
4859     * shader objects.
4860     *
4861     * If a program is active via \c glUseProgram, this will point to
4862     * \c ::Shader.
4863     *
4864     * If a program pipeline is active via \c glBindProgramPipeline, this will
4865     * point to \c ::Pipeline.Current.
4866     *
4867     * If neither a program nor a program pipeline is active, this will point to
4868     * \c ::Pipeline.Default.  This ensures that \c ::_Shader will never be
4869     * \c NULL.
4870     */
4871    struct gl_pipeline_object *_Shader;
4872 
4873    struct gl_query_state Query;  /**< occlusion, timer queries */
4874 
4875    struct gl_transform_feedback_state TransformFeedback;
4876 
4877    struct gl_perf_monitor_state PerfMonitor;
4878    struct gl_perf_query_state PerfQuery;
4879 
4880    struct gl_buffer_object *DrawIndirectBuffer; /** < GL_ARB_draw_indirect */
4881    struct gl_buffer_object *ParameterBuffer; /** < GL_ARB_indirect_parameters */
4882    struct gl_buffer_object *DispatchIndirectBuffer; /** < GL_ARB_compute_shader */
4883 
4884    struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */
4885    struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */
4886 
4887    struct gl_buffer_object *QueryBuffer; /**< GL_ARB_query_buffer_object */
4888 
4889    /**
4890     * Current GL_ARB_uniform_buffer_object binding referenced by
4891     * GL_UNIFORM_BUFFER target for glBufferData, glMapBuffer, etc.
4892     */
4893    struct gl_buffer_object *UniformBuffer;
4894 
4895    /**
4896     * Current GL_ARB_shader_storage_buffer_object binding referenced by
4897     * GL_SHADER_STORAGE_BUFFER target for glBufferData, glMapBuffer, etc.
4898     */
4899    struct gl_buffer_object *ShaderStorageBuffer;
4900 
4901    /**
4902     * Array of uniform buffers for GL_ARB_uniform_buffer_object and GL 3.1.
4903     * This is set up using glBindBufferRange() or glBindBufferBase().  They are
4904     * associated with uniform blocks by glUniformBlockBinding()'s state in the
4905     * shader program.
4906     */
4907    struct gl_buffer_binding
4908       UniformBufferBindings[MAX_COMBINED_UNIFORM_BUFFERS];
4909 
4910    /**
4911     * Array of shader storage buffers for ARB_shader_storage_buffer_object
4912     * and GL 4.3. This is set up using glBindBufferRange() or
4913     * glBindBufferBase().  They are associated with shader storage blocks by
4914     * glShaderStorageBlockBinding()'s state in the shader program.
4915     */
4916    struct gl_buffer_binding
4917       ShaderStorageBufferBindings[MAX_COMBINED_SHADER_STORAGE_BUFFERS];
4918 
4919    /**
4920     * Object currently associated with the GL_ATOMIC_COUNTER_BUFFER
4921     * target.
4922     */
4923    struct gl_buffer_object *AtomicBuffer;
4924 
4925    /**
4926     * Object currently associated w/ the GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
4927     * target.
4928     */
4929    struct gl_buffer_object *ExternalVirtualMemoryBuffer;
4930 
4931    /**
4932     * Array of atomic counter buffer binding points.
4933     */
4934    struct gl_buffer_binding
4935       AtomicBufferBindings[MAX_COMBINED_ATOMIC_BUFFERS];
4936 
4937    /**
4938     * Array of image units for ARB_shader_image_load_store.
4939     */
4940    struct gl_image_unit ImageUnits[MAX_IMAGE_UNITS];
4941 
4942    struct gl_subroutine_index_binding SubroutineIndex[MESA_SHADER_STAGES];
4943    /*@}*/
4944 
4945    struct gl_meta_state *Meta;  /**< for "meta" operations */
4946 
4947    /* GL_EXT_framebuffer_object */
4948    struct gl_renderbuffer *CurrentRenderbuffer;
4949 
4950    GLenum ErrorValue;        /**< Last error code */
4951 
4952    /**
4953     * Recognize and silence repeated error debug messages in buggy apps.
4954     */
4955    const char *ErrorDebugFmtString;
4956    GLuint ErrorDebugCount;
4957 
4958    /* GL_ARB_debug_output/GL_KHR_debug */
4959    simple_mtx_t DebugMutex;
4960    struct gl_debug_state *Debug;
4961 
4962    GLenum RenderMode;        /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
4963    GLbitfield NewState;      /**< bitwise-or of _NEW_* flags */
4964    uint64_t NewDriverState;  /**< bitwise-or of flags from DriverFlags */
4965 
4966    struct gl_driver_flags DriverFlags;
4967 
4968    GLboolean ViewportInitialized;  /**< has viewport size been initialized? */
4969 
4970    GLbitfield varying_vp_inputs;  /**< mask of VERT_BIT_* flags */
4971 
4972    /** \name Derived state */
4973    GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
4974    GLfloat _EyeZDir[3];
4975    GLfloat _ModelViewInvScale; /* may be for model- or eyespace lighting */
4976    GLfloat _ModelViewInvScaleEyespace; /* always factor defined in spec */
4977    GLboolean _NeedEyeCoords;
4978    GLboolean _ForceEyeCoords;
4979 
4980    GLuint TextureStateTimestamp; /**< detect changes to shared state */
4981 
4982    struct gl_list_extensions *ListExt; /**< driver dlist extensions */
4983 
4984    /** \name For debugging/development only */
4985    /*@{*/
4986    GLboolean FirstTimeCurrent;
4987    /*@}*/
4988 
4989    /**
4990     * False if this context was created without a config. This is needed
4991     * because the initial state of glDrawBuffers depends on this
4992     */
4993    GLboolean HasConfig;
4994 
4995    GLboolean TextureFormatSupported[MESA_FORMAT_COUNT];
4996 
4997    GLboolean RasterDiscard;  /**< GL_RASTERIZER_DISCARD */
4998    GLboolean IntelConservativeRasterization; /**< GL_INTEL_CONSERVATIVE_RASTERIZATION */
4999 
5000    /** Does glVertexAttrib(0) alias glVertex()? */
5001    bool _AttribZeroAliasesVertex;
5002 
5003    /**
5004     * When set, TileRasterOrderIncreasingX/Y control the order that a tiled
5005     * renderer's tiles should be excecuted, to meet the requirements of
5006     * GL_MESA_tile_raster_order.
5007     */
5008    GLboolean TileRasterOrderFixed;
5009    GLboolean TileRasterOrderIncreasingX;
5010    GLboolean TileRasterOrderIncreasingY;
5011 
5012    /**
5013     * \name Hooks for module contexts.
5014     *
5015     * These will eventually live in the driver or elsewhere.
5016     */
5017    /*@{*/
5018    void *swrast_context;
5019    void *swsetup_context;
5020    void *swtnl_context;
5021    struct vbo_context *vbo_context;
5022    struct st_context *st;
5023    void *aelt_context;
5024    /*@}*/
5025 
5026    /**
5027     * \name NV_vdpau_interop
5028     */
5029    /*@{*/
5030    const void *vdpDevice;
5031    const void *vdpGetProcAddress;
5032    struct set *vdpSurfaces;
5033    /*@}*/
5034 
5035    /**
5036     * Has this context observed a GPU reset in any context in the share group?
5037     *
5038     * Once this field becomes true, it is never reset to false.
5039     */
5040    GLboolean ShareGroupReset;
5041 
5042    /**
5043     * \name OES_primitive_bounding_box
5044     *
5045     * Stores the arguments to glPrimitiveBoundingBox
5046     */
5047    GLfloat PrimitiveBoundingBox[8];
5048 
5049    struct disk_cache *Cache;
5050 
5051    /**
5052     * \name GL_ARB_bindless_texture
5053     */
5054    /*@{*/
5055    struct hash_table_u64 *ResidentTextureHandles;
5056    struct hash_table_u64 *ResidentImageHandles;
5057    /*@}*/
5058 };
5059 
5060 /**
5061  * Information about memory usage. All sizes are in kilobytes.
5062  */
5063 struct gl_memory_info
5064 {
5065    unsigned total_device_memory; /**< size of device memory, e.g. VRAM */
5066    unsigned avail_device_memory; /**< free device memory at the moment */
5067    unsigned total_staging_memory; /**< size of staging memory, e.g. GART */
5068    unsigned avail_staging_memory; /**< free staging memory at the moment */
5069    unsigned device_memory_evicted; /**< size of memory evicted (monotonic counter) */
5070    unsigned nr_device_memory_evictions; /**< # of evictions (monotonic counter) */
5071 };
5072 
5073 #ifdef DEBUG
5074 extern int MESA_VERBOSE;
5075 extern int MESA_DEBUG_FLAGS;
5076 # define MESA_FUNCTION __func__
5077 #else
5078 # define MESA_VERBOSE 0
5079 # define MESA_DEBUG_FLAGS 0
5080 # define MESA_FUNCTION "a function"
5081 #endif
5082 
5083 
5084 /** The MESA_VERBOSE var is a bitmask of these flags */
5085 enum _verbose
5086 {
5087    VERBOSE_VARRAY		= 0x0001,
5088    VERBOSE_TEXTURE		= 0x0002,
5089    VERBOSE_MATERIAL		= 0x0004,
5090    VERBOSE_PIPELINE		= 0x0008,
5091    VERBOSE_DRIVER		= 0x0010,
5092    VERBOSE_STATE		= 0x0020,
5093    VERBOSE_API			= 0x0040,
5094    VERBOSE_DISPLAY_LIST		= 0x0100,
5095    VERBOSE_LIGHTING		= 0x0200,
5096    VERBOSE_PRIMS		= 0x0400,
5097    VERBOSE_VERTS		= 0x0800,
5098    VERBOSE_DISASSEM		= 0x1000,
5099    VERBOSE_DRAW                 = 0x2000,
5100    VERBOSE_SWAPBUFFERS          = 0x4000
5101 };
5102 
5103 
5104 /** The MESA_DEBUG_FLAGS var is a bitmask of these flags */
5105 enum _debug
5106 {
5107    DEBUG_SILENT                 = (1 << 0),
5108    DEBUG_ALWAYS_FLUSH		= (1 << 1),
5109    DEBUG_INCOMPLETE_TEXTURE     = (1 << 2),
5110    DEBUG_INCOMPLETE_FBO         = (1 << 3),
5111    DEBUG_CONTEXT                = (1 << 4)
5112 };
5113 
5114 #ifdef __cplusplus
5115 }
5116 #endif
5117 
5118 #endif /* MTYPES_H */
5119