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