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