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 "main/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 shader_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 shader_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 unsigned Version; /**< GLSL version used for linking */ 349 350 /* Mask of stages this program was linked against */ 351 unsigned linked_stages; 352 353 /* Whether the shaders of this program are loaded from SPIR-V binaries 354 * (all have the SPIR_V_BINARY_ARB state). This was introduced by the 355 * ARB_gl_spirv extension. 356 */ 357 bool spirv; 358 }; 359 360 /** 361 * A GLSL program object. 362 * Basically a linked collection of vertex and fragment shaders. 363 */ 364 struct gl_shader_program 365 { 366 GLenum16 Type; /**< Always GL_SHADER_PROGRAM (internal token) */ 367 GLuint Name; /**< aka handle or ID */ 368 GLchar *Label; /**< GL_KHR_debug */ 369 GLint RefCount; /**< Reference count */ 370 GLboolean DeletePending; 371 372 /** 373 * Is the application intending to glGetProgramBinary this program? 374 * 375 * BinaryRetrievableHint is the currently active hint that gets set 376 * during initialization and after linking and BinaryRetrievableHintPending 377 * is the hint set by the user to be active when program is linked next time. 378 */ 379 GLboolean BinaryRetrievableHint; 380 GLboolean BinaryRetrievableHintPending; 381 382 /** 383 * Indicates whether program can be bound for individual pipeline stages 384 * using UseProgramStages after it is next linked. 385 */ 386 GLboolean SeparateShader; 387 388 GLuint NumShaders; /**< number of attached shaders */ 389 struct gl_shader **Shaders; /**< List of attached the shaders */ 390 391 /** 392 * User-defined attribute bindings 393 * 394 * These are set via \c glBindAttribLocation and are used to direct the 395 * GLSL linker. These are \b not the values used in the compiled shader, 396 * and they are \b not the values returned by \c glGetAttribLocation. 397 */ 398 struct string_to_uint_map *AttributeBindings; 399 400 /** 401 * User-defined fragment data bindings 402 * 403 * These are set via \c glBindFragDataLocation and are used to direct the 404 * GLSL linker. These are \b not the values used in the compiled shader, 405 * and they are \b not the values returned by \c glGetFragDataLocation. 406 */ 407 struct string_to_uint_map *FragDataBindings; 408 struct string_to_uint_map *FragDataIndexBindings; 409 410 /** 411 * Transform feedback varyings last specified by 412 * glTransformFeedbackVaryings(). 413 * 414 * For the current set of transform feedback varyings used for transform 415 * feedback output, see LinkedTransformFeedback. 416 */ 417 struct { 418 GLenum16 BufferMode; 419 /** Global xfb_stride out qualifier if any */ 420 GLuint BufferStride[MAX_FEEDBACK_BUFFERS]; 421 GLuint NumVarying; 422 GLchar **VaryingNames; /**< Array [NumVarying] of char * */ 423 } TransformFeedback; 424 425 struct gl_program *last_vert_prog; 426 427 /** Post-link gl_FragDepth layout for ARB_conservative_depth. */ 428 enum gl_frag_depth_layout FragDepthLayout; 429 430 /** 431 * Geometry shader state - copied into gl_program by 432 * _mesa_copy_linked_program_data(). 433 */ 434 struct { 435 GLint VerticesIn; 436 437 bool UsesEndPrimitive; 438 unsigned ActiveStreamMask; 439 } Geom; 440 441 /** Data shared by gl_program and gl_shader_program */ 442 struct gl_shader_program_data *data; 443 444 /** 445 * Mapping from GL uniform locations returned by \c glUniformLocation to 446 * UniformStorage entries. Arrays will have multiple contiguous slots 447 * in the UniformRemapTable, all pointing to the same UniformStorage entry. 448 */ 449 unsigned NumUniformRemapTable; 450 struct gl_uniform_storage **UniformRemapTable; 451 452 /** 453 * Sometimes there are empty slots left over in UniformRemapTable after we 454 * allocate slots to explicit locations. This list stores the blocks of 455 * continuous empty slots inside UniformRemapTable. 456 */ 457 struct exec_list EmptyUniformLocations; 458 459 /** 460 * Total number of explicit uniform location including inactive uniforms. 461 */ 462 unsigned NumExplicitUniformLocations; 463 464 /** 465 * Map of active uniform names to locations 466 * 467 * Maps any active uniform that is not an array element to a location. 468 * Each active uniform, including individual structure members will appear 469 * in this map. This roughly corresponds to the set of names that would be 470 * enumerated by \c glGetActiveUniform. 471 */ 472 struct string_to_uint_map *UniformHash; 473 474 GLboolean SamplersValidated; /**< Samplers validated against texture units? */ 475 476 bool IsES; /**< True if this program uses GLSL ES */ 477 478 /** 479 * Per-stage shaders resulting from the first stage of linking. 480 * 481 * Set of linked shaders for this program. The array is accessed using the 482 * \c MESA_SHADER_* defines. Entries for non-existent stages will be 483 * \c NULL. 484 */ 485 struct gl_linked_shader *_LinkedShaders[MESA_SHADER_STAGES]; 486 487 /** 488 * True if any of the fragment shaders attached to this program use: 489 * #extension ARB_fragment_coord_conventions: enable 490 */ 491 GLboolean ARB_fragment_coord_conventions_enable; 492 }; 493 494 /** 495 * Base class for any kind of program object 496 */ 497 struct gl_program 498 { 499 /** FIXME: This must be first until we split shader_info from nir_shader */ 500 struct shader_info info; 501 502 GLuint Id; 503 GLint RefCount; 504 GLubyte *String; /**< Null-terminated program text */ 505 506 /** GL_VERTEX/FRAGMENT_PROGRAM_ARB, GL_GEOMETRY_PROGRAM_NV */ 507 GLenum16 Target; 508 GLenum16 Format; /**< String encoding format */ 509 510 GLboolean _Used; /**< Ever used for drawing? Used for debugging */ 511 512 struct nir_shader *nir; 513 514 /* Saved and restored with metadata. Freed with ralloc. */ 515 void *driver_cache_blob; 516 size_t driver_cache_blob_size; 517 518 /** Is this program written to on disk shader cache */ 519 bool program_written_to_cache; 520 521 /** whether to skip VARYING_SLOT_PSIZ in st_translate_stream_output_info() */ 522 bool skip_pointsize_xfb; 523 524 /** A bitfield indicating which vertex shader inputs consume two slots 525 * 526 * This is used for mapping from single-slot input locations in the GL API 527 * to dual-slot double input locations in the shader. This field is set 528 * once as part of linking and never updated again to ensure the mapping 529 * remains consistent. 530 * 531 * Note: There may be dual-slot variables in the original shader source 532 * which do not appear in this bitfield due to having been eliminated by 533 * the compiler prior to DualSlotInputs being calculated. There may also 534 * be bits set in this bitfield which are set but which the shader never 535 * reads due to compiler optimizations eliminating such variables after 536 * DualSlotInputs is calculated. 537 */ 538 GLbitfield64 DualSlotInputs; 539 /** Subset of OutputsWritten outputs written with non-zero index. */ 540 GLbitfield64 SecondaryOutputsWritten; 541 /** TEXTURE_x_BIT bitmask */ 542 GLbitfield16 TexturesUsed[MAX_COMBINED_TEXTURE_IMAGE_UNITS]; 543 /** Bitfield of which samplers are used */ 544 GLbitfield SamplersUsed; 545 /** Texture units used for shadow sampling. */ 546 GLbitfield ShadowSamplers; 547 /** Texture units used for samplerExternalOES */ 548 GLbitfield ExternalSamplersUsed; 549 550 /** Named parameters, constants, etc. from program text */ 551 struct gl_program_parameter_list *Parameters; 552 553 /** Map from sampler unit to texture unit (set by glUniform1i()) */ 554 GLubyte SamplerUnits[MAX_SAMPLERS]; 555 556 struct pipe_shader_state state; 557 struct ati_fragment_shader *ati_fs; 558 uint64_t affected_states; /**< ST_NEW_* flags to mark dirty when binding */ 559 560 void *serialized_nir; 561 unsigned serialized_nir_size; 562 563 struct gl_shader_program *shader_program; 564 565 struct st_variant *variants; 566 567 union { 568 /** Fields used by GLSL programs */ 569 struct { 570 /** Data shared by gl_program and gl_shader_program */ 571 struct gl_shader_program_data *data; 572 573 struct gl_active_atomic_buffer **AtomicBuffers; 574 575 /** Post-link transform feedback info. */ 576 struct gl_transform_feedback_info *LinkedTransformFeedback; 577 578 /** 579 * Number of types for subroutine uniforms. 580 */ 581 GLuint NumSubroutineUniformTypes; 582 583 /** 584 * Subroutine uniform remap table 585 * based on the program level uniform remap table. 586 */ 587 GLuint NumSubroutineUniforms; /* non-sparse total */ 588 GLuint NumSubroutineUniformRemapTable; 589 struct gl_uniform_storage **SubroutineUniformRemapTable; 590 591 /** 592 * Num of subroutine functions for this stage and storage for them. 593 */ 594 GLuint NumSubroutineFunctions; 595 GLuint MaxSubroutineFunctionIndex; 596 struct gl_subroutine_function *SubroutineFunctions; 597 598 /** 599 * Map from image uniform index to image unit (set by glUniform1i()) 600 * 601 * An image uniform index is associated with each image uniform by 602 * the linker. The image index associated with each uniform is 603 * stored in the \c gl_uniform_storage::image field. 604 */ 605 GLubyte ImageUnits[MAX_IMAGE_UNIFORMS]; 606 607 /** 608 * Access qualifier specified in the shader for each image uniform 609 * index. Either \c GL_READ_ONLY, \c GL_WRITE_ONLY, \c 610 * GL_READ_WRITE, or \c GL_NONE to indicate both read-only and 611 * write-only. 612 * 613 * It may be different, though only more strict than the value of 614 * \c gl_image_unit::Access for the corresponding image unit. 615 */ 616 GLenum16 ImageAccess[MAX_IMAGE_UNIFORMS]; 617 618 GLuint NumUniformBlocks; 619 struct gl_uniform_block **UniformBlocks; 620 struct gl_uniform_block **ShaderStorageBlocks; 621 622 /** 623 * Bitmask of shader storage blocks not declared as read-only. 624 */ 625 unsigned ShaderStorageBlocksWriteAccess; 626 627 /** Which texture target is being sampled 628 * (TEXTURE_1D/2D/3D/etc_INDEX) 629 */ 630 GLubyte SamplerTargets[MAX_SAMPLERS]; 631 632 /** 633 * Number of samplers declared with the bindless_sampler layout 634 * qualifier as specified by ARB_bindless_texture. 635 */ 636 GLuint NumBindlessSamplers; 637 GLboolean HasBoundBindlessSampler; 638 struct gl_bindless_sampler *BindlessSamplers; 639 640 /** 641 * Number of images declared with the bindless_image layout qualifier 642 * as specified by ARB_bindless_texture. 643 */ 644 GLuint NumBindlessImages; 645 GLboolean HasBoundBindlessImage; 646 struct gl_bindless_image *BindlessImages; 647 } sh; 648 649 /** ARB assembly-style program fields */ 650 struct { 651 struct prog_instruction *Instructions; 652 653 /** 654 * Local parameters used by the program. 655 * 656 * It's dynamically allocated because it is rarely used (just 657 * assembly-style programs), and MAX_PROGRAM_LOCAL_PARAMS entries 658 * once it's allocated. 659 */ 660 GLfloat (*LocalParams)[4]; 661 unsigned MaxLocalParams; 662 663 /** Bitmask of which register files are read/written with indirect 664 * addressing. Mask of (1 << PROGRAM_x) bits. 665 */ 666 GLbitfield IndirectRegisterFiles; 667 668 /** Logical counts */ 669 /*@{*/ 670 GLuint NumInstructions; 671 GLuint NumTemporaries; 672 GLuint NumParameters; 673 GLuint NumAttributes; 674 GLuint NumAddressRegs; 675 GLuint NumAluInstructions; 676 GLuint NumTexInstructions; 677 GLuint NumTexIndirections; 678 /*@}*/ 679 /** Native, actual h/w counts */ 680 /*@{*/ 681 GLuint NumNativeInstructions; 682 GLuint NumNativeTemporaries; 683 GLuint NumNativeParameters; 684 GLuint NumNativeAttributes; 685 GLuint NumNativeAddressRegs; 686 GLuint NumNativeAluInstructions; 687 GLuint NumNativeTexInstructions; 688 GLuint NumNativeTexIndirections; 689 /*@}*/ 690 691 /** Used by ARB assembly-style programs. Can only be true for vertex 692 * programs. 693 */ 694 GLboolean IsPositionInvariant; 695 } arb; 696 }; 697 }; 698 699 /* 700 * State/IR translators needs to store some extra vp info. 701 */ 702 struct gl_vertex_program 703 { 704 struct gl_program Base; 705 706 uint32_t vert_attrib_mask; /**< mask of sourced vertex attribs */ 707 ubyte num_inputs; 708 709 /** Maps VARYING_SLOT_x to slot */ 710 ubyte result_to_output[VARYING_SLOT_MAX]; 711 }; 712 713 /** 714 * Structure that represents a reference to an atomic buffer from some 715 * shader program. 716 */ 717 struct gl_active_atomic_buffer 718 { 719 /** Uniform indices of the atomic counters declared within it. */ 720 GLuint *Uniforms; 721 GLuint NumUniforms; 722 723 /** Binding point index associated with it. */ 724 GLuint Binding; 725 726 /** Minimum reasonable size it is expected to have. */ 727 GLuint MinimumSize; 728 729 /** Shader stages making use of it. */ 730 GLboolean StageReferences[MESA_SHADER_STAGES]; 731 }; 732 733 struct gl_transform_feedback_varying_info 734 { 735 struct gl_resource_name name; 736 GLenum16 Type; 737 GLint BufferIndex; 738 GLint Size; 739 GLint Offset; 740 }; 741 742 743 /** 744 * Per-output info vertex shaders for transform feedback. 745 */ 746 struct gl_transform_feedback_output 747 { 748 uint32_t OutputRegister; 749 uint32_t OutputBuffer; 750 uint32_t NumComponents; 751 uint32_t StreamId; 752 753 /** offset (in DWORDs) of this output within the interleaved structure */ 754 uint32_t DstOffset; 755 756 /** 757 * Offset into the output register of the data to output. For example, 758 * if NumComponents is 2 and ComponentOffset is 1, then the data to 759 * offset is in the y and z components of the output register. 760 */ 761 uint32_t ComponentOffset; 762 }; 763 764 765 struct gl_transform_feedback_buffer 766 { 767 uint32_t Binding; 768 769 uint32_t NumVaryings; 770 771 /** 772 * Total number of components stored in each buffer. This may be used by 773 * hardware back-ends to determine the correct stride when interleaving 774 * multiple transform feedback outputs in the same buffer. 775 */ 776 uint32_t Stride; 777 778 /** 779 * Which transform feedback stream this buffer binding is associated with. 780 */ 781 uint32_t Stream; 782 }; 783 784 785 /** Post-link transform feedback info. */ 786 struct gl_transform_feedback_info 787 { 788 unsigned NumOutputs; 789 790 /* Bitmask of active buffer indices. */ 791 unsigned ActiveBuffers; 792 793 struct gl_transform_feedback_output *Outputs; 794 795 /** Transform feedback varyings used for the linking of this shader program. 796 * 797 * Use for glGetTransformFeedbackVarying(). 798 */ 799 struct gl_transform_feedback_varying_info *Varyings; 800 GLint NumVarying; 801 802 struct gl_transform_feedback_buffer Buffers[MAX_FEEDBACK_BUFFERS]; 803 }; 804 805 /** 806 * Shader subroutine function definition 807 */ 808 struct gl_subroutine_function 809 { 810 struct gl_resource_name name; 811 int index; 812 int num_compat_types; 813 const struct glsl_type **types; 814 }; 815 816 /** 817 * Active resource in a gl_shader_program 818 */ 819 struct gl_program_resource 820 { 821 GLenum16 Type; /** Program interface type. */ 822 const void *Data; /** Pointer to resource associated data structure. */ 823 uint8_t StageReferences; /** Bitmask of shader stage references. */ 824 }; 825 826 struct gl_uniform_buffer_variable 827 { 828 char *Name; 829 830 /** 831 * Name of the uniform as seen by glGetUniformIndices. 832 * 833 * glGetUniformIndices requires that the block instance index \b not be 834 * present in the name of queried uniforms. 835 * 836 * \note 837 * \c gl_uniform_buffer_variable::IndexName and 838 * \c gl_uniform_buffer_variable::Name may point to identical storage. 839 */ 840 char *IndexName; 841 842 const struct glsl_type *Type; 843 unsigned int Offset; 844 GLboolean RowMajor; 845 }; 846 847 848 struct gl_uniform_block 849 { 850 /** Declared name of the uniform block */ 851 struct gl_resource_name name; 852 853 /** Array of supplemental information about UBO ir_variables. */ 854 struct gl_uniform_buffer_variable *Uniforms; 855 GLuint NumUniforms; 856 857 /** 858 * Index (GL_UNIFORM_BLOCK_BINDING) into ctx->UniformBufferBindings[] to use 859 * with glBindBufferBase to bind a buffer object to this uniform block. 860 */ 861 GLuint Binding; 862 863 /** 864 * Minimum size (in bytes) of a buffer object to back this uniform buffer 865 * (GL_UNIFORM_BLOCK_DATA_SIZE). 866 */ 867 GLuint UniformBufferSize; 868 869 /** Stages that reference this block */ 870 uint8_t stageref; 871 872 /** 873 * Linearized array index for uniform block instance arrays 874 * 875 * Given a uniform block instance array declared with size 876 * blk[s_0][s_1]..[s_m], the block referenced by blk[i_0][i_1]..[i_m] will 877 * have the linearized array index 878 * 879 * m-1 m 880 * i_m + ∑ i_j * ∏ s_k 881 * j=0 k=j+1 882 * 883 * For a uniform block instance that is not an array, this is always 0. 884 */ 885 uint8_t linearized_array_index; 886 887 /** 888 * Layout specified in the shader 889 * 890 * This isn't accessible through the API, but it is used while 891 * cross-validating uniform blocks. 892 */ 893 enum glsl_interface_packing _Packing; 894 GLboolean _RowMajor; 895 }; 896 897 /** 898 * A bindless sampler object. 899 */ 900 struct gl_bindless_sampler 901 { 902 /** Texture unit (set by glUniform1()). */ 903 GLubyte unit; 904 905 /** Whether this bindless sampler is bound to a unit. */ 906 GLboolean bound; 907 908 /** Texture Target (TEXTURE_1D/2D/3D/etc_INDEX). */ 909 gl_texture_index target; 910 911 /** Pointer to the base of the data. */ 912 GLvoid *data; 913 }; 914 915 916 /** 917 * A bindless image object. 918 */ 919 struct gl_bindless_image 920 { 921 /** Image unit (set by glUniform1()). */ 922 GLubyte unit; 923 924 /** Whether this bindless image is bound to a unit. */ 925 GLboolean bound; 926 927 /** Access qualifier (GL_READ_WRITE, GL_READ_ONLY, GL_WRITE_ONLY, or 928 * GL_NONE to indicate both read-only and write-only) 929 */ 930 GLenum16 access; 931 932 /** Pointer to the base of the data. */ 933 GLvoid *data; 934 }; 935 936 /** 937 * Data container for shader queries. This holds only the minimal 938 * amount of required information for resource queries to work. 939 */ 940 struct gl_shader_variable 941 { 942 /** 943 * Declared type of the variable 944 */ 945 const struct glsl_type *type; 946 947 /** 948 * If the variable is in an interface block, this is the type of the block. 949 */ 950 const struct glsl_type *interface_type; 951 952 /** 953 * For variables inside structs (possibly recursively), this is the 954 * outermost struct type. 955 */ 956 const struct glsl_type *outermost_struct_type; 957 958 /** 959 * Declared name of the variable 960 */ 961 struct gl_resource_name name; 962 963 /** 964 * Storage location of the base of this variable 965 * 966 * The precise meaning of this field depends on the nature of the variable. 967 * 968 * - Vertex shader input: one of the values from \c gl_vert_attrib. 969 * - Vertex shader output: one of the values from \c gl_varying_slot. 970 * - Geometry shader input: one of the values from \c gl_varying_slot. 971 * - Geometry shader output: one of the values from \c gl_varying_slot. 972 * - Fragment shader input: one of the values from \c gl_varying_slot. 973 * - Fragment shader output: one of the values from \c gl_frag_result. 974 * - Uniforms: Per-stage uniform slot number for default uniform block. 975 * - Uniforms: Index within the uniform block definition for UBO members. 976 * - Non-UBO Uniforms: explicit location until linking then reused to 977 * store uniform slot number. 978 * - Other: This field is not currently used. 979 * 980 * If the variable is a uniform, shader input, or shader output, and the 981 * slot has not been assigned, the value will be -1. 982 */ 983 int location; 984 985 /** 986 * Specifies the first component the variable is stored in as per 987 * ARB_enhanced_layouts. 988 */ 989 unsigned component:2; 990 991 /** 992 * Output index for dual source blending. 993 * 994 * \note 995 * The GLSL spec only allows the values 0 or 1 for the index in \b dual 996 * source blending. 997 */ 998 unsigned index:1; 999 1000 /** 1001 * Specifies whether a shader input/output is per-patch in tessellation 1002 * shader stages. 1003 */ 1004 unsigned patch:1; 1005 1006 /** 1007 * Storage class of the variable. 1008 * 1009 * \sa (n)ir_variable_mode 1010 */ 1011 unsigned mode:4; 1012 1013 /** 1014 * Interpolation mode for shader inputs / outputs 1015 * 1016 * \sa glsl_interp_mode 1017 */ 1018 unsigned interpolation:2; 1019 1020 /** 1021 * Was the location explicitly set in the shader? 1022 * 1023 * If the location is explicitly set in the shader, it \b cannot be changed 1024 * by the linker or by the API (e.g., calls to \c glBindAttribLocation have 1025 * no effect). 1026 */ 1027 unsigned explicit_location:1; 1028 1029 /** 1030 * Precision qualifier. 1031 */ 1032 unsigned precision:2; 1033 }; 1034 1035 #endif 1036