• 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 shader_types.h
28  * All the GL shader/program types.
29  */
30 
31 #ifndef SHADER_TYPES_H
32 #define SHADER_TYPES_H
33 
34 #include "main/config.h" /* for MAX_FEEDBACK_BUFFERS */
35 #include "util/glheader.h"
36 #include "main/menums.h"
37 #include "util/mesa-sha1.h"
38 #include "compiler/shader_info.h"
39 #include "compiler/glsl/list.h"
40 #include "compiler/glsl/ir_uniform.h"
41 
42 #include "pipe/p_state.h"
43 
44 /**
45  * Shader information needed by both gl_shader and gl_linked shader.
46  */
47 struct gl_shader_info
48 {
49    /**
50     * Tessellation Control shader state from layout qualifiers.
51     */
52    struct {
53       /**
54        * 0 - vertices not declared in shader, or
55        * 1 .. GL_MAX_PATCH_VERTICES
56        */
57       GLint VerticesOut;
58    } TessCtrl;
59 
60    /**
61     * Tessellation Evaluation shader state from layout qualifiers.
62     */
63    struct {
64       enum tess_primitive_mode _PrimitiveMode;
65 
66       enum gl_tess_spacing Spacing;
67 
68       /**
69        * GL_CW, GL_CCW, or 0 if it's not set in this shader.
70        */
71       GLenum16 VertexOrder;
72       /**
73        * 1, 0, or -1 if it's not set in this shader.
74        */
75       int PointMode;
76    } TessEval;
77 
78    /**
79     * Geometry shader state from GLSL 1.50 layout qualifiers.
80     */
81    struct {
82       GLint VerticesOut;
83       /**
84        * 0 - Invocations count not declared in shader, or
85        * 1 .. Const.MaxGeometryShaderInvocations
86        */
87       GLint Invocations;
88       /**
89        * GL_POINTS, GL_LINES, GL_LINES_ADJACENCY, GL_TRIANGLES, or
90        * GL_TRIANGLES_ADJACENCY, or PRIM_UNKNOWN if it's not set in this
91        * shader.
92        */
93       enum mesa_prim InputType;
94        /**
95         * GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP, or PRIM_UNKNOWN if
96         * it's not set in this shader.
97         */
98       enum mesa_prim OutputType;
99    } Geom;
100 
101    /**
102     * Compute shader state from ARB_compute_shader and
103     * ARB_compute_variable_group_size layout qualifiers.
104     */
105    struct {
106       /**
107        * Size specified using local_size_{x,y,z}, or all 0's to indicate that
108        * it's not set in this shader.
109        */
110       unsigned LocalSize[3];
111 
112       /**
113        * Whether a variable work group size has been specified as defined by
114        * ARB_compute_variable_group_size.
115        */
116       bool LocalSizeVariable;
117 
118       /*
119        * Arrangement of invocations used to calculate derivatives in a compute
120        * shader.  From NV_compute_shader_derivatives.
121        */
122       enum gl_derivative_group DerivativeGroup;
123    } Comp;
124 };
125 
126 /**
127  * Compile status enum. COMPILE_SKIPPED is used to indicate the compile
128  * was skipped due to the shader matching one that's been seen before by
129  * the on-disk cache.
130  */
131 enum gl_compile_status
132 {
133    COMPILE_FAILURE = 0,
134    COMPILE_SUCCESS,
135    COMPILE_SKIPPED
136 };
137 
138 /**
139  * A GLSL shader object.
140  */
141 struct gl_shader
142 {
143    /** GL_FRAGMENT_SHADER || GL_VERTEX_SHADER || GL_GEOMETRY_SHADER_ARB ||
144     *  GL_TESS_CONTROL_SHADER || GL_TESS_EVALUATION_SHADER.
145     * Must be the first field.
146     */
147    GLenum16 Type;
148    gl_shader_stage Stage;
149    GLuint Name;  /**< AKA the handle */
150    GLint RefCount;  /**< Reference count */
151    GLchar *Label;   /**< GL_KHR_debug */
152    GLboolean DeletePending;
153    bool IsES;              /**< True if this shader uses GLSL ES */
154 
155    enum gl_compile_status CompileStatus;
156 
157    /** SHA1 of the pre-processed source used by the disk cache. */
158    uint8_t disk_cache_sha1[SHA1_DIGEST_LENGTH];
159    /** SHA1 of the original source before replacement, set by glShaderSource. */
160    uint8_t source_sha1[SHA1_DIGEST_LENGTH];
161    /** SHA1 of FallbackSource (a copy of some original source before replacement). */
162    uint8_t fallback_source_sha1[SHA1_DIGEST_LENGTH];
163    /** SHA1 of the current compiled source, set by successful glCompileShader. */
164    uint8_t compiled_source_sha1[SHA1_DIGEST_LENGTH];
165 
166    const GLchar *Source;  /**< Source code string */
167    const GLchar *FallbackSource;  /**< Fallback string used by on-disk cache*/
168 
169    GLchar *InfoLog;
170 
171    unsigned Version;       /**< GLSL version used for linking */
172 
173    /**
174     * A bitmask of gl_advanced_blend_mode values
175     */
176    GLbitfield BlendSupport;
177 
178    struct exec_list *ir;
179    struct glsl_symbol_table *symbols;
180 
181    /**
182     * Whether early fragment tests are enabled as defined by
183     * ARB_shader_image_load_store.
184     */
185    bool EarlyFragmentTests;
186 
187    bool ARB_fragment_coord_conventions_enable;
188    bool OES_geometry_point_size_enable;
189    bool OES_tessellation_point_size_enable;
190 
191    bool redeclares_gl_fragcoord;
192    bool uses_gl_fragcoord;
193 
194    bool PostDepthCoverage;
195    bool PixelInterlockOrdered;
196    bool PixelInterlockUnordered;
197    bool SampleInterlockOrdered;
198    bool SampleInterlockUnordered;
199    bool InnerCoverage;
200 
201    /**
202     * Fragment shader state from GLSL 1.50 layout qualifiers.
203     */
204    bool origin_upper_left;
205    bool pixel_center_integer;
206 
207    /**
208     * Whether bindless_sampler/bindless_image, and respectively
209     * bound_sampler/bound_image are declared at global scope as defined by
210     * ARB_bindless_texture.
211     */
212    bool bindless_sampler;
213    bool bindless_image;
214    bool bound_sampler;
215    bool bound_image;
216 
217    /**
218     * Whether layer output is viewport-relative.
219     */
220    bool redeclares_gl_layer;
221    bool layer_viewport_relative;
222 
223    /** Global xfb_stride out qualifier if any */
224    GLuint TransformFeedbackBufferStride[MAX_FEEDBACK_BUFFERS];
225 
226    struct gl_shader_info info;
227 
228    /* ARB_gl_spirv related data */
229    struct gl_shader_spirv_data *spirv_data;
230 };
231 
232 /**
233  * A linked GLSL shader object.
234  */
235 struct gl_linked_shader
236 {
237    gl_shader_stage Stage;
238 
239    /** All gl_shader::compiled_source_sha1 combined. */
240    uint8_t linked_source_sha1[SHA1_DIGEST_LENGTH];
241 
242    struct gl_program *Program;  /**< Post-compile assembly code */
243 
244    /**
245     * \name Sampler tracking
246     *
247     * \note Each of these fields is only set post-linking.
248     */
249    /*@{*/
250    GLbitfield shadow_samplers;	/**< Samplers used for shadow sampling. */
251    /*@}*/
252 
253    /**
254     * Number of default uniform block components used by this shader.
255     *
256     * This field is only set post-linking.
257     */
258    unsigned num_uniform_components;
259 
260    /**
261     * Number of combined uniform components used by this shader.
262     *
263     * This field is only set post-linking.  It is the sum of the uniform block
264     * sizes divided by sizeof(float), and num_uniform_compoennts.
265     */
266    unsigned num_combined_uniform_components;
267 
268    struct exec_list *ir;
269    struct glsl_symbol_table *symbols;
270 
271    /**
272     * ARB_gl_spirv related data.
273     *
274     * This is actually a reference to the gl_shader::spirv_data, which
275     * stores information that is also needed during linking.
276     */
277    struct gl_shader_spirv_data *spirv_data;
278 };
279 
280 
281 /**
282  * Link status enum. LINKING_SKIPPED is used to indicate linking
283  * was skipped due to the shader being loaded from the on-disk cache.
284  */
285 enum gl_link_status
286 {
287    LINKING_FAILURE = 0,
288    LINKING_SUCCESS,
289    LINKING_SKIPPED
290 };
291 
292 /* All GLSL program resource types are next to each other, so we can use that
293  * to make them 0-based like this:
294  */
295 #define GET_PROGRAM_RESOURCE_TYPE_FROM_GLENUM(x) ((x) - GL_UNIFORM)
296 #define NUM_PROGRAM_RESOURCE_TYPES (GL_TRANSFORM_FEEDBACK_VARYING - GL_UNIFORM + 1)
297 
298 /**
299  * A data structure to be shared by gl_shader_program and gl_program.
300  */
301 struct gl_shader_program_data
302 {
303    GLint RefCount;  /**< Reference count */
304 
305    /** SHA1 hash of linked shader program */
306    unsigned char sha1[20];
307 
308    unsigned NumUniformStorage;
309    unsigned NumHiddenUniforms;
310    struct gl_uniform_storage *UniformStorage;
311 
312    unsigned NumUniformBlocks;
313    unsigned NumShaderStorageBlocks;
314 
315    struct gl_uniform_block *UniformBlocks;
316    struct gl_uniform_block *ShaderStorageBlocks;
317 
318    struct gl_active_atomic_buffer *AtomicBuffers;
319    unsigned NumAtomicBuffers;
320 
321    /* Shader cache variables used during restore */
322    unsigned NumUniformDataSlots;
323    union gl_constant_value *UniformDataSlots;
324 
325    /* Used to hold initial uniform values for program binary restores.
326     *
327     * From the ARB_get_program_binary spec:
328     *
329     *    "A successful call to ProgramBinary will reset all uniform
330     *    variables to their initial values. The initial value is either
331     *    the value of the variable's initializer as specified in the
332     *    original shader source, or 0 if no initializer was present.
333     */
334    union gl_constant_value *UniformDataDefaults;
335 
336    /** Hash for quick search by name. */
337    struct hash_table *ProgramResourceHash[NUM_PROGRAM_RESOURCE_TYPES];
338 
339    GLboolean Validated;
340 
341    /** List of all active resources after linking. */
342    struct gl_program_resource *ProgramResourceList;
343    unsigned NumProgramResourceList;
344 
345    enum gl_link_status LinkStatus;   /**< GL_LINK_STATUS */
346    GLchar *InfoLog;
347 
348    /* Mask of stages this program was linked against */
349    unsigned linked_stages;
350 
351    /* Whether the shaders of this program are loaded from SPIR-V binaries
352     * (all have the SPIR_V_BINARY_ARB state). This was introduced by the
353     * ARB_gl_spirv extension.
354     */
355    bool spirv;
356 };
357 
358 /**
359  * A GLSL program object.
360  * Basically a linked collection of vertex and fragment shaders.
361  */
362 struct gl_shader_program
363 {
364    GLenum16 Type;   /**< Always GL_SHADER_PROGRAM (internal token) */
365    GLuint Name;  /**< aka handle or ID */
366    GLchar *Label;   /**< GL_KHR_debug */
367    GLint RefCount;  /**< Reference count */
368    GLboolean DeletePending;
369 
370    /**
371     * Is the application intending to glGetProgramBinary this program?
372     *
373     * BinaryRetrievableHint is the currently active hint that gets set
374     * during initialization and after linking and BinaryRetrievableHintPending
375     * is the hint set by the user to be active when program is linked next time.
376     */
377    GLboolean BinaryRetrievableHint;
378    GLboolean BinaryRetrievableHintPending;
379 
380    /**
381     * Indicates whether program can be bound for individual pipeline stages
382     * using UseProgramStages after it is next linked.
383     */
384    GLboolean SeparateShader;
385 
386    GLuint NumShaders;          /**< number of attached shaders */
387    struct gl_shader **Shaders; /**< List of attached the shaders */
388 
389    /**
390     * User-defined attribute bindings
391     *
392     * These are set via \c glBindAttribLocation and are used to direct the
393     * GLSL linker.  These are \b not the values used in the compiled shader,
394     * and they are \b not the values returned by \c glGetAttribLocation.
395     */
396    struct string_to_uint_map *AttributeBindings;
397 
398    /**
399     * User-defined fragment data bindings
400     *
401     * These are set via \c glBindFragDataLocation and are used to direct the
402     * GLSL linker.  These are \b not the values used in the compiled shader,
403     * and they are \b not the values returned by \c glGetFragDataLocation.
404     */
405    struct string_to_uint_map *FragDataBindings;
406    struct string_to_uint_map *FragDataIndexBindings;
407 
408    /**
409     * Transform feedback varyings last specified by
410     * glTransformFeedbackVaryings().
411     *
412     * For the current set of transform feedback varyings used for transform
413     * feedback output, see LinkedTransformFeedback.
414     */
415    struct {
416       GLenum16 BufferMode;
417       /** Global xfb_stride out qualifier if any */
418       GLuint BufferStride[MAX_FEEDBACK_BUFFERS];
419       GLuint NumVarying;
420       GLchar **VaryingNames;  /**< Array [NumVarying] of char * */
421    } TransformFeedback;
422 
423    struct gl_program *last_vert_prog;
424 
425    /** Post-link gl_FragDepth layout for ARB_conservative_depth. */
426    enum gl_frag_depth_layout FragDepthLayout;
427 
428    /**
429     * Geometry shader state - copied into gl_program by
430     * _mesa_copy_linked_program_data().
431     */
432    struct {
433       GLint VerticesIn;
434 
435       bool UsesEndPrimitive;
436       unsigned ActiveStreamMask;
437    } Geom;
438 
439    /** Data shared by gl_program and gl_shader_program */
440    struct gl_shader_program_data *data;
441 
442    /**
443     * Mapping from GL uniform locations returned by \c glUniformLocation to
444     * UniformStorage entries. Arrays will have multiple contiguous slots
445     * in the UniformRemapTable, all pointing to the same UniformStorage entry.
446     */
447    unsigned NumUniformRemapTable;
448    struct gl_uniform_storage **UniformRemapTable;
449 
450    /**
451     * Sometimes there are empty slots left over in UniformRemapTable after we
452     * allocate slots to explicit locations. This list stores the blocks of
453     * continuous empty slots inside UniformRemapTable.
454     */
455    struct exec_list EmptyUniformLocations;
456 
457    /**
458     * Total number of explicit uniform location including inactive uniforms.
459     */
460    unsigned NumExplicitUniformLocations;
461 
462    /**
463     * Map of active uniform names to locations
464     *
465     * Maps any active uniform that is not an array element to a location.
466     * Each active uniform, including individual structure members will appear
467     * in this map.  This roughly corresponds to the set of names that would be
468     * enumerated by \c glGetActiveUniform.
469     */
470    struct string_to_uint_map *UniformHash;
471 
472    GLboolean SamplersValidated; /**< Samplers validated against texture units? */
473 
474    bool IsES;              /**< True if this program uses GLSL ES */
475 
476    /**
477     * Per-stage shaders resulting from the first stage of linking.
478     *
479     * Set of linked shaders for this program.  The array is accessed using the
480     * \c MESA_SHADER_* defines.  Entries for non-existent stages will be
481     * \c NULL.
482     */
483    struct gl_linked_shader *_LinkedShaders[MESA_SHADER_STAGES];
484 
485    unsigned GLSL_Version; /**< GLSL version used for linking */
486 };
487 
488 /**
489  * Base class for any kind of program object
490  */
491 struct gl_program
492 {
493    /** FIXME: This must be first until we split shader_info from nir_shader */
494    struct shader_info info;
495 
496    GLuint Id;
497    GLint RefCount;
498    GLubyte *String;  /**< Null-terminated program text */
499 
500    /** GL_VERTEX/FRAGMENT_PROGRAM_ARB, GL_GEOMETRY_PROGRAM_NV */
501    GLenum16 Target;
502    GLenum16 Format;    /**< String encoding format */
503 
504    GLboolean _Used;        /**< Ever used for drawing? Used for debugging */
505 
506    struct nir_shader *nir;
507 
508    /* Saved and restored with metadata. Freed with ralloc. */
509    void *driver_cache_blob;
510    size_t driver_cache_blob_size;
511 
512    /** whether to skip VARYING_SLOT_PSIZ in st_translate_stream_output_info() */
513    bool skip_pointsize_xfb;
514 
515    /** A bitfield indicating which vertex shader inputs consume two slots
516     *
517     * This is used for mapping from single-slot input locations in the GL API
518     * to dual-slot double input locations in the shader.  This field is set
519     * once as part of linking and never updated again to ensure the mapping
520     * remains consistent.
521     *
522     * Note: There may be dual-slot variables in the original shader source
523     * which do not appear in this bitfield due to having been eliminated by
524     * the compiler prior to DualSlotInputs being calculated.  There may also
525     * be bits set in this bitfield which are set but which the shader never
526     * reads due to compiler optimizations eliminating such variables after
527     * DualSlotInputs is calculated.
528     */
529    GLbitfield64 DualSlotInputs;
530    /** Subset of OutputsWritten outputs written with non-zero index. */
531    GLbitfield64 SecondaryOutputsWritten;
532    /** TEXTURE_x_BIT bitmask */
533    GLbitfield16 TexturesUsed[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
534    /** Bitfield of which samplers are used */
535    GLbitfield SamplersUsed;
536    /** Texture units used for shadow sampling. */
537    GLbitfield ShadowSamplers;
538    /** Texture units used for samplerExternalOES */
539    GLbitfield ExternalSamplersUsed;
540 
541    /** Named parameters, constants, etc. from program text */
542    struct gl_program_parameter_list *Parameters;
543 
544    /** Map from sampler unit to texture unit (set by glUniform1i()) */
545    GLubyte SamplerUnits[MAX_SAMPLERS];
546 
547    struct pipe_shader_state state;
548    struct ati_fragment_shader *ati_fs;
549    uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */
550 
551    void *serialized_nir;
552    unsigned serialized_nir_size;
553 
554    struct gl_shader_program *shader_program;
555 
556    struct st_variant *variants;
557 
558    union {
559       /** Fields used by GLSL programs */
560       struct {
561          /** Data shared by gl_program and gl_shader_program */
562          struct gl_shader_program_data *data;
563 
564          struct gl_active_atomic_buffer **AtomicBuffers;
565 
566          /** Post-link transform feedback info. */
567          struct gl_transform_feedback_info *LinkedTransformFeedback;
568 
569          /**
570           * Number of types for subroutine uniforms.
571           */
572          GLuint NumSubroutineUniformTypes;
573 
574          /**
575           * Subroutine uniform remap table
576           * based on the program level uniform remap table.
577           */
578          GLuint NumSubroutineUniforms; /* non-sparse total */
579          GLuint NumSubroutineUniformRemapTable;
580          struct gl_uniform_storage **SubroutineUniformRemapTable;
581 
582          /**
583           * Num of subroutine functions for this stage and storage for them.
584           */
585          GLuint NumSubroutineFunctions;
586          GLuint MaxSubroutineFunctionIndex;
587          struct gl_subroutine_function *SubroutineFunctions;
588 
589          /**
590           * Map from image uniform index to image unit (set by glUniform1i())
591           *
592           * An image uniform index is associated with each image uniform by
593           * the linker.  The image index associated with each uniform is
594           * stored in the \c gl_uniform_storage::image field.
595           */
596          GLubyte ImageUnits[MAX_IMAGE_UNIFORMS];
597 
598          /** Access qualifier from linked shader
599           */
600          enum gl_access_qualifier image_access[MAX_IMAGE_UNIFORMS];
601 
602          GLuint NumUniformBlocks;
603          struct gl_uniform_block **UniformBlocks;
604          struct gl_uniform_block **ShaderStorageBlocks;
605 
606          /**
607           * Bitmask of shader storage blocks not declared as read-only.
608           */
609          unsigned ShaderStorageBlocksWriteAccess;
610 
611          /** Which texture target is being sampled
612           * (TEXTURE_1D/2D/3D/etc_INDEX)
613           */
614          GLubyte SamplerTargets[MAX_SAMPLERS];
615 
616          /**
617           * Number of samplers declared with the bindless_sampler layout
618           * qualifier as specified by ARB_bindless_texture.
619           */
620          GLuint NumBindlessSamplers;
621          GLboolean HasBoundBindlessSampler;
622          struct gl_bindless_sampler *BindlessSamplers;
623 
624          /**
625           * Number of images declared with the bindless_image layout qualifier
626           * as specified by ARB_bindless_texture.
627           */
628          GLuint NumBindlessImages;
629          GLboolean HasBoundBindlessImage;
630          struct gl_bindless_image *BindlessImages;
631       } sh;
632 
633       /** ARB assembly-style program fields */
634       struct {
635          struct prog_instruction *Instructions;
636 
637          /**
638           * Local parameters used by the program.
639           *
640           * It's dynamically allocated because it is rarely used (just
641           * assembly-style programs), and MAX_PROGRAM_LOCAL_PARAMS entries
642           * once it's allocated.
643           */
644          GLfloat (*LocalParams)[4];
645          unsigned MaxLocalParams;
646 
647          /** Bitmask of which register files are read/written with indirect
648           * addressing.  Mask of (1 << PROGRAM_x) bits.
649           */
650          GLbitfield IndirectRegisterFiles;
651 
652          /** Logical counts */
653          /*@{*/
654          GLuint NumInstructions;
655          GLuint NumTemporaries;
656          GLuint NumParameters;
657          GLuint NumAttributes;
658          GLuint NumAddressRegs;
659          GLuint NumAluInstructions;
660          GLuint NumTexInstructions;
661          GLuint NumTexIndirections;
662          /*@}*/
663          /** Native, actual h/w counts */
664          /*@{*/
665          GLuint NumNativeInstructions;
666          GLuint NumNativeTemporaries;
667          GLuint NumNativeParameters;
668          GLuint NumNativeAttributes;
669          GLuint NumNativeAddressRegs;
670          GLuint NumNativeAluInstructions;
671          GLuint NumNativeTexInstructions;
672          GLuint NumNativeTexIndirections;
673          /*@}*/
674 
675          /** Used by ARB assembly-style programs. Can only be true for vertex
676           * programs.
677           */
678          GLboolean IsPositionInvariant;
679 
680          /** Used by ARB_fp programs, enum gl_fog_mode */
681          unsigned Fog;
682       } arb;
683    };
684 };
685 
686 /*
687  * State/IR translators needs to store some extra vp info.
688  */
689 struct gl_vertex_program
690 {
691    struct gl_program Base;
692 
693    uint32_t vert_attrib_mask; /**< mask of sourced vertex attribs */
694    uint8_t num_inputs;
695 
696    /** Maps VARYING_SLOT_x to slot */
697    uint8_t result_to_output[VARYING_SLOT_MAX];
698 };
699 
700 /**
701  * Structure that represents a reference to an atomic buffer from some
702  * shader program.
703  */
704 struct gl_active_atomic_buffer
705 {
706    /** Uniform indices of the atomic counters declared within it. */
707    GLuint *Uniforms;
708    GLuint NumUniforms;
709 
710    /** Binding point index associated with it. */
711    GLuint Binding;
712 
713    /** Minimum reasonable size it is expected to have. */
714    GLuint MinimumSize;
715 
716    /** Shader stages making use of it. */
717    GLboolean StageReferences[MESA_SHADER_STAGES];
718 };
719 
720 struct gl_transform_feedback_varying_info
721 {
722    struct gl_resource_name name;
723    GLenum16 Type;
724    GLint BufferIndex;
725    GLint Size;
726    GLint Offset;
727 };
728 
729 
730 /**
731  * Per-output info vertex shaders for transform feedback.
732  */
733 struct gl_transform_feedback_output
734 {
735    uint32_t OutputRegister;
736    uint32_t OutputBuffer;
737    uint32_t NumComponents;
738    uint32_t StreamId;
739 
740    /** offset (in DWORDs) of this output within the interleaved structure */
741    uint32_t DstOffset;
742 
743    /**
744     * Offset into the output register of the data to output.  For example,
745     * if NumComponents is 2 and ComponentOffset is 1, then the data to
746     * offset is in the y and z components of the output register.
747     */
748    uint32_t ComponentOffset;
749 };
750 
751 
752 struct gl_transform_feedback_buffer
753 {
754    uint32_t Binding;
755 
756    uint32_t NumVaryings;
757 
758    /**
759     * Total number of components stored in each buffer.  This may be used by
760     * hardware back-ends to determine the correct stride when interleaving
761     * multiple transform feedback outputs in the same buffer.
762     */
763    uint32_t Stride;
764 
765    /**
766     * Which transform feedback stream this buffer binding is associated with.
767     */
768    uint32_t Stream;
769 };
770 
771 
772 /** Post-link transform feedback info. */
773 struct gl_transform_feedback_info
774 {
775    unsigned NumOutputs;
776 
777    /* Bitmask of active buffer indices. */
778    unsigned ActiveBuffers;
779 
780    struct gl_transform_feedback_output *Outputs;
781 
782    /** Transform feedback varyings used for the linking of this shader program.
783     *
784     * Use for glGetTransformFeedbackVarying().
785     */
786    struct gl_transform_feedback_varying_info *Varyings;
787    GLint NumVarying;
788 
789    struct gl_transform_feedback_buffer Buffers[MAX_FEEDBACK_BUFFERS];
790 };
791 
792 /**
793  *  Shader subroutine function definition
794  */
795 struct gl_subroutine_function
796 {
797    struct gl_resource_name name;
798    int index;
799    int num_compat_types;
800    const struct glsl_type **types;
801 };
802 
803 /**
804  * Active resource in a gl_shader_program
805  */
806 struct gl_program_resource
807 {
808    GLenum16 Type; /** Program interface type. */
809    const void *Data; /** Pointer to resource associated data structure. */
810    uint8_t StageReferences; /** Bitmask of shader stage references. */
811 };
812 
813 struct gl_uniform_buffer_variable
814 {
815    char *Name;
816 
817    /**
818     * Name of the uniform as seen by glGetUniformIndices.
819     *
820     * glGetUniformIndices requires that the block instance index \b not be
821     * present in the name of queried uniforms.
822     *
823     * \note
824     * \c gl_uniform_buffer_variable::IndexName and
825     * \c gl_uniform_buffer_variable::Name may point to identical storage.
826     */
827    char *IndexName;
828 
829    const struct glsl_type *Type;
830    unsigned int Offset;
831    GLboolean RowMajor;
832 };
833 
834 
835 struct gl_uniform_block
836 {
837    /** Declared name of the uniform block */
838    struct gl_resource_name name;
839 
840    /** Array of supplemental information about UBO ir_variables. */
841    struct gl_uniform_buffer_variable *Uniforms;
842    GLuint NumUniforms;
843 
844    /**
845     * Index (GL_UNIFORM_BLOCK_BINDING) into ctx->UniformBufferBindings[] to use
846     * with glBindBufferBase to bind a buffer object to this uniform block.
847     */
848    GLuint Binding;
849 
850    /**
851     * Minimum size (in bytes) of a buffer object to back this uniform buffer
852     * (GL_UNIFORM_BLOCK_DATA_SIZE).
853     */
854    GLuint UniformBufferSize;
855 
856    /** Stages that reference this block */
857    uint8_t stageref;
858 
859    /**
860     * Linearized array index for uniform block instance arrays
861     *
862     * Given a uniform block instance array declared with size
863     * blk[s_0][s_1]..[s_m], the block referenced by blk[i_0][i_1]..[i_m] will
864     * have the linearized array index
865     *
866     *           m-1       m
867     *     i_m + ∑   i_j * ∏     s_k
868     *           j=0       k=j+1
869     *
870     * For a uniform block instance that is not an array, this is always 0.
871     */
872    uint8_t linearized_array_index;
873 
874    /**
875     * Layout specified in the shader
876     *
877     * This isn't accessible through the API, but it is used while
878     * cross-validating uniform blocks.
879     */
880    enum glsl_interface_packing _Packing;
881    GLboolean _RowMajor;
882 };
883 
884 /**
885  * A bindless sampler object.
886  */
887 struct gl_bindless_sampler
888 {
889    /** Texture unit (set by glUniform1()). */
890    GLubyte unit;
891 
892    /** Whether this bindless sampler is bound to a unit. */
893    GLboolean bound;
894 
895    /** Texture Target (TEXTURE_1D/2D/3D/etc_INDEX). */
896    gl_texture_index target;
897 
898    /** Pointer to the base of the data. */
899    GLvoid *data;
900 };
901 
902 
903 /**
904  * A bindless image object.
905  */
906 struct gl_bindless_image
907 {
908    /** Image unit (set by glUniform1()). */
909    GLubyte unit;
910 
911    /** Whether this bindless image is bound to a unit. */
912    GLboolean bound;
913 
914    /** Access qualifier from linked shader
915     */
916    enum gl_access_qualifier image_access;
917 
918    /** Pointer to the base of the data. */
919    GLvoid *data;
920 };
921 
922 /**
923  * Data container for shader queries. This holds only the minimal
924  * amount of required information for resource queries to work.
925  */
926 struct gl_shader_variable
927 {
928    /**
929     * Declared type of the variable
930     */
931    const struct glsl_type *type;
932 
933    /**
934     * If the variable is in an interface block, this is the type of the block.
935     */
936    const struct glsl_type *interface_type;
937 
938    /**
939     * For variables inside structs (possibly recursively), this is the
940     * outermost struct type.
941     */
942    const struct glsl_type *outermost_struct_type;
943 
944    /**
945     * Declared name of the variable
946     */
947    struct gl_resource_name name;
948 
949    /**
950     * Storage location of the base of this variable
951     *
952     * The precise meaning of this field depends on the nature of the variable.
953     *
954     *   - Vertex shader input: one of the values from \c gl_vert_attrib.
955     *   - Vertex shader output: one of the values from \c gl_varying_slot.
956     *   - Geometry shader input: one of the values from \c gl_varying_slot.
957     *   - Geometry shader output: one of the values from \c gl_varying_slot.
958     *   - Fragment shader input: one of the values from \c gl_varying_slot.
959     *   - Fragment shader output: one of the values from \c gl_frag_result.
960     *   - Uniforms: Per-stage uniform slot number for default uniform block.
961     *   - Uniforms: Index within the uniform block definition for UBO members.
962     *   - Non-UBO Uniforms: explicit location until linking then reused to
963     *     store uniform slot number.
964     *   - Other: This field is not currently used.
965     *
966     * If the variable is a uniform, shader input, or shader output, and the
967     * slot has not been assigned, the value will be -1.
968     */
969    int location;
970 
971    /**
972     * Specifies the first component the variable is stored in as per
973     * ARB_enhanced_layouts.
974     */
975    unsigned component:2;
976 
977    /**
978     * Output index for dual source blending.
979     *
980     * \note
981     * The GLSL spec only allows the values 0 or 1 for the index in \b dual
982     * source blending.
983     */
984    unsigned index:1;
985 
986    /**
987     * Specifies whether a shader input/output is per-patch in tessellation
988     * shader stages.
989     */
990    unsigned patch:1;
991 
992    /**
993     * Storage class of the variable.
994     *
995     * \sa (n)ir_variable_mode
996     */
997    unsigned mode:4;
998 
999    /**
1000     * Interpolation mode for shader inputs / outputs
1001     *
1002     * \sa glsl_interp_mode
1003     */
1004    unsigned interpolation:2;
1005 
1006    /**
1007     * Was the location explicitly set in the shader?
1008     *
1009     * If the location is explicitly set in the shader, it \b cannot be changed
1010     * by the linker or by the API (e.g., calls to \c glBindAttribLocation have
1011     * no effect).
1012     */
1013    unsigned explicit_location:1;
1014 
1015    /**
1016     * Precision qualifier.
1017     */
1018    unsigned precision:2;
1019 };
1020 
1021 #endif
1022