• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "util/glheader.h"
42 #include "main/glthread.h"
43 #include "main/consts_exts.h"
44 #include "main/shader_types.h"
45 #include "main/glconfig.h"
46 #include "main/menums.h"
47 #include "main/config.h"
48 #include "glapi/glapi.h"
49 #include "math/m_matrix.h"	/* GLmatrix */
50 #include "compiler/shader_enums.h"
51 #include "compiler/shader_info.h"
52 #include "main/formats.h"       /* MESA_FORMAT_COUNT */
53 #include "compiler/glsl/list.h"
54 #include "compiler/glsl/ir_uniform.h"
55 #include "util/u_idalloc.h"
56 #include "util/simple_mtx.h"
57 #include "util/u_dynarray.h"
58 #include "util/mesa-sha1.h"
59 #include "vbo/vbo.h"
60 
61 #include "pipe/p_state.h"
62 
63 #include "frontend/api.h"
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 #define GET_COLORMASK_BIT(mask, buf, chan) (((mask) >> (4 * (buf) + (chan))) & 0x1)
70 #define GET_COLORMASK(mask, buf) (((mask) >> (4 * (buf))) & 0xf)
71 
72 
73 /**
74  * \name Some forward type declarations
75  */
76 /*@{*/
77 struct gl_attrib_node;
78 struct gl_list_extensions;
79 struct gl_meta_state;
80 struct gl_program_cache;
81 struct gl_texture_object;
82 struct gl_debug_state;
83 struct gl_context;
84 struct st_context;
85 struct gl_uniform_storage;
86 struct prog_instruction;
87 struct gl_program_parameter_list;
88 struct gl_shader_spirv_data;
89 struct set;
90 struct shader_includes;
91 /*@}*/
92 
93 
94 /** Extra draw modes beyond GL_POINTS, GL_TRIANGLE_FAN, etc */
95 #define PRIM_MAX                 GL_PATCHES
96 #define PRIM_OUTSIDE_BEGIN_END   (PRIM_MAX + 1)
97 #define PRIM_UNKNOWN             (PRIM_MAX + 2)
98 
99 /**
100  * Bit flags for all renderbuffers
101  */
102 #define BUFFER_BIT_FRONT_LEFT   (1 << BUFFER_FRONT_LEFT)
103 #define BUFFER_BIT_BACK_LEFT    (1 << BUFFER_BACK_LEFT)
104 #define BUFFER_BIT_FRONT_RIGHT  (1 << BUFFER_FRONT_RIGHT)
105 #define BUFFER_BIT_BACK_RIGHT   (1 << BUFFER_BACK_RIGHT)
106 #define BUFFER_BIT_DEPTH        (1 << BUFFER_DEPTH)
107 #define BUFFER_BIT_STENCIL      (1 << BUFFER_STENCIL)
108 #define BUFFER_BIT_ACCUM        (1 << BUFFER_ACCUM)
109 #define BUFFER_BIT_COLOR0       (1 << BUFFER_COLOR0)
110 #define BUFFER_BIT_COLOR1       (1 << BUFFER_COLOR1)
111 #define BUFFER_BIT_COLOR2       (1 << BUFFER_COLOR2)
112 #define BUFFER_BIT_COLOR3       (1 << BUFFER_COLOR3)
113 #define BUFFER_BIT_COLOR4       (1 << BUFFER_COLOR4)
114 #define BUFFER_BIT_COLOR5       (1 << BUFFER_COLOR5)
115 #define BUFFER_BIT_COLOR6       (1 << BUFFER_COLOR6)
116 #define BUFFER_BIT_COLOR7       (1 << BUFFER_COLOR7)
117 
118 /**
119  * Mask of all the color buffer bits (but not accum).
120  */
121 #define BUFFER_BITS_COLOR  (BUFFER_BIT_FRONT_LEFT | \
122                             BUFFER_BIT_BACK_LEFT | \
123                             BUFFER_BIT_FRONT_RIGHT | \
124                             BUFFER_BIT_BACK_RIGHT | \
125                             BUFFER_BIT_COLOR0 | \
126                             BUFFER_BIT_COLOR1 | \
127                             BUFFER_BIT_COLOR2 | \
128                             BUFFER_BIT_COLOR3 | \
129                             BUFFER_BIT_COLOR4 | \
130                             BUFFER_BIT_COLOR5 | \
131                             BUFFER_BIT_COLOR6 | \
132                             BUFFER_BIT_COLOR7)
133 
134 /* Mask of bits for depth+stencil buffers */
135 #define BUFFER_BITS_DEPTH_STENCIL (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)
136 
137 
138 #define FRONT_MATERIAL_BITS   (MAT_BIT_FRONT_EMISSION | \
139                                MAT_BIT_FRONT_AMBIENT | \
140                                MAT_BIT_FRONT_DIFFUSE | \
141                                MAT_BIT_FRONT_SPECULAR | \
142                                MAT_BIT_FRONT_SHININESS | \
143                                MAT_BIT_FRONT_INDEXES)
144 
145 #define BACK_MATERIAL_BITS    (MAT_BIT_BACK_EMISSION | \
146                                MAT_BIT_BACK_AMBIENT | \
147                                MAT_BIT_BACK_DIFFUSE | \
148                                MAT_BIT_BACK_SPECULAR | \
149                                MAT_BIT_BACK_SHININESS | \
150                                MAT_BIT_BACK_INDEXES)
151 
152 #define ALL_MATERIAL_BITS     (FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
153 /*@}*/
154 
155 
156 /**
157  * Material state.
158  */
159 struct gl_material
160 {
161    GLfloat Attrib[MAT_ATTRIB_MAX][4];
162 };
163 
164 
165 /**
166  * Light state flags.
167  */
168 /*@{*/
169 #define LIGHT_SPOT         0x1
170 #define LIGHT_LOCAL_VIEWER 0x2
171 #define LIGHT_POSITIONAL   0x4
172 #define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
173 /*@}*/
174 
175 
176 /**
177  * Light source state.
178  */
179 struct gl_light
180 {
181    GLboolean Enabled;		/**< On/off flag */
182 
183    /**
184     * \name Derived fields
185     */
186    /*@{*/
187    GLbitfield _Flags;		/**< Mask of LIGHT_x bits defined above */
188 
189    GLfloat _Position[4];	/**< position in eye/obj coordinates */
190    GLfloat _VP_inf_norm[3];	/**< Norm direction to infinite light */
191    GLfloat _h_inf_norm[3];	/**< Norm( _VP_inf_norm + <0,0,1> ) */
192    GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */
193    GLfloat _VP_inf_spot_attenuation;
194 
195    GLfloat _MatAmbient[2][3];	/**< material ambient * light ambient */
196    GLfloat _MatDiffuse[2][3];	/**< material diffuse * light diffuse */
197    GLfloat _MatSpecular[2][3];	/**< material spec * light specular */
198    /*@}*/
199 };
200 
201 
202 /**
203  * Light model state.
204  */
205 struct gl_lightmodel
206 {
207    GLfloat Ambient[4];		/**< ambient color */
208    GLboolean LocalViewer;	/**< Local (or infinite) view point? */
209    GLboolean TwoSide;		/**< Two (or one) sided lighting? */
210    GLenum16 ColorControl;	/**< either GL_SINGLE_COLOR
211                                      or GL_SEPARATE_SPECULAR_COLOR */
212 };
213 
214 
215 /**
216  * Accumulation buffer attribute group (GL_ACCUM_BUFFER_BIT)
217  */
218 struct gl_accum_attrib
219 {
220    GLfloat ClearColor[4];	/**< Accumulation buffer clear color */
221 };
222 
223 
224 /**
225  * Used for storing clear color, texture border color, etc.
226  * The float values are typically unclamped.
227  */
228 union gl_color_union
229 {
230    GLfloat f[4];
231    GLint i[4];
232    GLuint ui[4];
233 };
234 
235 
236 /**
237  * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
238  */
239 struct gl_colorbuffer_attrib
240 {
241    GLuint ClearIndex;                      /**< Index for glClear */
242    union gl_color_union ClearColor;        /**< Color for glClear, unclamped */
243    GLuint IndexMask;                       /**< Color index write mask */
244 
245    /** 4 colormask bits per draw buffer, max 8 draw buffers. 4*8 = 32 bits */
246    GLbitfield ColorMask;
247 
248    GLenum16 DrawBuffer[MAX_DRAW_BUFFERS];  /**< Which buffer to draw into */
249 
250    /**
251     * \name alpha testing
252     */
253    /*@{*/
254    GLboolean AlphaEnabled;		/**< Alpha test enabled flag */
255    GLenum16 AlphaFunc;			/**< Alpha test function */
256    GLfloat AlphaRefUnclamped;
257    GLclampf AlphaRef;			/**< Alpha reference value */
258    /*@}*/
259 
260    /**
261     * \name Blending
262     */
263    /*@{*/
264    GLbitfield BlendEnabled;		/**< Per-buffer blend enable flags */
265 
266    /* NOTE: this does _not_ depend on fragment clamping or any other clamping
267     * control, only on the fixed-pointness of the render target.
268     * The query does however depend on fragment color clamping.
269     */
270    GLfloat BlendColorUnclamped[4];      /**< Blending color */
271    GLfloat BlendColor[4];		/**< Blending color */
272 
273    struct
274    {
275       GLenum16 SrcRGB;             /**< RGB blend source term */
276       GLenum16 DstRGB;             /**< RGB blend dest term */
277       GLenum16 SrcA;               /**< Alpha blend source term */
278       GLenum16 DstA;               /**< Alpha blend dest term */
279       GLenum16 EquationRGB;        /**< GL_ADD, GL_SUBTRACT, etc. */
280       GLenum16 EquationA;          /**< GL_ADD, GL_SUBTRACT, etc. */
281    } Blend[MAX_DRAW_BUFFERS];
282    /** Bitfield of color buffers with enabled dual source blending. */
283    GLbitfield _BlendUsesDualSrc;
284    /** Are the blend func terms currently different for each buffer/target? */
285    GLboolean _BlendFuncPerBuffer;
286    /** Are the blend equations currently different for each buffer/target? */
287    GLboolean _BlendEquationPerBuffer;
288 
289    /**
290     * Which advanced blending mode is in use (or BLEND_NONE).
291     *
292     * KHR_blend_equation_advanced only allows advanced blending with a single
293     * draw buffer, and NVX_blend_equation_advanced_multi_draw_buffer still
294     * requires all draw buffers to match, so we only need a single value.
295     */
296    enum gl_advanced_blend_mode _AdvancedBlendMode;
297 
298    /** Coherency requested via glEnable(GL_BLEND_ADVANCED_COHERENT_KHR)? */
299    bool BlendCoherent;
300    /*@}*/
301 
302    /**
303     * \name Logic op
304     */
305    /*@{*/
306    GLboolean IndexLogicOpEnabled;	/**< Color index logic op enabled flag */
307    GLboolean ColorLogicOpEnabled;	/**< RGBA logic op enabled flag */
308    GLenum16 LogicOp;			/**< Logic operator */
309    enum gl_logicop_mode _LogicOp;
310    /*@}*/
311 
312    GLboolean DitherFlag;           /**< Dither enable flag */
313 
314    GLboolean _ClampFragmentColor;  /** < with GL_FIXED_ONLY_ARB resolved */
315    GLenum16 ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
316    GLenum16 ClampReadColor;     /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
317 
318    GLboolean sRGBEnabled;  /**< Framebuffer sRGB blending/updating requested */
319 };
320 
321 /**
322  * Vertex format to describe a vertex element.
323  */
324 struct gl_vertex_format
325 {
326    union gl_vertex_format_user User;
327    enum pipe_format _PipeFormat:16; /**< pipe_format for Gallium */
328    GLushort _ElementSize; /**< Size of each element in bytes */
329 };
330 
331 
332 /**
333  * Current attribute group (GL_CURRENT_BIT).
334  */
335 struct gl_current_attrib
336 {
337    /**
338     * \name Current vertex attributes (color, texcoords, etc).
339     * \note Values are valid only after FLUSH_VERTICES has been called.
340     * \note Index and Edgeflag current values are stored as floats in the
341     * SIX and SEVEN attribute slots.
342     * \note We need double storage for 64-bit vertex attributes
343     */
344    GLfloat Attrib[VERT_ATTRIB_MAX][4*2];
345 
346    /**
347     * \name Current raster position attributes (always up to date after a
348     * glRasterPos call).
349     */
350    GLfloat RasterPos[4];
351    GLfloat RasterDistance;
352    GLfloat RasterColor[4];
353    GLfloat RasterSecondaryColor[4];
354    GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
355    GLboolean RasterPosValid;
356 };
357 
358 
359 /**
360  * Depth buffer attribute group (GL_DEPTH_BUFFER_BIT).
361  */
362 struct gl_depthbuffer_attrib
363 {
364    GLenum16 Func;		/**< Function for depth buffer compare */
365    GLclampd Clear;		/**< Value to clear depth buffer to */
366    GLboolean Test;		/**< Depth buffering enabled flag */
367    GLboolean Mask;		/**< Depth buffer writable? */
368    GLboolean BoundsTest;        /**< GL_EXT_depth_bounds_test */
369    GLclampd BoundsMin, BoundsMax;/**< GL_EXT_depth_bounds_test */
370 };
371 
372 
373 /**
374  * Evaluator attribute group (GL_EVAL_BIT).
375  */
376 struct gl_eval_attrib
377 {
378    /**
379     * \name Enable bits
380     */
381    /*@{*/
382    GLboolean Map1Color4;
383    GLboolean Map1Index;
384    GLboolean Map1Normal;
385    GLboolean Map1TextureCoord1;
386    GLboolean Map1TextureCoord2;
387    GLboolean Map1TextureCoord3;
388    GLboolean Map1TextureCoord4;
389    GLboolean Map1Vertex3;
390    GLboolean Map1Vertex4;
391    GLboolean Map2Color4;
392    GLboolean Map2Index;
393    GLboolean Map2Normal;
394    GLboolean Map2TextureCoord1;
395    GLboolean Map2TextureCoord2;
396    GLboolean Map2TextureCoord3;
397    GLboolean Map2TextureCoord4;
398    GLboolean Map2Vertex3;
399    GLboolean Map2Vertex4;
400    GLboolean AutoNormal;
401    /*@}*/
402 
403    /**
404     * \name Map Grid endpoints and divisions and calculated du values
405     */
406    /*@{*/
407    GLint MapGrid1un;
408    GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
409    GLint MapGrid2un, MapGrid2vn;
410    GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
411    GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
412    /*@}*/
413 };
414 
415 
416 /**
417  * Compressed fog mode.
418  */
419 enum gl_fog_mode
420 {
421    FOG_NONE,
422    FOG_LINEAR,
423    FOG_EXP,
424    FOG_EXP2,
425 };
426 
427 
428 /**
429  * Fog attribute group (GL_FOG_BIT).
430  */
431 struct gl_fog_attrib
432 {
433    GLboolean Enabled;		/**< Fog enabled flag */
434    GLboolean ColorSumEnabled;
435    uint8_t _PackedMode;		/**< Fog mode as 2 bits */
436    uint8_t _PackedEnabledMode;	/**< Masked CompressedMode */
437    GLfloat ColorUnclamped[4];            /**< Fog color */
438    GLfloat Color[4];		/**< Fog color */
439    GLfloat Density;		/**< Density >= 0.0 */
440    GLfloat Start;		/**< Start distance in eye coords */
441    GLfloat End;			/**< End distance in eye coords */
442    GLfloat Index;		/**< Fog index */
443    GLenum16 Mode;		/**< Fog mode */
444    GLenum16 FogCoordinateSource;/**< GL_EXT_fog_coord */
445    GLenum16 FogDistanceMode;     /**< GL_NV_fog_distance */
446 };
447 
448 
449 /**
450  * Hint attribute group (GL_HINT_BIT).
451  *
452  * Values are always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE.
453  */
454 struct gl_hint_attrib
455 {
456    GLenum16 PerspectiveCorrection;
457    GLenum16 PointSmooth;
458    GLenum16 LineSmooth;
459    GLenum16 PolygonSmooth;
460    GLenum16 Fog;
461    GLenum16 TextureCompression;   /**< GL_ARB_texture_compression */
462    GLenum16 GenerateMipmap;       /**< GL_SGIS_generate_mipmap */
463    GLenum16 FragmentShaderDerivative; /**< GL_ARB_fragment_shader */
464    GLuint MaxShaderCompilerThreads; /**< GL_ARB_parallel_shader_compile */
465 };
466 
467 
468 struct gl_light_uniforms {
469    /* These must be in the same order as the STATE_* enums,
470     * which should also match the order of gl_LightSource members.
471     */
472    GLfloat Ambient[4];           /**< STATE_AMBIENT */
473    GLfloat Diffuse[4];           /**< STATE_DIFFUSE */
474    GLfloat Specular[4];          /**< STATE_SPECULAR */
475    GLfloat EyePosition[4];       /**< STATE_POSITION in eye coordinates */
476    GLfloat _HalfVector[4];       /**< STATE_HALF_VECTOR */
477    GLfloat SpotDirection[3];     /**< STATE_SPOT_DIRECTION in eye coordinates */
478    GLfloat _CosCutoff;           /**< = MAX(0, cos(SpotCutoff)) */
479    GLfloat ConstantAttenuation;  /**< STATE_ATTENUATION */
480    GLfloat LinearAttenuation;
481    GLfloat QuadraticAttenuation;
482    GLfloat SpotExponent;
483    GLfloat SpotCutoff;           /**< STATE_SPOT_CUTOFF in degrees */
484 };
485 
486 
487 /**
488  * Lighting attribute group (GL_LIGHT_BIT).
489  */
490 struct gl_light_attrib
491 {
492    /* gl_LightSource uniforms */
493    union {
494       struct gl_light_uniforms LightSource[MAX_LIGHTS];
495       GLfloat LightSourceData[(sizeof(struct gl_light_uniforms) / 4) * MAX_LIGHTS];
496    };
497 
498    struct gl_light Light[MAX_LIGHTS];	/**< Array of light sources */
499    struct gl_lightmodel Model;		/**< Lighting model */
500 
501    /**
502     * Front and back material values.
503     * Note: must call FLUSH_VERTICES() before using.
504     */
505    struct gl_material Material;
506 
507    GLboolean Enabled;			/**< Lighting enabled flag */
508    GLboolean ColorMaterialEnabled;
509 
510    GLenum16 ShadeModel;			/**< GL_FLAT or GL_SMOOTH */
511    GLenum16 ProvokingVertex;              /**< GL_EXT_provoking_vertex */
512    GLenum16 ColorMaterialFace;		/**< GL_FRONT, BACK or FRONT_AND_BACK */
513    GLenum16 ColorMaterialMode;		/**< GL_AMBIENT, GL_DIFFUSE, etc */
514    GLbitfield _ColorMaterialBitmask;	/**< bitmask formed from Face and Mode */
515 
516 
517    GLboolean _ClampVertexColor;
518    GLenum16 ClampVertexColor;             /**< GL_TRUE, GL_FALSE, GL_FIXED_ONLY */
519 
520    /**
521     * Derived state for optimizations:
522     */
523    /*@{*/
524    GLbitfield _EnabledLights;	/**< bitmask containing enabled lights */
525 
526    GLboolean _NeedEyeCoords;
527    GLboolean _NeedVertices;		/**< Use fast shader? */
528 
529    GLfloat _BaseColor[2][3];
530    /*@}*/
531 };
532 
533 
534 /**
535  * Line attribute group (GL_LINE_BIT).
536  */
537 struct gl_line_attrib
538 {
539    GLboolean SmoothFlag;	/**< GL_LINE_SMOOTH enabled? */
540    GLboolean StippleFlag;	/**< GL_LINE_STIPPLE enabled? */
541    GLushort StipplePattern;	/**< Stipple pattern */
542    GLint StippleFactor;		/**< Stipple repeat factor */
543    GLfloat Width;		/**< Line width */
544 };
545 
546 
547 /**
548  * Display list attribute group (GL_LIST_BIT).
549  */
550 struct gl_list_attrib
551 {
552    GLuint ListBase;
553 };
554 
555 
556 /**
557  * Multisample attribute group (GL_MULTISAMPLE_BIT).
558  */
559 struct gl_multisample_attrib
560 {
561    GLboolean Enabled;
562    GLboolean SampleAlphaToCoverage;
563    GLboolean SampleAlphaToOne;
564    GLboolean SampleCoverage;
565    GLboolean SampleCoverageInvert;
566    GLboolean SampleShading;
567 
568    /* ARB_texture_multisample / GL3.2 additions */
569    GLboolean SampleMask;
570 
571    GLfloat SampleCoverageValue;  /**< In range [0, 1] */
572    GLfloat MinSampleShadingValue;  /**< In range [0, 1] */
573 
574    /** The GL spec defines this as an array but >32x MSAA is madness */
575    GLbitfield SampleMaskValue;
576 
577    /* NV_alpha_to_coverage_dither_control */
578    GLenum SampleAlphaToCoverageDitherControl;
579 };
580 
581 
582 /**
583  * A pixelmap (see glPixelMap)
584  */
585 struct gl_pixelmap
586 {
587    GLint Size;
588    GLfloat Map[MAX_PIXEL_MAP_TABLE];
589 };
590 
591 
592 /**
593  * Collection of all pixelmaps
594  */
595 struct gl_pixelmaps
596 {
597    struct gl_pixelmap RtoR;  /**< i.e. GL_PIXEL_MAP_R_TO_R */
598    struct gl_pixelmap GtoG;
599    struct gl_pixelmap BtoB;
600    struct gl_pixelmap AtoA;
601    struct gl_pixelmap ItoR;
602    struct gl_pixelmap ItoG;
603    struct gl_pixelmap ItoB;
604    struct gl_pixelmap ItoA;
605    struct gl_pixelmap ItoI;
606    struct gl_pixelmap StoS;
607 };
608 
609 
610 /**
611  * Pixel attribute group (GL_PIXEL_MODE_BIT).
612  */
613 struct gl_pixel_attrib
614 {
615    GLenum16 ReadBuffer;		/**< source buffer for glRead/CopyPixels() */
616 
617    /*--- Begin Pixel Transfer State ---*/
618    /* Fields are in the order in which they're applied... */
619 
620    /** Scale & Bias (index shift, offset) */
621    /*@{*/
622    GLfloat RedBias, RedScale;
623    GLfloat GreenBias, GreenScale;
624    GLfloat BlueBias, BlueScale;
625    GLfloat AlphaBias, AlphaScale;
626    GLfloat DepthBias, DepthScale;
627    GLint IndexShift, IndexOffset;
628    /*@}*/
629 
630    /* Pixel Maps */
631    /* Note: actual pixel maps are not part of this attrib group */
632    GLboolean MapColorFlag;
633    GLboolean MapStencilFlag;
634 
635    /*--- End Pixel Transfer State ---*/
636 
637    /** glPixelZoom */
638    GLfloat ZoomX, ZoomY;
639 };
640 
641 
642 /**
643  * Point attribute group (GL_POINT_BIT).
644  */
645 struct gl_point_attrib
646 {
647    GLfloat Size;		/**< User-specified point size */
648    GLfloat Params[3];		/**< GL_EXT_point_parameters */
649    GLfloat MinSize, MaxSize;	/**< GL_EXT_point_parameters */
650    GLfloat Threshold;		/**< GL_EXT_point_parameters */
651    GLboolean SmoothFlag;	/**< True if GL_POINT_SMOOTH is enabled */
652    GLboolean _Attenuated;	/**< True if Params != [1, 0, 0] */
653    GLboolean PointSprite;	/**< GL_NV/ARB_point_sprite */
654    GLbitfield CoordReplace;     /**< GL_ARB_point_sprite*/
655    GLenum16 SpriteOrigin;	/**< GL_ARB_point_sprite */
656 };
657 
658 
659 /**
660  * Polygon attribute group (GL_POLYGON_BIT).
661  */
662 struct gl_polygon_attrib
663 {
664    GLenum16 FrontFace;		/**< Either GL_CW or GL_CCW */
665    GLenum FrontMode;		/**< Either GL_POINT, GL_LINE or GL_FILL */
666    GLenum BackMode;		/**< Either GL_POINT, GL_LINE or GL_FILL */
667    GLboolean CullFlag;		/**< Culling on/off flag */
668    GLboolean SmoothFlag;	/**< True if GL_POLYGON_SMOOTH is enabled */
669    GLboolean StippleFlag;	/**< True if GL_POLYGON_STIPPLE is enabled */
670    GLenum16 CullFaceMode;	/**< Culling mode GL_FRONT or GL_BACK */
671    GLfloat OffsetFactor;	/**< Polygon offset factor, from user */
672    GLfloat OffsetUnits;		/**< Polygon offset units, from user */
673    GLfloat OffsetClamp;		/**< Polygon offset clamp, from user */
674    GLboolean OffsetPoint;	/**< Offset in GL_POINT mode */
675    GLboolean OffsetLine;	/**< Offset in GL_LINE mode */
676    GLboolean OffsetFill;	/**< Offset in GL_FILL mode */
677 };
678 
679 
680 /**
681  * Scissor attributes (GL_SCISSOR_BIT).
682  */
683 struct gl_scissor_rect
684 {
685    GLint X, Y;			/**< Lower left corner of box */
686    GLsizei Width, Height;	/**< Size of box */
687 };
688 
689 
690 struct gl_scissor_attrib
691 {
692    GLbitfield EnableFlags;	/**< Scissor test enabled? */
693    struct gl_scissor_rect ScissorArray[MAX_VIEWPORTS];
694    GLint NumWindowRects;        /**< Count of enabled window rectangles */
695    GLenum16 WindowRectMode;     /**< Whether to include or exclude the rects */
696    struct gl_scissor_rect WindowRects[MAX_WINDOW_RECTANGLES];
697 };
698 
699 
700 /**
701  * Stencil attribute group (GL_STENCIL_BUFFER_BIT).
702  *
703  * Three sets of stencil data are tracked so that OpenGL 2.0,
704  * GL_EXT_stencil_two_side, and GL_ATI_separate_stencil can all be supported
705  * simultaneously.  In each of the stencil state arrays, element 0 corresponds
706  * to GL_FRONT.  Element 1 corresponds to the OpenGL 2.0 /
707  * GL_ATI_separate_stencil GL_BACK state.  Element 2 corresponds to the
708  * GL_EXT_stencil_two_side GL_BACK state.
709  *
710  * The derived value \c _BackFace is either 1 or 2 depending on whether or
711  * not GL_STENCIL_TEST_TWO_SIDE_EXT is enabled.
712  *
713  * The derived value \c _TestTwoSide is set when the front-face and back-face
714  * stencil state are different.
715  */
716 struct gl_stencil_attrib
717 {
718    GLboolean Enabled;		/**< Enabled flag */
719    GLboolean TestTwoSide;	/**< GL_EXT_stencil_two_side */
720    GLubyte ActiveFace;		/**< GL_EXT_stencil_two_side (0 or 2) */
721    GLubyte _BackFace;           /**< Current back stencil state (1 or 2) */
722    GLenum16 Function[3];	/**< Stencil function */
723    GLenum16 FailFunc[3];	/**< Fail function */
724    GLenum16 ZPassFunc[3];	/**< Depth buffer pass function */
725    GLenum16 ZFailFunc[3];	/**< Depth buffer fail function */
726    GLint Ref[3];		/**< Reference value */
727    GLuint ValueMask[3];		/**< Value mask */
728    GLuint WriteMask[3];		/**< Write mask */
729    GLuint Clear;		/**< Clear value */
730 };
731 
732 
733 /**
734  * Bit flags for each type of texture object
735  */
736 /*@{*/
737 #define TEXTURE_2D_MULTISAMPLE_BIT (1 << TEXTURE_2D_MULTISAMPLE_INDEX)
738 #define TEXTURE_2D_MULTISAMPLE_ARRAY_BIT (1 << TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX)
739 #define TEXTURE_CUBE_ARRAY_BIT (1 << TEXTURE_CUBE_ARRAY_INDEX)
740 #define TEXTURE_BUFFER_BIT   (1 << TEXTURE_BUFFER_INDEX)
741 #define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
742 #define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
743 #define TEXTURE_EXTERNAL_BIT (1 << TEXTURE_EXTERNAL_INDEX)
744 #define TEXTURE_CUBE_BIT     (1 << TEXTURE_CUBE_INDEX)
745 #define TEXTURE_3D_BIT       (1 << TEXTURE_3D_INDEX)
746 #define TEXTURE_RECT_BIT     (1 << TEXTURE_RECT_INDEX)
747 #define TEXTURE_2D_BIT       (1 << TEXTURE_2D_INDEX)
748 #define TEXTURE_1D_BIT       (1 << TEXTURE_1D_INDEX)
749 /*@}*/
750 
751 
752 /**
753  * Texture image state.  Drivers will typically create a subclass of this
754  * with extra fields for memory buffers, etc.
755  */
756 struct gl_texture_image
757 {
758    GLint InternalFormat;	/**< Internal format as given by the user */
759    GLenum16 _BaseFormat;	/**< Either GL_RGB, GL_RGBA, GL_ALPHA,
760                                  *   GL_LUMINANCE, GL_LUMINANCE_ALPHA,
761                                  *   GL_INTENSITY, GL_DEPTH_COMPONENT or
762                                  *   GL_DEPTH_STENCIL_EXT only. Used for
763                                  *   choosing TexEnv arithmetic.
764                                  */
765    mesa_format TexFormat;         /**< The actual texture memory format */
766 
767    GLuint Border;		/**< 0 or 1 */
768    GLuint Width;
769    GLuint Height;
770    GLuint Depth;
771    GLuint Width2;		/**< = Width - 2*Border */
772    GLuint Height2;		/**< = Height - 2*Border */
773    GLuint Depth2;		/**< = Depth - 2*Border */
774    GLuint MaxNumLevels;		/**< = maximum possible number of mipmap
775                                        levels, computed from the dimensions */
776 
777    struct gl_texture_object *TexObject;  /**< Pointer back to parent object */
778    GLuint Level;                /**< Which mipmap level am I? */
779    /** Cube map face: index into gl_texture_object::Image[] array */
780    GLuint Face;
781 
782    unsigned FormatSwizzle;
783    unsigned FormatSwizzleGLSL130; //for depth formats
784 
785    /** GL_ARB_texture_multisample */
786    GLuint NumSamples;            /**< Sample count, or 0 for non-multisample */
787    GLboolean FixedSampleLocations; /**< Same sample locations for all pixels? */
788 
789    /* If stImage->pt != NULL, image data is stored here.
790     * Else there is no image data.
791     */
792    struct pipe_resource *pt;
793 
794    /* List of transfers, allocated on demand.
795     * transfer[layer] is a mapping for that layer.
796     */
797    struct st_texture_image_transfer *transfer;
798    unsigned num_transfers;
799 
800    /* For compressed images unsupported by the driver. Keep track of
801     * the original data. This is necessary for mapping/unmapping,
802     * as well as image copies.
803     */
804    struct st_compressed_data* compressed_data;
805 };
806 
807 
808 /**
809  * Indexes for cube map faces.
810  */
811 typedef enum
812 {
813    FACE_POS_X = 0,
814    FACE_NEG_X = 1,
815    FACE_POS_Y = 2,
816    FACE_NEG_Y = 3,
817    FACE_POS_Z = 4,
818    FACE_NEG_Z = 5,
819    MAX_FACES = 6
820 } gl_face_index;
821 
822 /**
823  * Sampler state saved and restore by glPush/PopAttrib.
824  *
825  * Don't put fields here that glPushAttrib shouldn't save.
826  * E.g. no GLES fields because GLES doesn't have glPushAttrib.
827  */
828 struct gl_sampler_attrib
829 {
830    GLenum16 WrapS;		/**< S-axis texture image wrap mode */
831    GLenum16 WrapT;		/**< T-axis texture image wrap mode */
832    GLenum16 WrapR;		/**< R-axis texture image wrap mode */
833    GLenum16 MinFilter;		/**< minification filter */
834    GLenum16 MagFilter;		/**< magnification filter */
835    GLenum16 sRGBDecode;         /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */
836    GLfloat MinLod;		/**< min lambda, OpenGL 1.2 */
837    GLfloat MaxLod;		/**< max lambda, OpenGL 1.2 */
838    GLfloat LodBias;		/**< OpenGL 1.4 */
839    GLfloat MaxAnisotropy;	/**< GL_EXT_texture_filter_anisotropic */
840    GLenum16 CompareMode;	/**< GL_ARB_shadow */
841    GLenum16 CompareFunc;	/**< GL_ARB_shadow */
842    GLboolean CubeMapSeamless;   /**< GL_AMD_seamless_cubemap_per_texture */
843    GLboolean IsBorderColorNonZero; /**< Does the border color have any effect? */
844    GLenum16 ReductionMode;      /**< GL_EXT_texture_filter_minmax */
845 
846    struct pipe_sampler_state state;  /**< Gallium representation */
847 };
848 
849 /**
850  * Texture state saved and restored by glPush/PopAttrib.
851  *
852  * Don't put fields here that glPushAttrib shouldn't save.
853  * E.g. no GLES fields because GLES doesn't have glPushAttrib.
854  */
855 struct gl_texture_object_attrib
856 {
857    GLfloat Priority;           /**< in [0,1] */
858    GLint BaseLevel;            /**< min mipmap level, OpenGL 1.2 */
859    GLint MaxLevel;             /**< max mipmap level (max=1000), OpenGL 1.2 */
860    GLenum Swizzle[4];          /**< GL_EXT_texture_swizzle */
861    GLushort _Swizzle;          /**< same as Swizzle, but SWIZZLE_* format */
862    GLenum16 DepthMode;         /**< GL_ARB_depth_texture */
863    GLenum16 ImageFormatCompatibilityType; /**< GL_ARB_shader_image_load_store */
864    GLushort MinLayer;          /**< GL_ARB_texture_view */
865    GLushort NumLayers;         /**< GL_ARB_texture_view */
866    GLboolean GenerateMipmap;   /**< GL_SGIS_generate_mipmap */
867    GLbyte ImmutableLevels;     /**< ES 3.0 / ARB_texture_view */
868    GLubyte MinLevel;           /**< GL_ARB_texture_view */
869    GLubyte NumLevels;          /**< GL_ARB_texture_view */
870 };
871 
872 
873 typedef enum
874 {
875    WRAP_S = (1<<0),
876    WRAP_T = (1<<1),
877    WRAP_R = (1<<2),
878 } gl_sampler_wrap;
879 
880 /**
881  * Sampler object state.  These objects are new with GL_ARB_sampler_objects
882  * and OpenGL 3.3.  Legacy texture objects also contain a sampler object.
883  */
884 struct gl_sampler_object
885 {
886    GLuint Name;
887    GLchar *Label;               /**< GL_KHR_debug */
888    GLint RefCount;
889 
890    struct gl_sampler_attrib Attrib;  /**< State saved by glPushAttrib */
891 
892    uint8_t glclamp_mask; /**< mask of GL_CLAMP wraps active */
893 
894    /** GL_ARB_bindless_texture */
895    bool HandleAllocated;
896    struct util_dynarray Handles;
897 };
898 
899 /**
900  * YUV color space that should be used to sample textures backed by YUV
901  * images.
902  */
903 enum gl_texture_yuv_color_space
904 {
905    GL_TEXTURE_YUV_COLOR_SPACE_REC601,
906    GL_TEXTURE_YUV_COLOR_SPACE_REC709,
907    GL_TEXTURE_YUV_COLOR_SPACE_REC2020,
908 };
909 
910 /**
911  * Texture object state.  Contains the array of mipmap images, border color,
912  * wrap modes, filter modes, and shadow/texcompare state.
913  */
914 struct gl_texture_object
915 {
916    GLint RefCount;             /**< reference count */
917    GLuint Name;                /**< the user-visible texture object ID */
918    GLenum16 Target;            /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
919    GLchar *Label;              /**< GL_KHR_debug */
920 
921    struct gl_sampler_object Sampler;
922    struct gl_texture_object_attrib Attrib;  /**< State saved by glPushAttrib */
923 
924    gl_texture_index TargetIndex; /**< The gl_texture_unit::CurrentTex index.
925                                       Only valid when Target is valid. */
926    GLbyte _MaxLevel;           /**< actual max mipmap level (q in the spec) */
927    GLfloat _MaxLambda;         /**< = _MaxLevel - BaseLevel (q - p in spec) */
928    GLint CropRect[4];          /**< GL_OES_draw_texture */
929    GLboolean _BaseComplete;    /**< Is the base texture level valid? */
930    GLboolean _MipmapComplete;  /**< Is the whole mipmap valid? */
931    GLboolean _IsIntegerFormat; /**< Does the texture store integer values? */
932    GLboolean _RenderToTexture; /**< Any rendering to this texture? */
933    GLboolean Immutable;        /**< GL_ARB_texture_storage */
934    GLboolean _IsFloat;         /**< GL_OES_float_texture */
935    GLboolean _IsHalfFloat;     /**< GL_OES_half_float_texture */
936    bool HandleAllocated;       /**< GL_ARB_bindless_texture */
937 
938    /* This should not be restored by glPopAttrib: */
939    bool StencilSampling;       /**< Should we sample stencil instead of depth? */
940 
941    /** GL_OES_EGL_image_external */
942    GLboolean External;
943    GLubyte RequiredTextureImageUnits;
944 
945    GLboolean NullTexture; /**< this texture is incomplete and should be passed to the driver as NULL */
946 
947    /** GL_EXT_memory_object */
948    GLenum16 TextureTiling;
949 
950    /** GL_ARB_texture_buffer_object */
951    GLenum16 BufferObjectFormat;
952    /** Equivalent Mesa format for BufferObjectFormat. */
953    mesa_format _BufferObjectFormat;
954    /* TODO: BufferObject->Name should be restored by glPopAttrib(GL_TEXTURE_BIT); */
955    struct gl_buffer_object *BufferObject;
956 
957    /** GL_ARB_texture_buffer_range */
958    GLintptr BufferOffset;
959    GLsizeiptr BufferSize; /**< if this is -1, use BufferObject->Size instead */
960 
961    /** Actual texture images, indexed by [cube face] and [mipmap level] */
962    struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
963 
964    /** GL_ARB_bindless_texture */
965    struct util_dynarray SamplerHandles;
966    struct util_dynarray ImageHandles;
967 
968    /** GL_ARB_sparse_texture */
969    GLboolean IsSparse;
970    GLint VirtualPageSizeIndex;
971    GLint NumSparseLevels;
972 
973    /* The texture must include at levels [0..lastLevel] once validated:
974     */
975    GLuint lastLevel;
976 
977    unsigned Swizzle;
978    unsigned SwizzleGLSL130;
979 
980    unsigned int validated_first_level;
981    unsigned int validated_last_level;
982 
983    /* On validation any active images held in main memory or in other
984     * textures will be copied to this texture and the old storage freed.
985     */
986    struct pipe_resource *pt;
987 
988    /* Protect modifications of the sampler_views array */
989    simple_mtx_t validate_mutex;
990 
991    /* Container of sampler views (one per context) attached to this texture
992     * object. Created lazily on first binding in context.
993     *
994     * Purely read-only accesses to the current context's own sampler view
995     * require no locking. Another thread may simultaneously replace the
996     * container object in order to grow the array, but the old container will
997     * be kept alive.
998     *
999     * Writing to the container (even for modifying the current context's own
1000     * sampler view) always requires taking the validate_mutex to protect against
1001     * concurrent container switches.
1002     *
1003     * NULL'ing another context's sampler view is allowed only while
1004     * implementing an API call that modifies the texture: an application which
1005     * calls those while simultaneously reading the texture in another context
1006     * invokes undefined behavior. (TODO: a dubious violation of this rule is
1007     * st_finalize_texture, which is a lazy operation that corresponds to a
1008     * texture modification.)
1009     */
1010    struct st_sampler_views *sampler_views;
1011 
1012    /* Old sampler views container objects that have not been freed yet because
1013     * other threads/contexts may still be reading from them.
1014     */
1015    struct st_sampler_views *sampler_views_old;
1016 
1017    /* True if this texture comes from the window system. Such a texture
1018     * cannot be reallocated and the format can only be changed with a sampler
1019     * view or a surface.
1020     */
1021    GLboolean surface_based;
1022 
1023    /* If surface_based is true, this format should be used for all sampler
1024     * views and surfaces instead of pt->format.
1025     */
1026    enum pipe_format surface_format;
1027 
1028    /* If surface_based is true and surface_format is a YUV format, these
1029     * settings should be used to convert from YUV to RGB.
1030     */
1031    enum gl_texture_yuv_color_space yuv_color_space;
1032    bool yuv_full_range;
1033 
1034    /* When non-negative, samplers should use this level instead of the level
1035     * range specified by the GL state.
1036     *
1037     * This is used for EGL images, which may correspond to a single level out
1038     * of an imported pipe_resources with multiple mip levels.
1039     */
1040    int level_override;
1041 
1042    /* When non-negative, samplers should use this layer instead of the one
1043     * specified by the GL state.
1044     *
1045     * This is used for EGL images and VDPAU interop, where imported
1046     * pipe_resources may be cube, 3D, or array textures (containing layers
1047     * with different fields in the case of VDPAU) even though the GL state
1048     * describes one non-array texture per field.
1049     */
1050    int layer_override;
1051 
1052     /**
1053      * Set when the texture images of this texture object might not all be in
1054      * the pipe_resource *pt above.
1055      */
1056     bool needs_validation;
1057 };
1058 
1059 
1060 /** Up to four combiner sources are possible with GL_NV_texture_env_combine4 */
1061 #define MAX_COMBINER_TERMS 4
1062 
1063 
1064 /**
1065  * Texture combine environment state.
1066  */
1067 struct gl_tex_env_combine_state
1068 {
1069    GLenum16 ModeRGB;       /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1070    GLenum16 ModeA;         /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1071    /** Source terms: GL_PRIMARY_COLOR, GL_TEXTURE, etc */
1072    GLenum16 SourceRGB[MAX_COMBINER_TERMS];
1073    GLenum16 SourceA[MAX_COMBINER_TERMS];
1074    /** Source operands: GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, etc */
1075    GLenum16 OperandRGB[MAX_COMBINER_TERMS];
1076    GLenum16 OperandA[MAX_COMBINER_TERMS];
1077    GLubyte ScaleShiftRGB; /**< 0, 1 or 2 */
1078    GLubyte ScaleShiftA;   /**< 0, 1 or 2 */
1079    GLubyte _NumArgsRGB;   /**< Number of inputs used for the RGB combiner */
1080    GLubyte _NumArgsA;     /**< Number of inputs used for the A combiner */
1081 };
1082 
1083 
1084 /** Compressed TexEnv effective Combine mode */
1085 enum gl_tex_env_mode
1086 {
1087    TEXENV_MODE_REPLACE,                 /* r = a0 */
1088    TEXENV_MODE_MODULATE,                /* r = a0 * a1 */
1089    TEXENV_MODE_ADD,                     /* r = a0 + a1 */
1090    TEXENV_MODE_ADD_SIGNED,              /* r = a0 + a1 - 0.5 */
1091    TEXENV_MODE_INTERPOLATE,             /* r = a0 * a2 + a1 * (1 - a2) */
1092    TEXENV_MODE_SUBTRACT,                /* r = a0 - a1 */
1093    TEXENV_MODE_DOT3_RGB,                /* r = a0 . a1 */
1094    TEXENV_MODE_DOT3_RGB_EXT,            /* r = a0 . a1 */
1095    TEXENV_MODE_DOT3_RGBA,               /* r = a0 . a1 */
1096    TEXENV_MODE_DOT3_RGBA_EXT,           /* r = a0 . a1 */
1097    TEXENV_MODE_MODULATE_ADD_ATI,        /* r = a0 * a2 + a1 */
1098    TEXENV_MODE_MODULATE_SIGNED_ADD_ATI, /* r = a0 * a2 + a1 - 0.5 */
1099    TEXENV_MODE_MODULATE_SUBTRACT_ATI,   /* r = a0 * a2 - a1 */
1100    TEXENV_MODE_ADD_PRODUCTS_NV,         /* r = a0 * a1 + a2 * a3 */
1101    TEXENV_MODE_ADD_PRODUCTS_SIGNED_NV,  /* r = a0 * a1 + a2 * a3 - 0.5 */
1102 };
1103 
1104 
1105 /** Compressed TexEnv Combine source */
1106 enum gl_tex_env_source
1107 {
1108    TEXENV_SRC_TEXTURE0,
1109    TEXENV_SRC_TEXTURE1,
1110    TEXENV_SRC_TEXTURE2,
1111    TEXENV_SRC_TEXTURE3,
1112    TEXENV_SRC_TEXTURE4,
1113    TEXENV_SRC_TEXTURE5,
1114    TEXENV_SRC_TEXTURE6,
1115    TEXENV_SRC_TEXTURE7,
1116    TEXENV_SRC_TEXTURE,
1117    TEXENV_SRC_PREVIOUS,
1118    TEXENV_SRC_PRIMARY_COLOR,
1119    TEXENV_SRC_CONSTANT,
1120    TEXENV_SRC_ZERO,
1121    TEXENV_SRC_ONE,
1122 };
1123 
1124 
1125 /** Compressed TexEnv Combine operand */
1126 enum gl_tex_env_operand
1127 {
1128    TEXENV_OPR_COLOR,
1129    TEXENV_OPR_ONE_MINUS_COLOR,
1130    TEXENV_OPR_ALPHA,
1131    TEXENV_OPR_ONE_MINUS_ALPHA,
1132 };
1133 
1134 
1135 /** Compressed TexEnv Combine argument */
1136 struct gl_tex_env_argument
1137 {
1138 #ifdef __GNUC__
1139    __extension__ uint8_t Source:4;  /**< TEXENV_SRC_x */
1140    __extension__ uint8_t Operand:2; /**< TEXENV_OPR_x */
1141 #else
1142    uint8_t Source;  /**< SRC_x */
1143    uint8_t Operand; /**< OPR_x */
1144 #endif
1145 };
1146 
1147 
1148 /***
1149  * Compressed TexEnv Combine state.
1150  */
1151 struct gl_tex_env_combine_packed
1152 {
1153    uint32_t ModeRGB:4;        /**< Effective mode for RGB as 4 bits */
1154    uint32_t ModeA:4;          /**< Effective mode for RGB as 4 bits */
1155    uint32_t ScaleShiftRGB:2;  /**< 0, 1 or 2 */
1156    uint32_t ScaleShiftA:2;    /**< 0, 1 or 2 */
1157    uint32_t NumArgsRGB:3;     /**< Number of inputs used for the RGB combiner */
1158    uint32_t NumArgsA:3;       /**< Number of inputs used for the A combiner */
1159    /** Source arguments in a packed manner */
1160    struct gl_tex_env_argument ArgsRGB[MAX_COMBINER_TERMS];
1161    struct gl_tex_env_argument ArgsA[MAX_COMBINER_TERMS];
1162 };
1163 
1164 
1165 /**
1166  * TexGenEnabled flags.
1167  */
1168 /*@{*/
1169 #define S_BIT 1
1170 #define T_BIT 2
1171 #define R_BIT 4
1172 #define Q_BIT 8
1173 #define STR_BITS (S_BIT | T_BIT | R_BIT)
1174 /*@}*/
1175 
1176 
1177 /**
1178  * Bit flag versions of the corresponding GL_ constants.
1179  */
1180 /*@{*/
1181 #define TEXGEN_SPHERE_MAP        0x1
1182 #define TEXGEN_OBJ_LINEAR        0x2
1183 #define TEXGEN_EYE_LINEAR        0x4
1184 #define TEXGEN_REFLECTION_MAP_NV 0x8
1185 #define TEXGEN_NORMAL_MAP_NV     0x10
1186 
1187 #define TEXGEN_NEED_NORMALS   (TEXGEN_SPHERE_MAP        | \
1188                                TEXGEN_REFLECTION_MAP_NV | \
1189                                TEXGEN_NORMAL_MAP_NV)
1190 #define TEXGEN_NEED_EYE_COORD (TEXGEN_SPHERE_MAP        | \
1191                                TEXGEN_REFLECTION_MAP_NV | \
1192                                TEXGEN_NORMAL_MAP_NV     | \
1193                                TEXGEN_EYE_LINEAR)
1194 /*@}*/
1195 
1196 
1197 
1198 /** Tex-gen enabled for texture unit? */
1199 #define ENABLE_TEXGEN(unit) (1 << (unit))
1200 
1201 /** Non-identity texture matrix for texture unit? */
1202 #define ENABLE_TEXMAT(unit) (1 << (unit))
1203 
1204 
1205 /**
1206  * Texture coord generation state.
1207  */
1208 struct gl_texgen
1209 {
1210    GLenum16 Mode;       /**< GL_EYE_LINEAR, GL_SPHERE_MAP, etc */
1211    GLbitfield8 _ModeBit; /**< TEXGEN_x bit corresponding to Mode */
1212 };
1213 
1214 
1215 /**
1216  * Sampler-related subset of a texture unit, like current texture objects.
1217  */
1218 struct gl_texture_unit
1219 {
1220    GLfloat LodBias;		/**< for biasing mipmap levels */
1221    float LodBiasQuantized;      /**< to reduce pipe_sampler_state variants */
1222 
1223    /** Texture targets that have a non-default texture bound */
1224    GLbitfield _BoundTextures;
1225 
1226    /** Current sampler object (GL_ARB_sampler_objects) */
1227    struct gl_sampler_object *Sampler;
1228 
1229    /** Current texture object pointers */
1230    struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
1231 
1232    /** Points to highest priority, complete and enabled texture object */
1233    struct gl_texture_object *_Current;
1234 };
1235 
1236 enum {
1237    GEN_S,
1238    GEN_T,
1239    GEN_R,
1240    GEN_Q,
1241    NUM_GEN,
1242 };
1243 
1244 /**
1245  * Fixed-function-related subset of a texture unit, like enable flags,
1246  * texture environment/function/combiners, and texgen state.
1247  */
1248 struct gl_fixedfunc_texture_unit
1249 {
1250    GLbitfield16 Enabled;          /**< bitmask of TEXTURE_*_BIT flags */
1251 
1252    GLenum16 EnvMode;            /**< GL_MODULATE, GL_DECAL, GL_BLEND, etc. */
1253    GLclampf EnvColor[4];
1254    GLfloat EnvColorUnclamped[4];
1255 
1256    struct gl_texgen GenS;
1257    struct gl_texgen GenT;
1258    struct gl_texgen GenR;
1259    struct gl_texgen GenQ;
1260 
1261    GLfloat EyePlane[NUM_GEN][4];
1262    GLfloat ObjectPlane[NUM_GEN][4];
1263 
1264    GLbitfield8 TexGenEnabled;	/**< Bitwise-OR of [STRQ]_BIT values */
1265    GLbitfield8 _GenFlags;	/**< Bitwise-OR of Gen[STRQ]._ModeBit */
1266 
1267    /**
1268     * \name GL_EXT_texture_env_combine
1269     */
1270    struct gl_tex_env_combine_state Combine;
1271 
1272    /**
1273     * Derived state based on \c EnvMode and the \c BaseFormat of the
1274     * currently enabled texture.
1275     */
1276    struct gl_tex_env_combine_state _EnvMode;
1277 
1278    /** Current compressed TexEnv & Combine state */
1279    struct gl_tex_env_combine_packed _CurrentCombinePacked;
1280 
1281    /**
1282     * Currently enabled combiner state.  This will point to either
1283     * \c Combine or \c _EnvMode.
1284     */
1285    struct gl_tex_env_combine_state *_CurrentCombine;
1286 };
1287 
1288 
1289 /**
1290  * Texture attribute group (GL_TEXTURE_BIT).
1291  */
1292 struct gl_texture_attrib
1293 {
1294    struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
1295 
1296    /** GL_ARB_texture_buffer_object */
1297    struct gl_buffer_object *BufferObject;
1298 
1299    GLuint CurrentUnit;   /**< GL_ACTIVE_TEXTURE */
1300 
1301    /** Texture coord units/sets used for fragment texturing */
1302    GLbitfield8 _EnabledCoordUnits;
1303 
1304    /** Texture coord units that have texgen enabled */
1305    GLbitfield8 _TexGenEnabled;
1306 
1307    /** Texture coord units that have non-identity matrices */
1308    GLbitfield8 _TexMatEnabled;
1309 
1310    /** Bitwise-OR of all Texture.Unit[i]._GenFlags */
1311    GLbitfield8 _GenFlags;
1312 
1313    /** Largest index of a texture unit with _Current != NULL. */
1314    GLshort _MaxEnabledTexImageUnit;
1315 
1316    /** Largest index + 1 of texture units that have had any CurrentTex set. */
1317    GLubyte NumCurrentTexUsed;
1318 
1319    /** GL_ARB_seamless_cubemap */
1320    GLboolean CubeMapSeamless;
1321 
1322    GLshort NumSamplersWithClamp;
1323 
1324    struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
1325    struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_TEXTURE_COORD_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    GLenum16 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 DepthClampNear;			/**< GL_AMD_depth_clamp_separate */
1349    GLboolean DepthClampFar;			/**< GL_AMD_depth_clamp_separate */
1350    /** GL_ARB_clip_control */
1351    GLenum16 ClipOrigin;   /**< GL_LOWER_LEFT or GL_UPPER_LEFT */
1352    GLenum16 ClipDepthMode;/**< GL_NEGATIVE_ONE_TO_ONE or GL_ZERO_TO_ONE */
1353 };
1354 
1355 
1356 /**
1357  * Viewport attribute group (GL_VIEWPORT_BIT).
1358  */
1359 struct gl_viewport_attrib
1360 {
1361    GLfloat X, Y;		/**< position */
1362    GLfloat Width, Height;	/**< size */
1363    GLfloat Near, Far;		/**< Depth buffer range */
1364 
1365    /**< GL_NV_viewport_swizzle */
1366    GLenum16 SwizzleX, SwizzleY, SwizzleZ, SwizzleW;
1367 };
1368 
1369 
1370 /**
1371  * Fields describing a mapped buffer range.
1372  */
1373 struct gl_buffer_mapping
1374 {
1375    GLbitfield AccessFlags; /**< Mask of GL_MAP_x_BIT flags */
1376    GLvoid *Pointer;        /**< User-space address of mapping */
1377    GLintptr Offset;        /**< Mapped offset */
1378    GLsizeiptr Length;      /**< Mapped length */
1379 };
1380 
1381 
1382 /**
1383  * Usages we've seen for a buffer object.
1384  */
1385 typedef enum
1386 {
1387    USAGE_UNIFORM_BUFFER = 0x1,
1388    USAGE_TEXTURE_BUFFER = 0x2,
1389    USAGE_ATOMIC_COUNTER_BUFFER = 0x4,
1390    USAGE_SHADER_STORAGE_BUFFER = 0x8,
1391    USAGE_TRANSFORM_FEEDBACK_BUFFER = 0x10,
1392    USAGE_PIXEL_PACK_BUFFER = 0x20,
1393    USAGE_ARRAY_BUFFER = 0x40,
1394    USAGE_DISABLE_MINMAX_CACHE = 0x100,
1395 } gl_buffer_usage;
1396 
1397 
1398 /**
1399  * GL_ARB_vertex/pixel_buffer_object buffer object
1400  */
1401 struct gl_buffer_object
1402 {
1403    GLint RefCount;
1404    GLuint Name;
1405 
1406    /**
1407     * The context that holds a global buffer reference for the lifetime of
1408     * the GL buffer ID to skip refcounting for all its private bind points.
1409     * Other contexts must still do refcounting as usual. Shared binding points
1410     * like TBO within gl_texture_object are always refcounted.
1411     *
1412     * Implementation details:
1413     * - Only the context that creates the buffer ("creating context") skips
1414     *   refcounting.
1415     * - Only buffers represented by an OpenGL buffer ID skip refcounting.
1416     *   Other internal buffers don't. (glthread requires refcounting for
1417     *   internal buffers, etc.)
1418     * - glDeleteBuffers removes the global buffer reference and increments
1419     *   RefCount for all private bind points where the deleted buffer is bound
1420     *   (e.g. unbound VAOs that are not changed by glDeleteBuffers),
1421     *   effectively enabling refcounting for that context. This is the main
1422     *   point where the global buffer reference is removed.
1423     * - glDeleteBuffers called from a different context adds the buffer into
1424     *   the ZombieBufferObjects list, which is a way to notify the creating
1425     *   context that it should remove its global buffer reference to allow
1426     *   freeing the buffer. The creating context walks over that list in a few
1427     *   GL functions.
1428     * - xxxDestroyContext walks over all buffers and removes its global
1429     *   reference from those buffers that it created.
1430     */
1431    struct gl_context *Ctx;
1432    GLint CtxRefCount;   /**< Non-atomic references held by Ctx. */
1433 
1434    gl_buffer_usage UsageHistory; /**< How has this buffer been used so far? */
1435 
1436    struct pipe_resource *buffer;
1437    struct gl_context *private_refcount_ctx;
1438    /* This mechanism allows passing buffer references to the driver without
1439     * using atomics to increase the reference count.
1440     *
1441     * This private refcount can be decremented without atomics but only one
1442     * context (ctx above) can use this counter to be thread-safe.
1443     *
1444     * This number is atomically added to buffer->reference.count at
1445     * initialization. If it's never used, the same number is atomically
1446     * subtracted from buffer->reference.count before destruction. If this
1447     * number is decremented, we can pass that reference to the driver without
1448     * touching reference.count. At buffer destruction we only subtract
1449     * the number of references we did not return. This can possibly turn
1450     * a million atomic increments into 1 add and 1 subtract atomic op.
1451     */
1452    int private_refcount;
1453 
1454    GLbitfield StorageFlags; /**< GL_MAP_PERSISTENT_BIT, etc. */
1455 
1456    /** Memoization of min/max index computations for static index buffers */
1457    unsigned MinMaxCacheHitIndices;
1458    unsigned MinMaxCacheMissIndices;
1459    struct hash_table *MinMaxCache;
1460    simple_mtx_t MinMaxCacheMutex;
1461    bool MinMaxCacheDirty:1;
1462 
1463    bool DeletePending:1;  /**< true if buffer object is removed from the hash */
1464    bool Immutable:1;    /**< GL_ARB_buffer_storage */
1465    bool HandleAllocated:1; /**< GL_ARB_bindless_texture */
1466    bool GLThreadInternal:1; /**< Created by glthread. */
1467    GLenum16 Usage;      /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */
1468    GLchar *Label;       /**< GL_KHR_debug */
1469    GLsizeiptrARB Size;  /**< Size of buffer storage in bytes */
1470 
1471    /** Counters used for buffer usage warnings */
1472    GLuint NumSubDataCalls;
1473    GLuint NumMapBufferWriteCalls;
1474 
1475    struct gl_buffer_mapping Mappings[MAP_COUNT];
1476    struct pipe_transfer *transfer[MAP_COUNT];
1477 };
1478 
1479 
1480 /**
1481  * Client pixel packing/unpacking attributes
1482  */
1483 struct gl_pixelstore_attrib
1484 {
1485    GLint Alignment;
1486    GLint RowLength;
1487    GLint SkipPixels;
1488    GLint SkipRows;
1489    GLint ImageHeight;
1490    GLint SkipImages;
1491    GLboolean SwapBytes;
1492    GLboolean LsbFirst;
1493    GLboolean Invert;        /**< GL_MESA_pack_invert */
1494    GLint CompressedBlockWidth;   /**< GL_ARB_compressed_texture_pixel_storage */
1495    GLint CompressedBlockHeight;
1496    GLint CompressedBlockDepth;
1497    GLint CompressedBlockSize;
1498    struct gl_buffer_object *BufferObj; /**< GL_ARB_pixel_buffer_object */
1499 };
1500 
1501 
1502 /**
1503  * Enum for defining the mapping for the position/generic0 attribute.
1504  *
1505  * Do not change the order of the values as these are used as
1506  * array indices.
1507  */
1508 typedef enum
1509 {
1510    ATTRIBUTE_MAP_MODE_IDENTITY, /**< 1:1 mapping */
1511    ATTRIBUTE_MAP_MODE_POSITION, /**< get position and generic0 from position */
1512    ATTRIBUTE_MAP_MODE_GENERIC0, /**< get position and generic0 from generic0 */
1513    ATTRIBUTE_MAP_MODE_MAX       /**< for sizing arrays */
1514 } gl_attribute_map_mode;
1515 
1516 
1517 /**
1518  * Attributes to describe a vertex array.
1519  *
1520  * Contains the size, type, format and normalization flag,
1521  * along with the index of a vertex buffer binding point.
1522  *
1523  * Note that the Stride field corresponds to VERTEX_ATTRIB_ARRAY_STRIDE
1524  * and is only present for backwards compatibility reasons.
1525  * Rendering always uses VERTEX_BINDING_STRIDE.
1526  * The gl*Pointer() functions will set VERTEX_ATTRIB_ARRAY_STRIDE
1527  * and VERTEX_BINDING_STRIDE to the same value, while
1528  * glBindVertexBuffer() will only set VERTEX_BINDING_STRIDE.
1529  */
1530 struct gl_array_attributes
1531 {
1532    /** Points to client array data. Not used when a VBO is bound */
1533    const GLubyte *Ptr;
1534    /** Offset of the first element relative to the binding offset */
1535    GLuint RelativeOffset;
1536    /** Vertex format */
1537    struct gl_vertex_format Format;
1538    /** Stride as specified with gl*Pointer() */
1539    GLshort Stride;
1540    /** Index into gl_vertex_array_object::BufferBinding[] array */
1541    GLubyte BufferBindingIndex;
1542 
1543    /**
1544     * Derived effective buffer binding index
1545     *
1546     * Index into the gl_vertex_buffer_binding array of the vao.
1547     * Similar to BufferBindingIndex, but with the mapping of the
1548     * position/generic0 attributes applied and with identical
1549     * gl_vertex_buffer_binding entries collapsed to a single
1550     * entry within the vao.
1551     *
1552     * The value is valid past calling _mesa_update_vao_derived_arrays.
1553     * Note that _mesa_update_vao_derived_arrays is called when binding
1554     * the VAO to Array._DrawVAO.
1555     */
1556    GLubyte _EffBufferBindingIndex;
1557    /**
1558     * Derived effective relative offset.
1559     *
1560     * Relative offset to the effective buffers offset in
1561     * gl_vertex_buffer_binding::_EffOffset.
1562     *
1563     * The value is valid past calling _mesa_update_vao_derived_arrays.
1564     * Note that _mesa_update_vao_derived_arrays is called when binding
1565     * the VAO to Array._DrawVAO.
1566     */
1567    GLushort _EffRelativeOffset;
1568 };
1569 
1570 
1571 /**
1572  * This describes the buffer object used for a vertex array (or
1573  * multiple vertex arrays).  If BufferObj points to the default/null
1574  * buffer object, then the vertex array lives in user memory and not a VBO.
1575  */
1576 struct gl_vertex_buffer_binding
1577 {
1578    GLintptr Offset;                    /**< User-specified offset */
1579    GLsizei Stride;                     /**< User-specified stride */
1580    GLuint InstanceDivisor;             /**< GL_ARB_instanced_arrays */
1581    struct gl_buffer_object *BufferObj; /**< GL_ARB_vertex_buffer_object */
1582    GLbitfield _BoundArrays;            /**< Arrays bound to this binding point */
1583 
1584    /**
1585     * Derived effective bound arrays.
1586     *
1587     * The effective binding handles enabled arrays past the
1588     * position/generic0 attribute mapping and reduces the refered
1589     * gl_vertex_buffer_binding entries to a unique subset.
1590     *
1591     * The value is valid past calling _mesa_update_vao_derived_arrays.
1592     * Note that _mesa_update_vao_derived_arrays is called when binding
1593     * the VAO to Array._DrawVAO.
1594     */
1595    GLbitfield _EffBoundArrays;
1596    /**
1597     * Derived offset.
1598     *
1599     * The absolute offset to that we can collapse some attributes
1600     * to this unique effective binding.
1601     * For user space array bindings this contains the smallest pointer value
1602     * in the bound and interleaved arrays.
1603     * For VBO bindings this contains an offset that lets the attributes
1604     * _EffRelativeOffset stay positive and in bounds with
1605     * Const.MaxVertexAttribRelativeOffset
1606     *
1607     * The value is valid past calling _mesa_update_vao_derived_arrays.
1608     * Note that _mesa_update_vao_derived_arrays is called when binding
1609     * the VAO to Array._DrawVAO.
1610     */
1611    GLintptr _EffOffset;
1612 };
1613 
1614 
1615 /**
1616  * A representation of "Vertex Array Objects" (VAOs) from OpenGL 3.1+ /
1617  * the GL_ARB_vertex_array_object extension.
1618  */
1619 struct gl_vertex_array_object
1620 {
1621    /** Name of the VAO as received from glGenVertexArray. */
1622    GLuint Name;
1623 
1624    GLint RefCount;
1625 
1626    GLchar *Label;       /**< GL_KHR_debug */
1627 
1628    /**
1629     * Has this array object been bound?
1630     */
1631    GLboolean EverBound;
1632 
1633    /**
1634     * Marked to true if the object is shared between contexts and immutable.
1635     * Then reference counting is done using atomics and thread safe.
1636     * Is used for dlist VAOs.
1637     */
1638    bool SharedAndImmutable;
1639 
1640    /** Vertex attribute arrays */
1641    struct gl_array_attributes VertexAttrib[VERT_ATTRIB_MAX];
1642 
1643    /** Vertex buffer bindings */
1644    struct gl_vertex_buffer_binding BufferBinding[VERT_ATTRIB_MAX];
1645 
1646    /** Mask indicating which vertex arrays have vertex buffer associated. */
1647    GLbitfield VertexAttribBufferMask;
1648 
1649    /** Mask indicating which vertex arrays have a non-zero instance divisor. */
1650    GLbitfield NonZeroDivisorMask;
1651 
1652    /** Mask of VERT_BIT_* values indicating which arrays are enabled */
1653    GLbitfield Enabled;
1654 
1655    /**
1656     * Mask of vertex attributes that have:
1657     *    VertexAttrib[i].BufferBindingIndex != i.
1658     */
1659    GLbitfield NonIdentityBufferAttribMapping;
1660 
1661    /**
1662     * Mask indicating which VertexAttrib and BufferBinding structures have
1663     * been changed since the VAO creation. No bit is ever cleared to 0 by
1664     * state updates. Setting to the default state doesn't update this.
1665     * (e.g. unbinding) Setting the derived state (_* fields) doesn't update
1666     * this either.
1667     */
1668    GLbitfield NonDefaultStateMask;
1669 
1670    /** Denotes the way the position/generic0 attribute is mapped */
1671    gl_attribute_map_mode _AttributeMapMode;
1672 
1673    /** "Enabled" with the position/generic0 attribute aliasing resolved */
1674    GLbitfield _EnabledWithMapMode;
1675 
1676    /** The index buffer (also known as the element array buffer in OpenGL). */
1677    struct gl_buffer_object *IndexBufferObj;
1678 };
1679 
1680 
1681 /**
1682  * Vertex array state
1683  */
1684 struct gl_array_attrib
1685 {
1686    /** Currently bound array object. */
1687    struct gl_vertex_array_object *VAO;
1688 
1689    /** The default vertex array object */
1690    struct gl_vertex_array_object *DefaultVAO;
1691 
1692    /** The last VAO accessed by a DSA function */
1693    struct gl_vertex_array_object *LastLookedUpVAO;
1694 
1695    /** These contents are copied to newly created VAOs. */
1696    struct gl_vertex_array_object DefaultVAOState;
1697 
1698    /** Array objects (GL_ARB_vertex_array_object) */
1699    struct _mesa_HashTable Objects;
1700 
1701    GLint ActiveTexture;		/**< Client Active Texture */
1702    GLuint LockFirst;            /**< GL_EXT_compiled_vertex_array */
1703    GLuint LockCount;            /**< GL_EXT_compiled_vertex_array */
1704 
1705    /**
1706     * \name Primitive restart controls
1707     *
1708     * Primitive restart is enabled if either \c PrimitiveRestart or
1709     * \c PrimitiveRestartFixedIndex is set.
1710     */
1711    /*@{*/
1712    GLboolean PrimitiveRestart;
1713    GLboolean PrimitiveRestartFixedIndex;
1714    GLboolean _PrimitiveRestart[3]; /**< Enable indexed by index_size_shift. */
1715    GLuint RestartIndex;
1716    GLuint _RestartIndex[3]; /**< Restart indices indexed by index_size_shift. */
1717    /*@}*/
1718 
1719    /* GL_ARB_vertex_buffer_object */
1720    struct gl_buffer_object *ArrayBufferObj;
1721 
1722    /**
1723     * Vertex array object that is used with the currently active draw command.
1724     * The _DrawVAO is either set to the currently bound VAO for array type
1725     * draws or to internal VAO's set up by the vbo module to execute immediate
1726     * mode or display list draws.
1727     */
1728    struct gl_vertex_array_object *_DrawVAO;
1729 
1730    /**
1731     * Whether per-vertex edge flags are enabled and should be processed by
1732     * the vertex shader.
1733     */
1734    bool _PerVertexEdgeFlagsEnabled;
1735 
1736    /**
1737     * Whether all edge flags are false, causing all points and lines generated
1738     * by polygon mode to be not drawn. (i.e. culled)
1739     */
1740    bool _PolygonModeAlwaysCulls;
1741 
1742    /**
1743     * If gallium vertex buffers are dirty, this flag indicates whether gallium
1744     * vertex elements are dirty too. If this is false, GL states corresponding
1745     * to vertex elements have not been changed. Thus, this affects what will
1746     * happen when ST_NEW_VERTEX_ARRAYS is set.
1747     *
1748     * The driver should clear this when it's done.
1749     */
1750    bool NewVertexElements;
1751 
1752    /** Legal array datatypes and the API for which they have been computed */
1753    GLbitfield LegalTypesMask;
1754    gl_api LegalTypesMaskAPI;
1755 };
1756 
1757 
1758 /**
1759  * Feedback buffer state
1760  */
1761 struct gl_feedback
1762 {
1763    GLenum16 Type;
1764    GLbitfield _Mask;    /**< FB_* bits */
1765    GLfloat *Buffer;
1766    GLuint BufferSize;
1767    GLuint Count;
1768 };
1769 
1770 
1771 /**
1772  * Selection buffer state
1773  */
1774 struct gl_selection
1775 {
1776    GLuint *Buffer;	/**< selection buffer */
1777    GLuint BufferSize;	/**< size of the selection buffer */
1778    GLuint BufferCount;	/**< number of values in the selection buffer */
1779    GLuint Hits;		/**< number of records in the selection buffer */
1780    GLuint NameStackDepth; /**< name stack depth */
1781    GLuint NameStack[MAX_NAME_STACK_DEPTH]; /**< name stack */
1782    GLboolean HitFlag;	/**< hit flag */
1783    GLfloat HitMinZ;	/**< minimum hit depth */
1784    GLfloat HitMaxZ;	/**< maximum hit depth */
1785 
1786    /* HW GL_SELECT */
1787    void *SaveBuffer;        /**< array holds multi stack data */
1788    GLuint SaveBufferTail;   /**< offset to SaveBuffer's tail */
1789    GLuint SavedStackNum;    /**< number of saved stacks */
1790 
1791    GLboolean ResultUsed;    /**< whether any draw used result buffer */
1792    GLuint ResultOffset;     /**< offset into result buffer */
1793    struct gl_buffer_object *Result; /**< result buffer */
1794 };
1795 
1796 
1797 /**
1798  * 1-D Evaluator control points
1799  */
1800 struct gl_1d_map
1801 {
1802    GLuint Order;	/**< Number of control points */
1803    GLfloat u1, u2, du;	/**< u1, u2, 1.0/(u2-u1) */
1804    GLfloat *Points;	/**< Points to contiguous control points */
1805 };
1806 
1807 
1808 /**
1809  * 2-D Evaluator control points
1810  */
1811 struct gl_2d_map
1812 {
1813    GLuint Uorder;		/**< Number of control points in U dimension */
1814    GLuint Vorder;		/**< Number of control points in V dimension */
1815    GLfloat u1, u2, du;
1816    GLfloat v1, v2, dv;
1817    GLfloat *Points;		/**< Points to contiguous control points */
1818 };
1819 
1820 
1821 /**
1822  * All evaluator control point state
1823  */
1824 struct gl_evaluators
1825 {
1826    /**
1827     * \name 1-D maps
1828     */
1829    /*@{*/
1830    struct gl_1d_map Map1Vertex3;
1831    struct gl_1d_map Map1Vertex4;
1832    struct gl_1d_map Map1Index;
1833    struct gl_1d_map Map1Color4;
1834    struct gl_1d_map Map1Normal;
1835    struct gl_1d_map Map1Texture1;
1836    struct gl_1d_map Map1Texture2;
1837    struct gl_1d_map Map1Texture3;
1838    struct gl_1d_map Map1Texture4;
1839    /*@}*/
1840 
1841    /**
1842     * \name 2-D maps
1843     */
1844    /*@{*/
1845    struct gl_2d_map Map2Vertex3;
1846    struct gl_2d_map Map2Vertex4;
1847    struct gl_2d_map Map2Index;
1848    struct gl_2d_map Map2Color4;
1849    struct gl_2d_map Map2Normal;
1850    struct gl_2d_map Map2Texture1;
1851    struct gl_2d_map Map2Texture2;
1852    struct gl_2d_map Map2Texture3;
1853    struct gl_2d_map Map2Texture4;
1854    /*@}*/
1855 };
1856 
1857 
1858 /**
1859  * Transform feedback object state
1860  */
1861 struct gl_transform_feedback_object
1862 {
1863    GLuint Name;  /**< AKA the object ID */
1864    GLint RefCount;
1865    GLchar *Label;     /**< GL_KHR_debug */
1866    GLboolean Active;  /**< Is transform feedback enabled? */
1867    GLboolean Paused;  /**< Is transform feedback paused? */
1868    GLboolean EndedAnytime; /**< Has EndTransformFeedback been called
1869                                 at least once? */
1870    GLboolean EverBound; /**< Has this object been bound? */
1871 
1872    /**
1873     * GLES: if Active is true, remaining number of primitives which can be
1874     * rendered without overflow.  This is necessary to track because GLES
1875     * requires us to generate INVALID_OPERATION if a call to glDrawArrays or
1876     * glDrawArraysInstanced would overflow transform feedback buffers.
1877     * Undefined if Active is false.
1878     *
1879     * Not tracked for desktop GL since it's unnecessary.
1880     */
1881    unsigned GlesRemainingPrims;
1882 
1883    /**
1884     * The program active when BeginTransformFeedback() was called.
1885     * When active and unpaused, this equals ctx->Shader.CurrentProgram[stage],
1886     * where stage is the pipeline stage that is the source of data for
1887     * transform feedback.
1888     */
1889    struct gl_program *program;
1890 
1891    /** The feedback buffers */
1892    GLuint BufferNames[MAX_FEEDBACK_BUFFERS];
1893    struct gl_buffer_object *Buffers[MAX_FEEDBACK_BUFFERS];
1894 
1895    /** Start of feedback data in dest buffer */
1896    GLintptr Offset[MAX_FEEDBACK_BUFFERS];
1897 
1898    /**
1899     * Max data to put into dest buffer (in bytes).  Computed based on
1900     * RequestedSize and the actual size of the buffer.
1901     */
1902    GLsizeiptr Size[MAX_FEEDBACK_BUFFERS];
1903 
1904    /**
1905     * Size that was specified when the buffer was bound.  If the buffer was
1906     * bound with glBindBufferBase() or glBindBufferOffsetEXT(), this value is
1907     * zero.
1908     */
1909    GLsizeiptr RequestedSize[MAX_FEEDBACK_BUFFERS];
1910 
1911    unsigned num_targets;
1912    struct pipe_stream_output_target *targets[PIPE_MAX_SO_BUFFERS];
1913 
1914    /* This encapsulates the count that can be used as a source for draw_vbo.
1915     * It contains stream output targets from the last call of
1916     * EndTransformFeedback for each stream. */
1917    struct pipe_stream_output_target *draw_count[MAX_VERTEX_STREAMS];
1918 };
1919 
1920 
1921 /**
1922  * Context state for transform feedback.
1923  */
1924 struct gl_transform_feedback_state
1925 {
1926    GLenum16 Mode;     /**< GL_POINTS, GL_LINES or GL_TRIANGLES */
1927 
1928    /** The general binding point (GL_TRANSFORM_FEEDBACK_BUFFER) */
1929    struct gl_buffer_object *CurrentBuffer;
1930 
1931    /** The table of all transform feedback objects */
1932    struct _mesa_HashTable Objects;
1933 
1934    /** The current xform-fb object (GL_TRANSFORM_FEEDBACK_BINDING) */
1935    struct gl_transform_feedback_object *CurrentObject;
1936 
1937    /** The default xform-fb object (Name==0) */
1938    struct gl_transform_feedback_object *DefaultObject;
1939 };
1940 
1941 
1942 /**
1943  * A "performance monitor" as described in AMD_performance_monitor.
1944  */
1945 struct gl_perf_monitor_object
1946 {
1947    GLuint Name;
1948 
1949    /** True if the monitor is currently active (Begin called but not End). */
1950    GLboolean Active;
1951 
1952    /**
1953     * True if the monitor has ended.
1954     *
1955     * This is distinct from !Active because it may never have began.
1956     */
1957    GLboolean Ended;
1958 
1959    /**
1960     * A list of groups with currently active counters.
1961     *
1962     * ActiveGroups[g] == n if there are n counters active from group 'g'.
1963     */
1964    unsigned *ActiveGroups;
1965 
1966    /**
1967     * An array of bitsets, subscripted by group ID, then indexed by counter ID.
1968     *
1969     * Checking whether counter 'c' in group 'g' is active can be done via:
1970     *
1971     *    BITSET_TEST(ActiveCounters[g], c)
1972     */
1973    GLuint **ActiveCounters;
1974 
1975    unsigned num_active_counters;
1976 
1977    struct gl_perf_counter_object {
1978       struct pipe_query *query;
1979       int id;
1980       int group_id;
1981       unsigned batch_index;
1982    } *active_counters;
1983 
1984    struct pipe_query *batch_query;
1985    union pipe_query_result *batch_result;
1986 };
1987 
1988 
1989 union gl_perf_monitor_counter_value
1990 {
1991    float f;
1992    uint64_t u64;
1993    uint32_t u32;
1994 };
1995 
1996 
1997 struct gl_perf_monitor_counter
1998 {
1999    /** Human readable name for the counter. */
2000    const char *Name;
2001 
2002    /**
2003     * Data type of the counter.  Valid values are FLOAT, UNSIGNED_INT,
2004     * UNSIGNED_INT64_AMD, and PERCENTAGE_AMD.
2005     */
2006    GLenum16 Type;
2007 
2008    /** Minimum counter value. */
2009    union gl_perf_monitor_counter_value Minimum;
2010 
2011    /** Maximum counter value. */
2012    union gl_perf_monitor_counter_value Maximum;
2013 
2014    unsigned query_type;
2015    unsigned flags;
2016 };
2017 
2018 
2019 struct gl_perf_monitor_group
2020 {
2021    /** Human readable name for the group. */
2022    const char *Name;
2023 
2024    /**
2025     * Maximum number of counters in this group which can be active at the
2026     * same time.
2027     */
2028    GLuint MaxActiveCounters;
2029 
2030    /** Array of counters within this group. */
2031    const struct gl_perf_monitor_counter *Counters;
2032    GLuint NumCounters;
2033 
2034    bool has_batch;
2035 };
2036 
2037 /**
2038  * A query object instance as described in INTEL_performance_query.
2039  *
2040  * NB: We want to keep this and the corresponding backend structure
2041  * relatively lean considering that applications may expect to
2042  * allocate enough objects to be able to query around all draw calls
2043  * in a frame.
2044  */
2045 struct gl_perf_query_object
2046 {
2047    GLuint Id;          /**< hash table ID/name */
2048    unsigned Used:1;    /**< has been used for 1 or more queries */
2049    unsigned Active:1;  /**< inside Begin/EndPerfQuery */
2050    unsigned Ready:1;   /**< result is ready? */
2051 };
2052 
2053 
2054 /**
2055  * Context state for AMD_performance_monitor.
2056  */
2057 struct gl_perf_monitor_state
2058 {
2059    /** Array of performance monitor groups (indexed by group ID) */
2060    const struct gl_perf_monitor_group *Groups;
2061    GLuint NumGroups;
2062 
2063    /** The table of all performance monitors. */
2064    struct _mesa_HashTable Monitors;
2065 };
2066 
2067 
2068 /**
2069  * Context state for INTEL_performance_query.
2070  */
2071 struct gl_perf_query_state
2072 {
2073    struct _mesa_HashTable Objects; /**< The table of all performance query objects */
2074 };
2075 
2076 
2077 /**
2078  * State common to vertex and fragment programs.
2079  */
2080 struct gl_program_state
2081 {
2082    GLint ErrorPos;                       /* GL_PROGRAM_ERROR_POSITION_ARB/NV */
2083    const char *ErrorString;              /* GL_PROGRAM_ERROR_STRING_ARB/NV */
2084 };
2085 
2086 
2087 /**
2088  * Context state for vertex programs.
2089  */
2090 struct gl_vertex_program_state
2091 {
2092    GLboolean Enabled;            /**< User-set GL_VERTEX_PROGRAM_ARB/NV flag */
2093    GLboolean PointSizeEnabled;   /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
2094    GLboolean TwoSideEnabled;     /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
2095    /** Whether the fixed-func program is being used right now. */
2096    GLboolean _UsesTnlProgram;
2097 
2098    struct gl_program *Current;  /**< User-bound vertex program */
2099 
2100    /** Currently enabled and valid vertex program (including internal
2101     * programs, user-defined vertex programs and GLSL vertex shaders).
2102     * This is the program we must use when rendering.
2103     */
2104    struct gl_program *_Current;
2105 
2106    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
2107 
2108    /** Program to emulate fixed-function T&L (see above) */
2109    struct gl_program *_TnlProgram;
2110 
2111    /** Cache of fixed-function programs */
2112    struct gl_program_cache *Cache;
2113 
2114    GLboolean _Overriden;
2115 
2116    bool _VPModeOptimizesConstantAttribs;
2117 
2118    /**
2119     * If we have a vertex program, a TNL program or no program at all.
2120     * Note that this value should be kept up to date all the time,
2121     * nevertheless its correctness is asserted in _mesa_update_state.
2122     * The reason is to avoid calling _mesa_update_state twice we need
2123     * this value on draw *before* actually calling _mesa_update_state.
2124     * Also it should need to get recomputed only on changes to the
2125     * vertex program which are heavyweight already.
2126     */
2127    gl_vertex_processing_mode _VPMode;
2128 
2129    GLbitfield _VaryingInputs;  /**< mask of VERT_BIT_* flags */
2130    GLbitfield _VPModeInputFilter;
2131 };
2132 
2133 /**
2134  * Context state for tessellation control programs.
2135  */
2136 struct gl_tess_ctrl_program_state
2137 {
2138    /** Currently bound and valid shader. */
2139    struct gl_program *_Current;
2140 
2141    GLint patch_vertices;
2142    GLfloat patch_default_outer_level[4];
2143    GLfloat patch_default_inner_level[2];
2144 };
2145 
2146 /**
2147  * Context state for tessellation evaluation programs.
2148  */
2149 struct gl_tess_eval_program_state
2150 {
2151    /** Currently bound and valid shader. */
2152    struct gl_program *_Current;
2153 };
2154 
2155 /**
2156  * Context state for geometry programs.
2157  */
2158 struct gl_geometry_program_state
2159 {
2160    /**
2161     * Currently enabled and valid program (including internal programs
2162     * and compiled shader programs).
2163     */
2164    struct gl_program *_Current;
2165 };
2166 
2167 /**
2168  * Context state for fragment programs.
2169  */
2170 struct gl_fragment_program_state
2171 {
2172    GLboolean Enabled;     /**< User-set fragment program enable flag */
2173    /** Whether the fixed-func program is being used right now. */
2174    GLboolean _UsesTexEnvProgram;
2175 
2176    struct gl_program *Current;  /**< User-bound fragment program */
2177 
2178    /**
2179     * Currently enabled and valid fragment program (including internal
2180     * programs, user-defined fragment programs and GLSL fragment shaders).
2181     * This is the program we must use when rendering.
2182     */
2183    struct gl_program *_Current;
2184 
2185    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
2186 
2187    /** Program to emulate fixed-function texture env/combine (see above) */
2188    struct gl_program *_TexEnvProgram;
2189 
2190    /** Cache of fixed-function programs */
2191    struct gl_program_cache *Cache;
2192 };
2193 
2194 
2195 /**
2196  * Context state for compute programs.
2197  */
2198 struct gl_compute_program_state
2199 {
2200    /** Currently enabled and valid program (including internal programs
2201     * and compiled shader programs).
2202     */
2203    struct gl_program *_Current;
2204 };
2205 
2206 
2207 /**
2208  * ATI_fragment_shader runtime state
2209  */
2210 
2211 struct atifs_instruction;
2212 struct atifs_setupinst;
2213 
2214 /**
2215  * ATI fragment shader
2216  */
2217 struct ati_fragment_shader
2218 {
2219    GLuint Id;
2220    GLint RefCount;
2221    struct atifs_instruction *Instructions[2];
2222    struct atifs_setupinst *SetupInst[2];
2223    GLfloat Constants[8][4];
2224    GLbitfield LocalConstDef;  /**< Indicates which constants have been set */
2225    GLubyte numArithInstr[2];
2226    GLubyte regsAssigned[2];
2227    GLubyte NumPasses;         /**< 1 or 2 */
2228    /**
2229     * Current compile stage: 0 setup pass1, 1 arith pass1,
2230     * 2 setup pass2, 3 arith pass2.
2231     */
2232    GLubyte cur_pass;
2233    GLubyte last_optype;
2234    GLboolean interpinp1;
2235    GLboolean isValid;
2236    /**
2237     * Array of 2 bit values for each tex unit to remember whether
2238     * STR or STQ swizzle was used
2239     */
2240    GLuint swizzlerq;
2241    struct gl_program *Program;
2242 };
2243 
2244 /**
2245  * Context state for GL_ATI_fragment_shader
2246  */
2247 struct gl_ati_fragment_shader_state
2248 {
2249    GLboolean Enabled;
2250    GLboolean Compiling;
2251    GLfloat GlobalConstants[8][4];
2252    struct ati_fragment_shader *Current;
2253 };
2254 
2255 #define GLSL_DUMP      0x1  /**< Dump shaders to stdout */
2256 #define GLSL_LOG       0x2  /**< Write shaders to files */
2257 #define GLSL_UNIFORMS  0x4  /**< Print glUniform calls */
2258 #define GLSL_NOP_VERT  0x8  /**< Force no-op vertex shaders */
2259 #define GLSL_NOP_FRAG 0x10  /**< Force no-op fragment shaders */
2260 #define GLSL_USE_PROG 0x20  /**< Log glUseProgram calls */
2261 #define GLSL_REPORT_ERRORS 0x40  /**< Print compilation errors */
2262 #define GLSL_DUMP_ON_ERROR 0x80 /**< Dump shaders to stderr on compile error */
2263 #define GLSL_CACHE_INFO 0x100 /**< Print debug information about shader cache */
2264 #define GLSL_CACHE_FALLBACK 0x200 /**< Force shader cache fallback paths */
2265 #define GLSL_SOURCE 0x400 /**< Only dump GLSL */
2266 
2267 
2268 /**
2269  * Context state for GLSL vertex/fragment shaders.
2270  * Extended to support pipeline object
2271  */
2272 struct gl_pipeline_object
2273 {
2274    /** Name of the pipeline object as received from glGenProgramPipelines.
2275     * It would be 0 for shaders without separate shader objects.
2276     */
2277    GLuint Name;
2278 
2279    GLint RefCount;
2280 
2281    GLchar *Label;   /**< GL_KHR_debug */
2282 
2283    /**
2284     * Programs used for rendering
2285     *
2286     * There is a separate program set for each shader stage.
2287     */
2288    struct gl_program *CurrentProgram[MESA_SHADER_STAGES];
2289 
2290    struct gl_shader_program *ReferencedPrograms[MESA_SHADER_STAGES];
2291 
2292    /**
2293     * Program used by glUniform calls.
2294     *
2295     * Explicitly set by \c glUseProgram and \c glActiveProgramEXT.
2296     */
2297    struct gl_shader_program *ActiveProgram;
2298 
2299    GLbitfield Flags;         /**< Mask of GLSL_x flags */
2300    GLboolean EverBound;      /**< Has the pipeline object been created */
2301    GLboolean Validated;      /**< Pipeline Validation status */
2302    GLboolean UserValidated;  /**< Validation status initiated by the user */
2303 
2304    GLchar *InfoLog;
2305 };
2306 
2307 /**
2308  * Context state for GLSL pipeline shaders.
2309  */
2310 struct gl_pipeline_shader_state
2311 {
2312    /** Currently bound pipeline object. See _mesa_BindProgramPipeline() */
2313    struct gl_pipeline_object *Current;
2314 
2315    /** Default Object to ensure that _Shader is never NULL */
2316    struct gl_pipeline_object *Default;
2317 
2318    /** Pipeline objects */
2319    struct _mesa_HashTable Objects;
2320 };
2321 
2322 /**
2323  * Occlusion/timer query object.
2324  */
2325 struct gl_query_object
2326 {
2327    GLenum16 Target;    /**< The query target, when active */
2328    GLuint Id;          /**< hash table ID/name */
2329    GLchar *Label;      /**< GL_KHR_debug */
2330    GLuint64EXT Result; /**< the counter */
2331    GLboolean Active;   /**< inside Begin/EndQuery */
2332    GLboolean Ready;    /**< result is ready? */
2333    GLboolean EverBound;/**< has query object ever been bound */
2334    GLuint Stream;      /**< The stream */
2335 
2336    struct pipe_query *pq;
2337 
2338    /* Begin TIMESTAMP query for GL_TIME_ELAPSED_EXT queries */
2339    struct pipe_query *pq_begin;
2340 
2341    unsigned type;  /**< PIPE_QUERY_x */
2342 };
2343 
2344 
2345 /**
2346  * Context state for query objects.
2347  */
2348 struct gl_query_state
2349 {
2350    struct _mesa_HashTable QueryObjects;
2351    struct gl_query_object *CurrentOcclusionObject; /* GL_ARB_occlusion_query */
2352    struct gl_query_object *CurrentTimerObject;     /* GL_EXT_timer_query */
2353 
2354    /** GL_NV_conditional_render */
2355    struct gl_query_object *CondRenderQuery;
2356 
2357    /** GL_EXT_transform_feedback */
2358    struct gl_query_object *PrimitivesGenerated[MAX_VERTEX_STREAMS];
2359    struct gl_query_object *PrimitivesWritten[MAX_VERTEX_STREAMS];
2360 
2361    /** GL_ARB_transform_feedback_overflow_query */
2362    struct gl_query_object *TransformFeedbackOverflow[MAX_VERTEX_STREAMS];
2363    struct gl_query_object *TransformFeedbackOverflowAny;
2364 
2365    /** GL_ARB_timer_query */
2366    struct gl_query_object *TimeElapsed;
2367 
2368    /** GL_ARB_pipeline_statistics_query */
2369    struct gl_query_object *pipeline_stats[MAX_PIPELINE_STATISTICS];
2370 
2371    GLenum16 CondRenderMode;
2372 };
2373 
2374 
2375 /** Sync object state */
2376 struct gl_sync_object
2377 {
2378    GLuint Name;               /**< Fence name */
2379    GLint RefCount;            /**< Reference count */
2380    GLchar *Label;             /**< GL_KHR_debug */
2381    GLboolean DeletePending;   /**< Object was deleted while there were still
2382                                * live references (e.g., sync not yet finished)
2383                                */
2384    GLenum16 SyncCondition;
2385    GLbitfield Flags;          /**< Flags passed to glFenceSync */
2386    GLuint StatusFlag:1;       /**< Has the sync object been signaled? */
2387 
2388    struct pipe_fence_handle *fence;
2389    simple_mtx_t mutex; /**< protects "fence" */
2390 };
2391 
2392 
2393 /**
2394  * State which can be shared by multiple contexts:
2395  */
2396 struct gl_shared_state
2397 {
2398    simple_mtx_t Mutex;		   /**< for thread safety */
2399    GLint RefCount;			   /**< Reference count */
2400    bool DisplayListsAffectGLThread;
2401 
2402    struct _mesa_HashTable DisplayList;	   /**< Display lists hash table */
2403    struct _mesa_HashTable TexObjects;	   /**< Texture objects hash table */
2404 
2405    /** Default texture objects (shared by all texture units) */
2406    struct gl_texture_object *DefaultTex[NUM_TEXTURE_TARGETS];
2407 
2408    /** Fallback texture used when a bound texture is incomplete */
2409    struct gl_texture_object *FallbackTex[NUM_TEXTURE_TARGETS][2]; /**< [color, depth] */
2410 
2411    /**
2412     * \name Thread safety and statechange notification for texture
2413     * objects.
2414     *
2415     * \todo Improve the granularity of locking.
2416     */
2417    /*@{*/
2418    simple_mtx_t TexMutex;		/**< texobj thread safety */
2419    GLuint TextureStateStamp;	        /**< state notification for shared tex */
2420    /*@}*/
2421 
2422    /**
2423     * \name Vertex/geometry/fragment programs
2424     */
2425    /*@{*/
2426    struct _mesa_HashTable Programs; /**< All vertex/fragment programs */
2427    struct gl_program *DefaultVertexProgram;
2428    struct gl_program *DefaultFragmentProgram;
2429    /*@}*/
2430 
2431    /* GL_ATI_fragment_shader */
2432    struct _mesa_HashTable ATIShaders;
2433    struct ati_fragment_shader *DefaultFragmentShader;
2434 
2435    struct _mesa_HashTable BufferObjects;
2436 
2437    /* Buffer objects released by a different context than the one that
2438     * created them. Since the creating context holds one global buffer
2439     * reference for each buffer it created and skips reference counting,
2440     * deleting a buffer by another context can't touch the buffer reference
2441     * held by the context that created it. Only the creating context can
2442     * remove its global buffer reference.
2443     *
2444     * This list contains all buffers that were deleted by a different context
2445     * than the one that created them. This list should be probed by all
2446     * contexts regularly and remove references of those buffers that they own.
2447     */
2448    struct set *ZombieBufferObjects;
2449 
2450    /** Table of both gl_shader and gl_shader_program objects */
2451    struct _mesa_HashTable ShaderObjects;
2452 
2453    /* GL_EXT_framebuffer_object */
2454    struct _mesa_HashTable RenderBuffers;
2455    struct _mesa_HashTable FrameBuffers;
2456 
2457    /* GL_ARB_sync */
2458    struct set *SyncObjects;
2459 
2460    /** GL_ARB_sampler_objects */
2461    struct _mesa_HashTable SamplerObjects;
2462 
2463    /* GL_ARB_bindless_texture */
2464    struct hash_table_u64 *TextureHandles;
2465    struct hash_table_u64 *ImageHandles;
2466    mtx_t HandlesMutex; /**< For texture/image handles safety */
2467 
2468    /* GL_ARB_shading_language_include */
2469    struct shader_includes *ShaderIncludes;
2470    /* glCompileShaderInclude expects ShaderIncludes not to change while it is
2471     * in progress.
2472     */
2473    simple_mtx_t ShaderIncludeMutex;
2474 
2475    /** EXT_external_objects */
2476    struct _mesa_HashTable MemoryObjects;
2477 
2478    /** EXT_semaphore */
2479    struct _mesa_HashTable SemaphoreObjects;
2480 
2481    /**
2482     * Whether at least one image has been imported or exported, excluding
2483     * the default framebuffer. If this is false, glFlush can be executed
2484     * asynchronously because there is no invisible dependency on external
2485     * users.
2486     */
2487    bool HasExternallySharedImages;
2488 
2489    /* Small display list storage */
2490    struct {
2491       union gl_dlist_node *ptr;
2492       struct util_idalloc free_idx;
2493       unsigned size;
2494    } small_dlist_store;
2495 
2496    /* Global GLThread state. */
2497    struct {
2498       /* The last context that locked global mutexes. */
2499       struct gl_context *LastExecutingCtx;
2500 
2501       /* The last time LastExecutingCtx started executing after a different
2502        * context (the time of multiple active contexts).
2503        */
2504       int64_t LastContextSwitchTime;
2505 
2506       /* The time for which no context can lock global mutexes since
2507        * LastContextSwitchTime.
2508        */
2509       int64_t NoLockDuration;
2510    } GLThread;
2511 };
2512 
2513 
2514 
2515 /**
2516  * Renderbuffers represent drawing surfaces such as color, depth and/or
2517  * stencil.  A framebuffer object has a set of renderbuffers.
2518  * Drivers will typically derive subclasses of this type.
2519  */
2520 struct gl_renderbuffer
2521 {
2522    GLuint Name;
2523    GLchar *Label;         /**< GL_KHR_debug */
2524    GLint RefCount;
2525    GLuint Width, Height;
2526    GLuint Depth;
2527    GLboolean AttachedAnytime; /**< TRUE if it was attached to a framebuffer */
2528    GLubyte NumSamples;    /**< zero means not multisampled */
2529    GLubyte NumStorageSamples; /**< for AMD_framebuffer_multisample_advanced */
2530    GLenum16 InternalFormat; /**< The user-specified format */
2531    GLenum16 _BaseFormat;    /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
2532                                GL_STENCIL_INDEX. */
2533    mesa_format Format;      /**< The actual renderbuffer memory format */
2534    /**
2535     * Pointer to the texture image if this renderbuffer wraps a texture,
2536     * otherwise NULL.
2537     *
2538     * Note that the reference on the gl_texture_object containing this
2539     * TexImage is held by the gl_renderbuffer_attachment.
2540     */
2541    struct gl_texture_image *TexImage;
2542 
2543    /** Delete this renderbuffer */
2544    void (*Delete)(struct gl_context *ctx, struct gl_renderbuffer *rb);
2545 
2546    /** Allocate new storage for this renderbuffer */
2547    GLboolean (*AllocStorage)(struct gl_context *ctx,
2548                              struct gl_renderbuffer *rb,
2549                              GLenum internalFormat,
2550                              GLuint width, GLuint height);
2551 
2552    struct pipe_resource *texture;
2553    /* This points to either "surface_linear" or "surface_srgb".
2554     * It doesn't hold the pipe_surface reference. The other two do.
2555     */
2556    struct pipe_surface *surface;
2557    struct pipe_surface *surface_linear;
2558    struct pipe_surface *surface_srgb;
2559    GLboolean defined;        /**< defined contents? */
2560 
2561    struct pipe_transfer *transfer; /**< only used when mapping the resource */
2562 
2563    /**
2564     * Used only when hardware accumulation buffers are not supported.
2565     */
2566    bool software;
2567    void *data;
2568 
2569    bool use_readpix_cache;
2570 
2571    /* Inputs from Driver.RenderTexture, don't use directly. */
2572    bool is_rtt; /**< whether Driver.RenderTexture was called */
2573    unsigned rtt_face, rtt_slice;
2574    bool rtt_layered; /**< whether glFramebufferTexture was called */
2575    unsigned rtt_nr_samples; /**< from FramebufferTexture2DMultisampleEXT */
2576 };
2577 
2578 
2579 /**
2580  * A renderbuffer attachment points to either a texture object (and specifies
2581  * a mipmap level, cube face or 3D texture slice) or points to a renderbuffer.
2582  */
2583 struct gl_renderbuffer_attachment
2584 {
2585    GLenum16 Type; /**< \c GL_NONE or \c GL_TEXTURE or \c GL_RENDERBUFFER_EXT */
2586    GLboolean Complete;
2587 
2588    /**
2589     * If \c Type is \c GL_RENDERBUFFER_EXT, this stores a pointer to the
2590     * application supplied renderbuffer object.
2591     */
2592    struct gl_renderbuffer *Renderbuffer;
2593 
2594    /**
2595     * If \c Type is \c GL_TEXTURE, this stores a pointer to the application
2596     * supplied texture object.
2597     */
2598    struct gl_texture_object *Texture;
2599    GLuint TextureLevel; /**< Attached mipmap level. */
2600    GLsizei NumSamples;  /**< from FramebufferTexture2DMultisampleEXT */
2601    GLuint CubeMapFace;  /**< 0 .. 5, for cube map textures. */
2602    GLuint Zoffset;      /**< Slice for 3D textures,  or layer for both 1D
2603                          * and 2D array textures */
2604    GLboolean Layered;
2605 };
2606 
2607 
2608 /**
2609  * A framebuffer is a collection of renderbuffers (color, depth, stencil, etc).
2610  * In C++ terms, think of this as a base class from which device drivers
2611  * will make derived classes.
2612  */
2613 struct gl_framebuffer
2614 {
2615    simple_mtx_t Mutex;  /**< for thread safety */
2616    /**
2617     * If zero, this is a window system framebuffer.  If non-zero, this
2618     * is a FBO framebuffer; note that for some devices (i.e. those with
2619     * a natural pixel coordinate system for FBOs that differs from the
2620     * OpenGL/Mesa coordinate system), this means that the viewport,
2621     * polygon face orientation, and polygon stipple will have to be inverted.
2622     */
2623    GLuint Name;
2624    GLint RefCount;
2625 
2626    GLchar *Label;       /**< GL_KHR_debug */
2627 
2628    GLboolean DeletePending;
2629 
2630    /**
2631     * The framebuffer's visual. Immutable if this is a window system buffer.
2632     * Computed from attachments if user-made FBO.
2633     */
2634    struct gl_config Visual;
2635 
2636    /**
2637     * Size of frame buffer in pixels. If there are no attachments, then both
2638     * of these are 0.
2639     */
2640    GLuint Width, Height;
2641 
2642    /**
2643     * In the case that the framebuffer has no attachment (i.e.
2644     * GL_ARB_framebuffer_no_attachments) then the geometry of
2645     * the framebuffer is specified by the default values.
2646     */
2647    struct {
2648      GLuint Width, Height, Layers, NumSamples;
2649      GLboolean FixedSampleLocations;
2650      /* Derived from NumSamples by the driver so that it can choose a valid
2651       * value for the hardware.
2652       */
2653      GLuint _NumSamples;
2654    } DefaultGeometry;
2655 
2656    /** \name  Drawing bounds (Intersection of buffer size and scissor box)
2657     * The drawing region is given by [_Xmin, _Xmax) x [_Ymin, _Ymax),
2658     * (inclusive for _Xmin and _Ymin while exclusive for _Xmax and _Ymax)
2659     */
2660    /*@{*/
2661    GLint _Xmin, _Xmax;
2662    GLint _Ymin, _Ymax;
2663    /*@}*/
2664 
2665    /** \name  Derived Z buffer stuff */
2666    /*@{*/
2667    GLuint _DepthMax;	/**< Max depth buffer value */
2668    GLfloat _DepthMaxF;	/**< Float max depth buffer value */
2669    GLfloat _MRD;	/**< minimum resolvable difference in Z values */
2670    /*@}*/
2671 
2672    /** One of the GL_FRAMEBUFFER_(IN)COMPLETE_* tokens */
2673    GLenum16 _Status;
2674 
2675    /** Whether one of Attachment has Type != GL_NONE
2676     * NOTE: the values for Width and Height are set to 0 in case of having
2677     * no attachments, a backend driver supporting the extension
2678     * GL_ARB_framebuffer_no_attachments must check for the flag _HasAttachments
2679     * and if GL_FALSE, must then use the values in DefaultGeometry to initialize
2680     * its viewport, scissor and so on (in particular _Xmin, _Xmax, _Ymin and
2681     * _Ymax do NOT take into account _HasAttachments being false). To get the
2682     * geometry of the framebuffer, the  helper functions
2683     *   _mesa_geometric_width(),
2684     *   _mesa_geometric_height(),
2685     *   _mesa_geometric_samples() and
2686     *   _mesa_geometric_layers()
2687     * are available that check _HasAttachments.
2688     */
2689    bool _HasAttachments;
2690 
2691    GLbitfield _IntegerBuffers;  /**< Which color buffers are integer valued */
2692    GLbitfield _BlendForceAlphaToOne;  /**< Which color buffers need blend factor adjustment */
2693    GLbitfield _IsRGB;  /**< Which color buffers have an RGB base format? */
2694    GLbitfield _FP32Buffers; /**< Which color buffers are FP32 */
2695 
2696    /* ARB_color_buffer_float */
2697    GLboolean _AllColorBuffersFixedPoint; /* no integer, no float */
2698    GLboolean _HasSNormOrFloatColorBuffer;
2699 
2700    /**
2701     * The maximum number of layers in the framebuffer, or 0 if the framebuffer
2702     * is not layered.  For cube maps and cube map arrays, each cube face
2703     * counts as a layer. As the case for Width, Height a backend driver
2704     * supporting GL_ARB_framebuffer_no_attachments must use DefaultGeometry
2705     * in the case that _HasAttachments is false
2706     */
2707    GLuint MaxNumLayers;
2708 
2709    /** Array of all renderbuffer attachments, indexed by BUFFER_* tokens. */
2710    struct gl_renderbuffer_attachment Attachment[BUFFER_COUNT];
2711    struct pipe_resource *resolve; /**< color resolve attachment */
2712 
2713    /* In unextended OpenGL these vars are part of the GL_COLOR_BUFFER
2714     * attribute group and GL_PIXEL attribute group, respectively.
2715     */
2716    GLenum16 ColorDrawBuffer[MAX_DRAW_BUFFERS];
2717    GLenum16 ColorReadBuffer;
2718 
2719    /* GL_ARB_sample_locations */
2720    GLfloat *SampleLocationTable; /**< If NULL, no table has been specified */
2721    GLboolean ProgrammableSampleLocations;
2722    GLboolean SampleLocationPixelGrid;
2723 
2724    /** Computed from ColorDraw/ReadBuffer above */
2725    GLuint _NumColorDrawBuffers;
2726    gl_buffer_index _ColorDrawBufferIndexes[MAX_DRAW_BUFFERS];
2727    gl_buffer_index _ColorReadBufferIndex;
2728    struct gl_renderbuffer *_ColorDrawBuffers[MAX_DRAW_BUFFERS];
2729    struct gl_renderbuffer *_ColorReadBuffer;
2730 
2731    /* GL_MESA_framebuffer_flip_y */
2732    bool FlipY;
2733 
2734    /** Delete this framebuffer */
2735    void (*Delete)(struct gl_framebuffer *fb);
2736 
2737    struct pipe_frontend_drawable *drawable;
2738    enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
2739    unsigned num_statts;
2740    int32_t stamp;
2741    int32_t drawable_stamp;
2742    uint32_t drawable_ID;
2743 
2744    /* list of framebuffer objects */
2745    struct list_head head;
2746 };
2747 
2748 /**
2749  * A stack of matrices (projection, modelview, color, texture, etc).
2750  */
2751 struct gl_matrix_stack
2752 {
2753    GLmatrix *Top;      /**< points into Stack */
2754    GLmatrix *Stack;    /**< array [MaxDepth] of GLmatrix */
2755    unsigned StackSize; /**< Number of elements in Stack */
2756    GLuint Depth;       /**< 0 <= Depth < MaxDepth */
2757    GLuint MaxDepth;    /**< size of Stack[] array */
2758    GLuint DirtyFlag;   /**< _NEW_MODELVIEW or _NEW_PROJECTION, for example */
2759    bool ChangedSincePush;
2760 };
2761 
2762 
2763 /**
2764  * \name Bits for image transfer operations
2765  * \sa __struct gl_contextRec::ImageTransferState.
2766  */
2767 /*@{*/
2768 #define IMAGE_SCALE_BIAS_BIT                      0x1
2769 #define IMAGE_SHIFT_OFFSET_BIT                    0x2
2770 #define IMAGE_MAP_COLOR_BIT                       0x4
2771 #define IMAGE_CLAMP_BIT                           0x800
2772 
2773 
2774 /** Pixel Transfer ops */
2775 #define IMAGE_BITS (IMAGE_SCALE_BIAS_BIT | \
2776                     IMAGE_SHIFT_OFFSET_BIT | \
2777                     IMAGE_MAP_COLOR_BIT)
2778 
2779 
2780 /**
2781  * \name Bits to indicate what state has changed.
2782  */
2783 /*@{*/
2784 #define _NEW_MODELVIEW         (1u << 0)   /**< gl_context::ModelView */
2785 #define _NEW_PROJECTION        (1u << 1)   /**< gl_context::Projection */
2786 #define _NEW_TEXTURE_MATRIX    (1u << 2)   /**< gl_context::TextureMatrix */
2787 #define _NEW_COLOR             (1u << 3)   /**< gl_context::Color */
2788 #define _NEW_DEPTH             (1u << 4)   /**< gl_context::Depth */
2789 #define _NEW_TNL_SPACES        (1u << 5)  /**< _mesa_update_tnl_spaces */
2790 #define _NEW_FOG               (1u << 6)   /**< gl_context::Fog */
2791 #define _NEW_HINT              (1u << 7)   /**< gl_context::Hint */
2792 #define _NEW_LIGHT_CONSTANTS   (1u << 8)   /**< gl_context::Light */
2793 #define _NEW_LINE              (1u << 9)   /**< gl_context::Line */
2794 #define _NEW_PIXEL             (1u << 10)  /**< gl_context::Pixel */
2795 #define _NEW_POINT             (1u << 11)  /**< gl_context::Point */
2796 #define _NEW_POLYGON           (1u << 12)  /**< gl_context::Polygon */
2797 #define _NEW_POLYGONSTIPPLE    (1u << 13)  /**< gl_context::PolygonStipple */
2798 #define _NEW_SCISSOR           (1u << 14)  /**< gl_context::Scissor */
2799 #define _NEW_STENCIL           (1u << 15)  /**< gl_context::Stencil */
2800 #define _NEW_TEXTURE_OBJECT    (1u << 16)  /**< gl_context::Texture (bindings only) */
2801 #define _NEW_TRANSFORM         (1u << 17)  /**< gl_context::Transform */
2802 #define _NEW_VIEWPORT          (1u << 18)  /**< gl_context::Viewport */
2803 #define _NEW_TEXTURE_STATE     (1u << 19)  /**< gl_context::Texture (states only) */
2804 #define _NEW_LIGHT_STATE       (1u << 20)  /**< gl_context::Light */
2805 #define _NEW_RENDERMODE        (1u << 21)  /**< gl_context::RenderMode, etc */
2806 #define _NEW_BUFFERS           (1u << 22)  /**< gl_context::Visual, DrawBuffer, */
2807 #define _NEW_CURRENT_ATTRIB    (1u << 23)  /**< gl_context::Current */
2808 #define _NEW_MULTISAMPLE       (1u << 24)  /**< gl_context::Multisample */
2809 #define _NEW_TRACK_MATRIX      (1u << 25)  /**< gl_context::VertexProgram */
2810 #define _NEW_PROGRAM           (1u << 26)  /**< New program/shader state */
2811 #define _NEW_PROGRAM_CONSTANTS (1u << 27)
2812 #define _NEW_FF_VERT_PROGRAM   (1u << 28)
2813 #define _NEW_FRAG_CLAMP        (1u << 29)
2814 #define _NEW_MATERIAL          (1u << 30)  /**< gl_context::Light.Material */
2815 #define _NEW_FF_FRAG_PROGRAM   (1u << 31)
2816 #define _NEW_ALL ~0
2817 /*@}*/
2818 
2819 
2820 /* This has to be included here. */
2821 #include "dd.h"
2822 
2823 
2824 /** Opaque declaration of display list payload data type */
2825 union gl_dlist_node;
2826 
2827 
2828 /**
2829  * Per-display list information.
2830  */
2831 struct gl_display_list
2832 {
2833    GLuint Name;
2834    bool execute_glthread;
2835    bool small_list;
2836    GLchar *Label;     /**< GL_KHR_debug */
2837    /** The dlist commands are in a linked list of nodes */
2838    union {
2839       /* Big lists allocate their own storage */
2840       union gl_dlist_node *Head;
2841       /* Small lists use ctx->Shared->small_dlist_store */
2842       struct {
2843          unsigned start;
2844          unsigned count;
2845       };
2846    };
2847 };
2848 
2849 
2850 /**
2851  * State used during display list compilation and execution.
2852  */
2853 struct gl_dlist_state
2854 {
2855    struct gl_display_list *CurrentList; /**< List currently being compiled */
2856    union gl_dlist_node *CurrentBlock; /**< Pointer to current block of nodes */
2857    GLuint CurrentPos;		/**< Index into current block of nodes */
2858    GLuint CallDepth;		/**< Current recursion calling depth */
2859    GLuint LastInstSize;         /**< Size of the last node. */
2860 
2861    GLubyte ActiveAttribSize[VERT_ATTRIB_MAX];
2862    uint32_t CurrentAttrib[VERT_ATTRIB_MAX][8];
2863 
2864    GLubyte ActiveMaterialSize[MAT_ATTRIB_MAX];
2865    GLfloat CurrentMaterial[MAT_ATTRIB_MAX][4];
2866 
2867    struct {
2868       /* State known to have been set by the currently-compiling display
2869        * list.  Used to eliminate some redundant state changes.
2870        */
2871       GLenum16 ShadeModel;
2872       bool UseLoopback;
2873    } Current;
2874 };
2875 
2876 /**
2877  * Driver-specific state flags.
2878  *
2879  * These are or'd with gl_context::NewDriverState to notify a driver about
2880  * a state change. The driver sets the flags at context creation and
2881  * the meaning of the bits set is opaque to core Mesa.
2882  */
2883 struct gl_driver_flags
2884 {
2885    /**
2886     * gl_context::AtomicBufferBindings
2887     */
2888    uint64_t NewAtomicBuffer;
2889 
2890    /** gl_context::Color::Alpha* */
2891    uint64_t NewAlphaTest;
2892 
2893    /** gl_context::Multisample::Enabled */
2894    uint64_t NewMultisampleEnable;
2895 
2896    /** gl_context::Multisample::(Min)SampleShading */
2897    uint64_t NewSampleShading;
2898 
2899    /** gl_context::Transform::ClipPlanesEnabled */
2900    uint64_t NewClipPlaneEnable;
2901 
2902    /** gl_context::Color::ClampFragmentColor */
2903    uint64_t NewFragClamp;
2904 
2905    /** Shader constants (uniforms, program parameters, state constants) */
2906    uint64_t NewShaderConstants[MESA_SHADER_STAGES];
2907 
2908    /** For GL_CLAMP emulation */
2909    uint64_t NewSamplersWithClamp;
2910 };
2911 
2912 struct gl_buffer_binding
2913 {
2914    struct gl_buffer_object *BufferObject;
2915    /** Start of uniform block data in the buffer */
2916    GLintptr Offset;
2917    /** Size of data allowed to be referenced from the buffer (in bytes) */
2918    GLsizeiptr Size;
2919    /**
2920     * glBindBufferBase() indicates that the Size should be ignored and only
2921     * limited by the current size of the BufferObject.
2922     */
2923    GLboolean AutomaticSize;
2924 };
2925 
2926 /**
2927  * ARB_shader_image_load_store image unit.
2928  */
2929 struct gl_image_unit
2930 {
2931    /**
2932     * Texture object bound to this unit.
2933     */
2934    struct gl_texture_object *TexObj;
2935 
2936    /**
2937     * Level of the texture object bound to this unit.
2938     */
2939    GLubyte Level;
2940 
2941    /**
2942     * \c GL_TRUE if the whole level is bound as an array of layers, \c
2943     * GL_FALSE if only some specific layer of the texture is bound.
2944     * \sa Layer
2945     */
2946    GLboolean Layered;
2947 
2948    /**
2949     * Layer of the texture object bound to this unit as specified by the
2950     * application.
2951     */
2952    GLushort Layer;
2953 
2954    /**
2955     * Layer of the texture object bound to this unit, or zero if
2956     * Layered == false.
2957     */
2958    GLushort _Layer;
2959 
2960    /**
2961     * Access allowed to this texture image.  Either \c GL_READ_ONLY,
2962     * \c GL_WRITE_ONLY or \c GL_READ_WRITE.
2963     */
2964    GLenum16 Access;
2965 
2966    /**
2967     * GL internal format that determines the interpretation of the
2968     * image memory when shader image operations are performed through
2969     * this unit.
2970     */
2971    GLenum16 Format;
2972 
2973    /**
2974     * Mesa format corresponding to \c Format.
2975     */
2976    mesa_format _ActualFormat:16;
2977 };
2978 
2979 /**
2980  * Shader subroutines storage
2981  */
2982 struct gl_subroutine_index_binding
2983 {
2984    GLuint NumIndex;
2985    GLuint *IndexPtr;
2986 };
2987 
2988 struct gl_texture_handle_object
2989 {
2990    struct gl_texture_object *texObj;
2991    struct gl_sampler_object *sampObj;
2992    GLuint64 handle;
2993 };
2994 
2995 struct gl_image_handle_object
2996 {
2997    struct gl_image_unit imgObj;
2998    GLuint64 handle;
2999 };
3000 
3001 struct gl_memory_object
3002 {
3003    GLuint Name;            /**< hash table ID/name */
3004    GLboolean Immutable;    /**< denotes mutability state of parameters */
3005    GLboolean Dedicated;    /**< import memory from a dedicated allocation */
3006 
3007    struct pipe_memory_object *memory;
3008 
3009    /* TEXTURE_TILING_EXT param from gl_texture_object */
3010    GLuint TextureTiling;
3011 };
3012 
3013 struct gl_semaphore_object
3014 {
3015    GLuint Name;            /**< hash table ID/name */
3016    struct pipe_fence_handle *fence;
3017    enum pipe_fd_type type;
3018    uint64_t timeline_value;
3019 };
3020 
3021 /**
3022  * One element of the client attrib stack.
3023  */
3024 struct gl_client_attrib_node
3025 {
3026    GLbitfield Mask;
3027    struct gl_array_attrib Array;
3028    struct gl_vertex_array_object VAO;
3029    struct gl_pixelstore_attrib Pack;
3030    struct gl_pixelstore_attrib Unpack;
3031 };
3032 
3033 /**
3034  * The VBO module implemented in src/vbo.
3035  */
3036 struct vbo_context {
3037    struct gl_array_attributes current[VBO_ATTRIB_MAX];
3038 
3039    struct gl_vertex_array_object *VAO;
3040 
3041    struct vbo_exec_context exec;
3042    struct vbo_save_context save;
3043 };
3044 
3045 /**
3046  * glEnable node for the attribute stack. (glPushAttrib/glPopAttrib)
3047  */
3048 struct gl_enable_attrib_node
3049 {
3050    GLboolean AlphaTest;
3051    GLboolean AutoNormal;
3052    GLboolean Blend;
3053    GLbitfield ClipPlanes;
3054    GLboolean ColorMaterial;
3055    GLboolean CullFace;
3056    GLboolean DepthClampNear;
3057    GLboolean DepthClampFar;
3058    GLboolean DepthTest;
3059    GLboolean Dither;
3060    GLboolean Fog;
3061    GLboolean Light[MAX_LIGHTS];
3062    GLboolean Lighting;
3063    GLboolean LineSmooth;
3064    GLboolean LineStipple;
3065    GLboolean IndexLogicOp;
3066    GLboolean ColorLogicOp;
3067 
3068    GLboolean Map1Color4;
3069    GLboolean Map1Index;
3070    GLboolean Map1Normal;
3071    GLboolean Map1TextureCoord1;
3072    GLboolean Map1TextureCoord2;
3073    GLboolean Map1TextureCoord3;
3074    GLboolean Map1TextureCoord4;
3075    GLboolean Map1Vertex3;
3076    GLboolean Map1Vertex4;
3077    GLboolean Map2Color4;
3078    GLboolean Map2Index;
3079    GLboolean Map2Normal;
3080    GLboolean Map2TextureCoord1;
3081    GLboolean Map2TextureCoord2;
3082    GLboolean Map2TextureCoord3;
3083    GLboolean Map2TextureCoord4;
3084    GLboolean Map2Vertex3;
3085    GLboolean Map2Vertex4;
3086 
3087    GLboolean Normalize;
3088    GLboolean PixelTexture;
3089    GLboolean PointSmooth;
3090    GLboolean PolygonOffsetPoint;
3091    GLboolean PolygonOffsetLine;
3092    GLboolean PolygonOffsetFill;
3093    GLboolean PolygonSmooth;
3094    GLboolean PolygonStipple;
3095    GLboolean RescaleNormals;
3096    GLbitfield Scissor;
3097    GLboolean Stencil;
3098    GLboolean StencilTwoSide;          /* GL_EXT_stencil_two_side */
3099    GLboolean MultisampleEnabled;      /* GL_ARB_multisample */
3100    GLboolean SampleAlphaToCoverage;   /* GL_ARB_multisample */
3101    GLboolean SampleAlphaToOne;        /* GL_ARB_multisample */
3102    GLboolean SampleCoverage;          /* GL_ARB_multisample */
3103    GLboolean RasterPositionUnclipped; /* GL_IBM_rasterpos_clip */
3104 
3105    GLbitfield Texture[MAX_TEXTURE_UNITS];
3106    GLbitfield TexGen[MAX_TEXTURE_UNITS];
3107 
3108    /* GL_ARB_vertex_program */
3109    GLboolean VertexProgram;
3110    GLboolean VertexProgramPointSize;
3111    GLboolean VertexProgramTwoSide;
3112 
3113    /* GL_ARB_fragment_program */
3114    GLboolean FragmentProgram;
3115 
3116    /* GL_ARB_point_sprite */
3117    GLboolean PointSprite;
3118    GLboolean FragmentShaderATI;
3119 
3120    /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
3121    GLboolean sRGBEnabled;
3122 
3123    /* GL_NV_conservative_raster */
3124    GLboolean ConservativeRasterization;
3125 };
3126 
3127 /**
3128  * Texture node for the attribute stack. (glPushAttrib/glPopAttrib)
3129  */
3130 struct gl_texture_attrib_node
3131 {
3132    GLuint CurrentUnit;   /**< GL_ACTIVE_TEXTURE */
3133    GLuint NumTexSaved;
3134    struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_TEXTURE_COORD_UNITS];
3135    GLfloat LodBias[MAX_TEXTURE_UNITS];
3136    float LodBiasQuantized[MAX_TEXTURE_UNITS];
3137 
3138    /** Saved default texture object state. */
3139    struct gl_texture_object SavedDefaultObj[NUM_TEXTURE_TARGETS];
3140 
3141    /* For saving per texture object state (wrap modes, filters, etc),
3142     * SavedObj[][].Target is unused, so the value is invalid.
3143     */
3144    struct gl_texture_object SavedObj[MAX_COMBINED_TEXTURE_IMAGE_UNITS][NUM_TEXTURE_TARGETS];
3145 };
3146 
3147 
3148 /**
3149  * Node for the attribute stack. (glPushAttrib/glPopAttrib)
3150  */
3151 struct gl_attrib_node
3152 {
3153    GLbitfield Mask;
3154    GLbitfield OldPopAttribStateMask;
3155    struct gl_accum_attrib Accum;
3156    struct gl_colorbuffer_attrib Color;
3157    struct gl_current_attrib Current;
3158    struct gl_depthbuffer_attrib Depth;
3159    struct gl_enable_attrib_node Enable;
3160    struct gl_eval_attrib Eval;
3161    struct gl_fog_attrib Fog;
3162    struct gl_hint_attrib Hint;
3163    struct gl_light_attrib Light;
3164    struct gl_line_attrib Line;
3165    struct gl_list_attrib List;
3166    struct gl_pixel_attrib Pixel;
3167    struct gl_point_attrib Point;
3168    struct gl_polygon_attrib Polygon;
3169    GLuint PolygonStipple[32];
3170    struct gl_scissor_attrib Scissor;
3171    struct gl_stencil_attrib Stencil;
3172    struct gl_transform_attrib Transform;
3173    struct gl_multisample_attrib Multisample;
3174    struct gl_texture_attrib_node Texture;
3175 
3176    struct viewport_state
3177    {
3178       struct gl_viewport_attrib ViewportArray[MAX_VIEWPORTS];
3179       GLuint SubpixelPrecisionBias[2];
3180    } Viewport;
3181 };
3182 
3183 /**
3184  * Dispatch tables.
3185  */
3186 struct gl_dispatch
3187 {
3188    /**
3189     * For non-displaylist-saving, non-begin/end.
3190     */
3191    struct _glapi_table *OutsideBeginEnd;
3192 
3193    /**
3194     * The dispatch table used between glBegin() and glEnd() (outside of a
3195     * display list).  Only valid functions between those two are set.
3196     */
3197    struct _glapi_table *BeginEnd;
3198 
3199    /**
3200     * Same as BeginEnd except glVertex{Attrib} functions. Used when
3201     * HW GL_SELECT mode instead of BeginEnd to insert extra code
3202     * for GL_SELECT.
3203     */
3204    struct _glapi_table *HWSelectModeBeginEnd;
3205 
3206    /**
3207     * The dispatch table used between glNewList() and glEndList().
3208     */
3209    struct _glapi_table *Save;
3210 
3211    /**
3212     * Dispatch table for when a graphics reset has happened.
3213     */
3214    struct _glapi_table *ContextLost;
3215 
3216    /**
3217     * The current dispatch table for non-displaylist-saving execution.
3218     * It can be equal to one of these:
3219     * - OutsideBeginEnd
3220     * - BeginEnd
3221     * - HWSelectModeBeginEnd
3222     */
3223    struct _glapi_table *Exec;
3224 
3225    /**
3226     * The current dispatch table overall. It can be equal to one of these:
3227     * - Exec
3228     * - Save
3229     * - ContextLost
3230     */
3231    struct _glapi_table *Current;
3232 };
3233 
3234 /**
3235  * Mesa rendering context.
3236  *
3237  * This is the central context data structure for Mesa.  Almost all
3238  * OpenGL state is contained in this structure.
3239  * Think of this as a base class from which device drivers will derive
3240  * sub classes.
3241  */
3242 struct gl_context
3243 {
3244    /** State possibly shared with other contexts in the address space */
3245    struct gl_shared_state *Shared;
3246 
3247    /** Whether Shared->BufferObjects has already been locked for this context. */
3248    bool BufferObjectsLocked;
3249    /** Whether Shared->TexMutex has already been locked for this context. */
3250    bool TexturesLocked;
3251 
3252    /** \name API function pointer tables */
3253    /*@{*/
3254    gl_api API;
3255 
3256    /**
3257     * Dispatch tables implementing OpenGL functions. GLThread has no effect
3258     * on this.
3259     */
3260    struct gl_dispatch Dispatch;
3261 
3262    /**
3263     * Dispatch table used by GLThread, a component used to marshal API
3264     * calls from an application to a separate thread.
3265     */
3266    struct _glapi_table *MarshalExec;
3267 
3268    /**
3269     * Dispatch table currently in use for fielding API calls from the client
3270     * program.  If API calls are being marshalled to another thread, this ==
3271     * MarshalExec.  Otherwise it == Dispatch.Current.
3272     */
3273    struct _glapi_table *GLApi;
3274 
3275    /*@}*/
3276 
3277    struct glthread_state GLThread;
3278 
3279    struct gl_config Visual;
3280    struct gl_framebuffer *DrawBuffer;	/**< buffer for writing */
3281    struct gl_framebuffer *ReadBuffer;	/**< buffer for reading */
3282    struct gl_framebuffer *WinSysDrawBuffer;  /**< set with MakeCurrent */
3283    struct gl_framebuffer *WinSysReadBuffer;  /**< set with MakeCurrent */
3284 
3285    /**
3286     * Device driver function pointer table
3287     */
3288    struct dd_function_table Driver;
3289 
3290    /** Core/Driver constants */
3291    struct gl_constants Const;
3292 
3293    /**
3294     * Bitmask of valid primitive types supported by this context type,
3295     * GL version, and extensions, not taking current states into account.
3296     * Current states can further reduce the final bitmask at draw time.
3297     */
3298    GLbitfield SupportedPrimMask;
3299 
3300    /**
3301     * Bitmask of valid primitive types depending on current states (such as
3302     * shaders). This is 0 if the current states should result in
3303     * GL_INVALID_OPERATION in draw calls.
3304     */
3305    GLbitfield ValidPrimMask;
3306 
3307    GLenum16 DrawGLError; /**< GL error to return from draw calls */
3308 
3309    /**
3310     * Same as ValidPrimMask, but should be applied to glDrawElements*.
3311     */
3312    GLbitfield ValidPrimMaskIndexed;
3313 
3314    /** DrawID for the next non-multi non-indirect draw. Only set by glthread. */
3315    GLuint DrawID;
3316 
3317    /**
3318     * Whether DrawPixels/CopyPixels/Bitmap are valid to render.
3319     */
3320    bool DrawPixValid;
3321 
3322    /** \name The various 4x4 matrix stacks */
3323    /*@{*/
3324    struct gl_matrix_stack ModelviewMatrixStack;
3325    struct gl_matrix_stack ProjectionMatrixStack;
3326    struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
3327    struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
3328    struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
3329    /*@}*/
3330 
3331    /** Combined modelview and projection matrix */
3332    GLmatrix _ModelProjectMatrix;
3333 
3334    /** \name Display lists */
3335    struct gl_dlist_state ListState;
3336 
3337    GLboolean ExecuteFlag;	/**< Execute GL commands? */
3338    GLboolean CompileFlag;	/**< Compile GL commands into display list? */
3339 
3340    /** Extension information */
3341    struct gl_extensions Extensions;
3342 
3343    /** GL version integer, for example 31 for GL 3.1, or 20 for GLES 2.0. */
3344    GLuint Version;
3345    char *VersionString;
3346 
3347    /** \name State attribute stack (for glPush/PopAttrib) */
3348    /*@{*/
3349    GLuint AttribStackDepth;
3350    struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
3351    /*@}*/
3352 
3353    /** \name Renderer attribute groups
3354     *
3355     * We define a struct for each attribute group to make pushing and popping
3356     * attributes easy.  Also it's a good organization.
3357     */
3358    /*@{*/
3359    struct gl_accum_attrib	Accum;		/**< Accum buffer attributes */
3360    struct gl_colorbuffer_attrib	Color;		/**< Color buffer attributes */
3361    struct gl_current_attrib	Current;	/**< Current attributes */
3362    struct gl_depthbuffer_attrib	Depth;		/**< Depth buffer attributes */
3363    struct gl_eval_attrib	Eval;		/**< Eval attributes */
3364    struct gl_fog_attrib		Fog;		/**< Fog attributes */
3365    struct gl_hint_attrib	Hint;		/**< Hint attributes */
3366    struct gl_light_attrib	Light;		/**< Light attributes */
3367    struct gl_line_attrib	Line;		/**< Line attributes */
3368    struct gl_list_attrib	List;		/**< List attributes */
3369    struct gl_multisample_attrib Multisample;
3370    struct gl_pixel_attrib	Pixel;		/**< Pixel attributes */
3371    struct gl_point_attrib	Point;		/**< Point attributes */
3372    struct gl_polygon_attrib	Polygon;	/**< Polygon attributes */
3373    GLuint PolygonStipple[32];			/**< Polygon stipple */
3374    struct gl_scissor_attrib	Scissor;	/**< Scissor attributes */
3375    struct gl_stencil_attrib	Stencil;	/**< Stencil buffer attributes */
3376    struct gl_texture_attrib	Texture;	/**< Texture attributes */
3377    struct gl_transform_attrib	Transform;	/**< Transformation attributes */
3378    struct gl_viewport_attrib	ViewportArray[MAX_VIEWPORTS];	/**< Viewport attributes */
3379    GLuint SubpixelPrecisionBias[2];	/**< Viewport attributes */
3380    /*@}*/
3381 
3382    /** \name Client attribute stack */
3383    /*@{*/
3384    GLuint ClientAttribStackDepth;
3385    struct gl_client_attrib_node ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
3386    /*@}*/
3387 
3388    /** \name Client attribute groups */
3389    /*@{*/
3390    struct gl_array_attrib	Array;	/**< Vertex arrays */
3391    struct gl_pixelstore_attrib	Pack;	/**< Pixel packing */
3392    struct gl_pixelstore_attrib	Unpack;	/**< Pixel unpacking */
3393    struct gl_pixelstore_attrib	DefaultPacking;	/**< Default params */
3394    /*@}*/
3395 
3396    /** \name Other assorted state (not pushed/popped on attribute stack) */
3397    /*@{*/
3398    struct gl_pixelmaps          PixelMaps;
3399 
3400    struct gl_evaluators EvalMap;   /**< All evaluators */
3401    struct gl_feedback   Feedback;  /**< Feedback */
3402    struct gl_selection  Select;    /**< Selection */
3403 
3404    struct gl_program_state Program;  /**< general program state */
3405    struct gl_vertex_program_state VertexProgram;
3406    struct gl_fragment_program_state FragmentProgram;
3407    struct gl_geometry_program_state GeometryProgram;
3408    struct gl_compute_program_state ComputeProgram;
3409    struct gl_tess_ctrl_program_state TessCtrlProgram;
3410    struct gl_tess_eval_program_state TessEvalProgram;
3411    struct gl_ati_fragment_shader_state ATIFragmentShader;
3412 
3413    struct gl_pipeline_shader_state Pipeline; /**< GLSL pipeline shader object state */
3414    struct gl_pipeline_object Shader; /**< GLSL shader object state */
3415 
3416    /**
3417     * Current active shader pipeline state
3418     *
3419     * Almost all internal users want ::_Shader instead of ::Shader.  The
3420     * exceptions are bits of legacy GLSL API that do not know about separate
3421     * shader objects.
3422     *
3423     * If a program is active via \c glUseProgram, this will point to
3424     * \c ::Shader.
3425     *
3426     * If a program pipeline is active via \c glBindProgramPipeline, this will
3427     * point to \c ::Pipeline.Current.
3428     *
3429     * If neither a program nor a program pipeline is active, this will point to
3430     * \c ::Pipeline.Default.  This ensures that \c ::_Shader will never be
3431     * \c NULL.
3432     */
3433    struct gl_pipeline_object *_Shader;
3434 
3435    /**
3436     * NIR containing the functions that implement software fp64 support.
3437     */
3438    struct nir_shader *SoftFP64;
3439 
3440    struct gl_query_state Query;  /**< occlusion, timer queries */
3441 
3442    struct gl_transform_feedback_state TransformFeedback;
3443 
3444    struct gl_perf_monitor_state PerfMonitor;
3445    struct gl_perf_query_state PerfQuery;
3446 
3447    struct gl_buffer_object *DrawIndirectBuffer; /** < GL_ARB_draw_indirect */
3448    struct gl_buffer_object *ParameterBuffer; /** < GL_ARB_indirect_parameters */
3449    struct gl_buffer_object *DispatchIndirectBuffer; /** < GL_ARB_compute_shader */
3450 
3451    struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */
3452    struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */
3453 
3454    struct gl_buffer_object *QueryBuffer; /**< GL_ARB_query_buffer_object */
3455 
3456    /**
3457     * Current GL_ARB_uniform_buffer_object binding referenced by
3458     * GL_UNIFORM_BUFFER target for glBufferData, glMapBuffer, etc.
3459     */
3460    struct gl_buffer_object *UniformBuffer;
3461 
3462    /**
3463     * Current GL_ARB_shader_storage_buffer_object binding referenced by
3464     * GL_SHADER_STORAGE_BUFFER target for glBufferData, glMapBuffer, etc.
3465     */
3466    struct gl_buffer_object *ShaderStorageBuffer;
3467 
3468    /**
3469     * Array of uniform buffers for GL_ARB_uniform_buffer_object and GL 3.1.
3470     * This is set up using glBindBufferRange() or glBindBufferBase().  They are
3471     * associated with uniform blocks by glUniformBlockBinding()'s state in the
3472     * shader program.
3473     */
3474    struct gl_buffer_binding
3475       UniformBufferBindings[MAX_COMBINED_UNIFORM_BUFFERS];
3476 
3477    /**
3478     * Array of shader storage buffers for ARB_shader_storage_buffer_object
3479     * and GL 4.3. This is set up using glBindBufferRange() or
3480     * glBindBufferBase().  They are associated with shader storage blocks by
3481     * glShaderStorageBlockBinding()'s state in the shader program.
3482     */
3483    struct gl_buffer_binding
3484       ShaderStorageBufferBindings[MAX_COMBINED_SHADER_STORAGE_BUFFERS];
3485 
3486    /**
3487     * Object currently associated with the GL_ATOMIC_COUNTER_BUFFER
3488     * target.
3489     */
3490    struct gl_buffer_object *AtomicBuffer;
3491 
3492    /**
3493     * Object currently associated w/ the GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
3494     * target.
3495     */
3496    struct gl_buffer_object *ExternalVirtualMemoryBuffer;
3497 
3498    /**
3499     * Array of atomic counter buffer binding points.
3500     */
3501    struct gl_buffer_binding
3502       AtomicBufferBindings[MAX_COMBINED_ATOMIC_BUFFERS];
3503 
3504    /**
3505     * Array of image units for ARB_shader_image_load_store.
3506     */
3507    struct gl_image_unit ImageUnits[MAX_IMAGE_UNITS];
3508 
3509    struct gl_subroutine_index_binding SubroutineIndex[MESA_SHADER_STAGES];
3510    /*@}*/
3511 
3512    struct gl_meta_state *Meta;  /**< for "meta" operations */
3513 
3514    /* GL_EXT_framebuffer_object */
3515    struct gl_renderbuffer *CurrentRenderbuffer;
3516 
3517    GLenum16 ErrorValue;      /**< Last error code */
3518 
3519    /**
3520     * Recognize and silence repeated error debug messages in buggy apps.
3521     */
3522    const char *ErrorDebugFmtString;
3523    GLuint ErrorDebugCount;
3524 
3525    /* GL_ARB_debug_output/GL_KHR_debug */
3526    simple_mtx_t DebugMutex;
3527    struct gl_debug_state *Debug;
3528 
3529    GLenum16 RenderMode;      /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
3530    GLbitfield NewState;      /**< bitwise-or of _NEW_* flags */
3531    GLbitfield PopAttribState; /**< Updated state since glPushAttrib */
3532    uint64_t NewDriverState;  /**< bitwise-or of flags from DriverFlags */
3533 
3534    struct gl_driver_flags DriverFlags;
3535 
3536    GLboolean ViewportInitialized;  /**< has viewport size been initialized? */
3537    GLboolean _AllowDrawOutOfOrder;
3538 
3539    /** \name Derived state */
3540    GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
3541    GLfloat _EyeZDir[3];
3542    GLfloat _ModelViewInvScale; /* may be for model- or eyespace lighting */
3543    GLfloat _ModelViewInvScaleEyespace; /* always factor defined in spec */
3544    GLboolean _NeedEyeCoords;
3545 
3546    GLuint TextureStateTimestamp; /**< detect changes to shared state */
3547 
3548    GLboolean PointSizeIsSet; /**< the glPointSize value in the shader is set */
3549 
3550    /** \name For debugging/development only */
3551    /*@{*/
3552    GLboolean FirstTimeCurrent;
3553    /*@}*/
3554 
3555    /**
3556     * False if this context was created without a config. This is needed
3557     * because the initial state of glDrawBuffers depends on this
3558     */
3559    GLboolean HasConfig;
3560 
3561    GLboolean TextureFormatSupported[MESA_FORMAT_COUNT];
3562 
3563    GLboolean RasterDiscard;  /**< GL_RASTERIZER_DISCARD */
3564    GLboolean IntelConservativeRasterization; /**< GL_CONSERVATIVE_RASTERIZATION_INTEL */
3565    GLboolean ConservativeRasterization; /**< GL_CONSERVATIVE_RASTERIZATION_NV */
3566    GLfloat ConservativeRasterDilate;
3567    GLenum16 ConservativeRasterMode;
3568 
3569    GLboolean IntelBlackholeRender; /**< GL_INTEL_blackhole_render */
3570 
3571    /** Does glVertexAttrib(0) alias glVertex()? */
3572    bool _AttribZeroAliasesVertex;
3573 
3574    /**
3575     * When set, TileRasterOrderIncreasingX/Y control the order that a tiled
3576     * renderer's tiles should be excecuted, to meet the requirements of
3577     * GL_MESA_tile_raster_order.
3578     */
3579    GLboolean TileRasterOrderFixed;
3580    GLboolean TileRasterOrderIncreasingX;
3581    GLboolean TileRasterOrderIncreasingY;
3582 
3583    /**
3584     * \name Hooks for module contexts.
3585     *
3586     * These will eventually live in the driver or elsewhere.
3587     */
3588    /*@{*/
3589    struct vbo_context vbo_context;
3590    struct st_context *st;
3591    struct pipe_screen *screen;
3592    struct pipe_context *pipe;
3593    struct st_config_options *st_opts;
3594    struct cso_context *cso_context;
3595    bool has_invalidate_buffer;
3596    bool has_string_marker;
3597    /* On old libGL's for linux we need to invalidate the drawables
3598     * on glViewpport calls, this is set via a option.
3599     */
3600    bool invalidate_on_gl_viewport;
3601 
3602    /*@}*/
3603 
3604    /**
3605     * \name NV_vdpau_interop
3606     */
3607    /*@{*/
3608    const void *vdpDevice;
3609    const void *vdpGetProcAddress;
3610    struct set *vdpSurfaces;
3611    /*@}*/
3612 
3613    /**
3614     * Has this context observed a GPU reset in any context in the share group?
3615     *
3616     * Once this field becomes true, it is never reset to false.
3617     */
3618    GLboolean ShareGroupReset;
3619 
3620    /**
3621     * \name OES_primitive_bounding_box
3622     *
3623     * Stores the arguments to glPrimitiveBoundingBox
3624     */
3625    GLfloat PrimitiveBoundingBox[8];
3626 
3627    struct disk_cache *Cache;
3628 
3629    /**
3630     * \name GL_ARB_bindless_texture
3631     */
3632    /*@{*/
3633    struct hash_table_u64 *ResidentTextureHandles;
3634    struct hash_table_u64 *ResidentImageHandles;
3635    /*@}*/
3636 
3637    bool shader_builtin_ref;
3638 
3639    struct pipe_draw_start_count_bias *tmp_draws;
3640    unsigned num_tmp_draws;
3641 };
3642 
3643 #ifndef NDEBUG
3644 extern int MESA_VERBOSE;
3645 extern int MESA_DEBUG_FLAGS;
3646 #else
3647 # define MESA_VERBOSE 0
3648 # define MESA_DEBUG_FLAGS 0
3649 #endif
3650 
3651 
3652 /** The MESA_VERBOSE var is a bitmask of these flags */
3653 enum _verbose
3654 {
3655    VERBOSE_VARRAY		= 0x0001,
3656    VERBOSE_TEXTURE		= 0x0002,
3657    VERBOSE_MATERIAL		= 0x0004,
3658    VERBOSE_PIPELINE		= 0x0008,
3659    VERBOSE_DRIVER		= 0x0010,
3660    VERBOSE_STATE		= 0x0020,
3661    VERBOSE_API			= 0x0040,
3662    VERBOSE_DISPLAY_LIST		= 0x0100,
3663    VERBOSE_LIGHTING		= 0x0200,
3664    VERBOSE_PRIMS		= 0x0400,
3665    VERBOSE_VERTS		= 0x0800,
3666    VERBOSE_DISASSEM		= 0x1000,
3667    VERBOSE_SWAPBUFFERS          = 0x4000
3668 };
3669 
3670 
3671 /** The MESA_DEBUG_FLAGS var is a bitmask of these flags */
3672 enum _debug
3673 {
3674    DEBUG_SILENT                 = (1 << 0),
3675    DEBUG_ALWAYS_FLUSH		= (1 << 1),
3676    DEBUG_INCOMPLETE_TEXTURE     = (1 << 2),
3677    DEBUG_INCOMPLETE_FBO         = (1 << 3),
3678    DEBUG_CONTEXT                = (1 << 4)
3679 };
3680 
3681 #ifdef __cplusplus
3682 }
3683 #endif
3684 
3685 #endif /* MTYPES_H */
3686