2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * \file shader_query.cpp
26 * C-to-C++ bridge functions to query GLSL shader data
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "main/context.h"
32 #include "main/core.h"
33 #include "main/enums.h"
34 #include "main/shaderapi.h"
35 #include "main/shaderobj.h"
36 #include "main/uniforms.h"
37 #include "compiler/glsl/glsl_symbol_table.h"
38 #include "compiler/glsl/ir.h"
39 #include "compiler/glsl/program.h"
40 #include "program/hash_table.h"
41 #include "util/strndup.h"
45 program_resource_location(struct gl_shader_program
*shProg
,
46 struct gl_program_resource
*res
, const char *name
,
47 unsigned array_index
);
50 * Declare convenience functions to return resource data in a given type.
51 * Warning! this is not type safe so be *very* careful when using these.
53 #define DECL_RESOURCE_FUNC(name, type) \
54 const type * RESOURCE_ ## name (gl_program_resource *res) { \
56 return (type *) res->Data; \
59 DECL_RESOURCE_FUNC(VAR
, gl_shader_variable
);
60 DECL_RESOURCE_FUNC(UBO
, gl_uniform_block
);
61 DECL_RESOURCE_FUNC(UNI
, gl_uniform_storage
);
62 DECL_RESOURCE_FUNC(ATC
, gl_active_atomic_buffer
);
63 DECL_RESOURCE_FUNC(XFV
, gl_transform_feedback_varying_info
);
64 DECL_RESOURCE_FUNC(XFB
, gl_transform_feedback_buffer
);
65 DECL_RESOURCE_FUNC(SUB
, gl_subroutine_function
);
68 _mesa_BindAttribLocation(GLuint program
, GLuint index
,
71 GET_CURRENT_CONTEXT(ctx
);
73 struct gl_shader_program
*const shProg
=
74 _mesa_lookup_shader_program_err(ctx
, program
, "glBindAttribLocation");
81 if (strncmp(name
, "gl_", 3) == 0) {
82 _mesa_error(ctx
, GL_INVALID_OPERATION
,
83 "glBindAttribLocation(illegal name)");
87 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
88 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindAttribLocation(index)");
92 /* Replace the current value if it's already in the list. Add
93 * VERT_ATTRIB_GENERIC0 because that's how the linker differentiates
94 * between built-in attributes and user-defined attributes.
96 shProg
->AttributeBindings
->put(index
+ VERT_ATTRIB_GENERIC0
, name
);
99 * Note that this attribute binding won't go into effect until
100 * glLinkProgram is called again.
105 _mesa_GetActiveAttrib(GLuint program
, GLuint desired_index
,
106 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
107 GLenum
* type
, GLchar
* name
)
109 GET_CURRENT_CONTEXT(ctx
);
110 struct gl_shader_program
*shProg
;
113 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(maxLength < 0)");
117 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveAttrib");
121 if (!shProg
->LinkStatus
) {
122 _mesa_error(ctx
, GL_INVALID_VALUE
,
123 "glGetActiveAttrib(program not linked)");
127 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
128 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(no vertex shader)");
132 struct gl_program_resource
*res
=
133 _mesa_program_resource_find_index(shProg
, GL_PROGRAM_INPUT
,
136 /* User asked for index that does not exist. */
138 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(index)");
142 const gl_shader_variable
*const var
= RESOURCE_VAR(res
);
144 const char *var_name
= var
->name
;
146 _mesa_copy_string(name
, maxLength
, length
, var_name
);
149 _mesa_program_resource_prop(shProg
, res
, desired_index
, GL_ARRAY_SIZE
,
150 size
, "glGetActiveAttrib");
153 _mesa_program_resource_prop(shProg
, res
, desired_index
, GL_TYPE
,
154 (GLint
*) type
, "glGetActiveAttrib");
158 _mesa_GetAttribLocation(GLuint program
, const GLchar
* name
)
160 GET_CURRENT_CONTEXT(ctx
);
161 struct gl_shader_program
*const shProg
=
162 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttribLocation");
168 if (!shProg
->LinkStatus
) {
169 _mesa_error(ctx
, GL_INVALID_OPERATION
,
170 "glGetAttribLocation(program not linked)");
177 /* Not having a vertex shader is not an error.
179 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
)
182 unsigned array_index
= 0;
183 struct gl_program_resource
*res
=
184 _mesa_program_resource_find_name(shProg
, GL_PROGRAM_INPUT
, name
,
190 return program_resource_location(shProg
, res
, name
, array_index
);
194 _mesa_count_active_attribs(struct gl_shader_program
*shProg
)
196 if (!shProg
->LinkStatus
197 || shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
201 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
203 for (unsigned j
= 0; j
< shProg
->NumProgramResourceList
; j
++, res
++) {
204 if (res
->Type
== GL_PROGRAM_INPUT
&&
205 res
->StageReferences
& (1 << MESA_SHADER_VERTEX
))
213 _mesa_longest_attribute_name_length(struct gl_shader_program
*shProg
)
215 if (!shProg
->LinkStatus
216 || shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
220 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
222 for (unsigned j
= 0; j
< shProg
->NumProgramResourceList
; j
++, res
++) {
223 if (res
->Type
== GL_PROGRAM_INPUT
&&
224 res
->StageReferences
& (1 << MESA_SHADER_VERTEX
)) {
226 const size_t length
= strlen(RESOURCE_VAR(res
)->name
);
227 if (length
>= longest
)
228 longest
= length
+ 1;
236 _mesa_BindFragDataLocation(GLuint program
, GLuint colorNumber
,
239 _mesa_BindFragDataLocationIndexed(program
, colorNumber
, 0, name
);
243 _mesa_BindFragDataLocationIndexed(GLuint program
, GLuint colorNumber
,
244 GLuint index
, const GLchar
*name
)
246 GET_CURRENT_CONTEXT(ctx
);
248 struct gl_shader_program
*const shProg
=
249 _mesa_lookup_shader_program_err(ctx
, program
, "glBindFragDataLocationIndexed");
256 if (strncmp(name
, "gl_", 3) == 0) {
257 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFragDataLocationIndexed(illegal name)");
262 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(index)");
266 if (index
== 0 && colorNumber
>= ctx
->Const
.MaxDrawBuffers
) {
267 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(colorNumber)");
271 if (index
== 1 && colorNumber
>= ctx
->Const
.MaxDualSourceDrawBuffers
) {
272 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(colorNumber)");
276 /* Replace the current value if it's already in the list. Add
277 * FRAG_RESULT_DATA0 because that's how the linker differentiates
278 * between built-in attributes and user-defined attributes.
280 shProg
->FragDataBindings
->put(colorNumber
+ FRAG_RESULT_DATA0
, name
);
281 shProg
->FragDataIndexBindings
->put(index
, name
);
283 * Note that this binding won't go into effect until
284 * glLinkProgram is called again.
290 _mesa_GetFragDataIndex(GLuint program
, const GLchar
*name
)
292 GET_CURRENT_CONTEXT(ctx
);
293 struct gl_shader_program
*const shProg
=
294 _mesa_lookup_shader_program_err(ctx
, program
, "glGetFragDataIndex");
300 if (!shProg
->LinkStatus
) {
301 _mesa_error(ctx
, GL_INVALID_OPERATION
,
302 "glGetFragDataIndex(program not linked)");
309 if (strncmp(name
, "gl_", 3) == 0) {
310 _mesa_error(ctx
, GL_INVALID_OPERATION
,
311 "glGetFragDataIndex(illegal name)");
315 /* Not having a fragment shader is not an error.
317 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)
320 return _mesa_program_resource_location_index(shProg
, GL_PROGRAM_OUTPUT
,
325 _mesa_GetFragDataLocation(GLuint program
, const GLchar
*name
)
327 GET_CURRENT_CONTEXT(ctx
);
328 struct gl_shader_program
*const shProg
=
329 _mesa_lookup_shader_program_err(ctx
, program
, "glGetFragDataLocation");
335 if (!shProg
->LinkStatus
) {
336 _mesa_error(ctx
, GL_INVALID_OPERATION
,
337 "glGetFragDataLocation(program not linked)");
344 if (strncmp(name
, "gl_", 3) == 0) {
345 _mesa_error(ctx
, GL_INVALID_OPERATION
,
346 "glGetFragDataLocation(illegal name)");
350 /* Not having a fragment shader is not an error.
352 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)
355 unsigned array_index
= 0;
356 struct gl_program_resource
*res
=
357 _mesa_program_resource_find_name(shProg
, GL_PROGRAM_OUTPUT
, name
,
363 return program_resource_location(shProg
, res
, name
, array_index
);
367 _mesa_program_resource_name(struct gl_program_resource
*res
)
370 case GL_UNIFORM_BLOCK
:
371 case GL_SHADER_STORAGE_BLOCK
:
372 return RESOURCE_UBO(res
)->Name
;
373 case GL_TRANSFORM_FEEDBACK_VARYING
:
374 return RESOURCE_XFV(res
)->Name
;
375 case GL_PROGRAM_INPUT
:
376 case GL_PROGRAM_OUTPUT
:
377 return RESOURCE_VAR(res
)->name
;
379 case GL_BUFFER_VARIABLE
:
380 return RESOURCE_UNI(res
)->name
;
381 case GL_VERTEX_SUBROUTINE_UNIFORM
:
382 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
383 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
384 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
385 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
386 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
387 return RESOURCE_UNI(res
)->name
+ MESA_SUBROUTINE_PREFIX_LEN
;
388 case GL_VERTEX_SUBROUTINE
:
389 case GL_GEOMETRY_SUBROUTINE
:
390 case GL_FRAGMENT_SUBROUTINE
:
391 case GL_COMPUTE_SUBROUTINE
:
392 case GL_TESS_CONTROL_SUBROUTINE
:
393 case GL_TESS_EVALUATION_SUBROUTINE
:
394 return RESOURCE_SUB(res
)->name
;
396 assert(!"support for resource type not implemented");
403 _mesa_program_resource_array_size(struct gl_program_resource
*res
)
406 case GL_TRANSFORM_FEEDBACK_VARYING
:
407 return RESOURCE_XFV(res
)->Size
> 1 ?
408 RESOURCE_XFV(res
)->Size
: 0;
409 case GL_PROGRAM_INPUT
:
410 case GL_PROGRAM_OUTPUT
:
411 return RESOURCE_VAR(res
)->type
->length
;
413 case GL_VERTEX_SUBROUTINE_UNIFORM
:
414 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
415 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
416 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
417 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
418 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
419 return RESOURCE_UNI(res
)->array_elements
;
420 case GL_BUFFER_VARIABLE
:
422 if (RESOURCE_UNI(res
)->array_stride
> 0 &&
423 RESOURCE_UNI(res
)->array_elements
== 0)
426 return RESOURCE_UNI(res
)->array_elements
;
427 case GL_VERTEX_SUBROUTINE
:
428 case GL_GEOMETRY_SUBROUTINE
:
429 case GL_FRAGMENT_SUBROUTINE
:
430 case GL_COMPUTE_SUBROUTINE
:
431 case GL_TESS_CONTROL_SUBROUTINE
:
432 case GL_TESS_EVALUATION_SUBROUTINE
:
433 case GL_ATOMIC_COUNTER_BUFFER
:
434 case GL_UNIFORM_BLOCK
:
435 case GL_SHADER_STORAGE_BLOCK
:
438 assert(!"support for resource type not implemented");
444 * Checks if array subscript is valid and if so sets array_index.
447 valid_array_index(const GLchar
*name
, unsigned *array_index
)
450 const GLchar
*out_base_name_end
;
452 idx
= parse_program_resource_name(name
, &out_base_name_end
);
462 /* Find a program resource with specific name in given interface.
464 struct gl_program_resource
*
465 _mesa_program_resource_find_name(struct gl_shader_program
*shProg
,
466 GLenum programInterface
, const char *name
,
467 unsigned *array_index
)
469 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
470 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
471 if (res
->Type
!= programInterface
)
474 /* Resource basename. */
475 const char *rname
= _mesa_program_resource_name(res
);
476 unsigned baselen
= strlen(rname
);
477 unsigned baselen_without_array_index
= baselen
;
478 const char *rname_last_square_bracket
= strrchr(rname
, '[');
480 bool rname_has_array_index_zero
= false;
481 /* From ARB_program_interface_query spec:
483 * "uint GetProgramResourceIndex(uint program, enum programInterface,
486 * If <name> exactly matches the name string of one of the active
487 * resources for <programInterface>, the index of the matched resource is
488 * returned. Additionally, if <name> would exactly match the name string
489 * of an active resource if "[0]" were appended to <name>, the index of
490 * the matched resource is returned. [...]"
492 * "A string provided to GetProgramResourceLocation or
493 * GetProgramResourceLocationIndex is considered to match an active variable
496 * * the string exactly matches the name of the active variable;
498 * * if the string identifies the base name of an active array, where the
499 * string would exactly match the name of the variable if the suffix
500 * "[0]" were appended to the string; [...]"
502 /* Remove array's index from interface block name comparison only if
503 * array's index is zero and the resulting string length is the same
504 * than the provided name's length.
506 if (rname_last_square_bracket
) {
507 baselen_without_array_index
-= strlen(rname_last_square_bracket
);
508 rname_has_array_index_zero
=
509 (strncmp(rname_last_square_bracket
, "[0]\0", 4) == 0) &&
510 (baselen_without_array_index
== strlen(name
));
513 if (strncmp(rname
, name
, baselen
) == 0)
515 else if (rname_has_array_index_zero
&&
516 strncmp(rname
, name
, baselen_without_array_index
) == 0)
520 switch (programInterface
) {
521 case GL_UNIFORM_BLOCK
:
522 case GL_SHADER_STORAGE_BLOCK
:
523 /* Basename match, check if array or struct. */
524 if (rname_has_array_index_zero
||
525 name
[baselen
] == '\0' ||
526 name
[baselen
] == '[' ||
527 name
[baselen
] == '.') {
531 case GL_TRANSFORM_FEEDBACK_VARYING
:
532 case GL_BUFFER_VARIABLE
:
534 case GL_VERTEX_SUBROUTINE_UNIFORM
:
535 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
536 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
537 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
538 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
539 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
540 case GL_VERTEX_SUBROUTINE
:
541 case GL_GEOMETRY_SUBROUTINE
:
542 case GL_FRAGMENT_SUBROUTINE
:
543 case GL_COMPUTE_SUBROUTINE
:
544 case GL_TESS_CONTROL_SUBROUTINE
:
545 case GL_TESS_EVALUATION_SUBROUTINE
:
546 if (name
[baselen
] == '.') {
550 case GL_PROGRAM_INPUT
:
551 case GL_PROGRAM_OUTPUT
:
552 if (name
[baselen
] == '\0') {
554 } else if (name
[baselen
] == '[' &&
555 valid_array_index(name
, array_index
)) {
560 assert(!"not implemented for given interface");
568 calc_resource_index(struct gl_shader_program
*shProg
,
569 struct gl_program_resource
*res
)
573 for (i
= 0; i
< shProg
->NumProgramResourceList
; i
++) {
574 if (&shProg
->ProgramResourceList
[i
] == res
)
576 if (shProg
->ProgramResourceList
[i
].Type
== res
->Type
)
579 return GL_INVALID_INDEX
;
583 * Calculate index for the given resource.
586 _mesa_program_resource_index(struct gl_shader_program
*shProg
,
587 struct gl_program_resource
*res
)
590 return GL_INVALID_INDEX
;
593 case GL_ATOMIC_COUNTER_BUFFER
:
594 return RESOURCE_ATC(res
) - shProg
->AtomicBuffers
;
595 case GL_VERTEX_SUBROUTINE
:
596 case GL_GEOMETRY_SUBROUTINE
:
597 case GL_FRAGMENT_SUBROUTINE
:
598 case GL_COMPUTE_SUBROUTINE
:
599 case GL_TESS_CONTROL_SUBROUTINE
:
600 case GL_TESS_EVALUATION_SUBROUTINE
:
601 return RESOURCE_SUB(res
)->index
;
602 case GL_UNIFORM_BLOCK
:
603 case GL_SHADER_STORAGE_BLOCK
:
604 case GL_TRANSFORM_FEEDBACK_BUFFER
:
605 case GL_TRANSFORM_FEEDBACK_VARYING
:
607 return calc_resource_index(shProg
, res
);
612 * Find a program resource that points to given data.
614 static struct gl_program_resource
*
615 program_resource_find_data(struct gl_shader_program
*shProg
, void *data
)
617 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
618 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
619 if (res
->Data
== data
)
625 /* Find a program resource with specific index in given interface.
627 struct gl_program_resource
*
628 _mesa_program_resource_find_index(struct gl_shader_program
*shProg
,
629 GLenum programInterface
, GLuint index
)
631 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
634 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
635 if (res
->Type
!= programInterface
)
639 case GL_UNIFORM_BLOCK
:
640 case GL_ATOMIC_COUNTER_BUFFER
:
641 case GL_SHADER_STORAGE_BLOCK
:
642 case GL_TRANSFORM_FEEDBACK_BUFFER
:
643 if (_mesa_program_resource_index(shProg
, res
) == index
)
646 case GL_TRANSFORM_FEEDBACK_VARYING
:
647 case GL_PROGRAM_INPUT
:
648 case GL_PROGRAM_OUTPUT
:
650 case GL_VERTEX_SUBROUTINE_UNIFORM
:
651 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
652 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
653 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
654 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
655 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
656 case GL_VERTEX_SUBROUTINE
:
657 case GL_GEOMETRY_SUBROUTINE
:
658 case GL_FRAGMENT_SUBROUTINE
:
659 case GL_COMPUTE_SUBROUTINE
:
660 case GL_TESS_CONTROL_SUBROUTINE
:
661 case GL_TESS_EVALUATION_SUBROUTINE
:
662 case GL_BUFFER_VARIABLE
:
663 if (++idx
== (int) index
)
667 assert(!"not implemented for given interface");
673 /* Function returns if resource name is expected to have index
677 * Page 61 (page 73 of the PDF) in section 2.11 of the OpenGL ES 3.0
680 * "If the active uniform is an array, the uniform name returned in
681 * name will always be the name of the uniform array appended with
684 * The same text also appears in the OpenGL 4.2 spec. It does not,
685 * however, appear in any previous spec. Previous specifications are
686 * ambiguous in this regard. However, either name can later be passed
687 * to glGetUniformLocation (and related APIs), so there shouldn't be any
688 * harm in always appending "[0]" to uniform array names.
690 * Geometry shader stage has different naming convention where the 'normal'
691 * condition is an array, therefore for variables referenced in geometry
692 * stage we do not add '[0]'.
694 * Note, that TCS outputs and TES inputs should not have index appended
698 add_index_to_name(struct gl_program_resource
*res
)
700 bool add_index
= !((res
->Type
== GL_PROGRAM_INPUT
&&
701 res
->StageReferences
& (1 << MESA_SHADER_GEOMETRY
|
702 1 << MESA_SHADER_TESS_CTRL
|
703 1 << MESA_SHADER_TESS_EVAL
)) ||
704 (res
->Type
== GL_PROGRAM_OUTPUT
&&
705 res
->StageReferences
& 1 << MESA_SHADER_TESS_CTRL
));
707 /* Transform feedback varyings have array index already appended
710 if (res
->Type
== GL_TRANSFORM_FEEDBACK_VARYING
)
716 /* Get name length of a program resource. This consists of
717 * base name + 3 for '[0]' if resource is an array.
720 _mesa_program_resource_name_len(struct gl_program_resource
*res
)
722 unsigned length
= strlen(_mesa_program_resource_name(res
));
723 if (_mesa_program_resource_array_size(res
) && add_index_to_name(res
))
728 /* Get full name of a program resource.
731 _mesa_get_program_resource_name(struct gl_shader_program
*shProg
,
732 GLenum programInterface
, GLuint index
,
733 GLsizei bufSize
, GLsizei
*length
,
734 GLchar
*name
, const char *caller
)
736 GET_CURRENT_CONTEXT(ctx
);
738 /* Find resource with given interface and index. */
739 struct gl_program_resource
*res
=
740 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
742 /* The error INVALID_VALUE is generated if <index> is greater than
743 * or equal to the number of entries in the active resource list for
744 * <programInterface>.
747 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index %u)", caller
, index
);
752 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(bufSize %d)", caller
, bufSize
);
759 length
= &localLength
;
761 _mesa_copy_string(name
, bufSize
, length
, _mesa_program_resource_name(res
));
763 if (_mesa_program_resource_array_size(res
) && add_index_to_name(res
)) {
766 /* The comparison is strange because *length does *NOT* include the
767 * terminating NUL, but maxLength does.
769 for (i
= 0; i
< 3 && (*length
+ i
+ 1) < bufSize
; i
++)
770 name
[*length
+ i
] = "[0]"[i
];
772 name
[*length
+ i
] = '\0';
779 program_resource_location(struct gl_shader_program
*shProg
,
780 struct gl_program_resource
*res
, const char *name
,
781 unsigned array_index
)
783 /* VERT_ATTRIB_GENERIC0 and FRAG_RESULT_DATA0 are decremented as these
784 * offsets are used internally to differentiate between built-in attributes
785 * and user-defined attributes.
788 case GL_PROGRAM_INPUT
: {
789 const gl_shader_variable
*var
= RESOURCE_VAR(res
);
791 if (var
->location
== -1)
794 /* If the input is an array, fail if the index is out of bounds. */
796 && array_index
>= var
->type
->length
) {
799 return (var
->location
+
800 (array_index
* var
->type
->without_array()->matrix_columns
) -
801 VERT_ATTRIB_GENERIC0
);
803 case GL_PROGRAM_OUTPUT
:
804 if (RESOURCE_VAR(res
)->location
== -1)
807 /* If the output is an array, fail if the index is out of bounds. */
809 && array_index
>= RESOURCE_VAR(res
)->type
->length
) {
812 return RESOURCE_VAR(res
)->location
+ array_index
- FRAG_RESULT_DATA0
;
814 /* If the uniform is built-in, fail. */
815 if (RESOURCE_UNI(res
)->builtin
)
818 /* From page 79 of the OpenGL 4.2 spec:
820 * "A valid name cannot be a structure, an array of structures, or any
821 * portion of a single vector or a matrix."
823 if (RESOURCE_UNI(res
)->type
->without_array()->is_record())
826 /* From the GL_ARB_uniform_buffer_object spec:
828 * "The value -1 will be returned if <name> does not correspond to an
829 * active uniform variable name in <program>, if <name> is associated
830 * with a named uniform block, or if <name> starts with the reserved
833 if (RESOURCE_UNI(res
)->block_index
!= -1 ||
834 RESOURCE_UNI(res
)->atomic_buffer_index
!= -1)
838 case GL_VERTEX_SUBROUTINE_UNIFORM
:
839 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
840 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
841 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
842 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
843 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
844 /* If the uniform is an array, fail if the index is out of bounds. */
846 && array_index
>= RESOURCE_UNI(res
)->array_elements
) {
850 /* location in remap table + array element offset */
851 return RESOURCE_UNI(res
)->remap_location
+ array_index
;
858 * Function implements following location queries:
859 * glGetUniformLocation
862 _mesa_program_resource_location(struct gl_shader_program
*shProg
,
863 GLenum programInterface
, const char *name
)
865 unsigned array_index
= 0;
866 struct gl_program_resource
*res
=
867 _mesa_program_resource_find_name(shProg
, programInterface
, name
,
870 /* Resource not found. */
874 return program_resource_location(shProg
, res
, name
, array_index
);
878 * Function implements following index queries:
882 _mesa_program_resource_location_index(struct gl_shader_program
*shProg
,
883 GLenum programInterface
, const char *name
)
885 struct gl_program_resource
*res
=
886 _mesa_program_resource_find_name(shProg
, programInterface
, name
, NULL
);
888 /* Non-existent variable or resource is not referenced by fragment stage. */
889 if (!res
|| !(res
->StageReferences
& (1 << MESA_SHADER_FRAGMENT
)))
892 return RESOURCE_VAR(res
)->index
;
896 stage_from_enum(GLenum ref
)
899 case GL_REFERENCED_BY_VERTEX_SHADER
:
900 return MESA_SHADER_VERTEX
;
901 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
902 return MESA_SHADER_TESS_CTRL
;
903 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
904 return MESA_SHADER_TESS_EVAL
;
905 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
906 return MESA_SHADER_GEOMETRY
;
907 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
908 return MESA_SHADER_FRAGMENT
;
909 case GL_REFERENCED_BY_COMPUTE_SHADER
:
910 return MESA_SHADER_COMPUTE
;
912 assert(!"shader stage not supported");
913 return MESA_SHADER_STAGES
;
918 * Check if resource is referenced by given 'referenced by' stage enum.
919 * ATC and UBO resources hold stage references of their own.
922 is_resource_referenced(struct gl_shader_program
*shProg
,
923 struct gl_program_resource
*res
,
924 GLuint index
, uint8_t stage
)
926 /* First, check if we even have such a stage active. */
927 if (!shProg
->_LinkedShaders
[stage
])
930 if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
)
931 return RESOURCE_ATC(res
)->StageReferences
[stage
];
933 if (res
->Type
== GL_UNIFORM_BLOCK
|| res
->Type
== GL_SHADER_STORAGE_BLOCK
)
934 return shProg
->InterfaceBlockStageIndex
[stage
][index
] != -1;
936 return res
->StageReferences
& (1 << stage
);
940 get_buffer_property(struct gl_shader_program
*shProg
,
941 struct gl_program_resource
*res
, const GLenum prop
,
942 GLint
*val
, const char *caller
)
944 GET_CURRENT_CONTEXT(ctx
);
945 if (res
->Type
!= GL_UNIFORM_BLOCK
&&
946 res
->Type
!= GL_ATOMIC_COUNTER_BUFFER
&&
947 res
->Type
!= GL_SHADER_STORAGE_BLOCK
&&
948 res
->Type
!= GL_TRANSFORM_FEEDBACK_BUFFER
)
949 goto invalid_operation
;
951 if (res
->Type
== GL_UNIFORM_BLOCK
) {
953 case GL_BUFFER_BINDING
:
954 *val
= RESOURCE_UBO(res
)->Binding
;
956 case GL_BUFFER_DATA_SIZE
:
957 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
959 case GL_NUM_ACTIVE_VARIABLES
:
961 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
962 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
963 struct gl_program_resource
*uni
=
964 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
971 case GL_ACTIVE_VARIABLES
: {
972 unsigned num_values
= 0;
973 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
974 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
975 struct gl_program_resource
*uni
=
976 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
981 _mesa_program_resource_index(shProg
, uni
);
987 } else if (res
->Type
== GL_SHADER_STORAGE_BLOCK
) {
989 case GL_BUFFER_BINDING
:
990 *val
= RESOURCE_UBO(res
)->Binding
;
992 case GL_BUFFER_DATA_SIZE
:
993 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
995 case GL_NUM_ACTIVE_VARIABLES
:
997 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
998 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
999 struct gl_program_resource
*uni
=
1000 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1007 case GL_ACTIVE_VARIABLES
: {
1008 unsigned num_values
= 0;
1009 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1010 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1011 struct gl_program_resource
*uni
=
1012 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1017 _mesa_program_resource_index(shProg
, uni
);
1023 } else if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
) {
1025 case GL_BUFFER_BINDING
:
1026 *val
= RESOURCE_ATC(res
)->Binding
;
1028 case GL_BUFFER_DATA_SIZE
:
1029 *val
= RESOURCE_ATC(res
)->MinimumSize
;
1031 case GL_NUM_ACTIVE_VARIABLES
:
1032 *val
= RESOURCE_ATC(res
)->NumUniforms
;
1034 case GL_ACTIVE_VARIABLES
:
1035 for (unsigned i
= 0; i
< RESOURCE_ATC(res
)->NumUniforms
; i
++) {
1036 /* Active atomic buffer contains index to UniformStorage. Find
1037 * out gl_program_resource via data pointer and then calculate
1038 * index of that uniform.
1040 unsigned idx
= RESOURCE_ATC(res
)->Uniforms
[i
];
1041 struct gl_program_resource
*uni
=
1042 program_resource_find_data(shProg
,
1043 &shProg
->UniformStorage
[idx
]);
1045 *val
++ = _mesa_program_resource_index(shProg
, uni
);
1047 return RESOURCE_ATC(res
)->NumUniforms
;
1049 } else if (res
->Type
== GL_TRANSFORM_FEEDBACK_BUFFER
) {
1051 case GL_BUFFER_BINDING
:
1052 *val
= RESOURCE_XFB(res
)->Binding
;
1054 case GL_NUM_ACTIVE_VARIABLES
:
1055 *val
= RESOURCE_XFB(res
)->NumVaryings
;
1057 case GL_ACTIVE_VARIABLES
:
1059 for ( ; i
< shProg
->LinkedTransformFeedback
.NumVarying
; i
++) {
1061 shProg
->LinkedTransformFeedback
.Varyings
[i
].BufferIndex
;
1062 struct gl_program_resource
*buf_res
=
1063 _mesa_program_resource_find_index(shProg
,
1064 GL_TRANSFORM_FEEDBACK_BUFFER
,
1067 if (res
== buf_res
) {
1071 return RESOURCE_XFB(res
)->NumVaryings
;
1074 assert(!"support for property type not implemented");
1077 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1078 _mesa_enum_to_string(res
->Type
),
1079 _mesa_enum_to_string(prop
));
1085 _mesa_program_resource_prop(struct gl_shader_program
*shProg
,
1086 struct gl_program_resource
*res
, GLuint index
,
1087 const GLenum prop
, GLint
*val
, const char *caller
)
1089 GET_CURRENT_CONTEXT(ctx
);
1091 #define VALIDATE_TYPE(type)\
1092 if (res->Type != type)\
1093 goto invalid_operation;
1095 #define VALIDATE_TYPE_2(type1, type2)\
1096 if (res->Type != type1 && res->Type != type2)\
1097 goto invalid_operation;
1100 case GL_NAME_LENGTH
:
1101 switch (res
->Type
) {
1102 case GL_ATOMIC_COUNTER_BUFFER
:
1103 case GL_TRANSFORM_FEEDBACK_BUFFER
:
1104 goto invalid_operation
;
1106 /* Resource name length + terminator. */
1107 *val
= _mesa_program_resource_name_len(res
) + 1;
1111 switch (res
->Type
) {
1113 case GL_BUFFER_VARIABLE
:
1114 *val
= RESOURCE_UNI(res
)->type
->gl_type
;
1116 case GL_PROGRAM_INPUT
:
1117 case GL_PROGRAM_OUTPUT
:
1118 *val
= RESOURCE_VAR(res
)->type
->gl_type
;
1120 case GL_TRANSFORM_FEEDBACK_VARYING
:
1121 *val
= RESOURCE_XFV(res
)->Type
;
1124 goto invalid_operation
;
1127 switch (res
->Type
) {
1129 case GL_BUFFER_VARIABLE
:
1130 /* Test if a buffer variable is an array or an unsized array.
1131 * Unsized arrays return zero as array size.
1133 if (RESOURCE_UNI(res
)->is_shader_storage
&&
1134 RESOURCE_UNI(res
)->array_stride
> 0)
1135 *val
= RESOURCE_UNI(res
)->array_elements
;
1137 *val
= MAX2(RESOURCE_UNI(res
)->array_elements
, 1);
1139 case GL_PROGRAM_INPUT
:
1140 case GL_PROGRAM_OUTPUT
:
1141 *val
= MAX2(_mesa_program_resource_array_size(res
), 1);
1143 case GL_TRANSFORM_FEEDBACK_VARYING
:
1144 *val
= MAX2(RESOURCE_XFV(res
)->Size
, 1);
1147 goto invalid_operation
;
1150 switch (res
->Type
) {
1152 case GL_BUFFER_VARIABLE
:
1153 *val
= RESOURCE_UNI(res
)->offset
;
1155 case GL_TRANSFORM_FEEDBACK_VARYING
:
1156 *val
= RESOURCE_XFV(res
)->Offset
;
1159 goto invalid_operation
;
1161 case GL_BLOCK_INDEX
:
1162 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1163 *val
= RESOURCE_UNI(res
)->block_index
;
1165 case GL_ARRAY_STRIDE
:
1166 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1167 *val
= RESOURCE_UNI(res
)->array_stride
;
1169 case GL_MATRIX_STRIDE
:
1170 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1171 *val
= RESOURCE_UNI(res
)->matrix_stride
;
1173 case GL_IS_ROW_MAJOR
:
1174 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1175 *val
= RESOURCE_UNI(res
)->row_major
;
1177 case GL_ATOMIC_COUNTER_BUFFER_INDEX
:
1178 VALIDATE_TYPE(GL_UNIFORM
);
1179 *val
= RESOURCE_UNI(res
)->atomic_buffer_index
;
1181 case GL_BUFFER_BINDING
:
1182 case GL_BUFFER_DATA_SIZE
:
1183 case GL_NUM_ACTIVE_VARIABLES
:
1184 case GL_ACTIVE_VARIABLES
:
1185 return get_buffer_property(shProg
, res
, prop
, val
, caller
);
1186 case GL_REFERENCED_BY_COMPUTE_SHADER
:
1187 if (!_mesa_has_compute_shaders(ctx
))
1190 case GL_REFERENCED_BY_VERTEX_SHADER
:
1191 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
1192 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1193 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
1194 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
1195 switch (res
->Type
) {
1197 case GL_PROGRAM_INPUT
:
1198 case GL_PROGRAM_OUTPUT
:
1199 case GL_UNIFORM_BLOCK
:
1200 case GL_BUFFER_VARIABLE
:
1201 case GL_SHADER_STORAGE_BLOCK
:
1202 case GL_ATOMIC_COUNTER_BUFFER
:
1203 *val
= is_resource_referenced(shProg
, res
, index
,
1204 stage_from_enum(prop
));
1207 goto invalid_operation
;
1210 switch (res
->Type
) {
1212 case GL_PROGRAM_INPUT
:
1213 case GL_PROGRAM_OUTPUT
:
1214 *val
= program_resource_location(shProg
, res
,
1215 _mesa_program_resource_name(res
),
1219 goto invalid_operation
;
1221 case GL_LOCATION_INDEX
:
1222 if (res
->Type
!= GL_PROGRAM_OUTPUT
)
1223 goto invalid_operation
;
1224 *val
= RESOURCE_VAR(res
)->index
;
1227 case GL_NUM_COMPATIBLE_SUBROUTINES
:
1228 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1229 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1230 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1231 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1232 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1233 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1234 goto invalid_operation
;
1235 *val
= RESOURCE_UNI(res
)->num_compatible_subroutines
;
1237 case GL_COMPATIBLE_SUBROUTINES
: {
1238 const struct gl_uniform_storage
*uni
;
1239 struct gl_shader
*sh
;
1243 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1244 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1245 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1246 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1247 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1248 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1249 goto invalid_operation
;
1250 uni
= RESOURCE_UNI(res
);
1252 sh
= shProg
->_LinkedShaders
[_mesa_shader_stage_from_subroutine_uniform(res
->Type
)];
1254 for (i
= 0; i
< sh
->NumSubroutineFunctions
; i
++) {
1255 struct gl_subroutine_function
*fn
= &sh
->SubroutineFunctions
[i
];
1256 for (j
= 0; j
< fn
->num_compat_types
; j
++) {
1257 if (fn
->types
[j
] == uni
->type
) {
1266 case GL_TOP_LEVEL_ARRAY_SIZE
:
1267 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1268 *val
= RESOURCE_UNI(res
)->top_level_array_size
;
1271 case GL_TOP_LEVEL_ARRAY_STRIDE
:
1272 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1273 *val
= RESOURCE_UNI(res
)->top_level_array_stride
;
1276 /* GL_ARB_tessellation_shader */
1277 case GL_IS_PER_PATCH
:
1278 switch (res
->Type
) {
1279 case GL_PROGRAM_INPUT
:
1280 case GL_PROGRAM_OUTPUT
:
1281 *val
= RESOURCE_VAR(res
)->patch
;
1284 goto invalid_operation
;
1287 case GL_TRANSFORM_FEEDBACK_BUFFER_INDEX
:
1288 VALIDATE_TYPE(GL_TRANSFORM_FEEDBACK_VARYING
);
1289 *val
= RESOURCE_XFV(res
)->BufferIndex
;
1291 case GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE
:
1292 VALIDATE_TYPE(GL_TRANSFORM_FEEDBACK_BUFFER
);
1293 *val
= RESOURCE_XFB(res
)->Stride
* 4;
1300 #undef VALIDATE_TYPE
1301 #undef VALIDATE_TYPE_2
1304 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(%s prop %s)", caller
,
1305 _mesa_enum_to_string(res
->Type
),
1306 _mesa_enum_to_string(prop
));
1310 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1311 _mesa_enum_to_string(res
->Type
),
1312 _mesa_enum_to_string(prop
));
1317 _mesa_get_program_resourceiv(struct gl_shader_program
*shProg
,
1318 GLenum programInterface
, GLuint index
, GLsizei propCount
,
1319 const GLenum
*props
, GLsizei bufSize
,
1320 GLsizei
*length
, GLint
*params
)
1322 GET_CURRENT_CONTEXT(ctx
);
1323 GLint
*val
= (GLint
*) params
;
1324 const GLenum
*prop
= props
;
1327 struct gl_program_resource
*res
=
1328 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
1330 /* No such resource found or bufSize negative. */
1331 if (!res
|| bufSize
< 0) {
1332 _mesa_error(ctx
, GL_INVALID_VALUE
,
1333 "glGetProgramResourceiv(%s index %d bufSize %d)",
1334 _mesa_enum_to_string(programInterface
), index
, bufSize
);
1338 /* Write propCount values until error occurs or bufSize reached. */
1339 for (int i
= 0; i
< propCount
&& i
< bufSize
; i
++, val
++, prop
++) {
1341 _mesa_program_resource_prop(shProg
, res
, index
, *prop
, val
,
1342 "glGetProgramResourceiv");
1344 /* Error happened. */
1345 if (props_written
== 0)
1348 amount
+= props_written
;
1351 /* If <length> is not NULL, the actual number of integer values
1352 * written to <params> will be written to <length>.
1359 validate_io(const struct gl_shader
*producer
,
1360 const struct gl_shader
*consumer
, bool isES
)
1362 assert(producer
&& consumer
);
1363 unsigned inputs
= 0, outputs
= 0;
1365 /* From OpenGL ES 3.1 spec (Interface matching):
1367 * "An output variable is considered to match an input variable in the
1368 * subsequent shader if:
1370 * - the two variables match in name, type, and qualification; or
1371 * - the two variables are declared with the same location qualifier and
1372 * match in type and qualification.
1376 * At an interface between program objects, the set of inputs and outputs
1377 * are considered to match exactly if and only if:
1379 * - Every declared input variable has a matching output, as described
1382 * - There are no user-defined output variables declared without a
1383 * matching input variable declaration.
1385 * - All matched input and output variables have identical precision
1388 * When the set of inputs and outputs on an interface between programs
1389 * matches exactly, all inputs are well-defined except when the
1390 * corresponding outputs were not written in the previous shader. However,
1391 * any mismatch between inputs and outputs will result in a validation
1394 * OpenGL Core 4.5 spec includes same paragraph as above but without check
1395 * for precision and the last 'validation failure' clause. Therefore
1396 * behaviour is more relaxed, input and output amount is not required by the
1397 * spec to be validated.
1399 * FIXME: Update once Khronos spec bug #15331 is resolved.
1400 * FIXME: Add validation by type, currently information loss during varying
1401 * packing makes this challenging.
1404 /* Currently no matching done for desktop. */
1408 /* For each output in a, find input in b and do any required checks. */
1409 foreach_in_list(ir_instruction
, out
, producer
->ir
) {
1410 ir_variable
*out_var
= out
->as_variable();
1411 if (!out_var
|| out_var
->data
.mode
!= ir_var_shader_out
||
1412 is_gl_identifier(out_var
->name
))
1418 foreach_in_list(ir_instruction
, in
, consumer
->ir
) {
1419 ir_variable
*in_var
= in
->as_variable();
1420 if (!in_var
|| in_var
->data
.mode
!= ir_var_shader_in
||
1421 is_gl_identifier(in_var
->name
))
1426 /* Match by location qualifier and precision.
1428 * FIXME: Add explicit location matching validation here. Be careful
1429 * not to match varyings with explicit locations to varyings without
1430 * explicit locations.
1432 if ((in_var
->data
.explicit_location
&&
1433 out_var
->data
.explicit_location
) &&
1434 in_var
->data
.location
== out_var
->data
.location
&&
1435 in_var
->data
.precision
== out_var
->data
.precision
)
1438 unsigned len
= strlen(in_var
->name
);
1440 /* Handle input swizzle in variable name. */
1441 const char *dot
= strchr(in_var
->name
, '.');
1443 len
= dot
- in_var
->name
;
1445 /* Match by name and precision. */
1446 if (strncmp(in_var
->name
, out_var
->name
, len
) == 0) {
1447 /* From OpenGL ES 3.1 spec:
1448 * "When both shaders are in separate programs, mismatched
1449 * precision qualifiers will result in a program interface
1450 * mismatch that will result in program pipeline validation
1451 * failures, as described in section 7.4.1 (“Shader Interface
1452 * Matching”) of the OpenGL ES 3.1 Specification."
1454 if (in_var
->data
.precision
!= out_var
->data
.precision
)
1459 return inputs
== outputs
;
1463 * Validate inputs against outputs in a program pipeline.
1466 _mesa_validate_pipeline_io(struct gl_pipeline_object
*pipeline
)
1468 struct gl_shader_program
**shProg
=
1469 (struct gl_shader_program
**) pipeline
->CurrentProgram
;
1471 /* Find first active stage in pipeline. */
1472 unsigned idx
, prev
= 0;
1473 for (idx
= 0; idx
< ARRAY_SIZE(pipeline
->CurrentProgram
); idx
++) {
1480 for (idx
= prev
+ 1; idx
< ARRAY_SIZE(pipeline
->CurrentProgram
); idx
++) {
1482 /* Pipeline might include both non-compute and a compute program, do
1483 * not attempt to validate varyings between non-compute and compute
1486 if (shProg
[idx
]->_LinkedShaders
[idx
]->Stage
== MESA_SHADER_COMPUTE
)
1489 if (!validate_io(shProg
[prev
]->_LinkedShaders
[prev
],
1490 shProg
[idx
]->_LinkedShaders
[idx
],
1491 shProg
[prev
]->IsES
|| shProg
[idx
]->IsES
))